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\ViewableCommentResponse;
6 use wcf\data\comment\Comment;
7 use wcf\data\moderation\queue\ModerationQueue;
8 use wcf\data\moderation\queue\ViewableModerationQueue;
9 use wcf\system\cache\runtime\CommentResponseRuntimeCache;
10 use wcf\system\cache\runtime\CommentRuntimeCache;
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-2016 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 {
29 protected $className = CommentResponse::class;
34 protected $objectType = 'com.woltlab.wcf.comment.response';
39 public function assignQueues(array $queues) {
42 // read comments and responses
44 foreach ($queues as $queue) {
45 $responseIDs[] = $queue->objectID;
48 $conditions = new PreparedStatementConditionBuilder();
49 $conditions->add("comment_response.responseID IN (?)", [$responseIDs]);
51 $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
52 FROM wcf".WCF_N."_comment_response comment_response
53 LEFT JOIN wcf".WCF_N."_comment comment
54 ON (comment.commentID = comment_response.commentID)
56 $statement = WCF::getDB()->prepareStatement($sql);
57 $statement->execute($conditions->getParameters());
58 $comments = $responses = [];
59 while ($row = $statement->fetchArray()) {
60 $comments[$row['commentID']] = new Comment(null, $row);
61 $responses[$row['responseID']] = new CommentResponse(null, $row);
64 $orphanedQueueIDs = [];
65 foreach ($queues as $queue) {
68 if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
69 $orphanedQueueIDs[] = $queue->queueID;
73 $comment = $comments[$responses[$queue->objectID]->commentID];
74 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
78 $assignments[$queue->queueID] = $assignUser;
81 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
82 ModerationQueueManager::getInstance()->setAssignment($assignments);
88 public function canReport($objectID) {
89 if (!$this->isValid($objectID)) {
93 $response = $this->getResponse($objectID);
94 $comment = $this->getComment($response->commentID);
95 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
105 public function getContainerID($objectID) {
112 public function getReportedContent(ViewableModerationQueue $queue) {
113 WCF::getTPL()->assign([
114 'message' => ViewableCommentResponse::getResponse($queue->objectID)
117 return WCF::getTPL()->fetch('moderationComment');
123 public function getReportedObject($objectID) {
124 return $this->getResponse($objectID);
130 public function isValid($objectID) {
131 if ($this->getResponse($objectID) === null) {
139 * Returns a comment response object by response id or null if response id is invalid.
141 * @param integer $objectID
142 * @return CommentResponse|null
144 protected function getResponse($objectID) {
145 return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
151 public function populate(array $queues) {
153 foreach ($queues as $object) {
154 $objectIDs[] = $object->objectID;
157 $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
160 foreach ($responses as $response) {
161 if ($response !== null) {
162 $commentIDs[] = $response->commentID;
167 if (!empty($commentIDs)) {
168 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
171 foreach ($queues as $object) {
172 if ($responses[$object->objectID] !== null) {
173 $response = $responses[$object->objectID];
174 $response->setComment($comments[$response->commentID]);
176 $object->setAffectedObject($response);
179 $object->setIsOrphaned();
187 public function removeContent(ModerationQueue $queue, $message) {
188 if ($this->isValid($queue->objectID)) {
189 $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
190 $responseAction->executeAction();