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\database\util\PreparedStatementConditionBuilder;
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-2013 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 {
27 * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$className
29 protected $className = 'wcf\data\comment\Comment';
32 * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$definitionName
34 protected $definitionName = 'com.woltlab.wcf.moderation.report';
37 * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
39 protected $objectType = 'com.woltlab.wcf.comment.comment';
43 * @var array<\wcf\data\comment\Comment>
45 protected static $comments = array();
48 * list of comment managers
49 * @var array<\wcf\system\comment\manager\ICommentManager>
51 protected static $commentManagers = array();
54 * @see \wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
56 public function assignQueues(array $queues) {
57 $assignments = array();
60 $commentIDs = array();
61 foreach ($queues as $queue) {
62 $commentIDs[] = $queue->objectID;
65 $conditions = new PreparedStatementConditionBuilder();
66 $conditions->add("commentID IN (?)", array($commentIDs));
68 $sql = "SELECT commentID, objectTypeID, objectID
69 FROM wcf".WCF_N."_comment
71 $statement = WCF::getDB()->prepareStatement($sql);
72 $statement->execute($conditions->getParameters());
74 while ($row = $statement->fetchArray()) {
75 $comments[$row['commentID']] = new Comment(null, $row);
78 $orphanedQueueIDs = array();
79 foreach ($queues as $queue) {
82 if (!isset($comments[$queue->objectID])) {
83 $orphanedQueueIDs[] = $queue->queueID;
87 $comment = $comments[$queue->objectID];
88 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
92 $assignments[$queue->queueID] = $assignUser;
95 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
96 ModerationQueueManager::getInstance()->setAssignment($assignments);
100 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::canReport()
102 public function canReport($objectID) {
103 if (!$this->isValid($objectID)) {
107 $comment = $this->getComment($objectID);
108 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
116 * @see \wcf\system\moderation\queue\IModerationQueueHandler::getContainerID()
118 public function getContainerID($objectID) {
123 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedContent()
125 public function getReportedContent(ViewableModerationQueue $queue) {
126 WCF::getTPL()->assign(array(
127 'message' => new ViewableComment($queue->getAffectedObject())
130 return WCF::getTPL()->fetch('moderationComment');
134 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
136 public function getReportedObject($objectID) {
137 if ($this->isValid($objectID)) {
138 return $this->getComment($objectID);
145 * @see \wcf\system\moderation\queue\IModerationQueueHandler::isValid()
147 public function isValid($objectID) {
148 if ($this->getComment($objectID) === null) {
156 * Returns a comment object by comment id or null if comment id is invalid.
158 * @param integer $objectID
159 * @return \wcf\data\comment\Comment
161 protected function getComment($objectID) {
162 if (!array_key_exists($objectID, self::$comments)) {
163 self::$comments[$objectID] = new Comment($objectID);
164 if (!self::$comments[$objectID]->commentID) {
165 self::$comments[$objectID] = null;
169 return self::$comments[$objectID];
173 * Returns a comment manager for given comment.
175 * @param \wcf\data\comment\Comment $comment
176 * @return \wcf\system\comment\manager\ICommentManager
178 protected function getCommentManager(Comment $comment) {
179 if (!isset(self::$commentManagers[$comment->objectTypeID])) {
180 self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
183 return self::$commentManagers[$comment->objectTypeID];
187 * @see \wcf\system\moderation\queue\IModerationQueueHandler::populate()
189 public function populate(array $queues) {
190 $objectIDs = array();
191 foreach ($queues as $object) {
192 $objectIDs[] = $object->objectID;
196 $commentList = new CommentList();
197 $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($objectIDs));
198 $commentList->readObjects();
199 $comments = $commentList->getObjects();
201 foreach ($queues as $object) {
202 if (isset($comments[$object->objectID])) {
203 $object->setAffectedObject($comments[$object->objectID]);
206 $object->setIsOrphaned();
212 * @see \wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
214 public function removeContent(ModerationQueue $queue, $message) {
215 if ($this->isValid($queue->objectID)) {
216 $commentAction = new CommentAction(array($this->getComment($queue->objectID)), 'delete');
217 $commentAction->executeAction();