Validate if an article may be edited in `setCategory` clipboard action
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / clipboard / action / ArticleClipboardAction.class.php
CommitLineData
8ff79ba2
MS
1<?php
2namespace wcf\system\clipboard\action;
3use wcf\data\article\Article;
4use wcf\data\article\ArticleAction;
5use wcf\data\category\CategoryNodeTree;
6use wcf\data\clipboard\action\ClipboardAction;
7use wcf\system\WCF;
8
9/**
10 * Clipboard action implementation for articles.
11 *
12 * @author Matthias Schmidt
7b7b9764 13 * @copyright 2001-2019 WoltLab GmbH
8ff79ba2
MS
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\Clipboard\Action
16 * @since 3.1
17 */
18class ArticleClipboardAction extends AbstractClipboardAction {
19 /**
20 * @inheritDoc
21 */
22 protected $actionClassActions = [
23 'delete',
24 'publish',
25 'restore',
26 'trash',
27 'unpublish'
28 ];
29
30 /**
31 * @inheritDoc
32 */
33 protected $supportedActions = [
34 'delete',
35 'publish',
36 'restore',
37 'setCategory',
38 'trash',
39 'unpublish'
40 ];
41
42 /**
43 * @inheritDoc
44 */
45 public function execute(array $objects, ClipboardAction $action) {
46 $item = parent::execute($objects, $action);
47
48 if ($item === null) {
49 return null;
50 }
51
52 // handle actions
53 switch ($action->actionName) {
54 case 'delete':
55 $item->addInternalData('confirmMessage', WCF::getLanguage()->getDynamicVariable('wcf.clipboard.item.com.woltlab.wcf.article.delete.confirmMessage', [
56 'count' => $item->getCount()
57 ]));
58 break;
59
60 case 'setCategory':
61 $item->addInternalData('template', WCF::getTPL()->fetch('articleCategoryDialog', 'wcf', [
62 'categoryNodeList' => (new CategoryNodeTree('com.woltlab.wcf.article.category'))->getIterator()
63 ]));
64 break;
65
66 case 'trash':
67 $item->addInternalData('confirmMessage', WCF::getLanguage()->getDynamicVariable('wcf.clipboard.item.com.woltlab.wcf.article.trash.confirmMessage', [
68 'count' => $item->getCount()
69 ]));
70 break;
71 }
72
73 return $item;
74 }
75
76 /**
77 * @inheritDoc
78 */
79 public function getClassName() {
80 return ArticleAction::class;
81 }
82
83 /**
84 * @inheritDoc
85 */
86 public function getTypeName() {
87 return 'com.woltlab.wcf.article';
88 }
89
90 /**
91 * Returns the ids of the articles that can be deleted.
92 *
93 * @return integer[]
94 */
95 public function validateDelete() {
8ff79ba2
MS
96 $objectIDs = [];
97
98 /** @var Article $article */
99 foreach ($this->objects as $article) {
a40df44c 100 if ($article->canDelete() && $article->isDeleted) {
8ff79ba2
MS
101 $objectIDs[] = $article->articleID;
102 }
103 }
104
105 return $objectIDs;
106 }
107
108 /**
109 * Returns the ids of the articles that can be published.
110 *
111 * @return integer[]
112 */
113 public function validatePublish() {
8ff79ba2
MS
114 $objectIDs = [];
115
116 /** @var Article $article */
117 foreach ($this->objects as $article) {
a40df44c 118 if ($article->canPublish() && $article->publicationStatus == Article::UNPUBLISHED) {
8ff79ba2
MS
119 $objectIDs[] = $article->articleID;
120 }
121 }
122
123 return $objectIDs;
124 }
125
126 /**
127 * Returns the ids of the articles that can be restored.
128 *
129 * @return integer[]
130 */
131 public function validateRestore() {
132 return $this->validateDelete();
133 }
134
135 /**
136 * Returns the ids of the articles whose category can be set.
137 *
138 * @return integer[]
139 */
140 public function validateSetCategory() {
141 if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) {
142 return [];
143 }
144
1bc95472
TD
145 $objectIDs = [];
146
147 /** @var Article $article */
148 foreach ($this->objects as $article) {
149 if ($article->canEdit()) {
150 $objectIDs[] = $article->articleID;
151 }
152 }
153
154 return $objectIDs;
8ff79ba2
MS
155 }
156
157 /**
158 * Returns the ids of the articles that can be trashed.
159 *
160 * @return integer[]
161 */
162 public function validateTrash() {
8ff79ba2
MS
163 $objectIDs = [];
164
165 /** @var Article $article */
166 foreach ($this->objects as $article) {
a40df44c 167 if ($article->canDelete() && !$article->isDeleted) {
8ff79ba2
MS
168 $objectIDs[] = $article->articleID;
169 }
170 }
171
172 return $objectIDs;
173 }
174
175 /**
176 * Returns the ids of the articles that can be unpublished.
177 *
178 * @return integer[]
179 */
180 public function validateUnpublish() {
8ff79ba2
MS
181 $objectIDs = [];
182
183 /** @var Article $article */
184 foreach ($this->objects as $article) {
a40df44c 185 if ($article->canPublish() && $article->publicationStatus == Article::PUBLISHED) {
8ff79ba2
MS
186 $objectIDs[] = $article->articleID;
187 }
188 }
189
190 return $objectIDs;
191 }
192}