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 WoltLabSuite\Core\System\Moderation\Queue
23 class CommentCommentModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
27 protected $className = Comment::class;
32 protected $definitionName = 'com.woltlab.wcf.moderation.report';
37 protected $objectType = 'com.woltlab.wcf.comment.comment';
40 * list of comment managers
41 * @var ICommentManager[]
43 protected static $commentManagers = [];
48 public function assignQueues(array $queues) {
53 foreach ($queues as $queue) {
54 $commentIDs[] = $queue->objectID;
57 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
59 $orphanedQueueIDs = [];
60 foreach ($queues as $queue) {
63 if ($comments[$queue->objectID] === null) {
64 $orphanedQueueIDs[] = $queue->queueID;
68 $comment = $comments[$queue->objectID];
69 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
73 $assignments[$queue->queueID] = $assignUser;
76 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
77 ModerationQueueManager::getInstance()->setAssignment($assignments);
83 public function canReport($objectID) {
84 if (!$this->isValid($objectID)) {
88 $comment = $this->getComment($objectID);
89 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
99 public function getContainerID($objectID) {
106 public function getReportedContent(ViewableModerationQueue $queue) {
107 WCF::getTPL()->assign([
108 'message' => ViewableComment::getComment($queue->objectID)
111 return WCF::getTPL()->fetch('moderationComment');
117 public function getReportedObject($objectID) {
118 return $this->getComment($objectID);
124 public function isValid($objectID) {
125 if ($this->getComment($objectID) === null) {
133 * Returns a comment object by comment id or null if comment id is invalid.
135 * @param integer $objectID
136 * @return Comment|null
138 protected function getComment($objectID) {
139 return CommentRuntimeCache::getInstance()->getObject($objectID);
143 * Returns a comment manager for given comment.
145 * @param Comment $comment
146 * @return ICommentManager
148 protected function getCommentManager(Comment $comment) {
149 if (!isset(self::$commentManagers[$comment->objectTypeID])) {
150 self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
153 return self::$commentManagers[$comment->objectTypeID];
159 public function populate(array $queues) {
161 foreach ($queues as $object) {
162 $objectIDs[] = $object->objectID;
166 $comments = CommentRuntimeCache::getInstance()->getObjects($objectIDs);
167 foreach ($queues as $object) {
168 if ($comments[$object->objectID] !== null) {
169 $object->setAffectedObject($comments[$object->objectID]);
172 $object->setIsOrphaned();
180 public function removeContent(ModerationQueue $queue, $message) {
181 if ($this->isValid($queue->objectID)) {
182 $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'delete');
183 $commentAction->executeAction();