Merge branch 'MDL-35644-MOODLE_22_STABLE' of git://github.com/mouneyrac/moodle into...
[moodle.git] / mod / resource / index.php
blobf3c516ca76d4077082f275befc186718ae91e895
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 * List of all resources in course
21 * @package mod
22 * @subpackage resource
23 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../../config.php');
29 $id = required_param('id', PARAM_INT); // course id
31 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
33 require_course_login($course, true);
34 $PAGE->set_pagelayout('incourse');
36 add_to_log($course->id, 'resource', 'view all', "index.php?id=$course->id", '');
38 $strresource = get_string('modulename', 'resource');
39 $strresources = get_string('modulenameplural', 'resource');
40 $strsectionname = get_string('sectionname', 'format_'.$course->format);
41 $strname = get_string('name');
42 $strintro = get_string('moduleintro');
43 $strlastmodified = get_string('lastmodified');
45 $PAGE->set_url('/mod/resource/index.php', array('id' => $course->id));
46 $PAGE->set_title($course->shortname.': '.$strresources);
47 $PAGE->set_heading($course->fullname);
48 $PAGE->navbar->add($strresources);
49 echo $OUTPUT->header();
51 if (!$resources = get_all_instances_in_course('resource', $course)) {
52 notice(get_string('thereareno', 'moodle', $strresources), "$CFG->wwwroot/course/view.php?id=$course->id");
53 exit;
56 $usesections = course_format_uses_sections($course->format);
57 if ($usesections) {
58 $sections = get_all_sections($course->id);
61 $table = new html_table();
62 $table->attributes['class'] = 'generaltable mod_index';
64 if ($usesections) {
65 $table->head = array ($strsectionname, $strname, $strintro);
66 $table->align = array ('center', 'left', 'left');
67 } else {
68 $table->head = array ($strlastmodified, $strname, $strintro);
69 $table->align = array ('left', 'left', 'left');
72 $modinfo = get_fast_modinfo($course);
73 $currentsection = '';
74 foreach ($resources as $resource) {
75 $cm = $modinfo->cms[$resource->coursemodule];
76 if ($usesections) {
77 $printsection = '';
78 if ($resource->section !== $currentsection) {
79 if ($resource->section) {
80 $printsection = get_section_name($course, $sections[$resource->section]);
82 if ($currentsection !== '') {
83 $table->data[] = 'hr';
85 $currentsection = $resource->section;
87 } else {
88 $printsection = '<span class="smallinfo">'.userdate($resource->timemodified)."</span>";
91 $extra = empty($cm->extra) ? '' : $cm->extra;
92 $icon = '';
93 if (!empty($cm->icon)) {
94 // each resource file has an icon in 2.0
95 $icon = '<img src="'.$OUTPUT->pix_url($cm->icon).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
98 $class = $resource->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
99 $table->data[] = array (
100 $printsection,
101 "<a $class $extra href=\"view.php?id=$cm->id\">".$icon.format_string($resource->name)."</a>",
102 format_module_intro('resource', $resource, $cm->id));
105 echo html_writer::table($table);
107 echo $OUTPUT->footer();