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; }
public function export_for_template(\renderer_base $output) { $data = new \stdClass(); $data->contacts = array(); foreach ($this->contacts as $contact) { $contact = new contact($contact); $data->contacts[] = $contact->export_for_template($output); } return $data; }
public function export_for_template(\renderer_base $output) { // Set the defaults for the data we are going to export. $data = new \stdClass(); $data->hascontacts = false; $data->contacts = array(); $data->hascourses = false; $data->courses = array(); $data->hasnoncontacts = false; $data->noncontacts = array(); // Check if there are any contacts. if (!empty($this->contacts)) { $data->hascontacts = true; foreach ($this->contacts as $contact) { $contact = new contact($contact); $data->contacts[] = $contact->export_for_template($output); } } // Check if there are any courses. if (!empty($this->courses)) { $data->hascourses = true; $data->courses = $this->courses; } // Check if there are any non-contacts. if (!empty($this->noncontacts)) { $data->hasnoncontacts = true; foreach ($this->noncontacts as $noncontact) { $noncontact = new contact($noncontact); $data->noncontacts[] = $noncontact->export_for_template($output); } } return $data; }
public function export_for_template(\renderer_base $output) { // Set the defaults for the data we are going to export. $data = new \stdClass(); $data->hascontacts = false; $data->contacts = array(); $data->hascourses = false; $data->courses = array(); $data->hasnoncontacts = false; $data->noncontacts = array(); // Check if there are any contacts. if (!empty($this->contacts)) { $data->hascontacts = true; foreach ($this->contacts as $contact) { $contact = new contact($contact); $data->contacts[] = $contact->export_for_template($output); } } // Check if there are any courses. if (!empty($this->courses)) { $data->hascourses = true; $data->courses = []; foreach ($this->courses as $course) { $coursecontext = \context_course::instance($course->id); $course->shortname = external_format_string($course->shortname, $coursecontext->id, true); $course->fullname = external_format_string($course->fullname, $coursecontext->id, true); $data->courses[] = $course; } } // Check if there are any non-contacts. if (!empty($this->noncontacts)) { $data->hasnoncontacts = true; foreach ($this->noncontacts as $noncontact) { $noncontact = new contact($noncontact); $data->noncontacts[] = $noncontact->export_for_template($output); } } return $data; }