Merge branch 'MDL-61033-master' of https://github.com/nashtechdev01/moodle
[moodle.git] / mod / resource / index.php
CommitLineData
aa54ed7b 1<?php
2
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.
14//
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/>.
17
18/**
19 * List of all resources in course
20 *
11e41f1a 21 * @package mod_resource
702ab58c
PS
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
aa54ed7b 24 */
25
26require('../../config.php');
27
28$id = required_param('id', PARAM_INT); // course id
29
74df2951 30$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
aa54ed7b 31
32require_course_login($course, true);
191b267b 33$PAGE->set_pagelayout('incourse');
aa54ed7b 34
4a536604
RT
35$params = array(
36 'context' => context_course::instance($course->id)
37);
38$event = \mod_resource\event\course_module_instance_list_viewed::create($params);
1e242b41 39$event->add_record_snapshot('course', $course);
4a536604 40$event->trigger();
aa54ed7b 41
42$strresource = get_string('modulename', 'resource');
43$strresources = get_string('modulenameplural', 'resource');
7487c856 44$strsectionname = get_string('sectionname', 'format_'.$course->format);
aa54ed7b 45$strname = get_string('name');
46$strintro = get_string('moduleintro');
47$strlastmodified = get_string('lastmodified');
48
a6855934 49$PAGE->set_url('/mod/resource/index.php', array('id' => $course->id));
aa54ed7b 50$PAGE->set_title($course->shortname.': '.$strresources);
51$PAGE->set_heading($course->fullname);
ef8869c7 52$PAGE->navbar->add($strresources);
53echo $OUTPUT->header();
b25e7d85 54echo $OUTPUT->heading($strresources);
aa54ed7b 55
56if (!$resources = get_all_instances_in_course('resource', $course)) {
57 notice(get_string('thereareno', 'moodle', $strresources), "$CFG->wwwroot/course/view.php?id=$course->id");
58 exit;
59}
60
7487c856 61$usesections = course_format_uses_sections($course->format);
7487c856 62
aa54ed7b 63$table = new html_table();
16be8974 64$table->attributes['class'] = 'generaltable mod_index';
aa54ed7b 65
7487c856
SH
66if ($usesections) {
67 $table->head = array ($strsectionname, $strname, $strintro);
aa54ed7b 68 $table->align = array ('center', 'left', 'left');
69} else {
70 $table->head = array ($strlastmodified, $strname, $strintro);
71 $table->align = array ('left', 'left', 'left');
72}
73
74$modinfo = get_fast_modinfo($course);
75$currentsection = '';
76foreach ($resources as $resource) {
77 $cm = $modinfo->cms[$resource->coursemodule];
7487c856 78 if ($usesections) {
aa54ed7b 79 $printsection = '';
80 if ($resource->section !== $currentsection) {
81 if ($resource->section) {
71a56e08 82 $printsection = get_section_name($course, $resource->section);
2a439ba7 83 }
aa54ed7b 84 if ($currentsection !== '') {
85 $table->data[] = 'hr';
86 }
87 $currentsection = $resource->section;
81cdaada 88 }
aa54ed7b 89 } else {
90 $printsection = '<span class="smallinfo">'.userdate($resource->timemodified)."</span>";
2a439ba7 91 }
92
aa54ed7b 93 $extra = empty($cm->extra) ? '' : $cm->extra;
94 $icon = '';
95 if (!empty($cm->icon)) {
96 // each resource file has an icon in 2.0
663640f5 97 $icon = $OUTPUT->pix_icon($cm->icon, get_string('modulename', $cm->modname));
aa54ed7b 98 }
2a439ba7 99
aa54ed7b 100 $class = $resource->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
101 $table->data[] = array (
102 $printsection,
103 "<a $class $extra href=\"view.php?id=$cm->id\">".$icon.format_string($resource->name)."</a>",
104 format_module_intro('resource', $resource, $cm->id));
105}
2a439ba7 106
16be8974 107echo html_writer::table($table);
73c24ef8 108
aa54ed7b 109echo $OUTPUT->footer();