diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 0f62ba026c17060a44d031cae090524cd864696a..2cfb6d8926db339d75015630844adf0c7dec1fe8 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -986,6 +986,7 @@ class AbonneController extends ZendAfi_Controller_Action { $data = $this->_request->getPost(); unset($data['id_items']); $form->updateUser($data)->save(); + $this->_redirect('/abonne/settings'); } } } diff --git a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml index 632bd3c3a8f22149ae9c233f78fd24ff82d61d18..f2f3cca934f6f6349dc93f20e53cfd3949fbb6e7 100644 --- a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml +++ b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml @@ -109,13 +109,13 @@ $html_facettes = '<div class="facette_outer" style="margin-left:10px;margin-top: $html_result .= '</div>'; $html_suggests = $this->suggests($this->suggests, $this->criteres_recherche); - $html_bookmarks = $this->bookmarks($this->bookmarks, $this->criteres_recherche); + $html_bookmarks = $this->bookmarks($this->bookmarks, $this->criteres_recherche, $preferences); $html_filters = ''; if ($hasFacettes || $hasTags) { $html_filters .= '<div class="filtre_recherche">'; - $html_filters .= $html_bookmarks; $html_filters .= $html_suggests; + $html_filters .= $html_bookmarks; if ($hasTags && (1 == $tagsPosition)) $html_filters.= $html_nuage_tags; if ($hasFacettes) $html_filters.= $html_facettes; if ($hasTags && (2 == $tagsPosition)) $html_filters.= $html_nuage_tags; diff --git a/library/Class/MoteurRecherche/Facettes.php b/library/Class/MoteurRecherche/Facettes.php index 00474b4e875b2086d4b374fb580c8f04c7c86f8c..cba27361b3c095811c6e607b1cc6857582a2c3fc 100644 --- a/library/Class/MoteurRecherche/Facettes.php +++ b/library/Class/MoteurRecherche/Facettes.php @@ -167,36 +167,31 @@ class Class_MoteurRecherche_Facettes { public function extractBookmarks($codes_count, $criteres, $preferences) { - if(!$user = Class_Users::getIdentity()) + if (!$preferences['bookmarks_enabled']) return []; - $ix = new Class_Indexation(); - if (!$search_words = $ix->getMots($criteres->getExpressionRecherche())) + if(!$user = Class_Users::getIdentity()) return []; - /* if (!$preferences['bookmarks_enabled']) */ - /* return []; */ + if(!$user_bookmarks = $user->getBookmarkedDomains()) + return []; $codification = Class_Codification::getInstance(); $matches = []; - if(!$user_bookmarks = $user->getBookmarkedDomains()) - return []; - $user_bookmarks_codes = array_map(function($domain) {return $domain->getFacetThesaurus();}, $user_bookmarks); + foreach($user_bookmarks_codes as $bookmark_code) { + if(isset($codes_count[$bookmark_code])) { + if(!$facet = Class_Notice_Facette::find($bookmark_code)) + continue; - foreach($codes_count as $code => $count) { - $facet = Class_Notice_Facette::find($code); - - if (!$facet_label = $facet->getLibelleFacette()) - continue; + if (!$facet_label = $facet->getLibelleFacette()) + continue; - if (count($user_bookmarks_codes) == count(array_diff($user_bookmarks_codes, [$code]))) - continue; - - $matches[] = ['id' => $code, - 'label' => $facet->getCodeRubriqueLibelle() . ' : ' . $facet_label . ' (' . $count . ')']; + $matches[] = ['id' => $bookmark_code, + 'label' => $facet->getCodeRubriqueLibelle() . ' : ' . $facet_label . ' (' . $codes_count[$bookmark_code] . ')']; + } } return $matches; diff --git a/library/Class/MoteurRecherche/Result.php b/library/Class/MoteurRecherche/Result.php index a35c32b035c4edb8836bfefd0b48b51c24815c61..ca7b2c8427f1833d05b4584957b0c41777bf1155 100644 --- a/library/Class/MoteurRecherche/Result.php +++ b/library/Class/MoteurRecherche/Result.php @@ -81,8 +81,6 @@ class Class_MoteurRecherche_Result { } - - protected function _fetchFromCache($request){ return (new Storm_Cache()) ->memoize( @@ -94,8 +92,6 @@ class Class_MoteurRecherche_Result { } - - public function fetchRecords() { if ($this->_records_query && !isset($this->_records)) $this->_records = Class_Notice::findAllByIds($this->fetchAllRecordsIds(), diff --git a/library/Class/Notice/RubriqueFacette.php b/library/Class/Notice/RubriqueFacette.php index de33bab69426147b236e89491e8d09298d1735d1..73d76e3e9c224963a8f7844b17c5b532f5af4d97 100644 --- a/library/Class/Notice/RubriqueFacette.php +++ b/library/Class/Notice/RubriqueFacette.php @@ -88,7 +88,7 @@ class Class_Notice_RubriqueFacette { public function getLibelle() { - if (!isset($this->_libelle)) + if (!isset($this->_libelle) || !$this->_libelle) $this->_libelle = Class_Codification::getInstance()->getNomFacette($this->_code); return $this->_libelle; diff --git a/library/Class/Systeme/ModulesAppli.php b/library/Class/Systeme/ModulesAppli.php index ed292117cb1dfdb82a23e1dd7dbc6463d17540f9..6b69a569e464d9aabe7a56591883d1d45cacc7b1 100644 --- a/library/Class/Systeme/ModulesAppli.php +++ b/library/Class/Systeme/ModulesAppli.php @@ -348,6 +348,7 @@ class Class_Systeme_ModulesAppli extends Class_Systeme_ModulesAbstract { $ret["facettes_message"] = "Affiner le résultat..."; // Message au dessus de la boite $ret["suggests_enabled"] = 1; // Display search suggests $ret["suggests_number"] = 3; // Number of suggests + $ret["bookmarks_enabled"] = 1; // Display search suggests $ret["tags_actif"] = 1; // Afficher les tags de liste $ret["tags_codes"] = "AMDPZ"; // Types de tags a afficher $ret["tags_nombre"] = 30; // Nombre de tags a afficher diff --git a/library/ZendAfi/Form/Configuration/SearchResult.php b/library/ZendAfi/Form/Configuration/SearchResult.php index e047948bb1b16b14ef23129385e136b7109c2b22..7e0bf5c60ba0587e1e5bc48dc71b95dad5c8bdf8 100644 --- a/library/ZendAfi/Form/Configuration/SearchResult.php +++ b/library/ZendAfi/Form/Configuration/SearchResult.php @@ -76,6 +76,10 @@ class ZendAfi_Form_Configuration_SearchResult extends ZendAfi_Form { 'suggests', ['legend' => $form->_('Suggestions')]) + ->addDisplayGroup(['bookmarks_enabled'], + 'bookmarks', + ['legend' => $form->_('Préférences utilisateur')]) + ->addCvsGroup() ->addDisplayGroup(['submit'], 'submit', @@ -226,9 +230,11 @@ class ZendAfi_Form_Configuration_SearchResult extends ZendAfi_Form { 'options' => [ 'min' => 1, 'max' => 50, - 'messages' =>'Le nombre de tags doit être compris entre 1 et 50'] + 'messages' =>'Le nombre de tags doit être compris entre 1 et 50']]]]) - ]]]) + ->addElement('checkbox', + 'bookmarks_enabled', + ['label' => $this->_('Afficher les préférences des utilisateurs')]) ->addCvsElement() diff --git a/library/ZendAfi/View/Helper/Bookmarks.php b/library/ZendAfi/View/Helper/Bookmarks.php index 9645d1d31040f47bef17d3033883c43d7b641c89..48e1036322621095dbc9ff3f8168811da705d92c 100644 --- a/library/ZendAfi/View/Helper/Bookmarks.php +++ b/library/ZendAfi/View/Helper/Bookmarks.php @@ -22,37 +22,43 @@ class ZendAfi_View_Helper_Bookmarks extends ZendAfi_View_Helper_BaseHelper { - public function bookmarks($bookmarks, $criteres) { - if (empty($bookmarks)) + public function bookmarks($bookmarks, $criteres, $preferences) { + if(!$preferences['bookmarks_enabled'] || 0 == count($bookmarks)) return ''; $url_base = $this->view->url(array_merge($criteres->getUrlRetourListe(), - ['controller' => 'recherche', - 'action' => 'simple', - 'page' => null]), null, true); + ['controller' => 'recherche', + 'action' => 'simple', + 'page' => null]), null, true); $links = array_map( - function ($bookmark) use ($url_base){ - return - $this->_tag('li', - $this->_tag('a', - $bookmark['label'], - ['href' => $url_base . '/facette/'.$bookmark['id']]), - ['class' => 'facette']); - - }, - $bookmarks); - - return - $this->_tag('div', - $this->_tag('h2', $this->_('Préférences')). - $this->_tag('div', - $this->_tag('ul', - implode($links), - ['style' => 'list-style-image:url(' . URL_IMG . 'puce_facette.gif)']). - $this->view->tagAnchor($this->view->url(['module' => 'opac', 'controller' => 'abonne' , 'action' => 'settings']), $this->_('Modifier vos préférences')), - ['class' => 'suggests facette']), - ['class' => 'suggests_outer facette_outer']); + function ($bookmark) use ($url_base){ + return + $this->_tag('li', + $this->_tag('a', + $bookmark['label'], + ['href' => $url_base . '/facette/'.$bookmark['id']]), + ['class' => 'facette']); + + }, + $bookmarks); + + $edit = $this->view->tagAnchor($this->view->url(['module' => 'opac', 'controller' => 'abonne' , 'action' => 'settings'], null, true), + '', + ['title' => $this->_('Modifier mes préférences'), + 'class' => 'bookmarks_edit']); + + + $title = $this->_tag('h2', $this->_('Affiner le résutlat avec mes préférences...') . $edit); + + $bookmarks_html = $this->_tag('div', + $this->_tag('ul', + implode($links), + ['style' => 'list-style-image:url(' . URL_IMG . 'puce_facette.gif)']), + ['class' => 'bookmark facette']); + + $content = $title . $bookmarks_html; + return $this->_tag('div', $content , ['class' => 'bookmarks_outer facette_outer']); } } ?> \ No newline at end of file diff --git a/public/opac/css/global.css b/public/opac/css/global.css index a2d2854ffa7896d3be91c4c8a9c105a1b4609e7f..53512f660d70933ad85e8f88d253ab9c0e0753bc 100644 --- a/public/opac/css/global.css +++ b/public/opac/css/global.css @@ -495,15 +495,25 @@ div#open_accessibility:hover { .facette ul ul, -.suggests.facette ul { +.suggests.facette ul, +.bookmark.facette ul { padding-left:22px; } +.bookmarks.facette, .suggests.facette { padding-top: 1px; padding-bottom: 1px; } +.bookmarks_outer h2 .bookmarks_edit { + display: inline-block; + width: 16px; + height: 16px; + float: right; + background: url(../../admin/images/ico/edit.gif) no-repeat center center; +} + .facette ul ul ul, .facette ul { padding-left:0px; diff --git a/tests/application/modules/admin/controllers/ModulesControllerTest.php b/tests/application/modules/admin/controllers/ModulesControllerTest.php index a5b8744e5c540473e462079c18ce586c0429f206..ebd0d4520dc386a6286dc11639493c7a3f764856 100644 --- a/tests/application/modules/admin/controllers/ModulesControllerTest.php +++ b/tests/application/modules/admin/controllers/ModulesControllerTest.php @@ -495,6 +495,12 @@ class ModulesControllerConfigRechercheResultatTest } + /** @test */ + public function checkboxBookmarksEnabledShouldBeChecledByDefault() { + $this->assertXPath('//input[@type="checkbox"][@name="bookmarks_enabled"][@checked="checked"]'); + } + + /** @test */ public function inputSuggestsNumberShouldBeThreeDefault() { $this->assertXPath('//input[@name="suggests_number"][@value="3"]'); diff --git a/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php b/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php index 59b2b2d4d93c79ace4b39da27226a3e7f28faa11..54206b6b67fa4ca00d86991ef646cc51e69418a9 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php @@ -63,4 +63,10 @@ class AbonneControllserSettingsFormPostTest extends AbstractControllerTestCase { public function userSettingsShouldHaveBeenUpdated() { $this->assertEquals([$this->music, $this->sport], $this->_user->getBookmarkedDomains()); } + + + /** @test */ + public function shouldRedirect() { + $this->assertRedirect(); + } } \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index 9718e28d32e032ee1e3f8599b259ebc413b9a8aa..176f9da24a323d8a22e5388f8f4eabe349c515dc 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -1144,10 +1144,10 @@ class RechercheAvanceeControllerSimpleActionWithDefaultConfigTest extends Recher ] ], 'bookmarks' => [ - [ - 'id' => 'dom1', - 'label' => 'Music' - ] + [ + 'id' => 'HCCCC0001', + 'label' => 'Music' + ] ], 'tags' => [ 1=>[ @@ -1167,6 +1167,13 @@ class RechercheAvanceeControllerSimpleActionWithDefaultConfigTest extends Recher Class_MoteurRecherche::setInstance($mock_moteur_recherche); + ZendAfi_Auth::getInstance()->logUser($this->fixture('Class_Users', + ['id' => 1, + 'login' => 'Lok', + 'password' => 'Lik', + 'settings' => Class_User_Settings::serializeSettings([Class_User_Settings::BOOKMARKED_DOMAINS => 1])])); + + $this->dispatch('/recherche/simple?rech_titres=maupassant',true); } @@ -1198,6 +1205,18 @@ class RechercheAvanceeControllerSimpleActionWithDefaultConfigTest extends Recher 'CD (Sujet)', $this->_response->getBody()); } + + + /** @test */ + public function bookmarksWidgetShouldBePresent() { + $this->assertXPathContentContains('//div[@class="filtre_recherche"]//div[contains(@class, "bookmarks_outer")]', 'préférences'); + } + + + /** @test */ + public function bookmarkFacetLinkShouldBePresent() { + $this->assertXPathContentContains('//div[@class="filtre_recherche"]//div[contains(@class, "bookmark")]//a[contains(@href, "/facette/HCCCC0001")]', 'Music'); + } } diff --git a/tests/library/Class/MoteurRecherche/MoteurRechercheFacettesTest.php b/tests/library/Class/MoteurRecherche/MoteurRechercheFacettesTest.php index 03c513d101f12fc32e355a4ef8721f1b24d5f8c4..d8bf8f6c2768633678df1f0ef8df638089927fe3 100644 --- a/tests/library/Class/MoteurRecherche/MoteurRechercheFacettesTest.php +++ b/tests/library/Class/MoteurRecherche/MoteurRechercheFacettesTest.php @@ -53,6 +53,30 @@ class MoteurRechercheFacettesTest extends ModelTestCase { Class_CodifMatiere::newInstanceWithId('6567', ['libelle' => 'Pommes : albums']); + ZendAfi_Auth::getInstance()->logUser($this->fixture('Class_Users', + ['id' => 1, + 'login' => 'Lok', + 'password' => 'Lik', + 'settings' => Class_User_Settings::serializeSettings([Class_User_Settings::BOOKMARKED_DOMAINS => 1])])); + + $this->fixture('Class_Catalogue', + ['id' => 1, + 'libelle' => 'Games']); + + $this->fixture('Class_CodifThesaurus', ['id' => 'HCCCC', + 'code' => 'Catalogue', + 'id_thesaurus'=>'CCCC', + 'id_origine' => '', + 'libelle' => 'Domaines', + 'libelle_facette' => null]); + + $this->fixture('Class_CodifThesaurus', ['id' => 'HCCCC0001', + 'code' => 'Catalogue', + 'id_thesaurus'=>'CCCC0001', + 'id_origine' => 1, + 'libelle' => 'Games', + 'libelle_facette' => null]); + $this->fixture('Class_CodifThesaurus', ['id' => 'TES10002', 'id_thesaurus'=>'TES10002', 'libelle' => 'Culture', @@ -84,7 +108,6 @@ class MoteurRechercheFacettesTest extends ModelTestCase { ['id' => 3, 'libelle' => 'Cran']); - $this->setupSearch('albums pommes'); } @@ -99,7 +122,8 @@ class MoteurRechercheFacettesTest extends ModelTestCase { 'facettes_codes'=>'MFSABZLYHTHEMHTES1V', 'facettes_actif' => 1, 'suggests_enabled' => 1, - 'suggests_number' => 5 + 'suggests_number' => 5, + 'bookmarks_enabled' => 1 ]); } @@ -110,7 +134,6 @@ class MoteurRechercheFacettesTest extends ModelTestCase { } - /** @test */ public function suggestsShouldContainsPommesAlbumsMatiere() { $this->assertEquals(['id' => 'M6567', @@ -119,7 +142,6 @@ class MoteurRechercheFacettesTest extends ModelTestCase { } - /** @test */ public function suggestWithEmptySearchShouldBeEmpty() { $this->setupSearch(''); @@ -147,6 +169,22 @@ class MoteurRechercheFacettesTest extends ModelTestCase { } + /** @test */ + public function bookmarksShouldContainsDomainGamesFacet() { + $this->assertEquals(['id' => 'HCCCC0001', + 'label' => 'Domaines : Games (1)'], + $this->facettes['bookmarks'][0]); + } + + + /** @test */ + public function bookmarksWithEmptySearchShouldNotBeEmpty() { + $this->setupSearch(''); + $this->assertEquals([['id' => 'HCCCC0001', + 'label' => 'Domaines : Games (1)']], $this->facettes['bookmarks']); + } + + /** @test */ public function facettesCountShouldBeNine() { $this->assertEquals(9, count($this->facettes['facettes'])); @@ -264,7 +302,8 @@ class MoteurRechercheFacettesTest extends ModelTestCase { 'facettes_codes'=>'MFSABZLYHTHEMHTES1V', 'facettes_actif' => 1, 'suggests_enabled' => 0, - 'suggests_number' => 1 + 'suggests_number' => 1, + 'bookmarks_enabled' => 0 ]); $this->assertEquals(813, count($this->facettes['facettes']['A'])); @@ -280,10 +319,26 @@ class MoteurRechercheFacettesTest extends ModelTestCase { 'facettes_codes'=>'MFSABZLYHTHEMHTES1V', 'facettes_actif' => 1, 'suggests_enabled' => 0, - 'suggests_number' => 1 + 'suggests_number' => 1, + 'bookmarks_enabled' => 0 ]); $this->assertEmpty($facettes['suggests']); + } + + /** @test */ + public function whenBookmarksDisabledShouldNotCompute() { + $facettes = $this->_result->fetchFacetsAndTags(['facettes_nombre' => 5, + 'tags_actif' => 1, + 'tags_codes'=> 'MDPZAHTES1', + 'tags_nombre' => 30, + 'facettes_codes'=>'MFSABZLYHTHEMHTES1V', + 'facettes_actif' => 1, + 'suggests_enabled' => 0, + 'suggests_number' => 1, + 'bookmarks_enabled' => 0 + ]); + $this->assertEmpty($facettes['bookmarks']); } } @@ -1169,7 +1224,7 @@ class MoteurRechercheFacettesFixtures { ' A29282 T3 B1', - ' A14251 M6567 HTES10002 Lfre T1 B1', + ' A14251 M6567 HTES10002 Lfre T1 B1 HCCCC0001', ' A781 A2696 Lfre T1 B1',