diff --git a/application/modules/opac/views/scripts/abonne/detail-session.phtml b/application/modules/opac/views/scripts/abonne/detail-session.phtml index 6924dc9f757e7cd500f9ed81d8e0d5a0f9f62aff..875c153cc65acc01a2fb8d50ed2f157654988fae 100644 --- a/application/modules/opac/views/scripts/abonne/detail-session.phtml +++ b/application/modules/opac/views/scripts/abonne/detail-session.phtml @@ -1,64 +1,14 @@ -<?php +<?php echo $this->openBoite(sprintf('Formation %s: session du %s', $this->session->getLibelleFormation(), $this->renderDateRange($this->session->getDateDebut(), - $this->session->getDateFin()))); - -?> - -<dl class="session_formation"> - <dt><?php echo $this->_('Lieu') ?></dt> - <dd><?php echo $this->renderLieu($this->session->getLieu(), array('size' => '300x300')) ?></dd> - - - <dt><?php echo $this->_('Horaires') ?></dt> - <dd><?php echo $this->session->getHoraires() ?></dd> - - - <dt><?php echo $this->_('Nombre de Participants') ?></dt> - <dd> - <?php - echo sprintf('%s: %d, %s: %d, %s: %d', - $this->_('minimum'), - $this->session->getEffectifMin(), - $this->_('maximum'), - $this->session->getEffectifMax(), - $this->_('actuel'), - $this->session->getNbStagiaires()); - ?> - </dd> - - <dt><?php echo $this->_('Intervenants') ?></dt> - <dd> - <ul> - <?php - foreach ($this->session->getIntervenants() as $intervenant) - echo sprintf('<li>%s, %s</li>', $intervenant->getNom(), $intervenant->getPrenom()); - ?> - </ul> - </dd> - - <dt><?php echo $this->_('Durée de la session') ?></dt> - <dd><?php echo sprintf('%d h', $this->session->getDuree()) ?></dd> - - - <dt><?php echo $this->_('Contenu') ?></dt> - <dd><?php echo $this->session->getContenu() ?></dd> -</dl> - - - -<div class='actions'> -<?php -echo $this->tagSessionFormationInscription($this->session); - -echo $this->tagAnchor($this->url(array('controller' => 'abonne', - 'action' => $this->retour_action), - null, - true), - $this->_('Retour')); - + $this->session->getDateFin()))); +echo $this->renderSession($this->session); +echo $this->tag('div', + $this->tagAnchor($this->url(['controller' => 'abonne', + 'action' => $this->retour_action] + ,null,true), + $this->_('Retour')), + ['class' => 'actions']); +echo $this->closeBoite(); ; ?> -</div> - -<?php echo $this->closeBoite(); ?> diff --git a/library/Class/SessionFormation.php b/library/Class/SessionFormation.php index b608593ff8083f69acb9218dade6cb8f05842ff8..9eeaa8b944b36b5ca8c64210f1d4224c2047f3da 100644 --- a/library/Class/SessionFormation.php +++ b/library/Class/SessionFormation.php @@ -23,35 +23,30 @@ class Class_SessionFormation extends Storm_Model_Abstract { use Trait_TimeSource; protected $_table_name = 'sessions_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', - 'dependents' => 'delete'), - - 'stagiaires' => array('through' => 'session_formation_inscriptions', - 'unique' => true), - - 'session_formation_interventions' => array('model' => 'Class_SessionFormationIntervention', - 'role' => 'session_intervention', - 'dependents' => 'delete'), - - 'intervenants' => array('through' => 'session_formation_interventions', - 'unique' => true)); - - protected $_default_attribute_values = array('effectif_min' => 1, - 'effectif_max' => 10, - 'cout' => 0, - 'duree' => 0, - 'date_debut' => '', - 'date_fin' => '', - 'date_limite_inscription' => null, - 'contenu' => '', - 'objectif' => '', - 'horaires' => '', - 'is_annule' => false); + protected $_belongs_to = ['formation' => ['model' => 'Class_Formation'], + 'lieu' => ['model' => 'Class_Lieu']]; + protected $_has_many = ['session_formation_inscriptions' => ['model' => 'Class_SessionFormationInscription', + 'role' => 'session_formation', + 'dependents' => 'delete'], + 'stagiaires' => ['through' => 'session_formation_inscriptions', + 'unique' => true], + 'session_formation_interventions' => ['model' => 'Class_SessionFormationIntervention', + 'role' => 'session_intervention', + 'dependents' => 'delete'], + 'intervenants' => ['through' => 'session_formation_interventions', + 'unique' => true]]; + + protected $_default_attribute_values = ['effectif_min' => 1, + 'effectif_max' => 10, + 'cout' => 0, + 'duree' => 0, + 'date_debut' => '', + 'date_fin' => '', + 'date_limite_inscription' => null, + 'contenu' => '', + 'objectif' => '', + 'horaires' => '', + 'is_annule' => false]; public static function getLoader() { return self::getLoaderFor(__CLASS__); @@ -183,6 +178,20 @@ class Class_SessionFormation extends Storm_Model_Abstract { public function getDateFinTexte() { return Class_Date::humanDate($this->getDateFin(), 'd MMMM yyyy'); } + + + public function isSubscriableFor($user) { + if(!$user) + return false; + + if(!$user->getRoleLevel()>= ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB) + return false; + + if(!$this->isValid() || $this->isFull() || $this->isAnnule()) + return false; + + return true; + } } ?> \ No newline at end of file diff --git a/library/Class/Users.php b/library/Class/Users.php index 712347d4b0bdf8af4793ab69188da32e5a451e0e..362b2c342b601b25106a1fe0b59b485cc348ee4f 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -1372,6 +1372,5 @@ class Class_Users extends Storm_Model_Abstract { } return $paniers; } - } ?> \ No newline at end of file diff --git a/library/ZendAfi/Form/Configuration/FormationsWidget.php b/library/ZendAfi/Form/Configuration/FormationsWidget.php index e6314f9f6a15f6987c8a4ce4d9df971ecd7b7b78..0515e3f1e02e4ac34df7aadc828a924deb40707a 100644 --- a/library/ZendAfi/Form/Configuration/FormationsWidget.php +++ b/library/ZendAfi/Form/Configuration/FormationsWidget.php @@ -22,7 +22,6 @@ class ZendAfi_Form_Configuration_FormationsWidget extends ZendAfi_Form { public static function newWith($module_settings) { - var_dump($module_settings['selected_formations']); $form = new self(); $form ->populate($module_settings) diff --git a/library/ZendAfi/View/Helper/RenderFormations.php b/library/ZendAfi/View/Helper/RenderFormations.php index b0c33bad6400ac2c169defff4398a044be22f778..176d7d0be5891f12e969829f61b1e24c371405ce 100644 --- a/library/ZendAfi/View/Helper/RenderFormations.php +++ b/library/ZendAfi/View/Helper/RenderFormations.php @@ -36,7 +36,6 @@ class ZendAfi_View_Helper_RenderFormations extends ZendAfi_View_Helper_BaseHelpe protected function renderFormation($formation) { $html = $formation->getLibelle(); - $html.= $this->renderSessions($formation->getAvailableSessions()); @@ -58,20 +57,8 @@ class ZendAfi_View_Helper_RenderFormations extends ZendAfi_View_Helper_BaseHelpe protected function renderSession($session) { - return $this->view->tag('li',$this->definitionList(array_merge(['is_full' => ($session->isFull() - ? $this->view->_('Complet'): '')], - $session->toArray()))); - } - - - protected function definitionList($datas) { - $html = ''; - foreach($datas as $dt => $dd) { - $html.= - $this->view->tag('dt', $dt). - $this->view->tag('dd', $dd); - } - return $this->view->tag('dl',$html); + return $this->view->tag('li', + $this->view->renderSession($session)); } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderSession.php b/library/ZendAfi/View/Helper/RenderSession.php new file mode 100644 index 0000000000000000000000000000000000000000..1884e6c57980efaaacfff5ea9ccfc0c040fee8d1 --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderSession.php @@ -0,0 +1,76 @@ +<?php +/** + * Copyright (c) 2012-2014, 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 ZendAfi_View_Helper_RenderSession extends ZendAfi_View_Helper_BaseHelper { + public function renderSession($session) { + return + $this->definitionListFor($session). + $this->actionsFor($session); + } + + + protected function actionsFor($session) { + return $this->view->tag('div', + $this->view->tagSessionFormationInscription($session), + ['class'=>'actions']); + } + + + protected function definitionListFor($session) { + $html = + $this->view->tag('dt', $this->view->_('Lieu')). + $this->view->tag('dd', $this->view->renderLieu($session->getLieu(), ['size' => '300x300'])). + $this->view->tag('dt', $this->view->_('Horaires')). + $this->view->tag('dd', $session->getHoraires()). + $this->view->tag('dt', $this->view->_('Etat')). + $this->view->tag('dd', $session->isFull() + ? $this->view->_('Complet') + : '' ). + $this->view->tag('dt', $this->view->_('Nombre de participants')). + $this->view->tag('dd', sprintf('%s: %d, %s: %d, %s: %d', + $this->view->_('minimum'), + $session->getEffectifMin(), + $this->view->_('maximum'), + $session->getEffectifMax(), + $this->view->_('actuel'), + $session->getNbStagiaires())). + $this->view->tag('dt', $this->view->_('Intervenants')). + $this->view->tag('dd', $this->getIntervenantsFor($session)). + $this->view->tag('dt', $this->view->_('Durée de la session')). + $this->view->tag('dd', $session->getDuree().' h'). + $this->view->tag('dt', $this->view->_('Contenu')). + $this->view->tag('dd', $session->getContenu()); + + return $this->view->tag('dl', $html , ['class' => 'session_formation']); + } + + + protected function getIntervenantsFor($session) { + $html = ''; + foreach ($session->getIntervenants() as $intervenant){ + $html.= $this->view->tag('li', $intervenant->getNom().', '.$intervenant->getPrenom()); + } + + return $this->view->tag('ul', $html); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/TagSessionFormationInscription.php b/library/ZendAfi/View/Helper/TagSessionFormationInscription.php index f9555b41504e29c5805320c876e83e4c1e846f8a..192952710c0781007ad36f0566ff3ebd6560abfa 100644 --- a/library/ZendAfi/View/Helper/TagSessionFormationInscription.php +++ b/library/ZendAfi/View/Helper/TagSessionFormationInscription.php @@ -39,8 +39,9 @@ class ZendAfi_View_Helper_TagSessionFormationInscription extends Zend_View_Helpe if ($is_inscrit) - $content = $this->view->tagAnchor(['action' => 'desinscrire-session', - 'id' => $session->getId()], + $content = $this->view->tagAnchor(['controller' => 'abonne', + 'action' => 'desinscrire-session', + 'id' => $session->getId()], $this->view->_("Se désinscrire")); if ($session->isFull()) @@ -50,8 +51,9 @@ class ZendAfi_View_Helper_TagSessionFormationInscription extends Zend_View_Helpe if ($is_inscrit) return $content; - $link_inscription = $this->view->tagAnchor(['action' => 'inscrire-session', - 'id' => $session->getId()], + $link_inscription = $this->view->tagAnchor(['controller' => 'abonne', + 'action' => 'inscrire-session', + 'id' => $session->getId()], $this->view->_("S'inscrire")); if (!$session->hasDateLimiteInscription()) diff --git a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php index fd2d7536f5ded7ab191d9b219005522173871bcc..4a8975019cff6a9978cc627397cacfdb04370577 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php @@ -696,7 +696,7 @@ class AbonneControllerFormationsSessionJuilletPythonDetailRetourFicheTest extend /** @test */ public function pageShouldContainsAButtontoGoBackToFicheAbonne() { - $this->assertXPathContentContains('//a[contains(@href, "abonne/fiche")]', 'Retour'); + $this->assertXPathContentContains('//a[contains(@href, "abonne/fiche")]', 'Retour', $this->_response->getBody()); } } diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php index 2ca54435599a67695d1771b7ad6f1a319258035f..fd788f3b775ef0b21ae8c55c190c8498d8ca3efd 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -1678,7 +1678,7 @@ class ProfilOptionsControllerWithFormationWidgetTest extends AbstractControllerT 'sessions' => [ $this->fixture('Class_SessionFormation', ['id' => 1, 'formation_id' => 1, - 'objectif' => 'dogfighting tricks', + 'contenu' => 'dogfighting tricks', 'date_debut' => '2014-05-02', 'date_fin' => '2014-05-30', 'date_limite_lnscription' => '2011-01-01', @@ -1720,7 +1720,7 @@ class ProfilOptionsControllerWithFormationWidgetTest extends AbstractControllerT /** @test */ public function sessionDogFigthShouldBeInChap1() { - $this->assertXpathContentContains('//div[@class="boite formations_widget"]//ul/li/ul/li/dl/dd', 'dogfighting tricks'); + $this->assertXpathContentContains('//div[@class="boite formations_widget"]//ul/li/ul/li/dl/dd', 'dogfighting tricks', $this->_response->getBody()); } diff --git a/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php b/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php index 8d38aa75812a95fdfda01dd55ce820059611b973..0221f24279ed741e96b683bd7974c9b3fa4aa5b5 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php @@ -24,10 +24,6 @@ class ZendAfi_View_Helper_Accueil_FormationWidgetTest extends ViewHelperTestCase public function setup() { parent::setup(); - $this->fixture('Class_Formation', - ['id' => 1, - 'libelle' => 'Air Dogfight chapter 1']); - $helper = new ZendAfi_View_Helper_Accueil_FormationsWidget( $this->fixture('Class_Formation', ['id' => 1, @@ -53,4 +49,48 @@ class ZendAfi_View_Helper_Accueil_FormationWidgetTest extends ViewHelperTestCase } } + + + +class ZendAfi_View_Helper_Accueil_FormationWidgetWithLoggedSIGBUserTest extends ViewHelperTestCase { + public function setup() { + + Class_Formation::setTimeSource(new TimeSourceForTest('2014-05-06 14:00:00')); + + $sigb_user = $this->fixture('Class_Users', + ['id' => 1, + 'login' => 'uR', + 'password' => 'pwd']) + ->beAbonneSIGB(); + + ZendAfi_Auth::getInstance()->logUser($sigb_user); + + $helper = new ZendAfi_View_Helper_Accueil_FormationsWidget( + $this->fixture('Class_Formation', + ['id' => 1, + 'libelle' => 'Air Dogfight chapter 1', + 'sessions' => [$this->fixture('Class_SessionFormation', + ['id' => 1, + 'date_debut' => '2014-06-01', + 'date_fin' => '2014-06-10'])]]), + ['division' => 1, + 'type_module' => 'FORMATIONS_WIDGET', + 'preferences' => ['selected_formations' => '1']]); + + $helper->setView(new ZendAfi_Controller_Action_Helper_View()); + $this->_html = $helper->getBoite(); + } + + + /** @test */ + public function session1ShouldBeDisplay() { + $this->assertXPathContentContains($this->_html,'//dl/dd', 'minimum: 1, maximum: 10, current: 0'); + } + + + /** @test */ + public function subscriptionLinkShouldBeDisplay() { + $this->assertXPath($this->_html, '//ul/li//a[contains(@href,"abonne/inscrire-session/id/1")]'); + } +} ?> \ No newline at end of file