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
17require_once('../../config.php');
18require_once('lib.php');
19
20$id = required_param('id', PARAM_INT);   // Course.
21
22$PAGE->set_url('/mod/chat/index.php', array('id' => $id));
23
24if (! $course = $DB->get_record('course', array('id' => $id))) {
25    print_error('invalidcourseid');
26}
27
28require_course_login($course);
29$PAGE->set_pagelayout('incourse');
30
31$params = array(
32    'context' => context_course::instance($id)
33);
34$event = \mod_chat\event\course_module_instance_list_viewed::create($params);
35$event->add_record_snapshot('course', $course);
36$event->trigger();
37
38// Get all required strings.
39$strchats = get_string('modulenameplural', 'chat');
40$strchat  = get_string('modulename', 'chat');
41
42// Print the header.
43$PAGE->navbar->add($strchats);
44$PAGE->set_title($strchats);
45$PAGE->set_heading($course->fullname);
46echo $OUTPUT->header();
47echo $OUTPUT->heading($strchats, 2);
48
49// Get all the appropriate data.
50if (! $chats = get_all_instances_in_course('chat', $course)) {
51    notice(get_string('thereareno', 'moodle', $strchats), "../../course/view.php?id=$course->id");
52    die();
53}
54
55$usesections = course_format_uses_sections($course->format);
56
57// Print the list of instances (your module will probably extend this).
58
59$timenow  = time();
60$strname  = get_string('name');
61
62$table = new html_table();
63
64if ($usesections) {
65    $strsectionname = get_string('sectionname', 'format_'.$course->format);
66    $table->head  = array ($strsectionname, $strname);
67    $table->align = array ('center', 'left');
68} else {
69    $table->head  = array ($strname);
70    $table->align = array ('left');
71}
72
73$currentsection = '';
74foreach ($chats as $chat) {
75    if (!$chat->visible) {
76        // Show dimmed if the mod is hidden.
77        $link = "<a class=\"dimmed\" href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name, true)."</a>";
78    } else {
79        // Show normal if the mod is visible.
80        $link = "<a href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name, true)."</a>";
81    }
82    $printsection = '';
83    if ($chat->section !== $currentsection) {
84        if ($chat->section) {
85            $printsection = get_section_name($course, $chat->section);
86        }
87        if ($currentsection !== '') {
88            $table->data[] = 'hr';
89        }
90        $currentsection = $chat->section;
91    }
92    if ($usesections) {
93        $table->data[] = array ($printsection, $link);
94    } else {
95        $table->data[] = array ($link);
96    }
97}
98
99echo '<br />';
100
101echo html_writer::table($table);
102
103// Finish the page.
104
105echo $OUTPUT->footer();
106
107