diff --git a/application/modules/admin/controllers/AlbumController.php b/application/modules/admin/controllers/AlbumController.php index b2fb9c031280f86150a66308b0bfdc4fbdadbc0c..87934f3155e724be4bd8ede51f84f2c7a2a317b8 100644 --- a/application/modules/admin/controllers/AlbumController.php +++ b/application/modules/admin/controllers/AlbumController.php @@ -260,7 +260,7 @@ class Admin_AlbumController extends Zend_Controller_Action { if ($this->_request->isPost() && ($form->isValid($this->_request->getPost()))) { $ressource->updateAttributes($this->_request->getPost()); if ($ressource->getAlbum()->save() && $ressource->save() && $ressource->receiveFile()) { - $this->_helper->notify(sprintf('Média %s sauvegardé', + $this->_helper->notify(sprintf('Média "%s" sauvegardé', $ressource->getTitre())); $this->_redirect('admin/album/edit_ressource/id/' . $ressource->getId()); diff --git a/library/Class/AlbumRessource.php b/library/Class/AlbumRessource.php index 43a3fcf823a960afd8c78ffde5d66c595b1119ed..c77960cfabac82c7afa6fbdae6b8e5f37f826a76 100644 --- a/library/Class/AlbumRessource.php +++ b/library/Class/AlbumRessource.php @@ -177,7 +177,8 @@ class Class_AlbumRessource extends Storm_Model_Abstract { unlink($oldOriginal); } - unlink($oldThumbnail); + if (file_exists($oldThumbnail)) + @unlink($oldThumbnail); return $this->createThumbnail(); } diff --git a/library/ZendAfi/Form/Album/Ressource.php b/library/ZendAfi/Form/Album/Ressource.php index 1dca6ecb9e66eac237009a474f3952dfb6a624da..111f78b39a437ce82b10e358955ab1a98a88524c 100644 --- a/library/ZendAfi/Form/Album/Ressource.php +++ b/library/ZendAfi/Form/Album/Ressource.php @@ -75,7 +75,14 @@ class ZendAfi_Form_Album_Ressource extends ZendAfi_Form { * @return ZendAfi_Form_Album_Ressource */ public function addFileFor($model) { - return $this->addElement('file', 'fichier', ['label' => 'Fichier']); + $element = new ZendAfi_Form_Element_Image('fichier', ['label' => 'Fichier']); + if ($model) { + $element + ->setBasePath($model->getOriginalsPath()) + ->setBaseUrl($model->getThumbnailsUrl()) + ->setThumbnailUrl($model->getThumbnailUrl()); + } + return $this->addElement($element); } } diff --git a/library/ZendAfi/Form/Element/File.php b/library/ZendAfi/Form/Element/File.php index 81c1267fa2965578e7acf3b15d67b65f1bc7b9b5..8549eaf95506d1b0ebf16f47dc84c006457e11ce 100644 --- a/library/ZendAfi/Form/Element/File.php +++ b/library/ZendAfi/Form/Element/File.php @@ -35,18 +35,29 @@ class ZendAfi_Form_Element_File extends Zend_Form_Element_Xhtml { /** @var string */ protected $_actionUrl; + public function __construct($spec, $options = null) { parent::__construct($spec, $options); + $this->_insertDecoratorsBefore(['File' => new ZendAfi_Form_Decorator_File(), + 'DeleteButton' => new ZendAfi_Form_Decorator_DeleteButton()]); + } + + + /** + * @param $decoratorsToInsert array + */ + protected function _insertDecoratorsBefore($decoratorsToInsert) { + if (!$decoratorsToInsert) + return; + $decorators = $this->_decorators; - $this->_decorators = array('File' => new ZendAfi_Form_Decorator_File(), - 'DeleteButton' => new ZendAfi_Form_Decorator_DeleteButton()); + $this->_decorators = $decoratorsToInsert; - foreach ($decorators as $name => $value) { + foreach ($decorators as $name => $value) $this->_decorators[$name] = $value; - } } - + /** * @param string $path diff --git a/library/ZendAfi/Form/Element/Image.php b/library/ZendAfi/Form/Element/Image.php index ddb9bad58506a776f3bc3363e897b186dd792d64..3deb6130c3b381eed49dc7eb957d6f544893929b 100644 --- a/library/ZendAfi/Form/Element/Image.php +++ b/library/ZendAfi/Form/Element/Image.php @@ -27,11 +27,10 @@ class ZendAfi_Form_Element_Image extends ZendAfi_Form_Element_File { parent::__construct($spec, $options); $decorators = $this->_decorators; - $this->_decorators = array('Image' => new ZendAfi_Form_Decorator_Image()); + $this->_decorators = ['Image' => new ZendAfi_Form_Decorator_Image()]; - foreach ($decorators as $name => $value) { + foreach ($decorators as $name => $value) $this->_decorators[$name] = $value; - } $this->setAutoInsertNotEmptyValidator(false); } diff --git a/tests/library/ZendAfi/Form/Element/FileTest.php b/tests/library/ZendAfi/Form/Element/FileTest.php index 2109674271c0c1ccba72229ea4d32bd2e013cb3f..5f3284ef5a95dd72305c7b6e951a0ff7215bf59c 100644 --- a/tests/library/ZendAfi/Form/Element/FileTest.php +++ b/tests/library/ZendAfi/Form/Element/FileTest.php @@ -19,10 +19,23 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_Form_Element_FileTest extends PHPUnit_Framework_TestCase { + protected $_element; + + public function setUp() { + $this->_element = new ZendAfi_Form_Element_File('fichier'); + } + + /** @test */ public function instanceShouldHaveFileDecorartor() { - $element = new ZendAfi_Form_Element_File('fichier'); $this->assertInstanceOf('ZendAfi_Form_Decorator_File', - $element->getDecorator('File')); + $this->_element->getDecorator('File')); + } + + + /** @test */ + public function instanceShouldHaveLabelDecorator() { + $this->assertInstanceOf('Zend_Form_Decorator_Label', + $this->_element->getDecorator('label')); } } \ No newline at end of file