Source for file sl_webintercom_lib.php

Documentation is available at sl_webintercom_lib.php

  1. <?php
  2.  
  3.     /**
  4.     * Sloodle WebIntercom local library functions.
  5.     *
  6.     * Allows easier access to the Moodle chatroom data.
  7.     *
  8.     * @package sloodlechat
  9.     * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  10.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11.     *
  12.     * @contributor Peter R. Bloomfield
  13.     *
  14.     */
  15.     
  16.     // This script expects that the Sloodle configuration script has already been included
  17.  
  18.     /**
  19.     * Gets an array of available chatrooms in the specified course.
  20.     * Chatrooms 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_glossaries_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_chatrooms_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 chatroom is (this will fail if the chat module is not installed)
  35.         if (!($chat_module get_record('modules''name''chat'))) return FALSE;
  36.         $chat_module_id $chat_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 chatrooms in the specified course
  47.         if (!($all_chats_in_course get_records('chat''course'$course_id))) return array();        
  48.         // We're going to want an array of records of visible chatrooms
  49.         $visible_chat_records array();
  50.         
  51.         // Get a list of module instances in the specified course (this gets everything, not just chats)
  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 chat ID's
  54.         $visible_chat_modules array();
  55.         foreach ($all_course_modules as $mod{
  56.             // Is this a chatroom, is it visible, and is it in a visible section of the course?
  57.             // (It's ridiculously complicated... I know...)
  58.             if ($mod->module == $chat_module_id && (int)$mod->visible != && in_array((int)$mod->section$visible_course_sections)) {
  59.                 // OK - this is a visible chatroom in the correct course.
  60.                 // Now find its database record...
  61.                 foreach ($all_chats_in_course as $cur_chat_record{
  62.                     // The 'instance' field of the course module instances corresponds to
  63.                     //  the 'id' field of the chatroom records
  64.                     if ($mod->instance == $cur_chat_record->id{
  65.                         // Woohoo! We found a match. Add it to our database
  66.                         $visible_chat_records[$mod->id$cur_chat_record;
  67.                     }
  68.                 }
  69.             }
  70.         }
  71.         
  72.         return $visible_chat_records;
  73.     }
  74.  
  75. ?>

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