diff --git a/application/modules/opac/views/scripts/auth/boite-login.phtml b/application/modules/opac/views/scripts/auth/boite-login.phtml index a27e94a06ba3e86751ba53dab54646a4ac9ec9e9..4374530010fcfdad4f481e36d7da3be134ae2c56 100644 --- a/application/modules/opac/views/scripts/auth/boite-login.phtml +++ b/application/modules/opac/views/scripts/auth/boite-login.phtml @@ -19,10 +19,12 @@ $html = $this->tag('div', $this->preferences['message_connecte'] . ' ' . $this->abonne_NamesOrLogin($user), ['class' => 'welcome']); -if ($user->hasIdabon() && !$user->isAbonnementValid()) - $html .= $this->tag('p', - $this->_('Abonnement expiré - Merci de contacter la médiathèque'), - ['class' => 'expired']); +// if ($user->hasIdabon() && !$user->isAbonnementValid()) +// $html .= $this->tag('p', +// $this->_('Abonnement expiré - Merci de contacter la médiathèque'), +// ['class' => 'expired']); + +$html .= $this->renderNotifications($user); $user_url = $this->url(['controller' => 'abonne', 'action' => 'fiche', diff --git a/library/Class/Users.php b/library/Class/Users.php index 070bcf67644be03aa32eaa06c05d71bc2a25ab84..767969cd0fcb5a6ab728172f3d68f665a2c6db48 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -518,6 +518,13 @@ class Class_Users extends Storm_Model_Abstract { } + public function isILSExpired() { + if (!$this->isAbonne()) return false; + if (! $this->hasDateFin()) return false; + return ($this->getDateFin() < date("Y-m-d")); + } + + /** * Retourne la Date au format YYYY/MM/DD * @return string @@ -1510,8 +1517,17 @@ class Class_Users extends Storm_Model_Abstract { public function registerNotificationsOn($notifiable) { - $this->_notifications = ['tost']; - array_map([$notifiable, 'notify'], $this->_notifications); + $this + ->_notifyOn($notifiable, + $this->isILSExpired(), + $this->_('Abonnement expiré - Merci de contacter la médiathèque')); + } + + + protected function _notifyOn($notifiable, $condition, $message) { + if ($condition) + $notifiable->notify($message); + return $this; } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderNotifications.php b/library/ZendAfi/View/Helper/RenderNotifications.php new file mode 100644 index 0000000000000000000000000000000000000000..b8120e0436a03cb6710b9552b7521d730759c57e --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderNotifications.php @@ -0,0 +1,41 @@ + + + +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_View_Helper_RenderNotifications extends ZendAfi_View_Helper_BaseHelper { + protected $_messages = []; + + public function renderNotifications($user) { + $user->registerNotificationsOn($this); + return $this->view->tag('p', + implode('<br>', $this->_messages), + ['class' => 'user_notifications']); + } + + + public function notify($message) { + $this->_messages []= $message; + } +} + +?> \ No newline at end of file diff --git a/public/opac/css/global.css b/public/opac/css/global.css index 7255c900e707c108a38daace3188c05d3e1e5108..9aa44497b4d1c18d2158bf595299b4d05440b9a2 100644 --- a/public/opac/css/global.css +++ b/public/opac/css/global.css @@ -2818,7 +2818,7 @@ a.readspeaker { } -.boite.login .expired { +.boite.login .user_notifications { display: none; } diff --git a/tests/application/modules/opac/controllers/AuthControllerTest.php b/tests/application/modules/opac/controllers/AuthControllerTest.php index b9436ebd5476fdc9802061b1aecfe9bdd0795b8c..650d0f0e7f1e305c86c473fc68fd9d4d81201245 100644 --- a/tests/application/modules/opac/controllers/AuthControllerTest.php +++ b/tests/application/modules/opac/controllers/AuthControllerTest.php @@ -1566,7 +1566,7 @@ class AuthControllerAbonneSIGBNotValidLoggedTest extends PortailWithOneLoginModu /** @test */ public function shouldDisplayExpiredSubscription() { - $this->assertXPathContentContains('//div[@class="boite login"]//p[@class="expired"]', 'Abonnement expiré - Merci de contacter la médiathèque'); + $this->assertXPathContentContains('//div[@class="boite login"]//p[@class="user_notifications"]', 'Abonnement expiré - Merci de contacter la médiathèque'); } } diff --git a/tests/library/Class/UsersTest.php b/tests/library/Class/UsersTest.php index e6bc78bc270bfb47452faa2cad5177ac1d944f3e..5002e5298368e3e6a36c45899e6626ea79d5deab 100644 --- a/tests/library/Class/UsersTest.php +++ b/tests/library/Class/UsersTest.php @@ -606,13 +606,21 @@ class UsersLostPassTest extends UsersMailingActionTestCase { class UsersFicheAbonneTest extends ModelTestCase { protected - $_storm_default_to_volatile = true; + $_storm_default_to_volatile = true, + $_notifications = []; public function setUp() { parent::setUp(); Zend_Registry::get('translate')->setLocale('fr'); Storm_Cache::setDefaultZendCache(null); + $this->_notifiable = Storm_Test_ObjectWrapper::mock() + ->whenCalled('notify') + ->willDo( + function($message) { + $this->_notifications []= $message; + }); + $this->bib_astro = Class_IntBib::getLoader() ->newInstanceWithId(5) ->setCommParams(array("url_serveur" => 'http://astrolabe.com/opsys.wsdl')) @@ -625,13 +633,17 @@ class UsersFicheAbonneTest extends ModelTestCase { $this->patrick = Class_Users::getLoader() ->newInstanceWithId(666) ->setLogin('patrick') + ->beAbonneSIGB() + ->setDateFin('2001-04-03') ->setIdSite(5); $this->amadou = Class_Users::getLoader() ->newInstanceWithId(123) ->setLogin('amadou') ->setIdSite(5) - ->setIdabon(123); + ->setIdabon(123) + ->beAbonneSIGB() + ->setDateFin('2020-02-02'); $this->pret_potter = Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire() ->setTitre('Harry Potter') @@ -657,6 +669,24 @@ class UsersFicheAbonneTest extends ModelTestCase { } + /** @test */ + public function patrickNotificationsShouldContainsAbonnementExpire() { + $this->patrick->registerNotificationsOn($this->_notifiable); + + $this->assertEquals(['Abonnement expiré - Merci de contacter la médiathèque'], + $this->_notifications); + } + + + /** @test */ + public function amadouNotificationsShouldNotContainsAbonnementExpire() { + $this->amadou->registerNotificationsOn($this->_notifiable); + + $this->assertNotContains('Abonnement expiré - Merci de contacter la médiathèque', + $this->_notifications); + } + + /** @test */ public function withoutIdAbonShouldReturnErrorVousDevezVousConnecter() { $this->assertContains("Vous devez vous connecter",