Commit | Line | Data |
---|---|---|
8ff79ba2 MS |
1 | <?php |
2 | namespace wcf\system\clipboard\action; | |
3 | use wcf\data\article\Article; | |
4 | use wcf\data\article\ArticleAction; | |
5 | use wcf\data\category\CategoryNodeTree; | |
6 | use wcf\data\clipboard\action\ClipboardAction; | |
7 | use wcf\system\WCF; | |
8 | ||
9 | /** | |
10 | * Clipboard action implementation for articles. | |
11 | * | |
12 | * @author Matthias Schmidt | |
c839bd49 | 13 | * @copyright 2001-2018 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 | */ | |
18 | class 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() { | |
96 | if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) { | |
97 | return []; | |
98 | } | |
99 | ||
100 | $objectIDs = []; | |
101 | ||
102 | /** @var Article $article */ | |
103 | foreach ($this->objects as $article) { | |
104 | if ($article->isDeleted) { | |
105 | $objectIDs[] = $article->articleID; | |
106 | } | |
107 | } | |
108 | ||
109 | return $objectIDs; | |
110 | } | |
111 | ||
112 | /** | |
113 | * Returns the ids of the articles that can be published. | |
114 | * | |
115 | * @return integer[] | |
116 | */ | |
117 | public function validatePublish() { | |
118 | if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) { | |
119 | return []; | |
120 | } | |
121 | ||
122 | $objectIDs = []; | |
123 | ||
124 | /** @var Article $article */ | |
125 | foreach ($this->objects as $article) { | |
126 | if ($article->publicationStatus == Article::UNPUBLISHED) { | |
127 | $objectIDs[] = $article->articleID; | |
128 | } | |
129 | } | |
130 | ||
131 | return $objectIDs; | |
132 | } | |
133 | ||
134 | /** | |
135 | * Returns the ids of the articles that can be restored. | |
136 | * | |
137 | * @return integer[] | |
138 | */ | |
139 | public function validateRestore() { | |
140 | return $this->validateDelete(); | |
141 | } | |
142 | ||
143 | /** | |
144 | * Returns the ids of the articles whose category can be set. | |
145 | * | |
146 | * @return integer[] | |
147 | */ | |
148 | public function validateSetCategory() { | |
149 | if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) { | |
150 | return []; | |
151 | } | |
152 | ||
153 | return array_keys($this->objects); | |
154 | } | |
155 | ||
156 | /** | |
157 | * Returns the ids of the articles that can be trashed. | |
158 | * | |
159 | * @return integer[] | |
160 | */ | |
161 | public function validateTrash() { | |
162 | if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) { | |
163 | return []; | |
164 | } | |
165 | ||
166 | $objectIDs = []; | |
167 | ||
168 | /** @var Article $article */ | |
169 | foreach ($this->objects as $article) { | |
170 | if (!$article->isDeleted) { | |
171 | $objectIDs[] = $article->articleID; | |
172 | } | |
173 | } | |
174 | ||
175 | return $objectIDs; | |
176 | } | |
177 | ||
178 | /** | |
179 | * Returns the ids of the articles that can be unpublished. | |
180 | * | |
181 | * @return integer[] | |
182 | */ | |
183 | public function validateUnpublish() { | |
184 | if (!WCF::getSession()->getPermission('admin.content.article.canManageArticle')) { | |
185 | return []; | |
186 | } | |
187 | ||
188 | $objectIDs = []; | |
189 | ||
190 | /** @var Article $article */ | |
191 | foreach ($this->objects as $article) { | |
192 | if ($article->publicationStatus == Article::PUBLISHED) { | |
193 | $objectIDs[] = $article->articleID; | |
194 | } | |
195 | } | |
196 | ||
197 | return $objectIDs; | |
198 | } | |
199 | } |