block_participants.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. * Participants block
  18. *
  19. * @package block_participants
  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. class block_participants extends block_list {
  24. function init() {
  25. $this->title = get_string('pluginname', 'block_participants');
  26. }
  27. function get_content() {
  28. global $CFG, $OUTPUT;
  29. if (empty($this->instance)) {
  30. $this->content = '';
  31. return $this->content;
  32. }
  33. $this->content = new stdClass();
  34. $this->content->items = array();
  35. $this->content->icons = array();
  36. $this->content->footer = '';
  37. // user/index.php expect course context, so get one if page has module context.
  38. $currentcontext = $this->page->context->get_course_context(false);
  39. if (empty($currentcontext)) {
  40. $this->content = '';
  41. return $this->content;
  42. } else if ($this->page->course->id == SITEID) {
  43. if (!has_capability('moodle/site:viewparticipants', context_system::instance())) {
  44. $this->content = '';
  45. return $this->content;
  46. }
  47. } else {
  48. if (!has_capability('moodle/course:viewparticipants', $currentcontext)) {
  49. $this->content = '';
  50. return $this->content;
  51. }
  52. }
  53. $icon = '<img src="'.$OUTPUT->pix_url('i/users') . '" class="icon" alt="" />';
  54. $this->content->items[] = '<a title="'.get_string('listofallpeople').'" href="'.
  55. $CFG->wwwroot.'/user/index.php?contextid='.$currentcontext->id.'">'.$icon.get_string('participants').'</a>';
  56. return $this->content;
  57. }
  58. // my moodle can only have SITEID and it's redundant here, so take it away
  59. function applicable_formats() {
  60. return array('all' => true, 'my' => false, 'tag' => false);
  61. }
  62. }