MDL-35770 Moved format_weeks_get_section_dates() to format_weeks::get_section_dates()
This commit is contained in:
+23
-19
@@ -56,8 +56,7 @@ class format_weeks extends format_base {
|
||||
// Return the general section.
|
||||
return get_string('section0name', 'format_weeks');
|
||||
} else {
|
||||
$course = $this->get_course();
|
||||
$dates = format_weeks_get_section_dates($section, $course);
|
||||
$dates = $this->get_section_dates($section);
|
||||
|
||||
// We subtract 24 hours for display purposes.
|
||||
$dates->end = ($dates->end - 86400);
|
||||
@@ -294,24 +293,29 @@ class format_weeks extends format_base {
|
||||
}
|
||||
return $this->update_format_options($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* Return the start and end date of the passed section
|
||||
*
|
||||
* @param int|stdClass|section_info $section section to get the dates for
|
||||
* @return stdClass property start for startdate, property end for enddate
|
||||
*/
|
||||
public function get_section_dates($section) {
|
||||
$course = $this->get_course();
|
||||
if (is_object($section)) {
|
||||
$sectionnum = $section->section;
|
||||
} else {
|
||||
$sectionnum = $section;
|
||||
}
|
||||
$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;
|
||||
$dates = new stdClass();
|
||||
$dates->start = $startdate + ($oneweekseconds * ($sectionnum - 1));
|
||||
$dates->end = $dates->start + $oneweekseconds;
|
||||
|
||||
return $dates;
|
||||
return $dates;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class format_weeks_renderer extends format_section_renderer_base {
|
||||
}
|
||||
|
||||
$timenow = time();
|
||||
$dates = format_weeks_get_section_dates($section, $course);
|
||||
$dates = course_get_format($course)->get_section_dates($section);
|
||||
|
||||
return (($timenow >= $dates->start) && ($timenow < $dates->end));
|
||||
}
|
||||
|
||||
@@ -3044,3 +3044,24 @@ function get_course_section($section, $courseid) {
|
||||
rebuild_course_cache($courseid, true);
|
||||
return $DB->get_record("course_sections", array("id"=>$id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the start and end date of the week in Weekly course format
|
||||
*
|
||||
* It is not recommended to use this function outside of format_weeks plugin
|
||||
*
|
||||
* @deprecated since 2.4
|
||||
* @see format_weeks::get_section_dates()
|
||||
*
|
||||
* @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) {
|
||||
debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
|
||||
' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
|
||||
if (isset($course->format) && $course->format === 'weeks') {
|
||||
return course_get_format($course)->get_section_dates($section);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user