diff --git a/VERSIONS_HOTLINE/132300 b/VERSIONS_HOTLINE/132300 new file mode 100644 index 0000000000000000000000000000000000000000..62d26ee41936baf8306229eec3d93e55677a708a --- /dev/null +++ b/VERSIONS_HOTLINE/132300 @@ -0,0 +1 @@ + - ticket #132300 : Magasin de thèmes : Amélioration de la boite sitothèque et correction de l'affichage des sitothèques en provenance des liens de menus. \ No newline at end of file diff --git a/application/modules/opac/views/scripts/sito/viewsitos.phtml b/application/modules/opac/views/scripts/sito/viewsitos.phtml index b6dfdf7c713bd7447b2dea0a7b35fdceec90663e..bcd08cd4aed05f7f8e640d8561db75b60170f40f 100644 --- a/application/modules/opac/views/scripts/sito/viewsitos.phtml +++ b/application/modules/opac/views/scripts/sito/viewsitos.phtml @@ -1,18 +1,2 @@ -<?php -foreach($this->sitos as $sito) { - $thumb_url = $this->webThumbnail($sito->getUrl()); - - $this->openBoite($sito->getTitre()); - echo "<div class='sitotheque'>"; - - if ($thumb_url) - printf('<img src="%s">', $thumb_url); - - echo $sito->getDescription(); - - printf('<div><a href="%s" target="_blank">%s</a></div>', $sito->getUrl(), $this->_('Voir le site')); - $this->closeBoite(); - - echo "</div>"; -} -?> +<?php +echo $this->renderWebsites($this->sitos); diff --git a/library/Class/Sitotheque.php b/library/Class/Sitotheque.php index 328ce32615d971d90ee3867a45376c543bef15de..0827336611081cd27de7364844e1356153fcca1c 100644 --- a/library/Class/Sitotheque.php +++ b/library/Class/Sitotheque.php @@ -188,9 +188,6 @@ class Class_Sitotheque extends Storm_Model_Abstract { } - //------------------------------------------------------------------------------------------------------ - // Get site - //------------------------------------------------------------------------------------------------------ public function getSite($id_site) { if(!$id_site) return false; @@ -210,14 +207,15 @@ class Class_Sitotheque extends Storm_Model_Abstract { return ''; } - //------------------------------------------------------------------------------------------------------ - // Renvoie tous les articles pour une categorie et ses sous-categories - //------------------------------------------------------------------------------------------------------ + public function getSitesCategorie($id_categorie) { - if(!$id_categorie) return array(); + if ( ! $id_categorie) + return []; + if ( ! $category = Class_SitothequeCategorie::find($id_categorie)) + return []; - $categories = Class_SitothequeCategorie::find($id_categorie)->getRecursiveSousCategories(); + $categories = $category->getRecursiveSousCategories(); $ids = array_map(function($categorie) {return $categorie->getId();}, $categories); diff --git a/library/ZendAfi/View/Helper/RenderWebsites.php b/library/ZendAfi/View/Helper/RenderWebsites.php new file mode 100644 index 0000000000000000000000000000000000000000..89d3970e01e54925d439a04323c04ff08de4464a --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderWebsites.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright (c) 2012-2021, 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 ZendAfi_View_Helper_RenderWebsites extends ZendAfi_View_Helper_BaseHelper { + public function renderWebsites($websites) { + $html = []; + foreach($websites as $website) { + $html [] = $this->view->openBoiteContent($website->getTitre()); + + $html [] = $this->_div(['class' => 'sitotheque'], $this->_websiteHtml($website)); + + $html [] = $this->view->closeBoiteContent(); + } + + return implode($html); + } + + + protected function _websiteHtml($website) { + $img = ''; + if ($thumb_url = $this->view->webThumbnail($website->getUrl())) + $img = $this->view->tagImg($thumb_url); + + return $img + . $website->getDescription() + . $this->_div([], + $this->view->tagAnchor($website->getUrl(), + $this->_('Voir le site'))); + } +} diff --git a/library/templates/Intonation/Library/AjaxPaginatedListHelper.php b/library/templates/Intonation/Library/AjaxPaginatedListHelper.php index 1863fde497c522356daffbb1c60eedf31432ecfe..413af52f9c1417d3e45732820b4efe80c3febad5 100644 --- a/library/templates/Intonation/Library/AjaxPaginatedListHelper.php +++ b/library/templates/Intonation/Library/AjaxPaginatedListHelper.php @@ -135,7 +135,7 @@ class Intonation_Library_AjaxPaginatedListHelper { $slice = function($collection) use ($page) { $sub = array_slice($collection->getArrayCopy(), (($page - 1) * $this->_page_size), - ($page * $this->_page_size)); + $this->_page_size); return $this->_page = new Storm_Collection($sub); }; diff --git a/library/templates/Intonation/Library/Settings.php b/library/templates/Intonation/Library/Settings.php index 3a61973ae2c4a2c82cff989e5f6be806065cb102..1f72f536c48b2280d320311ad8fbf5f1524f061d 100644 --- a/library/templates/Intonation/Library/Settings.php +++ b/library/templates/Intonation/Library/Settings.php @@ -297,6 +297,11 @@ class Intonation_Library_Settings extends Intonation_System_Abstract { 'form class user_configuration_form' => 'form row no-gutters', 'a class manage_activities_button' => 'btn btn-sm btn-success menu_admin_front_anchor', 'input class zendafi_form_review_review_submit' => 'ml-auto mr-auto mt-3', + 'button class accordion_button' => 'btn btn-link', + 'div class collection_actions' => 'col-12', + 'div class collection_truncate_list' => 'col-12', + 'div class websites_list_title' => 'col-12', + 'div class websites_list_content' => 'col-12', ], 'icons_map_doc_types' => [], diff --git a/library/templates/Intonation/Library/View/Wrapper/Website.php b/library/templates/Intonation/Library/View/Wrapper/Website.php index 9a87c501ddaa648870dfe2b13cec5f673e215df6..775f8d59b48394f3df37e7e30fef7bc5697afe81 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Website.php +++ b/library/templates/Intonation/Library/View/Wrapper/Website.php @@ -22,6 +22,23 @@ class Intonation_Library_View_Wrapper_Website extends Intonation_Library_View_Wrapper_Abstract { + protected $_title, + $_picture, + $_description; + + + public function __sleep() { + $this->_title = $this->getMainTitle(); + $this->_picture = $this->getPicture(); + $this->_description = $this->getDescription(); + + return array_merge(parent::__sleep(), + ['_title', + '_picture', + '_description']); + } + + public function getMainTitle() { return $this->_model->getTitle(); } diff --git a/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery.php b/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery.php index 63746010e52013ad74a12d6d85439d485fab6d91..c48485789a75dc42c7a114c902cb6184551fa218 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery.php +++ b/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery.php @@ -22,123 +22,11 @@ class Intonation_Library_View_Wrapper_Website_Smeltery { public function meltWebsite($website) { - return new Intonation_Library_View_Wrapper_Website_WebsiteMelted($website); + return new Intonation_Library_View_Wrapper_Website_Smeltery_Melted($website); } public function meltAlbum($album) { - return new Intonation_Library_View_Wrapper_Website_AlbumMelted($album); + return new Intonation_Library_View_Wrapper_Website_Smeltery_AlbumMelted($album); } -} - - - -abstract class Intonation_Library_View_Wrapper_Website_MeltedItem { - protected $_model, - $_resource_cache; - - - public function __construct($model) { - $this->_model = $model; - } - - - public function getTitle() { - return $this->_model->getTitre(); - } - - - public function getTags() { - return explode(';', $this->_model->getTags()); - } - - - public function getDescription() { - return $this->_model->getDescription(); - } - - - abstract public function getUrl(); - abstract public function getPreviewImageUrl(); - abstract public function getCategory(); - abstract public function getDomains(); -} - - - - -class Intonation_Library_View_Wrapper_Website_WebsiteMelted extends Intonation_Library_View_Wrapper_Website_MeltedItem{ - - public function getUrl() { - return $this->_model->getUrl(); - } - - - public function getPreviewImageUrl() { - return Class_Url::assemble(['module' => 'opac', - 'controller' => 'sitotheque', - 'action' => 'webthumbnail'], - null, - true) . '?url=' . urlencode($this->_model->getUrl()); - } - - - public function getDomains() { - if ( ! $ids = $this->_model->getDomaineIds()) - return []; - - $domains = []; - - return (new Storm_Model_Collection(Class_Catalogue::findAllBy(['id_catalogue' => $ids]))) - ->collect('libelle') - ->getArrayCopy(); - } - - - public function getCategory() { - return $this->_model->getCategorieLibelle(); - } -} - - - - -class Intonation_Library_View_Wrapper_Website_AlbumMelted extends Intonation_Library_View_Wrapper_Website_MeltedItem { - - public function getUrl() { - return $this->_withResourceDo(function ($resource) { return $resource->getUrl();}); - } - - - - protected function _getResource() { - if ( $this->_resource_cache) - return $this->_resource_cache; - - $resources = $this->_model->getRessources(); - return $this->_resource_cache = reset($resources); - } - - - protected function _withResourceDo($callback) { - if ( ! $this->_getResource()) - return ''; - - return $callback($this->_getResource()); - } - - - public function getPreviewImageUrl() { - return $this->_withResourceDo(function ($resource) { return $resource->getThumbnailsUrl();}); - } - - - public function getDomains() { - return []; - } - - - public function getCategory() { - return $this->_model->getCategoryLabel(); - } -} +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery/AlbumMelted.php b/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery/AlbumMelted.php new file mode 100644 index 0000000000000000000000000000000000000000..9d8c6efbeac9d36a322708dbc276c6f9d21b9217 --- /dev/null +++ b/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery/AlbumMelted.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright (c) 2012-2021, 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_Website_Smeltery_AlbumMelted extends Intonation_Library_View_Wrapper_Website_Smeltery_MeltedItem { + + protected $_resource_cache; + + + public function getUrl() { + return $this->_withResourceDo(function ($resource) { return $resource->getUrl();}); + } + + + protected function _getResource() { + if ( $this->_resource_cache) + return $this->_resource_cache; + + $resources = $this->_model->getRessources(); + return $this->_resource_cache = reset($resources); + } + + + protected function _withResourceDo($callback) { + if ( ! $this->_getResource()) + return ''; + + return $callback($this->_getResource()); + } + + + public function getPreviewImageUrl() { + return $this->_withResourceDo(function ($resource) { return $resource->getThumbnailsUrl();}); + } + + + public function getDomains() { + return []; + } + + + public function getCategory() { + return $this->_model->getCategoryLabel(); + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery/Melted.php b/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery/Melted.php new file mode 100644 index 0000000000000000000000000000000000000000..845e6c996e259d5c14f7966b337df684edaf6235 --- /dev/null +++ b/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery/Melted.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright (c) 2012-2021, 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_Website_Smeltery_Melted extends Intonation_Library_View_Wrapper_Website_Smeltery_MeltedItem { + + public function getUrl() { + return $this->_model->getUrl(); + } + + + public function getPreviewImageUrl() { + return (new Class_WebService_WebSiteThumbnail)->getWebThumbnailURL($this->_model->getUrl()); + } + + + public function getDomains() { + if ( ! $ids = $this->_model->getDomaineIds()) + return []; + + $domains = []; + + return (new Storm_Model_Collection(Class_Catalogue::findAllBy(['id_catalogue' => $ids]))) + ->collect('libelle') + ->getArrayCopy(); + } + + + public function getCategory() { + return $this->_model->getCategorieLibelle(); + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery/MeltedItem.php b/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery/MeltedItem.php new file mode 100644 index 0000000000000000000000000000000000000000..060018f6a9d6255b7d9cfef9725efcc534389fa8 --- /dev/null +++ b/library/templates/Intonation/Library/View/Wrapper/Website/Smeltery/MeltedItem.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright (c) 2012-2021, 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 + */ + + +abstract class Intonation_Library_View_Wrapper_Website_Smeltery_MeltedItem { + + protected $_model; + + + public function __sleep() { + return ['_model']; + } + + + public function __construct($model) { + $this->_model = $model; + } + + + public function getId() { + return $this->_model->getId(); + } + + + public function getLastEdited() { + return $this->_model->getDateMaj(); + } + + + public function getTitle() { + return $this->_model->getTitre(); + } + + + public function getTags() { + return explode(';', $this->_model->getTags()); + } + + + public function getDescription() { + return $this->_model->getDescription(); + } + + + abstract public function getUrl(); + abstract public function getPreviewImageUrl(); + abstract public function getCategory(); + abstract public function getDomains(); +} diff --git a/library/templates/Intonation/Library/Widget/Carousel/View.php b/library/templates/Intonation/Library/Widget/Carousel/View.php index e067fa21d5648fd546144843c798af298b95d83b..ffc92d503fcca2215821ecd568e10648a6becf5a 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/View.php +++ b/library/templates/Intonation/Library/Widget/Carousel/View.php @@ -188,9 +188,7 @@ abstract class Intonation_Library_Widget_Carousel_View extends Zendafi_View_Help protected function _renderElements($elements) { $content_callback = $this->_getContentCallback($this->_settings->getRendering()); - $elements = array_slice($elements, 0, $this->_settings->getSize()); - - $elements = $this->_wrapElements($elements); + $elements = $this->_sliceElements($elements); return $this->_renderLayout($this->_settings->getLayout(), $elements, $content_callback); } @@ -357,7 +355,13 @@ abstract class Intonation_Library_Widget_Carousel_View extends Zendafi_View_Help public function newCollectionWith($order) { $this->_settings->setOrder($order); - return new Storm_Collection($this->_wrapElements($this->_findElements())); + return new Storm_Collection($this->_sliceElements($this->_findElements())); + } + + + protected function _sliceElements($elements) { + $elements = array_slice($elements, 0, $this->_settings->getSize()); + return $this->_wrapElements($elements); } diff --git a/library/templates/Intonation/Library/Widget/Carousel/Websites/Definition.php b/library/templates/Intonation/Library/Widget/Carousel/Websites/Definition.php index 87cb368947ae9e454e7f3df75137c9d6137f2255..3e9ddc48df09e4edd5936085a3cdeee8f34993c8 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Websites/Definition.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Websites/Definition.php @@ -24,7 +24,19 @@ class Intonation_Library_Widget_Carousel_Websites_Definition extends Intonation_ const CODE = 'SITO', - SEARCH = 'search'; + + SORT_SELECTION = 'Selection', + + SORT_RANDOM = 'Random', + + SORT_TITLE_ASC = 'TitleAsc', + SORT_TITLE_DESC = 'TitleDesc', + + SORT_CREATION_ASC = 'CreatedAsc', + SORT_CREATION_DESC = 'CreatedDesc', + + SORT_EDITION_ASC = 'EditedAsc', + SORT_EDITION_DESC = 'EditedDesc'; protected $_group = Class_Systeme_ModulesAccueil::GROUP_INFO; @@ -48,4 +60,85 @@ class Intonation_Library_Widget_Carousel_Websites_Definition extends Intonation_ static::HORIZONTAL_LISTING, static::WALL]; } + + + public function getOrders() { + return [static::SORT_RANDOM => $this->_('Aléatoire'), + + static::SORT_CREATION_ASC => $this->_('Date de création croissant'), + static::SORT_CREATION_DESC => $this->_('Date de création décroissant'), + + static::SORT_EDITION_ASC => $this->_('Date de modification croissant'), + static::SORT_EDITION_DESC => $this->_('Date de modification décroissant'), + + static::SORT_SELECTION => $this->_('Sélection'), + + static::SORT_TITLE_ASC => $this->_('Titre A-z'), + static::SORT_TITLE_DESC => $this->_('Titre Z-a')]; + } + + + public function getOrderCallback($order) { + if ( static::SORT_SELECTION == $order) + return function ($websites) { return $websites; }; + + if ( static::SORT_RANDOM == $order) + return function ($websites) + { + shuffle($websites); + return $websites; + }; + + return $this->_isASC($order) + ? $this->_doASCCallback($order) + : $this->_doDESCCallback($order); + } + + + protected function _isASC($order) { + return in_array($order, + [static::SORT_CREATION_ASC, + static::SORT_EDITION_ASC, + static::SORT_TITLE_ASC]); + } + + + protected function _doASCCallback($order) { + $method_name = $this->_getMethodNameFor($order); + return function ($websites) use ($method_name) + { + usort($websites, function($a, $b) use ($method_name) + { + return strnatcasecmp($a->$method_name(), $b->$method_name()); + }); + return $websites; + }; + } + + + protected function _doDESCCallback($order) { + $method_name = $this->_getMethodNameFor($order); + return function ($websites) use ($method_name) + { + usort($websites, function($a, $b) use ($method_name) + { + $cmp = strnatcasecmp($a->$method_name(), $b->$method_name()); + return ($cmp == 0) + ? $cmp + : !$cmp; + }); + return $websites; + }; + } + + + protected function _getMethodNameFor($order) { + if ( static::SORT_EDITION_ASC == $order || static::SORT_EDITION_DESC == $order ) + return 'getLastEdited'; + + if ( static::SORT_TITLE_ASC == $order || static::SORT_TITLE_DESC == $order) + return 'getTitle'; + + return 'getId'; + } } \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/Websites/Form.php b/library/templates/Intonation/Library/Widget/Carousel/Websites/Form.php index 62238316817715ce6f36a1a23432cc17b755c644..184c7cdd89a5051bb5fadfa18805a0c07c813da6 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Websites/Form.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Websites/Form.php @@ -55,7 +55,7 @@ class Intonation_Library_Widget_Carousel_Websites_Form extends Intonation_Librar public function getOrders() { - return []; + return (new Intonation_Library_Widget_Carousel_Websites_Definition)->getOrders(); } diff --git a/library/templates/Intonation/Library/Widget/Carousel/Websites/View.php b/library/templates/Intonation/Library/Widget/Carousel/Websites/View.php index 646942ad9837d8eeedec239948f04088fc483c01..5819feea1de2d57a9b9d912f9f4bd517c5e8468e 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Websites/View.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Websites/View.php @@ -52,7 +52,7 @@ class Intonation_Library_Widget_Carousel_Websites_View extends Intonation_Librar foreach ($albums as $album) $melted_websites [] = $smeltery->meltAlbum($album); - return $melted_websites; + return $this->_order($melted_websites); } @@ -77,4 +77,13 @@ class Intonation_Library_Widget_Carousel_Websites_View extends Intonation_Librar protected function _getWrapper() { return Intonation_Library_View_Wrapper_Website::class; } + + + protected function _order($websites) { + $order = $this->_settings->getOrder(); + $order_callback = (new Intonation_Library_Widget_Carousel_Websites_Definition) + ->getOrderCallback($order); + + return $order_callback($websites); + } } diff --git a/library/templates/Intonation/System/Abstract.php b/library/templates/Intonation/System/Abstract.php index b21cb2cee6f90fb1a6ff452431f988c4861e29a5..524d1486954d81d0be6eebde2b88354ce0bdb548 100644 --- a/library/templates/Intonation/System/Abstract.php +++ b/library/templates/Intonation/System/Abstract.php @@ -174,6 +174,7 @@ abstract class Intonation_System_Abstract { $controllers [] = 'formulaire'; $controllers [] = 'bib'; $controllers [] = 'widget'; + $controllers [] = 'sito'; } if($this->isVisibleForBlogController()) { diff --git a/library/templates/Intonation/View/RenderAjaxPaginatedList.php b/library/templates/Intonation/View/RenderAjaxPaginatedList.php index 8287817c6ea89502f7ff7950db7395f77e5477a7..a4aaef347396bf9084b2277b8f8d9c46bd407e92 100644 --- a/library/templates/Intonation/View/RenderAjaxPaginatedList.php +++ b/library/templates/Intonation/View/RenderAjaxPaginatedList.php @@ -76,33 +76,43 @@ class Intonation_View_RenderAjaxPaginatedList extends ZendAfi_View_Helper_BaseHe ? true : null; + $anchor_previous_url = $this->view->url(['controller' => 'index', + 'action' => 'ajax-paginated-list', + 'id' => $this->_id, + 'size' => $helper->getPageSize(), + 'page' => $current_page -1], null, true); + + $anchor_previous = $this->view->tagAnchor($anchor_previous_url, + $this->_tag('i','',['class' => 'fas fa-chevron-left m-0']), + array_filter(['title' => $this->_('page précedente'), + 'class' => 'btn btn-sm btn-secondary ajax_anchor previous_ajax_anchor', + 'id' => 'previous_' . $this->_id, + 'data-disabled' => $previous_button_disabled])); + + $anchor_next_url = $this->view->url(['controller' => 'index', + 'action' => 'ajax-paginated-list', + 'id_profil' => Class_Profil::getCurrentProfil()->getId(), + 'id' => $this->_id, + 'size' => $helper->getPageSize(), + 'page' => $current_page +1], + null, + true); + + $anchor_next = $this->view->tagAnchor($anchor_next_url, + $this->_tag('i','',['class' => 'fas fa-chevron-right m-0']), + array_filter(['title' => $this->_('page suivante'), + 'class' => 'btn btn-sm btn-secondary ajax_anchor next_ajax_anchor', + 'id' => 'next_' . $this->_id, + 'data-disabled' => $next_button_disabled])); + return $this->view->div([], - implode([$this->view->tagAnchor(['controller' => 'index', - 'action' => 'ajax-paginated-list', - 'id' => $this->_id, - 'size' => $helper->getPageSize(), - 'page' => $current_page -1], - $this->_tag('i','',['class' => 'fas fa-chevron-left m-0']), - array_filter(['title' => $this->_('page précedente'), - 'class' => 'btn btn-sm btn-secondary ajax_anchor previous_ajax_anchor', - 'id' => 'previous_' . $this->_id, - 'data-disabled' => $previous_button_disabled])), + implode([$anchor_previous, $this->_tag( 'span' , $this->_('Page %d / %d' , $current_page, $count_pages), ['class' => 'btn btn-sm']), - $this->view->tagAnchor(['controller' => 'index', - 'action' => 'ajax-paginated-list', - 'id_profil' => Class_Profil::getCurrentProfil()->getId(), - 'id' => $this->_id, - 'size' => $helper->getPageSize(), - 'page' => $current_page +1], - $this->_tag('i','',['class' => 'fas fa-chevron-right m-0']), - array_filter(['title' => $this->_('page suivante'), - 'class' => 'btn btn-sm btn-secondary ajax_anchor next_ajax_anchor', - 'id' => 'next_' . $this->_id, - 'data-disabled' => $next_button_disabled]))])); + $anchor_next])); } diff --git a/library/templates/Intonation/View/RenderCollection.php b/library/templates/Intonation/View/RenderCollection.php index a4b41d98680928942df59696c8a72915cfd0a6a7..7fbf0a028d02917ca3c6684ee29960e6f4ab3773 100644 --- a/library/templates/Intonation/View/RenderCollection.php +++ b/library/templates/Intonation/View/RenderCollection.php @@ -33,9 +33,9 @@ class Intonation_View_RenderCollection extends ZendAfi_View_Helper_BaseHelper { if ( ! $action->getClass()) $action->setClass('btn btn-sm btn-success'); - $html = [$this->view->div(['class' => 'col-12'], + $html = [$this->view->div(['class' => 'collection_actions'], $this->view->renderCollectionActions($actions)), - $this->view->div(['class' => 'col-12'], + $this->view->div(['class' => 'collection_truncate_list'], $this->view->renderTruncateList($collection, $callback, $page_size))]; diff --git a/library/templates/Intonation/View/RenderWebsites.php b/library/templates/Intonation/View/RenderWebsites.php new file mode 100644 index 0000000000000000000000000000000000000000..b0c5536da312e4b248b77f35de76eac384569156 --- /dev/null +++ b/library/templates/Intonation/View/RenderWebsites.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright (c) 2012-2021, 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_View_RenderWebsites extends ZendAfi_View_Helper_BaseHelper { + public function renderWebsites($websites) { + if ( ! $this->view->titre) + $this->view->titre = $this->_('Sélection de sites'); + + $smeltery = new Intonation_Library_View_Wrapper_Website_Smeltery; + + $melted_websites = []; + foreach ($websites as $website) + $melted_websites [] = new Intonation_Library_View_Wrapper_Website($smeltery->meltWebsite($website), + $this->view); + + $content = [$this->_div(['class' => 'websites_list_title'], + $this->_tag('h1', $this->view->titre)), + + $this->_div(['class' => 'websites_list_content'], + $this->view->renderCollection(new Storm_Collection($melted_websites)))]; + + return $this->view->grid($content); + } +} diff --git a/tests/scenarios/Templates/TemplatesWebsitesTest.php b/tests/scenarios/Templates/TemplatesWebsitesTest.php index 911179741062be8414a5fa0380458a4d3b355fb5..6864592a9811e85d32ad10a61cc302bd7f9a4c4c 100644 --- a/tests/scenarios/Templates/TemplatesWebsitesTest.php +++ b/tests/scenarios/Templates/TemplatesWebsitesTest.php @@ -40,7 +40,13 @@ abstract class TemplatesWebsitesWidgetTestCase extends Admin_AbstractControllerT 'websites_ids' => '1-2', 'websites_categories' => '8-5', 'id_items' => '4-19', - 'id_categorie' => '3-53']); + 'id_categorie' => '3-53', + 'order' => $this->_order()]); + } + + + protected function _order() { + return 'Selection'; } } @@ -96,15 +102,17 @@ class TemplatesWebsitesWidgetAsAdminTest extends TemplatesWebsitesWidgetTestCase $this->dispatch('/admin/widget/add-from-template/id_profil/19'); $this->assertXPathContentContains('//div', 'Sitothèque'); } -} + /** @test */ + public function orderCreatedAscShouldBePresent() { + $this->dispatch('admin/widget/edit-widget/id/1/id_profil/19'); + $this->assertXPath('//div//select/option', 'Date de création croissant'); + } +} -class TemplatesWebsitesWidgetDispatchTest extends TemplatesWebsitesWidgetTestCase { - protected $_storm_default_to_volatile = true; - - +abstract class TemplatesWebsitesFixturesTestCase extends TemplatesWebsitesWidgetTestCase { public function setUp() { parent::setUp(); @@ -215,6 +223,17 @@ class TemplatesWebsitesWidgetDispatchTest extends TemplatesWebsitesWidgetTestCas 'titre' => 'Site de l\'eau' ]); + } +} + + + + +class TemplatesWebsitesWidgetDispatchTest extends TemplatesWebsitesFixturesTestCase { + + + public function setUp() { + parent::setUp(); $this->dispatch('opac/index'); } @@ -265,4 +284,153 @@ class TemplatesWebsitesWidgetDispatchTest extends TemplatesWebsitesWidgetTestCas public function leSiteDuLacShouldBePresent() { $this->assertXPathContentContains('//div', 'Le site du lac'); } +} + + + + +class TemplatesWebsitesControllerTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + $profile = + $this->_buildTemplateProfil(['id' => '19', + 'template' => 'MUSCLE']); + + $this->fixture('Class_Sitotheque', + ['id' => '32', + 'titre' => 'La médiathèque de la montée', + 'url' => 'https://la-mediatheque-de-la-montee.org', + 'id_cat' => '127' + ]); + + $this->fixture('Class_SitothequeCategorie', + ['id' => '127', + 'libelle' => 'Montée' + ]); + + $this->dispatch('/sito/sitoview/id_categorie/127'); + } + + + /** @test */ + public function pageShouldContainsMain() { + $this->assertXPath('//body//main'); + } +} + + + +class TemplatesWebsitesWidgetDispatchWithRandomOrderTest extends TemplatesWebsitesWidgetDispatchTest { + protected function _order() { + return 'Random'; + } +} + + + + +class TemplatesWebsitesWidgetDispatchWithTitleAscOrderTest extends TemplatesWebsitesWidgetDispatchTest { + protected function _order() { + return 'TitleAsc'; + } + + + /** @test */ + public function firstWebsiteShoulBeLaMediathequeDeLaDescente() { + $this->assertXPathContentContains('(//div[contains(@class, "card")])[1]', 'La médiathèque de la descente'); + } +} + + + +class TemplatesWebsitesWidgetDispatchWithTitleDescOrderTest extends TemplatesWebsitesWidgetDispatchTest { + protected function _order() { + return 'TitleDesc'; + } + + + /** @test */ + public function firstWebsiteShoulBeLaMediathequeDuCoin() { + $this->assertXPathContentContains('(//div[contains(@class, "card")])[1]', 'La médiathèque du coin'); + } +} + + + + +class TemplatesWebsitesWidgetDispatchWithCreationAscOrderTest extends TemplatesWebsitesWidgetDispatchTest { + protected function _order() { + return 'CreatedAsc'; + } + + + /** @test */ + public function firstWebsiteShoulBeLaMediathequeDeLaRue() { + $this->assertXPathContentContains('(//div[contains(@class, "card")])[1]', 'La médiathèque de la rue'); + } +} + + + + +class TemplatesWebsitesWidgetDispatchWithCreationDescOrderTest extends TemplatesWebsitesWidgetDispatchTest { + protected function _order() { + return 'CreatedDesc'; + } + + + /** @test */ + public function firstWebsiteShoulBeLaMediathequeDeLaDescente() { + $this->assertXPathContentContains('(//div[contains(@class, "card")])[1]', 'La médiathèque de la descente'); + } +} + + + + +class TemplatesWebsitesWidgetDispatchWithEditionAscOrderTest extends TemplatesWebsitesWidgetDispatchTest { + protected function _order() { + return 'EditedAsc'; + } +} + + + + +class TemplatesWebsitesWidgetDispatchWithEditionDescOrderTest extends TemplatesWebsitesWidgetDispatchTest { + protected function _order() { + return 'EditedDesc'; + } +} + + + + +class TemplatesWebsitesDispatchPaginatedTest extends TemplatesWebsitesFixturesTestCase { + /** @test */ + public function page2ShouldContainsSearchInputWithMd5Key() { + Storm_Cache::beVolatile(); + + $smeltery = new Intonation_Library_View_Wrapper_Website_Smeltery; + + $melted_websites = []; + + $view_renderer = new ZendAfi_Controller_Action_Helper_ViewRenderer; + $view_renderer->preDispatch(); + + foreach (Class_Sitotheque::getSitesCategorie(8) as $website) + $melted_websites [] = new Intonation_Library_View_Wrapper_Website($smeltery->meltWebsite($website), $view_renderer->view); + + $helper = (new Intonation_Library_AjaxPaginatedListHelper) + ->setCollection(new Storm_Collection($melted_websites)) + ->setRendering('cardifyHorizontal'); + + $id = $helper->getId(); + + $this->dispatch('/opac/index/ajax-paginated-list/id/' . $id . '/page/1/render/ajax/id_profil/19'); + $this->assertContains('input_38bcd646a69f4da7fce8921d4cf762ad', $this->_response->getBody()); + } } \ No newline at end of file