diff --git a/VERSIONS_WIP/70388 b/VERSIONS_WIP/70388 new file mode 100644 index 0000000000000000000000000000000000000000..39d7549f67442420196641825b52f462c32d8b62 --- /dev/null +++ b/VERSIONS_WIP/70388 @@ -0,0 +1 @@ + - ticket #70388 : Administration : Ajout des interfaces de gestion des formulaires de recherche avancée \ No newline at end of file diff --git a/application/modules/admin/controllers/SearchFormController.php b/application/modules/admin/controllers/SearchFormController.php new file mode 100644 index 0000000000000000000000000000000000000000..cda61785d8cb424dae58275772115306606383d8 --- /dev/null +++ b/application/modules/admin/controllers/SearchFormController.php @@ -0,0 +1,40 @@ +<?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 Admin_SearchFormController extends ZendAfi_Controller_Action { + + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_SearchForm', + 'ZendAfi_Controller_Plugin_Manager_SearchForm']; + } + + + public function makevisibleAction() { + if (!$search_form = Class_SearchForm::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/search-form'); + return; + } + + $search_form->setVisible(!$search_form->getVisible())->save(); + return $this->_redirectToIndex(); + } +} diff --git a/application/modules/admin/views/scripts/search-form/add.phtml b/application/modules/admin/views/scripts/search-form/add.phtml new file mode 100644 index 0000000000000000000000000000000000000000..ac7363359759fdc81ec27a1c761cdf8d81e268d8 --- /dev/null +++ b/application/modules/admin/views/scripts/search-form/add.phtml @@ -0,0 +1,2 @@ +<?php +echo $this->renderForm($this->form); diff --git a/application/modules/admin/views/scripts/search-form/edit.phtml b/application/modules/admin/views/scripts/search-form/edit.phtml new file mode 100644 index 0000000000000000000000000000000000000000..ac7363359759fdc81ec27a1c761cdf8d81e268d8 --- /dev/null +++ b/application/modules/admin/views/scripts/search-form/edit.phtml @@ -0,0 +1,2 @@ +<?php +echo $this->renderForm($this->form); diff --git a/application/modules/admin/views/scripts/search-form/index.phtml b/application/modules/admin/views/scripts/search-form/index.phtml new file mode 100644 index 0000000000000000000000000000000000000000..1eebbb9f6d214e259c8e1b726257b2097f4dba14 --- /dev/null +++ b/application/modules/admin/views/scripts/search-form/index.phtml @@ -0,0 +1,12 @@ +<?php +echo $this->Button_New((new Class_Entity()) + ->setText($this->_('Ajouter un formulaire de recherche avancé')) + ->setUrl($this->url(['action' => 'add', 'id' => null]))); + + +$description = (new Class_TableDescription('searchforms')) + ->addColumn($this->_('Libellé'), 'label') + ->addColumn($this->_('fichier'), 'filename') + ->addRowAction(function($model) { return $this->renderPluginsActions($model); }); + +echo $this->renderTable($description, Class_SearchForm::findAll(), ['sorter' => true]); diff --git a/cosmogramme/sql/patch/patch_344.php b/cosmogramme/sql/patch/patch_344.php new file mode 100644 index 0000000000000000000000000000000000000000..fbf36233d910187163bc870463fcf1e2989e2d11 --- /dev/null +++ b/cosmogramme/sql/patch/patch_344.php @@ -0,0 +1,11 @@ +<?php +Zend_Db_Table_Abstract::getDefaultAdapter() + ->query('CREATE TABLE if not exists `search_form` ( ' + . 'id int(11) unsigned not null auto_increment,' + . 'label varchar(255) not null,' + . 'filename varchar(255) not null,' + . 'visible tinyint(1) not null default 0,' + . 'display_order int(4) ,' + . 'created_at timestamp not null,' + . 'primary key (id)' + . ') engine=MyISAM default charset=utf8'); diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index 9d0334e251500924b2c4889140f576f8761e7b77..a396d465f2a7e98c82580af01765804f46db6aab 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -263,7 +263,9 @@ class Class_AdminVarLoader extends Storm_Model_Loader { 'SEARCH_ALSO_IN' => Class_AdminVar_Meta::newMultiInput($this->_('Liste des sites de recherche élargie (la chaine \'%s\' dans l\'url sera remplacée par le terme de recherche)'), [ 'options' => ['fields' => [['name' => 'site_label', 'label' => $this->_('Nom du site')], ['name' => 'site_url', 'label' => $this->_('Url de recherche')] ]]]), - 'NOM_DOMAINE' => Class_AdminVar_Meta::newDefault($this->_('Nom de domaine principal de l\'OPAC, ex: monopac.macommune.fr')),]; + 'NOM_DOMAINE' => Class_AdminVar_Meta::newDefault($this->_('Nom de domaine principal de l\'OPAC, ex: monopac.macommune.fr')), + + 'CUSTOM_SEARCH_FORM' => Class_AdminVar_Meta::newOnOff($this->_('Activer les formulaires de recherche configurables'))->bePrivate()]; } @@ -966,6 +968,11 @@ class Class_AdminVarLoader extends Storm_Model_Loader { } + public function isCustomSearchFormEnabled() { + return Class_AdminVar::isModuleEnabled('CUSTOM_SEARCH_FORM'); + } + + public function shouldKeepLastSigbRecord() { return Class_AdminVar::isModuleEnabled('KEEP_LAST_SIGB_RECORD'); } diff --git a/library/Class/FileManager.php b/library/Class/FileManager.php index 09cdbc3c6c072191221d2d023d137bedbed1ee4b..1499d5f9ae28f24e8efa1f6c5b454dd40ea260d2 100644 --- a/library/Class/FileManager.php +++ b/library/Class/FileManager.php @@ -31,7 +31,6 @@ class Class_FileManager extends Class_Entity { 'Name' => '', 'Basename' => '', 'ParentPath' => '', - 'Writable' => '', 'BrowserParam' => '', 'MTime' => '', 'Size' => '', @@ -337,13 +336,12 @@ class Class_FileManager extends Class_Entity { public function getModels() { - return (new Class_FileManager_Model)->findAllContaining($this); + return (new Class_FileManager_Model($this))->findAll(); } public function renameModels($by) { - foreach($this->getModels() as $model) - (new Class_FileManager_Model)->rename($model, $this->getId(), $by); + (new Class_FileManager_Model($this))->rename($by); return $this; } diff --git a/library/Class/FileManager/Model.php b/library/Class/FileManager/Model.php index 7593fa2e329152f8d955a85b9ffdcd4a997656b9..eee50fda58a8ad6dc359b947ac67dc513e065469 100644 --- a/library/Class/FileManager/Model.php +++ b/library/Class/FileManager/Model.php @@ -21,84 +21,100 @@ class Class_FileManager_Model { + protected + $_filemanager, + $_relations = []; + + public function __construct($filemanager) { + $this->_filemanager = $filemanager; + + $this->_relations = [new Class_FileManager_ModelRelation('Class_Catalogue', 'url_img'), + new Class_FileManager_ModelRelation('Class_SearchForm', 'filename'), + new Class_FileManager_ModelRelationText('Class_Article', 'contenu'), + new Class_FileManager_ModelRelationText('Class_Article', 'description'), + new Class_FileManager_ModelRelationProfil($filemanager) + ]; + } + - public function findAllContaining($instance) { - if(!$instance) + public function findAll() { + if(!$this->_filemanager) return []; - if(!$path = $instance->getId()) + if(!$path = $this->_filemanager->getId()) return []; - if($instance->isDir()) + if($this->_filemanager->isDir()) $path .= '/'; $path = str_replace('"', '\"', $path); - return array_merge($this->_findProfilesContaining($instance, $path), - $this->_findArticlesContaining($path), - $this->_findDomainsContaining($path)); - } + $models = []; + foreach ($this->_relations as $relation) + $models = array_merge($models, $relation->findAll($path)); + return $models; + } - public function rename($model, $path, $by) { - if($model instanceof Class_Article) - return $this->_renameInArticle($model, $path, $by); - - if($model instanceof Class_Catalogue) - return $this->_renameInDomain($model, $path, $by); - if($model instanceof Class_Profil) - return $this->_renameInProfile($model, $path, $by); + public function rename($by) { + if (!$this->_filemanager) + return; - return false; + foreach($this->_relations as $relation) + $relation->rename($this->_filemanager->getId(), $by); } +} - protected function _renameInProfile($profile, $path, $by) { - if($profile->hasParentProfil()) - return $profile - ->setCfgAccueilParam('page_css', str_replace($path, $by, $profile->getCfgAccueilParam('page_css'))) - ->save(); - foreach(['header_img', - 'favicon', - 'logo_gauche_img', - 'logo_droite_img', - 'header_css', - 'header_js'] as $key) - $profile->setCfgSiteParam($key, str_replace($path, $by, $profile->getCfgSiteParam($key))); +class Class_FileManager_ModelRelation { + protected $_model, $_field; - return $profile->save(); + public function __construct($model, $field) { + $this->_model = $model; + $this->_field = $field; } - protected function _renameInDomain($domain, $path, $by) { - return $domain - ->setUrlImg(str_replace($path, $by, $domain->getUrlImg())) - ->save(); + public function findAll($path) { + return call_user_func([$this->_model, 'findAllby'], + ['where' => $this->_field . ' like "%' . $path . '%"']); } - protected function _renameInArticle($article, $path, $by) { - return $article - ->setContenu(str_replace($path, $by, $article->getContenu())) - ->setDescription(str_replace($path, $by, $article->getDescription())) - ->save(); + protected function _generateValue($model, $previous, $new) { + return $new; } - - protected function _findArticlesContaining($path) { - return Class_Article::findAllBy(['where' => sprintf('concat(description, contenu) like "%%%s%%"', $path)]); + public function rename($path, $by) { + foreach($this->findAll($path) as $model) { + call_user_func([$model, 'callSetterByAttributeName'], $this->_field, $this->_generateValue($model, $path, $by)); + $model->save(); + } } +} - protected function _findDomainsContaining($path) { - return Class_Catalogue::findAllBy(['where' => sprintf('url_img like "%%%s%%"', $path)]); + +class Class_FileManager_ModelRelationText extends Class_FileManager_ModelRelation { + + protected function _generateValue($model, $previous, $new) { + return str_replace($previous, $new, + call_user_func([$model, 'callGetterByAttributeName'], $this->_field)); } +} + + +class Class_FileManager_ModelRelationProfil { + protected $_filemanager; + public function __construct($filemanager) { + $this->_filemanager = $filemanager; + } - protected function _findProfilesContaining($instance, $path) { + public function findAll($path) { $top_profiles = array_filter(Class_Profil::findTopProfils(), function($profile) use ($path) { foreach(['header_img', @@ -112,7 +128,7 @@ class Class_FileManager_Model { } }); - $sub_profiles = $instance->isCss() + $sub_profiles = $this->_filemanager->isCss() ? array_filter(Class_Profil::findAllBy(['parent_id not' => null]), function($profile) use ($path) { return false !== strpos($profile->getCfgAccueilParam('page_css'), @@ -121,5 +137,30 @@ class Class_FileManager_Model { : []; return array_merge($top_profiles, $sub_profiles); + } -} \ No newline at end of file + + + protected function _renameOne($model, $path, $by) { + if($model->hasParentProfil()) + return $model + ->setCfgAccueilParam('page_css', str_replace($path, $by, $model->getCfgAccueilParam('page_css'))) + ->save(); + + foreach(['header_img', + 'favicon', + 'logo_gauche_img', + 'logo_droite_img', + 'header_css', + 'header_js'] as $key) + $model->setCfgSiteParam($key, str_replace($path, $by, $model->getCfgSiteParam($key))); + + $model->save(); + } + + public function rename($path, $by) { + foreach($this->findAll($path) as $model) + $this->_renameOne($model, $path, $by); + } + +} diff --git a/library/Class/SearchForm.php b/library/Class/SearchForm.php new file mode 100644 index 0000000000000000000000000000000000000000..46f9a5ba56eb65690d94c322f67534d93297fad5 --- /dev/null +++ b/library/Class/SearchForm.php @@ -0,0 +1,47 @@ +<?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 Class_SearchForm extends Storm_Model_Abstract { + use Trait_TimeSource; + + protected $_table_name = 'search_form'; + protected $_default_attribute_values = ['label' => '', + 'filename' => '', + 'display_order' => 1, + 'visible' => false, + 'created_at' => '']; + + public function getLibelle() { + return $this->getLabel(); + } + + + public function getTitre() { + return $this->getLabel(); + } + + + public function beforeSave() { + if ($this->isNew()) + $this->setCreatedAt(static::getCurrentDate()); + } +} \ No newline at end of file diff --git a/library/ZendAfi/Acl/AdminControllerGroup.php b/library/ZendAfi/Acl/AdminControllerGroup.php index b4ad5918688ca63d73a3ebaf49062f4b6810a4c6..ded4dadb2813292cf6625eacb4905e46256223ec 100644 --- a/library/ZendAfi/Acl/AdminControllerGroup.php +++ b/library/ZendAfi/Acl/AdminControllerGroup.php @@ -65,7 +65,8 @@ class ZendAfi_Acl_AdminControllerGroup { 'premier-chapitre' => Class_AdminVar::isPremierChapitreEnabled(), 'i18n' => Class_AdminVar::isTranslationEnabled(), 'stat/piwik' => (new Class_AdminVar_Piwik())->isEnabled(), - 'multimedia' => Class_AdminVar::isMultimediaEnabled()]; + 'multimedia' => Class_AdminVar::isMultimediaEnabled(), + 'search-form' => Class_AdminVar::isCustomSearchFormEnabled()]; } diff --git a/library/ZendAfi/Acl/AdminControllerRoles.php b/library/ZendAfi/Acl/AdminControllerRoles.php index d354ecd2b97c0895d69eacd164cc69377c8d7797..35cb1f24f8f31967c37634aea7cad487dfdc6924 100644 --- a/library/ZendAfi/Acl/AdminControllerRoles.php +++ b/library/ZendAfi/Acl/AdminControllerRoles.php @@ -93,6 +93,7 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl { $this->add(new Zend_Acl_Resource('systeme')); $this->add(new Zend_Acl_Resource('batch')); $this->add(new Zend_Acl_Resource('file-manager')); + $this->add(new Zend_Acl_Resource('search-form')); //Roles $this->addRole(new Zend_Acl_Role('invite')); @@ -146,6 +147,7 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl { $this->allow('admin_bib','modo'); $this->allow('admin_bib','menus'); $this->allow('admin_bib','external-agendas'); + $this->allow('admin_bib','search-form'); $this->deny('modo_portail','catalogue'); $this->deny('modo_portail','rss'); @@ -165,6 +167,7 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl { $this->deny('modo_portail','usergroup'); $this->deny('modo_portail','systeme'); $this->deny('modo_portail','batch'); + $this->deny('modo_portail','search-form'); $this->allow('modo_portail'); $this->allow('admin_portail'); diff --git a/library/ZendAfi/Controller/Plugin/Manager/SearchForm.php b/library/ZendAfi/Controller/Plugin/Manager/SearchForm.php new file mode 100644 index 0000000000000000000000000000000000000000..b226e96a7eaa974d9d01c7166396c40d607c2bdc --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/SearchForm.php @@ -0,0 +1,47 @@ +<?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 ZendAfi_Controller_Plugin_Manager_SearchForm extends ZendAfi_Controller_Plugin_Manager_Manager { + public function getActions($model) { + return [ + ['url' => '/admin/search-form/edit/id/%s', + 'icon' => 'edit', + 'label' => $this->_('Modifier') ], + + ['url' => ['module' => 'admin', + 'controller' => 'search-form', + 'action' => 'makevisible', + 'id' => '%s'], + 'icon' => function($model) {return $model->getVisible() ? 'show' : 'hide';}, + 'label' => $this->_('Activation du formulaire')], + + ['url' => '/admin/search-form/delete/id/%s', + 'label' => $this->_('Supprimer'), + 'icon' => 'delete', + 'anchorOptions' => ['onclick' => 'return confirm(\''. + str_replace("'","\'", + $this->_('Etes-vous sûr de vouloir supprimer ce formulaire ?')). + '\')']], + + ]; + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/SearchForm.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/SearchForm.php new file mode 100644 index 0000000000000000000000000000000000000000..991c41955403abb7fd7ca2f8bb114c639b589440 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/SearchForm.php @@ -0,0 +1,43 @@ +<?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 ZendAfi_Controller_Plugin_ResourceDefinition_SearchForm + extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_SearchForm', + 'name' => 'search_form', + 'order' => 'label', + 'model_id' => 'id'], + + 'messages' => ['successful_save' => $this->_('Formulaire "%s" sauvegardé'), + 'successful_add' => $this->_('Le formulaire "%s" a été sauvegardé'), + 'successful_delete' => $this->_('Formulaire "%s" supprimé')], + + 'actions' => ['add' => ['title' => $this->_("Ajouter un formulaire de recherche avancée")], + 'edit' => ['title' => $this->_("Modifier un formulaire de recherche avancée")], + 'index' => ['title' => $this->_("Formulaires de recherche avancée")]], + + 'form_class_name' => 'ZendAfi_Form_Admin_SearchForm', + ]; + } +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Admin/SearchForm.php b/library/ZendAfi/Form/Admin/SearchForm.php new file mode 100644 index 0000000000000000000000000000000000000000..6511a8dc3b97510fd84780e26cb6ccf8fbcd79c0 --- /dev/null +++ b/library/ZendAfi/Form/Admin/SearchForm.php @@ -0,0 +1,46 @@ +<?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 ZendAfi_Form_Admin_SearchForm extends ZendAfi_Form { + public function init() { + parent::init(); + + $this + ->addElement('text', + 'label', + ['label' => $this->_('Libellé'), + 'required' => true, + 'allowEmpty' => false, + 'placeholder' => $this->_('Libellé de la configuration')]) + + ->addElement('userfile', 'filename', + ['label' => $this->_('Fichier de description'), + 'allowEmpty' => false, + 'required' => true]) + + ->addElement('checkbox', + 'visible', + ['label' => $this->_('Le formulaire est visible') ]) + + ->addUniqDisplayGroup('all', ['legend' => $this->_('Configuration du formulaire')]); + } +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Admin/ContentNav.php b/library/ZendAfi/View/Helper/Admin/ContentNav.php index 40e849acf7584b99b06399bc349ab87451b03da9..0e2a0f6c33d86f275699eb19f29efe24e6cb3019 100644 --- a/library/ZendAfi/View/Helper/Admin/ContentNav.php +++ b/library/ZendAfi/View/Helper/Admin/ContentNav.php @@ -129,7 +129,6 @@ class ZendAfi_View_Helper_Admin_ContentNav extends ZendAfi_View_Helper_BaseHelpe public function menuSysteme() { $is_admin = function($user) { return $user->isAdmin(); }; $is_super_admin = function($user) { return $user->isSuperAdmin(); }; - return $this ->renderBloc($this->_('Système'), [['cosmogramme', $this->_('Accès à Cosmogramme'), '/cosmogramme', @@ -152,6 +151,7 @@ class ZendAfi_View_Helper_Admin_ContentNav extends ZendAfi_View_Helper_BaseHelpe [], function($user) { return defined('DEVELOPMENT') && $user->isAdmin();}], ['filebrowser', $this->_('Explorateur de fichiers'), '/admin/file-manager'], + ['search_form', $this->_('Formulaires de recherche configurables'), '/admin/search-form'], ['customfields', $this->_('Champs personnalisés'), '/admin/custom-fields/index', [], $is_admin], ['customreports', $this->_('Rapports statistiques'), '/admin/custom-fields-report', [], $is_admin] @@ -296,4 +296,4 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdminItem { ? static::$_acl : static::$_acl = new ZendAfi_Acl_AdminControllerGroup(); } -} \ No newline at end of file +} diff --git a/library/ZendAfi/View/Helper/Admin/TagEdit.php b/library/ZendAfi/View/Helper/Admin/TagEdit.php index 5adbc8a76b8ce2c14757117c63acf682ba996290..22b903789863f597f862158485d941e8668523f1 100644 --- a/library/ZendAfi/View/Helper/Admin/TagEdit.php +++ b/library/ZendAfi/View/Helper/Admin/TagEdit.php @@ -36,6 +36,9 @@ class ZendAfi_View_Helper_Admin_TagEdit extends ZendAfi_View_Helper_BaseHelper { if($model instanceof Class_Catalogue) return $this->view->tagEditDomain($model); + if($model instanceof Class_SearchForm) + return $this->view->tagEditSearchForm($model); + return ''; } } diff --git a/library/ZendAfi/View/Helper/TagEditSearchForm.php b/library/ZendAfi/View/Helper/TagEditSearchForm.php new file mode 100644 index 0000000000000000000000000000000000000000..1683993fb97795c211824d9db7a9c0198c9aa2c3 --- /dev/null +++ b/library/ZendAfi/View/Helper/TagEditSearchForm.php @@ -0,0 +1,42 @@ +<?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 ZendAfi_View_Helper_TagEditSearchForm extends ZendAfi_View_Helper_BaseHelper { + public function tagEditSearchForm($model) { + if (!$user = Class_Users::getIdentity()) + return ''; + + return $this->view + ->tagAnchor($this->view->url(['module' => 'admin', + 'controller' => 'search-form', + 'action' => 'edit', + 'id' => $model->getId()], null, true), + Class_Admin_Skin::current() + ->renderActionIconOn('edit', $this->view, + ['class' => 'searchform_edit', + 'alt' => $this->_('Modifier le formulaire "%s"' , $model->getLabel()), + 'title' => $this->_('Modifier le formulaire "%s"', $model->getLabel())]), + ['class' => 'edit_searchform', + 'data-popup' => 'true']); + + } +} diff --git a/public/admin/skins/bokeh72/config.json b/public/admin/skins/bokeh72/config.json index 996d15069f302dc9e333f8a1d29610f7e5b6f804..e0e0c670c1e59194b00946b3a040f64fc5ca2418 100644 --- a/public/admin/skins/bokeh72/config.json +++ b/public/admin/skins/bokeh72/config.json @@ -52,6 +52,7 @@ "filebrowser": "../../images/picto/file_browser.png", "customfields": "../../images/picto/proprietes.gif", "customreports": "../../images/picto/stats_palmares_16.png", + "search_form": "icons/menu/search_form_24.png", "doctypes": "../../images/picto/type_docs_16.png", "thesaurus_init": "../../images/picto/generation_16.png", "thesaurus_edit": "../../images/picto/generation_16.png", diff --git a/public/admin/skins/bokeh72/icons/menu/search_form_24.png b/public/admin/skins/bokeh72/icons/menu/search_form_24.png new file mode 100644 index 0000000000000000000000000000000000000000..5b4a929110227c5e803836fb88e8c227c0288b97 Binary files /dev/null and b/public/admin/skins/bokeh72/icons/menu/search_form_24.png differ diff --git a/public/admin/skins/bokeh72/icons/menu/search_form_48.png b/public/admin/skins/bokeh72/icons/menu/search_form_48.png new file mode 100644 index 0000000000000000000000000000000000000000..5b4a929110227c5e803836fb88e8c227c0288b97 Binary files /dev/null and b/public/admin/skins/bokeh72/icons/menu/search_form_48.png differ diff --git a/public/admin/skins/bokeh74/config.json b/public/admin/skins/bokeh74/config.json index 7622412b8ccd901f4e5ee9a9fd9cc07b276ec911..4f9b981dfd4b14f5a741b914156bac681516e478 100644 --- a/public/admin/skins/bokeh74/config.json +++ b/public/admin/skins/bokeh74/config.json @@ -39,6 +39,7 @@ "migrate_comments": "icons/menu/import_avis_24.png", "portal_init": "icons/menu/generation_24.png", "customfields": "icons/menu/champs_perso_24.png", + "search_form": "icons/menu/search_form_24.png", "customreports": "icons/menu/rapports_stats_24.png", "doctypes": "icons/menu/type_docs_24.png", "thesaurus_init": "icons/menu/generation_24.png", diff --git a/public/admin/skins/bokeh74/icons/menu/search_form_24.png b/public/admin/skins/bokeh74/icons/menu/search_form_24.png new file mode 100644 index 0000000000000000000000000000000000000000..5b4a929110227c5e803836fb88e8c227c0288b97 Binary files /dev/null and b/public/admin/skins/bokeh74/icons/menu/search_form_24.png differ diff --git a/public/admin/skins/bokeh74/icons/menu/search_form_48.png b/public/admin/skins/bokeh74/icons/menu/search_form_48.png new file mode 100644 index 0000000000000000000000000000000000000000..5b4a929110227c5e803836fb88e8c227c0288b97 Binary files /dev/null and b/public/admin/skins/bokeh74/icons/menu/search_form_48.png differ diff --git a/public/admin/skins/retro/config.json b/public/admin/skins/retro/config.json index 9d72b4f08d06960ad39ef6894ec83f722350439a..3e4d472326e4e9e09f500a3719f141cfc625b5b4 100644 --- a/public/admin/skins/retro/config.json +++ b/public/admin/skins/retro/config.json @@ -40,6 +40,7 @@ "portal_init": "icons/menu/generation_24.png", "customfields": "icons/menu/champs_perso_24.png", "customreports": "icons/menu/rapports_stats_24.png", + "search_form": "icons/menu/search_form_24.png", "doctypes": "icons/menu/type_docs_24.png", "thesaurus_init": "icons/menu/generation_24.png", "thesaurus_edit": "icons/menu/import_thesaurus_24.png", diff --git a/public/admin/skins/retro/global.css b/public/admin/skins/retro/global.css index 9f954babda5afa0be82a18108b0db272d7bc5f1f..c97c2f85477ed67274f6eef6adc3a19e77f3f8c1 100755 --- a/public/admin/skins/retro/global.css +++ b/public/admin/skins/retro/global.css @@ -9,6 +9,16 @@ body { background-image:url(sand.png); } +img { + image-rendering: optimizeSpeed; /* STOP SMOOTHING, GIVE ME SPEED */ + image-rendering: -moz-crisp-edges; /* Firefox */ + image-rendering: -o-crisp-edges; /* Opera */ + image-rendering: -webkit-optimize-contrast; /* Chrome (and eventually Safari) */ + image-rendering: pixelated; /* Chrome */ + image-rendering: optimize-contrast; /* CSS3 Proposed */ + -ms-interpolation-mode: nearest-neighbor; /* IE8+ */ +} + .barre_nav { background: url(floor.png) repeat; } diff --git a/public/admin/skins/retro/icons/menu/search_form_24.png b/public/admin/skins/retro/icons/menu/search_form_24.png new file mode 100644 index 0000000000000000000000000000000000000000..5b4a929110227c5e803836fb88e8c227c0288b97 Binary files /dev/null and b/public/admin/skins/retro/icons/menu/search_form_24.png differ diff --git a/public/admin/skins/retro/icons/menu/search_form_48.png b/public/admin/skins/retro/icons/menu/search_form_48.png new file mode 100644 index 0000000000000000000000000000000000000000..5b4a929110227c5e803836fb88e8c227c0288b97 Binary files /dev/null and b/public/admin/skins/retro/icons/menu/search_form_48.png differ diff --git a/tests/application/modules/admin/controllers/FileManagerControllerTest.php b/tests/application/modules/admin/controllers/FileManagerControllerTest.php index b82ea59064f7ee823b7145273d34ef046ef2efe7..d3d0e8b9b125408d0652b1dc910d8dd38431632c 100644 --- a/tests/application/modules/admin/controllers/FileManagerControllerTest.php +++ b/tests/application/modules/admin/controllers/FileManagerControllerTest.php @@ -118,7 +118,7 @@ abstract class FileManagerControllerTestCase extends Admin_AbstractControllerTes ->setName('image') ->setDir(true); - $disk = Storm_Test_ObjectWrapper::mock() + $disk = $this->mock() ->whenCalled('diskSpaceInfo') ->answers((new Class_Entity) ->setFree('2 GO') diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index 463a5cc486f6e35229ea2b96fa4df17af54d5a2e..b1fbc82faa106d014e84831ca5a625d4f876b011 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -2036,4 +2036,34 @@ class UpgradeDB_343_Test extends UpgradeDBTestCase { public function fieldsShouldExists($field, $type) { $this->assertFieldType('bookmarked_search', $field, $type); } +} + + +class UpgradeDB_344_Test extends UpgradeDBTestCase { + public function prepare() { + try { + $this->query('drop table search_form'); + } catch (Exception $e) {} + } + + + public function datas() { + return + [ + ['label', 'varchar(255)'], + ['filename', 'varchar(255)'], + ['created_at', 'timestamp'], + ['display_order', 'int(4)'], + ['visible', 'tinyint(1)'] + ]; + } + + + /** + * @test + * @dataProvider datas + */ + public function fieldsShouldExists($field, $type) { + $this->assertFieldType('search_form', $field, $type); + } } \ No newline at end of file diff --git a/tests/scenarios/AdvancedSearch/AdminConfigurationTest.php b/tests/scenarios/AdvancedSearch/AdminConfigurationTest.php new file mode 100644 index 0000000000000000000000000000000000000000..db6dd404fe41e13e4fd67bed6e854bfe6e46af3b --- /dev/null +++ b/tests/scenarios/AdvancedSearch/AdminConfigurationTest.php @@ -0,0 +1,150 @@ +<?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 AdvancedSearch_AdminConfigurationUnactiveTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + Class_AdminVar::set('CUSTOM_SEARCH_FORM', 0); + } + + + public function tearDown() { + ZendAfi_View_Helper_Admin_MenuGaucheAdminItem::setAcl(null); + parent::tearDown(); + } + + + /** @test */ + public function menuAdvancedFormShouldBeDisplayed() { + $this->dispatch('/admin'); + $this->assertNotXPathContentContains('//ul[@class="menuAdmin"]//li', 'Formulaires de recherche configurables'); + } + + + /** @test */ + public function askControllerShouldRedirect() { + $this->dispatch('/admin/search-form/index'); + $this->assertRedirect('/'); + } +} + + + +class AdvancedSearch_ActiveTestCase extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + Class_AdminVar::set('CUSTOM_SEARCH_FORM', 1); + $this->fixture('Class_SearchForm', + ['id' => 1, + 'label' => 'Mon formulaire', + 'filename' => 'mypath/file', + 'visible' => true + ]); + } + + + public function tearDown() { + ZendAfi_View_Helper_Admin_MenuGaucheAdminItem::setAcl(null); + parent::tearDown(); + } +} + + + +class AdvancedSearch_AdminConfigurationSimpleActiveTest extends AdvancedSearch_ActiveTestCase { + /** @test */ + public function menuAdvancedFormShouldBeDisplayed() { + $this->dispatch('/admin'); + $this->assertXPathContentContains('//ul[@class="menuAdmin"]//li', + 'Formulaires de recherche configurables'); + } + + + /** @test */ + public function indexShouldDisplayAllForms() { + $this->dispatch('/admin/search-form/index'); + + $this->assertXPathContentContains('//td', 'mypath/file'); + $this->assertXPath('//a[contains(@href, "/admin/search-form/edit/id/1")]'); + $this->assertXPath('//a[contains(@href, "/admin/search-form/delete/id/1")]'); + $this->assertXPath('//a[contains(@href, "/admin/search-form/makevisible/id/1")]'); + } + + + /** @test */ + public function makeVisibleShouldRenderVisibleIfUnvisible() { + $this->dispatch('/admin/search-form/makevisible/id/1'); + $this->assertEquals(false, Class_SearchForm::find(1)->getVisible()); + } + + + /** @test */ + public function makeVisibleShouldRenderInVisibleIfVisible() { + Class_SearchForm::find(1)->setVisible(false)->save(); + $this->dispatch('/admin/search-form/makevisible/id/1'); + $this->assertEquals(true, Class_SearchForm::find(1)->getVisible()); + } + + + /** @test */ + public function deleteShouldDeleteForm() { + $this->dispatch('/admin/search-form/delete/id/1'); + $this->assertNull(Class_SearchForm::find(1)); + } +} + + + +class AdvancedSearch_AdminConfigurationAddActionTest extends AdvancedSearch_ActiveTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/search-form/add', true); + } + + + /** @test */ + public function titleShouldBeAjouterUnFormulaire() { + $this->assertXPathContentContains('//h1', 'Ajouter un formulaire'); + } + + + /** @test */ + public function labelInputShouldBePresent() { + $this->assertXPath('//input[@name="label"]'); + } + + + /** @test */ + public function fileInputShouldBePresent() { + $this->assertXPath('//input[@name="filename"]'); + } + + + /** @test */ + public function visibleCheckBoxShouldBePresent() { + $this->assertXPath('//input[@type="checkbox"][@name="visible"]'); + } +} \ No newline at end of file