Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]
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 * 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 24 */ 25 26 require_once('../config.php'); 27 require_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); 32 $PAGE->set_pagelayout('incourse'); 33 require_course_login($course, true); 34 35 // get list of all resource-like modules 36 $allmodules = $DB->get_records('modules', array('visible'=>1)); 37 $availableresources = 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; 43 } 44 $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER); 45 if ($archetype != MOD_ARCHETYPE_RESOURCE) { 46 continue; 47 } 48 49 $availableresources[] = $modname; 50 } 51 52 // Triger view event. 53 $event = \core\event\course_resources_list_viewed::create(array('context' => context_course::instance($course->id))); 54 $event->add_record_snapshot('course', $course); 55 $event->trigger(); 56 57 $strresources = get_string('resources'); 58 $strname = get_string('name'); 59 $strintro = get_string('moduleintro'); 60 $strlastmodified = get_string('lastmodified'); 61 62 $PAGE->set_url('/course/resources.php', array('id' => $course->id)); 63 $PAGE->set_title($course->shortname.': '.$strresources); 64 $PAGE->set_heading($course->fullname); 65 $PAGE->navbar->add($strresources); 66 echo $OUTPUT->header(); 67 68 $modinfo = get_fast_modinfo($course); 69 $usesections = course_format_uses_sections($course->format); 70 $cms = array(); 71 $resources = array(); 72 foreach ($modinfo->cms as $cm) { 73 if (!in_array($cm->modname, $availableresources)) { 74 continue; 75 } 76 // Exclude activities that aren't visible or have no view link (e.g. label). Account for folder being displayed inline. 77 if (!$cm->uservisible || (!$cm->has_view() && strcmp($cm->modname, 'folder') !== 0)) { 78 continue; 79 } 80 $cms[$cm->id] = $cm; 81 $resources[$cm->modname][] = $cm->instance; 82 } 83 84 // preload instances 85 foreach ($resources as $modname=>$instances) { 86 $additionalfields = ''; 87 if (plugin_supports('mod', $modname, FEATURE_MOD_INTRO)) { 88 $additionalfields = ',intro,introformat'; 89 } 90 $resources[$modname] = $DB->get_records_list($modname, 'id', $instances, 'id', 'id,name'.$additionalfields); 91 } 92 93 if (!$cms) { 94 notice(get_string('thereareno', 'moodle', $strresources), "$CFG->wwwroot/course/view.php?id=$course->id"); 95 exit; 96 } 97 98 $table = new html_table(); 99 $table->attributes['class'] = 'generaltable mod_index'; 100 101 if ($usesections) { 102 $strsectionname = get_string('sectionname', 'format_'.$course->format); 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'); 108 } 109 110 $currentsection = ''; 111 foreach ($cms as $cm) { 112 if (!isset($resources[$cm->modname][$cm->instance])) { 113 continue; 114 } 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); 121 } 122 if ($currentsection !== '') { 123 $table->data[] = 'hr'; 124 } 125 $currentsection = $cm->sectionnum; 126 } 127 } 128 129 $extra = empty($cm->extra) ? '' : $cm->extra; 130 $icon = '<img src="'.$cm->get_icon_url().'" class="activityicon" alt="'.$cm->get_module_type_name().'" /> '; 131 132 if (isset($resource->intro) && isset($resource->introformat)) { 133 $intro = format_module_intro($cm->modname, $resource, $cm->id); 134 } else { 135 $intro = ''; 136 } 137 138 $class = $cm->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed 139 $url = $cm->url ?: new moodle_url("/mod/{$cm->modname}/view.php", ['id' => $cm->id]); 140 141 $table->data[] = array ( 142 $printsection, 143 "<a $class $extra href=\"" . $url ."\">" . $icon . $cm->get_formatted_name() . "</a>", 144 $intro); 145 } 146 147 echo html_writer::table($table); 148 149 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body