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;
16 * An implementation of IModerationQueueReportHandler for comment responses.
18 * @author Alexander Ebert
19 * @copyright 2001-2015 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package com.woltlab.wcf
22 * @subpackage system.moderation.queue
23 * @category Community Framework
25 class CommentResponseModerationQueueReportHandler extends CommentCommentModerationQueueReportHandler {
27 * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$className
29 protected $className = 'wcf\data\comment\response\CommentResponse';
32 * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
34 protected $objectType = 'com.woltlab.wcf.comment.response';
37 * list of comment responses
38 * @var array<\wcf\data\comment\response\CommentResponse>
40 protected static $responses = array();
43 * @see \wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
45 public function assignQueues(array $queues) {
46 $assignments = array();
48 // read comments and responses
49 $responseIDs = array();
50 foreach ($queues as $queue) {
51 $responseIDs[] = $queue->objectID;
54 $conditions = new PreparedStatementConditionBuilder();
55 $conditions->add("comment_response.responseID IN (?)", array($responseIDs));
57 $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
58 FROM wcf".WCF_N."_comment_response comment_response
59 LEFT JOIN wcf".WCF_N."_comment comment
60 ON (comment.commentID = comment_response.commentID)
62 $statement = WCF::getDB()->prepareStatement($sql);
63 $statement->execute($conditions->getParameters());
64 $comments = $responses = array();
65 while ($row = $statement->fetchArray()) {
66 $comments[$row['commentID']] = new Comment(null, $row);
67 $responses[$row['responseID']] = new CommentResponse(null, $row);
70 $orphanedQueueIDs = array();
71 foreach ($queues as $queue) {
74 if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
75 $orphanedQueueIDs[] = $queue->queueID;
79 $comment = $comments[$responses[$queue->objectID]->commentID];
80 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
84 $assignments[$queue->queueID] = $assignUser;
87 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
88 ModerationQueueManager::getInstance()->setAssignment($assignments);
92 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::canReport()
94 public function canReport($objectID) {
95 if (!$this->isValid($objectID)) {
99 $response = $this->getResponse($objectID);
100 $comment = $this->getComment($response->commentID);
101 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
109 * @see \wcf\system\moderation\queue\IModerationQueueHandler::getContainerID()
111 public function getContainerID($objectID) {
116 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedContent()
118 public function getReportedContent(ViewableModerationQueue $queue) {
119 WCF::getTPL()->assign(array(
120 'message' => ViewableCommentResponse::getResponse($queue->objectID)
123 return WCF::getTPL()->fetch('moderationComment');
127 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
129 public function getReportedObject($objectID) {
130 return $this->getResponse($objectID);
134 * @see \wcf\system\moderation\queue\IModerationQueueHandler::isValid()
136 public function isValid($objectID) {
137 if ($this->getResponse($objectID) === null) {
145 * Returns a comment response object by response id or null if response id is invalid.
147 * @param integer $objectID
148 * @return \wcf\data\comment\response\CommentResponse
150 protected function getResponse($objectID) {
151 if (!array_key_exists($objectID, self::$responses)) {
152 self::$responses[$objectID] = new CommentResponse($objectID);
153 if (!self::$responses[$objectID]->responseID) {
154 self::$responses[$objectID] = null;
158 return self::$responses[$objectID];
162 * @see \wcf\system\moderation\queue\IModerationQueueHandler::populate()
164 public function populate(array $queues) {
165 $objectIDs = array();
166 foreach ($queues as $object) {
167 $objectIDs[] = $object->objectID;
171 $responseList = new CommentResponseList();
172 $responseList->setObjectIDs($objectIDs);
173 $responseList->readObjects();
174 $responses = $responseList->getObjects();
177 $commentIDs = array();
178 foreach ($responses as $response) {
179 $commentIDs[] = $response->commentID;
182 if (!empty($commentIDs)) {
183 $commentList = new CommentList();
184 $commentList->setObjectIDs($commentIDs);
185 $commentList->readObjects();
186 $comments = $commentList->getObjects();
189 foreach ($queues as $object) {
190 if (isset($responses[$object->objectID])) {
191 $response = $responses[$object->objectID];
192 $response->setComment($comments[$response->commentID]);
194 $object->setAffectedObject($response);
197 $object->setIsOrphaned();
203 * @see \wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
205 public function removeContent(ModerationQueue $queue, $message) {
206 if ($this->isValid($queue->objectID)) {
207 $responseAction = new CommentResponseAction(array($this->getResponse($queue->objectID)), 'delete');
208 $responseAction->executeAction();