Source for file module_glossary.php
Documentation is available at module_glossary.php
// This file is part of the Sloodle project (www.sloodle.org)
* This file defines a glossary module for Sloodle.
* @copyright Copyright (c) 2008 Sloodle (various contributors)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
* @contributor Peter R. Bloomfield
/** The Sloodle module base. */
require_once(SLOODLE_LIBROOT.
'/modules/module_base.php');
/** General Sloodle functions. */
require_once(SLOODLE_LIBROOT.
'/general.php');
* The Sloodle glossary module class.
* Internal for Moodle only - course module instance.
* Corresponds to one record from the Moodle 'course_modules' table.
* Internal only - Moodle glossary module instance database object.
* Corresponds to one record from the Moodle 'glossary' table.
parent::$constructor($_session);
* Loads data from the database.
* Note: even if the function fails, it may still have overwritten some or all existing data in the object.
* @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
* @return bool True if successful, or false otherwise
// Make sure the ID is valid
if ($id <=
0) return false;
// Fetch the course module data
if (!($this->cm =
get_coursemodule_from_id('glossary', $id))) {
sloodle_debug("Failed to load course module instance #$id.<br/>");
// Make sure the module is visible
if ($this->cm->visible ==
0) {
sloodle_debug("Error: course module instance #$id not visible.<br/>");
// Load from the primary table: glossary instance
sloodle_debug("Failed to load glossary with instance ID #{$cm->instance}.<br/>
");
* Searches all entries in the current glossary for the given term.
* @param string $term The term to search for
* @param bool $matchPartial If TRUE (default) then partial matches will be returned (e.g. 'vat' would partially match 'avatar')
* @param bool $searchAliases If TRUE (not default) then aliases will be searched as well
* @param bool $searchDefinitions If TRUE (not default) then definitions will be searched as well (can be SLOW, and always gets partial matches)
* @return array An array of {@link SloodleGlossaryEntry} objects
function search($term, $matchPartial =
true, $searchAliases =
false, $searchDefinitions =
false)
// This array will store the results associatively, ID => SloodleGlossaryDefinition
$termquery =
"$sql_like '$term'";
if ($matchPartial) $termquery =
"$sql_like '%$term%'";
$recs =
get_records_select('glossary_entries', 'concept '.
$termquery, 'concept');
$recs =
get_records_select('glossary_alias', 'alias '.
$termquery);
// Go through each alias found
// Did we already have this entry?
if (!isset
($entries[$r->entryid])) {
// No - fetch the entry and store it
$entry =
get_record('glossary_entries', 'id', $r->entryid);
if ($searchDefinitions) {
$recs =
get_records_select('glossary_entries', "definition $sql_like '%$term%'", 'concept');
if (!isset
($entries[$r->id])) $entries[$r->id] =
new SloodleGlossaryEntry($r->id, $r->concept, $r->definition);
* Gets the name of this module instance.
* @return string The name of this controller
* Gets the intro description of this module instance, if available.
* @return string The intro description of this controller
* Gets the identifier of the course this controller belongs to.
* @return mixed Course identifier. Type depends on VLE. (In Moodle, it will be an integer).
* Gets the time at which this instance was created, or 0 if unknown.
* Gets the time at which this instance was last modified, or 0 if unknown.
* Gets the short type name of this instance.
* Gets the full type name of this instance, according to the current language pack, if available.
* Note: should be overridden by sub-classes.
* @return string Full type name if possible, or the short name otherwise.
return get_string('modulename', 'glossary');
* Represents a single glossary entry
* Constructor - initialises members.
* @param mixed $id The ID of this message - type depends on VLE, but is typically an integer
* @param string $concept The name of this entry
* @param string $definition The definition of this entry
* Accessor - set all members in a single call.
* @param mixed $id The ID of this message - type depends on VLE, but is typically an integer
* @param string $concept The name of this entry
* @param string $definition The definition of this entry
function set($id, $concept, $definition)
* The type depends on the VLE, but typically is an integer.
* The name of this entry.
* The definition of this entry.
Documentation generated on Mon, 07 Jul 2008 12:32:58 +0100 by phpDocumentor 1.4.0