public function export_for_template(\renderer_base $output) { $data = new \stdClass(); $data->contacts = array(); $userids = array(); foreach ($this->contacts as $contact) { $contact = new contact($contact); $contactdata = $contact->export_for_template($output); $userids[$contactdata->userid] = $contactdata->userid; // Check if the contact was selected. if ($this->contactuserid == $contactdata->userid) { $contactdata->selected = true; } $data->contacts[] = $contactdata; } // Check if the other user is not part of the contacts. We may be sending a message to someone // we have not had a conversation with, so we want to add a new item to the contacts array. if ($this->contactuserid && !isset($userids[$this->contactuserid])) { $user = \core_user::get_user($this->contactuserid); // Set an empty message so that we know we are messaging the user, and not viewing their profile. $user->smallmessage = ''; $user->useridfrom = $user->id; $contact = \core_message\helper::create_contact($user); $contact = new contact($contact); $contactdata = $contact->export_for_template($output); $contactdata->selected = true; // Put the contact at the front. array_unshift($data->contacts, $contactdata); } return $data; }