3 namespace wcf\system\moderation\queue;
5 use wcf\data\comment\Comment;
6 use wcf\data\comment\CommentAction;
7 use wcf\data\comment\ViewableComment;
8 use wcf\data\moderation\queue\ModerationQueue;
9 use wcf\data\moderation\queue\ViewableModerationQueue;
10 use wcf\data\object\type\ObjectTypeCache;
11 use wcf\system\cache\runtime\CommentRuntimeCache;
12 use wcf\system\cache\runtime\UserProfileRuntimeCache;
13 use wcf\system\comment\manager\ICommentManager;
17 * An abstract implementation of IModerationQueueHandler for comments.
19 * @author Alexander Ebert
20 * @copyright 2001-2019 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
23 class AbstractCommentCommentModerationQueueHandler extends AbstractModerationQueueHandler
28 protected $className = Comment::class;
33 protected $objectType = 'com.woltlab.wcf.comment.comment';
36 * list of comment managers
37 * @var ICommentManager[]
39 protected static $commentManagers = [];
44 public function assignQueues(array $queues)
50 foreach ($queues as $queue) {
51 $commentIDs[] = $queue->objectID;
54 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
56 $orphanedQueueIDs = [];
57 foreach ($queues as $queue) {
60 if ($comments[$queue->objectID] === null) {
61 $orphanedQueueIDs[] = $queue->queueID;
65 $comment = $comments[$queue->objectID];
66 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
70 $assignments[$queue->queueID] = $assignUser;
73 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
74 ModerationQueueManager::getInstance()->setAssignment($assignments);
80 public function getContainerID($objectID)
88 public function isValid($objectID)
90 if ($this->getComment($objectID) === null) {
98 * Returns a comment object by comment id or null if comment id is invalid.
100 * @param int $objectID
101 * @return Comment|null
103 protected function getComment($objectID)
105 return CommentRuntimeCache::getInstance()->getObject($objectID);
109 * Returns a comment manager for given comment.
111 * @param Comment $comment
112 * @return ICommentManager
114 protected function getCommentManager(Comment $comment)
116 if (!isset(self::$commentManagers[$comment->objectTypeID])) {
117 self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()
118 ->getObjectType($comment->objectTypeID)
122 return self::$commentManagers[$comment->objectTypeID];
128 public function populate(array $queues)
131 foreach ($queues as $object) {
132 $objectIDs[] = $object->objectID;
136 $comments = CommentRuntimeCache::getInstance()->getObjects($objectIDs);
137 foreach ($queues as $object) {
138 if ($comments[$object->objectID] !== null) {
139 $object->setAffectedObject($comments[$object->objectID]);
141 $object->setIsOrphaned();
149 public function removeContent(ModerationQueue $queue, $message)
151 if ($this->isValid($queue->objectID)) {
152 $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'delete');
153 $commentAction->executeAction();
158 * Returns the parsed template for the target comment.
160 * @param ViewableModerationQueue $queue
163 protected function getRelatedContent(ViewableModerationQueue $queue)
165 WCF::getTPL()->assign([
166 'message' => ViewableComment::getComment($queue->objectID),
169 return WCF::getTPL()->fetch('moderationComment');
173 public function isAffectedUser(ModerationQueue $queue, $userID)
175 if (!parent::isAffectedUser($queue, $userID)) {
178 $comment = $this->getComment($queue->objectID);
179 if ($comment === null) {
183 return $this->getCommentManager($comment)->canModerateObject(
184 $comment->objectTypeID,
186 UserProfileRuntimeCache::getInstance()->getObject($userID)