Merge branch 'MDL-36754-master' of git://github.com/andrewnicols/moodle
[moodle.git] / mod / chat / index.php
blob41e2514784ea071b2730438bdbc3983f8b122406
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 require_once('../../config.php');
18 require_once('lib.php');
20 $id = required_param('id', PARAM_INT); // Course.
22 $PAGE->set_url('/mod/chat/index.php', array('id' => $id));
24 if (! $course = $DB->get_record('course', array('id' => $id))) {
25 print_error('invalidcourseid');
28 require_course_login($course);
29 $PAGE->set_pagelayout('incourse');
31 $params = array(
32 'context' => context_course::instance($id)
34 $event = \mod_chat\event\course_module_instance_list_viewed::create($params);
35 $event->add_record_snapshot('course', $course);
36 $event->trigger();
38 // Get all required strings.
39 $strchats = get_string('modulenameplural', 'chat');
40 $strchat = get_string('modulename', 'chat');
42 // Print the header.
43 $PAGE->navbar->add($strchats);
44 $PAGE->set_title($strchats);
45 $PAGE->set_heading($course->fullname);
46 echo $OUTPUT->header();
47 echo $OUTPUT->heading($strchats, 2);
49 // Get all the appropriate data.
50 if (! $chats = get_all_instances_in_course('chat', $course)) {
51 notice(get_string('thereareno', 'moodle', $strchats), "../../course/view.php?id=$course->id");
52 die();
55 $usesections = course_format_uses_sections($course->format);
57 // Print the list of instances (your module will probably extend this).
59 $timenow = time();
60 $strname = get_string('name');
62 $table = new html_table();
64 if ($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');
73 $currentsection = '';
74 foreach ($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>";
82 $printsection = '';
83 if ($chat->section !== $currentsection) {
84 if ($chat->section) {
85 $printsection = get_section_name($course, $chat->section);
87 if ($currentsection !== '') {
88 $table->data[] = 'hr';
90 $currentsection = $chat->section;
92 if ($usesections) {
93 $table->data[] = array ($printsection, $link);
94 } else {
95 $table->data[] = array ($link);
99 echo '<br />';
101 echo html_writer::table($table);
103 // Finish the page.
105 echo $OUTPUT->footer();