Commit 8fc7f2df authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #69826 : add link to bookmark current search

parent 967fbd38
Pipeline #3313 passed with stage
in 25 minutes and 59 seconds
'69826' =>
['Label' => $this->_('[Contractuel] MINSOC - Diffusion sélective de l'information : Enregistrer / modifier ma recherche'),
'Desc' => '',
'Image' => '',
'Video' => '',
'Category' => '',
'Right' => function($feature_description, $user) {return true;},
'Wiki' => '',
'Test' => '',
'Date' => '2018-01-17'],
\ No newline at end of file
- ticket #69826 : [Contractuel] MINSOC - Diffusion sélective de l'information : Enregistrer / modifier ma recherche
\ No newline at end of file
......@@ -1209,4 +1209,14 @@ class AbonneController extends ZendAfi_Controller_Action {
$this->renderPopupResult($this->_('Compléter votre adresse email'),
$this->view->render('abonne/ajax-email.phtml'));
}
public function bookmarkSearchAction() {
if (!$this->_user)
return $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]);
$this->_user->bookmarkSearch()->save();
$this->_helper->_notify($this->_('Cette recherche a été enregistrée dans vos favoris'));
$this->_redirectClose($this->_getReferer());
}
}
\ No newline at end of file
......@@ -26,7 +26,8 @@ class Class_User_Settings {
REDMINE_LIBRARY = 'redmine_library',
ADMIN_SKIN = 'admin_skin',
ADMIN_SKIN_COLOR = 'admin_skin_color',
CHECKED_FEATURE = 'checked_features';
CHECKED_FEATURE = 'checked_features',
BOOKMARKED_SEARCHES = 'bookmarked_searches';
protected $_user, $_user_settings;
......@@ -260,5 +261,20 @@ class Class_User_Settings {
$this->set(self::BOOKMARKED_LIBRARIES, $id);
$this->_user->save();
}
public function bookmarkSearch() {
if (!$namespace = new Zend_Session_Namespace('historiqueRecherche'))
return $this->_user;
if (!$searches = $namespace->criteres)
return $this->_user;
if ( !$bookmarks = $this->get(self::BOOKMARKED_SEARCHES))
$bookmarks = [];
$this->set(self::BOOKMARKED_SEARCHES, array_merge($bookmarks,[array_pop($searches)]));
return $this->_user;
}
}
?>
\ No newline at end of file
......@@ -1783,6 +1783,11 @@ class Class_Users extends Storm_Model_Abstract {
}
public function bookmarkSearch() {
return $this->getSettingsModel()->bookmarkSearch();
}
public function getRedmineLibrary() {
return $this->getSettingsModel()->getRedmineLibrary();
}
......
......@@ -111,6 +111,14 @@ class ZendAfi_View_Helper_Search_Header extends ZendAfi_View_Helper_BaseHelper {
$this->_tagSuggestAction(),
$this->_tag('span',
$this->view->tagAnchor($this->view->url(['controller' => 'abonne',
'action' => 'bookmark-search'], null, true),
$this->_('Enregistrer cette recherche'),
['title' => $this->_('Enregistrer cette recherche dans mes favoris'),
'data-popup' => true]),
['class' => 'save']),
$this->_tag('span',
$this->view->tagPrintLink($instance),
['class' => 'print']),
......
......@@ -331,4 +331,4 @@ class AbonneControllerSettingsAdminSettingsTest extends AbonneControllerSettings
$this->dispatch('/admin/users/settings/key/show_admin_icons/value/0', true);
$this->assertEquals(0, Class_User_Settings::newWith($this->_user)->get('show_admin_icons'));
}
}
\ No newline at end of file
}
<?php
/**
* Copyright (c) 2012-2017, 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 Bookmarks_SearchAbonneTest extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true,
$_user;
public function setUp() {
parent::setUp();
$this->_user = Class_Users::getIdentity();
$criteres_potter = (new Class_CriteresRecherche)
->setParams(['expressionRecherche' => 'Harry Potter',
'page' => 2]);
$criteres_davis = (new Class_CriteresRecherche)
->setParams(['rech_auteurs' => 'Miles Davis',
'annee_fin' => '1970']);
$session = new Zend_Session_Namespace('historiqueRecherche');
$session->criteres = [serialize($criteres_potter), serialize($criteres_davis)];
$this->dispatch('/abonne/bookmark-search',true);
}
/** @test */
public function lastSearchDavisShouldBeBookmarkedInUserSettings() {
$this->assertEquals('Miles Davis',unserialize(Class_User_Settings::newWith($this->_user)->get('bookmarked_searches')[0])->getParam('rech_auteurs'));
}
}
class Bookmarks_SearchLinkTest extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->dispatch('/recherche/pomme', true);
}
/** @test */
public function linkToBookmarkSearchShouldBePresent() {
$this->assertXPathContentContains('//a[contains(@href, "/abonne/bookmark-search")]', 'Enregistrer cette recherche');
}
}
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