Commit cb8a361a authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch 'dev#93032_bdp_yonne_custom_fields_sur_agenda_rdv_v2_v475' into 'master'

Dev#93032 bdp yonne custom fields sur agenda rdv v2 v475

See merge request !3174
parents 8a48710a 6199d05b
Pipeline #7661 passed with stage
in 38 minutes and 41 seconds
- ticket #93032 : Administration des rendez-vous : Recherche sur les champs personalisés
\ No newline at end of file
......@@ -3,16 +3,11 @@ echo $this->button_New((new Class_Entity())
->setText($this->_('Créer un agenda')));
echo $this->button((new Class_Entity())
->setText($this->_('Tous les rendez-vous'))
->setUrl($this->url(['module' => 'admin',
'controller' => 'usergroup-agenda',
'action' => 'all'], null, true))
->setImage($this->tagImg(Class_Admin_Skin::current()
->getIconUrl('buttons',
'test'))));
->setText($this->_('Tous les rendez-vous'))
->setUrl($this->url(['module' => 'admin',
'controller' => 'usergroup-agenda',
'action' => 'all'], null, true))
->setImage($this->tagImg(Class_Admin_Skin::current()
->getIconUrl('buttons', 'test'))));
$description = (new Class_TableDescription('agendas'))
->addColumn($this->_('Libellé'), 'libelle')
->addRowAction(function($model) { return $this->renderPluginsActions($model); });
echo $this->renderTable($description, $this->groups);
echo $this->renderTable(new Class_TableDescription_UsergroupAgenda('agendas'), $this->groups);
......@@ -32,10 +32,14 @@ class Class_CustomField_ValueLoader extends Storm_Model_Loader {
public function findAllByInstance($instance) {
$model = Class_CustomField_Model::getModel(get_class($instance));
if (!$instance
|| (!$model = Class_CustomField_Model::getModel(get_class($instance))))
return [];
$fields = $model->getFields();
$field_ids = array_map(function($f) {return $f->getId();},
$fields);
return $this->findAllBy(['model_id' => $instance->getId(),
'custom_field_id' => $field_ids]);
}
......
......@@ -24,12 +24,11 @@ class Class_RendezVous_SearchCriteria extends Class_SearchCriteria {
protected $_model_class = 'Class_RendezVous';
public function __construct($params) {
$this->_criteria = [
new Class_RendezVous_SearchCriteria_User($params),
new Class_RendezVous_SearchCriteria_Comment($params),
new Class_RendezVous_SearchCriteria_Date($params),
$this->_criteria = [new Class_RendezVous_SearchCriteria_Date($params),
new Class_RendezVous_SearchCriteria_Location($params),
new Class_RendezVous_SearchCriteria_Order($params),
];
new Class_RendezVous_SearchCriteria_Comment($params),
new Class_RendezVous_SearchCriteria_Order($params)];
$this->_addCustomCriteriaFor($this->_model_class, $params);
}
}
......@@ -20,32 +20,12 @@
*/
class Class_RendezVous_SearchCriteria_Comment extends Class_SearchCriteria_Abstract {
class Class_RendezVous_SearchCriteria_Comment extends Class_SearchCriteria_TextLike {
protected
$_name = 'comment',
$_value = '';
$_name = 'comment';
public function __construct($params) {
parent::__construct($params);
$previous = $this->_value;
$this->_value = trim((new Zend_Filter_Alnum(true))->filter($this->_value));
$this->_element->setValue($this->_value);
if ($previous != $this->_value)
$this->_element->addError($this->_('Seuls les caractères alphanumériques sont autorisés'));
}
protected function buildElement() {
return new Zend_Form_Element_Text($this->getName(),
['label' => $this->_('Commentaire contient')]);
}
public function acceptSearchVisitor($visitor) {
if (!$this->_value)
return;
$visitor->addWhereParam('comment like "%' . $this->_value . '%"');
public function buildElement() {
return parent::buildElement()->setLabel($this->_('Commentaire contient'));
}
}
......@@ -35,9 +35,7 @@ class Class_RendezVous_SearchCriteria_Date extends Class_SearchCriteria_DateRang
}
protected function buildElement() {
$element = parent::buildElement();
$element->setLabel($this->_('Date'));
return $element;
public function buildElement() {
return parent::buildElement()->setLabel($this->_('Date'));
}
}
......@@ -27,13 +27,12 @@ class Class_RendezVous_SearchCriteria_Location extends Class_SearchCriteria_Abst
const NONE = "none";
protected function buildElement() {
public function buildElement() {
$options = ['label' => $this->_('Lieu'),
'multiOptions' => [static::DEFAULT_VALUE => $this->_('Tous'),
static::NONE => $this->_('Indéterminé')]
+ Class_Lieu::getAllLibelles()
];
return new Zend_Form_Element_Select($this->getName(), $options);
}
......
<?php
/**
* Copyright (c) 2012-2019, 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 Class_RendezVous_SearchCriteriaAll extends Class_SearchCriteria {
protected
$_model_class = 'Class_RendezVous',
$_rendez_vous_criteria,
$_agenda_criteria;
public function __construct($params) {
$this->_rendez_vous_criteria = new Class_RendezVous_SearchCriteria($params);
$this->_agenda_criteria = new Class_UserGroup_Agenda_SearchCriteria($params);
}
public function getFormValues() {
return array_merge($this->_rendez_vous_criteria->getFormValues(),
$this->_agenda_criteria->getFormValues());
}
public function getForm() {
$form = parent::getForm();
$this->_addCompositeElements($form,
$this->_rendez_vous_criteria,
$this->_('Critères Rendez-vous'));
$this->_addCompositeElements($form,
$this->_agenda_criteria,
$this->_('Critères Agenda'));
return $form;
}
protected function _addCompositeElements($form, $composite, $legend) {
$composite_form = $composite->getForm();
if (!$composite_form->getElements())
return;
foreach($composite_form->getElements() as $element)
$form->addElement($element);
$form->addDisplayGroup($composite_form->getElementsNames(),
md5($legend) . '_fields',
['legend' => $legend]);
}
protected function _buildSearchParams() {
return $this
->_adoptSearchParams($this->_rendez_vous_criteria)
->_buildAgendaParams();
}
protected function _buildAgendaParams() {
if (!$this->_agenda_criteria->isFiltering())
return $this;
$agendas = new Storm_Model_Collection($this->_agenda_criteria
->findPage(1, static::PAGE_NO_LIMIT));
if ($agendas->isEmpty())
return $this->hasNoResult();
$this->addParam('group_id', $agendas->collect('id')->getArrayCopy());
return $this;
}
}
......@@ -22,6 +22,7 @@
abstract class Class_SearchCriteria {
use Trait_Translator;
const PAGE_NO_LIMIT = -1;
protected
$_model_class = '',
......@@ -51,16 +52,19 @@ abstract class Class_SearchCriteria {
public function findPage($page=1, $page_size=20) {
$this->_buildSearchParams();
return $this->_has_no_result
? []
: call_user_func([$this->_model_class, 'findAllBy'],
array_merge($this->_search_params, ['limitPage' => [$page, $page_size]]));
if ($this->_has_no_result)
return [];
$params = $this->_search_params;
if (static::PAGE_NO_LIMIT !== $page_size)
$params = array_merge($params, ['limitPage' => [$page, $page_size]]);
return call_user_func([$this->_model_class, 'findAllBy'], $params);
}
public function count() {
$this->_buildSearchParams();
return $this->_has_no_result
? 0
: call_user_func([$this->_model_class, 'countBy'], $this->_search_params);
......@@ -117,6 +121,7 @@ abstract class Class_SearchCriteria {
$wheres = $this->_search_params['wheres'];
unset($this->_search_params['wheres']);
if ($wheres)
$this->_search_params['where'] = '(' . implode(') AND (', $wheres) . ')';
......@@ -142,9 +147,33 @@ abstract class Class_SearchCriteria {
}
public function isFiltering() {
$this->_buildSearchParams();
return $this->_has_no_result || $this->_search_params;
}
public function describeOn($view) {
return array_filter((new Storm_Collection($this->_criteria))
->collect(function($c) use($view) { return $c->describeOn($view); })
->getArrayCopy());
}
protected function _addCustomCriteriaFor($class_name, $params) {
$model = Class_CustomField_Model::getModel($class_name);
foreach($model->getFields() as $field)
$this->_criteria[] = Class_SearchCriteria_CustomField::newWith($params, $field);
return $this;
}
protected function _adoptSearchParams($other) {
$other->_buildSearchParams();
$this->_search_params = $other->_search_params;
$this->_has_no_result = $other->_has_no_result;
return $this;
}
}
......@@ -40,13 +40,13 @@ abstract class Class_SearchCriteria_Abstract {
}
protected function buildElement() {
return new Zend_Form_Element_Hidden($this->getName(), ['value' => $this->_value]);
public function getElement() {
return $this->_element;
}
public function getElement() {
return $this->_element;
public function buildElement() {
return new Zend_Form_Element_Hidden($this->getName(), ['value' => $this->_value]);
}
......
<?php
/**
* Copyright (c) 2012-2019, 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 Class_SearchCriteria_CustomField extends Class_SearchCriteria_Abstract {
const FIELD_PREFIX = 'field_';
protected
$_params,
$_field,
$_strategy;
public static function newWith($params, $field) {
$type = $field->getFieldType();
$map = [Class_CustomField_Meta::SELECT => 'Multi',
Class_CustomField_Meta::MULTI_CHECKBOX => 'Multi',
Class_CustomField_Meta::DATE => 'DateRange'];
$class_name = 'Class_SearchCriteria_CustomField_'
. ((in_array($type, array_keys($map))
? $map[$type]
: 'Text'));
$criteria = (new $class_name($params))
->setField($field)
->init();
return $criteria;
}
public function __construct($params) {
$this->_params = $params;
}
public function setField($field) {
$this->_field = $field;
return $this;
}
public function init() {
if (!$this->_field)
return $this;
$this->_name = static::FIELD_PREFIX . $this->_field->getId();
if (isset($this->_params[$this->getName()]))
$this->_value = $this->_params[$this->getName()];
$this->_element = $this->buildElement();
return $this;
}
public function acceptSearchVisitor($visitor) {
if (!$this->_shouldSearch())
return;
$params = array_merge($this->_findAllByValueParams(),
['custom_field_id' => $this->_field->getId()]);
$values = new Storm_Model_Collection(Class_CustomField_Value::findAllBy($params));
if (!$values->isEmpty())
return $visitor->addWhereParam('id in (' . implode(',', $values->collect('model_id')->getArrayCopy()) . ')');
$visitor->hasNoResult();
}
protected function _shouldSearch() {
return $this->_value;
}
protected function _findAllByValueParams() {
return [];
}
}
<?php
/**
* Copyright (c) 2012-2019, 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 Class_SearchCriteria_CustomField_DateRange extends Class_SearchCriteria_CustomField {
const CAST_VALUE_TO_DATE = 'str_to_date(value, "%d/%m/%Y")';
protected
$_customized_daterange,
$_where_params = [];
public function buildElement() {
$params = $this->_params;
$params['name'] = $this->_name;
$this->_customized_daterange = new Class_SearchCriteria_CustomField_CustomizedDateRange($params);
return $this->_customized_daterange->getElement()->setLabel($this->_field->getLabel());
}
public function getCompositeValues() {
return $this->_customized_daterange->getCompositeValues();
}
protected function _shouldSearch() {
$this->_customized_daterange->acceptSearchVisitor($this);
return $this->_where_params;
}
protected function _findAllByValueParams() {
$wheres = static::CAST_VALUE_TO_DATE . ' is not null and '
. implode(' and ', $this->_where_params);
return ['where' => $wheres];
}
public function addWhereParam($param) {
$this->_where_params[] = str_replace($this->_name, static::CAST_VALUE_TO_DATE, $param);
return $this;
}
}
class Class_SearchCriteria_CustomField_CustomizedDateRange
extends Class_SearchCriteria_DateRange {
public function __construct($params) {
$this->_name = $params['name'];
unset($params['name']);
parent::__construct($params);
}
}
<?php
/**
* Copyright (c) 2012-2019, 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 Class_SearchCriteria_CustomField_Multi extends Class_SearchCriteria_CustomField {
public function buildElement() {
$multioptions=[];
foreach ($this->_field->getOptionsListAsArray() as $option)
$multioptions[$option] = $option;
return new Zend_Form_Element_MultiCheckbox($this->getName(),
['label' => $this->_field->getLabel(),
'value' => $this->_value,
'multiOptions' => $multioptions]);
}
protected function _findAllByValueParams() {
return ['value' => $this->_value];
}
}
<?php
/**
* Copyright (c) 2012-2019, 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 Class_SearchCriteria_CustomField_Text extends Class_SearchCriteria_CustomField {
public function buildElement() {
$element = new Zend_Form_Element_Text($this->getName(),
['label' => $this->_('%s contient',
$this->_field->getLabel()),
'value' => $this->_value,
'size' => 35]);
$previous = $this->_value;
$this->_value = trim((new Zend_Filter_Alnum(true))->filter($this->_value));
$element->setValue($this->_value);
if ($previous != $this->_value)
$element->addError($this->_('Les caractères non alphanumériques ont été filtrés'));
return $element;
}
protected function _findAllByValueParams() {
return ['where' => 'value like "%' . $this->_value . '%"'];
}
}
......@@ -60,7 +60,7 @@ class Class_SearchCriteria_DateRange extends Class_SearchCriteria_Abstract {
}
protected function buildElement() {
public function buildElement() {
return new ZendAfi_Form_Element_DateRangePicker($this->getName(),
['start' => ['name' => $this->_start_name],
'end' => ['name' => $this->_end_name]]);
......
......@@ -23,7 +23,7 @@
class Class_SearchCriteria_Select extends Class_SearchCriteria_Abstract {
protected $_value = Class_SearchCriteria_Abstract::DEFAULT_VALUE;
protected function buildElement() {
public function buildElement() {
return new Zend_Form_Element_Select($this->getName(), ['value' => $this->_value]);
}
......
<?php
/**
* Copyright (c) 2012-2019, 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 Class_SearchCriteria_TextLike extends Class_SearchCriteria_Abstract {
public function buildElement() {
$element = new Zend_Form_Element_Text($this->getName(),
['size' => 35]);
$previous = $this->_value;
$this->_value = trim((new Zend_Filter_Alnum(true))->filter($this->_value));
$element->setValue($this->_value);
if ($previous != $this->_value)
$element->addError($this->_('Seuls les caractères alphanumériques sont autorisés'));
return $element;
}
public function acceptSearchVisitor($visitor) {
if (!$this->_value)
return;
$visitor->addWhereParam($this->_name . ' like "%' . $this->_value . '%"');
}
}
......@@ -30,8 +30,16 @@ class Class_TableDescription_RendezVous extends Class_TableDescription {
'sort_attribute' => 'end_time'])
->addColumn($this->_('Lieu'), ['attribute' => 'location_label',
'sort_attribute' => 'location_id'])
->addColumn($this->_('Autres informations'),
['callback' => [$this, 'renderCustomFieldsOn'],
'sortable' => false])
->addColumn($this->_('Notifications'), ['attribute' => 'notification_status',
'sortable' => false])
->addRowPluginsActions();
}
public function renderCustomFieldsOn($model, $attribute, $canvas) {
return $model->getComment(). $canvas->getView()->customFields($model);
}
}
<?php
/**
* Copyright (c) 2012-2019, 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 Class_TableDescription_RendezVousExport extends Class_TableDescription {
public function init() {
$this
->addAgendaColumns()
->addRendezVousColumns();
}
public function addAgendaColumns() {
return $this
->addColumn($this->_('Agenda'), 'agenda_label')
->addColumn($this->_('Participants'), ['callback'=> [$this,'renderUsers']])
->addCustomFieldsColumnsOf('Class_UserGroup_Agenda', 'renderAgendaCustomField');
}
public function addRendezVousColumns() {
return $this