From 6c04427daa3aeff87e433716f6031b297f44f645 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Thu, 9 Jun 2016 13:58:59 +0800 Subject: [PATCH] MDL-54844 mod_glossary: Limiting of glossary searching. Searching of the glossary was returning results from all glossaries on the site. It has now been returned to just the glossary that you are currently viewing. --- mod/glossary/lib.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 0f6c7cf7f0e..173d7530bf9 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -3653,10 +3653,11 @@ function glossary_get_categories($glossary, $from, $limit) { * * @param array $terms Array of terms. * @param bool $fullsearch Whether or not full search should be enabled. + * @param int $glossaryid The ID of a glossary to reduce the search results. * @return array The first element being the where clause, the second array of parameters. * @since Moodle 3.1 */ -function glossary_get_search_terms_sql(array $terms, $fullsearch = true) { +function glossary_get_search_terms_sql(array $terms, $fullsearch = true, $glossaryid = null) { global $DB; static $i = 0; @@ -3707,6 +3708,12 @@ function glossary_get_search_terms_sql(array $terms, $fullsearch = true) { } } + // Reduce the search results by restricting it to one glossary. + if (isset($glossaryid)) { + $conditions[] = 'AND ge.glossaryid = :glossaryid'; + $params['glossaryid'] = $glossaryid; + } + // When there are no conditions we add a negative one to ensure that we don't return anything. if (empty($conditions)) { $conditions[] = '1 = 2'; @@ -3746,7 +3753,7 @@ function glossary_get_entries_by_search($glossary, $context, $query, $fullsearch } } - list($searchcond, $params) = glossary_get_search_terms_sql($terms, $fullsearch); + list($searchcond, $params) = glossary_get_search_terms_sql($terms, $fullsearch, $glossary->id); $userfields = user_picture::fields('u', null, 'userdataid', 'userdata'); -- 2.43.0