Commit 118775bc authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch 'dev#91960_bdp_yonne_custom_fields_sur_agenda_rdv' into 'WIP'

cdev#91960 : rendez-vous : add custom fields

See merge request afi/opacce!3136
parents 0c65e76f c1d6d9d3
- ticket #91960 : BDP Yonne : Custom fields sur Agenda + rdv
\ No newline at end of file
......@@ -62,7 +62,7 @@ class Class_CustomField extends Storm_Model_Abstract {
'role' => 'field',
'dependents' => 'delete']],
$_default_attribute_values = ['priority' => 0],
$_forwarded_to_meta = ['label', 'field_type', 'options_list', 'indexable'];
$_forwarded_to_meta = ['label', 'field_type', 'options_list', 'indexable', 'option'];
public function __call($method, $args) {
......
......@@ -26,6 +26,7 @@ class Class_CustomField_Meta extends Storm_Model_Abstract {
const
TEXT_INPUT = 'text',
TEXT_AREA = 'textarea',
DATE = 'datePicker',
MULTI_CHECKBOX = 'multiCheckbox',
CKEDITOR = 'ckeditor',
SELECT = 'select',
......@@ -64,7 +65,8 @@ class Class_CustomField_Meta extends Storm_Model_Abstract {
self::TEXT_AREA => $this->_('Zone de texte simple'),
self::CKEDITOR => $this->_('Zone de texte HTML'),
self::SELECT => $this->_('Liste d\'options'),
self::MULTI_CHECKBOX => $this->_('Cases à cocher')];
self::MULTI_CHECKBOX => $this->_('Cases à cocher'),
self::DATE => $this->_('Date')];
}
......@@ -75,6 +77,16 @@ class Class_CustomField_Meta extends Storm_Model_Abstract {
}
public function setOption($options) {
$this->setOptionsList(implode(';',$options));
return $this;
}
public function getOption() {
return $this->getOptionsListAsArray();
}
public function getFieldTypeLabel() {
return $this->getFieldTypes()[$this->getFieldType()];
}
......
......@@ -48,6 +48,12 @@ class Class_CustomField_Model {
new Class_CustomField_ModelConfiguration_Article(),
new Class_CustomField_ModelConfiguration_Activity(),
new Class_CustomField_ModelConfiguration_UserGroup(),
new Class_CustomField_ModelConfiguration_UserGroupAgenda(),
new Class_CustomField_ModelConfiguration('RendezVous',
$translator->_('Rendez-vous'),
['module' => 'admin',
'controller' => 'rendezvous',
'action' => 'edit']),
new Class_CustomField_ModelConfiguration_Sitotheque(),
new Class_CustomField_ModelConfiguration('SessionActivity',
$translator->_('Session'),
......
<?php
/**
* Copyright (c) 2012-2014, 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_CustomField_ModelConfiguration_UserGroupAgenda extends Class_CustomField_ModelConfiguration_UserGroup {
public function __construct() {
$this->_class_name = 'UserGroup_Agenda';
$this->_label = $this->_('Agenda');
$this->_edit_url = [
'module' => 'admin',
'controller' => 'usergroup-agenda',
'action' => 'edit'];
}
}
?>
\ No newline at end of file
......@@ -33,7 +33,7 @@ class RendezVousLoader extends Storm_Model_Loader {
class Class_RendezVous extends Storm_Model_Abstract {
use Trait_Translator, Trait_TimeSource;
use Trait_Translator, Trait_TimeSource, Trait_CustomFields;
protected $_table_name = 'rendez_vous';
protected $_loader_class = 'RendezVousLoader';
......
<?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
*/
/**
* required by customfields mechanics based upon class name
*/
class Class_UserGroup_Agenda extends Class_UserGroup {
}
\ No newline at end of file
......@@ -23,7 +23,7 @@
class ZendAfi_Controller_Plugin_ResourceDefinition_UsergroupAgenda extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract {
public function getDefinitions() {
return ['model' => ['class' => 'Class_UserGroup',
return ['model' => ['class' => 'Class_UserGroup_Agenda',
'name' => 'group',
'order' => 'libelle',
'filter' => ['model_class' => 'Class_RendezVous']],
......
......@@ -50,28 +50,36 @@ class ZendAfi_Form_Admin_CustomFields extends ZendAfi_Form {
'required' => true,
'allowEmpty' => false])
->addElement($checkbox)
->addElement('text',
->addElement('multiInput',
'options_list',
['label' => $this->_('Options pour le type "liste d\'options"'),
'size' => 50,
'placeholder' => $this->_('option 1; option 2; option 3')])
'fields' => [ ['name' => 'option',
'label' => $this->_('Libellé')]],
])
->addElement($checkbox)
->addDisplayGroup(['label', 'field_type', 'indexable'], 'base', ['legend' => ''])
->addDisplayGroup(['options_list'], 'options_group', ['legend' => $this->_('Options')]);
->addUniqDisplayGroup('base');
}
public function setDefault($name, $value) {
if ($name !== 'options_list')
return parent::setDefault($name, $value);
$this->getElement('options_list')->setValues([ 'option' => explode(';', $value) ]);
return $this;
}
protected function _toggleOptionsList() {
Class_ScriptLoader::getInstance()
->addJQueryBackEnd('formSelectToggleVisibilityForElement("#field_type", "#fieldset-options", ["' . Class_CustomField_Meta::SELECT . '","' . Class_CustomField_Meta::MULTI_CHECKBOX . '"]);');
->addJQueryBackEnd('formSelectToggleVisibilityForElement("#field_type", $("#multi_inputs_options_list").closest("tr"), ["' . Class_CustomField_Meta::SELECT . '","' . Class_CustomField_Meta::MULTI_CHECKBOX . '"]);');
return $this;
}
public function getFieldTypeLabel($fieldType) {
return (new Class_CustomField_Meta())->getFieldTypes()[$fieldType];
}
}
\ No newline at end of file
......@@ -42,7 +42,7 @@ class ZendAfi_Form_Admin_CustomFields_ModelValues extends ZendAfi_Form {
$field_names []= $field_name = self::FIELD_PREFIX.$value->getCustomFieldId();
ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy::strategyForValue($this, $value)
->addElement($value, $field_name, $value->getValue());
->addElement($value, $field_name, $value->getValue());
}
$this->addDisplayGroup($field_names, 'custom_fields', []);
......@@ -62,14 +62,21 @@ class ZendAfi_Form_Admin_CustomFields_ModelValues extends ZendAfi_Form {
class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy {
protected $_form,
protected
$_form,
$_field;
public static function strategyForValue($form, $value) {
$field_strategy = 'ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_'.$value->getFieldType();
$type = $value->getFieldType();
$field_strategy = (in_array($type, [Class_CustomField_Meta::MULTI_CHECKBOX,
Class_CustomField_Meta::SELECT]))
? 'ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_' . $type
: 'ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy';
return new $field_strategy($form);
}
public function __construct($form) {
$this->_form = $form;
}
......@@ -91,36 +98,21 @@ class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy {
protected function getOptions() {
return [];
}
}
class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_text extends ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy {
protected function getOptions() {
return ['size' => 35];
}
}
class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_textarea extends ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy {
protected function getOptions() {
return ['cols' => 35, 'rows' => 10];
}
}
$type = $this->_field->getFieldType();
if (Class_CustomField_Meta::TEXT_INPUT == $type)
return ['size' => 35];
if (in_array($type, [Class_CustomField_Meta::TEXT_AREA, Class_CustomField_Meta::CKEDITOR]))
return ['cols' => 35, 'rows' => 10];
class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_ckeditor extends ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy {
protected function getOptions() {
return ['cols' => 35, 'rows' => 10];
return [];
}
}
class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_select extends ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy {
class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_select
extends ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy {
protected function getOptions() {
$options = $this->_field->getOptionsListAsArray();
......@@ -136,7 +128,8 @@ class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_select extends
class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_multiCheckbox extends ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy {
class ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy_multiCheckbox
extends ZendAfi_Form_Admin_CustomFields_ModelValues_Field_Strategy {
protected function getOptions() {
$options = $this->_field->getOptionsListAsArray();
......
......@@ -80,6 +80,13 @@ abstract class CustomFieldControllerTestCase extends AbstractControllerTestCase
'field_type' => Class_CustomField_Meta::CKEDITOR,
'model' => 'UserGroup']);
$this->fixture('Class_CustomField',
['id' => 8,
'priority' => 6,
'label' => 'Starting date',
'field_type' => Class_CustomField_Meta::DATE,
'model' => 'UserGroup']);
$this->fixture('Class_UserGroup',
['id' => 1,
'libelle' => 'Teachers']);
......@@ -127,6 +134,12 @@ class CustomFieldsControllerIndexTest extends CustomFieldControllerTestCase {
}
/** @test */
public function rendezVousShouldBeCustomFields() {
$this->assertXPathContentContains('//a[@class="containerTriggerer"]', 'Rendez-vous');
}
/** @test */
public function treeSelectShouldBeDisplay() {
$this->assertXpath('//div[@class="treeView"]');
......@@ -368,14 +381,14 @@ class CustomFieldsControllerEditIndexTest extends CustomFieldControllerTestCase
/** @test */
public function optionsListShouldBeEmpty() {
$this->assertXPath('//input[@name="options_list"][@value=""]');
public function optionListShouldBeEmpty() {
$this->assertNotXPath('//div[@id="multi_input"]//input');
}
/** @test */
public function scriptToggleOptionsListShouldBePresent() {
$this->assertXPathContentContains('//script', 'formSelectToggleVisibilityForElement("#field_type", "#fieldset-options", ["' . Class_CustomField_Meta::SELECT . '","' . Class_CustomField_Meta::MULTI_CHECKBOX . '"]);', $this->_response->getBody());
$this->assertXPathContentContains('//script', 'formSelectToggleVisibilityForElement("#field_type", $("#multi_inputs_options_list").closest("tr"), ["' . Class_CustomField_Meta::SELECT . '","' . Class_CustomField_Meta::MULTI_CHECKBOX . '"]);', $this->_response->getBody());
}
}
......@@ -387,9 +400,12 @@ class CustomFieldsControllerPostEditActionTest extends CustomFieldControllerTest
$this->postDispatch('admin/custom-fields/edit/model/Article/id/1',
['label' => 'public',
'field_type' => 'SELECT',
'options_list' => 'all; teens',
'field_type' => 'select',
'option' => ['all','teens'],
'model' => 'Article']);
Class_CustomField::clearCache();
Class_CustomField_Meta::clearCache();
}
......@@ -407,6 +423,33 @@ class CustomFieldsControllerPostEditActionTest extends CustomFieldControllerTest
class CustomFieldsControllerPostFailEditActionTest extends CustomFieldControllerTestCase {
public function setUp() {
parent::setUp();
$this->postDispatch('admin/custom-fields/edit/model/Article/id/1',
['label' => '',
'field_type' => 'select',
'option' => ['all','teens'],
'model' => 'Article']);
}
/** @test */
public function responseShouldNotRedirect() {
$this->assertNotRedirect();
}
/** @test */
public function optionsListShouldKeepPostedValues() {
$this->assertXPathContentContains('//script','values:{"option":["all","teens"]}');
}
}
class CustomFieldsControllerSelectActionTest extends CustomFieldControllerTestCase {
public function setUp() {
parent::setUp();
......@@ -440,14 +483,14 @@ class CustomFieldsControllerUpDownActionTest extends CustomFieldControllerTestCa
public function updownForFieldExpectedOrder() {
// at start we have: Address, Age, Status
return [
['down', 3, ['Age', 'Address', 'Status', 'Zip code','Notes']],
['down', 4, ['Address', 'Status', 'Age', 'Zip code','Notes']],
['down', 6, ['Address', 'Age', 'Status','Notes' , 'Zip code']],
['down', 0, ['Address', 'Age', 'Status', 'Zip code','Notes']],
['up', 0, ['Address', 'Age', 'Status', 'Zip code','Notes']],
['up', 4, ['Age', 'Address', 'Status', 'Zip code','Notes']],
['up', 5, ['Address', 'Status', 'Age', 'Zip code','Notes']]
['down', 3, ['Age', 'Address', 'Status', 'Zip code','Notes','Starting date']],
['down', 4, ['Address', 'Status', 'Age', 'Zip code','Notes','Starting date']],
['down', 6, ['Address', 'Age', 'Status','Notes' , 'Zip code','Starting date']],
['down', 0, ['Address', 'Age', 'Status', 'Zip code','Notes','Starting date']],
['up', 0, ['Address', 'Age', 'Status', 'Zip code','Notes','Starting date']],
['up', 4, ['Age', 'Address', 'Status', 'Zip code','Notes','Starting date']],
['up', 5, ['Address', 'Status', 'Age', 'Zip code','Notes','Starting date']]
];
}
......@@ -528,6 +571,12 @@ class CustomFieldsControllerValuesForUserGroupTeachersTest extends CustomFieldCo
}
/** @test */
public function inputForDateShouldBePresent() {
$this->assertXPath('//form//fieldset//input[@name="field_8"]',$this->_response->getBody());
}
/** @test */
public function textAreaForAgeShouldBePresentAndContains25() {
$this->assertXPathContentContains('//form//fieldset//textarea[@name="field_4"]',
......
......@@ -202,6 +202,12 @@ class CustomFieldsMetaControllerAddActionTest extends CustomFieldsMetaController
public function shouldNotBeIndexable() {
$this->assertNotXPath('//input[@name="indexable"][@checked="checked"]');
}
/** @test */
public function typeDeChampsShouldContainsDate() {
$this->assertXPathContentContains('//select[@name="field_type"]/option', 'Date',$this->_response->getBody());
}
}
......@@ -213,7 +219,8 @@ class CustomFieldsMetaControllerPostEditActionTest extends CustomFieldsMetaContr
$this->postDispatch('admin/custom-fields-meta/edit/id/1',
['label' => 'public',
'field_type' => Class_CustomField_Meta::SELECT,
'options_list' => 'teens; parents ; all public ; ',
'option' => ['teens','parents',
'all public'],
'indexable' => 1]);
$this->meta = Class_CustomField_Meta::find(1);
......@@ -279,7 +286,9 @@ class CustomFieldsMetaControllerPostEditUnindexActionTest
$this->postDispatch('admin/custom-fields-meta/edit/id/1',
['label' => 'public',
'field_type' => Class_CustomField_Meta::SELECT,
'options_list' => 'teens;parents;all public',
'option' => ['teens',
'parents',
'all public'],
'indexable' => 0]);
$this->meta = Class_CustomField_Meta::find(1);
......@@ -381,7 +390,9 @@ class CustomFieldsMetaControllerDeleteAddressFieldEditTest extends CustomFieldsM
$this->postDispatch('admin/custom-fields-meta/edit/id/1',
['label' => 'un autre public',
'field_type' => Class_CustomField_Meta::SELECT,
'options_list' => 'teens; parents ; all public ; ',
'option' => ['teens',
'parents',
'all public'],
'indexable' => 1]);
}
......
......@@ -74,7 +74,7 @@ class DatasControllerTest extends AbstractControllerTestCase {
/** @test */
public function fieldsOfSessionActivityShouldReturnJson() {
$this->dispatch('/opac/datas/fields/model/SessionActivity');
$this->assertBody('[{"priority":0,"id":19,"model":"SessionActivity","meta_id":1,"label":"th\u00e9matique","field_type":"text","options_list":"","indexable":0}]');
$this->assertBody('[{"priority":0,"id":19,"model":"SessionActivity","meta_id":1,"label":"th\u00e9matique","field_type":"text","options_list":"","indexable":0,"option":[]}]');
}
......
......@@ -59,8 +59,8 @@ abstract class UsergroupAgendaAdminModoPortailLoggedTestCase extends Admin_Abstr
parent::setUp();
Class_AdminVar::set('ENABLE_RENDEZ_VOUS', 1);
$group = $this->fixture('Class_UserGroup', ['id' => 4,
'libelle'=>"UtilisateursRendezvous"]);
$group = $this->fixture('Class_UserGroup_Agenda', ['id' => 4,
'libelle'=>"UtilisateursRendezvous"]);
$group->addRight(Class_UserGroup::RIGHT_USER_RENDEZ_VOUS);
$user = $this->fixture('Class_Users',
......@@ -79,7 +79,7 @@ abstract class UsergroupAgendaAdminModoPortailLoggedTestCase extends Admin_Abstr
class UsergroupAgendaAdminIndexValidTest extends UsergroupAgendaAdminModoPortailLoggedTestCase {
public function setUp() {
parent::setUp();
$groupagenda = $this->fixture('Class_UserGroup',
$groupagenda = $this->fixture('Class_UserGroup_Agenda',
['id'=> 5,
'libelle'=> 'MonAgenda',
'model_class' => 'Class_RendezVous']);
......@@ -110,7 +110,7 @@ class UsergroupAgendaAdminIndexValidTest extends UsergroupAgendaAdminModoPortail
/** @test */
public function listAgendaShouldContainMonAgenda() {
$this->assertXPathContentContains('//td','MonAgenda');
$this->assertXPathContentContains('//td','MonAgenda', $this->_response->getBody());
}
......@@ -138,13 +138,13 @@ class UsergroupAgendaAdminDeleteTest extends UsergroupAgendaAdminModoPortailLogg
public function setUp() {
parent::setUp();
$this->fixture('Class_UserGroup', ['id' => 43,
'model_class'=> 'Class_RendezVous',
'libelle' => "MonSuperAgenda"]);
$this->fixture('Class_UserGroup_Agenda', ['id' => 43,
'model_class'=> 'Class_RendezVous',
'libelle' => "MonSuperAgenda"]);
$this->fixture('Class_RendezVous',
['id' => 4,
'agenda' => Class_UserGroup::find(43),
'agenda' => Class_UserGroup_Agenda::find(43),
'location' => $this->fixture('Class_Lieu',
['id' => 8,
'libelle' => 'Bellevue']),
......@@ -159,7 +159,7 @@ class UsergroupAgendaAdminDeleteTest extends UsergroupAgendaAdminModoPortailLogg
/** @test */
public function agendaShouldBeDeleted() {
$this->assertNull(Class_UserGroup::find(43));
$this->assertNull(Class_UserGroup_Agenda::find(43));
}
......@@ -534,7 +534,7 @@ class UsergroupAgendaAdminPostAddActionTest extends UsergroupAgendaAdminModoPort
'users' => '999-35-888']);
Class_UserGroup::resetCache();
$this->_created_group = Class_UserGroup::find(5);
$this->_created_group = Class_UserGroup_Agenda::find(5);
}
......@@ -572,7 +572,7 @@ class UsergroupAgendaAdminEditActionTest
'password' => 's3cr3t \o/',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
$this->fixture('Class_UserGroup',
$this->fixture('Class_UserGroup_Agenda',
['id'=> 45,
'libelle'=> 'MonAgenda',
'model_class' => 'Class_RendezVous',
......
Markdown is supported
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