diff --git a/course/format/lib.php b/course/format/lib.php index 7f6dfc99288..f0ccf9b1c0a 100644 --- a/course/format/lib.php +++ b/course/format/lib.php @@ -860,6 +860,23 @@ abstract class format_base { public function get_renderer(moodle_page $page) { return $page->get_renderer('format_'. $this->get_format()); } + + /** + * Returns true if the specified section is current + * + * By default we analyze $course->marker + * + * @param int|stdClass|section_info $section + * @return bool + */ + public function is_section_current($section) { + if (is_object($section)) { + $sectionnum = $section->section; + } else { + $sectionnum = $section; + } + return ($sectionnum && ($course = $this->get_course()) && $course->marker == $sectionnum); + } } /** diff --git a/course/format/renderer.php b/course/format/renderer.php index ea83ace3053..1856c624fb4 100644 --- a/course/format/renderer.php +++ b/course/format/renderer.php @@ -108,7 +108,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base { if ($section->section != 0) { // Only in the non-general sections. - if ($this->is_section_current($section, $course)) { + if (course_get_format($course)->is_section_current($section)) { $o = get_accesshide(get_string('currentsection', 'format_'.$course->format)); } } @@ -137,7 +137,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base { // Only in the non-general sections. if (!$section->visible) { $sectionstyle = ' hidden'; - } else if ($this->is_section_current($section, $course)) { + } else if (course_get_format($course)->is_section_current($section)) { $sectionstyle = ' current'; } } @@ -282,7 +282,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base { if (!$section->visible) { $classattr .= ' hidden'; $linkclasses .= ' dimmed_text'; - } else if ($this->is_section_current($section, $course)) { + } else if (course_get_format($course)->is_section_current($section)) { $classattr .= ' current'; } @@ -760,14 +760,18 @@ abstract class format_section_renderer_base extends plugin_renderer_base { } /** - * Is the section passed in the current section? (Note this isn't strictly - * a renderering method, but neater here). + * Is the section passed in the current section? + * + * @deprecated since 2.4 + * @see format_base::is_section_current() * * @param stdClass $course The course entry from DB * @param stdClass $section The course_section entry from the DB * @return bool true if the section is current */ - protected function is_section_current($section, $course) { - return ($course->marker == $section->section); + protected final function is_section_current($section, $course) { + debugging('Function format_section_renderer_base::is_section_current() is deprecated. '. + 'Use course_get_format($course)->is_section_current($section) instead', DEBUG_DEVELOPER); + return course_get_format($course)->is_section_current($section); } } diff --git a/course/format/upgrade.txt b/course/format/upgrade.txt index f14a8912052..4c5d1313cc3 100644 --- a/course/format/upgrade.txt +++ b/course/format/upgrade.txt @@ -13,6 +13,8 @@ format. * functions get_generic_section_name(), get_all_sections(), add_mod_to_section(), get_all_mods() are deprecated. See their phpdocs in lib/deprecatedlib.php on how to replace them * Course formats may now have their settings.php file as the most of other plugin types +* Function format_section_renderer_base::is_section_current() is deprecated, overwrite/use + function is_section_current in format class === 2.3 === diff --git a/course/format/weeks/lib.php b/course/format/weeks/lib.php index 8c9a8ddac7f..7c2dd9ba4f7 100644 --- a/course/format/weeks/lib.php +++ b/course/format/weeks/lib.php @@ -318,4 +318,24 @@ class format_weeks extends format_base { return $dates; } + + /** + * Returns true if the specified week is current + * + * @param int|stdClass|section_info $section + * @return bool + */ + public function is_section_current($section) { + if (is_object($section)) { + $sectionnum = $section->section; + } else { + $sectionnum = $section; + } + if ($sectionnum < 1) { + return false; + } + $timenow = time(); + $dates = $this->get_section_dates($section); + return (($timenow >= $dates->start) && ($timenow < $dates->end)); + } } diff --git a/course/format/weeks/renderer.php b/course/format/weeks/renderer.php index a3eb28fe15c..33590fdc87e 100644 --- a/course/format/weeks/renderer.php +++ b/course/format/weeks/renderer.php @@ -59,22 +59,4 @@ class format_weeks_renderer extends format_section_renderer_base { protected function page_title() { return get_string('weeklyoutline'); } - - /** - * Is the section passed in the current section? - * - * @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; - } - - $timenow = time(); - $dates = course_get_format($course)->get_section_dates($section); - - return (($timenow >= $dates->start) && ($timenow < $dates->end)); - } }