Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 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   * Class containing data for myprofile block.
  19   *
  20   * @package    block_myprofile
  21   * @copyright  2018 Mihail Geshoski <mihail@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace block_myprofile\output;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use renderable;
  30  use renderer_base;
  31  use templatable;
  32  
  33  /**
  34   * Class containing data for myprofile block.
  35   *
  36   * @copyright  2018 Mihail Geshoski <mihail@moodle.com>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class myprofile implements renderable, templatable {
  40  
  41      /**
  42       * @var object An object containing the configuration information for the current instance of this block.
  43       */
  44      protected $config;
  45  
  46      /**
  47       * Constructor.
  48       *
  49       * @param object $config An object containing the configuration information for the current instance of this block.
  50       */
  51      public function __construct($config) {
  52          $this->config = $config;
  53      }
  54  
  55      /**
  56       * Export this data so it can be used as the context for a mustache template.
  57       *
  58       * @param \renderer_base $output
  59       * @return stdClass
  60       */
  61      public function export_for_template(renderer_base $output) {
  62          global $USER, $OUTPUT;
  63  
  64          $data = new \stdClass();
  65  
  66          if (!isset($this->config->display_picture) || $this->config->display_picture == 1) {
  67              $data->userpicture = $OUTPUT->user_picture($USER, array('class' => 'userpicture'));
  68          }
  69  
  70          $data->userfullname = fullname($USER);
  71  
  72          if (!isset($this->config->display_country) || $this->config->display_country == 1) {
  73              $countries = get_string_manager()->get_list_of_countries(true);
  74              if (isset($countries[$USER->country])) {
  75                  $data->usercountry = $countries[$USER->country];
  76              }
  77          }
  78  
  79          if (!isset($this->config->display_city) || $this->config->display_city == 1) {
  80              $data->usercity = $USER->city;
  81          }
  82  
  83          if (!isset($this->config->display_email) || $this->config->display_email == 1) {
  84              $data->useremail = obfuscate_mailto($USER->email, '');
  85          }
  86  
  87          if (!empty($this->config->display_phone1) && !empty($USER->phone1)) {
  88              $data->userphone1 = s($USER->phone1);
  89          }
  90  
  91          if (!empty($this->config->display_phone2) && !empty($USER->phone2)) {
  92              $data->userphone2 = s($USER->phone2);
  93          }
  94  
  95          if (!empty($this->config->display_institution) && !empty($USER->institution)) {
  96              $data->userinstitution = format_string($USER->institution);
  97          }
  98  
  99          if (!empty($this->config->display_address) && !empty($USER->address)) {
 100              $data->useraddress = format_string($USER->address);
 101          }
 102  
 103          if (!empty($this->config->display_idnumber) && !empty($USER->idnumber)) {
 104              $data->useridnumber = s($USER->idnumber);
 105          }
 106  
 107          if (!empty($this->config->display_firstaccess) && !empty($USER->firstaccess)) {
 108              $data->userfirstaccess = userdate($USER->firstaccess);
 109          }
 110  
 111          if (!empty($this->config->display_lastaccess) && !empty($USER->lastaccess)) {
 112              $data->userlastaccess = userdate($USER->lastaccess);
 113          }
 114  
 115          if (!empty($this->config->display_currentlogin) && !empty($USER->currentlogin)) {
 116              $data->usercurrentlogin = userdate($USER->currentlogin);
 117          }
 118  
 119          if (!empty($this->config->display_lastip) && !empty($USER->lastip)) {
 120              $data->userlastip = $USER->lastip;
 121          }
 122  
 123          if (!empty($this->config->display_lastlogin) && !empty($USER->lastlogin)) {
 124              $data->userlastlogin = userdate($USER->lastlogin);
 125          }
 126  
 127          return $data;
 128      }
 129  }