An error occurred while loading the file. Please try again.
-
* rector on tests/ * upgradeDB and library/Trait * library/Class/templates * library/ZendAfi * cosmogramme/cosmozend * remove ExplicitBoolCompareRector + cosmogrammme/php/ * application/modules/telephone * application/modules/push * application/modules/api * application/modules/activitypub * application/modules/admin * application/modules/opac * storm * library/Class
29d9275e
CustomFieldsController.php 4.87 KiB
<?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 Admin_CustomFieldsController extends ZendAfi_Controller_Action {
public function getPlugins() : array {
return [ZendAfi_Controller_Plugin_ResourceDefinition_CustomField::class,
ZendAfi_Controller_Plugin_Manager_CustomField::class];
}
public function indexAction() {
$this->view->model = $this->_getParam('model');
if ($custom_field = Class_CustomField::find($this->_getParam('id', 0)))
$this->view->model = $custom_field->getModel();
parent::indexAction();
}
public function selectAction() {
$this->_helper->viewRenderer->setNoRender();
$id = $this->_getParam('id');
$model = $this->_getParam('model');
$custom_field_meta = Class_CustomField_Meta::find($id);
$custom_field = new Class_CustomField();
$custom_field->setMeta($custom_field_meta);
$custom_field->setModel($model);
$custom_field->save();
$this->_helper->notify($this->_('Le champ "%s" a bien été rattaché', $custom_field->getLabel()));
$this->_redirect('/admin/custom-fields/add/model/'.$model);
}
public function upAction() {
if ($field = Class_CustomField::find($id = $this->_getParam('id')))
$field->movePriorityUp();
$this->_redirect('/admin/custom-fields/index/id/'.$id);
}
public function downAction() {
if ($field = Class_CustomField::find($id = $this->_getParam('id')))
$field->movePriorityDown();
$this->_redirect('/admin/custom-fields/index/id/'.$id);
}
public function valuesAction() {
$model = Class_CustomField_Model::getModel($this->_getParam('model'));
$model_values = $model->find($model_id = $this->_getParam('id'));
if ($model_values->customizedModelIsNew()) {
$edit_url = $model->getEditUrl();
$edit_url['id'] = $this->_getParam('id');
$this->_redirect($this->view->url($edit_url, null, true), ['prependBase' => false]);
return;
}
$form = (new ZendAfi_Form_Admin_CustomFields_ModelValues(['model_values' => $model_values]));
if ($this->_request->isPost() && $form->isValid($this->_request->getPost())){
$form->updateModelValues();
$model_values->save();
$this->_helper->notify($this->_('Valeurs des champs personnalisés sauvegardées'));
$this->_redirect('/admin/custom-fields/values/model/'.$this->_getParam('model').'/id/'.$model_id);
}
if (!$model_values->getFields())
$this->view->error_message = $this->_('Aucun champ personnalisé n\'a été défini');
$this->view->titre = $this->view->_(
'Champs personnalisés: %s "%s"',
strtolower($model->getLabel()),
$model_values->getLabel());
$this->view->form = $form;
}
public function cleanAction() {
if ( ! $this->view->custom_field = $field = Class_CustomField::find($this->_getParam('id', 0)))
return $this->_redirect('/admin/custom-fields');
$this->view->titre = $this->view->_('Nettoyer le champ personnalisé %s',
strtolower($field->getLabel()));
$this->view->custom_field_values = $field->getValues();
return null;
}
public function deleteValueAction() {
if ( ! $value = Class_CustomField_Value::find($this->_getParam('id', 0)))
return $this->_redirect('/admin/custom-fields');
$this->_helper->notify($this->_('La valeur ID %s a bien été supprimée', $value->getId()));
$value->delete();
$this->_redirectClose($this->_getReferer());
return null;
}
public function cleanValuesAction() {
if ( ! $field = Class_CustomField::find($this->_getParam('id', 0))) {
$this->_helper->notify($this->_('Il y a une erreur, veuillez vérifier le paramètre "id" de votre URL.'));
return $this->_redirectCloseReferer();
}
$this->view->titre = $this->view->_('Mise à jour des valeurs du champs %s rattachées aux modèles',
strtolower($field->getLabel()));
$field->cleanValues();
$this->_helper->notify($this->_('Les valeurs rattachées au champs %s ont bien été mises à jour'));
$this->_redirectCloseReferer();
return null;
}
}