Merge branch 'MDL-57282-master' of https://github.com/xow/moodle
[moodle.git] / blocks / activity_modules / block_activity_modules.php
blob37736a5eda94bc5c22cccfd8db6966a39f9edd6f
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This file contains the Activity modules block.
20 * @package block_activity_modules
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
26 require_once($CFG->libdir . '/filelib.php');
28 class block_activity_modules extends block_list {
29 function init() {
30 $this->title = get_string('pluginname', 'block_activity_modules');
33 function get_content() {
34 global $CFG, $DB, $OUTPUT;
36 if($this->content !== NULL) {
37 return $this->content;
40 $this->content = new stdClass;
41 $this->content->items = array();
42 $this->content->icons = array();
43 $this->content->footer = '';
45 $course = $this->page->course;
47 require_once($CFG->dirroot.'/course/lib.php');
49 $modinfo = get_fast_modinfo($course);
50 $modfullnames = array();
52 $archetypes = array();
54 foreach($modinfo->cms as $cm) {
55 // Exclude activities which are not visible or have no link (=label)
56 if (!$cm->uservisible or !$cm->has_view()) {
57 continue;
59 if (array_key_exists($cm->modname, $modfullnames)) {
60 continue;
62 if (!array_key_exists($cm->modname, $archetypes)) {
63 $archetypes[$cm->modname] = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
65 if ($archetypes[$cm->modname] == MOD_ARCHETYPE_RESOURCE) {
66 if (!array_key_exists('resources', $modfullnames)) {
67 $modfullnames['resources'] = get_string('resources');
69 } else {
70 $modfullnames[$cm->modname] = $cm->modplural;
74 core_collator::asort($modfullnames);
76 foreach ($modfullnames as $modname => $modfullname) {
77 if ($modname === 'resources') {
78 $icon = $OUTPUT->pix_icon('icon', '', 'mod_page', array('class' => 'icon'));
79 $this->content->items[] = '<a href="'.$CFG->wwwroot.'/course/resources.php?id='.$course->id.'">'.$icon.$modfullname.'</a>';
80 } else {
81 $icon = '<img src="'.$OUTPUT->pix_url('icon', $modname) . '" class="icon" alt="" />';
82 $this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$course->id.'">'.$icon.$modfullname.'</a>';
86 return $this->content;
89 /**
90 * Returns the role that best describes this blocks contents.
92 * This returns 'navigation' as the blocks contents is a list of links to activities and resources.
94 * @return string 'navigation'
96 public function get_aria_role() {
97 return 'navigation';
100 function applicable_formats() {
101 return array('all' => true, 'mod' => false, 'my' => false, 'admin' => false,
102 'tag' => false);