weekly release 4.2.1+
[moodle.git] / mod / h5pactivity / index.php
blobf72fb4b7cdfd0d3418f648f2c45a58db002ccd9e
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.
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/>.
17 /**
18 * Display information about all the mod_h5pactivity modules in the requested course.
20 * @package mod_h5pactivity
21 * @copyright 2020 Ferran Recio <ferran@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require(__DIR__.'/../../config.php');
26 require_once(__DIR__.'/lib.php');
28 $id = required_param('id', PARAM_INT);
30 $course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST);
31 require_course_login($course);
33 $coursecontext = context_course::instance($course->id);
35 $event = \mod_h5pactivity\event\course_module_instance_list_viewed::create(['context' => $coursecontext]);
36 $event->add_record_snapshot('course', $course);
37 $event->trigger();
39 $PAGE->set_url('/mod/h5pactivity/index.php', ['id' => $id]);
40 $PAGE->set_title(format_string($course->fullname));
41 $PAGE->set_heading(format_string($course->fullname));
42 $PAGE->set_context($coursecontext);
44 echo $OUTPUT->header();
46 $modulenameplural = get_string('modulenameplural', 'mod_h5pactivity');
47 echo $OUTPUT->heading($modulenameplural);
49 $h5pactivities = get_all_instances_in_course('h5pactivity', $course);
51 if (empty($h5pactivities)) {
52 notice(get_string('thereareno', 'moodle'), new moodle_url('/course/view.php', ['id' => $course->id]));
53 exit;
56 $table = new html_table();
57 $table->attributes['class'] = 'generaltable mod_index';
59 $align = ['center', 'left'];
60 if ($course->format == 'weeks') {
61 $table->head = [get_string('week'), get_string('name')];
62 $table->align = ['center', 'left'];
63 } else if ($course->format == 'topics') {
64 $table->head = [get_string('topic'), get_string('name')];
65 $table->align = ['center', 'left'];
66 } else {
67 $table->head = [get_string('name')];
68 $table->align = ['left'];
71 foreach ($h5pactivities as $h5pactivity) {
72 $attributes = [];
73 if (!$h5pactivity->visible) {
74 $attributes['class'] = 'dimmed';
76 $link = html_writer::link(
77 new moodle_url('/mod/h5pactivity/view.php', ['id' => $h5pactivity->coursemodule]),
78 format_string($h5pactivity->name, true),
79 $attributes);
81 if ($course->format == 'weeks' or $course->format == 'topics') {
82 $table->data[] = [$h5pactivity->section, $link];
83 } else {
84 $table->data[] = [$link];
88 echo html_writer::table($table);
89 echo $OUTPUT->footer();