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-2013 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' => new ViewableCommentResponse($queue->getAffectedObject())
123 return WCF::getTPL()->fetch('moderationComment');
127 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
129 public function getReportedObject($objectID) {
130 if ($this->isValid($objectID)) {
131 return $this->getResponse($objectID);
138 * @see \wcf\system\moderation\queue\IModerationQueueHandler::isValid()
140 public function isValid($objectID) {
141 if ($this->getResponse($objectID) === null) {
149 * Returns a comment response object by response id or null if response id is invalid.
151 * @param integer $objectID
152 * @return \wcf\data\comment\response\CommentResponse
154 protected function getResponse($objectID) {
155 if (!array_key_exists($objectID, self::$responses)) {
156 self::$responses[$objectID] = new CommentResponse($objectID);
157 if (!self::$responses[$objectID]->responseID) {
158 self::$responses[$objectID] = null;
162 return self::$responses[$objectID];
166 * @see \wcf\system\moderation\queue\IModerationQueueHandler::populate()
168 public function populate(array $queues) {
169 $objectIDs = array();
170 foreach ($queues as $object) {
171 $objectIDs[] = $object->objectID;
175 $responseList = new CommentResponseList();
176 $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($objectIDs));
177 $responseList->readObjects();
178 $responses = $responseList->getObjects();
181 $commentIDs = array();
182 foreach ($responses as $response) {
183 $commentIDs[] = $response->commentID;
186 if (!empty($commentIDs)) {
187 $commentList = new CommentList();
188 $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs));
189 $commentList->readObjects();
190 $comments = $commentList->getObjects();
193 foreach ($queues as $object) {
194 if (isset($responses[$object->objectID])) {
195 $response = $responses[$object->objectID];
196 $response->setComment($comments[$response->commentID]);
198 $object->setAffectedObject($response);
201 $object->setIsOrphaned();
207 * @see \wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
209 public function removeContent(ModerationQueue $queue, $message) {
210 if ($this->isValid($queue->objectID)) {
211 $responseAction = new CommentResponseAction(array($this->getResponse($queue->objectID)), 'delete');
212 $responseAction->executeAction();