MDL-55770 core_message: remove the send message pop-up
[moodle.git] / message / classes / output / messagearea / contact.php
CommitLineData
879e2bef
MN
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Contains class used to prepare a contact for display.
19 *
20 * @package core_message
21 * @copyright 2016 Mark Nelson <markn@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
1e5f751f 25namespace core_message\output\messagearea;
879e2bef
MN
26
27use renderable;
28use templatable;
29
30/**
31 * Class to prepare a contact for display.
32 *
33 * @package core_message
34 * @copyright 2016 Mark Nelson <markn@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class contact implements templatable, renderable {
38
39 /**
40 * Maximum length of message to show in left panel.
41 */
42 const MAX_MSG_LENGTH = 60;
43
44 /**
45 * The contact.
46 */
47 protected $contact;
48
49 /**
50 * Constructor.
51 *
52 * @param \stdClass $contact
53 */
54 public function __construct($contact) {
55 $this->contact = $contact;
56 }
57
8c250260
RW
58 /**
59 * Get the user id for this contact.
60 */
61 public function get_contact() {
62 return $this->contact;
63 }
64
879e2bef
MN
65 public function export_for_template(\renderer_base $output) {
66 $contact = new \stdClass();
67 $contact->userid = $this->contact->userid;
68 $contact->fullname = $this->contact->fullname;
69 $contact->profileimageurl = $this->contact->profileimageurl;
70 $contact->profileimageurlsmall = $this->contact->profileimageurlsmall;
cd03b8d7 71 $contact->messageid = $this->contact->messageid;
5bf0ff27 72 $contact->ismessaging = $this->contact->ismessaging;
49aaadc3
MN
73 if ($this->contact->lastmessage) {
74 $contact->lastmessage = shorten_text($this->contact->lastmessage, self::MAX_MSG_LENGTH);
75 } else {
76 $contact->lastmessage = null;
77 }
879e2bef 78 $contact->isonline = $this->contact->isonline;
dd0c1403 79 $contact->isblocked = $this->contact->isblocked;
eda6bc19 80 $contact->isread = $this->contact->isread;
c33b7d89 81 $contact->unreadcount = $this->contact->unreadcount;
879e2bef
MN
82
83 return $contact;
84 }
6c3b9541
MN
85
86 /**
87 * Magic setter method.
88 *
89 * @param $name
90 * @param $value
91 */
92 public function __set($name, $value) {
93 if (property_exists($this->contact, $name)) {
94 $this->contact->$name = $value;
95 }
96 }
879e2bef 97}