Merge branch 'MDL-57036_master' of git://github.com/markn86/moodle

This commit is contained in:
David Monllao 2016-11-21 10:51:29 +08:00
commit dfe7cbe4cf

View File

@ -348,58 +348,54 @@ class api {
* @return \stdClass
*/
public static function get_profile($userid, $otheruserid) {
global $CFG, $DB;
global $CFG, $DB, $PAGE;
require_once($CFG->dirroot . '/user/lib.php');
if ($user = \core_user::get_user($otheruserid)) {
// Create the data we are going to pass to the renderable.
$userfields = user_get_user_details($user, null, array('city', 'country', 'email',
'profileimageurl', 'profileimageurlsmall', 'lastaccess'));
if ($userfields) {
$data = new \stdClass();
$data->userid = $userfields['id'];
$data->fullname = $userfields['fullname'];
$data->city = isset($userfields['city']) ? $userfields['city'] : '';
$data->country = isset($userfields['country']) ? $userfields['country'] : '';
$data->email = isset($userfields['email']) ? $userfields['email'] : '';
$data->profileimageurl = isset($userfields['profileimageurl']) ? $userfields['profileimageurl'] : '';
if (isset($userfields['profileimageurlsmall'])) {
$data->profileimageurlsmall = $userfields['profileimageurlsmall'];
} else {
$data->profileimageurlsmall = '';
}
if (isset($userfields['lastaccess'])) {
$data->isonline = helper::is_online($userfields['lastaccess']);
} else {
$data->isonline = false;
}
} else {
// Technically the access checks in user_get_user_details are correct,
// but messaging has never obeyed them. In order to keep messaging working
// we at least need to return a minimal user record.
$data = new \stdClass();
$data->userid = $otheruserid;
$data->fullname = fullname($user);
$data->city = '';
$data->country = '';
$data->email = '';
$data->profileimageurl = '';
$data->profileimageurlsmall = '';
$data->isonline = false;
}
// Check if the contact has been blocked.
$contact = $DB->get_record('message_contacts', array('userid' => $userid, 'contactid' => $otheruserid));
if ($contact) {
$data->isblocked = (bool) $contact->blocked;
$data->iscontact = true;
} else {
$data->isblocked = false;
$data->iscontact = false;
}
$user = \core_user::get_user($otheruserid, '*', MUST_EXIST);
return $data;
// Create the data we are going to pass to the renderable.
$data = new \stdClass();
$data->userid = $otheruserid;
$data->fullname = fullname($user);
$data->city = '';
$data->country = '';
$data->email = '';
$data->isonline = false;
// Get the user picture data - messaging has always shown these to the user.
$userpicture = new \user_picture($user);
$userpicture->size = 1; // Size f1.
$data->profileimageurl = $userpicture->get_url($PAGE)->out(false);
$userpicture->size = 0; // Size f2.
$data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false);
$userfields = user_get_user_details($user, null, array('city', 'country', 'email', 'lastaccess'));
if ($userfields) {
if (isset($userfields['city'])) {
$data->city = $userfields['city'];
}
if (isset($userfields['country'])) {
$data->country = $userfields['country'];
}
if (isset($userfields['email'])) {
$data->email = $userfields['email'];
}
if (isset($userfields['lastaccess'])) {
$data->isonline = helper::is_online($userfields['lastaccess']);
}
}
// Check if the contact has been blocked.
$contact = $DB->get_record('message_contacts', array('userid' => $userid, 'contactid' => $otheruserid));
if ($contact) {
$data->isblocked = (bool) $contact->blocked;
$data->iscontact = true;
} else {
$data->isblocked = false;
$data->iscontact = false;
}
return $data;
}
/**