2 namespace wcf\system\moderation\queue;
3 use wcf\data\comment\Comment;
4 use wcf\data\comment\CommentAction;
5 use wcf\data\comment\ViewableComment;
6 use wcf\data\moderation\queue\ModerationQueue;
7 use wcf\data\moderation\queue\ViewableModerationQueue;
8 use wcf\data\object\type\ObjectTypeCache;
9 use wcf\system\cache\runtime\CommentRuntimeCache;
10 use wcf\system\comment\manager\ICommentManager;
14 * An abstract implementation of IModerationQueueHandler for comments.
16 * @author Alexander Ebert
17 * @copyright 2001-2018 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package WoltLabSuite\Core\System\Moderation\Queue
21 class AbstractCommentCommentModerationQueueHandler extends AbstractModerationQueueHandler {
25 protected $className = Comment::class;
30 protected $objectType = 'com.woltlab.wcf.comment.comment';
33 * list of comment managers
34 * @var ICommentManager[]
36 protected static $commentManagers = [];
41 public function assignQueues(array $queues) {
46 foreach ($queues as $queue) {
47 $commentIDs[] = $queue->objectID;
50 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
52 $orphanedQueueIDs = [];
53 foreach ($queues as $queue) {
56 if ($comments[$queue->objectID] === null) {
57 $orphanedQueueIDs[] = $queue->queueID;
61 $comment = $comments[$queue->objectID];
62 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
66 $assignments[$queue->queueID] = $assignUser;
69 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
70 ModerationQueueManager::getInstance()->setAssignment($assignments);
76 public function getContainerID($objectID) {
83 public function isValid($objectID) {
84 if ($this->getComment($objectID) === null) {
92 * Returns a comment object by comment id or null if comment id is invalid.
94 * @param integer $objectID
95 * @return Comment|null
97 protected function getComment($objectID) {
98 return CommentRuntimeCache::getInstance()->getObject($objectID);
102 * Returns a comment manager for given comment.
104 * @param Comment $comment
105 * @return ICommentManager
107 protected function getCommentManager(Comment $comment) {
108 if (!isset(self::$commentManagers[$comment->objectTypeID])) {
109 self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
112 return self::$commentManagers[$comment->objectTypeID];
118 public function populate(array $queues) {
120 foreach ($queues as $object) {
121 $objectIDs[] = $object->objectID;
125 $comments = CommentRuntimeCache::getInstance()->getObjects($objectIDs);
126 foreach ($queues as $object) {
127 if ($comments[$object->objectID] !== null) {
128 $object->setAffectedObject($comments[$object->objectID]);
131 $object->setIsOrphaned();
139 public function removeContent(ModerationQueue $queue, $message) {
140 if ($this->isValid($queue->objectID)) {
141 $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'delete');
142 $commentAction->executeAction();
147 * Returns the parsed template for the target comment.
149 * @param ViewableModerationQueue $queue
152 protected function getRelatedContent(ViewableModerationQueue $queue) {
153 WCF::getTPL()->assign([
154 'message' => ViewableComment::getComment($queue->objectID)
157 return WCF::getTPL()->fetch('moderationComment');