From: mchampan Date: Wed, 26 Jul 2006 11:29:35 +0000 (+0000) Subject: Glossary indexing added, used to demonstrate that it's relatively simple X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=defb87ba90c9d9a653b550eee26f1da2b7235fb5;p=moodle.git Glossary indexing added, used to demonstrate that it's relatively simple to add a new module to the indexing queue. --- diff --git a/search/documents/glossary_document.php b/search/documents/glossary_document.php new file mode 100644 index 0000000000..0305b7229a --- /dev/null +++ b/search/documents/glossary_document.php @@ -0,0 +1,65 @@ +dirroot/search/documents/document.php"); + //require_once("$CFG->dirroot/mod/glossary/lib.php"); + + class GlossarySearchDocument extends SearchDocument { + public function __construct(&$entry, $glossary_id, $course_id, $group_id) { + // generic information; required + $doc->id = $entry['id']; + $doc->title = $entry['concept']; + + $user = get_recordset('user', 'id', $entry['userid'])->fields; + + $doc->author = $user['firstname'].' '.$user['lastname']; + $doc->contents = $entry['definition']; + $doc->url = glossary_make_link($entry['id']); + + // module specific information; optional + $data->glossary = $glossary_id; + + // construct the parent class + parent::__construct($doc, $data, SEARCH_TYPE_GLOSSARY, $course_id, $group_id); + } //constructor + } //GlossarySearchDocument + + function glossary_make_link($entry_id) { + global $CFG; + + //links directly to entry + //return $CFG->wwwroot.'/mod/glossary/showentry.php?eid='.$entry_id; + + //preserve glossary pop-up, be careful where you place your ' and "s + //this function is meant to return a url that is placed between href='[url here]' + return "$CFG->wwwroot/mod/glossary/showentry.php?eid=$entry_id' onclick='return openpopup(\"/mod/glossary/showentry.php?eid=$entry_id\", \"entry\", \"menubar=0,location=0,scrollbars,resizable,width=600,height=450\", 0);"; + } //glossary_make_link + + function glossary_iterator() { + return get_all_instances_in_courses("glossary", get_courses()); + } //glossary_iterator + + function glossary_get_content_for_index(&$glossary) { + $documents = array(); + + $entries = get_recordset('glossary_entries', 'glossaryid', $glossary->id); + + while (!$entries->EOF) { + $entry = $entries->fields; + + if ($entry and strlen($entry['definition']) > 0) { + $documents[] = new GlossarySearchDocument($entry, $glossary->id, $glossary->course, -1); + } //if + + $entries->MoveNext(); + } //foreach + + return $documents; + } //glossary_get_content_for_index + +?> \ No newline at end of file diff --git a/search/lib.php b/search/lib.php index 964f27545f..5da8d87baa 100644 --- a/search/lib.php +++ b/search/lib.php @@ -12,7 +12,8 @@ //document types that can be searched define('SEARCH_TYPE_NONE', 'none'); define('SEARCH_TYPE_WIKI', 'wiki'); - define('SEARCH_TYPE_FORUM', 'forum'); + define('SEARCH_TYPE_FORUM', 'forum'); + define('SEARCH_TYPE_GLOSSARY', 'glossary'); //returns all the document type constants function search_get_document_types($prefix='SEARCH_TYPE') {