Source for file course.php

Documentation is available at course.php

  1. <?php
  2.     // This file is part of the Sloodle project (www.sloodle.org)
  3.    
  4.     /**
  5.     * This file defines a structure for Sloodle data about a particular Moodle course.
  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.     /** Include the general Sloodle library. */
  15.     require_once(SLOODLE_LIBROOT.'/general.php');
  16.     /** Include the Sloodle controller structure. */
  17.     require_once(SLOODLE_LIBROOT.'/controller.php');
  18.     /** Include the layout profile management stuff. */
  19.     require_once(SLOODLE_LIBROOT.'/layout_profile.php');
  20.    
  21.     /**
  22.     * The Sloodle course data class
  23.     * @package sloodle
  24.     */
  25.     class SloodleCourse
  26.     {
  27.     // DATA //
  28.    
  29.         /**
  30.         * The database object of the course to which this object relates.
  31.         * Corresponds to the "course" table in Moodle.
  32.         * Is null if not yet set
  33.         * @var object 
  34.         * @access private
  35.         */
  36.         var $course_object = null;
  37.    
  38.         /**
  39.         * The Sloodle course data object, if it exists.
  40.         * Is null if not yet set.
  41.         * @var object 
  42.         * @var private 
  43.         */
  44.         var $sloodle_course_data = null;
  45.        
  46.         /**
  47.         * The {@link SloodleController} object being used to access this course, if available.
  48.         * @var SloodleController 
  49.         * @var public 
  50.         */
  51.         var $controller = null;
  52.        
  53.        
  54.     // FUNCTIONS //
  55.    
  56.         /**
  57.         * Constructor
  58.         */
  59.         function SloodleCourse()
  60.         {
  61.             $this->controller = new SloodleController();
  62.         }
  63.        
  64.         /**
  65.         * Determines whether or not course data has been loaded.
  66.         * @return bool 
  67.         */
  68.         function is_loaded()
  69.         {
  70.             if (empty($this->course_object|| empty($this->sloodle_course_data)) return false;
  71.             return true;
  72.         }
  73.        
  74.         /**
  75.         * Gets the identifier of the course in the VLE.
  76.         * @return mixed Course identifier. Type depends on VLE. (In Moodle, it will be an integer).
  77.         */
  78.         function get_course_id()
  79.         {
  80.             return (int)$this->course_object->id;
  81.         }
  82.        
  83.         /**
  84.         * Gets the VLE course object.
  85.         * WARNING: this should only be used when ABSOLUTELY necessary.
  86.         * The contents are specific to the VLE.
  87.         * @return mixed Type and content depends upon VLE. In Moodle, it is an object representing a record from the 'course' table.
  88.         */
  89.         function get_course_object()
  90.         {
  91.             return $this->course_object;
  92.         }
  93.        
  94.        
  95.         /**
  96.         * Gets the short name of this course in the VLE.
  97.         * @return string Shortname of this course.
  98.         */
  99.         function get_short_name()
  100.         {
  101.             return $this->course_object->shortname;
  102.         }
  103.        
  104.         /**
  105.         * Gets the full name of this course in the VLE.
  106.         * @return string Fullname of this course.
  107.         */
  108.         function get_full_name()
  109.         {
  110.             return $this->course_object->fullname;
  111.         }
  112.        
  113.         /**
  114.         * Is auto registration permitted on this site AND course?
  115.         * Takes into account the site-wide setting as well.
  116.         * @return bool 
  117.         */
  118.         function check_autoreg()
  119.         {
  120.             // Check the site *and* the course value
  121.             return ((bool)sloodle_autoreg_enabled_site(&& (bool)$this->get_autoreg());
  122.         }
  123.        
  124.         /**
  125.         * Gets the autoregistration value for this course only.
  126.         * (Ignores the site setting).
  127.         * @return bool 
  128.         */
  129.         function get_autoreg()
  130.         {
  131.             return (!empty($this->sloodle_course_data->autoreg));
  132.         }
  133.        
  134.         /**
  135.         * Enables auto-registration for this course.
  136.         * NOTE: it may still be disabled at site-level.
  137.         * @return void 
  138.         */
  139.         function enable_autoreg()
  140.         {
  141.             $this->sloodle_course_data->autoreg 1;
  142.         }
  143.        
  144.         /**
  145.         * Disables auto-registration for this course.
  146.         * NOTE: does not affect the site setting.
  147.         * @return void 
  148.         */
  149.         function disable_autoreg()
  150.         {
  151.             $this->sloodle_course_data->autoreg 0;
  152.         }
  153.        
  154.        
  155.        
  156.         /**
  157.         * Is auto enrolment permitted on this site AND course?
  158.         * Takes into account the site-wide setting as well.
  159.         * @return bool 
  160.         */
  161.         function check_autoenrol()
  162.         {
  163.             // Check the site *and* the course value
  164.             return ((bool)sloodle_autoenrol_enabled_site(&& $this->get_autoenrol());
  165.         }
  166.        
  167.         /**
  168.         * Gets the auto enrolment value for this course only.
  169.         * (Ignores the site setting).
  170.         * @return bool 
  171.         */
  172.         function get_autoenrol()
  173.         {
  174.             return (!empty($this->sloodle_course_data->autoenrol));
  175.         }
  176.        
  177.         /**
  178.         * Enables auto-enrolment for this course.
  179.         * NOTE: it may still be disabled at site-level.
  180.         * @return void 
  181.         */
  182.         function enable_autoenrol()
  183.         {
  184.             $this->sloodle_course_data->autoenrol 1;
  185.         }
  186.        
  187.         /**
  188.         * Disables auto-enrolment for this course.
  189.         * NOTE: does not affect the site setting.
  190.         * @return void 
  191.         */
  192.         function disable_autoenrol()
  193.         {
  194.             $this->sloodle_course_data->autoenrol 0;
  195.         }
  196.        
  197.        
  198.        
  199.         /**
  200.         * Determines whether or not the course is available.
  201.         * Checks that the course has not been disabled or hidden etc..
  202.         * @return bool True if the course is available
  203.         */
  204.         function is_available()
  205.         {
  206.             // Check visbility
  207.             if (empty($this->course_object->visible)) return false;
  208.            
  209.             return true;
  210.         }
  211.        
  212.        
  213.         /**
  214.         * Gets the position of the loginzone as a string vector <x,y,z>
  215.         * @return string 
  216.         */
  217.         function get_loginzone_position()
  218.         {
  219.             if (isset($this->sloodle_course_data->loginzonepos)) return $this->sloodle_course_data->loginzonepos;
  220.             return '';
  221.         }
  222.        
  223.         /**
  224.         * Sets the position of the loginzone as a string vector <x,y,z>
  225.         * @param string $pos A string position vector <x,y,z>
  226.         * @return void 
  227.         * @todo Update to handle arrays as well
  228.         */
  229.         function set_loginzone_position($pos)
  230.         {
  231.             $this->sloodle_course_data->loginzonepos $pos;
  232.         }
  233.        
  234.         /**
  235.         * Sets the position of the loginzone as a set of components
  236.         * @param float $x 
  237.         * @param float $y 
  238.         * @param float $z 
  239.         * @return void 
  240.         */
  241.         function set_loginzone_position_xyz($x$y$z)
  242.         {
  243.             $this->sloodle_course_data->loginzonepos "<$x,$y,$z>";
  244.         }
  245.        
  246.        
  247.         /**
  248.         * Gets the size of the loginzone as a string vector <x,y,z>
  249.         * @return string 
  250.         */
  251.         function get_loginzone_size()
  252.         {
  253.             if (isset($this->sloodle_course_data->loginzonesize)) return $this->sloodle_course_data->loginzonesize;
  254.             return '';
  255.         }
  256.        
  257.         /**
  258.         * Sets the size of the loginzone as a string vector <x,y,z>
  259.         * @param string $size A string size vector <x,y,z>
  260.         * @return void 
  261.         * @todo Update to handle arrays as well
  262.         */
  263.         function set_loginzone_size($size)
  264.         {
  265.             $this->sloodle_course_data->loginzonesize $size;
  266.         }
  267.        
  268.         /**
  269.         * Sets the size of the loginzone as a set of components
  270.         * @param float $x 
  271.         * @param float $y 
  272.         * @param float $z 
  273.         * @return void 
  274.         */
  275.         function set_loginzone_size_xyz($x$y$z)
  276.         {
  277.             $this->sloodle_course_data->loginzonesize "<$x,$y,$z>";
  278.         }
  279.        
  280.        
  281.         /**
  282.         * Gets the region of the loginzone
  283.         * @return string 
  284.         */
  285.         function get_loginzone_region()
  286.         {
  287.             if (isset($this->sloodle_course_data->loginzoneregion)) return $this->sloodle_course_data->loginzoneregion;
  288.             return '';
  289.         }
  290.        
  291.         /**
  292.         * Sets the region of the loginzone
  293.         * @param string $region A string naming a region
  294.         * @return void 
  295.         */
  296.         function set_loginzone_region($region)
  297.         {
  298.             $this->sloodle_course_data->loginzoneregion $region;
  299.         }
  300.        
  301.        
  302.         /**
  303.         * Gets the timestamp of the last time the loginzone was updated
  304.         * @return int 
  305.         */
  306.         function get_loginzone_time_updated()
  307.         {
  308.             if (isset($this->sloodle_course_data->loginzoneupdated)) return $this->sloodle_course_data->loginzoneupdated;
  309.             return 0;
  310.         }
  311.        
  312.         /**
  313.         * Sets the timestamp of the last time the loginzone was updated
  314.         * @param int $timestamp A unix timestamp. If null, the current timestamp is used
  315.         * @return void 
  316.         */
  317.         function set_loginzone_time_updated($timestamp null)
  318.         {
  319.             if ($timestamp == null$timestamp time();
  320.             $this->sloodle_course_data->loginzoneupdated $timestamp;
  321.         }
  322.  
  323.  
  324.  
  325.         /**
  326.         * Generates a new LoginZone allocation for the specified user.
  327.         * @param SloodleUser $user The user for whom this allocation should be made
  328.         * @return string|falseA SLurl for the allocation, or false if it was unsuccessful
  329.         */
  330.         function generate_loginzone_allocation($user)
  331.         {
  332.             // Make sure the necessary data is available
  333.             if (!(isset($this->sloodle_course_data->loginzonepos&& isset($this->sloodle_course_data->loginzonesize&& isset($this->sloodle_course_data->loginzoneregion))) return false;
  334.             // Delete any existing LoginZone allocation for this user
  335.             delete_records('sloodle_loginzone_allocation''userid'$user->get_user_id());
  336.            
  337.             // We will try up to 10 times to find a new available position
  338.             $loginzonesize sloodle_vector_to_array($this->sloodle_course_data->loginzonesize);
  339.             $maxtries 10;
  340.             $success false;
  341.             for ($i 0$i $maxtries && $success == false$i++{
  342.                 // Generate a new random position
  343.                 $rndpos_arr sloodle_random_position_in_zone($loginzonesize);
  344.                 $rndpos_str sloodle_array_to_vector($rndpos_arr);
  345.                 // Is the position already taken?
  346.                 if (!get_record('sloodle_loginzone_allocation''course'$this->get_course_id()'position'$rndpos_str)) {
  347.                     // Nobody has the position
  348.                     $success true;
  349.                 }
  350.             }
  351.             // Did we succeed in generating it?
  352.             if (!$successreturn false;
  353.            
  354.             // Create a new one
  355.             $alloc new stdClass();
  356.             $alloc->course $this->get_course_id();
  357.             $alloc->userid $user->get_user_id();
  358.             $alloc->position $rndpos_str;
  359.             $alloc->timecreated time();
  360.             // Attempt to insert it into the database
  361.             if (!insert_record('sloodle_loginzone_allocation'$alloc)) return false;
  362.             return true;
  363.         }
  364.        
  365.         /**
  366.         * Gets the SLurl for the specified user's loginzone alloation
  367.         * @param SloodleUser $user The user whose allocation is to be retrieved
  368.         * @return string|boolThe SLurl string if successful, or false if the user has no allocation or the loginzone does not exist
  369.         */
  370.         function get_loginzone_allocation($user)
  371.         {
  372.             // Make sure the necessary data is available
  373.             if (!(isset($this->sloodle_course_data->loginzonepos&& isset($this->sloodle_course_data->loginzonesize&& isset($this->sloodle_course_data->loginzoneregion))) return false;
  374.             // Attempt to fetch the data
  375.             $alloc get_record('sloodle_loginzone_allocation''course'$this->get_course_id()'userid'$user->get_user_id());
  376.             if (!$allocreturn false;
  377.             $relpos sloodle_vector_to_array($alloc->position);
  378.             // Calculate the absolute position of the allocation
  379.             $loginzonepossloodle_vector_to_array($this->sloodle_course_data->loginzonepos);
  380.             $abspos array('x'=>$loginzonepos['x'$relpos['x']'y'=>$loginzonepos['y'$relpos['y']'z'=>$loginzonepos['z'$relpos['z']);
  381.            
  382.             // Construct and return the SLurl
  383.             return "secondlife://{$this->sloodle_course_data->loginzoneregion}/{$abspos['x']}/{$abspos['y']}/{$abspos['z']}";
  384.         }
  385.        
  386.         /**
  387.         * Finds the user identified by LoginZone allocation, and loads it into the given user object.
  388.         * Note: does not delete the allocation.
  389.         * @param string $pos Absolute position vector (relative to sim, not to LoginZone)
  390.         * @param SloodleUser &$user The user object which will be manipulated (by reference)
  391.         * @return bool True if successful, or false otherwise
  392.         */
  393.         function load_user_by_loginzone($pos&$user)
  394.         {
  395.             // Calculate the relative position of the allocation
  396.             $abspos sloodle_vector_to_array($pos);
  397.             $loginzonepossloodle_vector_to_array($this->sloodle_course_data->loginzonepos);
  398.             $relpos array('x'=>$abspos['x'$loginzonepos['x']'y'=>$abspos['y'$loginzonepos['y']'z'=>$abspos['z'$loginzonepos['z']);
  399.             $relpos sloodle_array_to_vector($relpos);
  400.        
  401.             // Attempt to find a matching LoginZone position in the database
  402.             $rec get_record('sloodle_loginzone_allocation''course'$this->get_course_id()'position'$relpos);
  403.             if (!$recreturn false;
  404.             // Load the user
  405.             return $user->load_user($rec->userid);
  406.         }
  407.        
  408.         /**
  409.         * Deletes any loginzone allocations for the given user
  410.         * If there are multiple for the same user (which there should never be) it will delete them all.
  411.         * @param SloodleUser $user The user whose allocation is to be deleted
  412.         * @return void 
  413.         */
  414.         function delete_loginzone_allocation($user)
  415.         {
  416.             delete_records('sloodle_loginzone_allocation''userid'$user->get_user_id());
  417.         }
  418.        
  419.         /**
  420.         * Determines whether or not LoginZone data exists for this course.
  421.         * @return bool True if there is complete data, or false otherwise
  422.         */
  423.         function has_loginzone_data()
  424.         {
  425.             return (!(empty($this->sloodle_course_data->loginzonepos|| empty($this->sloodle_course_data->loginzonesize|| empty($this->sloodle_course_data->loginzoneregion)));
  426.         }
  427.        
  428.        
  429.         /**
  430.         * Reads fresh data into the structure from the database.
  431.         * Fetches Moodle and Sloodle data about the course specified.
  432.         * If necessary, it creates a new Sloodle entry with default settings.
  433.         * Returns true if successful, or false on failure.
  434.         * @param mixed $course Either a unique course ID, or a course data object. If the former, then VLE course data is read from the database. Otherwise, the data object is used as-is.
  435.         * @return bool 
  436.         */
  437.         function load($course)
  438.         {
  439.             // Reset everything
  440.             $this->course_object = null;
  441.             $this->sloodle_course_data = null;
  442.        
  443.             // Check what we are dealing with
  444.             if (is_int($course)) {
  445.                 // It is a course ID - make sure it's valid
  446.                 if ($course <= 0return false;
  447.                 // Load the course data
  448.                 $this->course_object = get_record('course''id'$course);
  449.                 if (!$this->course_object{
  450.                     $this->course_object = null;
  451.                     return false;
  452.                 }
  453.             else if (is_object($course)) {
  454.                 // It is an object - make sure it has an ID
  455.                 if (!isset($course->id)) return false;
  456.                 $this->course_object = $course;
  457.             else {
  458.                 // Don't know what it is - do nothing
  459.                 return false;
  460.             }
  461.            
  462.             // Fetch the Sloodle course data
  463.             $this->sloodle_course_data = get_record('sloodle_course''course'$this->course_object->id);
  464.             // Did it fail?
  465.             if (!$this->sloodle_course_data{
  466.                 // Create the new entry
  467.                 $this->sloodle_course_data = new stdClass();
  468.                 $this->sloodle_course_data->course $this->course_object->id;
  469.                 $this->sloodle_course_data->autoreg 0;
  470.                 $this->sloodle_course_data->loginzonepos '';
  471.                 $this->sloodle_course_data->loginzonesize '';
  472.                 $this->sloodle_course_data->loginzoneregion '';
  473.                 $this->sloodle_course_data->id insert_record('sloodle_course'$this->sloodle_course_data);
  474.                 // Did something go wrong?
  475.                 if (!$this->sloodle_course_data->id{
  476.                     $this->course_object = null;
  477.                     $this->sloodle_course_data = null;
  478.                     return false;
  479.                 }
  480.             }
  481.            
  482.             return true;
  483.         }
  484.        
  485.         /**
  486.         * Loads course and controller data by the unqiue site-wide identifier of a Sloodle controller.
  487.         * @param mixed $controllerid The unique site-wide identifier for a Sloodle Controller. (For Moodle, an integer cmi)
  488.         * @return bool True if successful, or false on failure.
  489.         */
  490.         function load_by_controller($controllerid)
  491.         {
  492.             // Clear out all our data
  493.             $this->course_object = null;
  494.             $this->sloodle_course_data = null;
  495.            
  496.             // Construct a new controller object, and attempt to load its data
  497.             $this->controller = new SloodleController();
  498.             if (!$this->controller->load($controllerid)) {
  499.                 sloodle_debug("Failed to load controller.<br>");
  500.                 return false;
  501.             }
  502.            
  503.             // Now attempt to load all the course data
  504.             if (!$this->load($this->controller->get_course_id())) {
  505.                 sloodle_debug("Failed to load course data.<br>");
  506.                 return false;
  507.             }
  508.            
  509.             return true;
  510.         }
  511.        
  512.         /**
  513.         * Writes current Sloodle course data back to the database.
  514.         * Requires that a course structure has already been retrieved.
  515.         * @return bool True if successful, or false on failure
  516.         */
  517.         function write()
  518.         {
  519.             // Make sure the course data is valid
  520.             if (empty($this->course_object|| $this->course_object->id <= 0return false;
  521.             if (empty($this->sloodle_course_data|| $this->sloodle_course_data->id <= 0return false;
  522.             // Update the Sloodle data
  523.             return update_record('sloodle_course'$this->sloodle_course_data);
  524.         }
  525.        
  526.         /**
  527.         * Gets an array associating layout ID's to names
  528.         * @return array 
  529.         */
  530.         function get_layout_names()
  531.         {
  532.             // Fetch the layout records
  533.             $layouts get_records('sloodle_layout''course'$this->course_object->id'name');
  534.             if (!$layoutsreturn array();
  535.             // Construct the array of names
  536.             $layout_names array();
  537.             foreach ($layouts as $l{
  538.                 $layout_names[$l->id$l->name;
  539.             }
  540.            
  541.             return $layout_names;
  542.         }
  543.  
  544.  
  545.         /**
  546.         * Gets all the entries in the named layout.
  547.         * @param string $name The name of the layout to query
  548.         * @return array|boolA numeric array of {@link SloodleLayoutEntry} objects if successful, or false if the layout does not exist
  549.         */
  550.         function get_layout_entries($name)
  551.         {
  552.             // Attempt to find the relevant layout
  553.             $layout get_record('sloodle_layout''course'$this->course_object->id'name'$name);
  554.             if (!$layoutreturn false;
  555.            
  556.             return $this->get_layout_entries_for_layout_id($layout->id);
  557.         }
  558.  
  559.         /**
  560.         * Gets all the entries in the named layout.
  561.         * @param string $name The name of the layout to query
  562.         * @return array|boolA numeric array of {@link SloodleLayoutEntry} objects if successful, or false if the layout does not exist
  563.         */
  564.         function get_layout_entries_for_layout_id($id)
  565.         {
  566.             // Fetch all entries
  567.             $recs get_records('sloodle_layout_entry''layout'$id);
  568.             if (!$recsreturn array();
  569.            
  570.             // Construct the array of SloodleLayoutEntry objects
  571.             $entries array();
  572.             foreach ($recs as $r{
  573.                 $entry new SloodleLayoutEntry($r);
  574.                 $entries[$entry;
  575.             }
  576.            
  577.             return $entries;
  578.         }
  579.  
  580.         /**
  581.         * Gets SloodleLayout objects for all the layouts in the course.
  582.         */
  583.         function get_layouts({
  584.             // Fetch the layout records
  585.             $layoutrecs get_records('sloodle_layout''course'$this->course_object->id'name');
  586.             $layouts array();
  587.  
  588.             if (!$layoutrecsreturn array();
  589.  
  590.             foreach ($layoutrecs as $r{
  591.                 $layouts[new SloodleLayout($r);
  592.             }
  593.  
  594.             return $layouts;
  595.         }
  596.        
  597.         /**
  598.         * Deletes the named layout.
  599.         * @param string $name The name of the layout to delete
  600.         * @return void 
  601.         */
  602.         function delete_layout($name)
  603.         {
  604.             // Attempt to find the relevant layout
  605.             $layout get_record('sloodle_layout''course'$this->course_object->id'name'$name);
  606.             if (!$layoutreturn;
  607.            
  608.             // Delete all related entries
  609.             delete_records('sloodle_layout_entry''layout'$layout->id);
  610.             // Delete the layout itself
  611.             delete_records('sloodle_layout''course'$this->course_object->id'name'$name);
  612.         }
  613.        
  614.         /**
  615.         * Save the given entries in the named profile.
  616.         * @param string $name The name of the layout to query
  617.         * @param array $entries A numeric array of {@link SloodleLayoutEntry} objects to store
  618.         * @param bool $add (Default: false) If true, then the entries will be added to the layout instead of replacing existing entries
  619.         * @return bool True if successful, or false otherwise
  620.         */
  621.         function save_layout($name$entries$add false)
  622.         {
  623.             // Attempt to find the relevant layout
  624.             $layout get_record('sloodle_layout''course'$this->course_object->id'name'$name);
  625.             $lid 0;
  626.             if ($layout{
  627.                $lid $layout->id;
  628.             }
  629.  
  630.             return $this->save_layout_by_id($lid$name$entries$add);
  631.         }
  632.          
  633.         /**
  634.         * Save the given entries in the profile specified by id.
  635.         * @param string $id The id of the layout to query. 0 to add a new layout.
  636.         * @param string $name The new name of the layout.
  637.         * @param array $entries A numeric array of {@link SloodleLayoutEntry} objects to store
  638.         * @param bool $add (Default: false) If true, then the entries will be added to the layout instead of replacing existing entries
  639.         * @return bool True if successful, or false otherwise
  640.         */
  641.         function save_layout_by_id($id$name$entries$add false)
  642.         {
  643.             // Attempt to find the relevant layout
  644.             if ($id 0{
  645.  
  646. /*
  647.                 // Delete all existing entries if necessary
  648.                 // This will happen when we save
  649.                 // TODO: make add-only functionality for backwards compatibility
  650.                 if (!$add) {
  651.                         delete_records('sloodle_layout_entry', 'layout', $layout->id);
  652.                 }
  653. */
  654.  
  655.                 $layout $this->get_layout($id);
  656.                 $layout->name $name;
  657.                 $layout->timeupdated time();
  658.                 $layout->entries $entries;
  659.                 $layout->populate_entries_from_active_objects()// where the records have objectuuids set, copy their settings
  660.                 if (!$layout->update()) {
  661.                    return false;
  662.                 }
  663.                 $this->layout $layout;
  664.             else {
  665.                 $layout new SloodleLayout();
  666.                 $layout->name $name;
  667.                 $layout->course $this->course_object->id;
  668.                 $layout->timeupdated time();
  669.                 $layout->entries $entries;
  670.                 $layout->populate_entries_from_active_objects();
  671.                 $layout->id $layout->insert();  #insert_record('sloodle_layout', $layout);
  672.                 if (!$layout->idreturn false;
  673.                 $this->layout $layout;
  674.             }
  675.            
  676. /*
  677.             // This should have been done by the layout
  678.             // Insert each new entry
  679.             $success = true;
  680.             foreach ($entries as $e) {
  681.                 $rec = new stdClass();
  682.                 $rec->layout = $layout->id;
  683.                 $rec->name = $e->name;
  684.                 $rec->position = $e->position;
  685.                 $rec->rotation = $e->rotation;
  686.  
  687.                 // TODO EDE: If there's an objectuuid for the entry, copy the entries from the active object table to the layout config table
  688.                 if ($objectuuid != '') {
  689.                    $rec->copy_active_object_with_uuid($e->objectuuid);
  690.                 }
  691.                
  692.                 $entry_id = insert_record('sloodle_layout_entry', $rec);
  693.                
  694.             }
  695. */
  696.            
  697.             return $layout->id;
  698.  
  699.         }
  700.  
  701.         function get_layout($layoutid{
  702.  
  703.             $rec get_record('sloodle_layout''course'$this->course_object->id'id'$layoutid);
  704.             return new SloodleLayout($rec);
  705.  
  706.         }
  707.  
  708.         /**
  709.         * Checks whether or not the CURRENTLY LOGGED-IN user can authorise objects on this course.
  710.         * @return bool True if the user has object authorisation permission, or false otherwise.
  711.         */
  712.         function can_user_authorise_objects()
  713.         {
  714.             global $USER;
  715.             // Make sure some user data
  716.             if (empty($USER|| $USER->id == 0return FALSE;
  717.            
  718.             // Check the capability
  719.             return has_capability('mod/sloodle:objectauth'get_context_instance(CONTEXT_COURSE$this->get_course_id()));
  720.         }
  721.    
  722.     }
  723. ?>

Documentation generated on Fri, 17 Jul 2009 11:01:13 +0100 by phpDocumentor 1.4.0