]> git.mjollnir.org Git - moodle.git/commitdiff
Glossary indexing added, used to demonstrate that it's relatively simple
authormchampan <mchampan>
Wed, 26 Jul 2006 11:29:35 +0000 (11:29 +0000)
committermchampan <mchampan>
Wed, 26 Jul 2006 11:29:35 +0000 (11:29 +0000)
to add a new module to the indexing queue.

search/documents/glossary_document.php [new file with mode: 0644]
search/lib.php

diff --git a/search/documents/glossary_document.php b/search/documents/glossary_document.php
new file mode 100644 (file)
index 0000000..0305b72
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+  /* This document illustrates how easy it is to add a module to
+   * the search index - the only modifications made were creating
+   * this file, and adding the SEARCH_TYPE_GLOSSARY constant to
+   * search/lib.php - everything else is automatically handled
+   * by the indexer script.
+   * */
+
+  require_once("$CFG->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
index 964f27545f87af9224f824b9725cd98b931b310c..5da8d87baac9295ff377de9dfeef108ae1887184 100644 (file)
@@ -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') {