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 for exporting a user summary from an stdClass.
  19   *
  20   * @package    core_user
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core_user\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use context_system;
  28  use renderer_base;
  29  use moodle_url;
  30  
  31  /**
  32   * Class for exporting a user summary from an stdClass.
  33   *
  34   * @copyright  2015 Damyon Wiese
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class user_summary_exporter extends \core\external\exporter {
  38  
  39      protected function get_other_values(renderer_base $output) {
  40          global $PAGE, $CFG;
  41  
  42          // Add user picture.
  43          $userpicture = new \user_picture($this->data);
  44          $userpicture->size = 1; // Size f1.
  45          $profileimageurl = $userpicture->get_url($PAGE)->out(false);
  46          $userpicture->size = 0; // Size f2.
  47          $profileimageurlsmall = $userpicture->get_url($PAGE)->out(false);
  48  
  49          $profileurl = (new moodle_url('/user/profile.php', array('id' => $this->data->id)))->out(false);
  50  
  51          $identityfields = array_flip(explode(',', $CFG->showuseridentity));
  52          $data = $this->data;
  53          foreach ($identityfields as $field => $index) {
  54              if (!empty($data->$field)) {
  55                  $identityfields[$field] = $data->$field;
  56              } else {
  57                  unset($identityfields[$field]);
  58              }
  59          }
  60          $identity = implode(', ', $identityfields);
  61          return array(
  62              'fullname' => fullname($this->data),
  63              'profileimageurl' => $profileimageurl,
  64              'profileimageurlsmall' => $profileimageurlsmall,
  65              'profileurl' => $profileurl,
  66              'identity' => $identity
  67          );
  68      }
  69  
  70  
  71      /**
  72       * Get the format parameters for department.
  73       *
  74       * @return array
  75       */
  76      protected function get_format_parameters_for_department() {
  77          return [
  78              'context' => context_system::instance(), // The system context is cached, so we can get it right away.
  79          ];
  80      }
  81  
  82      /**
  83       * Get the format parameters for institution.
  84       *
  85       * @return array
  86       */
  87      protected function get_format_parameters_for_institution() {
  88          return [
  89              'context' => context_system::instance(), // The system context is cached, so we can get it right away.
  90          ];
  91      }
  92  
  93      public static function define_properties() {
  94          return array(
  95              'id' => array(
  96                  'type' => \core_user::get_property_type('id'),
  97              ),
  98              'email' => array(
  99                  'type' => \core_user::get_property_type('email'),
 100                  'default' => ''
 101              ),
 102              'idnumber' => array(
 103                  'type' => \core_user::get_property_type('idnumber'),
 104                  'default' => ''
 105              ),
 106              'phone1' => array(
 107                  'type' => \core_user::get_property_type('phone1'),
 108                  'default' => ''
 109              ),
 110              'phone2' => array(
 111                  'type' => \core_user::get_property_type('phone2'),
 112                  'default' => ''
 113              ),
 114              'department' => array(
 115                  'type' => \core_user::get_property_type('department'),
 116                  'default' => ''
 117              ),
 118              'institution' => array(
 119                  'type' => \core_user::get_property_type('institution'),
 120                  'default' => ''
 121              )
 122          );
 123      }
 124  
 125      public static function define_other_properties() {
 126          return array(
 127              'fullname' => array(
 128                  'type' => PARAM_RAW
 129              ),
 130              'identity' => array(
 131                  'type' => PARAM_RAW
 132              ),
 133              'profileurl' => array(
 134                  'type' => PARAM_URL
 135              ),
 136              'profileimageurl' => array(
 137                  'type' => PARAM_URL
 138              ),
 139              'profileimageurlsmall' => array(
 140                  'type' => PARAM_URL
 141              ),
 142          );
 143      }
 144  }