2 namespace wcf\system\moderation\queue\report;
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;
11 use wcf\system\moderation\queue\AbstractModerationQueueHandler;
12 use wcf\system\moderation\queue\ModerationQueueManager;
16 * An implementation of IModerationQueueReportHandler for comments.
18 * @author Alexander Ebert
19 * @copyright 2001-2016 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package com.woltlab.wcf
22 * @subpackage system.moderation.queue
23 * @category Community Framework
25 class CommentCommentModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
29 protected $className = Comment::class;
34 protected $definitionName = 'com.woltlab.wcf.moderation.report';
39 protected $objectType = 'com.woltlab.wcf.comment.comment';
42 * list of comment managers
43 * @var ICommentManager[]
45 protected static $commentManagers = [];
50 public function assignQueues(array $queues) {
55 foreach ($queues as $queue) {
56 $commentIDs[] = $queue->objectID;
59 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
61 $orphanedQueueIDs = [];
62 foreach ($queues as $queue) {
65 if ($comments[$queue->objectID] === null) {
66 $orphanedQueueIDs[] = $queue->queueID;
70 $comment = $comments[$queue->objectID];
71 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
75 $assignments[$queue->queueID] = $assignUser;
78 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
79 ModerationQueueManager::getInstance()->setAssignment($assignments);
85 public function canReport($objectID) {
86 if (!$this->isValid($objectID)) {
90 $comment = $this->getComment($objectID);
91 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
101 public function getContainerID($objectID) {
108 public function getReportedContent(ViewableModerationQueue $queue) {
109 WCF::getTPL()->assign([
110 'message' => ViewableComment::getComment($queue->objectID)
113 return WCF::getTPL()->fetch('moderationComment');
119 public function getReportedObject($objectID) {
120 return $this->getComment($objectID);
126 public function isValid($objectID) {
127 if ($this->getComment($objectID) === null) {
135 * Returns a comment object by comment id or null if comment id is invalid.
137 * @param integer $objectID
138 * @return Comment|null
140 protected function getComment($objectID) {
141 return CommentRuntimeCache::getInstance()->getObject($objectID);
145 * Returns a comment manager for given comment.
147 * @param Comment $comment
148 * @return ICommentManager
150 protected function getCommentManager(Comment $comment) {
151 if (!isset(self::$commentManagers[$comment->objectTypeID])) {
152 self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
155 return self::$commentManagers[$comment->objectTypeID];
161 public function populate(array $queues) {
163 foreach ($queues as $object) {
164 $objectIDs[] = $object->objectID;
168 $comments = CommentRuntimeCache::getInstance()->getObjects($objectIDs);
169 foreach ($queues as $object) {
170 if ($comments[$object->objectID] !== null) {
171 $object->setAffectedObject($comments[$object->objectID]);
174 $object->setIsOrphaned();
182 public function removeContent(ModerationQueue $queue, $message) {
183 if ($this->isValid($queue->objectID)) {
184 $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'delete');
185 $commentAction->executeAction();