function callback_weeks_get_section_name($course, $section) {
// We can't add a node without text
if (!empty($section->name)) {
- // Return the name the user set
- return format_string($section->name, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ // Return the name the user set.
+ return format_string($section->name, true, array('context' => context_course::instance($course->id)));
} else if ($section->section == 0) {
- // Return the section0name
+ // Return the general section.
return get_string('section0name', 'format_weeks');
} else {
- // Got to work out the date of the week so that we can show it
- $sections = get_all_sections($course->id);
- $weekdate = $course->startdate+7200;
- foreach ($sections as $sec) {
- if ($sec->id == $section->id) {
- break;
- } else if ($sec->section != 0) {
- $weekdate += 604800;
- }
- }
- $strftimedateshort = ' '.get_string('strftimedateshort');
- $weekday = userdate($weekdate, $strftimedateshort);
- $endweekday = userdate($weekdate+518400, $strftimedateshort);
+ $dates = format_weeks_get_section_dates($section, $course);
+
+ // We subtract 24 hours for display purposes.
+ $dates->end = ($dates->end - 86400);
+
+ $dateformat = ' '.get_string('strftimedateshort');
+ $weekday = userdate($dates->start, $dateformat);
+ $endweekday = userdate($dates->end, $dateformat);
return $weekday.' - '.$endweekday;
}
}
$ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0);
return $ajaxsupport;
}
+
+/**
+ * Return the start and end date of the passed section
+ *
+ * @param stdClass $section The course_section entry from the DB
+ * @param stdClass $course The course entry from DB
+ * @return stdClass property start for startdate, property end for enddate
+ */
+function format_weeks_get_section_dates($section, $course) {
+ $oneweekseconds = 604800;
+ // Hack alert. We add 2 hours to avoid possible DST problems. (e.g. we go into daylight
+ // savings and the date changes.
+ $startdate = $course->startdate + 7200;
+
+ $dates = new stdClass();
+ $dates->start = $startdate + ($oneweekseconds * ($section->section - 1));
+ $dates->end = $dates->start + $oneweekseconds;
+
+ return $dates;
+}
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/course/format/renderer.php');
+require_once($CFG->dirroot.'/course/format/weeks/lib.php');
/**
/**
* Is the section passed in the current section?
*
- * @param stdClass $course The course entry from DB
* @param stdClass $section The course_section entry from the DB
+ * @param stdClass $course The course entry from DB
* @return bool true if the section is current
*/
protected function is_section_current($section, $course) {
if ($section->section < 1) {
return false;
}
- $oneweekseconds = 604800;
- $startdate = $course->startdate + ($oneweekseconds * ($section->section - 1));
- $enddate = $startdate + $oneweekseconds;
$timenow = time();
+ $dates = format_weeks_get_section_dates($section, $course);
- return (($timenow >= $startdate) && ($timenow < $enddate));
+ return (($timenow >= $dates->start) && ($timenow < $dates->end));
}
}