From c80828fe8fe3483a271fd6933dd2eee92d8882ee Mon Sep 17 00:00:00 2001 From: willcast Date: Wed, 3 Dec 2003 18:33:16 +0000 Subject: [PATCH] - First step towards Tom Murdock's suggestions on a global search feature (if it is ever implented)... Added a new funtion: module_search( $course, $searchterms, $extended, $glossary = NULL) It returns all entries that matches the specified criteria in any glossaries within a given $course. It performs an $extended search if necessary. It restrict the search to only one $glossary if specified (currently used by the internal search function of the module). --- mod/glossary/lib.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 719f11fa510..d5d582522e9 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -700,13 +700,24 @@ function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$mode=" return $return; } -function glossary_search_entries($searchterms, $glossary, $includedefinition) { -/// Returns a list of entries found using an array of search terms -/// eg word +word -word -/// +function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL) { +// It returns all entries from all glossaries that matches the specified criteria +// within a given $course. It performs an $extended search if necessary. +// It restrict the search to only one $glossary if the $glossary parameter is set. global $CFG; - + if ( !$glossary ) { + if ( $glossaries = get_records("glossary", "course", $course->id) ) { + $glos = ""; + foreach ( $glossaries as $glossary ) { + $glos .= "$glossary->id,"; + } + $glos = substr($ents,0,-1); + } + } else { + $glos = $glossary->id; + } + if (!isteacher($glossary->course)) { $glossarymodule = get_record("modules", "name", "glossary"); $onlyvisible = " AND g.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id"; @@ -756,7 +767,7 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) { } } - if ( !$includedefinition ) { + if ( !$extended ) { $definitionsearch = "0"; } @@ -764,12 +775,17 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) { {$CFG->prefix}glossary g $onlyvisibletable WHERE ($conceptsearch OR $definitionsearch) AND (e.glossaryid = g.id or e.sourceglossaryid = g.id) $onlyvisible - AND g.id = $glossary->id AND e.approved != 0"; + AND g.id IN ($glos) AND e.approved != 0"; return get_records_sql("SELECT e.* FROM $selectsql ORDER BY e.concept ASC"); } +function glossary_search_entries($searchterms, $glossary, $extended) { + $course = get_record("course","id",$glossary->course); + return glossary_search($course,$searchterms,$extended,$glossary); +} + function glossary_file_area_name($entry) { global $CFG; // Creates a directory file name, suitable for make_upload_directory()