Skip to content

Commit

Permalink
- First step towards Tom Murdock's suggestions on a global search fea…
Browse files Browse the repository at this point in the history
…ture (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).
  • Loading branch information
willcast committed Dec 3, 2003
1 parent d33986d commit c80828f
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions mod/glossary/lib.php
Expand Up @@ -700,13 +700,24 @@ function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$mode="
return $return; return $return;
} }


function glossary_search_entries($searchterms, $glossary, $includedefinition) { function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL) {
/// Returns a list of entries found using an array of search terms // It returns all entries from all glossaries that matches the specified criteria
/// eg word +word -word // 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; 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)) { if (!isteacher($glossary->course)) {
$glossarymodule = get_record("modules", "name", "glossary"); $glossarymodule = get_record("modules", "name", "glossary");
$onlyvisible = " AND g.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id"; $onlyvisible = " AND g.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id";
Expand Down Expand Up @@ -756,20 +767,25 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) {
} }
} }


if ( !$includedefinition ) { if ( !$extended ) {
$definitionsearch = "0"; $definitionsearch = "0";
} }


$selectsql = "{$CFG->prefix}glossary_entries e, $selectsql = "{$CFG->prefix}glossary_entries e,
{$CFG->prefix}glossary g $onlyvisibletable {$CFG->prefix}glossary g $onlyvisibletable
WHERE ($conceptsearch OR $definitionsearch) WHERE ($conceptsearch OR $definitionsearch)
AND (e.glossaryid = g.id or e.sourceglossaryid = g.id) $onlyvisible 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.* return get_records_sql("SELECT e.*
FROM $selectsql ORDER BY e.concept ASC"); 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) { function glossary_file_area_name($entry) {
global $CFG; global $CFG;
// Creates a directory file name, suitable for make_upload_directory() // Creates a directory file name, suitable for make_upload_directory()
Expand Down

0 comments on commit c80828f

Please sign in to comment.