3 namespace wcf\system\moderation\queue;
5 use wcf\data\comment\Comment;
6 use wcf\data\comment\response\CommentResponse;
7 use wcf\data\comment\response\CommentResponseAction;
8 use wcf\data\comment\response\ViewableCommentResponse;
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\cache\runtime\UserProfileRuntimeCache;
14 use wcf\system\database\util\PreparedStatementConditionBuilder;
18 * An implementation of IModerationQueueHandler for comment responses.
20 * @author Alexander Ebert
21 * @copyright 2001-2019 WoltLab GmbH
22 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
24 class AbstractCommentResponseModerationQueueHandler extends AbstractCommentCommentModerationQueueHandler
29 protected $className = CommentResponse::class;
34 protected $objectType = 'com.woltlab.wcf.comment.response';
39 public function assignQueues(array $queues)
43 // read comments and responses
45 foreach ($queues as $queue) {
46 $responseIDs[] = $queue->objectID;
49 $conditions = new PreparedStatementConditionBuilder();
50 $conditions->add("comment_response.responseID IN (?)", [$responseIDs]);
52 $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
53 FROM wcf" . WCF_N . "_comment_response comment_response
54 LEFT JOIN wcf" . WCF_N . "_comment comment
55 ON comment.commentID = comment_response.commentID
57 $statement = WCF::getDB()->prepareStatement($sql);
58 $statement->execute($conditions->getParameters());
59 $comments = $responses = [];
60 while ($row = $statement->fetchArray()) {
61 $comments[$row['commentID']] = new Comment(null, $row);
62 $responses[$row['responseID']] = new CommentResponse(null, $row);
65 $orphanedQueueIDs = [];
66 foreach ($queues as $queue) {
69 if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
70 $orphanedQueueIDs[] = $queue->queueID;
74 $comment = $comments[$responses[$queue->objectID]->commentID];
75 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
79 $assignments[$queue->queueID] = $assignUser;
82 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
83 ModerationQueueManager::getInstance()->setAssignment($assignments);
89 public function getRelatedContent(ViewableModerationQueue $queue)
91 WCF::getTPL()->assign([
92 'message' => ViewableCommentResponse::getResponse($queue->objectID),
95 return WCF::getTPL()->fetch('moderationComment');
101 public function isValid($objectID)
103 if ($this->getResponse($objectID) === null) {
111 * Returns a comment response object by response id or null if response id is invalid.
113 * @param int $objectID
114 * @return CommentResponse|null
116 protected function getResponse($objectID)
118 return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
124 public function populate(array $queues)
127 foreach ($queues as $object) {
128 $objectIDs[] = $object->objectID;
131 $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
134 foreach ($responses as $response) {
135 if ($response !== null) {
136 $commentIDs[] = $response->commentID;
141 if (!empty($commentIDs)) {
142 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
145 foreach ($queues as $object) {
146 if ($responses[$object->objectID] !== null) {
147 $response = $responses[$object->objectID];
148 $response->setComment($comments[$response->commentID]);
150 $object->setAffectedObject($response);
152 $object->setIsOrphaned();
160 public function removeContent(ModerationQueue $queue, $message)
162 if ($this->isValid($queue->objectID)) {
163 $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
164 $responseAction->executeAction();
169 public function isAffectedUser(ModerationQueue $queue, $userID)
171 if (!AbstractModerationQueueHandler::isAffectedUser($queue, $userID)) {
174 $response = $this->getResponse($queue->objectID);
175 if ($response === null) {
178 $comment = $this->getComment($response->commentID);
179 if ($comment === null) {
183 return $this->getCommentManager($comment)->canModerateObject(
184 $comment->objectTypeID,
186 UserProfileRuntimeCache::getInstance()->getObject($userID)