From 36df4d3e4fdc60bc3d971986030ef127690c8b84 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Wed, 12 Dec 2018 17:10:08 +0100 Subject: [PATCH] dev #64573 wip on articles widget --- library/ZendAfi/Form.php | 14 ++ .../Form/Configuration/Widget/Articles.php | 83 +++++----- .../Form/Configuration/Widget/Base.php | 19 ++- .../Form/Configuration/Widget/Carousel.php | 4 +- library/ZendAfi/Form/Decorator/TreeSelect.php | 3 +- library/ZendAfi/Form/Element/TreeSelect.php | 16 ++ .../Intonation/Assets/css/intonation.css | 2 +- .../Library/View/Wrapper/Article.php | 114 +++++++++++++ .../Library/Widget/AdminTools/View.php | 18 ++- .../Widget/Carousel/Article/Definition.php | 57 +++++++ .../Library/Widget/Carousel/Article/Form.php | 104 ++++++++++++ .../Library/Widget/Carousel/Article/View.php | 152 ++++++++++++++++++ .../Widget/Carousel/Record/Definition.php | 6 +- .../Library/Widget/Carousel/Record/Form.php | 14 +- .../Intonation/Library/Widget/Notify/View.php | 8 +- library/templates/Intonation/Template.php | 2 + .../Intonation/View/RenderCarousel.php | 2 +- tests/scenarios/Templates/TemplatesTest.php | 56 ++++++- 18 files changed, 616 insertions(+), 58 deletions(-) create mode 100644 library/templates/Intonation/Library/View/Wrapper/Article.php create mode 100644 library/templates/Intonation/Library/Widget/Carousel/Article/Definition.php create mode 100644 library/templates/Intonation/Library/Widget/Carousel/Article/Form.php create mode 100644 library/templates/Intonation/Library/Widget/Carousel/Article/View.php diff --git a/library/ZendAfi/Form.php b/library/ZendAfi/Form.php index e107b65de17..298efd3d11f 100644 --- a/library/ZendAfi/Form.php +++ b/library/ZendAfi/Form.php @@ -39,6 +39,12 @@ class ZendAfi_Form extends Zend_Form { } + public function __construct($options = null) { + parent::__construct($options); + $this->initDisplayGroups(); + } + + public function init() { parent::init(); $this @@ -52,6 +58,14 @@ class ZendAfi_Form extends Zend_Form { } + /** We need this hook to be call after init(). + ** Abstract children can place known elements in group + ** before they have been added to the form **/ + public function initDisplayGroups() { + return $this; + } + + public function setDefaults(array $defaults) { foreach ($this->getElements() as $name => $element) if(method_exists($element, 'setDefaults')) diff --git a/library/ZendAfi/Form/Configuration/Widget/Articles.php b/library/ZendAfi/Form/Configuration/Widget/Articles.php index ac188ff4406..cdc58dabd1f 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Articles.php +++ b/library/ZendAfi/Form/Configuration/Widget/Articles.php @@ -24,6 +24,14 @@ class ZendAfi_Form_Configuration_Widget_Articles extends ZendAfi_Form_Configurat public function init() { parent::init(); + Class_ScriptLoader::getInstance() + ->addJQueryReady( + 'radioToggleVisibilityForElement("input[name=\'display_order\']", $("#nb_aff").closest("tr"), ["DateCreationDesc", "DebutPublicationDesc", "EventDebut", "Random", "CommentCount"]);' + + . 'radioToggleVisibilityForElement("input[name=\'display_order\']", $("#nb_analyse").closest("tr"), "Random");' + + . 'checkBoxToggleVisibilityForElement("#allow_link_on_title", $("#anchor").closest("tr"), true);'); + $this ->addElement('url', 'anchor', @@ -55,15 +63,20 @@ class ZendAfi_Form_Configuration_Widget_Articles extends ZendAfi_Form_Configurat ->addElement('imagesViewer', 'style_liste', - ['label' => $this->_('Style de représentation')]); + ['label' => $this->_('Style de représentation')]) - Class_ScriptLoader::getInstance() - ->addJQueryReady( - 'radioToggleVisibilityForElement("input[name=\'display_order\']", $("#nb_aff").closest("tr"), ["DateCreationDesc", "DebutPublicationDesc", "EventDebut", "Random", "CommentCount"]);' + ->addElement('treeSelect', + 'articles_selector') - . 'radioToggleVisibilityForElement("input[name=\'display_order\']", $("#nb_analyse").closest("tr"), "Random");' + ->addToSelectionGroup(['articles_selector']) - . 'checkBoxToggleVisibilityForElement("#allow_link_on_title", $("#anchor").closest("tr"), true);'); + ->addToDisplaySettingsGroup(['display_order', + 'nb_aff', + 'nb_analyse']) + + ->addToStyleGroup(['display_titles_only', + 'allow_link_on_title', + 'anchor']); } @@ -73,38 +86,34 @@ class ZendAfi_Form_Configuration_Widget_Articles extends ZendAfi_Form_Configurat public function populate(array $datas) { - $this->getElement('style_liste') - ->setPreferences($datas); - - $this->addElement('treeSelect', - 'articles_selector', - ['IdItems' => isset($datas['id_items']) ? $datas['id_items'] : '', - 'ItemRenderer' => function($id) - { - if ($model = Class_Article::find($id)) - return $model->getTitre(); - }, - 'IdCategories' => isset($datas['id_categorie']) ? $datas['id_categorie'] : '', - 'CategoryRenderer' => function($id) - { - if ($model = Class_ArticleCategorie::find($id)) - return implode(' > ', $model->getPathParts()); - }, - 'UrlDataSource' => Class_Url::assemble(['module' => 'admin', - 'controller' => 'bib', - 'action' => 'articles', - 'id_bib' => isset($datas['id_bib']) ? $datas['id_bib'] : ''])]) - - ->addToSelectionGroup(['articles_selector']) - - ->addToDisplaySettingsGroup(['display_order', - 'nb_aff', - 'nb_analyse']); + $this->_customPopulate($datas); + return parent::populate($datas); + } - $this->addToStyleGroup(['display_titles_only', - 'allow_link_on_title', - 'anchor']); - return parent::populate($datas); + protected function _customPopulate($datas) { + $this + ->getElement('style_liste') + ->setPreferences($datas); + + $this + ->getElement('articles_selector') + ->setOptions(['IdItems' => isset($datas['id_items']) ? $datas['id_items'] : '', + 'ItemRenderer' => function($id) + { + if ($model = Class_Article::find($id)) + return $model->getTitre(); + }, + 'IdCategories' => isset($datas['id_categorie']) ? $datas['id_categorie'] : '', + 'CategoryRenderer' => function($id) + { + if ($model = Class_ArticleCategorie::find($id)) + return implode(' > ', $model->getPathParts()); + }, + 'UrlDataSource' => Class_Url::assemble(['module' => 'admin', + 'controller' => 'bib', + 'action' => 'articles', + 'id_bib' => isset($datas['id_bib']) ? $datas['id_bib'] : ''])]); + ; } } \ No newline at end of file diff --git a/library/ZendAfi/Form/Configuration/Widget/Base.php b/library/ZendAfi/Form/Configuration/Widget/Base.php index f4c549a047c..412e3ac868e 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Base.php +++ b/library/ZendAfi/Form/Configuration/Widget/Base.php @@ -33,12 +33,8 @@ class ZendAfi_Form_Configuration_Widget_Base extends ZendAfi_Form { ->addElement('select', 'boite', ['label' => $this->_('Style de la boite'), - 'multiOptions' => (new Class_Profil_Templates(Class_Profil::getCurrentProfil()))->toArray()]) + 'multiOptions' => (new Class_Profil_Templates(Class_Profil::getCurrentProfil()))->toArray()]); - ->addToHeadGroup(['titre', - 'style_liste']) - - ->addToStyleGroup(['boite']); if ($this->hasRssSupport()) $this @@ -52,6 +48,19 @@ class ZendAfi_Form_Configuration_Widget_Base extends ZendAfi_Form { } + public function initDisplayGroups() { + parent::initDisplayGroups(); + + $this + ->addToHeadGroup(['titre', + 'style_liste']) + + ->addToStyleGroup(['boite']); + + return $this; + } + + public function hasRssSupport() { return false; } diff --git a/library/ZendAfi/Form/Configuration/Widget/Carousel.php b/library/ZendAfi/Form/Configuration/Widget/Carousel.php index c08dfee0315..375cb4d875f 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Carousel.php +++ b/library/ZendAfi/Form/Configuration/Widget/Carousel.php @@ -82,8 +82,8 @@ class ZendAfi_Form_Configuration_Widget_Carousel extends ZendAfi_Form_Configurat public function populate(array $datas) { - parent::populate($datas); - return $this->_customPopulate($datas); + $this->_customPopulate($datas); + return parent::populate($datas); } diff --git a/library/ZendAfi/Form/Decorator/TreeSelect.php b/library/ZendAfi/Form/Decorator/TreeSelect.php index dfd8498fb3e..c8908ca1848 100644 --- a/library/ZendAfi/Form/Decorator/TreeSelect.php +++ b/library/ZendAfi/Form/Decorator/TreeSelect.php @@ -32,7 +32,8 @@ class ZendAfi_Form_Decorator_TreeSelect extends Zend_Form_Decorator_Abstract { 'InputIdItemsName' => 'id_items', 'IdItems' => $this->_element->getIdItems(), 'IdCategories' => $this->_element->getIdCategories()], - $this->_options); + $this->_options, + $this->_element->getOptions()); $view = $this->_element->getView(); $tree_select = $view->getHelper('TreeSelect'); diff --git a/library/ZendAfi/Form/Element/TreeSelect.php b/library/ZendAfi/Form/Element/TreeSelect.php index bae57f08b03..69c1373519d 100644 --- a/library/ZendAfi/Form/Element/TreeSelect.php +++ b/library/ZendAfi/Form/Element/TreeSelect.php @@ -20,6 +20,10 @@ */ class ZendAfi_Form_Element_TreeSelect extends Zend_Form_Element { + + protected $_options; + + public function __construct($spec, $options = null) { parent::__construct($spec, $options); @@ -33,6 +37,18 @@ class ZendAfi_Form_Element_TreeSelect extends Zend_Form_Element { } + public function setOptions(array $options) { + parent::setOptions($options); + $this->_options = $options; + return $this; + } + + + public function getOptions() { + return $this->_options; + } + + public function getIdItems() { return $this->IdItems; } diff --git a/library/templates/Intonation/Assets/css/intonation.css b/library/templates/Intonation/Assets/css/intonation.css index 13262e1274c..53074cb72e0 100644 --- a/library/templates/Intonation/Assets/css/intonation.css +++ b/library/templates/Intonation/Assets/css/intonation.css @@ -104,7 +104,7 @@ p > i { opacity: 0; } -.min-h-500 { +.min_h_500 { min-height: 500px; } diff --git a/library/templates/Intonation/Library/View/Wrapper/Article.php b/library/templates/Intonation/Library/View/Wrapper/Article.php new file mode 100644 index 00000000000..04837acc659 --- /dev/null +++ b/library/templates/Intonation/Library/View/Wrapper/Article.php @@ -0,0 +1,114 @@ +<?php +/** + * Copyright (c) 2012-2018, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_Library_View_Wrapper_Article { + use Trait_Translator; + + protected + $_view, + $_model; + + + public function setView($view) { + $this->_view = $view; + return $this; + } + + + public function setModel($article) { + $this->_model = $article; + return $this; + } + + + public function getTitle() { + return $this->_model->getTitre(); + } + + + public function getAuthor() { + return $this->_model->getAuthorName(); + } + + + public function getExplicitTitle() { + return $this->_('"%s" de "%s"', + $this->getTitle(), + $this->getAuthor()); + } + + + public function getDocType() { + return $this->_model->getTypeDocId(); + } + + + public function getDocTypeLabel() { + $type_doc = Class_TypeDoc::find($this->getDocType()); + return $type_doc ? $type_doc->getLabel() : '';; + } + + + public function getUrl() { + return $this->_model->getUrl(); + } + + + public function getLinkTitle() { + if ($author = $this->getAuthor()) + return $this->_('Voir l\'article "%s" de "%s"', + $this->getTitle(), + $this->getAuthor()); + + return $this->_('Voir l\'article "%s"', + $this->getTitle()); + } + + + public function getPicture() { + return $this->_model->getFirstImageAbsoluteURL(); + } + + + public function getDescription() { + return $this->_model->getSummary(); + } + + + public function getDescriptionTitle() { + return $this->_('Résumé du document "%s"', $this->getTitle()); + } + + + public function getAuthorIco() { + return Class_Template::current() + ->getIco($this->_view, + 'author', + 'library'); + } + + + public function getAuthorLinkTitle() { + return $this->_('Voir tous les documents de l\'auteur principal "%s"', + $this->getAuthor()); + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/AdminTools/View.php b/library/templates/Intonation/Library/Widget/AdminTools/View.php index c23a0bdd251..0159882d1da 100644 --- a/library/templates/Intonation/Library/Widget/AdminTools/View.php +++ b/library/templates/Intonation/Library/Widget/AdminTools/View.php @@ -22,6 +22,9 @@ class Intonation_Library_Widget_Admintools_View extends Zendafi_View_Helper_Accueil_Base { + protected $_entries; + + public function getHtml() { $this->titre = $this->_settings->getTitre(); $this->contenu = $this->_getHTML(); @@ -30,7 +33,7 @@ class Intonation_Library_Widget_Admintools_View extends Zendafi_View_Helper_Accu protected function _getHTML() { - if (!$entries = $this->view->Admin_FrontNavEntries()) + if (!$entries = $this->_getEntries()) return ''; $html = $this->_tag('div', @@ -65,4 +68,17 @@ class Intonation_Library_Widget_Admintools_View extends Zendafi_View_Helper_Accu 'aria-labelledby' => $id]), ['class' => 'dropdown']); } + + + protected function _getEntries() { + if ($this->_entries) + return $this->_entries; + + return $this->_entries = $this->view->Admin_FrontNavEntries(); + } + + + public function isBoiteVisible() { + return (boolean) $this->_getEntries(); + } } \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/Article/Definition.php b/library/templates/Intonation/Library/Widget/Carousel/Article/Definition.php new file mode 100644 index 00000000000..62839b87250 --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/Article/Definition.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright (c) 2012-2018, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_Library_Widget_Carousel_Article_Definition extends Class_Systeme_ModulesAccueil_Null { + + const + CODE = 'NEWS', + + WALL = 'wall', + CAROUSEL = 'carousel', + MULTIPLE_CAROUSEL = 'multiple_carousel', + + SORT_SELECTION = 'Selection', + SORT_RANDOM = 'Random', + SORT_CREATION_DESC = 'DateCreationDesc', + SORT_PUBLICATION_DESC = 'DebutPublicationDesc', + SORT_EVENT = 'EventDebut', + SORT_COMMENTS = 'CommentCount'; + + + protected + $_group = Class_Systeme_ModulesAccueil::GROUP_INFO, + $_is_phone = false; + + + public function __construct() { + $this->_libelle = $this->_('Boite d\'articles'); + $this->_form = 'Intonation_Library_Widget_Carousel_Article_Form'; + $this->_view_helper = 'Intonation_Library_Widget_Carousel_Article_View'; + $this->_defaultValues = ['titre' => $this->_libelle, + 'display_mode' => static::WALL, + 'rss_avis' => true, + 'embeded_code' => true, + 'link_to_all' => true, + 'order' => static::SORT_RANDOM, + 'nb_aff' => 9]; + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/Article/Form.php b/library/templates/Intonation/Library/Widget/Carousel/Article/Form.php new file mode 100644 index 00000000000..540c853670e --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/Article/Form.php @@ -0,0 +1,104 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_Library_Widget_Carousel_Article_Form extends ZendAfi_Form_Configuration_Widget_Articles { + public function init() { + parent::init(); + + $this + + ->addElement('select', + 'order', + ['label' => $this->_('Ordre des documents'), + 'order' => 1, + 'multiOptions' => [Intonation_Library_Widget_Carousel_Article_Definition::SORT_RANDOM => $this->_('Aléatoire'), + Intonation_Library_Widget_Carousel_Article_Definition::SORT_SELECTION => $this->_('Sélection') + ]]) + + ->addElement('radio', + 'display_mode', + ['label' => $this->_('Mode d\'affichage'), + 'multiOptions' => [Intonation_Library_Widget_Carousel_Article_Definition::WALL => $this->_('Mur'), + Intonation_Library_Widget_Carousel_Article_Definition::CAROUSEL => $this->_('Carousel'), + Intonation_Library_Widget_Carousel_Article_Definition::MULTIPLE_CAROUSEL => $this->_('Carousel à colonnes')]]) + + ->addElement('checkbox', + 'link_to_all', + ['label' => $this->_('Proposer le lien vers tous les articles')]) + + ->addElement('checkbox', + 'embeded_code', + ['label' => $this->_('Proposer le code "embeded"')]) + + ; + + } + + + public function initDisplayGroups() { + parent::initDisplayGroups(); + + $this + ->addToDisplaySettingsGroup(['order', + 'display_mode']) + + ->addToShareGroup(['link_to_all', + 'embeded_code']); + + $this->removeElement('anchor'); + $this->removeElement('allow_link_on_title'); + $this->removeElement('display_order'); + $this->removeElement('nb_analyse'); + $this->removeElement('display_titles_only'); + + $this->removeElement('profil_redirect'); + $this->removeElement('style_liste'); + $this->removeElement('aleatoire'); + + return $this; + } + + + protected function _customPopulate($datas) { + $this + ->getElement('articles_selector') + ->setOptions(['IdItems' => isset($datas['id_items']) ? $datas['id_items'] : '', + 'ItemRenderer' => function($id) + { + if ($model = Class_Article::find($id)) + return $model->getTitre(); + }, + 'IdCategories' => isset($datas['id_categorie']) ? $datas['id_categorie'] : '', + 'CategoryRenderer' => function($id) + { + if ($model = Class_ArticleCategorie::find($id)) + return implode(' > ', $model->getPathParts()); + }, + 'UrlDataSource' => Class_Url::assemble(['module' => 'admin', + 'controller' => 'bib', + 'action' => 'articles', + 'id_bib' => isset($datas['id_bib']) ? $datas['id_bib'] : ''])]); + ; + + return $this; + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/Article/View.php b/library/templates/Intonation/Library/Widget/Carousel/Article/View.php new file mode 100644 index 00000000000..62c08f61c82 --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/Article/View.php @@ -0,0 +1,152 @@ +<?php +/** + * Copyright (c) 2012-2018, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_Library_Widget_Carousel_Article_View extends Zendafi_View_Helper_Accueil_Base { + + public function getHtml() { + $this->titre = $this->_settings->getTitre(); + $this->contenu = $this->_getHTML(); + + return $this->getHtmlArray(); + } + + + public function getFooter() { + $rss = $this->_settings->getRssAvis() + ? $this->_getTagRss() + : ''; + + $embeded = $this->_settings->getEmbededCode() + ? $this->_getTagEmbededCode() + : ''; + + $link_to_all = $this->_settings->getLinkToAll() + ? $this->_getTagLinkToAll() + : ''; + + $html = array_filter([$rss, + $embeded, + $link_to_all]); + + if (empty($html)) + return ''; + + return $this->_tag('div', + implode($html), + ['class' => 'btn-group', + 'role' => 'group']); + } + + + protected function _getTagRss() { + return $this->view->button(new Class_Entity(['Text' => Class_Template::current() + ->getIco($this->view, + 'rss', + 'utils'), + 'Url' => $this->_getUrlFor('rss', 'news'), + 'Attribs' => ['title' => $this->_('Flux RSS de la boite "%s"', $this->titre)]])); + } + + + protected function _getTagEmbededCode() { + $id = 'dropdown_embed_' . $this->getId(); + return $this->_tag('div', + $this->_tag('button', + Class_Template::current()->getIco($this->view, 'embed', 'utils'), + ['class' => 'dropdown-toggle', + 'title' => $this->_('Code IFRAME à copier coller'), + 'id' => $id, + 'data-toggle' => 'dropdown', + 'aria-haspopup' => 'true', + 'aria-expanded' => 'false']) + . $this->_tag('div', + $this->view->tagPre($this->_tag('iframe', + '', + ['src' => $this->view->absoluteUrl([ + 'module' => 'opac', + 'controller' => 'widget', + 'action' => 'render', + 'widget_id' => $this->getId(), + 'profile_id' => Class_Profil::getCurrentProfil()->getId()], + null, + true)]), + ['class' => 'embeded_code']), + ['class' => 'dropdown-menu', + 'aria-labelledby' => $id]), + ['class' => 'btn-group', + 'role' => 'group']); + } + + + protected function _getTagLinkToAll() { + return $this->view->button(new Class_Entity(['Text' => Class_Template::current() + ->getIco($this->view, + 'search_more', + 'library'), + 'Url' => $this->_getSearchUrl(), + 'Attribs' => ['title' => $this->_('Voir les documents de la boite "%s" dans le résultat de recherche', $this->titre)]])); + } + + + protected function _getSearchUrl() { + $url_params = ['module' => 'opac', + 'controller' => 'recherche', + 'action' => 'simple']; + + if ($id = $this->_settings->getIdPanier()) + $url_params ['id_panier'] = $id; + + if ($id = $this->_settings->getIdCatalogue()) + $url_params ['id_catalogue'] = $id; + + return $this->view->url($url_params, null, true); + } + + + protected function _getHTML() { + if (!$articles = $this->_findArticles()) + return $this->_tag('p', $this->_('Aucun document')); + + $articles = array_slice($articles, 0, $this->_settings->getNbNotices()); + $articles = array_map(function($article) + { + return (new Intonation_Library_View_Wrapper_Article) + ->setView($this->view) + ->setModel($article); + }, $articles); + + $articles = new Storm_Collection($articles); + + if (Intonation_Library_Widget_Carousel_Article_Definition::WALL == $this->_settings->getDisplayMode()) + return $this->view->renderWall($articles); + + if (Intonation_Library_Widget_Carousel_Article_Definition::CAROUSEL == $this->_settings->getDisplayMode()) + return $this->view->renderCarousel($articles); + + return $this->view->renderMultipleCarousel($articles); + } + + + protected function _findArticles() { + return Class_Article::getArticlesByPreferences($this->preferences); + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php b/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php index 4e01f28a809..be748f53368 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php @@ -35,13 +35,13 @@ class Intonation_Library_Widget_Carousel_Record_Definition extends Class_Systeme public function __construct() { - $this->_libelle = $this->_('Boite kiosque de notices'); + $this->_libelle = $this->_('Boite de notices'); $this->_form = 'Intonation_Library_Widget_Carousel_Record_Form'; $this->_view_helper = 'Intonation_Library_Widget_Carousel_Record_View'; $this->_defaultValues = ['titre' => $this->_libelle, 'display_mode' => static::WALL, - 'rss_avis' => false, - 'embeded_code' => false, + 'rss_avis' => true, + 'embeded_code' => true, 'link_to_all' => true, 'order' => Class_CriteresRecherche::SORT_RANDOM, 'nb_notices' => 9]; diff --git a/library/templates/Intonation/Library/Widget/Carousel/Record/Form.php b/library/templates/Intonation/Library/Widget/Carousel/Record/Form.php index 235523a94e2..1688e20caa0 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Record/Form.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Record/Form.php @@ -46,8 +46,6 @@ class Intonation_Library_Widget_Carousel_Record_Form extends ZendAfi_Form_Config Intonation_Library_Widget_Carousel_Record_Definition::CAROUSEL => $this->_('Carousel'), Intonation_Library_Widget_Carousel_Record_Definition::MULTIPLE_CAROUSEL => $this->_('Carousel à colonnes')]]) - ->addToDisplaySettingsGroup(['order', - 'display_mode']) ->addElement('checkbox', 'link_to_all', @@ -55,7 +53,15 @@ class Intonation_Library_Widget_Carousel_Record_Form extends ZendAfi_Form_Config ->addElement('checkbox', 'embeded_code', - ['label' => $this->_('Proposer le code "embeded"')]) + ['label' => $this->_('Proposer le code "embeded"')]); + } + + + public function initDisplayGroups() { + parent::initDisplayGroups(); + $this + ->addToDisplaySettingsGroup(['order', + 'display_mode']) ->addToShareGroup(['link_to_all', 'embeded_code']); @@ -66,6 +72,8 @@ class Intonation_Library_Widget_Carousel_Record_Form extends ZendAfi_Form_Config $this->removeElement('profil_redirect'); $this->removeElement('style_liste'); $this->removeElement('aleatoire'); + + return $this; } diff --git a/library/templates/Intonation/Library/Widget/Notify/View.php b/library/templates/Intonation/Library/Widget/Notify/View.php index 795429b37b8..415b6606b76 100644 --- a/library/templates/Intonation/Library/Widget/Notify/View.php +++ b/library/templates/Intonation/Library/Widget/Notify/View.php @@ -55,7 +55,8 @@ $("#%1$s .alert").on("closed.bs.alert", function() { ->setAttribs(['onclick' => '', 'class' => 'close', 'data-dismiss' => 'alert', - 'aria-label' => $this->_('Fermer')])), + 'title' => $this->_('Masquer la notification'), + 'aria-label' => $this->_('Masquer la notification')])), ['role' => 'alert', 'class' => 'alert alert-dismissible ' .$alert->getStatus() . '_notify']); return $html; @@ -74,6 +75,9 @@ $("#%1$s .alert").on("closed.bs.alert", function() { public function isBoiteVisible() { - return (boolean) $this->_getNotifications(); + if (!$collection = $this->_getNotifications()) + return false; + + return !$collection->isEmpty(); } } \ No newline at end of file diff --git a/library/templates/Intonation/Template.php b/library/templates/Intonation/Template.php index 502f058b892..150627c18da 100644 --- a/library/templates/Intonation/Template.php +++ b/library/templates/Intonation/Template.php @@ -137,6 +137,8 @@ class Intonation_Template extends Class_Template { Intonation_Library_Widget_Credits_Definition::CODE => new Intonation_Library_Widget_Credits_Definition, Intonation_Library_Widget_Scroll_Definition::CODE => new Intonation_Library_Widget_Scroll_Definition, Intonation_Library_Widget_Carousel_Record_Definition::CODE => new Intonation_Library_Widget_Carousel_Record_Definition, + + Intonation_Library_Widget_Carousel_Article_Definition::CODE => new Intonation_Library_Widget_Carousel_Article_Definition ]; } diff --git a/library/templates/Intonation/View/RenderCarousel.php b/library/templates/Intonation/View/RenderCarousel.php index 24dd8486bc4..389d77e24c5 100644 --- a/library/templates/Intonation/View/RenderCarousel.php +++ b/library/templates/Intonation/View/RenderCarousel.php @@ -72,7 +72,7 @@ class Intonation_View_RenderCarousel extends ZendAfi_View_Helper_BaseHelper { 'controller' => 'index', 'action' => 'picture', 'url' => $element->getPicture()], null, true), - ['class' => 'min-h-500', + ['class' => 'd-block min_h_500', 'alt' => '']) . $this->_tag('div', diff --git a/tests/scenarios/Templates/TemplatesTest.php b/tests/scenarios/Templates/TemplatesTest.php index a568f3754dc..d5a1c0614ab 100644 --- a/tests/scenarios/Templates/TemplatesTest.php +++ b/tests/scenarios/Templates/TemplatesTest.php @@ -250,6 +250,10 @@ abstract class TemplatesIntonationTestCase extends TemplatesEnabledTestCase { '17' => ['division' => 3, 'type_module' => 'KIOSQUE', 'preferences' => []], + + '18' => ['division' => 3, + 'type_module' => 'NEWS', + 'preferences' => []], ], 'section' => [ '1' => ['boite' => ['ultra_light_widget']]] @@ -1531,7 +1535,7 @@ class TemplateRecordsWidgetWithOptionsTest extends TemplatesIntonationTestCase { public function setUp() { parent::setUp(); - $widget = ((new Class_Systeme_Widget_Widget) + $widget = ((new Class_Systeme_Widget_Widget) ->setId(17) ->setProfileId(72) ->load()); @@ -1594,7 +1598,7 @@ class TemplateRenderWidgetTest extends TemplatesIntonationTestCase { public function dispatchWidgetRenderShouldDisplayContent() { ZendAfi_Auth::getInstance()->clearIdentity(); $this->dispatch('/opac/widget/render/widget_id/17/profile_id/72/', true); - $this->assertXPathContentContains('//div', 'Boite kiosque de notices'); + $this->assertXPathContentContains('//div', 'Boite de notices'); } @@ -1604,4 +1608,52 @@ class TemplateRenderWidgetTest extends TemplatesIntonationTestCase { $this->dispatch('/opac/widget/render/widget_id/17/profile_id/72/', true); $this->assertHTML5(); } +} + + + + +class TemplatesArticlesWidgetTest extends TemplatesIntonationTestCase { + + /** @test */ + public function editArticlesWidgetShouldContainsSelection() { + $this->dispatch('/admin/widget/edit-widget/id/18/id_profil/72', true); + $this->assertXpath('//select[@name="order"]//option[@value="Selection"]'); + } + + + /** @test */ + public function dispatchFrontShouldContainsWinter() { + $widget = ((new Class_Systeme_Widget_Widget) + ->setId(18) + ->setProfileId(72) + ->load()); + $widget + ->setNewDatas(['display_order' => 'Selection', + 'id_items' => '5-6-7', + 'rss_avis' => 1, + 'link_to_all' => 1, + 'embeded_code'=> 1, + 'IntonationShowFooter' => 1, + 'display_mode' => 'multiple_carousel']) + ->updateProfile(); + + $this->fixture('Class_Article', + ['id' => 4, + 'titre' => 'Winter', + 'contenu' => '<p>is ...</p>']); + + $this->fixture('Class_Article', + ['id' => 6, + 'titre' => 'Sprechen Sie Deutsch ?', + 'contenu' => '<p>Ich ...</p>']); + + $this->fixture('Class_Article', + ['id' => 7, + 'titre' => 'Bar', + 'contenu' => '<p>Une b...</p>']); + + $this->dispatch('/opac/index/index/id_profil/72', true); + $this->assertXPath('//a/i[contains(@class, "arrow-circle-up")]'); + } } \ No newline at end of file -- GitLab