diff --git a/FEATURES/124404 b/FEATURES/124404 new file mode 100644 index 0000000000000000000000000000000000000000..d4f104ed024cb9b3fde905c72f7c8998df0b49fe --- /dev/null +++ b/FEATURES/124404 @@ -0,0 +1,10 @@ + '124404' => + ['Label' => $this->_('Mine en avant des termes recherchés'), + 'Desc' => $this->_('Magasin de thèmes : Il est maintenant possible de mettre en avant les termes recherchés dans le résultat de recherche.', + 'Image' => '', + 'Video' => 'https://youtu.be/iN2HIn_w50k', + 'Category' => $this->_('Recherche'), + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => 'https://wiki.bokeh-library-portal.org/index.php?title=R%C3%A9sultat_de_recherche', + 'Test' => '', + 'Date' => '2022-01-14'], \ No newline at end of file diff --git a/VERSIONS_WIP/124404 b/VERSIONS_WIP/124404 new file mode 100644 index 0000000000000000000000000000000000000000..3eb00478e8ef3c0d34bcf8f6fd7336ff7ae92e31 --- /dev/null +++ b/VERSIONS_WIP/124404 @@ -0,0 +1 @@ + - Nouveau #124404 : Magasin de thèmes : Il est maintenant possible de mettre en avant les termes recherchés dans le résultat de recherche. \ No newline at end of file diff --git a/library/Class/MoteurRecherche/Result.php b/library/Class/MoteurRecherche/Result.php index eac7eb47377ca2e890cbf69f46a25cda84bb4641..141c37d1f20cc17e36173e152c79735a7f0660c7 100644 --- a/library/Class/MoteurRecherche/Result.php +++ b/library/Class/MoteurRecherche/Result.php @@ -114,6 +114,15 @@ class Class_MoteurRecherche_Result { } + public function shouldHighlightRecords() : bool { + if ( ! $settings = $this->getSettings() ) + return false; + + return isset($settings['highlight_search_terms']) + && '1' === (string) $settings['highlight_search_terms']; + } + + public function fetchAllRecordsIds() { if (isset($this->_ids)) return $this->_ids; diff --git a/library/Class/MoteurRecherche/Terms.php b/library/Class/MoteurRecherche/Terms.php index 1785eb14f231a31a2cc72196067985d4ea3f5196..1baf6a28d15ae8fe3d634c80d324f36ec5d6efb2 100644 --- a/library/Class/MoteurRecherche/Terms.php +++ b/library/Class/MoteurRecherche/Terms.php @@ -85,8 +85,12 @@ class Class_MoteurRecherche_Terms { protected function _injectRecordsPhonetix($record, $phonetixs) { $words = preg_split('/\W+/u', - mb_strtolower($record->getTitrePrincipal(' '). - ' ' . $record->getAuteurPrincipal())); + mb_strtolower(implode(' ', + [$record->getTitreEtSousTitre(' '), + $record->getMainAuthorFromCodif(), + $record->getCollection(), + $record->getMatieres(), + $record->getOtherTerms()]))); foreach ($words as $token) $phonetixs = $this->_injectTermPhonetix($token, $phonetixs); diff --git a/library/Class/Notice/SerieLinks.php b/library/Class/Notice/SerieLinks.php index 566a30a2a6e5b7d8f1fa6ba268eb81b1b97cfd6f..fc59f74dab83bdd728878146ccb23af8f870e4c6 100644 --- a/library/Class/Notice/SerieLinks.php +++ b/library/Class/Notice/SerieLinks.php @@ -25,6 +25,7 @@ class Class_Notice_SerieLinks { protected Class_Notice $_record; + public function __construct(Class_Notice $record) { $this->_record = $record; } diff --git a/library/Class/Template.php b/library/Class/Template.php index 3a454bfcfc198cb10b1dd9a1e9d5e7332e4c4839..5bad85cd64489ed400444536e46d3dce11cf0db4 100644 --- a/library/Class/Template.php +++ b/library/Class/Template.php @@ -687,4 +687,9 @@ class Class_Template { public function validate() {} + + + public function shouldHighlightRecords() : bool { + return (bool) Class_AdminVar::isSearchTermHighlightedEnabled(); + } } diff --git a/library/ZendAfi/Form/Configuration/Widget/Action/SearchResult.php b/library/ZendAfi/Form/Configuration/Widget/Action/SearchResult.php index 00f1e546b297d330a626a763b6a69dbb3fb21262..7c90e755ad0d715adbd0f197359a93d1e17eaaf9 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Action/SearchResult.php +++ b/library/ZendAfi/Form/Configuration/Widget/Action/SearchResult.php @@ -69,6 +69,10 @@ class ZendAfi_Form_Configuration_Widget_Action_SearchResult 'multiOptions' => [Class_Systeme_ModulesAppli::LISTE_FORMAT_LIST => $this->_('liste'), Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR => $this->_('mur')]]) + ->addElement('checkbox', + 'highlight_search_terms', + ['label' => $this->_('Mise en avant des mots recherchés')]) + ->addElement('userfile', Class_Notice_Xsl::KEY, ['label' => $this->_('Fichier XSL'), @@ -99,6 +103,7 @@ class ZendAfi_Form_Configuration_Widget_Action_SearchResult : []; $display_elements[] = Class_Notice_Xsl::KEY; $display_elements[] = 'liste_format'; + $display_elements[] = 'highlight_search_terms'; $this->addToDisplaySettingsGroup($display_elements); parent::initDisplayGroups(); diff --git a/library/templates/Chili/View/Search/Result.php b/library/templates/Chili/View/Search/Result.php index d1eb5dc2e7fa55e76fdba8025ae5f457d82ac3d4..825fa9f8cbfb04a40588d1ba5ce9f5a72cb5ce7b 100644 --- a/library/templates/Chili/View/Search/Result.php +++ b/library/templates/Chili/View/Search/Result.php @@ -183,12 +183,12 @@ $(id).on('hide.bs.dropdown', function () { $('body').removeClass('overflow_hidde protected function _listModeLink() { - return parent::_listModeLink()->beNotResponsiveText(); + return parent::_listModeLink()->alwaysDisplayText(); } protected function _wallModeLink() { - return parent::_wallModeLink()->beNotResponsiveText(); + return parent::_wallModeLink()->alwaysDisplayText(); } diff --git a/library/templates/Intonation/Assets/css/intonation.css b/library/templates/Intonation/Assets/css/intonation.css index c64d14468f807ad1d51cec497f5b757b8d10fb68..c52b17932aa4a0614e6d42d9d372ab5e43e2657e 100644 --- a/library/templates/Intonation/Assets/css/intonation.css +++ b/library/templates/Intonation/Assets/css/intonation.css @@ -1021,3 +1021,7 @@ a.audio_track:hover .fa-music::before { .img-thumbnail { display: block; } + +.text_decoration_underline { + text-decoration: underline; +} diff --git a/library/templates/Intonation/Library/Link.php b/library/templates/Intonation/Library/Link.php index 358f318d051607a6c352e393e594c59ab1f24568..481f19c061f0d695d046cc3f672620fa399c8bf8 100644 --- a/library/templates/Intonation/Library/Link.php +++ b/library/templates/Intonation/Library/Link.php @@ -23,7 +23,7 @@ class Intonation_Library_Link extends Class_Button { protected - $_inline_text, + $_always_display_text = false, $_class = '', $_only_classes = '', $_popup, @@ -35,29 +35,14 @@ class Intonation_Library_Link extends Class_Button { } - public function setInlineText($flag) { - $this->_inline_text = (bool)$flag; - return $this; - } - - - public function getInlineText() { - return $this->_inline_text; + public function shouldAlwaysDisplayText() : bool { + return $this->_always_display_text; } - public function isNotResponsiveText() { - return false === $this->getInlineText(); - } - - - public function beResponsiveText() { - return $this->setInlineText(false); - } - - - public function beNotResponsiveText() { - return $this->setInlineText(true); + public function alwaysDisplayText() { + $this->_always_display_text = true; + return $this; } diff --git a/library/templates/Intonation/Library/ProfilePatcher.php b/library/templates/Intonation/Library/ProfilePatcher.php index 3ade3a01b820fe371dd4fe402bdcb7a713bc8fc2..ffdf907104c027fc90c0ee1db69867df30c06179 100644 --- a/library/templates/Intonation/Library/ProfilePatcher.php +++ b/library/templates/Intonation/Library/ProfilePatcher.php @@ -248,19 +248,6 @@ class Intonation_Library_ProfilePatcher extends Class_Template_ProfilePatcher { ->setCfgSiteParam('couleur_texte_bandeau', '') ->setAccessLevel(-1); - $codes = (new Class_Codification)->getCodesForFacets(); - - (new Class_Profil_Preferences()) - ->setModulePref($this->_profile, - (new Class_Profil_ModuleDefinition('recherche', - 'resultat', - 'simple')), - ['boite' => ['no_border'], - 'facettes_codes' => implode($codes), - 'liste_format' => Class_Systeme_ModulesAppli::LISTE_FORMAT_LIST, - 'facets_order' => 1, - 'facets_closed_codes' => implode(array_diff($codes,[Class_TypeDoc::CODE_FACETTE]))]); - return $this; } @@ -287,6 +274,20 @@ class Intonation_Library_ProfilePatcher extends Class_Template_ProfilePatcher { protected function _upgradeActions() { + $codes = (new Class_Codification)->getCodesForFacets(); + + (new Class_Profil_Preferences()) + ->setModulePref($this->_profile, + (new Class_Profil_ModuleDefinition('recherche', + 'resultat', + 'simple')), + ['boite' => ['no_border'], + 'facettes_codes' => implode($codes), + 'liste_format' => Class_Systeme_ModulesAppli::LISTE_FORMAT_LIST, + 'facets_order' => 1, + 'highlight_search_terms' => '1', + 'facets_closed_codes' => implode(array_diff($codes,[Class_TypeDoc::CODE_FACETTE]))]); + return $this; } diff --git a/library/templates/Intonation/Library/Settings.php b/library/templates/Intonation/Library/Settings.php index 8a9eed36b8f900c1057e042f9ecffde08ff542a7..5b193b370fa4ca528f60d8dfcacf9871f595d44d 100644 --- a/library/templates/Intonation/Library/Settings.php +++ b/library/templates/Intonation/Library/Settings.php @@ -320,6 +320,7 @@ class Intonation_Library_Settings extends Intonation_System_Abstract { 'div class truncate_list_wrapper' => 'col-12 list-group bg-transparent no_border', 'div class truncate_list_top_tools' => 'col-12', 'div class truncate_list_bottom_tools' => 'col-12', + 'span class highlight' => 'font-weight-bold text_decoration_underline', ], 'icons_map_doc_types' => [], diff --git a/library/templates/Intonation/Library/View/Wrapper/Record.php b/library/templates/Intonation/Library/View/Wrapper/Record.php index 6193af628ff5bef96d3f63588d65db60dbd66d15..e45d58bdbc7b823f8fe6d6481c4fef53d68698bd 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Record.php +++ b/library/templates/Intonation/Library/View/Wrapper/Record.php @@ -125,7 +125,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra public function getSecondaryLink() { - if (!$this->getSecondaryTitle()) + if (!$author = $this->getSecondaryTitle()) return null; if (!$facet = $this->_model->getCodifAuthorPrincipal()) @@ -136,7 +136,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra return (new Intonation_Library_Link) ->setUrl($author_field->getUrlForLink()) ->setImage($this->getSecondaryIco()) - ->setText($author_field->getLabel()) + ->setText($author) ->setTitle($author_field->getTitle()); } @@ -153,7 +153,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra 'facette' => Class_CodifTypeDoc::CODE_FACETTE. $this->_model->getTypeDoc(), 'page' => null])) ->setImage(($this->getIco($this->_model->getTypeDocLabel(), 'doc_types'))) - ->setText($this->_model->getTypeDocLabel()) + ->setText($this->decorateLabel($this->_model->getTypeDocLabel())) ->setTitle($this->_('Affiner le résultat de recherche avec le type de document %s du document %s', $this->_model->getTypeDocLabel(), $this->_model->getTitrePrincipal(' '))))]; @@ -245,7 +245,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra ->setTag('a') ->setClass('record_facets record_facet_' . strtolower($codif->getNomChamp($facet->getFacetCode()))) ->setImage($this->getIco('tag', 'utils')) - ->setText($facet->getLabel()) + ->setText($this->decorateLabel($facet->getLabel())) ->setTitle($facet->getTitle()) ->setUrl($facet->getUrlForLink())); @@ -264,13 +264,18 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra ->setTag('a') ->setUrl($this->_view->url((new Class_CriteresRecherche)->getNewUrlCriteresCollection($collection), null, true)) ->setClass('record_collection') - ->setText($collection) + ->setText($this->decorateLabel($collection)) ->setTitle($this->_('Afficher tous les titres de la collection "%s".', $collection)); return $badges; } + public function decorateLabel(string $label) : string { + return $label; + } + + protected function _addLinkToParentRecordBadge(array $badges) : array { (new Class_Notice_SerieLinks($this->_model)) ->withParentRecordDo( @@ -279,7 +284,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra ->setTag('a') ->setImage($this->getIco('related', 'library')) ->setUrl($this->_view->urlNotice($parent)) - ->setText($serie_label) + ->setText($this->decorateLabel($serie_label)) ->setTitle($serie_label); }); @@ -297,7 +302,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra ->setUrl($serie_url) ->setClass('record_serie') ->setImage($this->getIco('related', 'library')) - ->setText($serie_label) + ->setText($this->decorateLabel($serie_label)) ->setTitle($this->_('%s dans la recherche.', $serie_label)); @@ -511,7 +516,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra $actions [] = (new Intonation_Library_Link) ->setUrl($this->_view->urlNotice($bundle)) ->setImage(($this->getIco('list', 'utils'))) - ->setText($this->_('Fait partie du lot %s', $bundle->getTitrePrincipal())) + ->setText($this->decorate($this->_('Fait partie du lot %s', $bundle->getTitrePrincipal()))) ->setTitle($this->_('Le document %s fait partie du lot %s', $bundle->getTitrePrincipal())) ->setClass('view_record_bundle'); diff --git a/library/templates/Intonation/Library/View/Wrapper/Record/HighlightTerms.php b/library/templates/Intonation/Library/View/Wrapper/Record/HighlightTerms.php new file mode 100644 index 0000000000000000000000000000000000000000..b32f95cf2303c23f69b67b6d97cad36ad5115abf --- /dev/null +++ b/library/templates/Intonation/Library/View/Wrapper/Record/HighlightTerms.php @@ -0,0 +1,58 @@ +<?php +/** + * Copyright (c) 2012-2021, 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 Intonation_Library_View_Wrapper_Record_HighlightTerms extends Intonation_Library_View_Wrapper_Record { + + protected array $_terms; + protected array $_decorated_label_cache = []; + + + public function __construct($model = null, $view = null) { + parent::__construct($model, $view); + $this->setModel($model->getModel()); + } + + + public function setTerms(array $terms) : self{ + $this->_terms = $terms; + return $this; + } + + + public function getMainTitle() { + return $this->decorateLabel(parent::getMainTitle()); + } + + + public function getSecondaryTitle() { + return $this->decorateLabel(parent::getSecondaryTitle()); + } + + + public function decorateLabel(string $label) : string { + if ( isset($this->_decorated_label_cache[$label])) + return $this->_decorated_label_cache[$label]; + + return $this->_decorated_label_cache[$label] = (string) $this->_view->highlight(parent::decorateLabel($label), + $this->_terms); + } +} diff --git a/library/templates/Intonation/Library/View/Wrapper/Search.php b/library/templates/Intonation/Library/View/Wrapper/Search.php index b07c9d7a0e0b12c85ed9733fa7d456770e73d70c..68ac6c6c8fbe19d627a18c98ea740b2e672bc519 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Search.php +++ b/library/templates/Intonation/Library/View/Wrapper/Search.php @@ -130,7 +130,7 @@ class Intonation_Library_View_Wrapper_Search extends Intonation_Library_View_Wra ->setTitle($can_follow ? $this->_('Suivre cette recherche') : $this->_('Ne plus suivre cette recherche.')) - ->beNotResponsiveText() + ->alwaysDisplayText() ->setPopup(true)]; } @@ -143,7 +143,7 @@ class Intonation_Library_View_Wrapper_Search extends Intonation_Library_View_Wra ->setText($this->_('Suggérer un achat')) ->setTitle($this->_('Envoyer une demande d\'achat de document')) ->setAttrib('target', '_blank') - ->beNotResponsiveText() + ->alwaysDisplayText() , (new Intonation_Library_Link) ->setUrl($this->_view->url(['controller' => 'recherche', @@ -152,7 +152,7 @@ class Intonation_Library_View_Wrapper_Search extends Intonation_Library_View_Wra ->setText($this->_('Imprimer')) ->setTitle($this->_('Imprimer le résultat')) ->setAttrib('target', '_blank') - ->beNotResponsiveText() + ->alwaysDisplayText() , (new Intonation_Library_Link) ->setUrl($this->_view->url(['controller' => 'recherche', @@ -160,7 +160,7 @@ class Intonation_Library_View_Wrapper_Search extends Intonation_Library_View_Wra ->setImage($this->getIco('email', 'utils')) ->setText($this->_('Partager par email')) ->setTitle($this->_('Partager le résultat par email')) - ->beNotResponsiveText() + ->alwaysDisplayText() ->setPopup(true) , $this->_view->tagSearchExtension($this->_model->getUnserializedCriterias()), diff --git a/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Agenda.php b/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Agenda.php index a56816a1605ccfbbc5b369fd252f5782b2ff354d..dbd99516f1915417f16d10f1ceb533d181a62c76 100644 --- a/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Agenda.php +++ b/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Agenda.php @@ -86,7 +86,7 @@ class Intonation_Library_View_Wrapper_User_RichContent_Agenda ->setImage($this->getIco('team', 'library')) ->setText($this->_('Gérer les activités')) ->setClass('manage_activities_button') - ->beNotResponsiveText(); + ->alwaysDisplayText(); return $this->_view->renderCollectionActions([$link]); } diff --git a/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Settings.php b/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Settings.php index 0dbd4ea2fe746ae8075e429ffbc39d2f7360a06a..87e6a8dbb46c6b52aa2a5fbff867c5222dda022a 100644 --- a/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Settings.php +++ b/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Settings.php @@ -73,7 +73,7 @@ class Intonation_Library_View_Wrapper_User_RichContent_Settings extends Intonati ->setText($this->_('Ajouter une carte')) ->setImage($this->_view->templateIco('add_user', 'utils')) ->setClass('btn btn-sm btn-success') - ->beNotResponsiveText() + ->alwaysDisplayText() ->setPopup(true); $html = [$this->_div(['class' => 'col-12'], diff --git a/library/templates/Intonation/Library/Widget/Login/RenderAbstract.php b/library/templates/Intonation/Library/Widget/Login/RenderAbstract.php index 1c277876ac461f8469d8835f4181cb269054c030..ae6ff83c2b772e0bae7a509e91673a5d828c99ba 100644 --- a/library/templates/Intonation/Library/Widget/Login/RenderAbstract.php +++ b/library/templates/Intonation/Library/Widget/Login/RenderAbstract.php @@ -138,7 +138,7 @@ abstract class Intonation_Library_Widget_Login_RenderAbstract { ->setText($this->_view->abonne_Name($this->_user)) ->setTitle($this->_('Accéder à l\'interface de gestion de %s.', $this->_user->getNomComplet())) ->setAttrib('class', 'account-link') - ->beNotResponsiveText(); + ->alwaysDisplayText(); } @@ -149,7 +149,7 @@ abstract class Intonation_Library_Widget_Login_RenderAbstract { ->setText($this->_settings->getLienDeconnection()) ->setTitle($this->_('Se déconnecter de la session %s', $this->_user->getNomComplet())) ->setAttrib('class', 'account-disconnect') - ->beNotResponsiveText(); + ->alwaysDisplayText(); } @@ -167,7 +167,7 @@ abstract class Intonation_Library_Widget_Login_RenderAbstract { ->setText($this->_view->_('Voir tous mes prêts')) ->setTitle($this->_('Voir tous les prêts de %s', $this->_user->getNomComplet())) ->setAttrib('class', 'account-loans') - ->beNotResponsiveText(); + ->alwaysDisplayText(); return $links; } diff --git a/library/templates/Intonation/View/Abonne/Suggestions.php b/library/templates/Intonation/View/Abonne/Suggestions.php index 31eb8da7cf3caa9272bb85bceac35bda94a77f85..5c01e138bcbc2504fc495222f9d16014bfeb9590 100644 --- a/library/templates/Intonation/View/Abonne/Suggestions.php +++ b/library/templates/Intonation/View/Abonne/Suggestions.php @@ -45,7 +45,7 @@ class Intonation_View_Abonne_Suggestions extends ZendAfi_View_Helper_BaseHelper ->setText($this->_('Suggérer un achat')) ->setTitle($this->_('Suggérer un achat à la bibliothèque')) ->setClass('btn btn-sm btn-success') - ->beNotResponsiveText()]; + ->alwaysDisplayText()]; return $this->view->renderCollection($collection, $actions, $callback); } diff --git a/library/templates/Intonation/View/CardifyHorizontal.php b/library/templates/Intonation/View/CardifyHorizontal.php index 62b217016ae4b0b762ced01d248130b67e3c9745..6ba59d1111b5b926b31f8b9f018319f47e06188e 100644 --- a/library/templates/Intonation/View/CardifyHorizontal.php +++ b/library/templates/Intonation/View/CardifyHorizontal.php @@ -37,7 +37,7 @@ class Intonation_View_CardifyHorizontal extends Intonation_View_CardHelper { if ($second_link = $element->getSecondaryLink()) $content [] = $this->_tag('div', - $this->view->tagAction($second_link->beNotResponsiveText()), + $this->view->tagAction($second_link->alwaysDisplayText()), ['class' => 'card-subtitle']); if (!$second_link && $secondary_title = $element->getSecondaryTitle()) diff --git a/library/templates/Intonation/View/CardifyOnlyDescription.php b/library/templates/Intonation/View/CardifyOnlyDescription.php index 5a1d9cbbea4ba1080d18dd4c141649da70ff577f..92aa9b276523a0b2c7782c7ab142a2a7ac1dbb5b 100644 --- a/library/templates/Intonation/View/CardifyOnlyDescription.php +++ b/library/templates/Intonation/View/CardifyOnlyDescription.php @@ -30,7 +30,7 @@ class Intonation_View_CardifyOnlyDescription extends Intonation_View_CardHelper if ($second_link = $element->getSecondaryLink()) $content [] = $this->_tag('div', $this->view->tagAction($second_link - ->beNotResponsiveText()), + ->alwaysDisplayText()), ['class' => 'card-subtitle card_subtitle card_subtitle_' . $element_class]); if ($summary = $element->getDescription()) diff --git a/library/templates/Intonation/View/Jumbotron.php b/library/templates/Intonation/View/Jumbotron.php index 5838042adf493c8d0e5c0ecaecb19f2f0cb437b9..86bc031a8a77437cc1c9856df49c3fcc930eb1ca 100644 --- a/library/templates/Intonation/View/Jumbotron.php +++ b/library/templates/Intonation/View/Jumbotron.php @@ -95,7 +95,7 @@ class Intonation_View_Jumbotron extends ZendAfi_View_Helper_BaseHelper { $html = $this->_tag('h1', $this->_element->getMainTitle()); if ($secondary_link = $this->_element->getSecondaryLink()) - $html .= $this->view->tagAction($secondary_link->beNotResponsiveText()); + $html .= $this->view->tagAction($secondary_link->alwaysDisplayText()); return $html . $this->_element->getBadges() . $this->_actions(); } diff --git a/library/templates/Intonation/View/RenderOverlay.php b/library/templates/Intonation/View/RenderOverlay.php index cdc9ade230ff62232a27546f7ead9f1bafc69662..9c6c7a013920bd6b0e28a256f6a52c136bfedb1d 100644 --- a/library/templates/Intonation/View/RenderOverlay.php +++ b/library/templates/Intonation/View/RenderOverlay.php @@ -44,7 +44,7 @@ class Intonation_View_RenderOverlay extends ZendAfi_View_Helper_BaseHelper { $main_link ->setText($content) - ->beNotResponsiveText() + ->alwaysDisplayText() ->setImage(''); return $element->getContentForJSSearch() diff --git a/library/templates/Intonation/View/Search/HighlightTerms.php b/library/templates/Intonation/View/Search/HighlightTerms.php new file mode 100644 index 0000000000000000000000000000000000000000..278cbfd4cf31ab0a768d8c8bd2b4ffa0bbf7cfa6 --- /dev/null +++ b/library/templates/Intonation/View/Search/HighlightTerms.php @@ -0,0 +1,40 @@ +<?php +/** + * Copyright (c) 2012-2021, 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 Intonation_View_Search_HighlightTerms extends ZendAfi_View_Helper_BaseHelper { + + public function Search_HighlightTerms($records_wrappers, $search_result) : array { + if ( ! $search_result->shouldHighlightRecords()) + return $records_wrappers; + + if ( ! $terms = $search_result->getMatchingSearchTerms()) + return $records_wrappers; + + return array_map(function($wrapper) use ($terms) + { + return (new Intonation_Library_View_Wrapper_Record_HighlightTerms($wrapper, + $wrapper->getView())) + ->setTerms($terms); + }, + $records_wrappers); + } +} \ No newline at end of file diff --git a/library/templates/Intonation/View/Search/History.php b/library/templates/Intonation/View/Search/History.php index 78bc3397751ec4ebe769191cd20f2c390901783b..fcc41de6e2f6a398d36915e9d82fa8de19ab6066 100644 --- a/library/templates/Intonation/View/Search/History.php +++ b/library/templates/Intonation/View/Search/History.php @@ -60,7 +60,7 @@ class Intonation_View_Search_History extends ZendAfi_View_Helper_BaseHelper { ->setText($this->_('Vider')) ->setTitle($this->_('Vider l\'historique de recherches')) ->setClass('clear_history_button') - ->beNotResponsiveText() + ->alwaysDisplayText() ->setPopup(true)]; $html = [$this->view->div(['class' => 'col-12'], $this->view->renderCollectionActions($actions)), diff --git a/library/templates/Intonation/View/Search/HtmlCriteria.php b/library/templates/Intonation/View/Search/HtmlCriteria.php index 2fc6b51727758654b5c8afdca489fdc7ea80465b..b7aa08f09716e86818eee45cd48f728c604058eb 100644 --- a/library/templates/Intonation/View/Search/HtmlCriteria.php +++ b/library/templates/Intonation/View/Search/HtmlCriteria.php @@ -73,7 +73,7 @@ class Intonation_View_Search_HtmlCriteria extends ZendAfi_View_Helper_TagCritere ->setText($this->_('Réinitialiser')) ->setTitle($this->_('Supprimer les facettes')) ->setClass('reset_criteria') - ->beNotResponsiveText(); + ->alwaysDisplayText(); $this->_html .= $this->view->tagAction($link); return $this; @@ -100,7 +100,7 @@ class Intonation_View_Search_HtmlCriteria extends ZendAfi_View_Helper_TagCritere ->setText($criteria_label) ->setTitle($this->_('Retirer le critère: %s', $criteria_label)) ->setClass('active_criteria') - ->beNotResponsiveText()); + ->alwaysDisplayText()); } diff --git a/library/templates/Intonation/View/Search/Result.php b/library/templates/Intonation/View/Search/Result.php index 34348f440b4a54aa1f7168a4f209655c250f4789..cecfee6fa3737e03c5d34cf2f5e079e583112892 100644 --- a/library/templates/Intonation/View/Search/Result.php +++ b/library/templates/Intonation/View/Search/Result.php @@ -40,6 +40,7 @@ class Intonation_View_Search_Result extends ZendAfi_View_Helper_BaseHelper { : $this->_getRecordWrapperClass(); $records = array_map([$this, '_wrapperFor'], $records); + $records = $this->view->Search_HighlightTerms($records, $search); $records_html = $this->_isWallMode() ? $this->_renderWall($records) @@ -199,7 +200,7 @@ class Intonation_View_Search_Result extends ZendAfi_View_Helper_BaseHelper { ->setText($this->_tag('span', $this->_('Liste'))) ->setTitle($this->_('Afficher le résultat de recherche en mode liste')) ->setClass('btn-sm list_format' . ($this->_isWallMode() ? '' : ' active')) - ->beNotResponsiveText(); + ->alwaysDisplayText(); } @@ -210,7 +211,7 @@ class Intonation_View_Search_Result extends ZendAfi_View_Helper_BaseHelper { ->setText($this->_tag('span', $this->_('Mur'))) ->setTitle($this->_('Afficher le résultat de recherche en mode mur')) ->setClass('btn-sm list_format' . ($this->_isWallMode() ? 'active' : '')) - ->beNotResponsiveText(); + ->alwaysDisplayText(); } diff --git a/library/templates/Intonation/View/TagAction.php b/library/templates/Intonation/View/TagAction.php index 45c907066062dbfa85724375727877c85c19b5e2..54bba3daf3ecaa7fe97cfe8e2640e4064200bcdf 100644 --- a/library/templates/Intonation/View/TagAction.php +++ b/library/templates/Intonation/View/TagAction.php @@ -60,7 +60,7 @@ class Intonation_View_TagAction extends ZendAfi_View_Helper_BaseHelper { if ($only_classes = $action->getOnlyClasses()) $classes = [$only_classes]; - $attribs = array_merge(['title' => $action->getTitle(), + $attribs = array_merge(['title' => strip_tags($action->getTitle()), 'data-popup' => $action->getPopup(), 'class' => implode(' ', $classes)], $attribs); @@ -79,7 +79,7 @@ class Intonation_View_TagAction extends ZendAfi_View_Helper_BaseHelper { if (!$text = $action->getText()) return ''; - if ($action->isNotResponsiveText()) + if ($action->shouldAlwaysDisplayText()) return $this->_tag('div', $text, ['class' => 'd-inline text-left']); return $img diff --git a/library/templates/Intonation/View/User/Informations.php b/library/templates/Intonation/View/User/Informations.php index d27e3aece92827c721c8000556f53a38e8440a32..9bb9e85fe0bf30590483651e6e3a84045c02749a 100644 --- a/library/templates/Intonation/View/User/Informations.php +++ b/library/templates/Intonation/View/User/Informations.php @@ -37,7 +37,7 @@ class Intonation_View_User_Informations extends ZendAfi_View_Helper_BaseHelper { ->setText($this->_('Télécharger mes données')) ->setTitle($this->_('Télécharger mes données')) ->setClass('btn btn-sm btn-info mr-3') - ->beNotResponsiveText(); + ->alwaysDisplayText(); $links_html = array_map(function($link) { @@ -64,7 +64,7 @@ class Intonation_View_User_Informations extends ZendAfi_View_Helper_BaseHelper { ->setText($this->_('Modifier mes informations')) ->setTitle($this->_('Modifier les informations me concernant')) ->setClass('btn btn-sm btn-success mr-3') - ->beNotResponsiveText(); + ->alwaysDisplayText(); $links [] = (new Intonation_Library_Link) ->setUrl($this->view->url(['controller' => 'abonne', @@ -73,7 +73,7 @@ class Intonation_View_User_Informations extends ZendAfi_View_Helper_BaseHelper { ->setText($this->_('Changer mon mot de passe')) ->setTitle($this->_('Changer le mot de passe de mon compte.')) ->setClass('btn btn-sm btn-secondary mr-3') - ->beNotResponsiveText(); + ->alwaysDisplayText(); return $links; } diff --git a/tests/library/ZendAfi/View/Helper/ListeNoticesTest.php b/tests/library/ZendAfi/View/Helper/ListeNoticesTest.php index 4b4399f1251eefbab3367c42f52e6ba92ec5451d..afb6434a3130518eb913ac49b19a8bffb5261a44 100644 --- a/tests/library/ZendAfi/View/Helper/ListeNoticesTest.php +++ b/tests/library/ZendAfi/View/Helper/ListeNoticesTest.php @@ -89,6 +89,4 @@ class ListeNoticesWithSearchEroOdiarTest extends ViewHelperTestCase { '//span[@class="highlight"]', utf8_encode('Audiard')); } - -} -?> +} \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesAgendaTest.php b/tests/scenarios/Templates/TemplatesAgendaTest.php index d48b5c7b52f410fcd9e6be1a0b3272d471b4752b..be6314189233171f277ff1dbe8a735c1e7728a04 100644 --- a/tests/scenarios/Templates/TemplatesAgendaTest.php +++ b/tests/scenarios/Templates/TemplatesAgendaTest.php @@ -266,7 +266,6 @@ class TemplatesAgendaWallModeSelectDateTestCase extends AbstractControllerTestCa $articles = Class_Article::findAllBy([]); return array_filter($articles, function ($element) use ($preferences){ - xdebug_break(); return ( diff --git a/tests/scenarios/Templates/TemplatesSearchTest.php b/tests/scenarios/Templates/TemplatesSearchTest.php index 18472b2fe596dd4fbd5ccb6242b4debbbe1d6348..89eae19d460d25a06702b2541dd47884e17bf9a8 100644 --- a/tests/scenarios/Templates/TemplatesSearchTest.php +++ b/tests/scenarios/Templates/TemplatesSearchTest.php @@ -666,6 +666,13 @@ class TemplateSearchWithSerieTest extends abstractControllerTestCase { 'template' => 'MUSCLE' ]); + (new Class_Profil_Preferences()) + ->setModulePref(Class_Profil::find(34), + (new Class_Profil_ModuleDefinition('recherche', + 'resultat', + 'simple')), + ['highlight_search_terms' => '1']); + $profile->beCurrentProfil(); $fakir_58 = $this->fixture('Class_Notice', @@ -1011,4 +1018,151 @@ class TemplatesSearchCollectionWithoutSerie extends AbstractControllerTestCase { public function badgeRecordSerieShouldNotExist() { $this->assertNotXPath('//div//a[contains(@class,"record_serie")]'); } -} \ No newline at end of file +} + + + + +class TemplatesSearchResultWithSearchTermHighLightedTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $this->_buildTemplateProfil(['id' => 2]); + + (new Class_Profil_Preferences()) + ->setModulePref(Class_Profil::find(2), + (new Class_Profil_ModuleDefinition('recherche', + 'resultat', + 'simple')), + ['highlight_search_terms' => '1']); + + $this->fixture(Class_CodifAuteur::class, + ['id' => 43, + 'libelle' => 'Heros Audiard']); + + $this->fixture(Class_Notice::class, + ['id' => 1, + 'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/audiard_herosdiscret.uni')]); + + $sql = $this + ->mock() + + ->whenCalled('fetchAll') + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey, other_terms) AGAINST('+(ERO EROS) +(ODIAR ODIARS ODIAR)' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' ERO ODIAR') * 1.5) + (MATCH(auteurs) AGAINST(' ERO ODIAR')) desc", + true, + false) + ->answers([[1, '']]) + + ->beStrict(); + + Zend_Registry::set('sql', $sql); + + $this->dispatch('/recherche/simple/expressionRecherche/ero+Odiar'); + } + + + /** @test */ + public function herosShouldBeHighlightedInTitle() { + $this->assertXPathContentContains('//div[contains(@class, "card-title")]//a//span[@class="highlight font-weight-bold text_decoration_underline"]', + 'héros'); + } + + + /** @test */ + public function audiardShouldBeHighlightedInTitle() { + $this->assertXPathContentContains('//div[contains(@class, "card-subtitle")]//a//div[@class="d-inline text-left"]//span[@class="highlight font-weight-bold text_decoration_underline"]', + 'Audiard'); + } + + + /** @test */ + public function cardLinkReadDocumentTitleShouldNotContainsHTML() { + $this->assertXPath('//div[@class="card_action read_document col col-sm-12 p-1 m-1"]//a[@href="/recherche/viewnotice/id/1/expressionRecherche/ero+Odiar"][@title="Voir le document Un héros très discret de Heros Audiard de type "]'); + } +} + + + + +class TemplatesSearchEditActionTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + $this->_buildTemplateProfil(['id' => 45]); + $this->dispatch('admin/widget/edit-action/id/recherche_resultat_simple/id_profil/45'); + } + + + /** @test */ + public function listeFormatRadioListeShouldBePresent() { + $this->assertXPath('//form//input[@type="radio"][@name="liste_format"][@value="4"]'); + } + + + /** @test */ + public function listeFormatRadioMurShouldBePresent() { + $this->assertXPath('//form//input[@type="radio"][@name="liste_format"][@value="2"]'); + } + + + /** @test */ + public function checkboxHighlightSearchTermShouldBePresent() { + $this->assertXPath('//form//input[@type="checkbox"][@name="highlight_search_terms"]'); + } +} + + + + +class TemplatesSearchHighlightCollectionTest extends AbstractControllerTestCase { + + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $this->_buildTemplateProfil(['id' => 823]); + + (new Class_Profil_Preferences()) + ->setModulePref(Class_Profil::find(823), + (new Class_Profil_ModuleDefinition('recherche', + 'resultat', + 'simple')), + ['highlight_search_terms' => '1']); + + $unimarc = (new Class_NoticeUnimarc_Writer) + ->setNotice(file_get_contents(ROOT_PATH . 'tests/fixtures/bernard_genin.uni')); + + $this->fixture(Class_Notice::class, + ['id' => 345, + 'type_doc' => Class_TypeDoc::LIVRE, + 'collection' => 'LES PETITS CAHIERS', + 'unimarc' => $unimarc->toUnimarcISO2709()]); + + + $sql = $this->mock() + ->whenCalled('fetchAll') + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey, other_terms) AGAINST('+(PETIT PETITS PETI) +(CAHIER CAHIERS KAI)' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' PETITS CAHIERS') * 1.5) + (MATCH(auteurs) AGAINST(' PETITS CAHIERS')) desc", + true, + false) + ->answers([[345, '']]) + ->beStrict(); + + Zend_Registry::set('sql', $sql); + + $this->dispatch('recherche/simple/expressionRecherche/Les+petits+cahiers'); + } + + + /** @test */ + public function lesPetitsCahiersShouldBeHighlighted() { + $this->assertXPathContentContains('//div//a[contains(@class,"record_collection")][contains(@href,"/recherche/simple/rech_collection/Les+petits+cahiers")]//span[@class="highlight font-weight-bold text_decoration_underline"]', + 'cahiers'); + } +}