Merge branch 'MDL-67641-37' of git://github.com/dpalou/moodle into MOODLE_37_STABLE
[moodle.git] / user / classes / external / user_summary_exporter.php
blobf8f21dc767f5f1ab700cbb2ec67664a7a72bf682
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.
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/>.
17 /**
18 * Class for exporting a user summary from an stdClass.
20 * @package core_user
21 * @copyright 2015 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace core_user\external;
25 defined('MOODLE_INTERNAL') || die();
27 use context_system;
28 use renderer_base;
29 use moodle_url;
31 /**
32 * Class for exporting a user summary from an stdClass.
34 * @copyright 2015 Damyon Wiese
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class user_summary_exporter extends \core\external\exporter {
39 protected function get_other_values(renderer_base $output) {
40 global $PAGE, $CFG;
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);
49 $profileurl = (new moodle_url('/user/profile.php', array('id' => $this->data->id)))->out(false);
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]);
60 $identity = implode(', ', $identityfields);
61 return array(
62 'fullname' => fullname($this->data),
63 'profileimageurl' => $profileimageurl,
64 'profileimageurlsmall' => $profileimageurlsmall,
65 'profileurl' => $profileurl,
66 'identity' => $identity
71 /**
72 * Get the format parameters for department.
74 * @return array
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.
82 /**
83 * Get the format parameters for institution.
85 * @return array
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.
93 public static function define_properties() {
94 return array(
95 'id' => array(
96 'type' => \core_user::get_property_type('id'),
98 'email' => array(
99 'type' => \core_user::get_property_type('email'),
100 'default' => ''
102 'idnumber' => array(
103 'type' => \core_user::get_property_type('idnumber'),
104 'default' => ''
106 'phone1' => array(
107 'type' => \core_user::get_property_type('phone1'),
108 'default' => ''
110 'phone2' => array(
111 'type' => \core_user::get_property_type('phone2'),
112 'default' => ''
114 'department' => array(
115 'type' => \core_user::get_property_type('department'),
116 'default' => ''
118 'institution' => array(
119 'type' => \core_user::get_property_type('institution'),
120 'default' => ''
125 public static function define_other_properties() {
126 return array(
127 'fullname' => array(
128 'type' => PARAM_RAW
130 'identity' => array(
131 'type' => PARAM_RAW
133 'profileurl' => array(
134 'type' => PARAM_URL
136 'profileimageurl' => array(
137 'type' => PARAM_URL
139 'profileimageurlsmall' => array(
140 'type' => PARAM_URL