Merge branch 'MDL-74184' of https://github.com/timhunt/moodle
[moodle.git] / mod / wiki / index.php
blob8654658777fb5d116c848956ced3614e4ad4c38c
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 wiki in a particular course
21 * @package mod_wiki
22 * @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
23 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
25 * @author Jordi Piguillem
26 * @author Marc Alier
27 * @author David Jimenez
28 * @author Josep Arus
29 * @author Kenneth Riba
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 require_once('../../config.php');
35 require_once('lib.php');
37 $id = required_param('id', PARAM_INT); // course
38 $PAGE->set_url('/mod/wiki/index.php', array('id' => $id));
40 if (!$course = $DB->get_record('course', array('id' => $id))) {
41 print_error('invalidcourseid');
44 require_login($course, true);
45 $PAGE->set_pagelayout('incourse');
46 $context = context_course::instance($course->id);
48 $event = \mod_wiki\event\course_module_instance_list_viewed::create(array('context' => $context));
49 $event->add_record_snapshot('course', $course);
50 $event->trigger();
52 /// Get all required stringswiki
53 $strwikis = get_string("modulenameplural", "wiki");
54 $strwiki = get_string("modulename", "wiki");
56 /// Print the header
57 $PAGE->navbar->add($strwikis, "index.php?id=$course->id");
58 $PAGE->set_title($strwikis);
59 $PAGE->set_heading($course->fullname);
60 echo $OUTPUT->header();
61 echo $OUTPUT->heading($strwikis);
63 /// Get all the appropriate data
64 if (!$wikis = get_all_instances_in_course("wiki", $course)) {
65 notice("There are no wikis", "../../course/view.php?id=$course->id");
66 die;
69 $usesections = course_format_uses_sections($course->format);
71 /// Print the list of instances (your module will probably extend this)
73 $timenow = time();
74 $strname = get_string("name");
75 $table = new html_table();
77 if ($usesections) {
78 $strsectionname = get_string('sectionname', 'format_' . $course->format);
79 $table->head = array($strsectionname, $strname);
80 } else {
81 $table->head = array($strname);
84 foreach ($wikis as $wiki) {
85 $linkcss = null;
86 if (!$wiki->visible) {
87 $linkcss = array('class' => 'dimmed');
89 $link = html_writer::link(new moodle_url('/mod/wiki/view.php', array('id' => $wiki->coursemodule)), $wiki->name, $linkcss);
91 if ($usesections) {
92 $table->data[] = array(get_section_name($course, $wiki->section), $link);
93 } else {
94 $table->data[] = array($link);
98 echo html_writer::table($table);
100 /// Finish the page
101 echo $OUTPUT->footer();