5 use wcf\data\conversation\label\ConversationLabel
;
6 use wcf\data\conversation\label\ConversationLabelList
;
7 use wcf\data\conversation\UserConversationList
;
8 use wcf\system\clipboard\ClipboardHandler
;
9 use wcf\system\database\util\PreparedStatementConditionBuilder
;
10 use wcf\system\exception\IllegalLinkException
;
11 use wcf\system\page\PageLocationManager
;
13 use wcf\util\ArrayUtil
;
16 * Shows a list of conversations.
19 * @copyright 2001-2019 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package WoltLabSuite\Core\Page
23 * @property UserConversationList $objectList
25 class ConversationListPage
extends SortablePage
30 public $defaultSortField = CONVERSATION_LIST_DEFAULT_SORT_FIELD
;
35 public $defaultSortOrder = CONVERSATION_LIST_DEFAULT_SORT_ORDER
;
40 public $validSortFields = ['subject', 'time', 'username', 'lastPostTime', 'replies', 'participants'];
45 public $itemsPerPage = CONVERSATIONS_PER_PAGE
;
50 public $loginRequired = true;
55 public $neededModules = ['MODULE_CONVERSATION'];
60 public $neededPermissions = ['user.conversation.canUseConversation'];
76 * @var ConversationLabelList
81 * number of conversations (no filter)
84 public $conversationCount = 0;
90 public $draftCount = 0;
93 * number of hidden conversations
96 public $hiddenCount = 0;
99 * number of sent conversations
102 public $outboxCount = 0;
108 public $participants = [];
113 public function readParameters()
115 parent
::readParameters();
117 if (isset($_REQUEST['filter'])) {
118 $this->filter
= $_REQUEST['filter'];
120 if (!\
in_array($this->filter
, UserConversationList
::$availableFilters)) {
125 /** @noinspection PhpUndefinedFieldInspection */
126 if (WCF
::getUser()->conversationsPerPage
) {
127 /** @noinspection PhpUndefinedFieldInspection */
128 $this->itemsPerPage
= WCF
::getUser()->conversationsPerPage
;
132 $this->labelList
= ConversationLabel
::getLabelsByUser();
133 if (isset($_REQUEST['labelID'])) {
134 $this->labelID
= \
intval($_REQUEST['labelID']);
137 foreach ($this->labelList
as $label) {
138 if ($label->labelID
== $this->labelID
) {
145 throw new IllegalLinkException();
149 if (isset($_REQUEST['participants'])) {
150 $this->participants
= \array_slice
(ArrayUtil
::trim(\
explode(',', $_REQUEST['participants'])), 0, 20);
157 protected function initObjectList()
159 $this->objectList
= new UserConversationList(WCF
::getUser()->userID
, $this->filter
, $this->labelID
);
160 $this->objectList
->setLabelList($this->labelList
);
162 if (!empty($this->participants
)) {
163 // The column `conversation_to_user.username` has no index, causing full table scans when
164 // trying to filter by it, therefore we'll read the user ids in advance.
165 $conditions = new PreparedStatementConditionBuilder();
166 $conditions->add('username IN (?)', [$this->participants
]);
167 $sql = "SELECT userID
168 FROM wcf" . WCF_N
. "_user
170 $statement = WCF
::getDB()->prepareStatement($sql);
171 $statement->execute($conditions->getParameters());
173 while ($userID = $statement->fetchColumn()) {
174 $userIDs[] = $userID;
177 if (!empty($userIDs)) {
178 // The condition is split into two branches in order to account for invisible participants.
179 // Invisible participants are only visible to the conversation starter and remain invisible
180 // until the write their first message.
182 // We need to protect these users from being exposed as participants by including them for
183 // any conversation that the current user has started. For all other conversations, users
184 // flagged with `isInvisible = 0` must be excluded.
186 // See https://github.com/WoltLab/com.woltlab.wcf.conversation/issues/131
187 $this->objectList
->getConditionBuilder()->add('
190 conversation.userID = ?
192 conversation.conversationID IN (
193 SELECT conversationID
194 FROM wcf' . WCF_N
. '_conversation_to_user
195 WHERE participantID IN (?)
196 GROUP BY conversationID
197 HAVING COUNT(conversationID) = ?
202 conversation.userID <> ?
204 conversation.conversationID IN (
205 SELECT conversationID
206 FROM wcf' . WCF_N
. '_conversation_to_user
207 WHERE participantID IN (?)
209 GROUP BY conversationID
210 HAVING COUNT(conversationID) = ?
214 // Parameters for the first condition.
215 WCF
::getUser()->userID
,
219 // Parameters for the second condition.
220 WCF
::getUser()->userID
,
232 public function readData()
234 // if sort field is `username`, `conversation.` has to prepended because `username`
235 // alone is ambiguous
236 if ($this->sortField
=== 'username') {
237 $this->sortField
= 'conversation.username';
242 // change back to old value
243 if ($this->sortField
=== 'conversation.username') {
244 $this->sortField
= 'username';
247 if ($this->filter
!= '') {
248 // `-1` = pseudo object id to have to pages with identifier `com.woltlab.wcf.conversation.ConversationList`
249 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.conversation.ConversationList', -1);
253 if (!$this->labelID
&& empty($this->participants
)) {
254 switch ($this->filter
) {
256 $this->conversationCount
= $this->items
;
260 $this->draftCount
= $this->items
;
264 $this->hiddenCount
= $this->items
;
268 $this->outboxCount
= $this->items
;
273 if ($this->filter
!= '' ||
$this->labelID ||
!empty($this->participants
)) {
274 $conversationList = new UserConversationList(WCF
::getUser()->userID
, '');
275 $this->conversationCount
= $conversationList->countObjects();
277 if ($this->filter
!= 'draft' ||
$this->labelID ||
!empty($this->participants
)) {
278 $conversationList = new UserConversationList(WCF
::getUser()->userID
, 'draft');
279 $this->draftCount
= $conversationList->countObjects();
281 if ($this->filter
!= 'hidden' ||
$this->labelID ||
!empty($this->participants
)) {
282 $conversationList = new UserConversationList(WCF
::getUser()->userID
, 'hidden');
283 $this->hiddenCount
= $conversationList->countObjects();
285 if ($this->filter
!= 'outbox' ||
$this->labelID ||
!empty($this->participants
)) {
286 $conversationList = new UserConversationList(WCF
::getUser()->userID
, 'outbox');
287 $this->outboxCount
= $conversationList->countObjects();
294 public function assignVariables()
296 parent
::assignVariables();
298 WCF
::getTPL()->assign([
299 'filter' => $this->filter
,
300 'hasMarkedItems' => ClipboardHandler
::getInstance()->hasMarkedItems(
301 ClipboardHandler
::getInstance()->getObjectTypeID('com.woltlab.wcf.conversation.conversation')
303 'labelID' => $this->labelID
,
304 'labelList' => $this->labelList
,
305 'conversationCount' => $this->conversationCount
,
306 'draftCount' => $this->draftCount
,
307 'hiddenCount' => $this->hiddenCount
,
308 'outboxCount' => $this->outboxCount
,
309 'participants' => $this->participants
,
310 'validSortFields' => $this->validSortFields
,