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.comment
22 * @subpackage system.moderation.queue
23 * @category Community Framework
25 class CommentCommentModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
27 * @see wcf\system\moderation\queue\AbstractModerationQueueHandler::$definitionName
29 protected $definitionName = 'com.woltlab.wcf.moderation.report';
32 * @see wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
34 protected $objectType = 'com.woltlab.wcf.comment.comment';
38 * @var array<wcf\data\comment\Comment>
40 protected static $comments = array();
43 * list of comment managers
44 * @var array<wcf\system\comment\manager\ICommentManager>
46 protected static $commentManagers = array();
49 * @see wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
51 public function assignQueues(array $queues) {
52 $assignments = array();
55 $commentIDs = array();
56 foreach ($queues as $queue) {
57 $commentIDs[] = $queue->objectID;
60 $conditions = new PreparedStatementConditionBuilder();
61 $conditions->add("commentID IN (?)", array($commentIDs));
63 $sql = "SELECT commentID, objectTypeID, objectID
64 FROM wcf".WCF_N."_comment
66 $statement = WCF::getDB()->prepareStatement($sql);
67 $statement->execute($conditions->getParameters());
69 while ($row = $statement->fetchArray()) {
70 $comments[$row['commentID']] = new Comment(null, $row);
73 foreach ($queues as $queue) {
76 $comment = $comments[$queue->objectID];
77 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
81 $assignments[$queue->queueID] = $assignUser;
84 ModerationQueueManager::getInstance()->setAssignment($assignments);
88 * @see wcf\system\moderation\queue\report\IModerationQueueReportHandler::canReport()
90 public function canReport($objectID) {
91 if (!$this->isValid($objectID)) {
95 $comment = $this->getComment($objectID);
96 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
104 * @see wcf\system\moderation\queue\IModerationQueueHandler::getContainerID()
106 public function getContainerID($objectID) {
111 * @see wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedContent()
113 public function getReportedContent(ViewableModerationQueue $queue) {
114 WCF::getTPL()->assign(array(
115 'message' => new ViewableComment($queue->getAffectedObject())
118 return WCF::getTPL()->fetch('moderationComment');
122 * @see wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
124 public function getReportedObject($objectID) {
125 if ($this->isValid($objectID)) {
126 return $this->getComment($objectID);
133 * @see wcf\system\moderation\queue\IModerationQueueHandler::isValid()
135 public function isValid($objectID) {
136 if ($this->getComment($objectID) === null) {
144 * Returns a comment object by comment id or null if comment id is invalid.
146 * @param integer $objectID
147 * @return wcf\data\comment\Comment
149 protected function getComment($objectID) {
150 if (!array_key_exists($objectID, self::$comments)) {
151 self::$comments[$objectID] = new Comment($objectID);
152 if (!self::$comments[$objectID]->commentID) {
153 self::$comments[$objectID] = null;
157 return self::$comments[$objectID];
161 * Returns a comment manager for given comment.
163 * @param wcf\data\comment\Comment $comment
164 * @return wcf\system\comment\manager\ICommentManager
166 protected function getCommentManager(Comment $comment) {
167 if (!isset(self::$commentManagers[$comment->objectTypeID])) {
168 self::$commentManagers[$comment->objectTypeID] = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
171 return self::$commentManagers[$comment->objectTypeID];
175 * @see wcf\system\moderation\queue\IModerationQueueHandler::populate()
177 public function populate(array $queues) {
178 $objectIDs = array();
179 foreach ($queues as $object) {
180 $objectIDs[] = $object->objectID;
184 $commentList = new CommentList();
185 $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($objectIDs));
186 $commentList->readObjects();
187 $comments = $commentList->getObjects();
189 foreach ($queues as $object) {
190 if (isset($comments[$object->objectID])) {
191 $object->setAffectedObject($comments[$object->objectID]);
194 $object->setIsOrphaned();
200 * @see wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
202 public function removeContent(ModerationQueue $queue, $message) {
203 if ($this->isValid($queue->objectID)) {
204 $commentAction = new CommentAction(array($this->getComment($queue->objectID)), 'delete');
205 $commentAction->executeAction();