Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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.
   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   * Contains class used to prepare a profile for display.
  19   *
  20   * TODO: This file should be removed once the related web services go through final deprecation.
  21   * Followup: MDL-63261
  22   *
  23   * @package   core_message
  24   * @copyright 2016 Mark Nelson <markn@moodle.com>
  25   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  namespace core_message\output\messagearea;
  29  
  30  defined('MOODLE_INTERNAL') || die();
  31  
  32  use renderable;
  33  use templatable;
  34  
  35  /**
  36   * Class to prepare a profile for display.
  37   *
  38   * @package   core_message
  39   * @copyright 2016 Mark Nelson <markn@moodle.com>
  40   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class profile implements templatable, renderable {
  43  
  44      /**
  45       * @var int The id of the user we are going to view.
  46       */
  47      public $userid;
  48  
  49      /**
  50       * @var string The fullname.
  51       */
  52      public $fullname;
  53  
  54      /**
  55       * @var string The city.
  56       */
  57      public $city;
  58  
  59      /**
  60       * @var string The country.
  61       */
  62      public $country;
  63  
  64      /**
  65       * @var string The email.
  66       */
  67      public $email;
  68  
  69      /**
  70       * @var string The profile image url.
  71       */
  72      public $profileimageurl;
  73  
  74      /**
  75       * @var string The small profile image url.
  76       */
  77      public $profileimageurlsmall;
  78  
  79      /**
  80       * @var bool Is the user online?
  81       */
  82      public $isonline;
  83  
  84      /**
  85       * @var bool Is the user blocked?
  86       */
  87      public $isblocked;
  88  
  89      /**
  90       * @var bool Is the user a contact?
  91       */
  92      public $iscontact;
  93  
  94      /**
  95       * Constructor.
  96       *
  97       * @param \stdClass $profile
  98       */
  99      public function __construct($profile) {
 100          $this->userid = $profile->userid;
 101          $this->fullname = $profile->fullname;
 102          $this->isonline = $profile->isonline;
 103          $this->email = $profile->email;
 104          $this->country = $profile->country;
 105          $this->city = $profile->city;
 106          $this->profileimageurl = $profile->profileimageurl;
 107          $this->profileimageurlsmall = $profile->profileimageurlsmall;
 108          $this->isblocked = $profile->isblocked;
 109          $this->iscontact = $profile->iscontact;
 110      }
 111  
 112      public function export_for_template(\renderer_base $output) {
 113          $data = new \stdClass();
 114          $data->userid = $this->userid;
 115          $data->fullname = $this->fullname;
 116          $data->showonlinestatus = is_null($this->isonline) ? false : true;
 117          $data->isonline = $this->isonline;
 118          $data->email = $this->email;
 119          if (!empty($this->country)) {
 120              $data->country = get_string($this->country, 'countries');
 121          } else {
 122              $data->country = '';
 123          }
 124          $data->city = $this->city;
 125          $data->profileimageurl = $this->profileimageurl;
 126          $data->profileimageurlsmall = $this->profileimageurlsmall;
 127          $data->isblocked = $this->isblocked;
 128          $data->iscontact = $this->iscontact;
 129  
 130          return $data;
 131      }
 132  }