Skip to content
Snippets Groups Projects
Commit e7592b34 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

hotline MT #125258 improve custom field multi checkbox filter rendering

parent 6a8bf1ba
Branches
Tags
No related merge requests found
Pipeline #12359 passed with stage
in 57 minutes and 39 seconds
Showing
with 294 additions and 25 deletions
- ticket #125258 : Magasin de thèmes : amélioration des filtres pour les champs personnalisés dans les carousels.
\ No newline at end of file
......@@ -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 = [];
......
......@@ -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 [];
}
......
......@@ -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;
}
......
......@@ -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'] : [];
}
}
......@@ -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);
}
......@@ -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',
......
<?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
<?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);
}
}
<?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
<?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;
}
}
......@@ -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();
}
}
#contributor : Ghislain Loas <gloas@afi-sa.fr>
#name : xd
# --
xdebug_break();$0
\ No newline at end of file
......@@ -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());
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment