MDL-37516 Conditional activities: user field condition display fixes
[moodle.git] / course / resources.php
blobd0235f54960364609e1d2847afb22aeb118bba74
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 resource type modules in course
21 * @package moodlecore
22 * @copyright 2009 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../config.php');
27 require_once("$CFG->libdir/resourcelib.php");
29 $id = required_param('id', PARAM_INT); // course id
31 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
32 $PAGE->set_pagelayout('course');
33 require_course_login($course, true);
35 // get list of all resource-like modules
36 $allmodules = $DB->get_records('modules', array('visible'=>1));
37 $modules = array();
38 foreach ($allmodules as $key=>$module) {
39 $modname = $module->name;
40 $libfile = "$CFG->dirroot/mod/$modname/lib.php";
41 if (!file_exists($libfile)) {
42 continue;
44 $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
45 if ($archetype != MOD_ARCHETYPE_RESOURCE) {
46 continue;
49 $modules[$modname] = get_string('modulename', $modname);
50 //some hacky nasic logging
51 add_to_log($course->id, $modname, 'view all', "index.php?id=$course->id", '');
54 $strresources = get_string('resources');
55 $strsectionname = get_string('sectionname', 'format_'.$course->format);
56 $strname = get_string('name');
57 $strintro = get_string('moduleintro');
58 $strlastmodified = get_string('lastmodified');
60 $PAGE->set_url('/course/resources.php', array('id' => $course->id));
61 $PAGE->set_title($course->shortname.': '.$strresources);
62 $PAGE->set_heading($course->fullname);
63 $PAGE->navbar->add($strresources);
64 echo $OUTPUT->header();
66 $modinfo = get_fast_modinfo($course);
67 $usesections = course_format_uses_sections($course->format);
68 $cms = array();
69 $resources = array();
70 foreach ($modinfo->cms as $cm) {
71 if (!$cm->uservisible) {
72 continue;
74 if (!array_key_exists($cm->modname, $modules)) {
75 continue;
77 if (!$cm->has_view()) {
78 // Exclude label and similar
79 continue;
81 $cms[$cm->id] = $cm;
82 $resources[$cm->modname][] = $cm->instance;
85 // preload instances
86 foreach ($resources as $modname=>$instances) {
87 $additionalfields = '';
88 if (plugin_supports('mod', $modname, FEATURE_MOD_INTRO)) {
89 $additionalfields = ',intro,introformat';
91 $resources[$modname] = $DB->get_records_list($modname, 'id', $instances, 'id', 'id,name'.$additionalfields);
94 if (!$cms) {
95 notice(get_string('thereareno', 'moodle', $strresources), "$CFG->wwwroot/course/view.php?id=$course->id");
96 exit;
99 $table = new html_table();
100 $table->attributes['class'] = 'generaltable mod_index';
102 if ($usesections) {
103 $table->head = array ($strsectionname, $strname, $strintro);
104 $table->align = array ('center', 'left', 'left');
105 } else {
106 $table->head = array ($strlastmodified, $strname, $strintro);
107 $table->align = array ('left', 'left', 'left');
110 $currentsection = '';
111 foreach ($cms as $cm) {
112 if (!isset($resources[$cm->modname][$cm->instance])) {
113 continue;
115 $resource = $resources[$cm->modname][$cm->instance];
116 $printsection = '';
117 if ($usesections) {
118 if ($cm->sectionnum !== $currentsection) {
119 if ($cm->sectionnum) {
120 $printsection = get_section_name($course, $cm->sectionnum);
122 if ($currentsection !== '') {
123 $table->data[] = 'hr';
125 $currentsection = $cm->sectionnum;
129 $extra = empty($cm->extra) ? '' : $cm->extra;
130 if (!empty($cm->icon)) {
131 $icon = '<img src="'.$OUTPUT->pix_url($cm->icon).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
132 } else {
133 $icon = '<img src="'.$OUTPUT->pix_url('icon', $cm->modname).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
136 if (isset($resource->intro) && isset($resource->introformat)) {
137 $intro = format_module_intro('resource', $resource, $cm->id);
138 } else {
139 $intro = '';
142 $class = $cm->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
143 $table->data[] = array (
144 $printsection,
145 "<a $class $extra href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id\">".$icon.format_string($resource->name)."</a>",
146 $intro);
149 echo html_writer::table($table);
151 echo $OUTPUT->footer();