MDL-50015 mod_imscp: New WS mod_imscp_view_imscp
[moodle.git] / mod / imscp / index.php
CommitLineData
2ff648fb 1<?php
2ff648fb 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
17/**
18 * List of file imscps in course
19 *
35501c37 20 * @package mod_imscp
3b43615f
PS
21 * @copyright 2009 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2ff648fb 23 */
24
25require('../../config.php');
26
218ab060 27$id = required_param('id', PARAM_INT); // Course id.
2ff648fb 28
218ab060 29$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
2ff648fb 30
31require_course_login($course, true);
191b267b 32$PAGE->set_pagelayout('incourse');
2ff648fb 33
a2a7726f
MN
34$params = array(
35 'context' => context_course::instance($course->id)
36);
37$event = \mod_imscp\event\course_module_instance_list_viewed::create($params);
38$event->trigger();
2ff648fb 39
40$strimscp = get_string('modulename', 'imscp');
41$strimscps = get_string('modulenameplural', 'imscp');
2ff648fb 42$strname = get_string('name');
43$strintro = get_string('moduleintro');
44$strlastmodified = get_string('lastmodified');
45
a6855934 46$PAGE->set_url('/mod/imscp/index.php', array('id' => $course->id));
2ff648fb 47$PAGE->set_title($course->shortname.': '.$strimscps);
48$PAGE->set_heading($course->fullname);
44391f9f 49$PAGE->navbar->add($strimscps);
50echo $OUTPUT->header();
43601cdf 51echo $OUTPUT->heading($strimscps);
2ff648fb 52
53if (!$imscps = get_all_instances_in_course('imscp', $course)) {
54 notice(get_string('thereareno', 'moodle', $strimscps), "$CFG->wwwroot/course/view.php?id=$course->id");
55 exit;
56}
57
7487c856 58$usesections = course_format_uses_sections($course->format);
7487c856 59
2ff648fb 60$table = new html_table();
16be8974 61$table->attributes['class'] = 'generaltable mod_index';
2ff648fb 62
7487c856 63if ($usesections) {
09af1e28 64 $strsectionname = get_string('sectionname', 'format_'.$course->format);
7487c856 65 $table->head = array ($strsectionname, $strname, $strintro);
2ff648fb 66 $table->align = array ('center', 'left', 'left');
67} else {
68 $table->head = array ($strlastmodified, $strname, $strintro);
69 $table->align = array ('left', 'left', 'left');
70}
71
72$modinfo = get_fast_modinfo($course);
73$currentsection = '';
74foreach ($imscps as $imscp) {
75 $cm = $modinfo->cms[$imscp->coursemodule];
7487c856 76 if ($usesections) {
2ff648fb 77 $printsection = '';
78 if ($imscp->section !== $currentsection) {
79 if ($imscp->section) {
71a56e08 80 $printsection = get_section_name($course, $imscp->section);
2ff648fb 81 }
82 if ($currentsection !== '') {
83 $table->data[] = 'hr';
84 }
85 $currentsection = $imscp->section;
86 }
87 } else {
88 $printsection = '<span class="smallinfo">'.userdate($imscp->timemodified)."</span>";
89 }
90
218ab060 91 $class = $imscp->visible ? '' : 'class="dimmed"'; // Hidden modules are dimmed.
2ff648fb 92 $table->data[] = array (
93 $printsection,
218ab060 94 "<a $class href=\"view.php?id=$cm->id\">" . format_string($imscp->name)."</a>",
2ff648fb 95 format_module_intro('imscp', $imscp, $cm->id));
96}
97
16be8974 98echo html_writer::table($table);
2ff648fb 99
100echo $OUTPUT->footer();