Source for file module_map.php

Documentation is available at module_map.php

  1. <?php
  2.     // This file is part of the Sloodle project (www.sloodle.org)
  3.     
  4.     /**
  5.     * This file defines a map resource module for Sloodle.
  6.     *
  7.     * @package sloodle
  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.     /** The Sloodle module base. */
  15.     require_once(SLOODLE_LIBROOT.'/modules/module_base.php');
  16.     /** General Sloodle functions. */
  17.     require_once(SLOODLE_LIBROOT.'/general.php');
  18.     
  19.     /**
  20.     * The Sloodle map resource module class.
  21.     * @package sloodle
  22.     */
  23.     class SloodleModuleMap extends SloodleModule
  24.     {
  25.     // DATA //
  26.     
  27.         /**
  28.         * Internal for Moodle only - course module instance.
  29.         * Corresponds to one record from the Moodle 'course_modules' table.
  30.         * @var object 
  31.         * @access private
  32.         */
  33.         var $cm = null;
  34.     
  35.         /**
  36.         * Internal only - Sloodle module instance database object.
  37.         * Corresponds to one record from the Moodle 'mdl_sloodle' table.
  38.         * @var object 
  39.         * @access private
  40.         */
  41.         var $sloodle_instance = null;
  42.         
  43.         /**
  44.         * Instance of the extra Map data from the sloodle_map table.
  45.         * @var object 
  46.         * @access private
  47.         */
  48.         var $sloodle_map = null;
  49.                 
  50.         
  51.     // FUNCTIONS //
  52.     
  53.         /**
  54.         * Constructor
  55.         */
  56.         function SloodleModuleMap(&$_session)
  57.         {
  58.             $constructor get_parent_class($this);
  59.             parent::$constructor($_session);
  60.         }
  61.         
  62.         /**
  63.         * Loads data from the database.
  64.         * Note: even if the function fails, it may still have overwritten some or all existing data in the object.
  65.         * @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)
  66.         * @return bool True if successful, or false otherwise
  67.         */
  68.         function load($id)
  69.         {
  70.             // Make sure the ID is valid
  71.             $id = (int)$id;
  72.             if ($id <= 0return false;
  73.             
  74.             // Fetch the course module data
  75.             if (!($this->cm = get_coursemodule_from_id('sloodle'$id))) {
  76.                 sloodle_debug("Failed to load course module instance #$id.<br/>");
  77.                 return false;
  78.             }
  79.             // Make sure the module is visible
  80.             if ($this->cm->visible == 0{
  81.                 // Ignore visibility - teachers may want to setup map when it's invisible.
  82.                 //sloodle_debug("Error: course module instance #$id not visible.<br/>");
  83.                 //return false;
  84.             }
  85.             
  86.             // Load from the primary table: sloodle instance
  87.             if (!($this->sloodle_instance = get_record('sloodle''id'$this->cm->instance))) {
  88.                 sloodle_debug("Failed to load Sloodle module with instance ID #{$cm->instance}.<br/>");
  89.                 return false;
  90.             }
  91.             
  92.             // Load from the secondary table: sloodle map
  93.             if (!($this->sloodle_map = get_record('sloodle_map''sloodleid'$this->sloodle_instance->id))) {
  94.                 sloodle_debug("Failed to load Sloodle map with sloodleid #{$this->sloodle_instance->id}.<br/>");
  95.                 return false;
  96.             }
  97.             
  98.             return true;
  99.         }
  100.         
  101.         /**
  102.         * Gets the initial coordinates of the map.
  103.         * @return array Numeric array (or list) containing X and Y floating point components, as global coordinates.
  104.         */
  105.         function get_initial_coordinates()
  106.         {
  107.             return array((float)$this->sloodle_map->initialx(float)$this->sloodle_map->initialy);
  108.         }
  109.         
  110.         /**
  111.         * Sets the initial coordinates of the map.
  112.         * @par int $x The global X coordinate for the map's initial location
  113.         * @par int $y The global Y coordinate for the map's initial location
  114.         * @return bool True if successful, or false if not.
  115.         */
  116.         function set_initial_coordinates($x$y)
  117.         {
  118.             // Clean the data
  119.             $x = (float)$x;
  120.             $y = (float)$y;
  121.             // Update the data
  122.             $this->sloodle_map->initialx $x;
  123.             $this->sloodle_map->initialy $y;
  124.             return update_record('sloodle_map'$this->sloodle_map);
  125.         }
  126.         
  127.         /**
  128.         * Gets the initial zoom factor of the map (1 - 6).
  129.         * @return integer 
  130.         */
  131.         function get_initial_zoom()
  132.         {
  133.             return (int)$this->sloodle_map->initialzoom;
  134.         }
  135.         
  136.         /**
  137.         * Checks if the pan controls should be visible.
  138.         * @return bool 
  139.         */
  140.         function check_pan_controls()
  141.         {
  142.             return (!empty($this->sloodle_map->showpan));
  143.         }
  144.         
  145.         /**
  146.         * Checks if map dragging should be enabled.
  147.         * @return bool 
  148.         */
  149.         function check_allow_drag()
  150.         {
  151.             return (!empty($this->sloodle_map->allowdrag));
  152.         }
  153.         
  154.         /**
  155.         * Checks if the zoom controls should be visible.
  156.         * @return bool 
  157.         */
  158.         function check_zoom_controls()
  159.         {
  160.             return (!empty($this->sloodle_map->showzoom));
  161.         }
  162.         
  163.         
  164.         /**
  165.         * Returns a numeric array of locations associated with this map. Sorted by name.
  166.         * Each element is an object direct from the sloodle_map_location table.
  167.         * @return array 
  168.         */
  169.         function get_locations()
  170.         {
  171.             $results get_records('sloodle_map_location''sloodleid'$this->sloodle_instance->id'name');
  172.             if (!$resultsreturn array();
  173.             return $results;
  174.         }
  175.         
  176.         /**
  177.         * Adds a new location to this map.
  178.         * @par float $globalx Global X coordinate for map location.
  179.         * @par float $globaly Global Y coordinate for map location.
  180.         * @par string $region Name of the region this location is in.
  181.         * @par int $localx Local X coordinate for SLurl (local to region).
  182.         * @par int $localy Local Y coordinate for SLurl (local to region).
  183.         * @par int $localz Local Z coordinate for SLurl (local to region).
  184.         * @par string $name Name of the location.
  185.         * @par string $desc Description of the location (optional).
  186.         * @return bool True if successful or false if not.
  187.         */
  188.         function add_location($globalx$globaly$region$localx$localy$localz$name$desc '')
  189.         {
  190.             // Prepare a database record
  191.             $rec new stdClass();
  192.             $rec->sloodleid $this->sloodle_instance->id;
  193.             // Clean all the data and add it
  194.             $rec->globalx = (float)$globalx;
  195.             $rec->globaly = (float)$globaly;
  196.             $rec->region clean_text($regionFORMAT_PLAIN);
  197.             $rec->localx = (int)$localx;
  198.             $rec->localy = (int)$localy;
  199.             $rec->localz = (int)$localz;
  200.             $rec->name clean_text($nameFORMAT_PLAIN);
  201.             $rec->description clean_text($descFORMAT_PLAIN);
  202.             
  203.             return insert_record('sloodle_map_location'$recfalse);
  204.         }
  205.         
  206.         
  207.     // ACCESSORS //
  208.     
  209.         /**
  210.         * Gets the name of this module instance.
  211.         * @return string The name of this module
  212.         */
  213.         function get_name()
  214.         {
  215.             return $this->sloodle_instance->name;
  216.         }
  217.         
  218.         /**
  219.         * Gets the intro description of this module instance, if available.
  220.         * @return string The intro description of this controller
  221.         */
  222.         function get_intro()
  223.         {
  224.             return $this->sloodle_instance->intro;
  225.         }
  226.         
  227.         /**
  228.         * Gets the identifier of the course this controller belongs to.
  229.         * @return mixed Course identifier. Type depends on VLE. (In Moodle, it will be an integer).
  230.         */
  231.         function get_course_id()
  232.         {
  233.             return (int)$this->sloodle_instance->course;
  234.         }
  235.         
  236.         /**
  237.         * Gets the time at which this instance was created, or 0 if unknown.
  238.         * @return int Timestamp
  239.         */
  240.         function get_creation_time()
  241.         {
  242.             return (int)$this->sloodle_instance->timecreated;
  243.         }
  244.         
  245.         /**
  246.         * Gets the time at which this instance was last modified, or 0 if unknown.
  247.         * @return int Timestamp
  248.         */
  249.         function get_modification_time()
  250.         {
  251.             return (int)$this->sloodle_instance->timemodified;
  252.         }
  253.         
  254.         
  255.         /**
  256.         * Gets the short type name of this instance.
  257.         * @return string 
  258.         */
  259.         function get_type()
  260.         {
  261.             return SLOODLE_TYPE_MAP;
  262.         }
  263.  
  264.         /**
  265.         * Gets the full type name of this instance, according to the current language pack, if available.
  266.         * Note: should be overridden by sub-classes.
  267.         * @return string Full type name if possible, or the short name otherwise.
  268.         */
  269.         function get_type_full()
  270.         {
  271.             return get_string('moduletype:'.SLOODLE_TYPE_MAP'sloodle');
  272.         }
  273.  
  274.     }
  275. ?>

Documentation generated on Fri, 17 Jul 2009 11:02:03 +0100 by phpDocumentor 1.4.0