diff --git a/application/modules/admin/controllers/AdvancedSearchFormController.php b/application/modules/admin/controllers/SearchFormController.php similarity index 85% rename from application/modules/admin/controllers/AdvancedSearchFormController.php rename to application/modules/admin/controllers/SearchFormController.php index 2f9884a633c000af35cf07e5f0e3b8709828ee4f..f46bba0c9c283e85c09454b73b0ee5f32ea8cdbf 100644 --- a/application/modules/admin/controllers/AdvancedSearchFormController.php +++ b/application/modules/admin/controllers/SearchFormController.php @@ -20,7 +20,7 @@ */ -class Admin_AdvancedSearchFormController extends ZendAfi_Controller_Action { +class Admin_SearchFormController extends ZendAfi_Controller_Action { public function getPlugins() { return ['ZendAfi_Controller_Plugin_ResourceDefinition_SearchForm', @@ -32,20 +32,16 @@ class Admin_AdvancedSearchFormController extends ZendAfi_Controller_Action { parent::init(); if (!Class_AdminVar::get('ADVANCED_SEARCH_CONFIGURABLE')) return $this->_redirect('/'); - - } + public function makevisibleAction() { - if (!$search_form = Class_SearchForm::getLoader()->find((int)$this->_getParam('id'))) { - $this->_redirect('admin/advanced-search-form'); + 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(); - } - - } -?> \ No newline at end of file diff --git a/application/modules/admin/views/scripts/advanced-search-form/add.phtml b/application/modules/admin/views/scripts/search-form/add.phtml similarity index 100% rename from application/modules/admin/views/scripts/advanced-search-form/add.phtml rename to application/modules/admin/views/scripts/search-form/add.phtml diff --git a/application/modules/admin/views/scripts/advanced-search-form/edit.phtml b/application/modules/admin/views/scripts/search-form/edit.phtml similarity index 100% rename from application/modules/admin/views/scripts/advanced-search-form/edit.phtml rename to application/modules/admin/views/scripts/search-form/edit.phtml diff --git a/application/modules/admin/views/scripts/advanced-search-form/index.phtml b/application/modules/admin/views/scripts/search-form/index.phtml similarity index 100% rename from application/modules/admin/views/scripts/advanced-search-form/index.phtml rename to application/modules/admin/views/scripts/search-form/index.phtml 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 index 8057415b95df12a0f557ef7e0e018c12ce2ef010..c165c8cdfe7425c06f96c33190a6a463b271a155 100644 --- a/library/Class/SearchForm.php +++ b/library/Class/SearchForm.php @@ -41,6 +41,10 @@ class Class_SearchForm extends Storm_Model_Abstract { return $this->getLabel(); } + public function getTitre() { + return $this->getLabel(); + } + public function __construct() { parent::__construct(); $this->setCreatedAt(static::getCurrentDate()); diff --git a/library/ZendAfi/Controller/Plugin/Manager/SearchForm.php b/library/ZendAfi/Controller/Plugin/Manager/SearchForm.php index afbf1ad7c39a48c643f59cda1c62a412b5150ce8..8c709e4197a917aac83708dbaa9a5c5a802e8ea6 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/SearchForm.php +++ b/library/ZendAfi/Controller/Plugin/Manager/SearchForm.php @@ -23,26 +23,25 @@ class ZendAfi_Controller_Plugin_Manager_SearchForm extends ZendAfi_Controller_Plugin_Manager_Manager { public function getActions($model) { return [ - ['url' => '/admin/advanced-search-form/view/id/%s', - 'icon' => 'view', - 'label' => $this->_('') - ], ['url' => '/admin/advanced-search-form/edit/id/%s', 'icon' => 'edit', - 'label' => $this->_('Modifier'), - 'anchorOptions' => ['data-popup' => 'true']], + 'label' => $this->_('Modifier') ], ['url' => ['module' => 'admin', 'controller' => 'advanced-search-form', 'action' => 'makevisible', 'id' => '%s'], 'icon' => function($model) {return $model->getVisible() ? 'show' : 'hide';}, - 'label' => $this->_('Visualisation de l\album')], + 'label' => $this->_('Activation du formulaire')], ['url' => '/admin/advanced-search-form/delete/id/%s', 'label' => $this->_('Supprimer'), 'icon' => 'delete', - 'anchorOptions' => ['data-popup' => 'true']] + '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 index 22bae7ed65593e1ed5f8069901d00779a49b85e9..f035e2be282666354d014e758d1f6609d0863275 100644 --- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/SearchForm.php +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/SearchForm.php @@ -32,7 +32,9 @@ class ZendAfi_Controller_Plugin_ResourceDefinition_SearchForm extends ZendAfi_Co '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é")]], + '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_AdvancedSearch', ]; } diff --git a/library/ZendAfi/Form/AdvancedSearch.php b/library/ZendAfi/Form/AdvancedSearch.php index 32e399e8864f725c56c0f4c375fd86d1b3952365..584e6859637d65c3535a72bb65efc1ccf68d6f74 100644 --- a/library/ZendAfi/Form/AdvancedSearch.php +++ b/library/ZendAfi/Form/AdvancedSearch.php @@ -31,14 +31,17 @@ class ZendAfi_Form_AdvancedSearch extends ZendAfi_Form { 'required' => true, 'allowEmpty' => false, 'placeholder' => $this->_('Libellé de la configuration')]) - ->addElement('userfile', 'filename') + + ->addElement('userfile', 'filename', + ['label' => $this->_('Fichier de description'), + 'allowEmpty' => false, + 'required' => true]) + ->addElement('checkbox', 'visible', - ['label' => $this->_('Le formulaire est visible'), - 'required' => true, - 'allowEmpty' => false]) - ->addDisplayGroup(['filename', 'label','visible'], - 'all', + ['label' => $this->_('Le formulaire est visible') ]) + + ->addUniqDisplayGroup('all', ['legend' => $this->_('Configuration du formulaire')]); } diff --git a/library/ZendAfi/View/Helper/Admin/ContentNav.php b/library/ZendAfi/View/Helper/Admin/ContentNav.php index 76ef70736618d73666e4dd55d87413a930dc7c95..aff21ae596c052ee4da9b7406256ae574264b3a1 100644 --- a/library/ZendAfi/View/Helper/Admin/ContentNav.php +++ b/library/ZendAfi/View/Helper/Admin/ContentNav.php @@ -152,7 +152,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'], - ['customfields', $this->_('Formulaires de recherche avancée'), '/admin/advanced-search-form', [], $advanced_search_form], + ['customfields', $this->_('Formulaires de recherche avancée'), '/admin/search-form', [], $advanced_search_form], ['customfields', $this->_('Champs personnalisés'), '/admin/custom-fields/index', [], $is_admin], ['customreports', $this->_('Rapports statistiques'), '/admin/custom-fields-report', [], $is_admin] 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/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')