Skip to content

Commit

Permalink
MDL-33307 format_weeks - highlight current week
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed May 24, 2012
1 parent 5744ea3 commit 2ea6533
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
16 changes: 14 additions & 2 deletions course/format/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function section_left_content($section, $course, $onsectionpage) {

if ($section->section != 0) {
// Only in the non-general sections.
if ($course->marker == $section->section) {
if ($this->is_section_current($section, $course)) {
$o = get_accesshide(get_string('currentsection', 'format_'.$course->format));
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ protected function section_header($section, $course, $onsectionpage) {
// Only in the non-general sections.
if (!$section->visible) {
$sectionstyle = ' hidden';
} else if ($course->marker == $section->section) {
} else if ($this->is_section_current($section, $course)) {
$sectionstyle = ' current';
}
$linktitle = ($course->coursedisplay == COURSE_DISPLAY_MULTIPAGE);
Expand Down Expand Up @@ -669,4 +669,16 @@ protected function format_summary_text($section) {
$options->overflowdiv = true;
return format_text($summarytext, $section->summaryformat, $options);
}

/**
* Is the section passed in the current section? (Note this isn't strictly
* a renderering method, but neater here).
*
* @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);
}
}
20 changes: 20 additions & 0 deletions course/format/weeks/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,24 @@ protected function end_section_list() {
protected function page_title() {
return get_string('weeklyoutline');
}

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

return (($timenow >= $startdate) && ($timenow < $enddate));
}
}

0 comments on commit 2ea6533

Please sign in to comment.