Source for file modules.php

Documentation is available at modules.php

  1. <?php
  2.     // This file is part of the Sloodle project (www.sloodle.org)
  3.     
  4.     /**
  5.     * This file brings all of the Sloodle module classes together.
  6.     * It also provides functionality to create and load different module types.
  7.     *
  8.     * @package sloodle
  9.     * @copyright Copyright (c) 2008 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.     /** Base module. */
  17.     require_once(SLOODLE_LIBROOT.'/modules/module_base.php');
  18.     
  19.     /** Distributor module. */
  20.     include_once(SLOODLE_LIBROOT.'/modules/module_distributor.php');
  21.     /** Chat module. */
  22.     include_once(SLOODLE_LIBROOT.'/modules/module_chat.php');
  23.     /** Glossary module. */
  24.     include_once(SLOODLE_LIBROOT.'/modules/module_glossary.php');
  25.     /** Sloodle Object assignment module. */
  26.     include_once(SLOODLE_LIBROOT.'/modules/module_sloodleobject.php');
  27.     
  28.     //... include more module types here!
  29.     
  30.     
  31.     // We will store an associative array of module types to module class names
  32.     // e.g. { 'chat'=>'SloodleModuleChat', 'distributor'=>'SloodleModuleDistributor', ...}
  33.     global $SLOODLE_MODULE_CLASS;
  34.     $SLOODLE_MODULE_CLASS array();
  35.     // Go through each declared class
  36.     $allclasses get_declared_classes();
  37.     foreach ($allclasses as $c{
  38.         // Is this class a subclass of the Sloodle Module type?
  39.         if (strcasecmp(get_parent_class($c)'SloodleModule'== 0{
  40.             // Fetch the type name
  41.             $curtype call_user_func(array($c'get_type'));
  42.             if (!empty($curtype)) {
  43.                 // Add it to our array with its type
  44.                 $SLOODLE_MODULE_CLASS[$curtype$c;
  45.             }
  46.         }
  47.     }
  48.     
  49.     
  50.     /**
  51.     * Constructs a appropriate Sloodle module object based on the named type.
  52.     * @param string $type The type of module to construct - typically a short name, such as 'chat' or 'blog'
  53.     * @param SloodleSession &$_session The {@link SloodleSession} object to pass to the module on construction, or just null
  54.     * @param mixed $id The identifier of the module instance to load from the database (or null if there is no module data)
  55.     * @return SloodleModule|boolReturns the cosntructed module object, or false if it fails
  56.     */
  57.     function sloodle_load_module($type&$_session$id null)
  58.     {
  59.         global $SLOODLE_MODULE_CLASS;
  60.         
  61.         // Abort if the type is not recognised
  62.         if (!array_key_exists($type$SLOODLE_MODULE_CLASS)) {
  63.             sloodle_debug("Module load failed - type \"$type\" not recognised.<br/>");
  64.             return false;
  65.         }
  66.         // Construct the object, based on the class name in our array
  67.         $module new $SLOODLE_MODULE_CLASS[$type]($_session);
  68.         
  69.         // Load the data from the database, if necessary
  70.         if ($id != null{
  71.             if ($module->load($id)) return $module;
  72.             sloodle_debug("Failed to load module data from database with ID $id.<br/>");
  73.             return false;
  74.         }
  75.         
  76.         // Everything seems OK
  77.         return $module;
  78.     }
  79.  
  80. ?>

Documentation generated on Mon, 16 Jun 2008 15:56:43 +0100 by phpDocumentor 1.4.0