MDL-54687 core_message: created page for new messaging interface
[moodle.git] / message / classes / output / 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
25namespace core_message\output;
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
58 public function export_for_template(\renderer_base $output) {
59 $contact = new \stdClass();
60 $contact->userid = $this->contact->userid;
61 $contact->fullname = $this->contact->fullname;
62 $contact->profileimageurl = $this->contact->profileimageurl;
63 $contact->profileimageurlsmall = $this->contact->profileimageurlsmall;
64 $contact->lastmessage = shorten_text($this->contact->lastmessage, self::MAX_MSG_LENGTH);
65 $contact->isonline = $this->contact->isonline;
66
67 return $contact;
68 }
69}