diff --git a/library/Class/Template.php b/library/Class/Template.php index 6c3bd1ff3cad1b92caddd8cbd8e76b9ec5811118..5ddbd9bdef4d7d0e6b18714090616551b0526451 100644 --- a/library/Class/Template.php +++ b/library/Class/Template.php @@ -291,7 +291,7 @@ class Class_Template { } - public function upgradePost($post) { + public function handleMappings($post) { return $post; } diff --git a/library/ZendAfi/Controller/Plugin/Manager/Template.php b/library/ZendAfi/Controller/Plugin/Manager/Template.php index 026faf161a7e93e17d50aac53aac35f52424cd6a..3f4cdcee2b4638befbd15f49f5bdb9955683406d 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Template.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Template.php @@ -68,6 +68,6 @@ class ZendAfi_Controller_Plugin_Manager_Template extends ZendAfi_Controller_Plug protected function _getPost($key = null, $default = null) { - return Class_Template::current()->upgradePost(parent::_getPost($key, $default)); + return Class_Template::current()->handleMappings(parent::_getPost($key, $default)); } } \ No newline at end of file diff --git a/library/templates/Intonation/Library/FormCustomizer/Abstract.php b/library/templates/Intonation/Library/FormCustomizer/Abstract.php index 58e52d65efccb69da564b891b2ba9d362bdb89c9..1917520eac36387d54f1aceeefce42dab267fc43 100644 --- a/library/templates/Intonation/Library/FormCustomizer/Abstract.php +++ b/library/templates/Intonation/Library/FormCustomizer/Abstract.php @@ -241,24 +241,17 @@ class Intonation_Library_FormCustomizer_Abstract { protected function _addHydratingMappingGroupTo() { - $values = $this->_template->getHydratingMapping(); + if (!$maps = $this->_template->getHydratingMappingMap()) + return $this; - $this->_form - ->addElement('multiInput', - $this->_template->withNameSpace('hydrating_mapping'), - ['label' => $this->_('Table de correspondance'), - 'fields' => [['name' => $this->_template->withNameSpace('hydrating_mapping_dry'), - 'label' => $this->_('sélecteur')], - ['name' => $this->_template->withNameSpace('hydrating_mapping_hydrated'), - 'label' => $this->_('hydraté par')]], - 'values' => [$this->_template->withNameSpace('hydrating_mapping_dry') => array_keys($values), - $this->_template->withNameSpace('hydrating_mapping_hydrated') => array_values($values)], - 'deleteMessage' => $this->_('cette règle')]) + foreach($maps as $map) + $this->_addMultiInput($map); + $this->_form ->addDisplayGroup(array_map(function($element) { return $this->_template->withNameSpace($element); - }, ['hydrating_mapping']), + }, array_keys($maps)), $this->_template->withNameSpace('hydrating_mapping_group'), ['legend' => $this->_('Thème %s : bootstrap', $this->_template->getId()), 'order' => static::SECOND]); @@ -291,7 +284,7 @@ class Intonation_Library_FormCustomizer_Abstract { $this->_form ->addElement('multiInput', $this->_template->withNameSpace($map->getColumn()), - ['label' => $this->_('Table de correspondance'), + ['label' => $this->_('Table de correspondances'), 'fields' => [['name' => $map->getSource(), 'label' => $map->getSourceLabel()], ['name' => $map->getDestination(), diff --git a/library/templates/Intonation/Library/Settings.php b/library/templates/Intonation/Library/Settings.php index b42554159b22c774d82944ad1a2f3f7ce48deb74..f63769ea1983b9f38b1488cdfe2da3a3721e3689 100644 --- a/library/templates/Intonation/Library/Settings.php +++ b/library/templates/Intonation/Library/Settings.php @@ -143,110 +143,4 @@ class Intonation_Library_Settings extends Intonation_System_Abstract { }, array_keys($this->_default_settings)), $this->_default_settings); } - - - public function customizePostData($post) { - $dry = []; - if(isset($post['IntonationHydratingMappingDry'])) { - $dry = $post['IntonationHydratingMappingDry']; - unset($post['IntonationHydratingMappingDry']); - } - - $hydrated = []; - if(isset($post['IntonationHydratingMappingHydrated'])) { - $hydrated = $post['IntonationHydratingMappingHydrated']; - unset($post['IntonationHydratingMappingHydrated']); - } - - if(!$hydrated || !$dry) - return $post; - - $post['IntonationHydratingMapping'] = array_combine($dry, $hydrated); - return $post; - } - - - public function getIconsMapping() { - $columns = ['icons_map_doc_types' => $this->_('Types de documents'), - 'icons_map_library' => $this->_('Bibliothèque')]; - - $mapping = []; - foreach ($columns as $column => $label) - $mapping [$column] = new Class_Entity(['Column' => $column, - 'Source' => $this->withNameSpace($column . '_source'), - 'SourceLabel' => $label, - 'Destination' => $this->withNameSpace($column . '_destination'), - 'DestinationLabel' => $this->_('Icon'), - 'DeleteMessage' => $this->_('Supprimer cette correspondance')]); - - return $mapping; - } - - - public function getWidgets() { - return [Intonation_Library_Widget_Nav_Definition::CODE => new Intonation_Library_Widget_Nav_Definition, - Intonation_Library_Widget_Breadcrumb_Definition::CODE => new Intonation_Library_Widget_Breadcrumb_Definition, - Intonation_Library_Widget_Notify_Definition::CODE => new Intonation_Library_Widget_Notify_Definition, - Intonation_Library_Widget_Login_Definition::CODE => new Intonation_Library_Widget_Login_Definition, - Intonation_Library_Widget_Search_Definition::CODE => new Intonation_Library_Widget_Search_Definition, - Intonation_Library_Widget_Accessibility_Definition::CODE => new Intonation_Library_Widget_Accessibility_Definition, - Intonation_Library_Widget_Share_Definition::CODE => new Intonation_Library_Widget_Share_Definition, - Intonation_Library_Widget_Image_Definition::CODE => new Intonation_Library_Widget_Image_Definition, - Intonation_Library_Widget_AdminTools_Definition::CODE => new Intonation_Library_Widget_AdminTools_Definition, - Intonation_Library_Widget_Credits_Definition::CODE => new Intonation_Library_Widget_Credits_Definition, - Intonation_Library_Widget_Scroll_Definition::CODE => new Intonation_Library_Widget_Scroll_Definition, - Intonation_Library_Widget_Carousel_Record_Definition::CODE => new Intonation_Library_Widget_Carousel_Record_Definition, - ]; - } - - - public function handleFooter() { - return true; - } - - - public function hydrate($attribs, $name) { - if('opac' != Class_Url::getModuleName()) - return $attribs; - - $existing_classes = isset($attribs['class']) - ? $attribs['class'] - : ''; - - $hydrated_classes = $this->_getHydrateClasses($attribs, $name); - - $attribs['class'] = trim(implode(' ', - [$existing_classes, - $hydrated_classes])); - - return $attribs; - } - - - protected function _getHydrateClasses($attribs, $name) { - $hydrating_mapping = $this->getHydratingMapping(); - if(!is_array($attribs)) - return ''; - - foreach($attribs as $key => $value) { - $dry_key = implode(' ', [$name, $key, $value]); - if(isset($hydrating_mapping[$dry_key])) - return $hydrating_mapping[$dry_key]; - } - - foreach($attribs as $key => $value) { - if($values = array_filter(explode(' ', $value))) { - foreach($values as $value) { - $dry_key = implode(' ', [$name, $key, $value]); - if(isset($hydrating_mapping[$dry_key])) - return $hydrating_mapping[$dry_key]; - } - } - } - - if(isset($hydrating_mapping[$name])) - return $hydrating_mapping[$name]; - - return ''; - } } \ No newline at end of file diff --git a/library/templates/Intonation/System/Template.php b/library/templates/Intonation/System/Template.php deleted file mode 100644 index 5d79143edd0d994085c003b3e9e4b3f55632adfd..0000000000000000000000000000000000000000 --- a/library/templates/Intonation/System/Template.php +++ /dev/null @@ -1,143 +0,0 @@ -<?php -/** - * Copyright (c) 2012-2017, 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_System_Template extends Intonation_System_Abstract { - protected $_template; - protected $_default_settings = ['core_css' => 1, - 'core_js' => 1, - 'font_awesome_css' => 1, - 'jquery' => 1, - 'jquery_ui' => 1, - 'bootstrap_css' => 1, - 'bootstrap_js' => 1, - 'bootstrap_dependency_popper' => 1, - 'intonation_css' => 1, - 'custom_css_url' => [], - 'custom_js_url' => [], - - 'custom_css_class' => ['blue', - 'red', - 'transparent', - 'card', - 'col', - 'container-fluid', - 'row', - 'mr-auto', - 'ml-auto' - ], - - 'hydrating_mapping' => ['div id site_web_wrapper' => 'container align-self-center', - 'div id site_web_content_wrapper' => 'row justify-content-center', - 'div class section_wrapper' => 'container-fluid', - 'div class section_content_wrapper' => 'row no-gutters', - 'div class widget' => 'card', - 'div class widget-header' => 'card-header', - 'div class widget-body' => 'card-body', - 'div class widget-footer' => 'card-footer', - 'label' => 'col-5 col-form-label col-form-label-sm', - 'label class multi-element-label' => 'col-form-label col-form-label-sm', - 'input' => 'form-control form-control-sm', - 'input data-spambots true' => '', - 'input type checkbox' => 'form-check-input form-check-input-sm mr-1', - 'input type submit' => 'btn btn-sm btn-primary', - 'select' => 'form-control form-control-sm custom-select', - 'button' => 'btn btn-secondary', - 'button class btn' => '', - 'button class accessibility' => 'btn btn-light', - 'button type submit' => 'btn btn-primary', - 'fieldset' => 'form-group row', - 'table' => 'table table-stripped table-hover table-responsive-md table-sm', - 'thead' => 'thead-dark', - 'img' => 'img-fluid rounded', - 'dl' => 'row', - 'dt' => 'col-3', - 'dd' => 'col-9', - 'a' => 'btn-link', - 'a class account-loans' => 'list-group-item-info', - 'ul' => 'list-unstyled', - 'form class indent-form' => 'px-4 py-1', - ], - - 'icons_map_doc_types' => ['0' => 'class far fa-question-circle', - '1' => 'class fas fa-book', - '2' => 'class fas fa-newspaper', - '3' => 'class fas fa-compact-disc', - '4' => 'class fas fa-video', - '5' => 'class fas fa-keyboard', - '8' => 'class fas fa-align-left', - '9' => 'class fas fa-rss-square', - '10' => 'class fas fa-link'], - - 'icons_map_library' => ['author' => 'class fas fa-user'], - - ]; - - - public function __construct($template) { - $this->_template = $template; - - $settings = ($settings = Class_Template_Settings::findFirstBy(['template' => $this->_template->getId()])) - ? $settings - : Class_Template_Settings::newInstance(); - - $this->setSettings($settings); - } - - - public function getHtmlAttribs() { - return ['id' => 'site_web_wrapper', - 'class' => $this->_getResponsiveWidths()]; - } - - - protected function _injectDefaultSettings() { - $this->_settings->setTemplate($this->_template->getId()); - $this->_initSettings(); - return $this; - } - - - protected function _initSettings() { - $local_settings = $this->_settings->getSettingsInstance()->toArray(); - $defaults_settings = $this->_getDefaultSettings(); - - if(!array_diff_key($defaults_settings, $local_settings)) - return $this; - - $local_settings = array_merge($defaults_settings, - $local_settings); - - $this->_settings->setSettings(serialize($local_settings)); - $this->_settings->save(); - return $this; - } - - - protected function _getDefaultSettings() { - return array_combine( - array_map(function($name) - { - return $this->_template->withNameSpace($name); - }, array_keys($this->_default_settings)), - $this->_default_settings); - } -} \ No newline at end of file diff --git a/library/templates/Intonation/Template.php b/library/templates/Intonation/Template.php index b93f3dc5337ec3025e92dd09e62ec170092deb9b..f1cd720a09cdf0b61830fe828d6a6e2c47173a0b 100644 --- a/library/templates/Intonation/Template.php +++ b/library/templates/Intonation/Template.php @@ -68,8 +68,8 @@ class Intonation_Template extends Class_Template { $hydrated_classes = $this->_getHydrateClasses($attribs, $name); $attribs['class'] = trim(implode(' ', - [$existing_classes, - $hydrated_classes])); + [$existing_classes, + $hydrated_classes])); return $attribs; } @@ -176,39 +176,56 @@ class Intonation_Template extends Class_Template { } - public function upgradePost($post) { - $dry = []; - if(isset($post['IntonationHydratingMappingDry'])) { - $dry = $post['IntonationHydratingMappingDry']; - unset($post['IntonationHydratingMappingDry']); - } + public function handleMappings($post) { + $post = parent::handleMappings($post); - $hydrated = []; - if(isset($post['IntonationHydratingMappingHydrated'])) { - $hydrated = $post['IntonationHydratingMappingHydrated']; - unset($post['IntonationHydratingMappingHydrated']); - } + $maps = array_merge($this->getHydratingMappingMap(), + $this->getIconsMapping()); - if(!$hydrated || !$dry) - return $post; + foreach($maps as $map) { + $source = isset($post[$map->getSource()]) + ? $post[$map->getSource()] + : []; + unset($post[$map->getSource()]); + + $destination = isset($post[$map->getDestination()]) + ? $post[$map->getDestination()] + : []; + unset($post[$map->getDestination()]); + + $post[$map->getNamespaced()] = array_combine($source, $destination); + } - $post['IntonationHydratingMapping'] = array_combine($dry, $hydrated); return $post; } + public function getHydratingMappingMap() { + $mapping = []; + $column = 'hydrating_mapping'; + $mapping [$column] = $this->_createMapElement($column, $this->_('Sélecteur'), $this->_('hydraté par')); + return $mapping; + } + + + protected function _createMapElement($column, $source_label, $destination_label) { + return new Class_Entity(['Column' => $column, + 'Namespaced' => $this->withNameSpace($column), + 'Source' => $this->withNameSpace($column . '_source'), + 'SourceLabel' => $source_label, + 'Destination' => $this->withNameSpace($column . '_destination'), + 'DestinationLabel' => $destination_label, + 'DeleteMessage' => $this->_('Supprimer cette correspondance')]); + } + + public function getIconsMapping() { $columns = ['icons_map_doc_types' => $this->_('Types de documents'), 'icons_map_library' => $this->_('Bibliothèque')]; $mapping = []; foreach ($columns as $column => $label) - $mapping [$column] = new Class_Entity(['Column' => $column, - 'Source' => $this->withNameSpace($column . '_source'), - 'SourceLabel' => $label, - 'Destination' => $this->withNameSpace($column . '_destination'), - 'DestinationLabel' => $this->_('Icon'), - 'DeleteMessage' => $this->_('Supprimer cette correspondance')]); + $mapping [$column] = $this->_createMapElement($column, $label, $this->_('Icon')); return $mapping; } diff --git a/tests/scenarios/Templates/TemplatesTest.php b/tests/scenarios/Templates/TemplatesTest.php index b8b4701db054a42bfbe18d3fde56486419ba0c85..364b1efbf6644f9ad44fc5e6da84d7f95f87f1cd 100644 --- a/tests/scenarios/Templates/TemplatesTest.php +++ b/tests/scenarios/Templates/TemplatesTest.php @@ -880,8 +880,10 @@ class TemplatesPostEditTest extends TemplatesEnabledTestCase { parent::setUp(); $this->postDispatch('/admin/template/edit/template/intonation', ['IntonationHiddenMode' => Intonation_Template::RESPONSIVE_MODE_MEDIUM, - 'IntonationHydratingMappingDry' => ['body', 'widget'], - 'IntonationHydratingMappingHydrated' => ['container-fluid', '']]); + 'IntonationHydratingMappingSource' => ['body', 'widget'], + 'IntonationHydratingMappingDestination' => ['container-fluid', ''], + 'IntonationIconsMapDocTypesSource' => ['1', '2'], + 'IntonationIconsMapDocTypesDestination' => ['class fas fa-link', '']]); } @@ -908,6 +910,13 @@ class TemplatesPostEditTest extends TemplatesEnabledTestCase { $this->assertEquals(['body' => 'container-fluid', 'widget' => ''], Class_Template_Settings::find(1)->getSettingsInstance()->getIntonationHydratingMapping()); } + + + /** @test */ + public function intonationIconsMapDocTypesShouldContains101AndFaLink() { + $this->assertEquals(['1' => 'class fas fa-link', + '2' => ''], Class_Template_Settings::find(1)->getSettingsInstance()->getIntonationIconsMapDocTypes()); + } }