d06ffc04ff3d5b32dcba48d606f5b62cc14e83c0
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\moderation\queue\report;
3 use wcf\data\comment\response\CommentResponse;
4 use wcf\data\comment\response\CommentResponseAction;
5 use wcf\data\comment\response\CommentResponseList;
6 use wcf\data\comment\response\ViewableCommentResponse;
7 use wcf\data\comment\Comment;
8 use wcf\data\comment\CommentList;
9 use wcf\data\moderation\queue\ModerationQueue;
10 use wcf\data\moderation\queue\ViewableModerationQueue;
11 use wcf\system\database\util\PreparedStatementConditionBuilder;
12 use wcf\system\moderation\queue\ModerationQueueManager;
13 use wcf\system\WCF;
14
15 /**
16 * An implementation of IModerationQueueReportHandler for comment responses.
17 *
18 * @author Alexander Ebert
19 * @copyright 2001-2013 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package com.woltlab.wcf.comment
22 * @subpackage system.moderation.queue
23 * @category Community Framework
24 */
25 class CommentResponseModerationQueueReportHandler extends CommentCommentModerationQueueReportHandler {
26 /**
27 * @see wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
28 */
29 protected $objectType = 'com.woltlab.wcf.comment.response';
30
31 /**
32 * list of comment responses
33 * @var array<wcf\data\comment\response\CommentResponse>
34 */
35 protected static $responses = array();
36
37 /**
38 * @see wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
39 */
40 public function assignQueues(array $queues) {
41 $assignments = array();
42
43 // read comments and responses
44 $responseIDs = array();
45 foreach ($queues as $queue) {
46 $responseIDs[] = $queue->objectID;
47 }
48
49 $conditions = new PreparedStatementConditionBuilder();
50 $conditions->add("comment_response.responseID IN (?)", array($responseIDs));
51
52 $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
53 FROM wcf".WCF_N."_comment_response comment_response
54 LEFT JOIN wcf".WCF_N."_comment comment
55 ON (comment.commentID = comment_response.commentID)
56 ".$conditions;
57 $statement = WCF::getDB()->prepareStatement($sql);
58 $statement->execute($conditions->getParameters());
59 $comments = $responses = array();
60 while ($row = $statement->fetchArray()) {
61 $comments[$row['commentID']] = new Comment(null, $row);
62 $responses[$row['responseID']] = new CommentResponse(null, $row);
63 }
64
65 foreach ($queues as $queue) {
66 $assignUser = false;
67
68 $comment = $comments[$responses[$queue->objectID]->commentID];
69 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
70 $assignUser = true;
71 }
72
73 $assignments[$queue->queueID] = $assignUser;
74 }
75
76 ModerationQueueManager::getInstance()->setAssignment($assignments);
77 }
78
79 /**
80 * @see wcf\system\moderation\queue\report\IModerationQueueReportHandler::canReport()
81 */
82 public function canReport($objectID) {
83 if (!$this->isValid($objectID)) {
84 return false;
85 }
86
87 $response = $this->getResponse($objectID);
88 $comment = $this->getComment($response->commentID);
89 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
90 return false;
91 }
92
93 return true;
94 }
95
96 /**
97 * @see wcf\system\moderation\queue\IModerationQueueHandler::getContainerID()
98 */
99 public function getContainerID($objectID) {
100 return 0;
101 }
102
103 /**
104 * @see wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedContent()
105 */
106 public function getReportedContent(ViewableModerationQueue $queue) {
107 WCF::getTPL()->assign(array(
108 'message' => new ViewableCommentResponse($queue->getAffectedObject())
109 ));
110
111 return WCF::getTPL()->fetch('moderationComment');
112 }
113
114 /**
115 * @see wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
116 */
117 public function getReportedObject($objectID) {
118 if ($this->isValid($objectID)) {
119 return $this->getResponse($objectID);
120 }
121
122 return null;
123 }
124
125 /**
126 * @see wcf\system\moderation\queue\IModerationQueueHandler::isValid()
127 */
128 public function isValid($objectID) {
129 if ($this->getResponse($objectID) === null) {
130 return false;
131 }
132
133 return true;
134 }
135
136 /**
137 * Returns a comment response object by response id or null if response id is invalid.
138 *
139 * @param integer $objectID
140 * @return wcf\data\comment\response\CommentResponse
141 */
142 protected function getResponse($objectID) {
143 if (!array_key_exists($objectID, self::$responses)) {
144 self::$responses[$objectID] = new CommentResponse($objectID);
145 if (!self::$responses[$objectID]->responseID) {
146 self::$responses[$objectID] = null;
147 }
148 }
149
150 return self::$responses[$objectID];
151 }
152
153 /**
154 * @see wcf\system\moderation\queue\IModerationQueueHandler::populate()
155 */
156 public function populate(array $queues) {
157 $objectIDs = array();
158 foreach ($queues as $object) {
159 $objectIDs[] = $object->objectID;
160 }
161
162 // fetch responses
163 $responseList = new CommentResponseList();
164 $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($objectIDs));
165 $responseList->readObjects();
166 $responses = $responseList->getObjects();
167
168 // fetch comments
169 $commentIDs = array();
170 foreach ($responses as $response) {
171 $commentIDs[] = $response->commentID;
172 }
173
174 if (!empty($commentIDs)) {
175 $commentList = new CommentList();
176 $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs));
177 $commentList->readObjects();
178 $comments = $commentList->getObjects();
179 }
180
181 foreach ($queues as $object) {
182 if (isset($responses[$object->objectID])) {
183 $response = $responses[$object->objectID];
184 $response->setComment($comments[$response->commentID]);
185
186 $object->setAffectedObject($response);
187 }
188 else {
189 $object->setIsOrphaned();
190 }
191 }
192 }
193
194 /**
195 * @see wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
196 */
197 public function removeContent(ModerationQueue $queue, $message) {
198 if ($this->isValid($queue->objectID)) {
199 $responseAction = new CommentResponseAction(array($this->getResponse($queue->objectID)), 'delete');
200 $responseAction->executeAction();
201 }
202 }
203 }