MDL-36594 Add function format_base::is_section_current()

- added function format_base::is_section_current()
- overwritten in format_weeks::is_section_current()
- deprecated function format_section_renderer_base::is_section_current()
This commit is contained in:
Marina Glancy 2012-11-14 15:54:13 +08:00
parent 1b2581f430
commit 081c8f7fe0
5 changed files with 50 additions and 25 deletions

View File

@ -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);
}
}
/**

View File

@ -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);
}
}

View File

@ -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 ===

View File

@ -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));
}
}

View File

@ -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));
}
}