2 namespace wcf\system\moderation\queue\report;
3 use wcf\data\comment\response\CommentResponse;
4 use wcf\data\comment\response\CommentResponseAction;
5 use wcf\data\comment\response\CommentResponseList;
6 use wcf\data\comment\response\ViewableCommentResponse;
7 use wcf\data\comment\Comment;
8 use wcf\data\comment\CommentList;
9 use wcf\data\moderation\queue\ModerationQueue;
10 use wcf\data\moderation\queue\ViewableModerationQueue;
11 use wcf\system\database\util\PreparedStatementConditionBuilder;
12 use wcf\system\moderation\queue\ModerationQueueManager;
16 * An implementation of IModerationQueueReportHandler for comment responses.
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 CommentResponseModerationQueueReportHandler extends CommentCommentModerationQueueReportHandler {
27 * @see wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
29 protected $objectType = 'com.woltlab.wcf.comment.response';
32 * list of comment responses
33 * @var array<wcf\data\comment\response\CommentResponse>
35 protected static $responses = array();
38 * @see wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
40 public function assignQueues(array $queues) {
41 $assignments = array();
43 // read comments and responses
44 $responseIDs = array();
45 foreach ($queues as $queue) {
46 $responseIDs[] = $queue->objectID;
49 $conditions = new PreparedStatementConditionBuilder();
50 $conditions->add("comment_response.responseID IN (?)", array($responseIDs));
52 $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
53 FROM wcf".WCF_N."_comment_response comment_response
54 LEFT JOIN wcf".WCF_N."_comment comment
55 ON (comment.commentID = comment_response.commentID)
57 $statement = WCF::getDB()->prepareStatement($sql);
58 $statement->execute($conditions->getParameters());
59 $comments = $responses = array();
60 while ($row = $statement->fetchArray()) {
61 $comments[$row['commentID']] = new Comment(null, $row);
62 $responses[$row['responseID']] = new CommentResponse(null, $row);
65 foreach ($queues as $queue) {
68 $comment = $comments[$responses[$queue->objectID]->commentID];
69 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
73 $assignments[$queue->queueID] = $assignUser;
76 ModerationQueueManager::getInstance()->setAssignment($assignments);
80 * @see wcf\system\moderation\queue\report\IModerationQueueReportHandler::canReport()
82 public function canReport($objectID) {
83 if (!$this->isValid($objectID)) {
87 $response = $this->getResponse($objectID);
88 $comment = $this->getComment($response->commentID);
89 if (!$this->getCommentManager($comment)->isAccessible($comment->objectID)) {
97 * @see wcf\system\moderation\queue\IModerationQueueHandler::getContainerID()
99 public function getContainerID($objectID) {
104 * @see wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedContent()
106 public function getReportedContent(ViewableModerationQueue $queue) {
107 WCF::getTPL()->assign(array(
108 'message' => new ViewableCommentResponse($queue->getAffectedObject())
111 return WCF::getTPL()->fetch('moderationComment');
115 * @see wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
117 public function getReportedObject($objectID) {
118 if ($this->isValid($objectID)) {
119 return $this->getResponse($objectID);
126 * @see wcf\system\moderation\queue\IModerationQueueHandler::isValid()
128 public function isValid($objectID) {
129 if ($this->getResponse($objectID) === null) {
137 * Returns a comment response object by response id or null if response id is invalid.
139 * @param integer $objectID
140 * @return wcf\data\comment\response\CommentResponse
142 protected function getResponse($objectID) {
143 if (!array_key_exists($objectID, self::$responses)) {
144 self::$responses[$objectID] = new CommentResponse($objectID);
145 if (!self::$responses[$objectID]->responseID) {
146 self::$responses[$objectID] = null;
150 return self::$responses[$objectID];
154 * @see wcf\system\moderation\queue\IModerationQueueHandler::populate()
156 public function populate(array $queues) {
157 $objectIDs = array();
158 foreach ($queues as $object) {
159 $objectIDs[] = $object->objectID;
163 $responseList = new CommentResponseList();
164 $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($objectIDs));
165 $responseList->readObjects();
166 $responses = $responseList->getObjects();
169 $commentIDs = array();
170 foreach ($responses as $response) {
171 $commentIDs[] = $response->commentID;
174 if (!empty($commentIDs)) {
175 $commentList = new CommentList();
176 $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs));
177 $commentList->readObjects();
178 $comments = $commentList->getObjects();
181 foreach ($queues as $object) {
182 if (isset($responses[$object->objectID])) {
183 $response = $responses[$object->objectID];
184 $response->setComment($comments[$response->commentID]);
186 $object->setAffectedObject($response);
189 $object->setIsOrphaned();
195 * @see wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
197 public function removeContent(ModerationQueue $queue, $message) {
198 if ($this->isValid($queue->objectID)) {
199 $responseAction = new CommentResponseAction(array($this->getResponse($queue->objectID)), 'delete');
200 $responseAction->executeAction();