1 |
efrain |
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 |
// TODO Does not support custom user profile fields (MDL-70456).
|
|
|
52 |
$identityfields = array_flip(\core_user\fields::get_identity_fields(null, false));
|
|
|
53 |
$data = $this->data;
|
|
|
54 |
foreach ($identityfields as $field => $index) {
|
|
|
55 |
if (!empty($data->$field)) {
|
|
|
56 |
$identityfields[$field] = $data->$field;
|
|
|
57 |
} else {
|
|
|
58 |
unset($identityfields[$field]);
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
$identity = implode(', ', $identityfields);
|
|
|
62 |
return array(
|
|
|
63 |
'fullname' => fullname($this->data),
|
|
|
64 |
'profileimageurl' => $profileimageurl,
|
|
|
65 |
'profileimageurlsmall' => $profileimageurlsmall,
|
|
|
66 |
'profileurl' => $profileurl,
|
|
|
67 |
'identity' => $identity
|
|
|
68 |
);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* Get the format parameters for department.
|
|
|
74 |
*
|
|
|
75 |
* @return array
|
|
|
76 |
*/
|
|
|
77 |
protected function get_format_parameters_for_department() {
|
|
|
78 |
return [
|
|
|
79 |
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
|
|
|
80 |
];
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Get the format parameters for institution.
|
|
|
85 |
*
|
|
|
86 |
* @return array
|
|
|
87 |
*/
|
|
|
88 |
protected function get_format_parameters_for_institution() {
|
|
|
89 |
return [
|
|
|
90 |
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
|
|
|
91 |
];
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public static function define_properties() {
|
|
|
95 |
return array(
|
|
|
96 |
'id' => array(
|
|
|
97 |
'type' => \core_user::get_property_type('id'),
|
|
|
98 |
),
|
|
|
99 |
'email' => array(
|
|
|
100 |
'type' => \core_user::get_property_type('email'),
|
|
|
101 |
'default' => ''
|
|
|
102 |
),
|
|
|
103 |
'idnumber' => array(
|
|
|
104 |
'type' => \core_user::get_property_type('idnumber'),
|
|
|
105 |
'default' => ''
|
|
|
106 |
),
|
|
|
107 |
'phone1' => array(
|
|
|
108 |
'type' => \core_user::get_property_type('phone1'),
|
|
|
109 |
'default' => ''
|
|
|
110 |
),
|
|
|
111 |
'phone2' => array(
|
|
|
112 |
'type' => \core_user::get_property_type('phone2'),
|
|
|
113 |
'default' => ''
|
|
|
114 |
),
|
|
|
115 |
'department' => array(
|
|
|
116 |
'type' => \core_user::get_property_type('department'),
|
|
|
117 |
'default' => ''
|
|
|
118 |
),
|
|
|
119 |
'institution' => array(
|
|
|
120 |
'type' => \core_user::get_property_type('institution'),
|
|
|
121 |
'default' => ''
|
|
|
122 |
)
|
|
|
123 |
);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
public static function define_other_properties() {
|
|
|
127 |
return array(
|
|
|
128 |
'fullname' => array(
|
|
|
129 |
'type' => PARAM_RAW
|
|
|
130 |
),
|
|
|
131 |
'identity' => array(
|
|
|
132 |
'type' => PARAM_RAW
|
|
|
133 |
),
|
|
|
134 |
'profileurl' => array(
|
|
|
135 |
'type' => PARAM_URL
|
|
|
136 |
),
|
|
|
137 |
'profileimageurl' => array(
|
|
|
138 |
'type' => PARAM_URL
|
|
|
139 |
),
|
|
|
140 |
'profileimageurlsmall' => array(
|
|
|
141 |
'type' => PARAM_URL
|
|
|
142 |
),
|
|
|
143 |
);
|
|
|
144 |
}
|
|
|
145 |
}
|