mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
message_area.php
137 lines (120 loc) · 4.33 KB
/
message_area.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains class used to prepare the message area for display.
*
* TODO: This file should be removed once the related web services go through final deprecation.
* Followup: MDL-63261
*
* @package core_message
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output\messagearea;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
/**
* Class to prepare the message area for display.
*
* @package core_message
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_area implements templatable, renderable {
/**
* @var int The user id.
*/
public $userid;
/**
* @var int The other user id.
*/
public $otheruserid;
/**
* @var array The contacts for the users.
*/
public $contacts;
/**
* @var array The messages for the user.
*/
public $messages;
/**
* @var bool Was a specific conversation requested.
*/
public $requestedconversation;
/**
* @var int The minimum time to poll for messages.
*/
public $pollmin;
/**
* @var int The maximum time to poll for messages.
*/
public $pollmax;
/**
* @var int The time used once we have reached the maximum polling time.
*/
public $polltimeout;
/**
* @var bool Are we creating a new message and show the contacts section first?
*/
public $contactsfirst;
/**
* Constructor.
*
* @param int $userid The ID of the user whose contacts and messages we are viewing
* @param int|null $otheruserid The id of the user we are viewing, null if none
* @param array $contacts
* @param array|null $messages
* @param bool $requestedconversation
* @param bool $contactsfirst Whether we are viewing the contacts first.
* @param int $pollmin
* @param int $pollmax
* @param int $polltimeout
*/
public function __construct($userid, $otheruserid, $contacts, $messages, $requestedconversation, $contactsfirst, $pollmin,
$pollmax, $polltimeout) {
$this->userid = $userid;
// Setting the other user to null when showing contacts will remove any contact from being selected.
$this->otheruserid = (!$contactsfirst) ? $otheruserid : null;
$this->contacts = $contacts;
$this->messages = $messages;
$this->requestedconversation = $requestedconversation;
$this->pollmin = $pollmin;
$this->pollmax = $pollmax;
$this->polltimeout = $polltimeout;
$this->contactsfirst = $contactsfirst;
}
public function export_for_template(\renderer_base $output) {
$data = new \stdClass();
$data->userid = $this->userid;
$contacts = new contacts($this->otheruserid, $this->contacts);
$data->contacts = $contacts->export_for_template($output);
if ($this->contactsfirst) {
// Don't show any messages if we are creating a new message.
$messages = new messages($this->userid, null, array());
} else {
$messages = new messages($this->userid, $this->otheruserid, $this->messages);
}
$data->messages = $messages->export_for_template($output);
$data->isconversation = ($this->contactsfirst) ? false : true;
$data->requestedconversation = $this->requestedconversation;
$data->pollmin = $this->pollmin;
$data->pollmax = $this->pollmax;
$data->polltimeout = $this->polltimeout;
$data->contactsfirst = $this->contactsfirst;
return $data;
}
}