2 /* This document illustrates how easy it is to add a module to
3 * the search index - the only modifications made were creating
4 * this file, and adding the SEARCH_TYPE_GLOSSARY constant to
5 * search/lib.php - everything else is automatically handled
6 * by the indexer script.
9 require_once("$CFG->dirroot/search/documents/document.php");
11 class GlossarySearchDocument
extends SearchDocument
{
12 public function __construct(&$entry, $glossary_id, $course_id, $group_id) {
13 // generic information; required
14 $doc->docid
= $entry['id'];
15 $doc->title
= $entry['concept'];
16 $doc->date
= $entry['timecreated'];
18 $user = get_recordset('user', 'id', $entry['userid'])->fields
;
20 $doc->author
= $user['firstname'].' '.$user['lastname'];
21 $doc->contents
= $entry['definition'];
22 $doc->url
= glossary_make_link($entry['id']);
24 // module specific information; optional
25 $data->glossary
= $glossary_id;
27 // construct the parent class
28 parent
::__construct($doc, $data, SEARCH_TYPE_GLOSSARY
, $course_id, $group_id);
30 } //GlossarySearchDocument
32 function glossary_make_link($entry_id) {
35 //links directly to entry
36 //return $CFG->wwwroot.'/mod/glossary/showentry.php?eid='.$entry_id;
38 //preserve glossary pop-up, be careful where you place your ' and "s
39 //this function is meant to return a url that is placed between href='[url here]'
40 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);";
41 } //glossary_make_link
43 function glossary_iterator() {
44 return get_all_instances_in_courses("glossary", get_courses());
47 function glossary_get_content_for_index(&$glossary) {
50 $entries = get_recordset('glossary_entries', 'glossaryid', $glossary->id
);
52 while (!$entries->EOF
) {
53 $entry = $entries->fields
;
55 if ($entry and strlen($entry['definition']) > 0) {
56 $documents[] = new GlossarySearchDocument($entry, $glossary->id
, $glossary->course
, -1);
63 } //glossary_get_content_for_index
65 //returns a single glossary search document based on a glossary_entry id
66 function glossary_single_document($id) {
67 $entries = get_recordset('glossary_entries', 'id', $id);
68 $entry = $entries->fields
;
70 $glossaries = get_recordset('glossary', 'id', $entry['glossaryid']);
71 $glossary = $glossaries->fields
;
73 return new GlossarySearchDocument($entry, $entry['glossaryid'], $glossary['course'], -1);
74 } //glossary_single_document
76 //dummy delete function that converts docid from the search table to itself..
77 //this was here for a reason, but I can't remember it at the moment.
78 function glossary_delete($info) {
82 //returns the var names needed to build a sql query for addition/deletions
83 function glossary_db_names() {
84 //[primary id], [table name], [time created field name], [time modified field name]
85 return array('id', 'glossary_entries', 'timecreated', 'timemodified');