Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (11)
Showing
with 432 additions and 56 deletions
- ticket #70388 : [Planif] Contractuel - MINSOC - Formulaire Gérer le rendu - Coté Back
\ No newline at end of file
<?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();
}
}
<?php
echo $this->renderForm($this->form);
<?php
echo $this->renderForm($this->form);
<?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]);
<?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');
......@@ -244,7 +244,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()];
}
......@@ -938,6 +940,11 @@ class Class_AdminVarLoader extends Storm_Model_Loader {
return Class_AdminVar::isBibNumEnabled()
&& Class_AdminVar::get('SITO_IN_ALBUMS');
}
public function isCustomSearchFormEnabled() {
return Class_AdminVar::isModuleEnabled('CUSTOM_SEARCH_FORM');
}
}
......
......@@ -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;
}
......
......@@ -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);
}
}
<?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
......@@ -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()];
}
......
......@@ -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');
......
<?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/advanced-search-form/edit/id/%s',
'icon' => 'edit',
'label' => $this->_('Modifier') ],
['url' => ['module' => 'admin',
'controller' => 'advanced-search-form',
'action' => 'makevisible',
'id' => '%s'],
'icon' => function($model) {return $model->getVisible() ? 'show' : 'hide';},
'label' => $this->_('Activation du formulaire')],
['url' => '/admin/advanced-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
<?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
<?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
......@@ -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'],
['customfields', $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
}
......@@ -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 '';
}
}
<?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']);
}
}
......@@ -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')
......
......@@ -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