2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * This file contains general functions for the course format Week
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * Indicates this format uses sections.
30 * @return bool Returns true
32 function callback_weeks_uses_sections() {
37 * Used to display the course structure for a course where format=weeks
39 * This is called automatically by {@link load_course()} if the current course
42 * @param navigation_node $navigation The course node
43 * @param array $path An array of keys to the course node
44 * @param stdClass $course The course we are loading the section for
46 function callback_weeks_load_content(&$navigation, $course, $coursenode) {
47 return $navigation->load_generic_course_sections($course, $coursenode, 'weeks');
51 * The string that is used to describe a section of the course
56 function callback_weeks_definition() {
57 return get_string('week');
61 * The GET argument variable that is used to identify the section being
62 * viewed by the user (if there is one)
66 function callback_weeks_request_key() {
71 * Gets the name for the provided section.
73 * @param stdClass $course
74 * @param stdClass $section
77 function callback_weeks_get_section_name($course, $section) {
78 // We can't add a node without text
79 if (!empty($section->name)) {
80 // Return the name the user set
81 return format_string($section->name, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
82 } else if ($section->section == 0) {
83 // Return the section0name
84 return get_string('section0name', 'format_weeks');
86 // Got to work out the date of the week so that we can show it
87 $sections = get_all_sections($course->id);
88 $weekdate = $course->startdate+7200;
89 foreach ($sections as $sec) {
90 if ($sec->id == $section->id) {
92 } else if ($sec->section != 0) {
96 $strftimedateshort = ' '.get_string('strftimedateshort');
97 $weekday = userdate($weekdate, $strftimedateshort);
98 $endweekday = userdate($weekdate+518400, $strftimedateshort);
99 return $weekday.' - '.$endweekday;
104 * Declares support for course AJAX features
106 * @see course_format_ajax_support()
109 function callback_weeks_ajax_support() {
110 $ajaxsupport = new stdClass();
111 $ajaxsupport->capable = true;
112 $ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0);
117 * Returns a URL to arrive directly at a section
119 * @param int $courseid The id of the course to get the link for
120 * @param int $sectionnum The section number to jump to
123 function callback_weeks_get_section_url($courseid, $sectionnum) {
124 return new moodle_url('/course/view.php', array('id' => $courseid, 'week' => $sectionnum));