2 namespace wcf\system\moderation\queue\report;
3 use wcf\data\article\ArticleAction;
4 use wcf\data\article\ViewableArticle;
5 use wcf\data\moderation\queue\ModerationQueue;
6 use wcf\data\moderation\queue\ViewableModerationQueue;
7 use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
8 use wcf\system\moderation\queue\AbstractModerationQueueHandler;
9 use wcf\system\moderation\queue\ModerationQueueManager;
13 * An implementation of IModerationQueueReportHandler for articles.
15 * @author Joshua Ruesweg
16 * @copyright 2001-2018 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Suite\System\Moderation\Queue\Report
21 class ArticleModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
25 protected $definitionName = 'com.woltlab.wcf.moderation.report';
30 protected $objectType = 'com.woltlab.wcf.article';
35 public function canReport($objectID) {
36 if (!$this->isValid($objectID)) {
40 if (!$this->getReportedObject($objectID)->canRead()) {
50 public function getReportedContent(ViewableModerationQueue $queue) {
51 WCF::getTPL()->assign([
52 'article' => $this->getArticle($queue->getAffectedObject()->articleID),
55 return WCF::getTPL()->fetch('moderationArticle');
61 * @return ViewableArticle|null
63 public function getReportedObject($objectID) {
64 if ($this->isValid($objectID)) {
65 return $this->getArticle($objectID);
73 * @return ViewableArticle|null
75 public function getArticle($articleID) {
76 return ViewableArticleRuntimeCache::getInstance()->getObject($articleID);
82 public function assignQueues(array $queues) {
83 $assignments = $orphanedQueueIDs = [];
85 // first cache all articles
86 foreach ($queues as $queue) {
87 ViewableArticleRuntimeCache::getInstance()->cacheObjectID($queue->objectID);
90 // now process articles
91 foreach ($queues as $queue) {
92 $article = ViewableArticleRuntimeCache::getInstance()->getObject($queue->objectID);
94 if ($article === null) {
95 $orphanedQueueIDs[] = $queue->queueID;
98 if ($article->canDelete()) {
99 $assignments[$queue->queueID] = true;
102 $assignments[$queue->queueID] = false;
107 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
108 ModerationQueueManager::getInstance()->setAssignment($assignments);
114 public function getContainerID($objectID) {
115 if ($this->isValid($objectID)) {
116 return $this->getArticle($objectID)->getCategory()->categoryID;
125 public function isValid($objectID) {
126 if ($this->getArticle($objectID) === null) {
136 public function populate(array $queues) {
137 // first cache all articles
138 foreach ($queues as $queue) {
139 ViewableArticleRuntimeCache::getInstance()->cacheObjectID($queue->objectID);
142 foreach ($queues as $object) {
143 $article = ViewableArticleRuntimeCache::getInstance()->getObject($object->objectID);
144 if ($article !== null) {
145 $object->setAffectedObject($article->getDecoratedObject());
148 $object->setIsOrphaned();
156 public function canRemoveContent(ModerationQueue $queue) {
157 if ($this->isValid($queue->objectID)) {
158 return $this->getArticle($queue->objectID)->canDelete();
167 public function removeContent(ModerationQueue $queue, $message) {
168 if ($this->isValid($queue->objectID)) {
169 (new ArticleAction([$this->getArticle($queue->objectID)->getDecoratedObject()], 'trash'))->executeAction();