public function export_for_template(\renderer_base $output) { global $USER; $data = new \stdClass(); $data->iscurrentuser = $USER->id == $this->currentuserid; $data->currentuserid = $this->currentuserid; if ($this->otheruserid) { $data->otheruserid = $this->otheruserid; $data->otheruserfullname = fullname($this->otheruser); } $data->isonline = null; if ($this->otheruserid) { if (\core_message\helper::show_online_status($this->otheruser)) { $data->isonline = \core_message\helper::is_online($this->otheruser->lastaccess); } } $data->showonlinestatus = is_null($data->isonline) ? false : true; $data->messages = array(); foreach ($this->messages as $message) { $message = new message($message); $data->messages[] = $message->export_for_template($output); } $data->isblocked = api::is_user_blocked($this->currentuserid, $this->otheruserid); return $data; }
/** * Checks if the recipient has specifically blocked the sending user. * * Note: This function will always return false if the sender has the * readallmessages capability at the system context level. * * @deprecated since Moodle 3.2 * @param object $recipient User object. * @param object $sender User object. * @return bool true if $sender is blocked, false otherwise. */ function message_is_user_blocked($recipient, $sender = null) { debugging('message_is_user_blocked() is deprecated and is no longer used, please use \\core_message\\api::is_user_blocked() instead.', DEBUG_DEVELOPER); return \core_message\api::is_user_blocked($recipient, $sender); }
/** * Tests that the admin is not blocked even if someone has chosen to block them. */ public function test_is_user_blocked_as_admin() { // Create a user. $user1 = self::getDataGenerator()->create_user(); // Set the user. $this->setUser($user1); // Block the admin user. message_block_contact(2); // Now change to the admin user. $this->setAdminUser(); // As the admin you should still be able to send messages to the user. $this->assertFalse(\core_message\api::is_user_blocked($user1)); }