From c4fa3d6f0d7eaa9971b03d612957ffa1605bcf94 Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@git-test.afi-sa.fr> Date: Fri, 14 Sep 2012 15:22:57 +0000 Subject: [PATCH] =?UTF-8?q?Bib=20num=C3=A9rique=20:=20correction=20g=C3=A9?= =?UTF-8?q?n=C3=A9ration=20vignette=20+=20=20gestion=20des=20fichiers=20au?= =?UTF-8?q?=20changement=20de=20type=20de=20m=C3=A9dia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/Class/AlbumRessource.php | 65 ++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/library/Class/AlbumRessource.php b/library/Class/AlbumRessource.php index 7006091500e..06e9d8e27bf 100644 --- a/library/Class/AlbumRessource.php +++ b/library/Class/AlbumRessource.php @@ -285,17 +285,18 @@ class Class_AlbumRessource extends Storm_Model_Abstract { * @return Imagick */ public function getImage() { - if (!isset($this->_image)) { - try { - $this->_image = new Imagick(($this->isImage) ? - $this->getOriginalPath() : - $this->getPosterPath()); - - } catch (Exception $e) { - $this->_image = new Imagick(); - $this->_image->newPseudoImage(50, 50, "gradient:black-black"); - $this->_image->setImageFormat('jpg'); - } + if (isset($this->_image)) + return $this->_image; + + try { + $this->_image = new Imagick(($this->isImage()) ? + $this->getOriginalPath() : + $this->getPosterPath()); + + } catch (Exception $e) { + $this->_image = new Imagick(); + $this->_image->newPseudoImage(50, 50, "gradient:black-black"); + $this->_image->setImageFormat('jpg'); } return $this->_image; @@ -629,14 +630,47 @@ class Class_AlbumRessource extends Storm_Model_Abstract { if ($this->isNew()) $this->setOrdre($this->getNextOrder()); + + if (!$mediaType = $this->getMediaType()) + return; + + if (in_array($mediaType, [self::MEDIA_TYPE_IMAGE, self::MEDIA_TYPE_FILE]) + && $this->hasUrl()) { + $this->setUrl(''); + } + + if ((self::MEDIA_TYPE_IMAGE == $mediaType) && $this->hasPoster()) { + $this->deletePosterAndThumbnail(); + $this->setPoster(''); + } + + if ((self::MEDIA_TYPE_URL == $mediaType) && $this->hasFichier()) { + $this->deleteFichierAndThumbnail(); + $this->setFichier(''); + } } public function deleteFiles() { - if ('' != $this->getFichier()) { - $this->unlink($this->getOriginalPath()); - $this->unlink($this->getThumbnailPath()); + if ($this->isImage() && $this->hasFichier()) { + $this->deleteFichierAndThumbnail(); + return; } + + if ($this->hasPoster()) + $this->deletePosterAndThumbnail(); + } + + + public function deleteFichierAndThumbnail() { + $this->unlink($this->getOriginalPath()); + $this->unlink($this->getThumbnailPath()); + } + + + public function deletePosterAndThumbnail() { + $this->unlink($this->getPosterPath()); + $this->unlink($this->getThumbnailPath()); } @@ -722,7 +756,6 @@ class Class_AlbumRessource extends Storm_Model_Abstract { return $folio; } - public function setMediaType($type) { $this->_media_type = $type; @@ -767,7 +800,7 @@ class Class_AlbumRessource extends Storm_Model_Abstract { public function validateMediaIsFileWithExtensions($extensions = []) { - // en édition et fichier inchangé + // en édition et fichier inchangé if (!$this->isNew() && !$this->isFileUploadedForName('fichier')) return; -- GitLab