partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 374dbffe42c267ab0adee74aa5675d1f48b34836
parent 59ddf6f5d2f45c05dbf3680a79adfc66dc81c62e
Author: Felicitus <felicitus@felicitus.org>
Date:   Wed,  4 Nov 2015 19:14:32 +0100

Generate the isImage property dynamically depending on the installed image library. Currently hard-coded for GD

Diffstat:
Mapp/config/config_partkeepr.yml | 7+++++++
Msrc/PartKeepr/ImageBundle/Services/ImageService.php | 17+++++++++++++++++
Msrc/PartKeepr/PartBundle/Entity/PartAttachment.php | 8++++++++
Asrc/PartKeepr/PartBundle/Listeners/ImageAttachmentListener.php | 24++++++++++++++++++++++++
4 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/app/config/config_partkeepr.yml b/app/config/config_partkeepr.yml @@ -9,6 +9,13 @@ services: tags: - { name: "kernel.event_listener", event: "kernel.view", method: "onKernelView" } + part_image_listener: + class: PartKeepr\PartBundle\Listeners\ImageAttachmentListener + arguments: + - "@partkeepr_image_service" + tags: + - { name: doctrine.event_listener, event: postLoad } + partkeepr_legacy_user_provider: class: PartKeepr\AuthBundle\Security\User\LegacyUserProvider arguments: diff --git a/src/PartKeepr/ImageBundle/Services/ImageService.php b/src/PartKeepr/ImageBundle/Services/ImageService.php @@ -51,4 +51,21 @@ class ImageService extends UploadedFileService $entityManager->remove($file); } } + + /** + * Checks if the system can handle the given mime type as image. Currently hardcoded for GD + * + * @param $mimeType The mime type to check + * @return boolean True if the system can display images of the given mimetype, false otherwise + */ + public function canHandleMimetype ($mimeType) { + switch ($mimeType) { + case "image/jpeg": + case "image/png": + case "image/gif": + return true; + default: + return false; + } + } } diff --git a/src/PartKeepr/PartBundle/Entity/PartAttachment.php b/src/PartKeepr/PartBundle/Entity/PartAttachment.php @@ -68,4 +68,12 @@ class PartAttachment extends UploadedFile { return $this->isImage; } + + /** + * Sets if the attachment is an image + * @param $image + */ + public function setImage($image) { + $this->isImage = $image; + } } diff --git a/src/PartKeepr/PartBundle/Listeners/ImageAttachmentListener.php b/src/PartKeepr/PartBundle/Listeners/ImageAttachmentListener.php @@ -0,0 +1,24 @@ +<?php +namespace PartKeepr\PartBundle\Listeners; +use Doctrine\ORM\Event\LifecycleEventArgs; +use PartKeepr\ImageBundle\Services\ImageService; +use PartKeepr\PartBundle\Entity\PartAttachment; + +class ImageAttachmentListener +{ + private $imageService; + + public function __construct (ImageService $imageService) { + $this->imageService = $imageService; + } + public function postLoad(LifecycleEventArgs $event) { + if ($event->getEntity() instanceof PartAttachment) { + /** + * @var $entity PartAttachment + */ + $entity = $event->getEntity(); + + $entity->setImage($this->imageService->canHandleMimetype($entity->getMimeType())); + } + } +}