2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Contains class used to prepare a contact for display.
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
25 namespace core_message\output\messagearea
;
27 defined('MOODLE_INTERNAL') ||
die();
33 * Class to prepare a contact for display.
35 * @package core_message
36 * @copyright 2016 Mark Nelson <markn@moodle.com>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class contact
implements templatable
, renderable
{
42 * @var int Maximum length of message to show in panel.
44 const MAX_MSG_LENGTH
= 60;
47 * @var int The userid.
52 * @var int The id of the user who sent the last message.
57 * @var string The fullname.
62 * @var string The profile image url.
64 public $profileimageurl;
67 * @var string The small profile image url.
69 public $profileimageurlsmall;
72 * @var int The message id.
77 * @var bool Are we messaging the user?
82 * @var string The last message sent.
87 * @var int The last message sent timestamp.
89 public $lastmessagedate;
92 * @var bool Is the user online?
97 * @var bool Is the user blocked?
102 * @var bool Is the message read?
107 * @var int The number of unread messages.
114 * @param \stdClass $contact
116 public function __construct($contact) {
117 $this->userid
= $contact->userid
;
118 $this->useridfrom
= $contact->useridfrom
;
119 $this->fullname
= $contact->fullname
;
120 $this->profileimageurl
= $contact->profileimageurl
;
121 $this->profileimageurlsmall
= $contact->profileimageurlsmall
;
122 $this->messageid
= $contact->messageid
;
123 $this->ismessaging
= $contact->ismessaging
;
124 $this->lastmessage
= $contact->lastmessage
;
125 $this->lastmessagedate
= $contact->lastmessagedate
;
126 $this->isonline
= $contact->isonline
;
127 $this->isblocked
= $contact->isblocked
;
128 $this->isread
= $contact->isread
;
129 $this->unreadcount
= $contact->unreadcount
;
132 public function export_for_template(\renderer_base
$output) {
133 $contact = new \
stdClass();
134 $contact->userid
= $this->userid
;
135 $contact->fullname
= $this->fullname
;
136 $contact->profileimageurl
= $this->profileimageurl
;
137 $contact->profileimageurlsmall
= $this->profileimageurlsmall
;
138 $contact->messageid
= $this->messageid
;
139 $contact->ismessaging
= $this->ismessaging
;
140 $contact->sentfromcurrentuser
= false;
141 if ($this->lastmessage
) {
142 if ($this->userid
!== $this->useridfrom
) {
143 $contact->sentfromcurrentuser
= true;
145 $contact->lastmessage
= shorten_text($this->lastmessage
, self
::MAX_MSG_LENGTH
);
147 $contact->lastmessage
= null;
149 $contact->lastmessagedate
= $this->lastmessagedate
;
150 $contact->showonlinestatus
= is_null($this->isonline
) ?
false : true;
151 $contact->isonline
= $this->isonline
;
152 $contact->isblocked
= $this->isblocked
;
153 $contact->isread
= $this->isread
;
154 $contact->unreadcount
= $this->unreadcount
;