Glossary indexing added, used to demonstrate that it's relatively simple
[moodle.git] / search / documents / glossary_document.php
1 <?php
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.
7    * */
9   require_once("$CFG->dirroot/search/documents/document.php");
10   //require_once("$CFG->dirroot/mod/glossary/lib.php");
11   
12   class GlossarySearchDocument extends SearchDocument {  
13     public function __construct(&$entry, $glossary_id, $course_id, $group_id) {
14       // generic information; required
15       $doc->id        = $entry['id'];
16       $doc->title     = $entry['concept'];
17                   
18       $user = get_recordset('user', 'id', $entry['userid'])->fields;
19       
20       $doc->author    = $user['firstname'].' '.$user['lastname'];
21       $doc->contents  = $entry['definition'];
22       $doc->url       = glossary_make_link($entry['id']);      
23       
24       // module specific information; optional
25       $data->glossary = $glossary_id;
26       
27       // construct the parent class
28       parent::__construct($doc, $data, SEARCH_TYPE_GLOSSARY, $course_id, $group_id);
29     } //constructor    
30   } //GlossarySearchDocument  
32   function glossary_make_link($entry_id) {
33     global $CFG;
34     
35     //links directly to entry
36     //return $CFG->wwwroot.'/mod/glossary/showentry.php?eid='.$entry_id;
37     
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
42     
43   function glossary_iterator() {
44     return get_all_instances_in_courses("glossary", get_courses());  
45   } //glossary_iterator
46   
47   function glossary_get_content_for_index(&$glossary) {
48     $documents = array();
49     
50     $entries = get_recordset('glossary_entries', 'glossaryid', $glossary->id);   
51     
52     while (!$entries->EOF) {
53       $entry = $entries->fields;
54       
55       if ($entry and strlen($entry['definition']) > 0) {
56         $documents[] = new GlossarySearchDocument($entry, $glossary->id, $glossary->course, -1);
57       } //if
58       
59       $entries->MoveNext();
60     } //foreach
61     
62     return $documents;
63   } //glossary_get_content_for_index 
64   
65 ?>