Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

   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          $userfieldsapi = \core_user\fields::for_name();
  54          $allusernames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
  55          if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, $allusernames
  56                                                      FROM {role_assignments} ra, {context} c, {user} u
  57                                                     WHERE ra.userid = ?
  58                                                           AND ra.contextid = c.id
  59                                                           AND c.instanceid = u.id
  60                                                           AND c.contextlevel = ".CONTEXT_USER, array($USER->id))) {
  61  
  62              $this->content->text = '<ul>';
  63              foreach ($usercontexts as $usercontext) {
  64                  $this->content->text .= '<li><a href="'.$CFG->wwwroot.'/user/view.php?id='.$usercontext->instanceid.'&amp;course='.SITEID.'">'.fullname($usercontext).'</a></li>';
  65              }
  66              $this->content->text .= '</ul>';
  67          }
  68  
  69          $this->content->footer = '';
  70  
  71          return $this->content;
  72      }
  73  
  74      /**
  75       * Returns true if the block can be docked.
  76       * The mentees block can only be docked if it has a non-empty title.
  77       * @return bool
  78       */
  79      public function instance_can_be_docked() {
  80          return parent::instance_can_be_docked() && isset($this->config->title) && !empty($this->config->title);
  81      }
  82  
  83      /**
  84       * Return the plugin config settings for external functions.
  85       *
  86       * @return stdClass the configs for both the block instance and plugin
  87       * @since Moodle 3.8
  88       */
  89      public function get_config_for_external() {
  90          // Return all settings for all users since it is safe (no private keys, etc..).
  91          $configs = !empty($this->config) ? $this->config : new stdClass();
  92  
  93          return (object) [
  94              'instance' => $configs,
  95              'plugin' => new stdClass(),
  96          ];
  97      }
  98  }
  99