2 declare(strict_types=1);
3 namespace wcf\system\moderation\queue;
4 use wcf\data\comment\Comment;
5 use wcf\data\comment\CommentAction;
6 use wcf\data\comment\ViewableComment;
7 use wcf\data\moderation\queue\ModerationQueue;
8 use wcf\data\moderation\queue\ViewableModerationQueue;
9 use wcf\data\object\type\ObjectTypeCache;
10 use wcf\system\cache\runtime\CommentRuntimeCache;
11 use wcf\system\comment\manager\ICommentManager;
15 * An abstract implementation of IModerationQueueHandler for comments.
17 * @author Alexander Ebert
18 * @copyright 2001-2018 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Core\System\Moderation\Queue
22 class AbstractCommentCommentModerationQueueHandler extends AbstractModerationQueueHandler {
26 protected $className = Comment::class;
31 protected $objectType = 'com.woltlab.wcf.comment.comment';
34 * list of comment managers
35 * @var ICommentManager[]
37 protected static $commentManagers = [];
42 public function assignQueues(array $queues) {
47 foreach ($queues as $queue) {
48 $commentIDs[] = $queue->objectID;
51 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
53 $orphanedQueueIDs = [];
54 foreach ($queues as $queue) {
57 if ($comments[$queue->objectID] === null) {
58 $orphanedQueueIDs[] = $queue->queueID;
62 $comment = $comments[$queue->objectID];
63 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
67 $assignments[$queue->queueID] = $assignUser;
70 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
71 ModerationQueueManager::getInstance()->setAssignment($assignments);
77 public function getContainerID($objectID) {
84 public function isValid($objectID) {
85 if ($this->getComment($objectID) === null) {
93 * Returns a comment object by comment id or null if comment id is invalid.
95 * @param integer $objectID
96 * @return Comment|null
98 protected function getComment($objectID) {
99 return CommentRuntimeCache::getInstance()->getObject($objectID);
103 * Returns a comment manager for given comment.
105 * @param Comment $comment
106 * @return ICommentManager
108 protected function getCommentManager(Comment $comment) {
109 if (!isset(self::$commentManagers[$comment->objectTypeID])) {
110 self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
113 return self::$commentManagers[$comment->objectTypeID];
119 public function populate(array $queues) {
121 foreach ($queues as $object) {
122 $objectIDs[] = $object->objectID;
126 $comments = CommentRuntimeCache::getInstance()->getObjects($objectIDs);
127 foreach ($queues as $object) {
128 if ($comments[$object->objectID] !== null) {
129 $object->setAffectedObject($comments[$object->objectID]);
132 $object->setIsOrphaned();
140 public function removeContent(ModerationQueue $queue, $message) {
141 if ($this->isValid($queue->objectID)) {
142 $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'delete');
143 $commentAction->executeAction();
148 * Returns the parsed template for the target comment.
150 * @param ViewableModerationQueue $queue
153 protected function getRelatedContent(ViewableModerationQueue $queue) {
154 WCF::getTPL()->assign([
155 'message' => ViewableComment::getComment($queue->objectID)
158 return WCF::getTPL()->fetch('moderationComment');