diff --git a/application/modules/admin/controllers/FormationController.php b/application/modules/admin/controllers/FormationController.php index 7543f4d18164e0fb677a4bcde20f5484ab206e15..a9a810efcc403e5f167e672c7ef4a8db6c010bea 100644 --- a/application/modules/admin/controllers/FormationController.php +++ b/application/modules/admin/controllers/FormationController.php @@ -282,6 +282,7 @@ class Admin_FormationController extends Zend_Controller_Action { public function sessionaddAction() { + xdebug_break(); if (!$formation = Class_Formation::getLoader()->find((int)$this->_getParam('formation_id'))) { $this->_redirect('admin/formation'); return; @@ -419,22 +420,25 @@ class Admin_FormationController extends Zend_Controller_Action { 'label' => 'Durée (h)', 'size' => 2, 'validators' => array('int'))) + ->addElement('text', 'horaires', array( 'label' => 'Horaires', 'size' => 50, 'required' => true, 'allowEmpty' => false)) - ->addElement('text', 'lieu', array( - 'label' => 'Lieu', - 'size' => 50, - 'required' => true, - 'allowEmpty' => false)) + + ->addElement('select', 'lieu_id', array('label' => 'Lieu', + 'multiOptions' => Class_Lieu::getAllLibelles())) + ->addElement('text', 'cout', array( 'label' => 'Coût', 'size' => 6, 'validators' => array('int'))) + ->addElement('checkbox', 'is_annule', array('label' => 'Session annulée')) + ->addElement($intervenants_checkboxes) + ->addElement('ckeditor', 'contenu', array( 'label' => 'Contenu *', 'required' => true, @@ -447,7 +451,7 @@ class Admin_FormationController extends Zend_Controller_Action { 'date_limite_inscription', 'effectif_min', 'effectif_max', - 'lieu', + 'lieu_id', 'horaires', 'duree', 'cout', diff --git a/application/modules/opac/views/scripts/abonne/_session.phtml b/application/modules/opac/views/scripts/abonne/_session.phtml index c890f61e2129db2a5ea145a3eb36385055833b21..ab430e4fb3dcfe404d2257411153e4b7d5af0932 100644 --- a/application/modules/opac/views/scripts/abonne/_session.phtml +++ b/application/modules/opac/views/scripts/abonne/_session.phtml @@ -4,7 +4,7 @@ echo sprintf("<div>%s %s</div>", $this->humanDate($this->session->getDateDebut(), 'MMMM, d'), $this->session->isAnnule() ? '(Annulé)' : ''); -echo sprintf("<div>%s </div>", $this->session->getLieu()); +echo sprintf("<div>%s </div>", $this->session->getLibelleLieu()); echo sprintf("<div class='actions'>%s %s</div>", $this->tagAnchor(array('action' => 'detail_session', 'id' => $this->session->getId()), diff --git a/application/modules/opac/views/scripts/abonne/detail-session.phtml b/application/modules/opac/views/scripts/abonne/detail-session.phtml index b0b57773e60b8cf2716679cdb9259a5650aa92ff..a5d9d474ba53a5beb7946c750f433cbbf66efa54 100644 --- a/application/modules/opac/views/scripts/abonne/detail-session.phtml +++ b/application/modules/opac/views/scripts/abonne/detail-session.phtml @@ -8,7 +8,7 @@ echo $this->openBoite(sprintf('Formation %s: session du %s', <dl class="session_formation"> <dt><?php echo $this->_('Lieu') ?></dt> - <dd><?php echo $this->session->getLieu() ?></dd> + <dd><?php echo $this->session->getLibelleLieu() ?></dd> <dt><?php echo $this->_('Horaires') ?></dt> diff --git a/library/Class/Lieu.php b/library/Class/Lieu.php index 7ad70f6ff82ede8cfcab305e0020392d752e0eac..30317b9d169efa009456793b12638b426932b39f 100644 --- a/library/Class/Lieu.php +++ b/library/Class/Lieu.php @@ -21,12 +21,27 @@ class Class_Lieu extends Storm_Model_Abstract { protected $_table_name = 'lieux'; - protected $_default_attribute_values = array('pays' => 'FRANCE'); + protected $_default_attribute_values = array('libelle' => '', + 'pays' => 'FRANCE'); public static function getLoader() { return self::getLoaderFor(__CLASS__); } + + public static function getAllLibelles() { + $lieux = self::getLoader()->findAllBy(array('order' => 'libelle')); + $libelles = array(); + foreach($lieux as $lieu) + $libelles[$lieu->getId()] = $lieu->getLibelle(); + return $libelles; + } + + + public function validate() { + $this->check($this->hasLibelle(), 'Le libelle doit être renseigné'); + } + } ?> \ No newline at end of file diff --git a/library/Class/SessionFormation.php b/library/Class/SessionFormation.php index 0940a169565301074832f64fa1ace6b960dd0ed7..11dac26e3380b392d02ad323212a9b4c02bff94d 100644 --- a/library/Class/SessionFormation.php +++ b/library/Class/SessionFormation.php @@ -22,7 +22,9 @@ class Class_SessionFormation extends Storm_Model_Abstract { protected $_table_name = 'sessions_formation'; - protected $_belongs_to = array('formation' => array('model' => 'Class_Formation')); + protected $_belongs_to = array( + 'formation' => array('model' => 'Class_Formation'), + 'lieu' => array('model' => 'Class_Lieu')); protected $_has_many = array( 'session_formation_inscriptions' => array('model' => 'Class_SessionFormationInscription', 'role' => 'session_formation', @@ -46,7 +48,6 @@ class Class_SessionFormation extends Storm_Model_Abstract { 'date_limite_inscription' => null, 'contenu' => '', 'objectif' => '', - 'lieu' => '', 'horaires' => '', 'is_annule' => false); @@ -59,6 +60,13 @@ class Class_SessionFormation extends Storm_Model_Abstract { return array_first(explode('-', $this->getDateDebut())); } + + public function getLibelleLieu() { + if ($this->hasLieu()) + return $this->getLieu()->getLibelle(); + return ''; + } + /** * @return bool diff --git a/tests/application/modules/admin/controllers/FormationControllerTest.php b/tests/application/modules/admin/controllers/FormationControllerTest.php index 8c9e3a9a96bc7b48b1bdda55a7c0caae8f4586a5..31d621aaa94d31918eab8971b19629e39ea3526a 100644 --- a/tests/application/modules/admin/controllers/FormationControllerTest.php +++ b/tests/application/modules/admin/controllers/FormationControllerTest.php @@ -85,7 +85,9 @@ abstract class Admin_FormationControllerTestCase extends Admin_AbstractControlle ->setDuree(8) ->setContenu('Intro à la syntaxe') ->setHoraires('9h - 12h, 13h - 18h') - ->setLieu('Salle réunion AFI') + ->setLieu($salle_reunion = Class_Lieu::getLoader() + ->newInstanceWithId(12) + ->setLibelle('Salle reunion AFI')) ->setDateLimiteInscription('2012-03-05') ->setIntervenants(array($this->_prof_laurent)), @@ -109,6 +111,23 @@ abstract class Admin_FormationControllerTestCase extends Admin_AbstractControlle ->beAnnule())) )); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Lieu') + ->whenCalled('save') + ->answers(true) + + ->whenCalled('findAllBy') + ->answers(array($salle_reunion, + + Class_Lieu::getLoader() + ->newInstanceWithId(28) + ->setLibelle('au marché'), + + Class_Lieu::getLoader() + ->newInstanceWithId(18) + ->setLibelle('Au café du coin'))); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_SessionFormationInscription') ->whenCalled('save')->answers(true) ->whenCalled('delete')->answers(null) @@ -539,6 +558,7 @@ class Admin_FormationControllerEditSessionLearningJavaMars27Test extends Admin_ $this->assertXPathContentContains('//td//textarea[@name="contenu"]', 'Intro à la syntaxe'); } + /** @test */ public function checkboxIntervenantLaurentShouldBeChecked() { $this->assertXPath('//input[@name="intervenant_ids[]"][@value="34"][@checked="checked"]'); @@ -553,11 +573,13 @@ class Admin_FormationControllerEditSessionLearningJavaMars27Test extends Admin_ /** @test */ public function inputLieuShouldContainsSalleReunionAFI() { - $this->assertXPath('//input[@name="lieu"][@value="Salle réunion AFI"]'); + $this->assertXPathContentContains('//select[@name="lieu_id"]//option[@value="12"]', "Salle reunion AFI"); } } + + class Admin_FormationControllerDeleteSessionLearningJavaMars27Test extends Admin_FormationControllerTestCase { public function setUp() { parent::setUp(); @@ -579,6 +601,8 @@ class Admin_FormationControllerDeleteSessionLearningJavaMars27Test extends Admi } + + class Admin_FormationControllerDeleteFormationLearningJavaTest extends Admin_FormationControllerTestCase { public function setUp() { parent::setUp(); @@ -614,6 +638,7 @@ class Admin_FormationControllerPostSessionLearnJavaTest extends Admin_Formation public function setUp() { parent::setUp(); + $this->postDispatch('/admin/formation/session_edit/id/32', array('date_debut' => '29/05/2012', 'date_limite_inscription' => '03/05/2012', @@ -621,7 +646,7 @@ class Admin_FormationControllerPostSessionLearnJavaTest extends Admin_Formation 'effectif_max' => '8', 'contenu' => 'Accompagné d un bon café', 'horaires' => '9h - 18h', - 'lieu' => 'Au café du coin', + 'lieu_id' => 18, 'is_annule' => '1')); $this->_session = Class_SessionFormation::getLoader()->find(32); } @@ -677,7 +702,7 @@ class Admin_FormationControllerPostSessionLearnJavaTest extends Admin_Formation /** @test */ public function lieuShouldEqualsAuCafeDuCoin() { - $this->assertEquals('Au café du coin', $this->_session->getLieu()); + $this->assertEquals('Au café du coin', $this->_session->getLieu()->getLibelle()); } @@ -779,6 +804,7 @@ class Admin_FormationControllerAddSessionToFormationLearningPythonTest extends class Admin_FormationControllerPostAddSessionToFormationLearningPythonTest extends Admin_FormationControllerTestCase { public function setUp() { parent::setUp(); + $this->postDispatch('/admin/formation/session_add/formation_id/12', array('date_debut' => '17/02/2010', 'effectif_min' => '3', @@ -786,7 +812,7 @@ class Admin_FormationControllerPostAddSessionToFormationLearningPythonTest exten 'contenu' => 'On charme les serpents', 'intervenant_ids' => array(34, 35), 'horaires' => '9h - 18h', - 'lieu' => 'au marché', + 'lieu_id' => 28, 'is_annule' => '0')); $this->session = Class_SessionFormation::getLoader()->getFirstAttributeForLastCallOn('save'); } diff --git a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php index cd7bfb6b7ca311a5e1cea55b777774e5aee6001d..94725d86e481133aac023e205d2c68671222ab8a 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php @@ -31,6 +31,9 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro protected $_session_java_fevrier; protected $_session_java_septembre; protected $_session_python_juillet; + protected $_gallice_cafe; + protected $_bib_romains; + protected $_bonlieu; protected function _loginHook($account) { $account->ROLE = "abonne_sigb"; @@ -46,6 +49,18 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro ->newInstanceWithId('FORMATIONS') ->setValeur('1'); + $this->_gallice_cafe = Class_Lieu::getLoader() + ->newInstanceWithId(98) + ->setLibelle('Gallice'); + + $this->_bib_romains = Class_Lieu::getLoader() + ->newInstanceWithId(99) + ->setLibelle('Bibliothèque des romains'); + + $this->_bonlieu = Class_Lieu::getLoader() + ->newInstanceWithId(100) + ->setLibelle('Bonlieu'); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') ->whenCalled('save')->answers(true); @@ -65,7 +80,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro ->setEffectifMin(1) ->setEffectifMax(10) ->setStagiaires(array()) - ->setLieu('Gallice') + ->setLieu($this->_gallice_cafe) ->setDateDebut('2009-01-17'), @@ -75,7 +90,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro ->setEffectifMin(1) ->setEffectifMax(10) ->setStagiaires(array()) - ->setLieu('Gallice') + ->setLieu($this->_gallice_cafe) ->setDateDebut('2023-07-12') )), @@ -96,7 +111,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro ->setEffectifMin(2) ->setEffectifMax(5) ->setStagiaires(array()) - ->setLieu('Bonlieu') + ->setLieu($this->_bonlieu) ->setDateDebut('2022-02-17') ->setDateLimiteInscription('2022-02-15'), @@ -123,7 +138,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro ->setEffectifMax(22) ->setDuree(8) ->setHoraires('8h-12h, 14h-18h') - ->setLieu('Bibliothèque des romains') + ->setLieu($this->_bib_romains) ->setIntervenants( array(Class_Users::getLoader() ->newInstanceWithId(76) ->setLogin('jpp'), diff --git a/tests/library/Class/FormationTest.php b/tests/library/Class/FormationTest.php index 20f7cb2216393abdb1f095559814cfa9612a4dae..236d3f9c0781f3cc5918ab39d3434c203f6bb029 100644 --- a/tests/library/Class/FormationTest.php +++ b/tests/library/Class/FormationTest.php @@ -51,6 +51,11 @@ class FormationSmalltalkWithTwoSessionsTest extends Storm_Test_ModelTestCase { protected $_laurent_intervention; public function setUp() { + parent::setUp(); + Class_Lieu::getLoader() + ->newInstanceWithId(74) + ->setLibelle('Bonlieu'); + $this->_learn_st = Class_Formation::getLoader() ->newInstanceWithId(3) ->setLibelle('Learning Smalltalk') @@ -61,7 +66,8 @@ class FormationSmalltalkWithTwoSessionsTest extends Storm_Test_ModelTestCase { ->setDateDebut('2009-01-05') ->setDateLimiteInscription('0000-00-00') ->setEffectifMin(1) - ->setEffectifMax(3), + ->setEffectifMax(3) + ->setLieuId(74), $this->_session_fevrier = Class_SessionFormation::getLoader() ->newInstanceWithId(2) @@ -133,6 +139,12 @@ class FormationSmalltalkWithTwoSessionsTest extends Storm_Test_ModelTestCase { } + /** @test */ + public function lieuSessionJanvierShouldBeBonlieu() { + $this->assertEquals('Bonlieu', $this->_session_janvier->getLieu()->getLibelle()); + } + + /** @test */ public function sessionJanvierHasDateLimiteInscriptionShouldReturnFalse() { $this->assertFalse($this->_session_janvier->hasDateLimiteInscription()); diff --git a/tests/library/Class/LieuTest.php b/tests/library/Class/LieuTest.php index b9e4961e680384fca671b77a530bd322850bbdd6..f74a31fd358a60fcfcf933d60fcf8a1d78cf9721 100644 --- a/tests/library/Class/LieuTest.php +++ b/tests/library/Class/LieuTest.php @@ -19,4 +19,22 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +class LieuTest extends Storm_Test_ModelTestCase { + + /** @test */ + public function lieuShouldNotBeValidWithoutLibelle() { + $this->assertFalse(Class_Lieu::getLoader()->newInstanceWithId(4)->isValid()); + } + + + /** @test */ + public function lieuShouldBeValidWithLibelle() { + $this->assertTrue(Class_Lieu::getLoader() + ->newInstanceWithId(4) + ->setLibelle('ici') + ->isValid()); + } +} + ?> \ No newline at end of file