diff --git a/.gitattributes b/.gitattributes index b6295f083ae6dce5b7caf0c34dc95040aadaff55..72a63c1dc071e817438d135e5d942329fcb7a460 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1981,6 +1981,7 @@ library/ZendAfi/Filters/ReadSql.php -text library/ZendAfi/Filters/Serialize.php -text library/ZendAfi/Filters/WriteSql.php -text library/ZendAfi/Form.php -text +library/ZendAfi/Form/Album.php -text library/ZendAfi/Form/Decorator/Ckeditor.php -text library/ZendAfi/Form/Decorator/CochesSuggestion.php -text library/ZendAfi/Form/Decorator/DatePicker.php -text diff --git a/application/modules/admin/controllers/AlbumController.php b/application/modules/admin/controllers/AlbumController.php index 381c0a14271d397f4c329f95b7d1a269a672cdf1..fd011801675625f9ceb317d5635ba79d453e06c9 100644 --- a/application/modules/admin/controllers/AlbumController.php +++ b/application/modules/admin/controllers/AlbumController.php @@ -370,108 +370,7 @@ class Admin_AlbumController extends Zend_Controller_Action { * @return Zend_Form */ protected function _albumForm($album) { - $form = $this->view->newForm(['id' => 'album', - 'enctype' => Zend_Form::ENCTYPE_MULTIPART]); - - $vignette_element = new ZendAfi_Form_Element_Image('fichier', - ['label' => 'Vignette<br/><em style="font-size:80%;font-weight:normal">(jpg, gif, png)</em>', - 'escape' => false, - 'basePath' => $album->getBasePath(), - 'baseUrl' => $album->getBaseUrl(), - 'thumbnailUrl' => $album->getThumbnailUrl(), - 'actionUrl' => $this->view->url(['action' => 'album-delete-vignette'])]); - $vignette_element - ->getDecorator('label') - ->setOption('escape', false); - - $form - ->addElement('text', 'titre', ['label' => 'Titre *', - 'size' => 80, - 'required' => true, - 'allowEmpty' => false]) - ->addElement('text', 'sous_titre', ['label' => 'Sous-titre', - 'size' => 80]) - - ->addElement('select', 'cat_id', ['label' => 'Catégorie', - 'multiOptions' => Class_AlbumCategorie::getAllLibelles()]) - ->addElement('checkbox', 'visible', ['label' => $this->_('Visible')]) - ->addElement($vignette_element) - - ->addElement(new ZendAfi_Form_Element_File('pdf', - [ 'label' => 'Album PDF', - 'escape' => false, - 'basePath' => $album->getBasePath(), - 'baseUrl' => $album->getBaseUrl(), - 'actionUrl' => $this->view->url(['action' => 'album-delete-pdf'])])) - - ->addElement('text', 'auteur', ['label' => 'Auteur', - 'size' => 80]) - - ->addElement('ckeditor', 'description') - - ->addElement('text', 'annee', ['label' => "Année d'édition", - 'size' => 4, - 'maxlength' => 4]) - - ->addElement('text', 'editeur', ['label' => 'Editeur', - 'size' => 80]) - - ->addElement('text', 'cote', ['label' => 'Cote', - 'size' => 20]) - - ->addElement('text', 'provenance', ['label' => 'Provenance', - 'size' => 80]) - - ->addElement('select', 'id_langue', ['label' => 'Langue', - 'multioptions' => Class_CodifLangue::allByIdLibelle()]) - - ->addElement('select', 'type_doc_id', ['label' => 'Type de document', - 'multioptions' => Class_TypeDoc::allByIdLabelForAlbum()]) - - ->addElement('listeSuggestion', 'matiere', - ['label' => 'Matières / sujets', - 'name' => 'matiere', - 'rubrique' => 'matiere']) - - ->addElement('listeSuggestion', 'dewey', ['label' => 'Indices dewey', - 'name' => 'dewey', - 'rubrique' => 'dewey']) - - ->addElement('cochesSuggestion', 'genre', ['label' => 'Genres', - 'name' => 'genre', - 'rubrique' => 'genre']) - - ->addElement('textarea', 'tags', ['label' => 'Tags', - 'rows' => 2]) - ->addDisplayGroup(['titre', - 'sous_titre', - 'cat_id', - 'visible', - 'fichier', - 'pdf'], - 'album', - ["legend" => "Album"]) - - ->addDisplayGroup(['description'], - 'album_desc', - ["legend" => "Description"]) - - ->addDisplayGroup(['auteur', - 'annee', - 'editeur', - 'provenance', - 'id_langue', - 'type_doc_id', - 'cote', - 'matiere', - 'dewey', - 'genre', - 'tags'], - 'album_metadata', - ["legend" => "Metadonnées"]) - ->populate($album->toArray()); - - return $form; + return ZendAfi_Form_Album::newWith($album); } @@ -538,7 +437,11 @@ class Admin_AlbumController extends Zend_Controller_Action { unset($values['fichier']); unset($values['pdf']); + $video_url = $values['video_url']; + unset($values['video_url']); $album->updateAttributes($values); + $album->setVideoUrl($video_url); + if ($album->save() && $album->receiveFile() && $album->receivePDF()) { $this->_helper->notify('Album sauvegardé'); diff --git a/library/Class/Album.php b/library/Class/Album.php index 40b505ed6e8a9b2db7367eff74d2752aa241bb19..07dad2af475fce76f231040b2f69d413c3f2b341 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -68,6 +68,9 @@ class Class_Album extends Storm_Model_Abstract { const ORIGINAL_PATH = 'big/'; const ANNEE_MIN = 800; const DEFAULT_CODE_LANGUE = 'fre'; + const VIDEO_URL_FIELD = '856'; + const VIDEO_URL_TYPE = 'video'; + protected static $DEFAULT_THUMBNAIL_VALUES; @@ -886,6 +889,47 @@ class Class_Album extends Storm_Model_Abstract { } + /** + * @param $field string + * @param $datas array + */ + public function getNoteForFieldAndDatas($field, $datas = []) { + $notes = $this->getNotesAsArray(); + + foreach ($notes as $note) { + if (!array_key_exists('field', $note) + or !array_key_exists('data', $note) + or $field != $note['field']) + continue; + + foreach ($datas as $k => $v) { + if ($note['data'][$k] != $v) + continue 2; + } + + return $note['data']['a']; + } + } + + + /** @return string */ + public function getVideoUrl() { + return $this->getNoteForFieldAndDatas(self::VIDEO_URL_FIELD, + ['x' => self::VIDEO_URL_TYPE]); + } + + + /** + * @param $url string + * @return Class_Album + */ + public function setVideoUrl($url) { + return $this->setNotes([[ + 'field' => self::VIDEO_URL_FIELD, + 'data' => ['x' => self::VIDEO_URL_TYPE, 'a' => $url]]]); + } + + public function setNotes($array_or_string) { if (is_array($array_or_string)) parent::setNotes(serialize($array_or_string)); diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php index 2b3617a7fae902a9240d76fe9924ccfad79b14a6..1046ca59461d1de3d9f91bedf414fd7bf64c93d0 100644 --- a/library/Class/TypeDoc.php +++ b/library/Class/TypeDoc.php @@ -125,6 +125,7 @@ class Class_TypeDoc extends Storm_Model_Abstract { const EPUB = 102; const OAI = 103; const ARTEVOD = 104; + const STREAMING_VIDEO = 105; public static function getDefaultTypeDocs() { @@ -132,7 +133,8 @@ class Class_TypeDoc extends Storm_Model_Abstract { self::DIAPORAMA => 'Diaporamas', self::EPUB => 'E-Books', self::OAI => 'OAI', - self::ARTEVOD => 'Arte VOD'); + self::ARTEVOD => 'Arte VOD', + self::STREAMING_VIDEO => 'Vidéo en ligne'); } diff --git a/library/ZendAfi/Form/Album.php b/library/ZendAfi/Form/Album.php new file mode 100644 index 0000000000000000000000000000000000000000..4c513de57e1fd08b3c7cf8c5ce02960fe6121d71 --- /dev/null +++ b/library/ZendAfi/Form/Album.php @@ -0,0 +1,183 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_Form_Album extends ZendAfi_Form { + use Trait_Translator; + + public static function newWith($album) { + $form = new self(); + + $form + ->populate($album->toArray()) + ->addVignetteFor($album) + ->addFileFor($album) + ->addVideoUrlFor($album) + ->addDisplayGroup(['titre', + 'sous_titre', + 'cat_id', + 'visible', + 'fichier', + 'pdf'], + 'album', + ["legend" => "Album"]) + + ->addDisplayGroup(['description'], + 'album_desc', + ["legend" => "Description"]) + + ->addDisplayGroup(['auteur', + 'annee', + 'editeur', + 'provenance', + 'id_langue', + 'type_doc_id', + 'video_url', + 'cote', + 'matiere', + 'dewey', + 'genre', + 'tags'], + 'album_metadata', + ["legend" => $form->_("Metadonnées")]); + + return $form; + } + + + public function init() { + parent::init(); + $this + ->setAttrib('id', 'album') + ->setAttrib('enctype', self::ENCTYPE_MULTIPART) + ->addElement('text', 'titre', ['label' => 'Titre *', + 'size' => 80, + 'required' => true, + 'allowEmpty' => false]) + + ->addElement('text', 'sous_titre', ['label' => 'Sous-titre', + 'size' => 80]) + + ->addElement('select', 'cat_id', ['label' => 'Catégorie', + 'multiOptions' => Class_AlbumCategorie::getAllLibelles()]) + ->addElement('checkbox', 'visible', ['label' => 'Visible']) + + ->addElement('text', 'auteur', ['label' => 'Auteur', + 'size' => 80]) + + ->addElement('ckeditor', 'description') + + ->addElement('text', 'annee', ['label' => "Année d'édition", + 'size' => 4, + 'maxlength' => 4]) + + ->addElement('text', 'editeur', ['label' => 'Editeur', + 'size' => 80]) + + ->addElement('text', 'cote', ['label' => 'Cote', + 'size' => 20]) + + ->addElement('text', 'provenance', ['label' => 'Provenance', + 'size' => 80]) + + ->addElement('select', 'id_langue', ['label' => 'Langue', + 'multioptions' => Class_CodifLangue::allByIdLibelle()]) + + ->addElement('select', 'type_doc_id', ['label' => 'Type de document', + 'multioptions' => Class_TypeDoc::allByIdLabelForAlbum(), + 'onchange' => 'toggleAlbumVideoUrl();']) + + ->addElement('listeSuggestion', 'matiere', + ['label' => 'Matières / sujets', + 'name' => 'matiere', + 'rubrique' => 'matiere']) + + ->addElement('listeSuggestion', 'dewey', ['label' => 'Indices dewey', + 'name' => 'dewey', + 'rubrique' => 'dewey']) + + ->addElement('cochesSuggestion', 'genre', ['label' => 'Genres', + 'name' => 'genre', + 'rubrique' => 'genre']) + + ->addElement('textarea', 'tags', ['label' => 'Tags', + 'rows' => 2]); + + Class_ScriptLoader::getInstance() + ->addInlineScript("function toggleAlbumVideoUrl() { + if ('" . Class_TypeDoc::STREAMING_VIDEO . "' == \$('#type_doc_id').val()) { + $('#video_url').parents('tr').show(); + return true; + } + $('#video_url').parents('tr').hide();}") + ->addJQueryReady('toggleAlbumVideoUrl();'); + + } + + + /** + * @param $album Class_Album + * @return ZendAfi_Form_Album + */ + public function addVignetteFor($album) { + $vignette_element = new ZendAfi_Form_Element_Image( + 'fichier', + ['label' => 'Vignette<br/><em style="font-size:80%;font-weight:normal">(jpg, gif, png)</em>', + 'escape' => false, + 'basePath' => $album->getBasePath(), + 'baseUrl' => $album->getBaseUrl(), + 'thumbnailUrl' => $album->getThumbnailUrl(), + 'actionUrl' => $this->getView()->url(['action' => 'album-delete-vignette'])]); + + $vignette_element + ->getDecorator('label') + ->setOption('escape', false); + + return $this->addElement($vignette_element); + } + + + /** + * @param $album Class_Album + * @return ZendAfi_Form_Album + */ + public function addFileFor($album) { + return $this->addElement(new ZendAfi_Form_Element_File('pdf', + [ 'label' => 'Album PDF', + 'escape' => false, + 'basePath' => $album->getBasePath(), + 'baseUrl' => $album->getBaseUrl(), + 'actionUrl' => $this->getView()->url(['action' => 'album-delete-pdf'])])); + } + + + /** + * @param $album Class_Album + * @return ZendAfi_Form_Album + */ + public function addVideoUrlFor($album) { + return $this->addElement('text', 'video_url', + ['label' => 'Adresse de la vidéo', + 'size' => 80, + 'value' => $album->getVideoUrl()]); + } +} + +?> \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php index 7032ca483a2bfd8914b20aab4084681f961cd819..fff1b9942f2b9e386cbe5c1b230d03d2563621c5 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php @@ -637,9 +637,10 @@ class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTest extends Admin_Al public function setUp() { parent::setUp(); - $data = array('titre' => 'Renaissance', - 'sous_titre' => 'Ze Renaissance', - 'description' => 'Oeuvres majeures sous François 1er'); + $data = ['titre' => 'Renaissance', + 'sous_titre' => 'Ze Renaissance', + 'description' => 'Oeuvres majeures sous François 1er', + 'video_url' => 'http://www.youtube.com/watch?v=FqXYGBZooHg&feature=html5_ns&list=UUzfAMGBG12oxX7dSYAurMGA&playnext=1']; $this ->getRequest() @@ -691,6 +692,20 @@ class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTest extends Admin_Al } + /** @test */ + public function newAlbumNotesShouldContainVideoUrl() { + $this->assertEquals('http://www.youtube.com/watch?v=FqXYGBZooHg&feature=html5_ns&list=UUzfAMGBG12oxX7dSYAurMGA&playnext=1', + $this->new_album->getNotesAsArray()[0]['data']['a']); + } + + + /** @test */ + public function newAlbumNotesShouldContainVideoType() { + $this->assertEquals('video', + $this->new_album->getNotesAsArray()[0]['data']['x']); + } + + /** @test */ public function shouldRedirectToEditAlbum() { $this->assertRedirectTo('/admin/album/edit_album/id/67'); @@ -874,6 +889,12 @@ class Admin_AlbumControllerEditAlbumMesBDTest extends Admin_AlbumControllerTestC } + /** @test */ + public function formShouldHaveAInputForVideoUrl() { + $this->assertXPath('//input[@type="text"][@name="video_url"]'); + } + + /** @test */ function formShouldHaveTagSuggestForMatiere() { $this->assertXPath("//input[@name='matiere'][@value='1;3;5']"); @@ -911,7 +932,10 @@ class Admin_AlbumControllerEditAlbumMesRomans extends Admin_AlbumControllerTestC Class_Album::getLoader() ->newInstanceWithId(24) ->setTitre('Mes Romans') - ->setLangue(''); + ->setLangue('') + ->setNotes([['field' => 856, + 'data' => ['x' => 'video', + 'a' => 'http://www.youtube.com/watch?v=FqXYGBZooHg&feature=html5_ns&list=UUzfAMGBG12oxX7dSYAurMGA&playnext=1']]]); $this->dispatch('/admin/album/edit_album/id/24'); } @@ -930,6 +954,12 @@ class Admin_AlbumControllerEditAlbumMesRomans extends Admin_AlbumControllerTestC $this->assertXPathContentContains("//select[@name='id_langue']//option[@value='dak']", 'dakota'); } + + + /** @test */ + public function formShouldHaveVideoUrlAsExpected() { + $this->assertXPath('//input[@name="video_url"][@value="http://www.youtube.com/watch?v=FqXYGBZooHg&feature=html5_ns&list=UUzfAMGBG12oxX7dSYAurMGA&playnext=1"]'); + } } diff --git a/tests/library/Class/TypeDocTest.php b/tests/library/Class/TypeDocTest.php index ff805ef8e4d27feaa82fc642474a10791c3a4ab9..64aade08de4f5eb7113b9b6ad02cf2bea370e5ea 100644 --- a/tests/library/Class/TypeDocTest.php +++ b/tests/library/Class/TypeDocTest.php @@ -35,7 +35,7 @@ class TypeDocTest extends PHPUnit_Framework_TestCase { /** @test */ function instancesCountShouldBeHeight() { - $this->assertEquals(8, count($this->types_docs)); + $this->assertEquals(9, count($this->types_docs)); } @@ -67,7 +67,7 @@ class TypeDocTest extends PHPUnit_Framework_TestCase { function saveNewInstanceVideoShouldUpdateTypesDocsVars() { Class_TypeDoc::newWithLabel('videos')->save(); - $this->assertEquals("0:non identifié\r\n1:livres\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:videos", + $this->assertEquals("0:non identifié\r\n1:livres\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:Vidéo en ligne\r\n106:videos", $this->cosmo_types->getListe()); } @@ -78,7 +78,7 @@ class TypeDocTest extends PHPUnit_Framework_TestCase { ->setLabel('journaux') ->save(); - $this->assertEquals("0:non identifié\r\n1:livres\r\n2:journaux\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD", + $this->assertEquals("0:non identifié\r\n1:livres\r\n2:journaux\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:Vidéo en ligne", $this->cosmo_types->getListe(), 'Current value: '.$this->cosmo_types->getListe()); } @@ -96,7 +96,7 @@ class TypeDocTest extends PHPUnit_Framework_TestCase { ->setLabel('CD') ->save(); - $this->assertEquals("0:non identifié\r\n1:livres\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:videos\r\n106:CD", + $this->assertEquals("0:non identifié\r\n1:livres\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:Vidéo en ligne\r\n106:videos\r\n107:CD", $this->cosmo_types->getListe(), 'Current value: '.$this->cosmo_types->getListe()); } @@ -106,7 +106,7 @@ class TypeDocTest extends PHPUnit_Framework_TestCase { function deleteLivresShouldUpdateTypesDocsVar() { array_at(1, $this->types_docs)->delete(); - $this->assertEquals("0:non identifié\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD", + $this->assertEquals("0:non identifié\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:Vidéo en ligne", $this->cosmo_types->getListe()); } @@ -114,14 +114,15 @@ class TypeDocTest extends PHPUnit_Framework_TestCase { /** @test */ function typeDocToIdLabelArrayShouldAnswerAssociativeArray() { $array = Class_TypeDoc::toIdLabelArray(Class_TypeDoc::getLoader()->findAll()); - $this->assertEquals($array, array(0 => 'non identifié', - 1 => 'livres', - 2 => 'périodiques', - 100 => 'Livres numérisés', - 101 => 'Diaporamas', - 102 => 'E-Books', - 103 => 'OAI', - 104 => 'Arte VOD')); + $this->assertEquals($array, [0 => 'non identifié', + 1 => 'livres', + 2 => 'périodiques', + 100 => 'Livres numérisés', + 101 => 'Diaporamas', + 102 => 'E-Books', + 103 => 'OAI', + 104 => 'Arte VOD', + 105 => 'Vidéo en ligne']); }