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