base_view_module.php 6.6 KB

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