mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Glossary indexing added, used to demonstrate that it's relatively simple
to add a new module to the indexing queue.
This commit is contained in:
parent
ed35659607
commit
defb87ba90
2 changed files with 67 additions and 1 deletions
65
search/documents/glossary_document.php
Normal file
65
search/documents/glossary_document.php
Normal file
|
@ -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
|
||||
|
||||
?>
|
|
@ -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') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue