diff --git a/application/modules/opac/controllers/FormationsController.php b/application/modules/opac/controllers/FormationsController.php index a2e0e04dff8185efb677ebdb65902e25dbf90156..cf677978caf86b0f713a6a4473d91cff526aad3b 100644 --- a/application/modules/opac/controllers/FormationsController.php +++ b/application/modules/opac/controllers/FormationsController.php @@ -28,9 +28,8 @@ class FormationsController extends ZendAfi_Controller_Action { public function indexAction() { - $this->sessions_inscrit = []; - $this->view->formations_by_year = Class_Formation::indexByYear(Class_Formation::findAll()); - $this->view->user = $this->_user; + $this->view->titre = $this->_('S\'inscrire à une formation'); + $this->view->sessions = Class_SessionFormation::findAllAvailable($this->_user); } diff --git a/application/modules/opac/views/scripts/formations/index.phtml b/application/modules/opac/views/scripts/formations/index.phtml index 865911adc5c220d07d66917eb976501391f710e8..c1566795908dd9c036dd79c6e1cbcb7b84783d11 100644 --- a/application/modules/opac/views/scripts/formations/index.phtml +++ b/application/modules/opac/views/scripts/formations/index.phtml @@ -1,20 +1,44 @@ <?php -echo $this->openBoite('Formations'); +echo $this->openBoite($this->titre); -if ($this->user && !$this->user->hasRightSuivreFormation()) - echo sprintf('<p class="error">%s</p>', - $this->_("Vous n'avez pas les droits suffisants pour vous inscrire à une formation")); +$details_link = $this->url(['action' => 'detail-session', + 'id' => null]); -foreach($this->formations_by_year as $year => $formations) { - echo '<div class="formations">'; - echo $this->partialCycle('formations/_formation.phtml', - 'formation', - $formations, - ['first', 'second']); - echo '</div>'; -} +$register_link = $this->url(['controller' => 'abonne', + 'action' => 'inscrire-session', + 'id' => null]); -echo $this->closeBoite(); -?> +$current_link = $this->url(); -<?php if ($this->user) echo $this->abonne_RetourFiche(); ?> +echo $this->tagModelTable( + $this->sessions, + [$this->_('Formation'), + $this->_('Date'), + $this->_('Lieu'), + $this->_('Informations')], + ['libelle_formation', + 'date_debut_texte', + 'libelle_lieu', + 'infos'], + [function($model) use($details_link, $register_link, $current_link) { + return $this->modelActions($model, + [['url' => $details_link . '/id/%s?retour=' . $current_link, + 'icon' => 'view', + 'label' => $this->_('Details de la session %s', + $model->getLabel())], + ['url' => $register_link . '/id/%s', + 'icon' => 'add_user', + 'label' => $this->_('S\'inscrire à la session %s', + $model->getLabel())]] + );}], + 'available_sessions', + null, + ['infos' => function($model) { + return $this->_('Date limite d\'inscription : %s', + $model->getDateLimiteInscriptionHumanRead()); + }] +); + +$this->closeBoite(); + +echo $this->abonne_RetourFiche(); diff --git a/library/Class/SessionFormation.php b/library/Class/SessionFormation.php index 77aae35fd79e2e094d77bd59a0b2f63ad99ae800..7593d37f184dad69d19c1e818277fe037aa2777b 100644 --- a/library/Class/SessionFormation.php +++ b/library/Class/SessionFormation.php @@ -20,6 +20,25 @@ */ class SessionFormationLoader extends Storm_Model_Loader { + + public function findAllAvailable($user) { + if(!$user) + return []; + + return (new Storm_Model_Collection(Class_SessionFormation::findAll())) + ->reject('isInscriptionClosed') + ->reject(function($session) use ($user) + { + return in_array($session, $user->getSessionFormations()); + }) + ->select(function($session) use ($user) + { + return $session->isSubscriableFor($user) + && $session->isVisible(); + }) + ->getArrayCopy(); + } + public function findAllRegistered($user) { if (!$user) return []; diff --git a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php index bd92428b315a7cd628a915f86f590dbeb19b89b8..fa2f06637c17a4d9a1254f10d48fdcbe51140e44 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php @@ -96,7 +96,9 @@ abstract class AbstractAbonneControllerFormationsTestCase 'effectif_min' => 1, 'effectif_max' => 10, 'lieu' => $this->_gallice_cafe, - 'date_debut' => '2014-01-10']); + 'date_debut' => '2014-01-10', + 'date_fin' => '2014-01-10', + 'date_limite_inscription' => '2014-01-10']); $this->_session_smalltalk_juillet = $this->fixture('Class_SessionFormation', ['id' => 12, @@ -105,7 +107,9 @@ abstract class AbstractAbonneControllerFormationsTestCase 'effectif_max' => 10, 'lieu' => $this->_gallice_cafe, 'stagiaires' => [], - 'date_debut' => '2014-07-11']); + 'date_debut' => '2014-07-11', + 'date_fin' => '2014-07-15', + 'date_limite_inscription' => '2014-07-11']); $this->_learn_smalltalk = $this->fixture('Class_Formation', ['id' => 1, @@ -155,6 +159,8 @@ abstract class AbstractAbonneControllerFormationsTestCase ['id' => 121, 'formation_id' => 12, 'date_debut' => '2014-07-10', + 'date_fin' => '2014-07-14', + 'date_limit_inscription' => '2014-07-10', 'contenu' => 'Introduction a la syntaxe', 'objectif' => 'Ecrire un premier programme', 'effectif_min' => 1, @@ -220,16 +226,15 @@ class AbonneControllerFormationsListWithLearnJavaNotVisibleTest extends Abstract class AbonneControllerFormationsSessionListWithLearnSmalltalkNotVisibleTest extends AbstractAbonneControllerFormationsTestCase { - public function setUp() { - parent::setUp(); - } /** @test */ public function trainingJavaShouldBeDisplayed() { $this->dispatch('/opac/formations', true); - $this->assertXPathContentContains('//h2', 'Learn Java',$this->response->getBody()); + $this->assertXPathContentContains('//td', 'Learn Java'); } + + /** @test */ function noH2ShouldContainsLearnSmalltalk() { $this->_learn_smalltalk->hide()->save(); @@ -254,12 +259,13 @@ class AbonneControllerFormationsSessionListWithLearnSmalltalkNotVisibleTest exte $this->assertNotXPathContentContains('//tbody//tr//td', '11 juillet 2014'); } + /** @test */ function sessionJuilletShouldBeVisibleIfShow() { $this->_learn_smalltalk->show()->save(); $this->_session_smalltalk_juillet->show()->save(); $this->dispatch('/opac/formations', true); - $this->assertXPathContentContains('//tbody//tr//td', '11 juillet 2014'); + $this->assertXPathContentContains('//td', '11 juillet 2014'); } } @@ -278,24 +284,21 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati Class_Profil::newInstanceWithId(42, ['cfg_modules' => ['abonne' => ['formations' => ['barre_nav' => 'Les formations']]]])); - $this->dispatch('/opac/formations', true); - } + $this->_session_python_juillet->show()->assertSave(); - /** @test */ - function aH2ShouldContainsLearnJava() { - $this->assertXPathContentContains('//h2', 'Learn Java'); + $this->dispatch('/opac/formations', true); } /** @test */ - function aDivForDescriptionShouldContainsIfYouWantTo() { - $this->assertXPathContentContains('//div', 'whaaat ?'); + function aTdShouldContainsLearnJava() { + $this->assertXPathContentContains('//td', 'Learn Java'); } /** @test */ - function aH2ShouldContainsLearnPython() { - $this->assertXPathContentContains('//h2', 'Learn Python'); + function aTdShouldNotContainsLearnPythonBeCauseAmadouAlreadyRegistered() { + $this->assertNotXPathContentContains('//td', 'Learn Python'); } @@ -325,7 +328,7 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati /** @test */ function sessionJanuary2014ShouldBeFirst() { - $this->assertXPathContentContains('//tbody//tr[1]//td', '10 janvier 2014'); + $this->assertXPathContentContains('//tbody//tr[1]//td', '10 janvier 2014', $this->_response->getBody()); }