MDL-54844 mod_glossary: Limiting of glossary searching.
authorAdrian Greeve <adrian@moodle.com>
Thu, 9 Jun 2016 05:58:59 +0000 (13:58 +0800)
committerMr. Jenkins (CiBoT) <cibot@moodle.org>
Wed, 6 Jul 2016 01:20:32 +0000 (09:20 +0800)
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

index 0f6c7cf..173d753 100644 (file)
@@ -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 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
  */
  * @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;
 
     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';
     // 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');
 
 
     $userfields = user_picture::fields('u', null, 'userdataid', 'userdata');