Completed
Push — master ( 11144a...f5a495 )
by Maxence
12:24 queued 10s
created

WidgetSetting::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
5
/**
6
 * Nextcloud - Dashboard App
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2018, Maxence Lange <[email protected]>
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
namespace OCP\Dashboard\Model;
31
32
33
use JsonSerializable;
34
35
36
/**
37
 * Interface WidgetSetting
38
 *
39
 * Each setting that can be edited by a user should be defined in a
40
 * WidgetSetting.
41
 *
42
 * When using this framework, the settings interface is generated by the
43
 * Dashboard app.
44
 *
45
 * Each WidgetSetting must be generated and declared in the WidgetTemplate
46
 * during the setup of the widget in the IDashboardWidget using addSetting().
47
 *
48
 * @see IDashboardWidget::getWidgetTemplate
49
 * @see WidgetTemplate::addSetting
50
 *
51
 * @since 15.0.0
52
 *
53
 * @package OCP\Dashboard\Model
54
 */
55
final class WidgetSetting implements JsonSerializable {
56
57
58
	const TYPE_INPUT = 'input';
59
	const TYPE_CHECKBOX = 'checkbox';
60
61
62
	/** @var string */
63
	private $name = '';
64
65
	/** @var string */
66
	private $title = '';
67
68
	/** @var string */
69
	private $type = '';
70
71
	/** @var string */
72
	private $placeholder = '';
73
74
	/** @var string */
75
	private $default = '';
76
77
78
	/**
79
	 * WidgetSetting constructor.
80
	 *
81
	 * @since 15.0.0
82
	 *
83
	 * @param string $type
84
	 */
85
	public function __construct(string $type = '') {
86
		$this->type = $type;
87
	}
88
89
90
	/**
91
	 * Set the name of the setting (full string, no space)
92
	 *
93
	 * @since 15.0.0
94
	 *
95
	 * @param string $name
96
	 *
97
	 * @return WidgetSetting
98
	 */
99
	public function setName(string $name): WidgetSetting {
100
		$this->name = $name;
101
102
		return $this;
103
	}
104
105
	/**
106
	 * Get the name of the setting
107
	 *
108
	 * @since 15.0.0
109
	 *
110
	 * @return string
111
	 */
112
	public function getName(): string {
113
		return $this->name;
114
	}
115
116
117
	/**
118
	 * Set the title/display name of the setting.
119
	 *
120
	 * @since 15.0.0
121
	 *
122
	 * @param string $title
123
	 *
124
	 * @return WidgetSetting
125
	 */
126
	public function setTitle(string $title): WidgetSetting {
127
		$this->title = $title;
128
129
		return $this;
130
	}
131
132
	/**
133
	 * Get the title of the setting
134
	 *
135
	 * @since 15.0.0
136
	 *
137
	 * @return string
138
	 */
139
	public function getTitle(): string {
140
		return $this->title;
141
	}
142
143
144
	/**
145
	 * Set the type of the setting (input, checkbox, ...)
146
	 *
147
	 * @since 15.0.0
148
	 *
149
	 * @param string $type
150
	 *
151
	 * @return WidgetSetting
152
	 */
153
	public function setType(string $type): WidgetSetting {
154
		$this->type = $type;
155
156
		return $this;
157
	}
158
159
	/**
160
	 * Get the type of the setting.
161
	 *
162
	 * @since 15.0.0
163
	 *
164
	 * @return string
165
	 */
166
	public function getType(): string {
167
		return $this->type;
168
	}
169
170
171
	/**
172
	 * Set the placeholder (in case of type=input)
173
	 *
174
	 * @since 15.0.0
175
	 *
176
	 * @param string $text
177
	 *
178
	 * @return WidgetSetting
179
	 */
180
	public function setPlaceholder(string $text): WidgetSetting {
181
		$this->placeholder = $text;
182
183
		return $this;
184
	}
185
186
	/**
187
	 * Get the placeholder.
188
	 *
189
	 * @since 15.0.0
190
	 *
191
	 * @return string
192
	 */
193
	public function getPlaceholder(): string {
194
		return $this->placeholder;
195
	}
196
197
198
	/**
199
	 * Set the default value of the setting.
200
	 *
201
	 * @since 15.0.0
202
	 *
203
	 * @param string $value
204
	 *
205
	 * @return WidgetSetting
206
	 */
207
	public function setDefault(string $value): WidgetSetting {
208
		$this->default = $value;
209
210
		return $this;
211
	}
212
213
	/**
214
	 * Get the default value.
215
	 *
216
	 * @since 15.0.0
217
	 *
218
	 * @return string
219
	 */
220
	public function getDefault(): string {
221
		return $this->default;
222
	}
223
224
225
	/**
226
	 * @since 15.0.0
227
	 *
228
	 * @return array
229
	 */
230
	public function jsonSerialize() {
231
		return [
232
			'name' => $this->getName(),
233
			'title' => $this->getTitle(),
234
			'type' => $this->getTitle(),
235
			'default' => $this->getDefault(),
236
			'placeholder' => $this->getPlaceholder()
237
		];
238
	}
239
240
241
}
242
243