From 1b2581f43028ea14dab26aaebe1c4da60c882eff Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Wed, 14 Nov 2012 14:31:07 +0800 Subject: [PATCH 1/1] MDL-35770 Moved format_weeks_get_section_dates() to format_weeks::get_section_dates() --- course/format/weeks/lib.php | 42 +++++++++++++++++--------------- course/format/weeks/renderer.php | 2 +- lib/deprecatedlib.php | 21 ++++++++++++++++ 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/course/format/weeks/lib.php b/course/format/weeks/lib.php index 5864bfaa484..8c9a8ddac7f 100644 --- a/course/format/weeks/lib.php +++ b/course/format/weeks/lib.php @@ -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; + } } diff --git a/course/format/weeks/renderer.php b/course/format/weeks/renderer.php index e87936ccbf5..a3eb28fe15c 100644 --- a/course/format/weeks/renderer.php +++ b/course/format/weeks/renderer.php @@ -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)); } diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 1a2b205c15e..900b6e72b93 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -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; +} -- 2.43.0