MDL-36482 activities block: Allow mod display without intro's
[moodle.git] / course / resources.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 resource type modules in course
20 *
aa6c1ced 21 * @package moodlecore
aa54ed7b 22 * @copyright 2009 Petr Skoda (http://skodak.org)
aa6c1ced 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
aa54ed7b 24 */
25
26require_once('../config.php');
27require_once("$CFG->libdir/resourcelib.php");
28
29$id = required_param('id', PARAM_INT); // course id
30
31$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
7487c856 32$PAGE->set_pagelayout('course');
aa54ed7b 33require_course_login($course, true);
34
35// get list of all resource-like modules
36$allmodules = $DB->get_records('modules', array('visible'=>1));
37$modules = array();
38foreach ($allmodules as $key=>$module) {
39 $modname = $module->name;
40 $libfile = "$CFG->dirroot/mod/$modname/lib.php";
41 if (!file_exists($libfile)) {
42 continue;
43 }
44 $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
45 if ($archetype != MOD_ARCHETYPE_RESOURCE) {
46 continue;
47 }
48
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", '');
52}
53
54$strresources = get_string('resources');
7487c856 55$strsectionname = get_string('sectionname', 'format_'.$course->format);
aa54ed7b 56$strname = get_string('name');
57$strintro = get_string('moduleintro');
58$strlastmodified = get_string('lastmodified');
59
a6855934 60$PAGE->set_url('/course/resources.php', array('id' => $course->id));
aa54ed7b 61$PAGE->set_title($course->shortname.': '.$strresources);
62$PAGE->set_heading($course->fullname);
3856ca56 63$PAGE->navbar->add($strresources);
64echo $OUTPUT->header();
aa54ed7b 65
66$modinfo = get_fast_modinfo($course);
7487c856
SH
67$usesections = course_format_uses_sections($course->format);
68if ($usesections) {
69 $sections = get_all_sections($course->id);
70}
aa54ed7b 71$cms = array();
72$resources = array();
73foreach ($modinfo->cms as $cm) {
74 if (!$cm->uservisible) {
75 continue;
76 }
77 if (!array_key_exists($cm->modname, $modules)) {
78 continue;
79 }
0d8b6a69 80 if (!$cm->has_view()) {
81 // Exclude label and similar
82 continue;
83 }
aa54ed7b 84 $cms[$cm->id] = $cm;
85 $resources[$cm->modname][] = $cm->instance;
86}
87
88// preload instances
89foreach ($resources as $modname=>$instances) {
9dc1f685
RS
90 $additionalfields = '';
91 if (plugin_supports('mod', $modname, FEATURE_MOD_INTRO)) {
92 $additionalfields = ',intro,introformat';
93 }
94 $resources[$modname] = $DB->get_records_list($modname, 'id', $instances, 'id', 'id,name'.$additionalfields);
aa54ed7b 95}
96
97if (!$cms) {
98 notice(get_string('thereareno', 'moodle', $strresources), "$CFG->wwwroot/course/view.php?id=$course->id");
99 exit;
100}
101
102$table = new html_table();
16be8974 103$table->attributes['class'] = 'generaltable mod_index';
aa54ed7b 104
7487c856
SH
105if ($usesections) {
106 $table->head = array ($strsectionname, $strname, $strintro);
aa54ed7b 107 $table->align = array ('center', 'left', 'left');
108} else {
109 $table->head = array ($strlastmodified, $strname, $strintro);
110 $table->align = array ('left', 'left', 'left');
111}
112
113$currentsection = '';
114foreach ($cms as $cm) {
115 if (!isset($resources[$cm->modname][$cm->instance])) {
116 continue;
117 }
118 $resource = $resources[$cm->modname][$cm->instance];
9dc1f685 119 $printsection = '';
7487c856 120 if ($usesections) {
aa54ed7b 121 if ($cm->sectionnum !== $currentsection) {
122 if ($cm->sectionnum) {
7487c856 123 $printsection = get_section_name($course, $sections[$cm->sectionnum]);
aa54ed7b 124 }
125 if ($currentsection !== '') {
126 $table->data[] = 'hr';
127 }
128 $currentsection = $cm->sectionnum;
129 }
aa54ed7b 130 }
131
132 $extra = empty($cm->extra) ? '' : $cm->extra;
133 if (!empty($cm->icon)) {
3aa11c75 134 $icon = '<img src="'.$OUTPUT->pix_url($cm->icon).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
aa54ed7b 135 } else {
3aa11c75 136 $icon = '<img src="'.$OUTPUT->pix_url('icon', $cm->modname).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
aa54ed7b 137 }
138
9dc1f685
RS
139 if (isset($cm->intro) && isset($cm->introformat)) {
140 $intro = format_module_intro('resource', $resource, $cm->id);
141 } else {
142 $intro = '';
143 }
144
aa54ed7b 145 $class = $cm->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
146 $table->data[] = array (
147 $printsection,
148 "<a $class $extra href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id\">".$icon.format_string($resource->name)."</a>",
9dc1f685 149 $intro);
aa54ed7b 150}
151
16be8974 152echo html_writer::table($table);
aa54ed7b 153
154echo $OUTPUT->footer();