lib.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Competence Graph
  18. *
  19. * Competence graph format allows the visualization of courses with competencies in a graph.
  20. * In the course structure, teacher associates activities to competencies. Each course module
  21. * can have restrictions between them, so a module is opened only when the student accomplish
  22. * its requirements. In student visualization, the structure of the course is presented as a
  23. * graph. In such graph, each node is a resource available to the student that can be handled.
  24. * Subgraphs in the main graph represent competences. As students can have different paths in
  25. * the course, the plugin registers all the steps that a student produces.
  26. *
  27. * @package course/format
  28. * @subpackage competencegraph
  29. * @version 0.1
  30. * @author Laboratório de Informática na Educação <http://www.usp.br/line>
  31. * @link http://www.usp.br/line/competencegraph
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  33. */
  34. defined('MOODLE_INTERNAL') || die();
  35. require_once($CFG->dirroot . '/course/format/lib.php'); // For format_base.
  36. class format_competencegraph extends format_base {
  37. // Used to determine the type of view URL to generate - parameter or anchor.
  38. private $coursedisplay = COURSE_DISPLAY_SINGLEPAGE;
  39. private $settings;
  40. public function __construct($format, $courseid) {
  41. if ($courseid === 0 || !is_numeric($courseid)) {
  42. global $COURSE;
  43. $courseid = $COURSE->id;
  44. }
  45. parent::__construct($format, $courseid);
  46. $section = optional_param('section', 0, PARAM_INT);
  47. if ($section) {
  48. $this->coursedisplay = COURSE_DISPLAY_MULTIPAGE;
  49. }
  50. }
  51. /**
  52. * Returns the format's settings and gets them if they do not exist.
  53. * @return type The settings as an array.
  54. */
  55. public function get_settings() {
  56. if (empty($this->settings) == true) {
  57. $this->settings = $this->get_format_options();
  58. }
  59. return $this->settings;
  60. }
  61. /**
  62. * Indicates this format uses sections.
  63. *
  64. * @return bool Returns false
  65. */
  66. public function uses_sections() {
  67. return false;
  68. }
  69. /**
  70. * The URL to use for the specified course (with section)
  71. *
  72. * @param int|stdClass $section Section object from database or just field course_sections.section
  73. * if omitted the course view page is returned
  74. * @param array $options options for view URL. At the moment core uses:
  75. * 'navigation' (bool) if true and section has no separate page, the function returns null
  76. * 'sr' (int) used by multipage formats to specify to which section to return
  77. * @return null|moodle_url
  78. */
  79. public function get_view_url($section, $options = array()) {
  80. $course = $this->get_course();
  81. $url = new moodle_url('/course/view.php', array('id' => $course->id));
  82. $sr = null;
  83. if (array_key_exists('sr', $options)) {
  84. $sr = $options['sr'];
  85. }
  86. if (is_object($section)) {
  87. $sectionno = $section->section;
  88. } else {
  89. $sectionno = $section;
  90. }
  91. if ($sectionno !== null) {
  92. if ($sr !== null) {
  93. if ($sr) {
  94. $usercoursedisplay = COURSE_DISPLAY_MULTIPAGE;
  95. $sectionno = $sr;
  96. } else {
  97. $usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
  98. }
  99. } else {
  100. $usercoursedisplay = $this->coursedisplay;
  101. }
  102. if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
  103. $url->param('section', $sectionno);
  104. } else {
  105. global $CFG;
  106. if (empty($CFG->linkcoursesections) && !empty($options['navigation'])) { // MDL-57412.
  107. return null;
  108. }
  109. $url->set_anchor('section-' . $sectionno);
  110. }
  111. }
  112. return $url;
  113. }
  114. /**
  115. * Returns the information about the ajax support in the given source format
  116. *
  117. * The returned object's property (boolean)capable indicates that
  118. * the course format supports Moodle course ajax features.
  119. * The property (array)testedbrowsers can be used as a parameter for {@link ajaxenabled()}.
  120. *
  121. * @return stdClass
  122. */
  123. public function supports_ajax() {
  124. $ajaxsupport = new stdClass();
  125. $ajaxsupport->capable = true;
  126. return $ajaxsupport;
  127. }
  128. /**
  129. * Returns the list of blocks to be automatically added for the newly created course
  130. *
  131. * @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT
  132. * each of values is an array of block names (for left and right side columns)
  133. */
  134. public function get_default_blocks() {
  135. return array(
  136. BLOCK_POS_LEFT => array(),
  137. BLOCK_POS_RIGHT => array('search_forums', 'news_items', 'calendar_upcoming', 'recent_activity')
  138. );
  139. }
  140. private function get_context() {
  141. global $SITE;
  142. if ($SITE->id == $this->courseid) {
  143. // Use the context of the page which should be the course category.
  144. global $PAGE;
  145. return $PAGE->context;
  146. } else {
  147. return context_course::instance($this->courseid);
  148. }
  149. }
  150. /**
  151. * Indicates whether the course format supports the creation of a news forum.
  152. *
  153. * @return bool
  154. */
  155. public function supports_news() {
  156. return true;
  157. }
  158. /**
  159. * Returns whether this course format allows the activity to
  160. * have "triple visibility state" - visible always, hidden on course page but available, hidden.
  161. *
  162. * @param stdClass|cm_info $cm course module (may be null if we are displaying a form for adding a module)
  163. * @param stdClass|section_info $section section where this module is located or will be added to
  164. * @return bool
  165. */
  166. public function allow_stealth_module_visibility($cm, $section) {
  167. // Allow the third visibility state inside visible sections or in section 0, not allow in orphaned sections.
  168. return !$section->section || ($section->visible && $section->section <= $this->get_course()->numsections);
  169. }
  170. }