Completed
Pull Request — master (#1216)
by René
04:41
created

UserGroupClass::setDisplayName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 2
c 3
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Model;
25
use OCA\Polls\Exceptions\InvalidShareType;
26
27
class UserGroupClass implements \JsonSerializable {
28
	public const TYPE = 'generic';
29
	public const TYPE_PUBLIC = 'public';
30
	public const TYPE_EXTERNAL = 'external';
31
	public const TYPE_CIRCLE = Circle::TYPE;
32
	public const TYPE_CONTACT = Contact::TYPE;
33
	public const TYPE_CONTACTGROUP = ContactGroup::TYPE;
34
	public const TYPE_EMAIL = Email::TYPE;
35
	public const TYPE_GROUP = Group::TYPE;
36
	public const TYPE_USER = User::TYPE;
37
38
	private $l10n;
39
40
	/** @var string */
41
	protected $id;
42
43
	/** @var string */
44
	protected $type;
45
46
	/** @var string */
47
	protected $displayName = '';
48
49
	/** @var string */
50
	protected $description = '';
51
52
	/** @var string */
53
	protected $emailAddress = '';
54
55
	/** @var string */
56
	protected $language = '';
57
58
	/** @var string */
59
	protected $organisation = '';
60
61
	/** @var string */
62
	protected $icon = '';
63
64
	/** @var boolean */
65
	protected $isNoUser = true;
66
67
	/** @var string[] */
68
	protected $categories = [];
69
70
	/**
71
	 * User constructor.
72
	 * @param $id
73
	 * @param $displayName
74
	 */
75
	public function __construct(
76
		$id,
77
		$type,
78
		$displayName = '',
79
		$emailAddress = '',
80
		$language = ''
81
	) {
82
		$this->id = $id;
83
		$this->type = $type;
84
		$this->displayName = $displayName;
85
		$this->emailAddress = $emailAddress;
86
		$this->language = $language;
87
		$this->icon = 'icon-share';
88
		$this->l10n = \OC::$server->getL10N('polls');
89
	}
90
91
	/**
92
	 * getId
93
	 * @NoAdminRequired
94
	 * @return String
95
	 */
96
	public function getId() {
97
		return $this->id;
98
	}
99
100
	/**
101
	 * getPublicId
102
	 * @NoAdminRequired
103
	 * @return String
104
	 */
105
	public function getPublicId() {
106
		return $this->id;
107
	}
108
109
	/**
110
	 * getUser
111
	 * @NoAdminRequired
112
	 * @return String
113
	 */
114
	public function getUser() {
115
		return $this->id;
116
	}
117
118
	/**
119
	 * getType
120
	 * @NoAdminRequired
121
	 * @return String
122
	 */
123
	public function getType() {
124
		return $this->type;
125
	}
126
127
	/**
128
	 * getLanguage
129
	 * @NoAdminRequired
130
	 * @return String
131
	 */
132
	public function getLanguage() {
133
		return $this->language;
134
	}
135
136
	/**
137
	 * getDisplayName
138
	 * @NoAdminRequired
139
	 * @return String
140
	 */
141
	public function getDisplayName() {
142
		return $this->displayName;
143
	}
144
145
	/**
146
	 * getDescription
147
	 * @NoAdminRequired
148
	 * @return String
149
	 */
150
	public function getDescription() {
151
		return $this->description;
152
	}
153
154
	/**
155
	 * getIcon
156
	 * @NoAdminRequired
157
	 * @return String
158
	 */
159
	public function getIcon() {
160
		return $this->icon;
161
	}
162
163
	/**
164
	 * getEmailAddress
165
	 * @NoAdminRequired
166
	 * @return String
167
	 */
168
	public function getEmailAddress() {
169
		return $this->emailAddress;
170
	}
171
172
	/**
173
	 * getOrganisation
174
	 * @NoAdminRequired
175
	 * @return String
176
	 */
177
	public function getOrganisation() {
178
		return $this->organisation;
179
	}
180
181
	/**
182
	 * getCategories
183
	 * @NoAdminRequired
184
	 * @return Array
185
	 */
186
	public function getCategories() {
187
		return $this->categories;
188
	}
189
190
	/**
191
	 * getOrganisation
192
	 * @NoAdminRequired
193
	 * @return String
194
	 */
195
	public function getIsNoUser() {
196
		return $this->isNoUser;
197
	}
198
199
	/**
200
	 * setType
201
	 * @NoAdminRequired
202
	 * @param string $type
203
	 * @return String
204
	 */
205
	public function setType($type) {
206
		$this->type = $type;
207
		return $this->type;
208
	}
209
210
	/**
211
	 * setDisplayName
212
	 * @NoAdminRequired
213
	 * @param string $displayName
214
	 * @return String
215
	 */
216
	public function setDisplayName($displayName) {
217
		$this->displayName = $displayName;
218
		return $this->displayName;
219
	}
220
221
	/**
222
	 * setDescription
223
	 * @NoAdminRequired
224
	 * @param string $description
225
	 * @return String
226
	 */
227
	public function setDescription($description) {
228
		$this->description = $description;
229
		return $this->description;
230
	}
231
232
	/**
233
	 * setEmailAddress
234
	 * @NoAdminRequired
235
	 * @param string $emailAddress
236
	 * @return String
237
	 */
238
	public function setEmailAddress($emailAddress) {
239
		$this->emailAddress = $emailAddress;
240
		return $this->emailAddress;
241
	}
242
243
	/**
244
	 * setLanguage
245
	 * @NoAdminRequired
246
	 * @param string $language
247
	 * @return String
248
	 */
249
	public function setLanguage($language) {
250
		$this->language = $language;
251
		return $this->language;
252
	}
253
254
	/**
255
	 * setOrganisation
256
	 * @NoAdminRequired
257
	 * @param string $organisation
258
	 * @return String
259
	 */
260
	public function setOrganisation($organisation) {
261
		$this->organisation = $organisation;
262
		return $this->organisation;
263
	}
264
265
	/**
266
	 * search
267
	 * @NoAdminRequired
268
	 * @return Array
269
	 */
270
	public static function search() {
271
		return [];
272
	}
273
274
	public static function getUserGroupChild($type, $id, $displayName = '', $emailAddress = '') {
275
		switch ($type) {
276
			case Group::TYPE:
277
				return new Group($id);
278
			case Circle::TYPE:
279
				return new Circle($id);
280
			case Contact::TYPE:
281
				return new Contact($id);
282
			case ContactGroup::TYPE:
283
				return new ContactGroup($id);
284
			case User::TYPE:
285
				return new User($id);
286
			case Email::TYPE:
287
				return new Email($id);
288
			case self::TYPE_PUBLIC:
289
				return new GenericUser($id, self::TYPE_PUBLIC);
290
			case self::TYPE_EXTERNAL:
291
				return new GenericUser($id, self::TYPE_EXTERNAL, $displayName, $emailAddress);
292
			default:
293
				throw new InvalidShareType('Invalid share type (' . $type . ')');
294
			}
295
	}
296
297
	/**
298
	 * @return array
299
	 */
300
	public function jsonSerialize(): array {
301
		return	[
302
			'id'        	=> $this->getId(),
303
			'user'          => $this->getId(),
304
			'userId'        => $this->getId(),
305
			'type'       	=> $this->getType(),
306
			'displayName'	=> $this->getDisplayName(),
307
			'organisation'	=> $this->getOrganisation(),
308
			'emailAddress'	=> $this->getEmailAddress(),
309
			'language'		=> $this->getLanguage(),
310
			'desc' 			=> $this->getDescription(),
311
			'icon'			=> $this->getIcon(),
312
			'categories'	=> $this->getCategories(),
313
			'isNoUser'		=> $this->getIsNoUser(),
314
		];
315
	}
316
}
317