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 WoltLabSuite\Core\System\Moderation\Queue
23 class CommentResponseModerationQueueReportHandler extends CommentCommentModerationQueueReportHandler {
27 protected $className = CommentResponse::class;
32 protected $objectType = 'com.woltlab.wcf.comment.response';
37 public function assignQueues(array $queues) {
40 // read comments and responses
42 foreach ($queues as $queue) {
43 $responseIDs[] = $queue->objectID;
46 $conditions = new PreparedStatementConditionBuilder();
47 $conditions->add("comment_response.responseID IN (?)", [$responseIDs]);
49 $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
50 FROM wcf".WCF_N."_comment_response comment_response
51 LEFT JOIN wcf".WCF_N."_comment comment
52 ON (comment.commentID = comment_response.commentID)
54 $statement = WCF::getDB()->prepareStatement($sql);
55 $statement->execute($conditions->getParameters());
56 $comments = $responses = [];
57 while ($row = $statement->fetchArray()) {
58 $comments[$row['commentID']] = new Comment(null, $row);
59 $responses[$row['responseID']] = new CommentResponse(null, $row);
62 $orphanedQueueIDs = [];
63 foreach ($queues as $queue) {
66 if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
67 $orphanedQueueIDs[] = $queue->queueID;
71 $comment = $comments[$responses[$queue->objectID]->commentID];
72 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
76 $assignments[$queue->queueID] = $assignUser;
79 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
80 ModerationQueueManager::getInstance()->setAssignment($assignments);
86 public function canReport($objectID) {
87 if (!$this->isValid($objectID)) {
91 $response = $this->getResponse($objectID);
92 $comment = $this->getComment($response->commentID);
93 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
103 public function getContainerID($objectID) {
110 public function getReportedContent(ViewableModerationQueue $queue) {
111 WCF::getTPL()->assign([
112 'message' => ViewableCommentResponse::getResponse($queue->objectID)
115 return WCF::getTPL()->fetch('moderationComment');
121 public function getReportedObject($objectID) {
122 return $this->getResponse($objectID);
128 public function isValid($objectID) {
129 if ($this->getResponse($objectID) === null) {
137 * Returns a comment response object by response id or null if response id is invalid.
139 * @param integer $objectID
140 * @return CommentResponse|null
142 protected function getResponse($objectID) {
143 return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
149 public function populate(array $queues) {
151 foreach ($queues as $object) {
152 $objectIDs[] = $object->objectID;
155 $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
158 foreach ($responses as $response) {
159 if ($response !== null) {
160 $commentIDs[] = $response->commentID;
165 if (!empty($commentIDs)) {
166 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
169 foreach ($queues as $object) {
170 if ($responses[$object->objectID] !== null) {
171 $response = $responses[$object->objectID];
172 $response->setComment($comments[$response->commentID]);
174 $object->setAffectedObject($response);
177 $object->setIsOrphaned();
185 public function removeContent(ModerationQueue $queue, $message) {
186 if ($this->isValid($queue->objectID)) {
187 $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
188 $responseAction->executeAction();