Skip to content
Snippets Groups Projects
Commit fe6cd159 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

migrate dateProfile controller to manager plugin

parent 27cc0944
Branches
Tags
5 merge requests!2080Sandbox detach zf from storm,!2061Master,!1989Dev#45275 3155 contractuel application nouvelle methode d edition par lot des articles aux collections,!1968full plugin mod for multiselection,!1959Dev#45275 3155 contractuel application nouvelle methode d edition par lot des articles aux collections
Pipeline #137 passed with stage
in 8 minutes and 49 seconds
......@@ -22,6 +22,11 @@
class Cosmo_DataProfileController extends ZendAfi_Controller_Action {
public function getPlugins() {
return ['ZendAfi_Controller_Plugin_Manager_DataProfile'];
}
public function getRessourceDefinitions() {
return ['model' => ['class' => 'Class_IntProfilDonnees',
'name' => 'data_profile',
......@@ -39,67 +44,6 @@ class Cosmo_DataProfileController extends ZendAfi_Controller_Action {
}
protected function _setupFormAndSave($model) {
$model = $this->_autoUpdateFormatInModel($model);
$form = $this->_getForm($model);
$this->view->form = $form;
if (!$this->_request->isPost())
return false;
$values = $this->_autoUpdateFormat($this->_getPost());
$attributes_values = $this->_extractAttributesFrom($values);
$model->updateAttributes($attributes_values);
$profile_prefs = $this->_extractProfilePrefsFrom($values);
$model->setAttributs($profile_prefs);
if ((!$form->isValidModelAndArray($model, $values)))
return false;
return $model->save();
}
protected function _autoUpdateFormatInModel($model) {
$attributes = $this->_autoUpdateFormat($model->toArray(), $model);
$model->updateAttributes($attributes);
return $model;
}
protected function _autoUpdateFormat($attributes) {
$old_format = $attributes['format'];
$default_formats = Class_IntProfilDonnees::getFormatsForType($attributes['type_fichier']);
if(!key_exists($old_format, $default_formats)) {
$keys = array_keys($default_formats);
$attributes['format'] = array_shift($keys);
}
return $attributes;
}
protected function _extractAttributesFrom($values) {
$default_values = Class_IntProfilDonnees::getClassVar('_default_attribute_values');
return array_intersect_key($values, $default_values);
}
protected function _extractProfilePrefsFrom($values) {
return (new Class_ProfileSerializer($values))->serializeDatas();
}
protected function _getEditUrl($model) {
return sprintf('/cosmo/%s/edit/id/%s',
$this->_request->getControllerName(), $model->getId());
}
protected function _redirectToIndex() {
$url = '/cosmo/'.$this->_request->getControllerName().'/index';
if (($scope_field = $this->_definitions->getScope())
......
<?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_DataProfile extends ZendAfi_Controller_Plugin_Manager_Manager {
protected function _setupFormAndSave($model) {
$model = $this->_autoUpdateFormatInModel($model);
$form = $this->_getForm($model);
$this->_view->form = $form;
if (!$this->_request->isPost())
return false;
$values = $this->_autoUpdateFormat($this->_getPost());
$attributes_values = $this->_extractAttributesFrom($values);
$model->updateAttributes($attributes_values);
$profile_prefs = $this->_extractProfilePrefsFrom($values);
$model->setAttributs($profile_prefs);
if ((!$form->isValidModelAndArray($model, $values)))
return false;
return $model->save();
}
protected function _autoUpdateFormatInModel($model) {
$attributes = $this->_autoUpdateFormat($model->toArray(), $model);
$model->updateAttributes($attributes);
return $model;
}
protected function _autoUpdateFormat($attributes) {
$old_format = $attributes['format'];
$default_formats = Class_IntProfilDonnees::getFormatsForType($attributes['type_fichier']);
if(!key_exists($old_format, $default_formats)) {
$keys = array_keys($default_formats);
$attributes['format'] = array_shift($keys);
}
return $attributes;
}
protected function _extractAttributesFrom($values) {
$default_values = Class_IntProfilDonnees::getClassVar('_default_attribute_values');
return array_intersect_key($values, $default_values);
}
protected function _extractProfilePrefsFrom($values) {
return (new Class_ProfileSerializer($values))->serializeDatas();
}
protected function _getEditUrl($model) {
return sprintf('/cosmo/%s/edit/id/%s',
$this->_request->getControllerName(), $model->getId());
}
}
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment