Merge branch '42316-26' of git://github.com/samhemelryk/moodle
[moodle.git] / mod / lesson / index.php
blob1f5093f6f1467d829865a1f68fb1ff4b214dd0f1
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * This page lists all the instances of lesson in a particular course
21 * @package mod
22 * @subpackage lesson
23 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 **/
27 /** Include required files */
28 require_once("../../config.php");
29 require_once($CFG->dirroot.'/mod/lesson/locallib.php');
31 $id = required_param('id', PARAM_INT); // course
33 $PAGE->set_url('/mod/lesson/index.php', array('id'=>$id));
35 if (!$course = $DB->get_record("course", array("id" => $id))) {
36 print_error('invalidcourseid');
39 require_login($course);
40 $PAGE->set_pagelayout('incourse');
42 add_to_log($course->id, "lesson", "view all", "index.php?id=$course->id", "");
45 /// Get all required strings
47 $strlessons = get_string("modulenameplural", "lesson");
48 $strlesson = get_string("modulename", "lesson");
51 /// Print the header
52 $PAGE->navbar->add($strlessons);
53 $PAGE->set_title("$course->shortname: $strlessons");
54 $PAGE->set_heading($course->fullname);
55 echo $OUTPUT->header();
56 echo $OUTPUT->heading($strlessons, 2);
58 /// Get all the appropriate data
60 if (! $lessons = get_all_instances_in_course("lesson", $course)) {
61 notice(get_string('thereareno', 'moodle', $strlessons), "../../course/view.php?id=$course->id");
62 die;
65 $usesections = course_format_uses_sections($course->format);
67 /// Print the list of instances (your module will probably extend this)
69 $timenow = time();
70 $strsectionname = get_string('sectionname', 'format_'.$course->format);
71 $strname = get_string("name");
72 $strgrade = get_string("grade");
73 $strdeadline = get_string("deadline", "lesson");
74 $strnodeadline = get_string("nodeadline", "lesson");
75 $table = new html_table();
77 if ($usesections) {
78 $table->head = array ($strsectionname, $strname, $strgrade, $strdeadline);
79 $table->align = array ("center", "left", "center", "center");
80 } else {
81 $table->head = array ($strname, $strgrade, $strdeadline);
82 $table->align = array ("left", "center", "center");
85 foreach ($lessons as $lesson) {
86 if (!$lesson->visible) {
87 //Show dimmed if the mod is hidden
88 $link = "<a class=\"dimmed\" href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
89 } else {
90 //Show normal if the mod is visible
91 $link = "<a href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
93 $cm = get_coursemodule_from_instance('lesson', $lesson->id);
94 $context = context_module::instance($cm->id);
96 if ($lesson->deadline == 0) {
97 $due = $strnodeadline;
98 } else if ($lesson->deadline > $timenow) {
99 $due = userdate($lesson->deadline);
100 } else {
101 $due = "<font color=\"red\">".userdate($lesson->deadline)."</font>";
104 if ($usesections) {
105 if (has_capability('mod/lesson:manage', $context)) {
106 $grade_value = $lesson->grade;
107 } else {
108 // it's a student, show their grade
109 $grade_value = 0;
110 if ($return = lesson_get_user_grades($lesson, $USER->id)) {
111 $grade_value = $return[$USER->id]->rawgrade;
114 $table->data[] = array (get_section_name($course, $lesson->section), $link, $grade_value, $due);
115 } else {
116 $table->data[] = array ($link, $lesson->grade, $due);
119 echo html_writer::table($table);
120 echo $OUTPUT->footer();