diff --git a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php index 075c73bb010aeadd530c509bf69b7bf841cd18b1..1223c6d613d343323240843f407311b9d2d96e5f 100644 --- a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php +++ b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php @@ -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()) diff --git a/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php b/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php new file mode 100644 index 0000000000000000000000000000000000000000..5dd9ea36309c84bb13116be9d2d981ccdd0ef059 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php @@ -0,0 +1,84 @@ +<?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