Commit | Line | Data |
---|---|---|
9544b6b4 MW |
1 | <?php |
2 | namespace wcf\page; | |
5e279c42 | 3 | use wcf\data\conversation\label\ConversationLabel; |
65f1cc0b | 4 | use wcf\data\conversation\label\ConversationLabelList; |
9544b6b4 | 5 | use wcf\data\conversation\UserConversationList; |
18ec67a4 | 6 | use wcf\system\clipboard\ClipboardHandler; |
5e279c42 | 7 | use wcf\system\exception\IllegalLinkException; |
e298db3c | 8 | use wcf\system\page\PageLocationManager; |
9544b6b4 | 9 | use wcf\system\WCF; |
3d6dd2ed | 10 | use wcf\util\ArrayUtil; |
9544b6b4 MW |
11 | |
12 | /** | |
13 | * Shows a list of conversations. | |
61f754e0 | 14 | * |
9544b6b4 | 15 | * @author Marcel Werk |
4ddaa70e | 16 | * @copyright 2001-2019 WoltLab GmbH |
9544b6b4 | 17 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
c032049e | 18 | * @package WoltLabSuite\Core\Page |
7e95339f MS |
19 | * |
20 | * @property UserConversationList $objectList | |
9544b6b4 MW |
21 | */ |
22 | class ConversationListPage extends SortablePage { | |
23 | /** | |
3d6dd2ed | 24 | * @inheritDoc |
9544b6b4 MW |
25 | */ |
26 | public $defaultSortField = CONVERSATION_LIST_DEFAULT_SORT_FIELD; | |
27 | ||
28 | /** | |
3d6dd2ed | 29 | * @inheritDoc |
9544b6b4 MW |
30 | */ |
31 | public $defaultSortOrder = CONVERSATION_LIST_DEFAULT_SORT_ORDER; | |
32 | ||
33 | /** | |
3d6dd2ed | 34 | * @inheritDoc |
9544b6b4 | 35 | */ |
3d6dd2ed | 36 | public $validSortFields = ['subject', 'time', 'username', 'lastPostTime', 'replies', 'participants']; |
9544b6b4 MW |
37 | |
38 | /** | |
3d6dd2ed | 39 | * @inheritDoc |
9544b6b4 | 40 | */ |
3675ca40 | 41 | public $itemsPerPage = CONVERSATIONS_PER_PAGE; |
9544b6b4 | 42 | |
84e18f05 | 43 | /** |
3d6dd2ed | 44 | * @inheritDoc |
84e18f05 MS |
45 | */ |
46 | public $loginRequired = true; | |
47 | ||
9544b6b4 | 48 | /** |
3d6dd2ed | 49 | * @inheritDoc |
9544b6b4 | 50 | */ |
3d6dd2ed | 51 | public $neededModules = ['MODULE_CONVERSATION']; |
9544b6b4 MW |
52 | |
53 | /** | |
3d6dd2ed | 54 | * @inheritDoc |
9544b6b4 | 55 | */ |
3d6dd2ed | 56 | public $neededPermissions = ['user.conversation.canUseConversation']; |
9544b6b4 MW |
57 | |
58 | /** | |
59 | * list filter | |
61f754e0 | 60 | * @var string |
9544b6b4 MW |
61 | */ |
62 | public $filter = ''; | |
63 | ||
5e279c42 AE |
64 | /** |
65 | * label id | |
66 | * @var integer | |
67 | */ | |
68 | public $labelID = 0; | |
69 | ||
70 | /** | |
71 | * label list object | |
3d6dd2ed | 72 | * @var ConversationLabelList |
5e279c42 | 73 | */ |
09ab08af | 74 | public $labelList; |
5e279c42 | 75 | |
f5406cc8 MS |
76 | /** |
77 | * number of conversations (no filter) | |
78 | * @var integer | |
79 | */ | |
80 | public $conversationCount = 0; | |
81 | ||
82 | /** | |
83 | * number of drafts | |
84 | * @var integer | |
85 | */ | |
86 | public $draftCount = 0; | |
87 | ||
88 | /** | |
89 | * number of hidden conversations | |
90 | * @var integer | |
91 | */ | |
92 | public $hiddenCount = 0; | |
93 | ||
94 | /** | |
95 | * number of sent conversations | |
96 | * @var integer | |
97 | */ | |
98 | public $outboxCount = 0; | |
99 | ||
9544b6b4 | 100 | /** |
3d6dd2ed MS |
101 | * participant that |
102 | * @var string[] | |
103 | */ | |
104 | public $participants = []; | |
105 | ||
106 | /** | |
107 | * @inheritDoc | |
9544b6b4 MW |
108 | */ |
109 | public function readParameters() { | |
110 | parent::readParameters(); | |
111 | ||
112 | if (isset($_REQUEST['filter'])) $this->filter = $_REQUEST['filter']; | |
113 | if (!in_array($this->filter, UserConversationList::$availableFilters)) $this->filter = ''; | |
114 | ||
115 | // user settings | |
b41c9fd6 MS |
116 | /** @noinspection PhpUndefinedFieldInspection */ |
117 | if (WCF::getUser()->conversationsPerPage) { | |
118 | /** @noinspection PhpUndefinedFieldInspection */ | |
119 | $this->itemsPerPage = WCF::getUser()->conversationsPerPage; | |
120 | } | |
5e279c42 AE |
121 | |
122 | // labels | |
123 | $this->labelList = ConversationLabel::getLabelsByUser(); | |
124 | if (isset($_REQUEST['labelID'])) { | |
125 | $this->labelID = intval($_REQUEST['labelID']); | |
126 | ||
127 | $validLabel = false; | |
128 | foreach ($this->labelList as $label) { | |
129 | if ($label->labelID == $this->labelID) { | |
130 | $validLabel = true; | |
131 | break; | |
132 | } | |
133 | } | |
134 | ||
135 | if (!$validLabel) { | |
136 | throw new IllegalLinkException(); | |
137 | } | |
138 | } | |
3d6dd2ed MS |
139 | |
140 | if (isset($_REQUEST['participants'])) $this->participants = ArrayUtil::trim(explode(',', $_REQUEST['participants'])); | |
9544b6b4 MW |
141 | } |
142 | ||
be03f342 | 143 | /** @noinspection PhpMissingParentCallCommonInspection */ |
9544b6b4 | 144 | /** |
3d6dd2ed | 145 | * @inheritDoc |
9544b6b4 MW |
146 | */ |
147 | protected function initObjectList() { | |
72f75266 | 148 | $this->objectList = new UserConversationList(WCF::getUser()->userID, $this->filter, $this->labelID); |
02b42a61 | 149 | $this->objectList->setLabelList($this->labelList); |
3d6dd2ed MS |
150 | |
151 | if (!empty($this->participants)) { | |
152 | $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) = ?)', [ | |
153 | $this->participants, | |
154 | count($this->participants) | |
155 | ]); | |
156 | } | |
9544b6b4 MW |
157 | } |
158 | ||
159 | /** | |
3d6dd2ed | 160 | * @inheritDoc |
9544b6b4 MW |
161 | */ |
162 | public function readData() { | |
f788f251 | 163 | // if sort field is `username`, `conversation.` has to prepended because `username` |
d8838bd9 | 164 | // alone is ambiguous |
f788f251 MS |
165 | if ($this->sortField === 'username') { |
166 | $this->sortField = 'conversation.username'; | |
167 | } | |
168 | ||
9544b6b4 MW |
169 | parent::readData(); |
170 | ||
f788f251 MS |
171 | // change back to old value |
172 | if ($this->sortField === 'conversation.username') { | |
173 | $this->sortField = 'username'; | |
174 | } | |
175 | ||
9544b6b4 | 176 | if ($this->filter != '') { |
2163ec8f MS |
177 | // `-1` = pseudo object id to have to pages with identifier `com.woltlab.wcf.conversation.ConversationList` |
178 | PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.conversation.ConversationList', -1); | |
9544b6b4 | 179 | } |
f5406cc8 MS |
180 | |
181 | // read stats | |
3d6dd2ed | 182 | if (!$this->labelID && empty($this->participants)) { |
f5406cc8 MS |
183 | switch ($this->filter) { |
184 | case '': | |
185 | $this->conversationCount = $this->items; | |
186 | break; | |
187 | ||
188 | case 'draft': | |
189 | $this->draftCount = $this->items; | |
190 | break; | |
191 | ||
192 | case 'hidden': | |
193 | $this->hiddenCount = $this->items; | |
194 | break; | |
195 | ||
196 | case 'outbox': | |
197 | $this->outboxCount = $this->items; | |
198 | break; | |
199 | } | |
200 | } | |
201 | ||
3d6dd2ed | 202 | if ($this->filter != '' || $this->labelID || !empty($this->participants)) { |
f5406cc8 MS |
203 | $conversationList = new UserConversationList(WCF::getUser()->userID, ''); |
204 | $this->conversationCount = $conversationList->countObjects(); | |
205 | } | |
3d6dd2ed | 206 | if ($this->filter != 'draft' || $this->labelID || !empty($this->participants)) { |
f5406cc8 MS |
207 | $conversationList = new UserConversationList(WCF::getUser()->userID, 'draft'); |
208 | $this->draftCount = $conversationList->countObjects(); | |
209 | } | |
3d6dd2ed | 210 | if ($this->filter != 'hidden' || $this->labelID || !empty($this->participants)) { |
f5406cc8 MS |
211 | $conversationList = new UserConversationList(WCF::getUser()->userID, 'hidden'); |
212 | $this->hiddenCount = $conversationList->countObjects(); | |
213 | } | |
3d6dd2ed | 214 | if ($this->filter != 'outbox' || $this->labelID || !empty($this->participants)) { |
f5406cc8 MS |
215 | $conversationList = new UserConversationList(WCF::getUser()->userID, 'outbox'); |
216 | $this->outboxCount = $conversationList->countObjects(); | |
217 | } | |
9544b6b4 MW |
218 | } |
219 | ||
220 | /** | |
3d6dd2ed | 221 | * @inheritDoc |
9544b6b4 MW |
222 | */ |
223 | public function assignVariables() { | |
224 | parent::assignVariables(); | |
225 | ||
3d6dd2ed | 226 | WCF::getTPL()->assign([ |
18ec67a4 | 227 | 'filter' => $this->filter, |
5e279c42 AE |
228 | 'hasMarkedItems' => ClipboardHandler::getInstance()->hasMarkedItems(ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.conversation.conversation')), |
229 | 'labelID' => $this->labelID, | |
f5406cc8 MS |
230 | 'labelList' => $this->labelList, |
231 | 'conversationCount' => $this->conversationCount, | |
232 | 'draftCount' => $this->draftCount, | |
233 | 'hiddenCount' => $this->hiddenCount, | |
3d6dd2ed MS |
234 | 'outboxCount' => $this->outboxCount, |
235 | 'participants' => $this->participants | |
236 | ]); | |
9544b6b4 | 237 | } |
9544b6b4 | 238 | } |