Replace @see tags with @inheritDoc tags
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / clipboard / action / AbstractClipboardAction.class.php
1 <?php
2 namespace wcf\system\clipboard\action;
3 use wcf\data\clipboard\action\ClipboardAction;
4 use wcf\data\DatabaseObject;
5 use wcf\system\clipboard\ClipboardEditorItem;
6 use wcf\system\exception\SystemException;
7 use wcf\system\WCF;
8
9 /**
10 * Abstract implementation of a clipboard action handler.
11 *
12 * @author Matthias Schmidt
13 * @copyright 2001-2016 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.clipboard.action
17 * @category Community Framework
18 */
19 abstract class AbstractClipboardAction implements IClipboardAction {
20 /**
21 * list of the clipboard actions which are executed by the action class
22 * @var string[]
23 */
24 protected $actionClassActions = [];
25
26 /**
27 * relevant database objects
28 * @var DatabaseObject[]
29 */
30 protected $objects = [];
31
32 /**
33 * list of the supported clipboard actions
34 * @var string[]
35 */
36 protected $supportedActions = [];
37
38 /**
39 * @inheritDoc
40 */
41 public function execute(array $objects, ClipboardAction $action) {
42 if (!in_array($action->actionName, $this->supportedActions)) {
43 throw new SystemException("Unknown clipboard action '".$action->actionName."'");
44 }
45
46 $this->objects = $objects;
47
48 $item = new ClipboardEditorItem();
49 $item->setName($this->getTypeName().'.'.$action->actionName);
50
51 // set action class-related data
52 if (in_array($action->actionName, $this->actionClassActions)) {
53 $item->addParameter('actionName', $action->actionName);
54 $item->addParameter('className', $this->getClassName());
55 }
56
57 // validate objects if relevant method exists and set valid object ids
58 $methodName = 'validate'.ucfirst($action->actionName);
59 if (method_exists($this, $methodName)) {
60 $objectIDs = $this->$methodName();
61 if (empty($objectIDs)) {
62 return null;
63 }
64
65 $item->addParameter('objectIDs', $objectIDs);
66 }
67
68 return $item;
69 }
70
71 /**
72 * @inheritDoc
73 */
74 public function getEditorLabel(array $objects) {
75 return WCF::getLanguage()->getDynamicVariable('wcf.clipboard.label.'.$this->getTypeName().'.marked', [
76 'count' => count($objects)
77 ]);
78 }
79 }