2 namespace wcf\system\moderation\queue\report;
3 use wcf\data\comment\Comment;
4 use wcf\data\comment\CommentAction;
5 use wcf\data\comment\CommentList;
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;
12 use wcf\system\moderation\queue\AbstractModerationQueueHandler;
13 use wcf\system\moderation\queue\ModerationQueueManager;
17 * An implementation of IModerationQueueReportHandler for comments.
19 * @author Alexander Ebert
20 * @copyright 2001-2016 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22 * @package com.woltlab.wcf
23 * @subpackage system.moderation.queue
24 * @category Community Framework
26 class CommentCommentModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
30 protected $className = Comment::class;
35 protected $definitionName = 'com.woltlab.wcf.moderation.report';
40 protected $objectType = 'com.woltlab.wcf.comment.comment';
43 * list of comment managers
44 * @var ICommentManager[]
46 protected static $commentManagers = [];
51 public function assignQueues(array $queues) {
56 foreach ($queues as $queue) {
57 $commentIDs[] = $queue->objectID;
60 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
62 $orphanedQueueIDs = [];
63 foreach ($queues as $queue) {
66 if ($comments[$queue->objectID] === null) {
67 $orphanedQueueIDs[] = $queue->queueID;
71 $comment = $comments[$queue->objectID];
72 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
76 $assignments[$queue->queueID] = $assignUser;
79 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
80 ModerationQueueManager::getInstance()->setAssignment($assignments);
86 public function canReport($objectID) {
87 if (!$this->isValid($objectID)) {
91 $comment = $this->getComment($objectID);
92 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
102 public function getContainerID($objectID) {
109 public function getReportedContent(ViewableModerationQueue $queue) {
110 WCF::getTPL()->assign([
111 'message' => ViewableComment::getComment($queue->objectID)
114 return WCF::getTPL()->fetch('moderationComment');
120 public function getReportedObject($objectID) {
121 return $this->getComment($objectID);
127 public function isValid($objectID) {
128 if ($this->getComment($objectID) === null) {
136 * Returns a comment object by comment id or null if comment id is invalid.
138 * @param integer $objectID
139 * @return Comment|null
141 protected function getComment($objectID) {
142 return CommentRuntimeCache::getInstance()->getObject($objectID);
146 * Returns a comment manager for given comment.
148 * @param Comment $comment
149 * @return ICommentManager
151 protected function getCommentManager(Comment $comment) {
152 if (!isset(self::$commentManagers[$comment->objectTypeID])) {
153 self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
156 return self::$commentManagers[$comment->objectTypeID];
162 public function populate(array $queues) {
164 foreach ($queues as $object) {
165 $objectIDs[] = $object->objectID;
169 $comments = CommentRuntimeCache::getInstance()->getObjects($objectIDs);
170 foreach ($queues as $object) {
171 if ($comments[$object->objectID] !== null) {
172 $object->setAffectedObject($comments[$object->objectID]);
175 $object->setIsOrphaned();
183 public function removeContent(ModerationQueue $queue, $message) {
184 if ($this->isValid($queue->objectID)) {
185 $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'delete');
186 $commentAction->executeAction();