| 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 |
| 13 | * @copyright 2001-2018 WoltLab GmbH |
| 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 | $objectIDs = []; |
| 97 | |
| 98 | /** @var Article $article */ |
| 99 | foreach ($this->objects as $article) { |
| 100 | if ($article->canDelete() && $article->isDeleted) { |
| 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() { |
| 114 | $objectIDs = []; |
| 115 | |
| 116 | /** @var Article $article */ |
| 117 | foreach ($this->objects as $article) { |
| 118 | if ($article->canPublish() && $article->publicationStatus == Article::UNPUBLISHED) { |
| 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 | |
| 145 | return array_keys($this->objects); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Returns the ids of the articles that can be trashed. |
| 150 | * |
| 151 | * @return integer[] |
| 152 | */ |
| 153 | public function validateTrash() { |
| 154 | $objectIDs = []; |
| 155 | |
| 156 | /** @var Article $article */ |
| 157 | foreach ($this->objects as $article) { |
| 158 | if ($article->canDelete() && !$article->isDeleted) { |
| 159 | $objectIDs[] = $article->articleID; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | return $objectIDs; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Returns the ids of the articles that can be unpublished. |
| 168 | * |
| 169 | * @return integer[] |
| 170 | */ |
| 171 | public function validateUnpublish() { |
| 172 | $objectIDs = []; |
| 173 | |
| 174 | /** @var Article $article */ |
| 175 | foreach ($this->objects as $article) { |
| 176 | if ($article->canPublish() && $article->publicationStatus == Article::PUBLISHED) { |
| 177 | $objectIDs[] = $article->articleID; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | return $objectIDs; |
| 182 | } |
| 183 | } |