block_activity_modules.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.
  13. //
  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/>.
  16. /**
  17. * This file contains the Activity modules block.
  18. *
  19. * @package block_activity_modules
  20. * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. require_once($CFG->libdir . '/filelib.php');
  25. class block_activity_modules extends block_list {
  26. function init() {
  27. $this->title = get_string('pluginname', 'block_activity_modules');
  28. }
  29. function get_content() {
  30. global $CFG, $DB, $OUTPUT;
  31. if($this->content !== NULL) {
  32. return $this->content;
  33. }
  34. $this->content = new stdClass;
  35. $this->content->items = array();
  36. $this->content->icons = array();
  37. $this->content->footer = '';
  38. $course = $this->page->course;
  39. require_once($CFG->dirroot.'/course/lib.php');
  40. $modinfo = get_fast_modinfo($course);
  41. $modfullnames = array();
  42. $archetypes = array();
  43. foreach($modinfo->cms as $cm) {
  44. // Exclude activities which are not visible or have no link (=label)
  45. if (!$cm->uservisible or !$cm->has_view()) {
  46. continue;
  47. }
  48. if (array_key_exists($cm->modname, $modfullnames)) {
  49. continue;
  50. }
  51. if (!array_key_exists($cm->modname, $archetypes)) {
  52. $archetypes[$cm->modname] = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
  53. }
  54. if ($archetypes[$cm->modname] == MOD_ARCHETYPE_RESOURCE) {
  55. if (!array_key_exists('resources', $modfullnames)) {
  56. $modfullnames['resources'] = get_string('resources');
  57. }
  58. } else {
  59. $modfullnames[$cm->modname] = $cm->modplural;
  60. }
  61. }
  62. core_collator::asort($modfullnames);
  63. foreach ($modfullnames as $modname => $modfullname) {
  64. if ($modname === 'resources') {
  65. $icon = $OUTPUT->pix_icon('icon', '', 'mod_page', array('class' => 'icon'));
  66. $this->content->items[] = '<a href="'.$CFG->wwwroot.'/course/resources.php?id='.$course->id.'">'.$icon.$modfullname.'</a>';
  67. } else {
  68. $icon = '<img src="'.$OUTPUT->pix_url('icon', $modname) . '" class="icon" alt="" />';
  69. $this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$course->id.'">'.$icon.$modfullname.'</a>';
  70. }
  71. }
  72. return $this->content;
  73. }
  74. /**
  75. * Returns the role that best describes this blocks contents.
  76. *
  77. * This returns 'navigation' as the blocks contents is a list of links to activities and resources.
  78. *
  79. * @return string 'navigation'
  80. */
  81. public function get_aria_role() {
  82. return 'navigation';
  83. }
  84. function applicable_formats() {
  85. return array('all' => true, 'mod' => false, 'my' => false, 'admin' => false,
  86. 'tag' => false);
  87. }
  88. }