3 use wcf\data\conversation\label\ConversationLabel
;
4 use wcf\data\conversation\label\ConversationLabelList
;
5 use wcf\data\conversation\UserConversationList
;
6 use wcf\system\clipboard\ClipboardHandler
;
7 use wcf\system\exception\IllegalLinkException
;
8 use wcf\system\page\PageLocationManager
;
10 use wcf\util\ArrayUtil
;
13 * Shows a list of conversations.
16 * @copyright 2001-2016 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package com.woltlab.wcf.conversation
20 * @category Community Framework
22 * @property UserConversationList $objectList
24 class ConversationListPage
extends SortablePage
{
28 public $enableTracking = true;
33 public $defaultSortField = CONVERSATION_LIST_DEFAULT_SORT_FIELD
;
38 public $defaultSortOrder = CONVERSATION_LIST_DEFAULT_SORT_ORDER
;
43 public $validSortFields = ['subject', 'time', 'username', 'lastPostTime', 'replies', 'participants'];
48 public $itemsPerPage = CONVERSATIONS_PER_PAGE
;
53 public $loginRequired = true;
58 public $neededModules = ['MODULE_CONVERSATION'];
63 public $neededPermissions = ['user.conversation.canUseConversation'];
79 * @var ConversationLabelList
81 public $labelList = null;
84 * number of conversations (no filter)
87 public $conversationCount = 0;
93 public $draftCount = 0;
96 * number of hidden conversations
99 public $hiddenCount = 0;
102 * number of sent conversations
105 public $outboxCount = 0;
111 public $participants = [];
116 public function readParameters() {
117 parent
::readParameters();
119 if (isset($_REQUEST['filter'])) $this->filter
= $_REQUEST['filter'];
120 if (!in_array($this->filter
, UserConversationList
::$availableFilters)) $this->filter
= '';
123 if (WCF
::getUser()->conversationsPerPage
) $this->itemsPerPage
= WCF
::getUser()->conversationsPerPage
;
126 $this->labelList
= ConversationLabel
::getLabelsByUser();
127 if (isset($_REQUEST['labelID'])) {
128 $this->labelID
= intval($_REQUEST['labelID']);
131 foreach ($this->labelList
as $label) {
132 if ($label->labelID
== $this->labelID
) {
139 throw new IllegalLinkException();
143 if (isset($_REQUEST['participants'])) $this->participants
= ArrayUtil
::trim(explode(',', $_REQUEST['participants']));
149 protected function initObjectList() {
150 $this->objectList
= new UserConversationList(WCF
::getUser()->userID
, $this->filter
, $this->labelID
);
151 $this->objectList
->setLabelList($this->labelList
);
153 if (!empty($this->participants
)) {
154 $this->objectList
->getConditionBuilder()->add('conversation.conversationID IN (SELECT conversationID FROM wcf'.WCF_N
.'_conversation_to_user WHERE username IN (?) GROUP BY conversationID HAVING COUNT(conversationID) = ?)', [
156 count($this->participants
)
164 public function readData() {
167 if ($this->filter
!= '') {
169 // TODO: this is not working at the moment as PageLocationManager already sets this as the current page based on request data which is later discarded
170 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.conversation.ConversationList');
174 if (!$this->labelID
&& empty($this->participants
)) {
175 switch ($this->filter
) {
177 $this->conversationCount
= $this->items
;
181 $this->draftCount
= $this->items
;
185 $this->hiddenCount
= $this->items
;
189 $this->outboxCount
= $this->items
;
194 if ($this->filter
!= '' ||
$this->labelID ||
!empty($this->participants
)) {
195 $conversationList = new UserConversationList(WCF
::getUser()->userID
, '');
196 $this->conversationCount
= $conversationList->countObjects();
198 if ($this->filter
!= 'draft' ||
$this->labelID ||
!empty($this->participants
)) {
199 $conversationList = new UserConversationList(WCF
::getUser()->userID
, 'draft');
200 $this->draftCount
= $conversationList->countObjects();
202 if ($this->filter
!= 'hidden' ||
$this->labelID ||
!empty($this->participants
)) {
203 $conversationList = new UserConversationList(WCF
::getUser()->userID
, 'hidden');
204 $this->hiddenCount
= $conversationList->countObjects();
206 if ($this->filter
!= 'outbox' ||
$this->labelID ||
!empty($this->participants
)) {
207 $conversationList = new UserConversationList(WCF
::getUser()->userID
, 'outbox');
208 $this->outboxCount
= $conversationList->countObjects();
215 public function assignVariables() {
216 parent
::assignVariables();
218 WCF
::getTPL()->assign([
219 'filter' => $this->filter
,
220 'hasMarkedItems' => ClipboardHandler
::getInstance()->hasMarkedItems(ClipboardHandler
::getInstance()->getObjectTypeID('com.woltlab.wcf.conversation.conversation')),
221 'labelID' => $this->labelID
,
222 'labelList' => $this->labelList
,
223 'conversationCount' => $this->conversationCount
,
224 'draftCount' => $this->draftCount
,
225 'hiddenCount' => $this->hiddenCount
,
226 'outboxCount' => $this->outboxCount
,
227 'participants' => $this->participants