From b7aaadddd93cf4769bfb4a3c17746e6c188665cc Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Mon, 2 Jan 2017 16:55:49 +0100 Subject: [PATCH] hotline #52364 : revert legacy training page --- VERSIONS_HOTLINE/52364 | 1 + .../opac/controllers/AbonneController.php | 20 ++++- .../opac/controllers/FormationsController.php | 23 ++---- .../formations-done.phtml} | 3 +- .../formations-registered.phtml} | 3 +- .../views/scripts/abonne/formations.phtml | 45 +++++++++++ .../opac/views/scripts/formations/index.phtml | 54 ++++--------- library/Class/SessionFormation.php | 1 - .../ZendAfi/View/Helper/Abonne/Formations.php | 12 +-- .../AbonneControllerFormationsTest.php | 79 ++++++------------- .../controllers/FormationsControllerTest.php | 19 ++++- 11 files changed, 138 insertions(+), 122 deletions(-) create mode 100644 VERSIONS_HOTLINE/52364 rename application/modules/opac/views/scripts/{formations/done.phtml => abonne/formations-done.phtml} (87%) rename application/modules/opac/views/scripts/{formations/registered.phtml => abonne/formations-registered.phtml} (93%) create mode 100644 application/modules/opac/views/scripts/abonne/formations.phtml diff --git a/VERSIONS_HOTLINE/52364 b/VERSIONS_HOTLINE/52364 new file mode 100644 index 00000000000..57fdfaf3ffc --- /dev/null +++ b/VERSIONS_HOTLINE/52364 @@ -0,0 +1 @@ + - ticket #52364 : Restauration de l'ancienne page listant les formations \ No newline at end of file diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index b3a1d86280c..6f0a93a62e0 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -68,7 +68,7 @@ class AbonneController extends ZendAfi_Controller_Action { public function inscrireSessionAction() { - $this->_redirect('/formations'); + $this->_redirectToReferer(); if ((!$session = Class_SessionFormation::find((int)$this->_getParam('id'))) || $session->isInscriptionClosed()) @@ -1183,4 +1183,22 @@ class AbonneController extends ZendAfi_Controller_Action { $this->_redirectToReferer(); } + + + public function formationsAction() { + $this->view->titre = $this->_('S\'inscrire à une formation'); + $this->view->sessions = Class_SessionFormation::findAllAvailable($this->_user); + } + + + public function formationsRegisteredAction() { + $this->view->titre = $this->_('Mes inscriptions en cours'); + $this->view->sessions = Class_SessionFormation::findAllRegistered($this->_user); + } + + + public function formationsDoneAction() { + $this->view->titre = $this->_('Mes formations suivies'); + $this->view->sessions = Class_SessionFormation::findAllDone($this->_user); + } } \ No newline at end of file diff --git a/application/modules/opac/controllers/FormationsController.php b/application/modules/opac/controllers/FormationsController.php index cf677978caf..7274e94d579 100644 --- a/application/modules/opac/controllers/FormationsController.php +++ b/application/modules/opac/controllers/FormationsController.php @@ -28,16 +28,15 @@ class FormationsController extends ZendAfi_Controller_Action { public function indexAction() { - $this->view->titre = $this->_('S\'inscrire à une formation'); - $this->view->sessions = Class_SessionFormation::findAllAvailable($this->_user); + $this->sessions_inscrit = []; + $this->view->formations_by_year = Class_Formation::indexByYear(Class_Formation::findAll()); + $this->view->user = $this->_user; } public function detailSessionAction() { - if (!$session = Class_SessionFormation::find((int)$this->_getParam('id'))) { - $this->_redirect('/formations/index'); - return; - } + if (!$session = Class_SessionFormation::find((int)$this->_getParam('id'))) + return $this->_redirectToReferer(); $this->view->url_retour = ($this->_getParam('retour')) ? $this->_getParam('retour') @@ -46,16 +45,4 @@ class FormationsController extends ZendAfi_Controller_Action { null, true); $this->view->session = $session; } - - - public function registeredAction() { - $this->view->titre = $this->_('Mes inscriptions en cours'); - $this->view->sessions = Class_SessionFormation::findAllRegistered($this->_user); - } - - - public function doneAction() { - $this->view->titre = $this->_('Mes formations suivies'); - $this->view->sessions = Class_SessionFormation::findAllDone($this->_user); - } } \ No newline at end of file diff --git a/application/modules/opac/views/scripts/formations/done.phtml b/application/modules/opac/views/scripts/abonne/formations-done.phtml similarity index 87% rename from application/modules/opac/views/scripts/formations/done.phtml rename to application/modules/opac/views/scripts/abonne/formations-done.phtml index 5792b31b006..b494e3346b7 100644 --- a/application/modules/opac/views/scripts/formations/done.phtml +++ b/application/modules/opac/views/scripts/abonne/formations-done.phtml @@ -1,7 +1,8 @@ <?php $this->openBoite($this->titre); -$details_link = $this->url(['action' => 'detail-session', +$details_link = $this->url(['controller' => 'formations', + 'action' => 'detail-session', 'id' => null]); $current_link = $this->url(); diff --git a/application/modules/opac/views/scripts/formations/registered.phtml b/application/modules/opac/views/scripts/abonne/formations-registered.phtml similarity index 93% rename from application/modules/opac/views/scripts/formations/registered.phtml rename to application/modules/opac/views/scripts/abonne/formations-registered.phtml index cedc05fb65e..9dfaafb6675 100644 --- a/application/modules/opac/views/scripts/formations/registered.phtml +++ b/application/modules/opac/views/scripts/abonne/formations-registered.phtml @@ -1,7 +1,8 @@ <?php $this->openBoite($this->titre); -$details_link = $this->url(['action' => 'detail-session', +$details_link = $this->url(['controller' => 'formations', + 'action' => 'detail-session', 'id' => null]); $unregister_link = $this->url(['controller' => 'abonne', diff --git a/application/modules/opac/views/scripts/abonne/formations.phtml b/application/modules/opac/views/scripts/abonne/formations.phtml new file mode 100644 index 00000000000..05cf8d95638 --- /dev/null +++ b/application/modules/opac/views/scripts/abonne/formations.phtml @@ -0,0 +1,45 @@ +<?php +echo $this->openBoite($this->titre); + +$details_link = $this->url(['controller' => 'formations', + 'action' => 'detail-session', + 'id' => null]); + +$register_link = $this->url(['controller' => 'abonne', + 'action' => 'inscrire-session', + 'id' => null]); + +$current_link = $this->url(); + +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/application/modules/opac/views/scripts/formations/index.phtml b/application/modules/opac/views/scripts/formations/index.phtml index c1566795908..865911adc5c 100644 --- a/application/modules/opac/views/scripts/formations/index.phtml +++ b/application/modules/opac/views/scripts/formations/index.phtml @@ -1,44 +1,20 @@ <?php -echo $this->openBoite($this->titre); +echo $this->openBoite('Formations'); -$details_link = $this->url(['action' => 'detail-session', - 'id' => null]); +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")); -$register_link = $this->url(['controller' => 'abonne', - 'action' => 'inscrire-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>'; +} -$current_link = $this->url(); +echo $this->closeBoite(); +?> -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(); +<?php if ($this->user) echo $this->abonne_RetourFiche(); ?> diff --git a/library/Class/SessionFormation.php b/library/Class/SessionFormation.php index 894b15e30d1..322cfae1349 100644 --- a/library/Class/SessionFormation.php +++ b/library/Class/SessionFormation.php @@ -20,7 +20,6 @@ */ class SessionFormationLoader extends Storm_Model_Loader { - public function findAllAvailable($user) { if(!$user) return []; diff --git a/library/ZendAfi/View/Helper/Abonne/Formations.php b/library/ZendAfi/View/Helper/Abonne/Formations.php index 60766ac6627..ab32b9c9e32 100644 --- a/library/ZendAfi/View/Helper/Abonne/Formations.php +++ b/library/ZendAfi/View/Helper/Abonne/Formations.php @@ -25,8 +25,8 @@ class ZendAfi_View_Helper_Abonne_Formations extends ZendAfi_View_Helper_Abonne_A || !$user->hasRightSuivreFormation()) return ''; - $action_url = $this->view->url(['controller' => 'formations', - 'action' => 'index'], + $action_url = $this->view->url(['controller' => 'abonne', + 'action' => 'formations'], null, true); @@ -43,12 +43,12 @@ class ZendAfi_View_Helper_Abonne_Formations extends ZendAfi_View_Helper_Abonne_A return $this ->_tag('ul', $this->_tag('li', - $this->view->tagAnchor(['controller' => 'formations', - 'action' => 'done'], + $this->view->tagAnchor(['controller' => 'abonne', + 'action' => 'formations-done'], $this->_('Mes formations suivies'))) . $this->_tag('li', - $this->view->tagAnchor(['controller' => 'formations', - 'action' => 'registered'], + $this->view->tagAnchor(['controller' => 'abonne', + 'action' => 'formations-registered'], $this->_('Mes inscriptions en cours')))); } } \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php index 80d376e551e..4aa71504d96 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php @@ -42,6 +42,8 @@ abstract class AbstractAbonneControllerFormationsTestCase public function setUp() { parent::setUp(); + $_SERVER['HTTP_REFERER'] = '/formations'; + $test_time = new TimeSourceForTest('2014-05-01 14:00:00'); Class_Formation::setTimeSource($test_time); @@ -211,31 +213,28 @@ class AbonneControllerFormationsListWithLearnJavaNotVisibleTest extends Abstract public function setUp() { parent::setUp(); $this->_learn_java->hide()->save(); - $this->dispatch('/opac/formations', true); + $this->dispatch('/opac/abonne/formations', true); } /** @test */ - function noH2ShouldContainsLearnJava() { + public function noH2ShouldContainsLearnJava() { $this->assertNotXPathContentContains('//h2', 'Learn Java'); } /** @test */ - function sessionMarsShouldNotBeVisible() { + public function sessionMarsShouldNotBeVisible() { $this->assertNotXPathContentContains('//tbody//tr//td', '1 mars 2014'); } - } class AbonneControllerFormationsSessionListWithLearnSmalltalkNotVisibleTest extends AbstractAbonneControllerFormationsTestCase { - - /** @test */ public function trainingJavaShouldBeDisplayed() { - $this->dispatch('/opac/formations', true); + $this->dispatch('/opac/abonne/formations', true); $this->assertXPathContentContains('//td', 'Learn Java'); } @@ -243,7 +242,7 @@ class AbonneControllerFormationsSessionListWithLearnSmalltalkNotVisibleTest exte /** @test */ function noH2ShouldContainsLearnSmalltalk() { $this->_learn_smalltalk->hide()->save(); - $this->dispatch('/opac/formations', true); + $this->dispatch('/opac/abonne/formations', true); $this->assertNotXPathContentContains('//h2', 'Learn Smalltalk'); } @@ -251,7 +250,7 @@ class AbonneControllerFormationsSessionListWithLearnSmalltalkNotVisibleTest exte /** @test */ function sessionJuilletShouldNotBeVisibleIfParentTrainingIsHidden() { $this->_learn_smalltalk->hide()->save(); - $this->dispatch('/opac/formations', true); + $this->dispatch('/opac/abonne/formations', true); $this->assertNotXPathContentContains('//tbody//tr//td', '11 juillet 2014'); } @@ -260,7 +259,7 @@ class AbonneControllerFormationsSessionListWithLearnSmalltalkNotVisibleTest exte function sessionJuilletShouldNotBeVisibleIfHidden() { $this->_learn_smalltalk->show()->save(); $this->_session_smalltalk_juillet->hide()->save(); - $this->dispatch('/opac/formations', true); + $this->dispatch('/opac/abonne/formations', true); $this->assertNotXPathContentContains('//tbody//tr//td', '11 juillet 2014'); } @@ -269,10 +268,9 @@ class AbonneControllerFormationsSessionListWithLearnSmalltalkNotVisibleTest exte function sessionJuilletShouldBeVisibleIfShow() { $this->_learn_smalltalk->show()->save(); $this->_session_smalltalk_juillet->show()->save(); - $this->dispatch('/opac/formations', true); + $this->dispatch('/opac/abonne/formations', true); $this->assertXPathContentContains('//td', '11 juillet 2014'); } - } @@ -293,7 +291,7 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati ->show() ->assertSave(); - $this->dispatch('/opac/formations', true); + $this->dispatch('/opac/abonne/formations', true); } @@ -431,13 +429,13 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati class AbonneControllerFormationsFicheAbonneTest extends AbstractAbonneControllerFormationsTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/opac/abonne/fiche?retour=/opac/abonne/fiche', true); + $this->dispatch('/opac/abonne/fiche', true); } /** @test */ public function pageShouldContainsLinkToFormations() { - $this->assertXPathContentContains('//a[contains(@href, "/formations")]', + $this->assertXPathContentContains('//a[contains(@href, "/abonne/formations")]', 'S\'inscrire à une formation'); } @@ -450,14 +448,14 @@ class AbonneControllerFormationsFicheAbonneTest extends AbstractAbonneController /** @test */ public function pageShouldContainsLinkToRegistrations() { - $this->assertXPathContentContains('//a[contains(@href, "/formations/registered")]', + $this->assertXPathContentContains('//a[contains(@href, "/abonne/formations-registered")]', 'Mes inscriptions en cours'); } /** @test */ public function pageShouldContainsLinkToDone() { - $this->assertXPathContentContains('//a[contains(@href, "/formations/done")]', + $this->assertXPathContentContains('//a[contains(@href, "/abonne/formations-done")]', 'Mes formations suivies'); } } @@ -470,7 +468,7 @@ class AbonneControllerFormationsRegisteredActionTest public function setUp() { parent::setUp(); - $this->dispatch('/formations/registered', true); + $this->dispatch('/abonne/formations-registered', true); } @@ -523,10 +521,9 @@ class AbonneControllerFormationsDoneActionTest extends AbstractAbonneControllerFormationsTestCase { public function setUp() { - parent::setUp(); $this->_session_python_juillet->setDateDebut('2006-09-09')->assertSave(); - $this->dispatch('/formations/done', true); + $this->dispatch('/abonne/formations-done', true); } @@ -588,7 +585,7 @@ class AbonneControllerFormationsListWithoutRightSuivreFormationTest extends Abst public function setUp() { parent::setUp(); $this->_amadou->setUserGroups([]); - $this->dispatch('/opac/formations'); + $this->dispatch('/opac/abonne/formations'); } @@ -816,7 +813,7 @@ class AbonneControllerFormationsSessionJavaFevrierFullListTest extends AbonneCon parent::setUp(); Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'pseudo;nom;prenom;mail']); - $this->dispatch('/opac/formations'); + $this->dispatch('/opac/abonne/formations'); } @@ -833,7 +830,7 @@ class AbonneControllerFormationsSessionJavaFevrierFullAndInscritListTest extends public function pageShouldHaveLinkToDesinscrire() { $this->_session_java_fevrier->addStagiaire($this->_amadou); $this->_amadou->setSessionFormations(array($this->_session_java_fevrier)); - $this->dispatch('/opac/formations/registered'); + $this->dispatch('/opac/abonne/formations-registered'); $this->assertXPath('//a[contains(@href, "abonne/desinscrire-session/id/31")]'); } } @@ -886,14 +883,10 @@ class AbonneControllerFormationsInscritSessionWithoutRightSuivreFormationTest ex class AbonneControllerFormationsAmadouDesinscritSessionJuilletPythonTest extends AbstractAbonneControllerFormationsTestCase { - protected $_mails, $_previous_referer; + protected $_mails; public function setUp() { parent::setUp(); - $this->_previous_referer = isset($_SERVER['HTTP_REFERER']) - ? $_SERVER['HTTP_REFERER'] - : null; - $_SERVER['HTTP_REFERER'] = '/formations'; $this->dispatch('/opac/abonne/desinscrire-session/id/121', true); @@ -901,14 +894,6 @@ class AbonneControllerFormationsAmadouDesinscritSessionJuilletPythonTest } - public function tearDown() { - if ($this->_previous_referer) - $_SERVER['HTTP_REFERER'] = $this->_previous_referer; - - parent::tearDown(); - } - - /** @test */ function answerShouldRedirectToFormationList() { $this->assertRedirectTo('/formations'); @@ -1098,43 +1083,29 @@ class AbonneControllerFormationsSessionJuilletPythonDetailRetourFicheTest extend class AbonneControllerFormationsWrongIdsTest extends AbstractAbonneControllerFormationsTestCase { - protected $_previous_referer; - public function setUp() { parent::setUp(); - - $this->_previous_referer = isset($_SERVER['HTTP_REFERER']) - ? $_SERVER['HTTP_REFERER'] - : null; - - $_SERVER['HTTP_REFERER'] = '/formations'; + $_SERVER['HTTP_REFERER'] = '/abonne/formations'; } - public function tearDown() { - if ($this->_previous_referer) - $_SERVER['HTTP_REFERER'] = $this->_previous_referer; - - parent::tearDown(); - } - /** @test */ public function detailSessionShouldRedirectToFormations() { $this->dispatch('/opac/formations/detail-session/id/9999'); - $this->assertRedirectTo('/formations/index'); + $this->assertRedirectTo('/abonne/formations'); } /** @test */ public function inscrireSessionShouldRedirectToFormations() { $this->dispatch('/opac/abonne/inscrire-session/id/9999'); - $this->assertRedirectTo('/formations'); + $this->assertRedirectTo('/abonne/formations'); } /** @test */ public function desinscrireSessionShouldRedirectToFormations() { $this->dispatch('/opac/abonne/desinscrire-session/id/9999'); - $this->assertRedirectTo('/formations'); + $this->assertRedirectTo('/abonne/formations'); } } \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/FormationsControllerTest.php b/tests/application/modules/opac/controllers/FormationsControllerTest.php index 7bfdd5e7c89..00019e07925 100644 --- a/tests/application/modules/opac/controllers/FormationsControllerTest.php +++ b/tests/application/modules/opac/controllers/FormationsControllerTest.php @@ -127,6 +127,24 @@ class FormationsControllerFormationsSessionFevrierJavaTest extends AbstractForma + +class FormationsControllerAnonymousTest extends AbstractFormationsControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/formations', true); + } + + + /** @test */ + public function sessionShouldDisplaySubscribeTime() { + $this->assertXPathContentContains('//tbody//tr/td/span', + 'Date de limite d\'inscription:'); + } +} + + + + class FormationsControllerFormationsSessionJuilletPythonDetailRetourFicheTest extends AbstractFormationsControllerTestCase { public function setUp() { parent::setUp(); @@ -137,5 +155,4 @@ class FormationsControllerFormationsSessionJuilletPythonDetailRetourFicheTest ex public function pageShouldContainsAButtontoGoBackToFicheAbonne() { $this->assertXPathContentContains('//a[contains(@href, "abonne/fiche")]', 'Retour', $this->_response->getBody()); } - } \ No newline at end of file -- GitLab