MDL-33307 format_weeks - highlight current week
[moodle.git] / course / format / weeks / renderer.php
CommitLineData
1804b7c1
DP
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Renderer for outputting the weeks course format.
19 *
20 * @package format_weeks
21 * @copyright 2012 Dan Poltawski
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @since Moodle 2.3
24 */
25
26
27defined('MOODLE_INTERNAL') || die();
28require_once($CFG->dirroot.'/course/format/renderer.php');
29
30
31/**
32 * Basic renderer for weeks format.
33 *
34 * @copyright 2012 Dan Poltawski
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
a8f02a34 37class format_weeks_renderer extends format_section_renderer_base {
1804b7c1
DP
38 /**
39 * Generate the starting container html for a list of sections
40 * @return string HTML to output.
41 */
cbf44997 42 protected function start_section_list() {
1804b7c1
DP
43 return html_writer::start_tag('ul', array('class' => 'weeks'));
44 }
45
46 /**
47 * Generate the closing container html for a list of sections
48 * @return string HTML to output.
49 */
cbf44997 50 protected function end_section_list() {
1804b7c1
DP
51 return html_writer::end_tag('ul');
52 }
53
54 /**
55 * Generate the title for this section page
56 * @return string the page title
57 */
cbf44997 58 protected function page_title() {
1804b7c1
DP
59 return get_string('weeklyoutline');
60 }
2ea6533a
DP
61
62 /**
63 * Is the section passed in the current section?
64 *
65 * @param stdClass $course The course entry from DB
66 * @param stdClass $section The course_section entry from the DB
67 * @return bool true if the section is current
68 */
69 protected function is_section_current($section, $course) {
70 if ($section->section < 1) {
71 return false;
72 }
73 $oneweekseconds = 604800;
74 $startdate = $course->startdate + ($oneweekseconds * ($section->section - 1));
75 $enddate = $startdate + $oneweekseconds;
76
77 $timenow = time();
78
79 return (($timenow >= $startdate) && ($timenow < $enddate));
80 }
1804b7c1 81}