PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/taoresource/taoresource_base.class.php

https://github.com/nadavkav/MoodleTAO
PHP | 293 lines | 164 code | 55 blank | 74 comment | 30 complexity | a5887922a3327e274b35b92b6e6c1564 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @author Piers Harding piers@catalyst.net.nz
  5. * @version 0.0.1
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License, mod/taoresource is a work derived from Moodle mod/resoruce
  7. * @package taoresource
  8. *
  9. */
  10. /**
  11. * taoresource_base is the base class for taoresource types
  12. *
  13. * This class provides all the functionality for a taoresource
  14. */
  15. class taoresource_base {
  16. var $cm;
  17. var $course;
  18. var $taoresource;
  19. var $navlinks;
  20. /**
  21. * Constructor for the base taoresource class
  22. *
  23. * Constructor for the base taoresource class.
  24. * If cmid is set create the cm, course, taoresource objects.
  25. * and do some checks to make sure people can be here, and so on.
  26. *
  27. * @param cmid integer, the current course module id - not set for new taoresources
  28. * @param identifier hash, alternative direct identifier for a taoresource - not set for new taoresources
  29. */
  30. function taoresource_base($cmid=0, $identifier=false) {
  31. global $CFG, $COURSE;
  32. $this->navlinks = array();
  33. $this->inpopup = false;
  34. if ($cmid) {
  35. if (! $this->cm = get_coursemodule_from_id('taoresource', $cmid)) {
  36. error("Course Module ID was incorrect");
  37. }
  38. if (! $this->course = get_record("course", "id", $this->cm->course)) {
  39. error("Course is misconfigured");
  40. }
  41. if (! $this->taoresource = get_record("taoresource", "id", $this->cm->instance)) {
  42. error("TAO Resource ID was incorrect");
  43. }
  44. if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) {
  45. $pagetitle = strip_tags($this->course->shortname.': '.$this->strtaoresource);
  46. $navigation = build_navigation($this->navlinks, $this->cm);
  47. print_header($pagetitle, $this->course->fullname, $navigation, "", "", true, '', navmenu($this->course, $this->cm));
  48. notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
  49. }
  50. } else {
  51. $this->course = $COURSE;
  52. if ($identifier) {
  53. if (! $this->taoresource = get_record("taoresource_entry", "identifier", $identifier)) {
  54. error("TAO Resource ID was incorrect");
  55. }
  56. }
  57. }
  58. if (isset($this->taoresource) && !isset($this->taoresource->summary)) {
  59. $this->taoresource->summary = $this->taoresource->description;
  60. }
  61. $this->strtaoresource = get_string("modulename", "taoresource");
  62. $this->strtaoresources = get_string("modulenameplural", "taoresource");
  63. }
  64. /**
  65. * accessor for setting the display attribute for window popup
  66. */
  67. function inpopup() {
  68. $this->inpopup = true;
  69. }
  70. /**
  71. * Display function does nothing in the base class
  72. */
  73. function display() {
  74. }
  75. /**
  76. * Display the taoresource with the course blocks.
  77. */
  78. function display_course_blocks_start() {
  79. global $CFG;
  80. global $USER;
  81. global $THEME;
  82. require_once($CFG->libdir.'/blocklib.php');
  83. require_once($CFG->libdir.'/pagelib.php');
  84. require_once($CFG->dirroot.'/course/lib.php'); //required by some blocks
  85. $PAGE = page_create_object(PAGE_COURSE_VIEW, $this->course->id);
  86. $this->PAGE = $PAGE;
  87. $pageblocks = blocks_setup($PAGE);
  88. $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
  89. /// Print the page headings
  90. $edit = optional_param('edit', -1, PARAM_BOOL);
  91. if (($edit != -1) and $PAGE->user_allowed_editing()) {
  92. $USER->editing = $edit;
  93. }
  94. $morenavlinks = array($this->strtaoresources => 'index.php?id='.$this->course->id,
  95. $this->taoresource->name => '');
  96. $PAGE->print_header($this->course->shortname.': %fullname%', $morenavlinks, "", "",
  97. update_module_button($this->cm->id, $this->course->id, $this->strtaoresource));
  98. echo '<table id="layout-table"><tr>';
  99. $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
  100. foreach ($lt as $column) {
  101. $lt1[] = $column;
  102. if ($column == 'middle') break;
  103. }
  104. foreach ($lt1 as $column) {
  105. switch ($column) {
  106. case 'left':
  107. if((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
  108. echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
  109. print_container_start();
  110. blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
  111. print_container_end();
  112. echo '</td>';
  113. }
  114. break;
  115. case 'middle':
  116. echo '<td id="middle-column">';
  117. print_container_start(false, 'middle-column-wrap');
  118. echo '<div id="taoresource">';
  119. break;
  120. case 'right':
  121. if((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
  122. echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
  123. print_container_start();
  124. blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
  125. print_container_end();
  126. echo '</td>';
  127. }
  128. break;
  129. }
  130. }
  131. }
  132. /**
  133. * Finish displaying the taoresource with the course blocks
  134. */
  135. function display_course_blocks_end() {
  136. global $CFG;
  137. global $THEME;
  138. $PAGE = $this->PAGE;
  139. $pageblocks = blocks_setup($PAGE);
  140. $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
  141. $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
  142. foreach ($lt as $column) {
  143. if ($column != 'middle') {
  144. array_shift($lt);
  145. } else if ($column == 'middle') {
  146. break;
  147. }
  148. }
  149. foreach ($lt as $column) {
  150. switch ($column) {
  151. case 'left':
  152. if((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
  153. echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
  154. print_container_start();
  155. blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
  156. print_container_end();
  157. echo '</td>';
  158. }
  159. break;
  160. case 'middle':
  161. echo '</div>';
  162. print_container_end();
  163. echo '</td>';
  164. break;
  165. case 'right':
  166. if((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
  167. echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
  168. print_container_start();
  169. blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
  170. print_container_end();
  171. echo '</td>';
  172. }
  173. break;
  174. }
  175. }
  176. echo '</tr></table>';
  177. print_footer($this->course);
  178. }
  179. /**
  180. * Finish displaying the taoresource with the course blocks
  181. * Given an object containing all the necessary data,
  182. * (defined by the form in mod.html) this function
  183. * will create a new instance and return the id number
  184. * of the new instance.
  185. *
  186. * @param taoresource object, taoresource record values
  187. * @return int, taoresource id or false
  188. */
  189. function add_instance($taoresource) {
  190. $taoresource->timemodified = time();
  191. return insert_record("taoresource", $taoresource);
  192. }
  193. /**
  194. * Given an object containing all the necessary data,
  195. * (defined by the form in mod.html) this function
  196. * will update an existing instance with new data.
  197. *
  198. * @param taoresource object, taoresource record values
  199. * @return bool taoresource insert status
  200. */
  201. function update_instance($taoresource) {
  202. $taoresource->id = $taoresource->instance;
  203. $taoresource->timemodified = time();
  204. return update_record("taoresource", $taoresource);
  205. }
  206. /**
  207. * Given an object containing the taoresource data
  208. * this function will permanently delete the instance
  209. * and any data that depends on it.
  210. *
  211. * @param taoresource object, taoresource record values
  212. * @return bool taoresource delete status
  213. */
  214. function delete_instance($taoresource) {
  215. $result = true;
  216. if (! delete_records("taoresource", "id", "$taoresource->id")) {
  217. $result = false;
  218. }
  219. return $result;
  220. }
  221. /**
  222. * set up form elements for add/update of taoresource
  223. *
  224. * @param mform object, reference to Moodle Forms object
  225. */
  226. function setup_elements(&$mform) {
  227. //override to add your own options
  228. }
  229. /**
  230. * set up form element default values prior to display for add/update of taoresource
  231. *
  232. * @param default_values object, reference to form default values object
  233. */
  234. function setup_preprocessing(&$default_values){
  235. //override to add your own options
  236. }
  237. }
  238. ?>