3 namespace wcf\system\moderation\queue\report;
5 use wcf\data\article\ArticleAction;
6 use wcf\data\article\ViewableArticle;
7 use wcf\data\moderation\queue\ModerationQueue;
8 use wcf\data\moderation\queue\ViewableModerationQueue;
9 use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
10 use wcf\system\moderation\queue\AbstractModerationQueueHandler;
11 use wcf\system\moderation\queue\ModerationQueueManager;
15 * An implementation of IModerationQueueReportHandler for articles.
17 * @author Joshua Ruesweg
18 * @copyright 2001-2019 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Suite\System\Moderation\Queue\Report
23 class ArticleModerationQueueReportHandler extends AbstractModerationQueueHandler implements
24 IModerationQueueReportHandler
29 protected $definitionName = 'com.woltlab.wcf.moderation.report';
34 protected $objectType = 'com.woltlab.wcf.article';
39 public function canReport($objectID)
41 if (!$this->isValid($objectID)) {
45 if (!$this->getReportedObject($objectID)->canRead()) {
55 public function getReportedContent(ViewableModerationQueue $queue)
57 WCF::getTPL()->assign([
58 'article' => $this->getArticle($queue->getAffectedObject()->articleID),
61 return WCF::getTPL()->fetch('moderationArticle');
67 * @return ViewableArticle|null
69 public function getReportedObject($objectID)
71 if ($this->isValid($objectID)) {
72 return $this->getArticle($objectID);
78 * @return ViewableArticle|null
80 public function getArticle($articleID)
82 return ViewableArticleRuntimeCache::getInstance()->getObject($articleID);
88 public function assignQueues(array $queues)
90 $assignments = $orphanedQueueIDs = [];
92 // first cache all articles
93 foreach ($queues as $queue) {
94 ViewableArticleRuntimeCache::getInstance()->cacheObjectID($queue->objectID);
97 // now process articles
98 foreach ($queues as $queue) {
99 $article = ViewableArticleRuntimeCache::getInstance()->getObject($queue->objectID);
101 if ($article === null) {
102 $orphanedQueueIDs[] = $queue->queueID;
104 if ($article->canDelete()) {
105 $assignments[$queue->queueID] = true;
107 $assignments[$queue->queueID] = false;
112 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
113 ModerationQueueManager::getInstance()->setAssignment($assignments);
119 public function getContainerID($objectID)
121 if ($this->isValid($objectID)) {
122 return $this->getArticle($objectID)->getCategory()->categoryID;
131 public function isValid($objectID)
133 if ($this->getArticle($objectID) === null) {
143 public function populate(array $queues)
145 // first cache all articles
146 foreach ($queues as $queue) {
147 ViewableArticleRuntimeCache::getInstance()->cacheObjectID($queue->objectID);
150 foreach ($queues as $object) {
151 $article = ViewableArticleRuntimeCache::getInstance()->getObject($object->objectID);
152 if ($article !== null) {
153 $object->setAffectedObject($article->getDecoratedObject());
155 $object->setIsOrphaned();
163 public function canRemoveContent(ModerationQueue $queue)
165 if ($this->isValid($queue->objectID)) {
166 return $this->getArticle($queue->objectID)->canDelete();
175 public function removeContent(ModerationQueue $queue, $message)
177 if ($this->isValid($queue->objectID)) {
178 (new ArticleAction([$this->getArticle($queue->objectID)->getDecoratedObject()], 'trash'))->executeAction();