mirror of
https://github.com/moodle/moodle.git
synced 2025-03-12 19:54:08 +01:00
This commit: a) moves modinfo code into new library modinfolib.php b) uses classes instead of stdClass objects, allowing a huge amount of documentation (and IDE completion) c) adds hooks so that plugins other than forum can display messages like forum's 'unread', and plugins other than label can display html (apart from/as well as their view.php link) on the course view page d) removes current hacks for forum and label (mainly in print_section but also across the code), replacing with new 'content' and similar variables [this is the reason for the changes in blocks, etc] e) reduces size of modinfo in database (only when rebuilt) by excluding empty fields The change is intended to be backward compatible and does not affect the format of modinfo in database.
71 lines
2.4 KiB
PHP
71 lines
2.4 KiB
PHP
<?php
|
|
|
|
class block_activity_modules extends block_list {
|
|
function init() {
|
|
$this->title = get_string('pluginname', 'block_activity_modules');
|
|
}
|
|
|
|
function get_content() {
|
|
global $CFG, $DB, $OUTPUT;
|
|
|
|
if($this->content !== NULL) {
|
|
return $this->content;
|
|
}
|
|
|
|
$this->content = new stdClass;
|
|
$this->content->items = array();
|
|
$this->content->icons = array();
|
|
$this->content->footer = '';
|
|
|
|
$course = $this->page->course;
|
|
|
|
require_once($CFG->dirroot.'/course/lib.php');
|
|
|
|
$modinfo = get_fast_modinfo($course);
|
|
$modfullnames = array();
|
|
|
|
$archetypes = array();
|
|
|
|
foreach($modinfo->cms as $cm) {
|
|
// Exclude activities which are not visible or have no link (=label)
|
|
if (!$cm->uservisible or !$cm->has_view()) {
|
|
continue;
|
|
}
|
|
if (array_key_exists($cm->modname, $modfullnames)) {
|
|
continue;
|
|
}
|
|
if (!array_key_exists($cm->modname, $archetypes)) {
|
|
$archetypes[$cm->modname] = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
|
|
}
|
|
if ($archetypes[$cm->modname] == MOD_ARCHETYPE_RESOURCE) {
|
|
if (!array_key_exists('resources', $modfullnames)) {
|
|
$modfullnames['resources'] = get_string('resources');
|
|
}
|
|
} else {
|
|
$modfullnames[$cm->modname] = $cm->modplural;
|
|
}
|
|
}
|
|
|
|
textlib_get_instance()->asort($modfullnames);
|
|
|
|
foreach ($modfullnames as $modname => $modfullname) {
|
|
if ($modname === 'resources') {
|
|
$icon = '<img src="'.$OUTPUT->pix_url('f/html') . '" class="icon" alt="" /> ';
|
|
$this->content->items[] = '<a href="'.$CFG->wwwroot.'/course/resources.php?id='.$course->id.'">'.$icon.$modfullname.'</a>';
|
|
} else {
|
|
$icon = '<img src="'.$OUTPUT->pix_url('icon', $modname) . '" class="icon" alt="" /> ';
|
|
$this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$course->id.'">'.$icon.$modfullname.'</a>';
|
|
}
|
|
}
|
|
|
|
return $this->content;
|
|
}
|
|
|
|
function applicable_formats() {
|
|
return array('all' => true, 'mod' => false, 'my' => false, 'admin' => false,
|
|
'tag' => false);
|
|
}
|
|
}
|
|
|
|
|