Source for file controller.php

Documentation is available at controller.php

  1. <?php
  2. /**
  3. * Defines a base class for viewing SLOODLE Controller modules.
  4. * Class is inherited from the base module view class.
  5. *
  6. @package sloodle
  7. @copyright Copyright (c) 2008 Sloodle (various contributors)
  8. @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. *
  10. @contributor Peter R. Bloomfield
  11. */
  12.  
  13. /** The base module view class */
  14. require_once(SLOODLE_DIRROOT.'/view/base/base_view_module.php');
  15.  
  16.  
  17. /**
  18. * The base class for viewing a SLOODLE Controller module.
  19. @package sloodle
  20. */
  21. {
  22.     /**
  23.     * SLOODLE Controller data object, retreived directly from the database (table: sloodle_controller).
  24.     * @var object 
  25.     * @access private
  26.     */
  27.     var $controller = null;
  28.  
  29.     /**
  30.     * Constructor.
  31.     */
  32.     function sloodle_view_controller()
  33.     {
  34.     }
  35.  
  36.     /**
  37.     * Uses the parent class to process basic request information, then obtains additional Controller data.
  38.     */
  39.     function process_request()
  40.     {
  41.         // Process basic data first
  42.         parent::process_request();
  43.         // Obtain the Controller-specific data
  44.         if (!$this->controller = get_record('sloodle_controller''sloodleid'$this->sloodle->id)) error('Failed to locate Controller data');
  45.     }
  46.  
  47.     /**
  48.     * Process any form data which has been submitted.
  49.     */
  50.     function process_form()
  51.     {
  52.     }
  53.  
  54.     /**
  55.     * Render the view of the Controller.
  56.     */
  57.     function render()
  58.     {
  59.         global $CFG;
  60.         
  61.         // Fetch the controller data
  62.         $this->controller = get_record('sloodle_controller''sloodleid'$this->sloodle->id);
  63.         if (!$this->controllerreturn false;
  64.         
  65.         // The name, type and description of the module should already be displayed by the main "view.php" script.
  66.         echo "<div style=\"text-align:center;\">\n";
  67.         
  68.         // Check if some kind of action has been requested
  69.         $action optional_param('action'''PARAM_TEXT);
  70.         
  71.         // Indicate whether or not this module is enabled
  72.         echo '<p style="font-size:14pt;">'.get_string('status''sloodle').': ';
  73.         if ($this->controller->enabled{
  74.             echo '<span style="color:green; font-weight:bold;">'.get_string('enabled','sloodle').'</span>';
  75.         else {
  76.             echo '<span style="color:red; font-weight:bold;">'.get_string('disabled','sloodle').'</span>';
  77.         }
  78.         echo "</p>\n";
  79.         
  80.         // Can the user access protected data?
  81.         if ($this->canedit{
  82.         
  83.             // Display a link to the configuration notecard page, as a popup window
  84.             print_box_start('generalbox boxaligncenter boxwidthwide');
  85.             echo '<h3>'.get_string('objectconfig:header''sloodle').'</h3>';
  86.             echo '<p>'.get_string('objectconfig:body''sloodle').'</p>';
  87.             
  88.             // Is Prim Password access available?
  89.             if (empty($this->controller->password)) {
  90.                 // No - display an error message
  91.                 echo '<span style="color:red; font-weight:bold;">'.get_string('objectconfig:noprimpassword','sloodle').'</span>';
  92.             else {
  93.                 print_string('objectconfig:select','sloodle');
  94.                 // Go through each installed type to produce our own array of objects.
  95.                 // (Our array will associate translated names and version numbers with complete object ID's).
  96.                 $objects array();
  97.                 $mods sloodle_get_installed_object_types();
  98.                 if (!$modserror('Error fetching installed object types.');
  99.                 
  100.                 foreach ($mods as $name => $versions{
  101.                     // Get the translated name
  102.                     $translatedname get_string("object:$name"'sloodle');
  103.                     // Reverse-sort the version
  104.                     $sortedversions $versions;
  105.                     krsort($sortedversions);
  106.                     foreach ($sortedversions as $v => $cfg{
  107.                         // Construct and store the complete object ID
  108.                         $objectid "$name-$v";
  109.                         $objects[$translatedname][$v$objectid;
  110.                     }
  111.                 }
  112.                 
  113.                 // Sort the objects by name
  114.                 ksort($objects);
  115.                 
  116.                 // Display our list of objects
  117.                 echo '<br><br><table style="text-align:left; margin-left:auto; margin-right:auto;">';
  118.                 foreach ($objects as $name => $versions{
  119.                     // The primary link will always be the latest version
  120.                     $num 0;
  121.                     echo '<tr><td>';
  122.                     $multipleversions (count($versions1);
  123.                     // Go through each version (this will be latest first)
  124.                     foreach ($versions as $v => $objectid{
  125.                         // Construct a link for this object's configuration
  126.                         $link SLOODLE_WWWROOT."/classroom/notecard_configuration_form.php?sloodlecontrollerid={$this->cm->id}&sloodleobjtype=$objectid";
  127.                     
  128.                         // Is this the latest version?
  129.                         if ($num == 0{
  130.                             // Yes - display the object name for the link
  131.                             echo "<span style=\"font-size:14pt;\"><a href=\"$link\">$name</a>";
  132.                         }
  133.                         // Do we have multiple versions available?
  134.                         if ($multipleversions{
  135.                             // Yes - add the version in brackets afterwards
  136.                             if ($num == 0echo ' <span style="font-size:11pt; font-style:italic;">[';
  137.                             else if ($num 0echo ', ';
  138.                             echo "<a href=\"$link\">$v</a>";
  139.                         }
  140.                         
  141.                         $num++;
  142.                     }
  143.                     
  144.                     // Close the extra versions section if necessary
  145.                     if ($multipleversionsecho "]</span>";
  146.                     echo "</td></tr>";
  147.                 }
  148.                 
  149.                 echo '</table>';
  150.             }
  151.  
  152.             print_box_end();
  153.             
  154.             // Active (authorised) objects
  155.             print_box_start('generalbox boxaligncenter boxwidthwide');
  156.             echo '<h3>'.get_string('authorizedobjects','sloodle').'</h3>';
  157.             
  158.             // Has a delete objects action been requested
  159.             if ($action == 'delete_objects'{
  160.                 
  161.                 // Count how many objects we delete
  162.                 $numdeleted 0;
  163.                 
  164.                 // Go through each request parameter
  165.                 foreach ($_REQUEST as $name => $val{
  166.                     // Is this a delete objects request?
  167.                     if ($val != 'true'continue;
  168.                     $parts explode('_'$name);
  169.                     if (count($parts== && $parts[0== 'sloodledeleteobj'{
  170.                         // Only delete the object if it belongs to this controller
  171.                         if (delete_records('sloodle_active_object''controllerid'$this->cm->id'id'(int)$parts[1])) {
  172.                             $numdeleted++;
  173.                             // Delete any associated configuration settings too
  174.                             delete_records('sloodle_object_config''object'(int)$parts[1]);
  175.                         }
  176.                         
  177.                     }
  178.                 }
  179.                 
  180.                 // Indicate our results
  181.                 echo '<span style="color:red; font-weight:bold;">'.get_string('numdeleted','sloodle').': '.$numdeleted.'</span><br><br>';
  182.             }
  183.             
  184.             // Get all objects authorised for this controller
  185.             $recs get_records('sloodle_active_object''controllerid'$this->cm->id'timeupdated DESC');
  186.             if (is_array($recs&& count($recs0{
  187.                 // Construct a table
  188.                 //TODO: add authorising user link
  189.                 $objects_table new stdClass();
  190.                 $objects_table->head array(get_string('objectname','sloodle'),get_string('objectuuid','sloodle'),get_string('objecttype','sloodle'),get_string('lastupdated','sloodle'),'');
  191.                 $objects_table->align array('left''left''left''left''center');
  192.                 foreach ($recs as $obj{
  193.                     // Skip this object if it has no type information
  194.                     if (empty($obj->type)) continue;
  195.                     // Construct a link to this object's configuration page
  196.                     $config_link "<a href=\"{$CFG->wwwroot}/mod/sloodle/classroom/configure_object.php?sloodleauthid={$obj->id}\">";
  197.                     $objects_table->data[array($config_link.$obj->name.'</a>'$obj->uuid$obj->typedate('Y-m-d H:i:s T'(int)$obj->timeupdated)"<input type=\"checkbox\" name=\"sloodledeleteobj_{$obj->id}\" value=\"true\" /");
  198.                 }
  199.                 
  200.                 // Display a form and the table
  201.                 echo '<form action="" method="POST">';
  202.                 echo '<input type="hidden" name="id" value="'.$this->cm->id.'"/>';
  203.                 echo '<input type="hidden" name="action" value="delete_objects"/>';
  204.                 
  205.                 print_table($objects_table);
  206.                 echo '<input type="submit" value="'.get_string('deleteselected','sloodle').'"/>';
  207.                 
  208.                 echo '</form>';
  209.                 
  210.             else {
  211.                 echo '<span style="text-align:center;color:red">'.get_string('noentries','sloodle').'</span><br>';
  212.             }
  213.             
  214.             print_box_end();
  215.         }
  216.         
  217.         echo "</div>\n"
  218.     }
  219.  
  220. }
  221.  
  222.  
  223. ?>

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