From 56c16e9d6d65e93b3c2e36469a13e0981c37950c Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@git-test.afi-sa.fr> Date: Thu, 15 Nov 2012 13:43:45 +0000 Subject: [PATCH] Formulaires : stockage dans la base + edition --- .gitattributes | 7 ++ .../admin/controllers/ModoController.php | 5 ++ .../views/scripts/modo/formulaires.phtml | 13 +++ .../opac/controllers/FormulaireController.php | 31 ++++++++ .../opac/views/scripts/formulaire/add.phtml | 0 ckeditor/config.js | 3 +- library/Class/Formulaire.php | 67 ++++++++++++++++ library/Class/Multimedia/Device.php | 26 +----- library/Trait/TimeSource.php | 50 ++++++++++++ library/ZendAfi/View/Helper/TagModelTable.php | 16 ++++ .../ModoControllerFormulaireTest.php | 79 +++++++++++++++++++ .../controllers/FormulaireControllerTest.php | 67 ++++++++++++++++ tests/library/Class/TimeSourceForTest.php | 6 ++ 13 files changed, 344 insertions(+), 26 deletions(-) create mode 100644 application/modules/admin/views/scripts/modo/formulaires.phtml create mode 100644 application/modules/opac/controllers/FormulaireController.php create mode 100644 application/modules/opac/views/scripts/formulaire/add.phtml create mode 100644 library/Class/Formulaire.php create mode 100644 library/Trait/TimeSource.php create mode 100644 tests/application/modules/admin/controllers/ModoControllerFormulaireTest.php create mode 100644 tests/application/modules/opac/controllers/FormulaireControllerTest.php diff --git a/.gitattributes b/.gitattributes index 40aada3c5b2..3289aa654a9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -536,6 +536,7 @@ application/modules/admin/views/scripts/modo/_avis_partial.phtml -text application/modules/admin/views/scripts/modo/alert.phtml -text application/modules/admin/views/scripts/modo/aviscms.phtml -text application/modules/admin/views/scripts/modo/avisnotice.phtml -text +application/modules/admin/views/scripts/modo/formulaires.phtml -text application/modules/admin/views/scripts/modo/index.phtml -text application/modules/admin/views/scripts/modo/membreview.phtml -text application/modules/admin/views/scripts/modo/suggestion-achat-edit.phtml -text @@ -661,6 +662,7 @@ application/modules/opac/controllers/CatalogueController.php -text application/modules/opac/controllers/CmsController.php -text application/modules/opac/controllers/ErrorController.php -text application/modules/opac/controllers/EtagereController.php -text +application/modules/opac/controllers/FormulaireController.php -text application/modules/opac/controllers/IndexController.php -text application/modules/opac/controllers/JavaController.php -text application/modules/opac/controllers/NoticeajaxController.php -text @@ -731,6 +733,7 @@ application/modules/opac/views/scripts/empty.phtml -text application/modules/opac/views/scripts/error/error.phtml -text application/modules/opac/views/scripts/etagere/appelmenu.phtml -text application/modules/opac/views/scripts/footer.phtml -text +application/modules/opac/views/scripts/formulaire/add.phtml -text application/modules/opac/views/scripts/head.phtml -text application/modules/opac/views/scripts/iframe.phtml -text application/modules/opac/views/scripts/index/embed-module.phtml -text @@ -1855,6 +1858,7 @@ library/Class/File/Mime.php -text library/Class/FileWriter.php -text library/Class/Folder/Manager.php -text library/Class/Formation.php -text +library/Class/Formulaire.php -text library/Class/Hash.php -text library/Class/I18n.php -text library/Class/I18nTranslator.php -text @@ -2098,6 +2102,7 @@ library/Thumbs/ThumbBase.inc.php -text library/Thumbs/ThumbLib.php -text library/Thumbs/thumb_plugins/gd_reflection.inc.php -text library/Trait/StaticFileWriter.php -text +library/Trait/TimeSource.php -text library/Trait/Translator.php -text library/ZendAfi/Acl/AdminControllerRoles.php -text library/ZendAfi/Auth.php -text @@ -4500,6 +4505,7 @@ tests/application/modules/admin/controllers/IndexControllerTest.php -text tests/application/modules/admin/controllers/IndexControllerTranslationTest.php -text tests/application/modules/admin/controllers/LieuControllerTest.php -text tests/application/modules/admin/controllers/MenusControllerTest.php -text +tests/application/modules/admin/controllers/ModoControllerFormulaireTest.php -text tests/application/modules/admin/controllers/ModoControllerTest.php -text tests/application/modules/admin/controllers/ModulesControllerTest.php -text tests/application/modules/admin/controllers/MultimediaControllerTest.php -text @@ -4537,6 +4543,7 @@ tests/application/modules/opac/controllers/CatalogueControllerTest.php -text tests/application/modules/opac/controllers/CmsControllerTest.php -text tests/application/modules/opac/controllers/ErrorControllerTest.php -text tests/application/modules/opac/controllers/FormulaireContactTest.php -text +tests/application/modules/opac/controllers/FormulaireControllerTest.php -text tests/application/modules/opac/controllers/IndexControllerTest.php -text tests/application/modules/opac/controllers/IndexControllerTranslationTest.php -text tests/application/modules/opac/controllers/JavaControllerTest.php -text diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php index eeeb69aa590..497c6f69142 100644 --- a/application/modules/admin/controllers/ModoController.php +++ b/application/modules/admin/controllers/ModoController.php @@ -951,4 +951,9 @@ class Admin_ModoController extends Zend_Controller_Action { } $this->_redirect('admin/modo/alert'); } + + + public function formulairesAction() { + $this->view->formulaires = Class_Formulaire::findAll(); + } } \ No newline at end of file diff --git a/application/modules/admin/views/scripts/modo/formulaires.phtml b/application/modules/admin/views/scripts/modo/formulaires.phtml new file mode 100644 index 00000000000..8ecc47c8ce8 --- /dev/null +++ b/application/modules/admin/views/scripts/modo/formulaires.phtml @@ -0,0 +1,13 @@ +<h1><?php echo $this->_('Modération des formulaires');?></h1> + +<?php + +$data_names = Class_Formulaire::mergeDataNames($this->formulaires); + +echo $this->tagModelTable( + $this->formulaires, + $data_names, + $data_names, + [], + 'formulaires'); +?> \ No newline at end of file diff --git a/application/modules/opac/controllers/FormulaireController.php b/application/modules/opac/controllers/FormulaireController.php new file mode 100644 index 00000000000..5edb858a313 --- /dev/null +++ b/application/modules/opac/controllers/FormulaireController.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +class FormulaireController extends ZendAfi_Controller_Action { + public function addAction() { + $formulaire = new Class_Formulaire(); + $formulaire + ->setData(serialize($this->_request->getPost())) + ->save(); + } + +} + +?> \ No newline at end of file diff --git a/application/modules/opac/views/scripts/formulaire/add.phtml b/application/modules/opac/views/scripts/formulaire/add.phtml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/ckeditor/config.js b/ckeditor/config.js index 34ddc6fa5b9..a15bc1ad1db 100644 --- a/ckeditor/config.js +++ b/ckeditor/config.js @@ -55,7 +55,7 @@ CKEDITOR.editorConfig = function( config ) // ['Source','-','Save','NewPage','Preview','-','Templates'], // ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], // ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], - // ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], + // '/', // ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], // ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], @@ -80,6 +80,7 @@ CKEDITOR.editorConfig = function( config ) ['Bold','Italic','Underline','Strike'], ['NumberedList','BulletedList','-','Outdent','Indent'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], + ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'] ]; }; diff --git a/library/Class/Formulaire.php b/library/Class/Formulaire.php new file mode 100644 index 00000000000..56e98872a27 --- /dev/null +++ b/library/Class/Formulaire.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class Class_Formulaire extends Storm_Model_Abstract { + use Trait_TimeSource; + + protected $_datas; + protected $_table_name='formulaires'; + protected $_default_attribute_values = ['data' => '']; + + public static function mergeDataNames($formulaires) { + $names = []; + foreach($formulaires as $formulaire) { + $names=array_merge($names,$formulaire->getDataNames()); + } + + return array_unique($names); + } + + public function getDataNames() { + return array_keys($this->getDatas()); + + } + + + public function getDatas() { + return isset($_datas) + ? $this->_datas + : $this->_datas = unserialize(parent::_get('data')); + } + + + public function _get($attribute) { + try { + return parent::_get($attribute); + } + catch (Exception $e) { + $datas = array_change_key_case($this->getDatas()); + $attribute=strtolower($attribute); + return isset($datas[$attribute])?$datas[$attribute]:'' ; + } + } + + + public function beforeSave() { + $this->setDateCreation(date('Y-m-d H:i:s', self::getTimeSource()->time())); + } + +} diff --git a/library/Class/Multimedia/Device.php b/library/Class/Multimedia/Device.php index 8e3bff4a11e..448cda17c8c 100644 --- a/library/Class/Multimedia/Device.php +++ b/library/Class/Multimedia/Device.php @@ -60,9 +60,7 @@ class Multimedia_DeviceLoader extends Storm_Model_Loader { class Class_Multimedia_Device extends Storm_Model_Abstract { - /** @var Class_TimeSource */ - protected static $_time_source; - + use Trait_TimeSource; protected $_loader_class = 'Multimedia_DeviceLoader'; protected $_table_name = 'multimedia_device'; protected $_belongs_to = ['group' => ['model' => 'Class_Multimedia_DeviceGroup', @@ -72,28 +70,6 @@ class Class_Multimedia_Device extends Storm_Model_Abstract { 'role' => 'device', 'order' => 'start', 'dependents' => 'delete']]; - - /** - * @category testing - * @return int - */ - public function getCurrentTime() { - return self::getTimeSource()->time(); - } - - - /** @return Class_TimeSource */ - public static function getTimeSource() { - if (null == self::$_time_source) - self::$_time_source = new Class_TimeSource(); - return self::$_time_source; - } - - - /** @param $time_source Class_TimeSource */ - public static function setTimeSource($time_source) { - self::$_time_source = $time_source; - } /** diff --git a/library/Trait/TimeSource.php b/library/Trait/TimeSource.php new file mode 100644 index 00000000000..9faad329722 --- /dev/null +++ b/library/Trait/TimeSource.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +trait Trait_TimeSource { + /** @var Class_TimeSource */ + protected static $_time_source; + + + /** + * @category testing + * @return int + */ + public function getCurrentTime() { + return self::getTimeSource()->time(); + } + + + /** @return Class_TimeSource */ + public static function getTimeSource() { + if (null == self::$_time_source) + self::$_time_source = new Class_TimeSource(); + return self::$_time_source; + } + + + /** @param $time_source Class_TimeSource */ + public static function setTimeSource($time_source) { + self::$_time_source = $time_source; + } +} + +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/TagModelTable.php b/library/ZendAfi/View/Helper/TagModelTable.php index 8c5ec767e02..c56774585e9 100644 --- a/library/ZendAfi/View/Helper/TagModelTable.php +++ b/library/ZendAfi/View/Helper/TagModelTable.php @@ -24,7 +24,23 @@ class ZendAfi_View_Helper_TagModelTable extends Zend_View_Helper_HtmlElement { /** @var int */ protected $_cols_count = 0; + + /** + Exemple: + + echo $this->tagModelTable($this->relations, + + [$this->_('Libellé'), $this->_('De A à B'), $this->_('De B à A')], + + ['libelle', 'from_source', 'from_target'], + + [ ['action' => 'edit', 'content' => $this->boutonIco('type=edit')], + ['action' => 'delete', 'content' => $this->boutonIco('type=del')] ], + + 'relations'); + */ public function tagModelTable($models, $cols, $attribs, $actions, $id, $group_by = null, $callbacks = []) { + $this->_hasActions = 0 < count($actions); $this->_cols_count = count($attribs) + ($this->_hasActions ? 1 : 0); diff --git a/tests/application/modules/admin/controllers/ModoControllerFormulaireTest.php b/tests/application/modules/admin/controllers/ModoControllerFormulaireTest.php new file mode 100644 index 00000000000..08715fc7e17 --- /dev/null +++ b/tests/application/modules/admin/controllers/ModoControllerFormulaireTest.php @@ -0,0 +1,79 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ModoControllerFormulaireListTest extends Admin_AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Formulaire') + ->whenCalled('findAll') + ->answers([ + Class_Formulaire::newInstanceWithId(3, ['data' => serialize(['nom' => 'Tinguette', + 'prenom' => 'Quentine'])]), + + Class_Formulaire::newInstanceWithId(5, ['data' => serialize(['nom' => 'Bougie', + 'Prenom' => 'Mireille'])]), + + Class_Formulaire::newInstanceWithId(6, ['data' => serialize(['name' => 'Lefort', + 'prenom' => 'Nono', + 'age' => 12])]) + ]); + + + $this->dispatch('admin/modo/formulaires', true); + } + + + /** + * @test + */ + public function h1ShouldContainsFormulaires() { + $this->assertXPathContentContains('//h1', 'Modération des formulaires'); + } + + + /** @test */ + public function aTDShouldContainsTinguette() { + $this->assertXPathContentContains('//td', 'Tinguette'); + } + + + /** @test */ + public function aTDShouldContainsBougie() { + $this->assertXPathContentContains('//td', 'Bougie'); + } + + + /** @test */ + public function aLastTDShouldContainsAge12() { + $this->assertXPathContentContains('//td', '12',$this->_response->getBody()); + } + + + /** @test */ + public function aTDShouldContainsPrenomMireille() { + $this->assertXPathContentContains('//td', 'Mireille',$this->_response->getBody()); + } + +} + +?> + diff --git a/tests/application/modules/opac/controllers/FormulaireControllerTest.php b/tests/application/modules/opac/controllers/FormulaireControllerTest.php new file mode 100644 index 00000000000..74073c404d9 --- /dev/null +++ b/tests/application/modules/opac/controllers/FormulaireControllerTest.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class FormulaireControllerPostActionTest extends Admin_AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Formulaire') + ->whenCalled('save') + ->willDo(function ($formulaire) { + $formulaire->setId(2)->cache(); + return true; + }); + + + $timesource = new TimeSourceForTest(); + $timesource->setTime(strtotime('2012-10-23 12:32:00')); + Class_Formulaire::setTimeSource($timesource); + + $this->postDispatch('/formulaire/add', + ['nom' => 'Tinguette' , + 'prenom' => 'Quentin' ] + ,true); + + $this->new_formulaire = Class_Formulaire::find(2); + } + + + /** @test */ + public function saveFormulaireShouldHaveNomTinguette() { + $this->assertEquals('Tinguette', $this->new_formulaire->getNom()); + } + + + /** @test */ + public function dateCreationShouldBeNow() { + $this->assertEquals('2012-10-23 12:32:00', $this->new_formulaire->getDateCreation()); + } + + + /** @test */ + public function getDataShouldAnswerSerializedNomPrenom() { + $this->assertEquals(serialize(['nom' => 'Tinguette' , + 'prenom' => 'Quentin']), + $this->new_formulaire->getData()); + } +} + +?> \ No newline at end of file diff --git a/tests/library/Class/TimeSourceForTest.php b/tests/library/Class/TimeSourceForTest.php index d8e35b8737f..bb475147f6f 100644 --- a/tests/library/Class/TimeSourceForTest.php +++ b/tests/library/Class/TimeSourceForTest.php @@ -22,11 +22,17 @@ class TimeSourceForTest extends Class_TimeSource { protected $_time; + /** + * @param $time timestamp + */ public function setTime($time) { $this->_time = $time; return $this; } + /** + * @return timestamp + */ public function time() { return $this->_time; } -- GitLab