/** * Tests retrieving a user's profile. */ public function test_get_profile_as_admin() { // The person doing the search. $this->setAdminUser(); // Create some users. $user1 = self::getDataGenerator()->create_user(); $user2 = new stdClass(); $user2->country = 'AU'; $user2->city = 'Perth'; $user2 = self::getDataGenerator()->create_user($user2); // Get the profile. $profile = \core_message\api::get_profile($user1->id, $user2->id); $this->assertEquals($user2->id, $profile->userid); $this->assertEquals($user2->email, $profile->email); $this->assertEquals($user2->country, $profile->country); $this->assertEquals($user2->city, $profile->city); $this->assertEquals(fullname($user2), $profile->fullname); $this->assertFalse($profile->isonline); $this->assertFalse($profile->isblocked); $this->assertFalse($profile->iscontact); }
/** * Get the profile information for a contact. * * @param int $currentuserid The current user's id * @param int $otheruserid The id of the user whose profile we are viewing * @return stdClass * @throws moodle_exception * @since 3.2 */ public static function data_for_messagearea_get_profile($currentuserid, $otheruserid) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array('currentuserid' => $currentuserid, 'otheruserid' => $otheruserid); self::validate_parameters(self::data_for_messagearea_get_profile_parameters(), $params); self::validate_context($systemcontext); if ($USER->id != $currentuserid && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $profile = \core_message\api::get_profile($currentuserid, $otheruserid); $profile = new \core_message\output\messagearea\profile($profile); $renderer = $PAGE->get_renderer('core_message'); return $profile->export_for_template($renderer); }