Source for file base_view_module.php

Documentation is available at base_view_module.php

  1. <?php
  2. /**
  3. * Defines a base class for viewing sub-types of the SLOODLE module, such as the Controller and the Distributor.
  4. * Class is inherited from the base view class, and should be further derived for module-specific functionality.
  5. * This simply provides a common framework for initially handling requests and displaying common header/footer.
  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 base view class */
  15. require_once(SLOODLE_DIRROOT.'/view/base/base_view.php');
  16. /** The SLOODLE course data structure */
  17. require_once(SLOODLE_LIBROOT.'/course.php');
  18.  
  19.  
  20. /**
  21. * The base class for viewing a SLOODLE module.
  22. * Should be inherited and overridden.
  23. * Child class MUST be named "sloodle_view_NAME", where NAME replaces the name of the feature or module.
  24. * For example, "sloodle_view_controller" or "sloodle_view_course".
  25. * For modules, the NAME must match the "type" specifier in the "sloodle" table, such as "controller", "distributor", or "presenter".
  26. @package sloodle
  27. */
  28. {
  29.     /**
  30.     * The course module instance, retrieved directly from the database (table: course_modules)
  31.     * @var object 
  32.     * @access private
  33.     */
  34.     var $cm = null;
  35.  
  36.     /**
  37.     * The main SLOODLE module instance, retreived directly from the database (table: sloodle)
  38.     * @var object 
  39.     * @access private
  40.     */
  41.     var $sloodle = null;
  42.  
  43.     /**
  44.     * The VLE course object, retrieved directly from the database (table: course)
  45.     * @var object 
  46.     * @access private
  47.     */
  48.     var $course = null;
  49.  
  50.     /**
  51.     * The SLOODLE course object.
  52.     * @var SloodleCourse 
  53.     * @access private
  54.     */
  55.     var $sloodle_course = null;
  56.  
  57.     /**
  58.     * Context object for permissions in the Moodle course.
  59.     * @var object 
  60.     * @access private
  61.     */
  62.     var $course_context = null;
  63.  
  64.     /**
  65.     * Context object for permissions in the Moodle module.
  66.     * @var object 
  67.     * @access private
  68.     */
  69.     var $module_context = null;
  70.  
  71.     /**
  72.     * Indicates whether or the user can edit (or 'manage') this module, according to the VLE permissions.
  73.     * @var bool 
  74.     * @access private
  75.     */
  76.     var $canedit = false;
  77.  
  78.  
  79.     /**
  80.     * Constructor.
  81.     */
  82.     function sloodle_base_view_module()
  83.     {
  84.     }
  85.  
  86.     /**
  87.     * Checks for incoming request data identifying a particular module (parameter 'id').
  88.     * Loads the relevant course module and SLOODLE module instances.
  89.     * This should be overridden to add functionality to load any module-specific data.
  90.     * However, you can simply call the parent function (i.e. this one) first to load the basic data.
  91.     */
  92.     function process_request()
  93.     {
  94.         // Note: some modules prefer 's' to indicate the instance number... may need to implement that as well.
  95.         // Fetch the course module instance
  96.         $id required_param('id'PARAM_INT);
  97.         if (!$this->cm = get_coursemodule_from_id('sloodle'$id)) error('Course module ID was incorrect.');
  98.         // Fetch the course data
  99.         if (!$this->course = get_record('course''id'$this->cm->course)) error('Failed to retrieve course.');
  100.         $this->sloodle_course = new SloodleCourse();
  101.         if (!$this->sloodle_course->load($this->course)) error(get_string('failedcourseload''sloodle'));
  102.  
  103.         // Fetch the SLOODLE instance itself
  104.         if (!$this->sloodle = get_record('sloodle''id'$this->cm->instance)) error('Failed to find SLOODLE module instance');
  105.     }
  106.  
  107.     /**
  108.     * Check that the user has permission to view this module, and check if they can edit it too.
  109.     */
  110.     function check_permission()
  111.     {
  112.         // Make sure the user is logged-in
  113.         require_course_login($this->coursetrue$this->cm);
  114.  
  115.         add_to_log($this->course->id'sloodle''view sloodle module'"view.php?id={$this->cm->id}""{$this->sloodle->id}"$this->cm->id);
  116.         
  117.         // Check for permissions
  118.         $this->module_context = get_context_instance(CONTEXT_MODULE$this->cm->id);
  119.         $this->course_context = get_context_instance(CONTEXT_COURSE$this->course->id);
  120.         if (has_capability('moodle/course:manageactivities'$this->module_context)) $this->canedit = true;
  121.  
  122.         // If the module is hidden, then can the user still view it?
  123.         if (empty($this->cm->visible&& !has_capability('moodle/course:viewhiddenactivities'$this->module_context)) notice(get_string('activityiscurrentlyhidden'));
  124.     }
  125.  
  126.     /**
  127.     * Process any form data which has been submitted.
  128.     */
  129.     function process_form()
  130.     {
  131.     }
  132.  
  133.     /**
  134.     * Print module header info.
  135.     */
  136.     function print_header()
  137.     {
  138.         global $CFG;
  139.  
  140.         // Offer the user an 'update' button if they are allowed to edit the module
  141.         $editbuttons '';
  142.         if ($this->canedit{
  143.             $editbuttons update_module_button($this->cm->id$this->course->idget_string('modulename''sloodle'));
  144.         }
  145.         // Display the header
  146.         $navigation "<a href=\"index.php?id={$this->course->id}\">".get_string('modulenameplural','sloodle')."</a> ->";
  147.         print_header_simple(format_string($this->sloodle->name)"""{$navigation} ".format_string($this->sloodle->name)""""true$editbuttonsnavmenu($this->course$this->cm));
  148.  
  149.         // Display the module name
  150.         $img '<img src="'.$CFG->wwwroot.'/mod/sloodle/icon.gif" width="16" height="16" alt=""/> ';
  151.         print_heading($img.$this->sloodle->name'center');
  152.     
  153.         // Display the module type and description
  154.         $fulltypename get_string("moduletype:{$this->sloodle->type}"'sloodle');
  155.         echo '<h4 style="text-align:center;">'.get_string('moduletype''sloodle').': '.$fulltypename;
  156.         echo helpbutton("moduletype_{$this->sloodle->type}"$fulltypename'sloodle'truefalse''true).'</h4>';
  157.         // We'll apply a general introduction to all Controllers, since they seem to confuse lots of people!
  158.         $intro $this->sloodle->intro;
  159.         if ($this->sloodle->type == SLOODLE_TYPE_CTRL$intro '<p style="font-style:italic;">'.get_string('controllerinfo','sloodle').'</p>' $this->sloodle->intro;
  160.         // Display the intro in a box, if we have an intro
  161.         if (!empty($intro)) print_box($intro'generalbox''intro');
  162.     
  163.     }
  164.  
  165.     /**
  166.     * Render the view of the module or feature.
  167.     * This MUST be overridden to provide functionality.
  168.     */
  169.     function render()
  170.     {
  171.     }
  172.  
  173.     /**
  174.     * Print the footer for this course.
  175.     */
  176.     function print_footer()
  177.     {
  178.         print_footer($this->course);
  179.     }
  180. }
  181.  
  182.  
  183. ?>

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