diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 3fdcc5ffe5b67475d1b8f3cc7baf0f9e7fc19e65..56b42552f82bc707b4a0bfacc2c9449b6335cd23 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -97,8 +97,8 @@ class AbonneController extends ZendAfi_Controller_Action { $this->_user->removeSessionActivity($session); if ($this->_user->save()) { $this->_helper->notify($this->_('Vous n\'êtes plus inscrit à la session du %s de l\'activité %s', - $this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'), - $session->getLibelleActivity())); + $this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'), + $session->getLibelleActivity())); (new Class_Activity_UnregistrationMail($session, $this->_user))->send(); }; @@ -622,17 +622,17 @@ class AbonneController extends ZendAfi_Controller_Action { $mode = $this->_getParam('mode', ''); if ($mode === 'holdable-day') return $this->_forward('is-holdable-day', 'multimedia', $this->_request->getModuleName(), - $this->_request->getParams()); + $this->_request->getParams()); if ($mode === 'hold') return $this->_forward('hold-device', 'multimedia', $this->_request->getModuleName(), - $this->_request->getParams()); + $this->_request->getParams()); if ($mode === 'modified-hold') return $this->_forward('close-holding', 'multimedia', $this->_request->getModuleName(), - $this->_request->getParams()); + $this->_request->getParams()); return $this->_forward('authenticate', 'multimedia', $this->_request->getModuleName(), - $this->_request->getParams()); + $this->_request->getParams()); } @@ -1073,7 +1073,7 @@ class AbonneController extends ZendAfi_Controller_Action { function($child) { return $this->_('Vous n\'utilisez plus la carte de %s', - $child->getNomComplet()); + $child->getNomComplet()); }); } @@ -1234,7 +1234,7 @@ class AbonneController extends ZendAfi_Controller_Action { $form->setAction(Class_Url::absolute('/abonne/bookmark-search')); if( !$this->_request->isPost() || !$form->isValid($this->_request->getPost())) - return; + return; $criterias = Class_User_BookmarkedSearch::newInstance(['id_user' => $this->_user->getId(), 'label' => $this->_getParam('label'), @@ -1262,22 +1262,57 @@ class AbonneController extends ZendAfi_Controller_Action { public function deleteBookmarkedSearchAction() { $this->view->titre = $this->_('Supprimer la recherche de mes favoris'); - if(!$this->_user) - return $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]); + if(!$search = $this->_checkBookmarkedSearchRequest()) + return; + + $search->delete(); + $this->_helper->_notify($this->_('La recherche "%s" a été supprimée.', $search->getLabel())); + return $this->_redirectClose($this->_getReferer()); + } + + + protected function _checkBookmarkedSearchRequest() { + if(!$this->_user) { + $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]); + return; + } if(!$search = Class_User_BookmarkedSearch::find($this->_getParam('id', 0))) { $this->_helper->_notify($this->_('La recherche demandée est introuvable.')); - return $this->_redirectClose($this->_getReferer()); + $this->_redirectClose($this->_getReferer()); + return; } if(!$search->belongsTo($this->_user)) { - $this->_helper->_notify($this->_('Vous n\'avez pas les droits pour supprimer cette recherche.')); - return $this->_redirectClose($this->_getReferer()); + $this->_helper->_notify($this->_('Cette recherche ne vous appartient pas.')); + $this->_redirectClose($this->_getReferer()); + return; } - $search->delete(); - $this->_helper->_notify($this->_('La recherche "%s" a été supprimée.', $search->getLabel())); + return $search; + + } + + + public function notifyBookmarkedSearchAction() { + if(!$search = $this->_checkBookmarkedSearchRequest()) + return; + + $search->beNotified()->save(); + + $this->_helper->_notify($this->_('Les notifications de nouveautés pour la recherche "%s" sont activées.', $search->getLabel())); + return $this->_redirectClose($this->_getReferer()); + } + + + public function unnotifyBookmarkedSearchAction() { + if(!$search = $this->_checkBookmarkedSearchRequest()) + return; + + $search->beUnnotified()->save(); + + $this->_helper->_notify($this->_('Les notifications de nouveautés pour la recherche "%s" sont désactivées.', $search->getLabel())); return $this->_redirectClose($this->_getReferer()); } } \ No newline at end of file diff --git a/application/modules/opac/views/scripts/abonne/settings.phtml b/application/modules/opac/views/scripts/abonne/settings.phtml index 142f4d95a35344bfa5b4b56e6e118396541def9e..36dd06aa81eef63ad8179e085d925b50d67bde7b 100644 --- a/application/modules/opac/views/scripts/abonne/settings.phtml +++ b/application/modules/opac/views/scripts/abonne/settings.phtml @@ -19,10 +19,12 @@ return $this->tagPreview(Class_Url::relative($model->getCriteriasUrl()), { $action = 'notify-bookmarked-search'; $label = $this->_('Me notifier des nouveautés'); + $icon = 'toggle_off'; if($model->isNotified()) { $action = 'unnotify-bookmarked-search'; $label = $this->_('Annuler la notification des nouveautés'); + $icon = 'toggle_on'; } $params = ['controller' => 'abonne', @@ -30,16 +32,23 @@ return $this->tagPreview(Class_Url::relative($model->getCriteriasUrl()), 'id' => $model->getId()]; return $this->tagAnchor($this->url($params, null, true), - $label); + Class_Admin_Skin::current()->renderActionIconOn($icon, $this, + ['title' => $label, + 'alt' => $label]), + ['title' => $label]); }) ->addRowAction(function ($model) { - return $this->renderModelActions($model, [ ['url' => $this->url(['controller' => 'abonne', - 'action' => 'delete-bookmarked-search', - 'id' => $model->getId()],null,true), - 'icon' => 'delete', - 'anchorOptions' => ['onclick' => "return confirm('Etes-vous sûr de vouloir supprimer cette recherche ?');"], - 'label' => $this->_('Supprimer la recherche "%s"', $model->getLabel())]]); + $label = $this->_('Supprimer la recherche "%s"', $model->getLabel()); + return $this->tagAnchor($this->url(['controller' => 'abonne', + 'action' => 'delete-bookmarked-search', + 'id' => $model->getId()],null,true), + Class_Admin_Skin::current()->renderActionIconOn('delete', $this, + ['title' => $label, + 'alt' => $label]), + ['onclick' => "return confirm('Etes-vous sûr de vouloir supprimer cette recherche ?');", + 'title' => $label]); + }); if(!$searches = $this->renderTable($description, $this->bookmarked_searches, ['sorter' => true])) diff --git a/library/Class/User/BookmarkedSearch.php b/library/Class/User/BookmarkedSearch.php index c7f5b46a314c710c8bbd47f2c608753123878a7b..66fe3c0b519d5c15e23bdcb7adc628ae98ca40de 100644 --- a/library/Class/User/BookmarkedSearch.php +++ b/library/Class/User/BookmarkedSearch.php @@ -65,6 +65,16 @@ class Class_User_BookmarkedSearch extends Storm_Model_Abstract { public function isNotified() { - return $this->getNotified(); + return 1 == $this->getNotified(); + } + + + public function beNotified() { + return $this->setNotified(1); + } + + + public function beUnnotified() { + return $this->setNotified(0); } } \ No newline at end of file diff --git a/tests/scenarios/bookmarks/SearchTest.php b/tests/scenarios/bookmarks/SearchTest.php index e2152d7235f53469107d539b0a6b04c00a2987f5..e8e11de15c9aad878a2d5f356ff7d22209961949 100644 --- a/tests/scenarios/bookmarks/SearchTest.php +++ b/tests/scenarios/bookmarks/SearchTest.php @@ -266,3 +266,54 @@ class Bookmarks_SearchDeleteBookmarkedSearchTest extends Bookmarks_SearchWithSes $this->assertFlashMessengerContentContains('La recherche "Miles Davis" a été supprimée.'); } } + + + +class Bookmarks_SearchNotifyBookmarkedSearchTest extends Bookmarks_SearchWithSessionAbstract { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_User_BookmarkedSearch', + ['id' => 5, + 'id_user' => $this->_user->getId(), + 'label' => 'Miles Davis', + 'criterias' => '', + 'creation_date' => '2018-01-17 15:05:57']); + + $this->dispatch('/abonne/notify-bookmarked-search/id/5', true); + } + + + /** @test */ + public function searchMilesDavisShouldBeMarkAsNotified() { + $this->assertTrue(Class_User_BookmarkedSearch::find(5)->isNotified()); + } +} + + + +class Bookmarks_SearchUnnotifyBookmarkedSearchTest extends Bookmarks_SearchWithSessionAbstract { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_User_BookmarkedSearch', + ['id' => 5, + 'id_user' => $this->_user->getId(), + 'label' => 'Miles Davis', + 'notified' => 1, + 'criterias' => '', + 'creation_date' => '2018-01-17 15:05:57']); + + $this->dispatch('/abonne/unnotify-bookmarked-search/id/5', true); + } + + + /** @test */ + public function searchMilesDavisShouldBeMarkAsUnNotified() { + $this->assertFalse(Class_User_BookmarkedSearch::find(5)->isNotified()); + } +} \ No newline at end of file