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   * 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_icq) && !empty($USER->icq)) {
  88              $data->usericq = s($USER->icq);
  89          }
  90  
  91          if (!empty($this->config->display_skype) && !empty($USER->skype)) {
  92              $data->userskype = s($USER->skype);
  93          }
  94  
  95          if (!empty($this->config->display_yahoo) && !empty($USER->yahoo)) {
  96              $data->useryahoo = s($USER->yahoo);
  97          }
  98  
  99          if (!empty($this->config->display_aim) && !empty($USER->aim)) {
 100              $data->useraim = s($USER->aim);
 101          }
 102  
 103          if (!empty($this->config->display_msn) && !empty($USER->msn)) {
 104              $data->usermsn = s($USER->msn);
 105          }
 106  
 107          if (!empty($this->config->display_phone1) && !empty($USER->phone1)) {
 108              $data->userphone1 = s($USER->phone1);
 109          }
 110  
 111          if (!empty($this->config->display_phone2) && !empty($USER->phone2)) {
 112              $data->userphone2 = s($USER->phone2);
 113          }
 114  
 115          if (!empty($this->config->display_institution) && !empty($USER->institution)) {
 116              $data->userinstitution = format_string($USER->institution);
 117          }
 118  
 119          if (!empty($this->config->display_address) && !empty($USER->address)) {
 120              $data->useraddress = format_string($USER->address);
 121          }
 122  
 123          if (!empty($this->config->display_firstaccess) && !empty($USER->firstaccess)) {
 124              $data->userfirstaccess = userdate($USER->firstaccess);
 125          }
 126  
 127          if (!empty($this->config->display_lastaccess) && !empty($USER->lastaccess)) {
 128              $data->userlastaccess = userdate($USER->lastaccess);
 129          }
 130  
 131          if (!empty($this->config->display_currentlogin) && !empty($USER->currentlogin)) {
 132              $data->usercurrentlogin = userdate($USER->currentlogin);
 133          }
 134  
 135          if (!empty($this->config->display_lastip) && !empty($USER->lastip)) {
 136              $data->userlastip = $USER->lastip;
 137          }
 138  
 139          return $data;
 140      }
 141  }