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\cache\runtime\CommentResponseRuntimeCache;
12 use wcf\system\cache\runtime\CommentRuntimeCache;
13 use wcf\system\database\util\PreparedStatementConditionBuilder;
14 use wcf\system\moderation\queue\ModerationQueueManager;
18 * An implementation of IModerationQueueReportHandler for comment responses.
20 * @author Alexander Ebert
21 * @copyright 2001-2016 WoltLab GmbH
22 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
23 * @package com.woltlab.wcf
24 * @subpackage system.moderation.queue
25 * @category Community Framework
27 class CommentResponseModerationQueueReportHandler extends CommentCommentModerationQueueReportHandler {
31 protected $className = CommentResponse::class;
36 protected $objectType = 'com.woltlab.wcf.comment.response';
41 public function assignQueues(array $queues) {
44 // read comments and responses
46 foreach ($queues as $queue) {
47 $responseIDs[] = $queue->objectID;
50 $conditions = new PreparedStatementConditionBuilder();
51 $conditions->add("comment_response.responseID IN (?)", [$responseIDs]);
53 $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
54 FROM wcf".WCF_N."_comment_response comment_response
55 LEFT JOIN wcf".WCF_N."_comment comment
56 ON (comment.commentID = comment_response.commentID)
58 $statement = WCF::getDB()->prepareStatement($sql);
59 $statement->execute($conditions->getParameters());
60 $comments = $responses = [];
61 while ($row = $statement->fetchArray()) {
62 $comments[$row['commentID']] = new Comment(null, $row);
63 $responses[$row['responseID']] = new CommentResponse(null, $row);
66 $orphanedQueueIDs = [];
67 foreach ($queues as $queue) {
70 if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
71 $orphanedQueueIDs[] = $queue->queueID;
75 $comment = $comments[$responses[$queue->objectID]->commentID];
76 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
80 $assignments[$queue->queueID] = $assignUser;
83 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
84 ModerationQueueManager::getInstance()->setAssignment($assignments);
90 public function canReport($objectID) {
91 if (!$this->isValid($objectID)) {
95 $response = $this->getResponse($objectID);
96 $comment = $this->getComment($response->commentID);
97 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
107 public function getContainerID($objectID) {
114 public function getReportedContent(ViewableModerationQueue $queue) {
115 WCF::getTPL()->assign([
116 'message' => ViewableCommentResponse::getResponse($queue->objectID)
119 return WCF::getTPL()->fetch('moderationComment');
125 public function getReportedObject($objectID) {
126 return $this->getResponse($objectID);
132 public function isValid($objectID) {
133 if ($this->getResponse($objectID) === null) {
141 * Returns a comment response object by response id or null if response id is invalid.
143 * @param integer $objectID
144 * @return CommentResponse|null
146 protected function getResponse($objectID) {
147 return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
153 public function populate(array $queues) {
155 foreach ($queues as $object) {
156 $objectIDs[] = $object->objectID;
159 $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
162 foreach ($responses as $response) {
163 if ($response !== null) {
164 $commentIDs[] = $response->commentID;
168 if (!empty($commentIDs)) {
169 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
172 foreach ($queues as $object) {
173 if ($responses[$object->objectID] !== null) {
174 $response = $responses[$object->objectID];
175 $response->setComment($comments[$response->commentID]);
177 $object->setAffectedObject($response);
180 $object->setIsOrphaned();
188 public function removeContent(ModerationQueue $queue, $message) {
189 if ($this->isValid($queue->objectID)) {
190 $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
191 $responseAction->executeAction();