From 6b91c32318c496902f19c118167d9905147befd8 Mon Sep 17 00:00:00 2001 From: lbrun <leo@sandbox.pergame.net> Date: Mon, 22 Feb 2016 15:13:33 +0100 Subject: [PATCH] dev#37281 : refacto bibnum view helper (strategy) --- VERSIONS_WIP/37281 | 1 + .../ModulesAccueil/BibliothequeNumerique.php | 18 +- .../View/Helper/Accueil/BibNumerique.php | 207 +++++++++++++----- 3 files changed, 160 insertions(+), 66 deletions(-) create mode 100644 VERSIONS_WIP/37281 diff --git a/VERSIONS_WIP/37281 b/VERSIONS_WIP/37281 new file mode 100644 index 00000000000..c028a7bb08c --- /dev/null +++ b/VERSIONS_WIP/37281 @@ -0,0 +1 @@ + - ticket #37281 : Configuration : Boite bibliothèque numérique : Possibilite d'affichage pagine \ No newline at end of file diff --git a/library/Class/Systeme/ModulesAccueil/BibliothequeNumerique.php b/library/Class/Systeme/ModulesAccueil/BibliothequeNumerique.php index ba826582ae3..fd875ca35c3 100644 --- a/library/Class/Systeme/ModulesAccueil/BibliothequeNumerique.php +++ b/library/Class/Systeme/ModulesAccueil/BibliothequeNumerique.php @@ -16,26 +16,30 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_Systeme_ModulesAccueil_BibliothequeNumerique extends Class_Systeme_ModulesAccueil_Null { const DISPLAY_TREE = 'displayTree'; const DISPLAY_ALBUM_TEASER = 'displayAlbumTeaser'; + const DISPLAY_PAGINATED = 'displayPaginated'; const ORDER_RESPECT = 'orderRespect'; const ORDER_RANDOM = 'orderRandom'; + const ORDER_RECENT = 'orderRecent'; /** @var array */ - protected $_displayModes = array(self::DISPLAY_TREE => 'Arborescence', - self::DISPLAY_ALBUM_TEASER => 'Mise en avant d\'un album'); + protected $_displayModes = [self::DISPLAY_TREE => 'Arborescence', + self::DISPLAY_ALBUM_TEASER => 'Mise en avant d\'un album', + self::DISPLAY_PAGINATED => 'Affichage paginé']; /** @var array */ - protected $_orderModes = array(self::ORDER_RESPECT => 'Respecter l\'ordre', - self::ORDER_RANDOM => 'Aléatoire'); + protected $_orderModes = [self::ORDER_RESPECT => 'Respecter l\'ordre', + self::ORDER_RANDOM => 'Aléatoire', + self::ORDER_RECENT => 'Les plus récents']; /** @var string */ protected $_group = Class_Systeme_ModulesAccueil::GROUP_INFO; - + /** @var string */ protected $_libelle = 'Bibliothèque numérique'; @@ -66,7 +70,7 @@ class Class_Systeme_ModulesAccueil_BibliothequeNumerique extends Class_Systeme_M return $this->_displayModes; } - + /** @return array */ public function getOrderModes() { return $this->_orderModes; diff --git a/library/ZendAfi/View/Helper/Accueil/BibNumerique.php b/library/ZendAfi/View/Helper/Accueil/BibNumerique.php index 2a4998620c5..51ca682567d 100644 --- a/library/ZendAfi/View/Helper/Accueil/BibNumerique.php +++ b/library/ZendAfi/View/Helper/Accueil/BibNumerique.php @@ -19,99 +19,188 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_Accueil_BibNumerique extends ZendAfi_View_Helper_Accueil_Base { - protected $_slideshow; + protected $_slideshow, $strategy; + public function __construct($id_module,$params) { parent::__construct($id_module,$params); - $this->preferences = array_merge(array('id_albums' => ''), - $this->preferences); + $this->preferences = array_merge(['id_albums' => ''], $this->preferences); } - public function displayNumericRessources() { - if (!$album = Class_Album::getLoader()->find((int)$this->preferences['id_albums'])) - return false; - if ($album->getImages()) - return false; - $html=$this->view->renderAlbum($album); - return $html; + + protected function _renderHeadScriptsOn($script_loader) { + if (!array_isset('id_albums', $this->preferences)) + return $this; + + if ($this->isDisplayDiaporama()) + $this->getSlideshow()->renderSlideShowScripts(); + + if ($this->isDisplayBooklet()) + Class_ScriptLoader::getInstance()->loadBooklet($this->preferences['id_albums'], + '#booklet_'.$this->id_module); + } + + + public function getHtml() { + $strategy = $this->getStrategy(); + $this->titre = $strategy->getTitle(); + $this->contenu = $strategy->getContent(); + + return $this->getHtmlArray(); } + public function getStrategy() { + if ($this->strategy) + return $this->strategy; + + $strategy = new BibNumPaginatedStrategy(); + + if ($this->isAlbumTeaserDisplay()) + $strategy = new BibNumAlbumTeaserStrategy(); + + if ($this->isTreeDisplay()) + $strategy = new BibNumTreeStrategy(); + + $this->strategy = $strategy->setView($this->view) + ->setAccueilBibnum($this) + ->setIdModule($this->id_module) + ->setPreferences($this->preferences); + + return $this->strategy; + } + + + public function isPaginatedDisplay() { + return $this->_isDisplayType(Class_Systeme_ModulesAccueil_BibliothequeNumerique::DISPLAY_PAGINATED); + } + + + public function isAlbumTeaserDisplay() { + return $this->_isDisplayType(Class_Systeme_ModulesAccueil_BibliothequeNumerique::DISPLAY_ALBUM_TEASER); + } + + + public function isTreeDisplay() { + return $this->_isDisplayType(Class_Systeme_ModulesAccueil_BibliothequeNumerique::DISPLAY_TREE); + } + + + protected function _isDisplayType($type) { + return $this->getPreference('type_aff') == $type; + } + + public function getSlideshow() { - if (!isset($this->_slideshow)) { - $album = Class_Album::getLoader()->find((int)$this->preferences['id_albums']); - $this->_slideshow = $this->view->getHelper('TagSlideshow') - ->setAlbum($album) - ->setPreferences($this->preferences); - } + if (isset($this->_slideshow)) + return $this->_slideshow; + + $album = Class_Album::getLoader()->find((int)$this->preferences['id_albums']); + $this->_slideshow = $this->view->getHelper('TagSlideshow') + ->setAlbum($album) + ->setPreferences($this->preferences); return $this->_slideshow; } +} - public function getTreeRenderer() { - return new ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer($this->view, $this->preferences); + +class BibNumDisplayStrategy { + protected + $view, + $id_module, + $preferences, + $accueil_bibnum; + + + public function setView($view) { + $this->view = $view; + return $this; } - protected function _renderHeadScriptsOn($script_loader) { - if (!array_isset('id_albums', $this->preferences)) - return $this; + public function setPreferences($preferences) { + $this->preferences = $preferences; + return $this; + } - if ($this->isDisplayDiaporama()) - $this->getSlideshow()->renderSlideShowScripts(); - if ($this->isDisplayBooklet()) - Class_ScriptLoader::getInstance()->loadBooklet($this->preferences['id_albums'], - '#booklet_'.$this->id_module); + public function setAccueilBibnum($accueil_bibnum) { + $this->accueil_bibnum = $accueil_bibnum; + return $this; } - public function isDisplayAlbumTeaser() { - return $this->preferences['type_aff'] == Class_Systeme_ModulesAccueil_BibliothequeNumerique::DISPLAY_ALBUM_TEASER; + public function setIdModule($id_module) { + $this->id_module = $id_module; + return $this; + } + + + public function getTitle() { + return $this->preferences['titre']; } +} + - /** @return array */ - public function getHTML() { - $this->titre = $this->preferences['titre']; - if ($this->isDisplayAlbumTeaser()) - $this->_renderAlbumTeaser(); + +class BibNumAlbumTeaserStrategy extends BibNumDisplayStrategy { + public function getContent() { + $contenu = $this->displayNumericRessources(); + + if ($contenu) + return $contenu; + + if ($this->accueil_bibnum->isDisplayDiaporama() or $this->accueil_bibnum->isDisplayListe()) + $contenu .= $this->accueil_bibnum->getSlideshow()->renderAlbumMedias(); else - $this->_renderTree(); + $contenu .= sprintf('<div id="booklet_%d" class="bib-num-album"></div>', $this->id_module); - return $this->getHtmlArray(); + return $contenu; } - /** - * @return ZendAfi_View_Helper_Accueil_BibNumerique - */ - public function _renderAlbumTeaser() { - if ($this->contenu = $this->displayNumericRessources()) - return $this; - if ($this->isDisplayDiaporama() or $this->isDisplayListe()) { - $this->contenu .= $this->getSlideshow()->renderAlbumMedias(); - } else { - $this->contenu .= sprintf('<div id="booklet_%d" class="bib-num-album"></div>', - $this->id_module); - - $this->titre = $this->view->tagAnchor(array('controller' => 'bib-numerique', - 'action' => 'booklet', - 'id' => $this->preferences['id_albums']), - $this->titre); - } + public function getTitle() { + return $this->view->tagAnchor(['controller' => 'bib-numerique', + 'action' => 'booklet', + 'id' => $this->preferences['id_albums']], + $this->preferences['titre']); + } - return $this; + + public function displayNumericRessources() { + if (!$album = Class_Album::getLoader()->find((int)$this->preferences['id_albums'])) + return false; + + if ($album->getImages()) + return false; + + $html = $this->view->renderAlbum($album); + + return $html; } +} - /** - * @return ZendAfi_View_Helper_Accueil_BibNumerique - */ - protected function _renderTree() { - $this->contenu = $this->getTreeRenderer()->render(); - return $this; + + +class BibNumTreeStrategy extends BibNumDisplayStrategy { + public function getContent() { + return $this->_getTreeRenderer()->render(); + } + + protected function _getTreeRenderer() { + return new ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer($this->view, $this->preferences); } } + + + +class BibNumPaginatedStrategy extends BibNumDisplayStrategy { + public function getContent() { + return 'LOL'; + } +} ?> \ No newline at end of file -- GitLab