Source for file sl_glossary_lib.php

Documentation is available at sl_glossary_lib.php

  1. <?php
  2.     /**
  3.     * Sloodle glossary local library functions.
  4.     *
  5.     * Allows easier access to the Moodle glossary data.
  6.     *
  7.     * @package sloodleglossary
  8.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  9.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  10.     *
  11.     * @contributor Peter R. Bloomfield
  12.     *
  13.     */
  14.     
  15.     // This script expects that the Sloodle configuration script has already been included
  16.  
  17.  
  18.     /**
  19.     * Gets an array of available glossaries in the specified course.
  20.     * Glossaries which are hidden, or which are in a hidden section of the course, are ignored.
  21.     *
  22.     * @param int $course_id Integer ID of a Moodle course
  23.     * @return mixed If successful, a numeric array, associating module instance ID's with database record objects of the activity modules. Returns boolean false if an error occurs.
  24.     * @see sloodle_get_visible_chatrooms_in_course()
  25.     * @see sloodle_get_visible_choices_in_course()
  26.     * @todo: Generalise this function to support any module type
  27.     */
  28.     function sloodle_get_visible_glossaries_in_course$course_id )
  29.     {
  30.         // THIS IS HIDEOUSLY COMPLICATED! My brain is officially fried... :-|.... PRB
  31.         
  32.         // Make sure the course ID is valid
  33.         if (!is_int($course_id|| $course_id <= 0return FALSE;
  34.         // Find out which module number the glossary is (this will fail if the glossary module is not installed)
  35.         if (!($glossary_module get_record('modules''name''glossary'))) return FALSE;
  36.         $glossary_module_id $glossary_module->id;
  37.         
  38.         // We want a list of sections in the specified course
  39.         if (!($course_sections get_records('course_sections''course'$course_id))) return FALSE;
  40.         // We need to filter that to visible sections only
  41.         $visible_course_sections array();
  42.         foreach ($course_sections as $cur_section{
  43.             if ((int)$cur_section->visible != 0$visible_course_sections[= (int)$cur_section->id;
  44.         }
  45.         
  46.         // Get full records for all glossaryes in the specified course
  47.         if (!($all_glossaries_in_course get_records('glossary''course'$course_id))) return array();        
  48.         // We're going to want an array of records of visible glossaries
  49.         $visible_glossary_records array();
  50.         
  51.         // Get a list of module instances in the specified course (this gets everything, not just glossaries)
  52.         if (!($all_course_modules get_records('course_modules''course'$course_id))) return array();
  53.         // We want to filter the module instances down to visible glossary ID's
  54.         $visible_glossary_modules array();
  55.         foreach ($all_course_modules as $mod{
  56.             // Is this a glossary, is it visible, and is it in a visible section of the course?
  57.             // (It's ridiculously complicated... I know...)
  58.             if ($mod->module == $glossary_module_id && (int)$mod->visible != && in_array((int)$mod->section$visible_course_sections)) {
  59.                 // OK - this is a visible glossary in the correct course.
  60.                 // Now find its database record...
  61.                 foreach ($all_glossaries_in_course as $cur_glossary_record{
  62.                     // The 'instance' field of the course module instances corresponds to
  63.                     //  the 'id' field of the glossary records
  64.                     if ($mod->instance == $cur_glossary_record->id{
  65.                         // Woohoo! We found a match. Add it to our database
  66.                         $visible_glossary_records[$mod->id$cur_glossary_record;
  67.                     }
  68.                 }
  69.             }
  70.         }
  71.         
  72.         return $visible_glossary_records;
  73.     }
  74.     
  75.     /**
  76.     * Gets a glossary activity module instance.
  77.     *
  78.     * @param object $cmi A course module instance object (database record)
  79.     * @return mixed A database record object if successful, or false if not.
  80.     */
  81.     function sloodle_get_glossary_activity_module$cmi )
  82.     {
  83.         // Make sure we were given a valid object
  84.         if (!is_object($cmi|| !isset($cmi->instance)) return FALSE;
  85.         // Search the database for a glossary object
  86.         return get_record('glossary''id'$cmi->instance);
  87.     }
  88.     
  89.     /**
  90.     * Searches glossary terms for a word or phrase.
  91.     *
  92.     * @param object $glossary An activity module instance (e.g. returned from {@link sloodle_get_glossary_activity_module()}.
  93.     * @param string $concept A string to search for.
  94.     * @return mixed A numeric array of entries (as records from the database) if successful, or boolean false if not.
  95.     */
  96.     function sloodle_lookup_glossary$glossary$concept )
  97.     {
  98.         return glossary_search_entries(array($concept)$glossary0);
  99.     }
  100.     
  101.  
  102. ?>

Documentation generated on Tue, 04 Mar 2008 15:08:42 +0000 by phpDocumentor 1.4.0