Commit b5243f49 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #69826 implement notify / unnotify actions

parent dfcf8a1e
Pipeline #3338 passed with stage
in 26 minutes and 23 seconds
......@@ -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
......@@ -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]))
......
......@@ -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
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment