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\comment\manager\ICommentPermissionManager;
15 use wcf\system\database\util\PreparedStatementConditionBuilder;
19 * An implementation of IModerationQueueHandler for comment responses.
21 * @author Alexander Ebert
22 * @copyright 2001-2019 WoltLab GmbH
23 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
25 class AbstractCommentResponseModerationQueueHandler extends AbstractCommentCommentModerationQueueHandler
30 protected $className = CommentResponse::class;
35 protected $objectType = 'com.woltlab.wcf.comment.response';
40 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 getRelatedContent(ViewableModerationQueue $queue)
92 WCF::getTPL()->assign([
93 'message' => ViewableCommentResponse::getResponse($queue->objectID),
96 return WCF::getTPL()->fetch('moderationComment');
102 public function isValid($objectID)
104 if ($this->getResponse($objectID) === null) {
112 * Returns a comment response object by response id or null if response id is invalid.
114 * @param int $objectID
115 * @return CommentResponse|null
117 protected function getResponse($objectID)
119 return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
125 public function populate(array $queues)
128 foreach ($queues as $object) {
129 $objectIDs[] = $object->objectID;
132 $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
135 foreach ($responses as $response) {
136 if ($response !== null) {
137 $commentIDs[] = $response->commentID;
142 if (!empty($commentIDs)) {
143 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
146 foreach ($queues as $object) {
147 if ($responses[$object->objectID] !== null) {
148 $response = $responses[$object->objectID];
149 $response->setComment($comments[$response->commentID]);
151 $object->setAffectedObject($response);
153 $object->setIsOrphaned();
161 public function removeContent(ModerationQueue $queue, $message)
163 if ($this->isValid($queue->objectID)) {
164 $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
165 $responseAction->executeAction();
170 public function isAffectedUser(ModerationQueue $queue, $userID)
172 if (!AbstractModerationQueueHandler::isAffectedUser($queue, $userID)) {
175 $response = $this->getResponse($queue->objectID);
176 if ($response === null) {
179 $comment = $this->getComment($response->commentID);
180 if ($comment === null) {
183 $manager = $this->getCommentManager($comment);
184 if (!($manager instanceof ICommentPermissionManager)) {
188 return $manager->canModerateObject(
189 $comment->objectTypeID,
191 UserProfileRuntimeCache::getInstance()->getObject($userID)