Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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  /**
  18   * Mentees block.
  19   *
  20   * @package    block_mentees
  21   * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  class block_mentees extends block_base {
  26  
  27      function init() {
  28          $this->title = get_string('pluginname', 'block_mentees');
  29      }
  30  
  31      function applicable_formats() {
  32          return array('all' => true, 'tag' => false);
  33      }
  34  
  35      function specialization() {
  36          $this->title = isset($this->config->title) ? $this->config->title : get_string('newmenteesblock', 'block_mentees');
  37      }
  38  
  39      function instance_allow_multiple() {
  40          return true;
  41      }
  42  
  43      function get_content() {
  44          global $CFG, $USER, $DB;
  45  
  46          if ($this->content !== NULL) {
  47              return $this->content;
  48          }
  49  
  50          $this->content = new stdClass();
  51  
  52          // get all the mentees, i.e. users you have a direct assignment to
  53          $allusernames = get_all_user_name_fields(true, 'u');
  54          if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, $allusernames
  55                                                      FROM {role_assignments} ra, {context} c, {user} u
  56                                                     WHERE ra.userid = ?
  57                                                           AND ra.contextid = c.id
  58                                                           AND c.instanceid = u.id
  59                                                           AND c.contextlevel = ".CONTEXT_USER, array($USER->id))) {
  60  
  61              $this->content->text = '<ul>';
  62              foreach ($usercontexts as $usercontext) {
  63                  $this->content->text .= '<li><a href="'.$CFG->wwwroot.'/user/view.php?id='.$usercontext->instanceid.'&amp;course='.SITEID.'">'.fullname($usercontext).'</a></li>';
  64              }
  65              $this->content->text .= '</ul>';
  66          }
  67  
  68          $this->content->footer = '';
  69  
  70          return $this->content;
  71      }
  72  
  73      /**
  74       * Returns true if the block can be docked.
  75       * The mentees block can only be docked if it has a non-empty title.
  76       * @return bool
  77       */
  78      public function instance_can_be_docked() {
  79          return parent::instance_can_be_docked() && isset($this->config->title) && !empty($this->config->title);
  80      }
  81  
  82      /**
  83       * Return the plugin config settings for external functions.
  84       *
  85       * @return stdClass the configs for both the block instance and plugin
  86       * @since Moodle 3.8
  87       */
  88      public function get_config_for_external() {
  89          // Return all settings for all users since it is safe (no private keys, etc..).
  90          $configs = !empty($this->config) ? $this->config : new stdClass();
  91  
  92          return (object) [
  93              'instance' => $configs,
  94              'plugin' => new stdClass(),
  95          ];
  96      }
  97  }
  98