3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * This page lists all the instances of lesson in a particular course
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 /** Include required files */
27 require_once("../../config.php");
28 require_once($CFG->dirroot
.'/mod/lesson/locallib.php');
30 $id = required_param('id', PARAM_INT
); // course
32 $PAGE->set_url('/mod/lesson/index.php', array('id'=>$id));
34 if (!$course = $DB->get_record("course", array("id" => $id))) {
35 print_error('invalidcourseid');
38 require_login($course);
39 $PAGE->set_pagelayout('incourse');
41 // Trigger instances list viewed event.
43 'context' => context_course
::instance($course->id
)
45 $event = \mod_lesson\event\course_module_instance_list_viewed
::create($params);
46 $event->add_record_snapshot('course', $course);
49 /// Get all required strings
51 $strlessons = get_string("modulenameplural", "lesson");
52 $strlesson = get_string("modulename", "lesson");
56 $PAGE->navbar
->add($strlessons);
57 $PAGE->set_title("$course->shortname: $strlessons");
58 $PAGE->set_heading($course->fullname
);
59 echo $OUTPUT->header();
60 echo $OUTPUT->heading($strlessons, 2);
62 /// Get all the appropriate data
64 if (! $lessons = get_all_instances_in_course("lesson", $course)) {
65 notice(get_string('thereareno', 'moodle', $strlessons), "../../course/view.php?id=$course->id");
69 $usesections = course_format_uses_sections($course->format
);
71 /// Print the list of instances (your module will probably extend this)
74 $strname = get_string("name");
75 $strgrade = get_string("grade");
76 $strdeadline = get_string("deadline", "lesson");
77 $strnodeadline = get_string("nodeadline", "lesson");
78 $table = new html_table();
81 $strsectionname = get_string('sectionname', 'format_'.$course->format
);
82 $table->head
= array ($strsectionname, $strname, $strgrade, $strdeadline);
83 $table->align
= array ("center", "left", "center", "center");
85 $table->head
= array ($strname, $strgrade, $strdeadline);
86 $table->align
= array ("left", "center", "center");
89 $deadlines = lesson_get_user_deadline($course->id
);
90 foreach ($lessons as $lesson) {
91 $cm = get_coursemodule_from_instance('lesson', $lesson->id
);
92 $context = context_module
::instance($cm->id
);
94 $class = $lesson->visible ?
null : array('class' => 'dimmed'); // Hidden modules are dimmed.
95 $link = html_writer
::link(new moodle_url('view.php', array('id' => $cm->id
)), format_string($lesson->name
, true), $class);
97 $deadline = $deadlines[$lesson->id
]->userdeadline
;
99 $due = $strnodeadline;
100 } else if ($deadline > $timenow) {
101 $due = userdate($deadline);
103 $due = html_writer
::tag('span', userdate($deadline), array('class' => 'text-danger'));
107 if (has_capability('mod/lesson:manage', $context)) {
108 $grade_value = $lesson->grade
;
110 // it's a student, show their grade
112 if ($return = lesson_get_user_grades($lesson, $USER->id
)) {
113 $grade_value = $return[$USER->id
]->rawgrade
;
116 $table->data
[] = array (get_section_name($course, $lesson->section
), $link, $grade_value, $due);
118 $table->data
[] = array ($link, $lesson->grade
, $due);
121 echo html_writer
::table($table);
122 echo $OUTPUT->footer();