Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / clipboard / ClipboardEditorItem.class.php
CommitLineData
0d6ea23f
AE
1<?php
2namespace wcf\system\clipboard;
6286572b 3use wcf\system\exception\SystemException;
0d6ea23f
AE
4
5/**
6 * Represents a clipboard item for inline editing.
9f959ced
MS
7 *
8 * @author Alexander Ebert
c839bd49 9 * @copyright 2001-2018 WoltLab GmbH
0d6ea23f 10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
e71525e4 11 * @package WoltLabSuite\Core\System\Clipboard
0d6ea23f
AE
12 */
13final class ClipboardEditorItem {
14 /**
15 * internal data
16 * @var array
17 */
058cbd6a 18 protected $internalData = [];
0d6ea23f
AE
19
20 /**
21 * item name
22 * @var string
23 */
24 protected $name = '';
25
26 /**
27 * list of parameters passed to ClipboardProxyAction
28 * @var array
29 */
058cbd6a 30 protected $parameters = [];
0d6ea23f
AE
31
32 /**
33 * redirect url
34 * @var string
35 */
36 protected $url = '';
37
38 /**
39 * Returns internal data.
40 *
41 * @return array
42 */
43 public function getInternalData() {
44 return $this->internalData;
45 }
46
47 /**
48 * Returns item name.
49 *
50 * @return string
51 */
52 public function getName() {
53 return $this->name;
54 }
55
56 /**
57 * Returns parameters passed to ClipboardProxyAction.
58 *
59 * @return array
60 */
61 public function getParameters() {
62 return $this->parameters;
63 }
64
65 /**
66 * Returns redirect url.
67 *
68 * @return string
69 */
70 public function getURL() {
71 return $this->url;
72 }
73
74 /**
75 * Adds internal data, values will be left untouched by clipboard API.
76 *
77 * @param string $name
78 * @param mixed $value
2b770bdd 79 * @throws SystemException
0d6ea23f
AE
80 */
81 public function addInternalData($name, $value) {
82 if (!preg_match('~^[a-zA-Z]+$~', $name)) {
83 throw new SystemException("internal data name '".$name."' is invalid");
84 }
85
86 if (in_array($name, $this->internalData)) {
87 throw new SystemException("internal data name '".$name."' is not unique");
88 }
89
90 $this->internalData[$name] = $value;
91 }
92
93 /**
94 * Adds an parameter passed to ClipboardProxyAction.
95 *
96 * @param string $name
97 * @param mixed $value
2b770bdd 98 * @throws SystemException
0d6ea23f
AE
99 */
100 public function addParameter($name, $value) {
101 if (!preg_match('~^[a-zA-Z]+$~', $name)) {
102 throw new SystemException("parameter name '".$name."' is invalid");
103 }
104
105 if (in_array($name, $this->parameters)) {
106 throw new SystemException("parameter name '".$name."' is not unique");
107 }
108
109 $this->parameters[$name] = $value;
110 }
111
112 /**
113 * Sets item name.
114 *
115 * @param string $name
2b770bdd 116 * @throws SystemException
0d6ea23f
AE
117 */
118 public function setName($name) {
3536d2fe 119 if (!preg_match('~^[a-zA-Z0-9\.-]+$~', $name)) {
0d6ea23f
AE
120 throw new SystemException("item name '".$name."' is invalid");
121 }
122
123 $this->name = $name;
124 }
125
126 /**
127 * Sets redirect url, session id will be appended.
128 *
129 * @param string $url
130 */
131 public function setURL($url) {
0d6ea23f
AE
132 $this->url = $url;
133 }
fb434b97
AE
134
135 /**
136 * Returns number of affected items.
137 *
138 * @return integer
139 */
140 public function getCount() {
141 if (isset($this->parameters['objectIDs'])) {
142 return count($this->parameters['objectIDs']);
143 }
144
145 return 0;
146 }
0d6ea23f 147}