3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * List of all resources in course
21 * @package mod_resource
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require('../../config.php');
28 $id = required_param('id', PARAM_INT
); // course id
30 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST
);
32 require_course_login($course, true);
33 $PAGE->set_pagelayout('incourse');
36 'context' => context_course
::instance($course->id
)
38 $event = \mod_resource\event\course_module_instance_list_viewed
::create($params);
39 $event->add_record_snapshot('course', $course);
42 $strresource = get_string('modulename', 'resource');
43 $strresources = get_string('modulenameplural', 'resource');
44 $strsectionname = get_string('sectionname', 'format_'.$course->format
);
45 $strname = get_string('name');
46 $strintro = get_string('moduleintro');
47 $strlastmodified = get_string('lastmodified');
49 $PAGE->set_url('/mod/resource/index.php', array('id' => $course->id
));
50 $PAGE->set_title($course->shortname
.': '.$strresources);
51 $PAGE->set_heading($course->fullname
);
52 $PAGE->navbar
->add($strresources);
53 echo $OUTPUT->header();
54 if (!$PAGE->has_secondary_navigation()) {
55 echo $OUTPUT->heading($strresources);
58 if (!$resources = get_all_instances_in_course('resource', $course)) {
59 notice(get_string('thereareno', 'moodle', $strresources), "$CFG->wwwroot/course/view.php?id=$course->id");
63 $usesections = course_format_uses_sections($course->format
);
65 $table = new html_table();
66 $table->attributes
['class'] = 'generaltable mod_index';
69 $table->head
= array ($strsectionname, $strname, $strintro);
70 $table->align
= array ('center', 'left', 'left');
72 $table->head
= array ($strlastmodified, $strname, $strintro);
73 $table->align
= array ('left', 'left', 'left');
76 $modinfo = get_fast_modinfo($course);
78 foreach ($resources as $resource) {
79 $cm = $modinfo->cms
[$resource->coursemodule
];
82 if ($resource->section
!== $currentsection) {
83 if ($resource->section
) {
84 $printsection = get_section_name($course, $resource->section
);
86 if ($currentsection !== '') {
87 $table->data
[] = 'hr';
89 $currentsection = $resource->section
;
92 $printsection = '<span class="smallinfo">'.userdate($resource->timemodified
)."</span>";
95 $extra = empty($cm->extra
) ?
'' : $cm->extra
;
97 if (!empty($cm->icon
)) {
98 // each resource file has an icon in 2.0
99 $icon = $OUTPUT->pix_icon($cm->icon
, get_string('modulename', $cm->modname
));
102 $class = $resource->visible ?
'' : 'class="dimmed"'; // hidden modules are dimmed
103 $table->data
[] = array (
105 "<a $class $extra href=\"view.php?id=$cm->id\">".$icon.format_string($resource->name
)."</a>",
106 format_module_intro('resource', $resource, $cm->id
));
109 echo html_writer
::table($table);
111 echo $OUTPUT->footer();