diff --git a/VERSIONS_HOTLINE/125258 b/VERSIONS_HOTLINE/125258 new file mode 100644 index 0000000000000000000000000000000000000000..4c992c4d03673a1153657d141485a7b355105cec --- /dev/null +++ b/VERSIONS_HOTLINE/125258 @@ -0,0 +1 @@ + - ticket #125258 : Magasin de thèmes : amélioration des filtres pour les champs personnalisés dans les carousels. \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Filters/Element/CustomField.php b/library/ZendAfi/View/Helper/Filters/Element/CustomField.php index c67a38c1277588bc42bd997253b42a8f5cad03d3..5de09370b346e448eba70ead69b0500042c757f6 100644 --- a/library/ZendAfi/View/Helper/Filters/Element/CustomField.php +++ b/library/ZendAfi/View/Helper/Filters/Element/CustomField.php @@ -22,6 +22,9 @@ class ZendAfi_View_Helper_Filters_Element_CustomField extends ZendAfi_View_Helper_Filters_Element { public function elements() { + if ( ! $this->_custom_field_id) + return []; + $values = Class_CustomField_Value::findAllBy(['custom_field_id' => $this->_custom_field_id]); $elements = []; diff --git a/library/ZendAfi/View/Helper/Filters/Element/Reset.php b/library/ZendAfi/View/Helper/Filters/Element/Reset.php index 338e04f7994dc70a40564cb362d21d6f6d438368..ebe975bf9ecf51429f8801260edbaad338f6fbb9 100644 --- a/library/ZendAfi/View/Helper/Filters/Element/Reset.php +++ b/library/ZendAfi/View/Helper/Filters/Element/Reset.php @@ -26,12 +26,18 @@ class ZendAfi_View_Helper_Filters_Element_Reset extends ZendAfi_View_Helper_Filt } + public function isCheckBox() { + return false; + } + + public function isReset() { return true; } public function elements() { + return []; } diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Abstract.php b/library/ZendAfi/View/Helper/Filters/Strategy/Abstract.php index bbd4ee5254a3572642248237a4a06ed4cc27ed84..5a0a77ac281e8344ca29f7308a0785316a6804f2 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Abstract.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Abstract.php @@ -21,8 +21,11 @@ abstract class ZendAfi_View_Helper_Filters_Strategy_Abstract extends ZendAfi_View_Helper_BaseHelper { + const NAME_PREFIX = 'ZendAfi_View_Helper_Filters_Strategy_'; + protected static $_strategies_map; + protected $_filter_elements, $_settings; @@ -31,20 +34,18 @@ abstract class ZendAfi_View_Helper_Filters_Strategy_Abstract extends ZendAfi_Vie /** * @param $filter_elements ZendAfi_View_Helper_Filters_Element_* */ - public static function newFor($filter_elements) { - $name = 'Facet'; - foreach(['Checkbox' => 'isCheckBox', - 'Reset' => 'isReset', - 'Search' => 'isSearch', - 'Calendar' => 'isCalendar'] as $k => $v) { + public static function newFor($filter_elements, $strategies_map = []) { + if ( ! $strategies_map) + $strategies_map = static::getStrategiesMap(); + + $name = static::NAME_PREFIX . 'Facet'; + foreach($strategies_map as $k => $v) { if ($filter_elements->$v()) { $name = $k; break; } } - $name = static::NAME_PREFIX . $name; - $strategy = new $name($filter_elements); $strategy->setView($filter_elements->view); @@ -52,6 +53,18 @@ abstract class ZendAfi_View_Helper_Filters_Strategy_Abstract extends ZendAfi_Vie } + public static function getStrategiesMap() { + if (isset(static::$_strategies_map)) + return static::$_strategies_map; + + return static::$_strategies_map = + [static::NAME_PREFIX . 'Checkbox' => 'isCheckBox', + static::NAME_PREFIX . 'Reset' => 'isReset', + static::NAME_PREFIX . 'Search' => 'isSearch', + static::NAME_PREFIX . 'Calendar' => 'isCalendar']; + } + + public function __construct($filter_elements) { $this->_filter_elements = $filter_elements; } diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Checkbox.php b/library/ZendAfi/View/Helper/Filters/Strategy/Checkbox.php index 1db9da876289bcb91b193f505fb94c0cbc7f7c09..767710f72416c38243997ff679708cfe89c2c010 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Checkbox.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Checkbox.php @@ -33,21 +33,22 @@ class ZendAfi_View_Helper_Filters_Strategy_Checkbox extends ZendAfi_View_Helper_ } - protected function _renderFilterItem($value, $label, $selected) { + protected function _renderFilterItem($values, $label, $selected) { $selected - ? $value = array_diff($value, [$label]) - : $value[] = $label; + ? $values = array_diff($values, [$label]) + : $values[] = $label; - $url_params = $this->_getUrlParams(); - if($values = implode(';', $value)) - $url_params = array_merge($url_params, [$this->_getFilterKey() => $values]); + $checked = $this->_renderFilterItemChecked($selected); - if(!$values) - unset($url_params[$this->_getFilterKey()]); + $url_params = array_filter(array_merge($this->_getUrlParams(), + [$this->_getFilterKey() => implode(';', $values)])); $url = $this->view->url($url_params, null, true); - $checked = $selected ? ['checked' => 'checked'] : []; + return $this->_renderFilterItemHTML($label, $url, $checked); + } + + protected function _renderFilterItemHTML($label, $url, $checked) { return $this->_tag('li', $this->_tag('input', $label, @@ -57,4 +58,9 @@ class ZendAfi_View_Helper_Filters_Strategy_Checkbox extends ZendAfi_View_Helper_ 'value' => $label, 'data-url' => $url]))); } + + + protected function _renderFilterItemChecked($selected) { + return $selected ? ['checked' => 'checked'] : []; + } } diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php b/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php index c5aad13dc27fac08f93013254bd8bb1893062da0..41fc96fa48090562dcff913a3c49890cc49fb65c 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Elements.php @@ -62,5 +62,5 @@ abstract class ZendAfi_View_Helper_Filters_Strategy_Elements public abstract function renderFilterItems($elements); - protected abstract function _renderFilterItem($value, $label, $selected); + protected abstract function _renderFilterItem($values, $label, $selected); } diff --git a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php index 3dc494bdce049eb4fa963b9190e17c30f97b915c..b15547493c9ff53f5d8d40c13410b76916a7454a 100644 --- a/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php +++ b/library/ZendAfi/View/Helper/Filters/Strategy/Facet.php @@ -42,9 +42,9 @@ class ZendAfi_View_Helper_Filters_Strategy_Facet } - protected function _renderFilterItem($value, $label, $selected) { + protected function _renderFilterItem($values, $label, $selected) { $url_params = array_merge($this->_getUrlParams(), - [ $this->_getFilterKey() => $value ]); + [ $this->_getFilterKey() => $values ]); $url = $this->view->url($url_params, null, true); return $this->_tag('li', diff --git a/library/templates/Intonation/Library/Widget/Carousel/Filter/Checkbox.php b/library/templates/Intonation/Library/Widget/Carousel/Filter/Checkbox.php new file mode 100644 index 0000000000000000000000000000000000000000..3102086a304181b3c9f4b2040d37358e2ca574f4 --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/Filter/Checkbox.php @@ -0,0 +1,39 @@ +<?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_Widget_Carousel_Filter_Checkbox extends ZendAfi_View_Helper_Filters_Strategy_Checkbox { + + protected function _renderFilterItemHTML($label, $url, $checked) { + return $this->_tag('li', + $this->_tag('a', + $label, + ['title' => $this->_('Filtrer la liste par %s', + $label), + 'href' => $url]), + $checked); + } + + + protected function _renderFilterItemChecked($selected) { + return $selected ? ['class' => 'selected'] : []; + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/Filter/CustomField.php b/library/templates/Intonation/Library/Widget/Carousel/Filter/CustomField.php new file mode 100644 index 0000000000000000000000000000000000000000..de6038c717a7a19c2ca831bd3881194fd38fd02b --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/Filter/CustomField.php @@ -0,0 +1,81 @@ +<?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_Widget_Carousel_Filter_CustomField { + + protected + $_custom_field_id, + $_view, + $_filter, + $_settings, + $_legacy_element; + + + public function __construct($custom_field_id) { + $this->_custom_field_id = $custom_field_id; + } + + + public function setView($view) { + $this->_view = $view; + return $this; + } + + + public function setFilter($filter) { + $this->_filter = $filter; + return $this; + } + + + public function setSettings($settings) { + $this->_settings = $settings; + return $this; + } + + + public function getContent() { + return $this->_getFilterStrategy()->getContent($this->_settings); + } + + + public function getTitle() { + return $this->_getFilterStrategy()->getTitle($this->_settings); + } + + + protected function _getFilterStrategy() { + return (new Intonation_Library_Widget_Carousel_Filter_Strategy($this->_getLegacyElement()))->build(); + } + + + protected function _getLegacyElement() { + if ( isset($this->_legacy_element )) + return $this->_legacy_element; + + return $this->_legacy_element = + (new ZendAfi_View_Helper_Filters_Element_CustomField($this->_custom_field_id)) + ->setSettings($this->_settings) + ->setFilter($this->_filter) + ->setView($this->_view); + } +} diff --git a/library/templates/Intonation/Library/Widget/Carousel/Filter/Element.php b/library/templates/Intonation/Library/Widget/Carousel/Filter/Element.php new file mode 100644 index 0000000000000000000000000000000000000000..3114fa70049bceebc589ecb336dba41e16112961 --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/Filter/Element.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright (c) 2012-2020, 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_Filter_Element { + + protected + $_filter, + $_settings, + $_view; + + + public function __construct($filter, $settings, $view) { + $this->_filter = $filter; + $this->_settings = $settings; + $this->_view = $view; + } + + + public function build() { + if (preg_match('/^custom_field_(\d+)/', $this->_filter, $matches)) + return (new Intonation_Library_Widget_Carousel_Filter_CustomField($matches[1])) + ->setView($this->_view) + ->setSettings($this->_settings) + ->setFilter($this->_filter); + + return ZendAfi_View_Helper_Filters_Element::forFilter($this->_filter) + ->setView($this->_view) + ->setSettings($this->_settings); + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/Filter/Strategy.php b/library/templates/Intonation/Library/Widget/Carousel/Filter/Strategy.php new file mode 100644 index 0000000000000000000000000000000000000000..a25bf5bd5083b07d32b5ace36f1fbdb34ac837e2 --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/Filter/Strategy.php @@ -0,0 +1,47 @@ +<?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_Widget_Carousel_Filter_Strategy { + + protected $_element; + + public function __construct($element) { + $this->_element = $element; + } + + + public function build() { + $strategy = 'Intonation_Library_Widget_Carousel_Filter_Checkbox'; + + return + ZendAfi_View_Helper_Filters_Strategy_Abstract::newFor($this->_element, + $this->_customStrategies($strategy)); + } + + + protected function _customStrategies($strategy) { + $map = ZendAfi_View_Helper_Filters_Strategy_Abstract::getStrategiesMap(); + unset($map[ZendAfi_View_Helper_Filters_Strategy_Abstract::NAME_PREFIX . 'Checkbox']); + $map [$strategy] = 'isCheckBox'; + return $map; + } +} diff --git a/library/templates/Intonation/View/Filters/Render.php b/library/templates/Intonation/View/Filters/Render.php index 8a58031dbbb6eaa1eb2066fe735c1b24a7623d02..3a5fe3f7332dc281897554b91e431d4f4b2c2cdc 100644 --- a/library/templates/Intonation/View/Filters/Render.php +++ b/library/templates/Intonation/View/Filters/Render.php @@ -46,8 +46,9 @@ class Intonation_View_Filters_Render extends ZendAfi_View_Helper_BaseHelper { protected function _getFilterRenderer($filter, $settings) { - return ZendAfi_View_Helper_Filters_Element::forFilter($filter) - ->setView($this->view) - ->setSettings($settings); + return (new Intonation_Library_Widget_Carousel_Filter_Element($filter, + $settings, + $this->view)) + ->build(); } } diff --git a/scripts/emacs/yasnippet/snippets/text-mode/php-mode/xd b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/xd new file mode 100644 index 0000000000000000000000000000000000000000..888cd8ae8a8072eea93fc6a43f5bd8dc329ba08c --- /dev/null +++ b/scripts/emacs/yasnippet/snippets/text-mode/php-mode/xd @@ -0,0 +1,4 @@ +#contributor : Ghislain Loas <gloas@afi-sa.fr> +#name : xd +# -- +xdebug_break();$0 \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesWidgetTest.php b/tests/scenarios/Templates/TemplatesWidgetTest.php index 37bde30232e3a443e9128e248b7cf8a13890c002..905243cfc9e1a764e90ace423beb3d4f504c981b 100644 --- a/tests/scenarios/Templates/TemplatesWidgetTest.php +++ b/tests/scenarios/Templates/TemplatesWidgetTest.php @@ -468,6 +468,14 @@ class TemplatesWidgetLibraryWithOSMAndLinkToProfileTest extends TemplatesIntonat $this->fixture('Class_Profil', ['id' => 123]); + $this->fixture('Class_CustomField', + ['id' => 1, + 'priority' => 1, + 'label' => 'Services', + 'options_list' => 'Wifi;Projection;Restauration;l\'Médias', + 'field_type' => Class_CustomField_Meta::MULTI_CHECKBOX, + 'model' => 'Bib']); + $this->fixture('Class_Bib', ['id' => 1, 'libelle' => 'Annecy', @@ -476,7 +484,9 @@ class TemplatesWidgetLibraryWithOSMAndLinkToProfileTest extends TemplatesIntonat 'libelle' => 'Annecy', 'latitude' => '1', 'longitude' => '1']), - 'link_to_profil_id' => 123]); + 'link_to_profil_id' => 123]) + ->setCustomField('Services', ['Wifi', 'Projection', 'Restauration','l\'Médias']) + ->saveWithCustomFields(); Class_Profil::find(72) ->setCfgAccueil(['modules' => @@ -484,12 +494,21 @@ class TemplatesWidgetLibraryWithOSMAndLinkToProfileTest extends TemplatesIntonat 'type_module' => 'LIBRARY', 'preferences' => ['osm_map' => 1, 'osm_layer' => 1, - 'geo_json' => 'files/my_geojson.geojson']]]]) + 'geo_json' => 'files/my_geojson.geojson', + 'filters' => 'custom_field_1']]]]) ->assertSave(); + $this->dispatch('/opac/index/index/id_profil/72'); } + /** @test */ + public function customFieldServiceProjectionShouldBeAnAnchor() { + $this->assertXPathContentContains('//div[contains(@class,"boite library")]//div[@class="dropdown-menu"]//li//a[@href = "/bib/widget/id_profil/72/id_module/21/id_division/3/custom_field_1/Projection"]', + 'Projection'); + } + + /** @test */ public function scriptLoaderShouldContainsOpenStreetMapJs() { $this->assertContains('openStreetMap.js', Class_ScriptLoader::getInstance()->html());