Passed
Pull Request — master (#1234)
by René
03:31
created

UserGroupClass::getMembers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
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
26
use OCA\Polls\Exceptions\InvalidShareTypeException;
27
28
class UserGroupClass implements \JsonSerializable {
29
	public const TYPE = 'generic';
30
	public const TYPE_PUBLIC = 'public';
31
	public const TYPE_EXTERNAL = 'external';
32
	public const TYPE_CIRCLE = Circle::TYPE;
33
	public const TYPE_CONTACT = Contact::TYPE;
34
	public const TYPE_CONTACTGROUP = ContactGroup::TYPE;
35
	public const TYPE_EMAIL = Email::TYPE;
36
	public const TYPE_GROUP = Group::TYPE;
37
	public const TYPE_USER = User::TYPE;
38
39
	private $l10n;
40
41
	/** @var string */
42
	protected $id;
43
44
	/** @var string */
45
	protected $type;
46
47
	/** @var string */
48
	protected $displayName = '';
49
50
	/** @var string */
51
	protected $description = '';
52
53
	/** @var string */
54
	protected $emailAddress = '';
55
56
	/** @var string */
57
	protected $language = '';
58
59
	/** @var string */
60
	protected $organisation = '';
61
62
	/** @var string */
63
	protected $icon = '';
64
65
	/** @var boolean */
66
	protected $isNoUser = true;
67
68
	/** @var string[] */
69
	protected $categories = [];
70
71
	/**
72
	 * User constructor.
73
	 * @param $id
74
	 * @param $displayName
75
	 */
76
	public function __construct(
77
		$id,
78
		$type,
79
		$displayName = '',
80
		$emailAddress = '',
81
		$language = ''
82
	) {
83
		$this->id = $id;
84
		$this->type = $type;
85
		$this->displayName = $displayName;
86
		$this->emailAddress = $emailAddress;
87
		$this->language = $language;
88
		$this->icon = 'icon-share';
89
		$this->l10n = \OC::$server->getL10N('polls');
90
	}
91
92
	/**
93
	 * getId
94
	 * @return String
95
	 */
96
	public function getId() {
97
		return $this->id;
98
	}
99
100
	/**
101
	 * getPublicId
102
	 * @return String
103
	 */
104
	public function getPublicId() {
105
		return $this->id;
106
	}
107
108
	/**
109
	 * getUser
110
	 * @return String
111
	 */
112
	public function getUser() {
113
		return $this->id;
114
	}
115
116
	/**
117
	 * getType
118
	 * @return String
119
	 */
120
	public function getType() {
121
		return $this->type;
122
	}
123
124
	/**
125
	 * getLanguage
126
	 * @return String
127
	 */
128
	public function getLanguage() {
129
		return $this->language;
130
	}
131
132
	/**
133
	 * getDisplayName
134
	 * @return String
135
	 */
136
	public function getDisplayName() {
137
		return $this->displayName;
138
	}
139
140
	/**
141
	 * getDescription
142
	 * @return String
143
	 */
144
	public function getDescription() {
145
		return $this->description;
146
	}
147
148
	/**
149
	 * getIcon
150
	 * @return String
151
	 */
152
	public function getIcon() {
153
		return $this->icon;
154
	}
155
156
	/**
157
	 * getEmailAddress
158
	 * @return String
159
	 */
160
	public function getEmailAddress() {
161
		return $this->emailAddress;
162
	}
163
164
	/**
165
	 * getOrganisation
166
	 * @return String
167
	 */
168
	public function getOrganisation() {
169
		return $this->organisation;
170
	}
171
172
	/**
173
	 * getCategories
174
	 * @return Array
175
	 */
176
	public function getCategories() {
177
		return $this->categories;
178
	}
179
180
	/**
181
	 * getOrganisation
182
	 * @return String
183
	 */
184
	public function getIsNoUser() {
185
		return $this->isNoUser;
186
	}
187
188
	/**
189
	 * setType
190
	 * @param string $type
191
	 * @return String
192
	 */
193
	public function setType($type) {
194
		$this->type = $type;
195
		return $this->type;
196
	}
197
198
	/**
199
	 * setDisplayName
200
	 * @param string $displayName
201
	 * @return String
202
	 */
203
	public function setDisplayName($displayName) {
204
		$this->displayName = $displayName;
205
		return $this->displayName;
206
	}
207
208
	/**
209
	 * setDescription
210
	 * @param string $description
211
	 * @return String
212
	 */
213
	public function setDescription($description) {
214
		$this->description = $description;
215
		return $this->description;
216
	}
217
218
	/**
219
	 * setEmailAddress
220
	 * @param string $emailAddress
221
	 * @return String
222
	 */
223
	public function setEmailAddress($emailAddress) {
224
		$this->emailAddress = $emailAddress;
225
		return $this->emailAddress;
226
	}
227
228
	/**
229
	 * setLanguage
230
	 * @param string $language
231
	 * @return String
232
	 */
233
	public function setLanguage($language) {
234
		$this->language = $language;
235
		return $this->language;
236
	}
237
238
	/**
239
	 * setOrganisation
240
	 * @param string $organisation
241
	 * @return String
242
	 */
243
	public function setOrganisation($organisation) {
244
		$this->organisation = $organisation;
245
		return $this->organisation;
246
	}
247
248
	/**
249
	 * search
250
	 * @return Array
251
	 * @throws InvalidShareTypeException
252
	 */
253
	public static function search() {
254
		return [];
255
	}
256
257
	/**
258
	 * getMembers
259
	 * @return array
260
	 */
261
	public function getMembers() {
262
		return [];
263
	}
264
265
	/**
266
	 * getUserGroupChild
267
	 * @return UserGroupClass
268
	 */
269
	public static function getUserGroupChild($type, $id, $displayName = '', $emailAddress = '') {
270
		switch ($type) {
271
			case Group::TYPE:
272
				return new Group($id);
273
			case Circle::TYPE:
274
				return new Circle($id);
275
			case Contact::TYPE:
276
				return new Contact($id);
277
			case ContactGroup::TYPE:
278
				return new ContactGroup($id);
279
			case User::TYPE:
280
				return new User($id);
281
			case Email::TYPE:
282
				return new Email($id);
283
			case self::TYPE_PUBLIC:
284
				return new GenericUser($id, self::TYPE_PUBLIC);
285
			case self::TYPE_EXTERNAL:
286
				return new GenericUser($id, self::TYPE_EXTERNAL, $displayName, $emailAddress);
287
			default:
288
				throw new InvalidShareTypeException('Invalid share type (' . $type . ')');
289
			}
290
	}
291
292
	/**
293
	 * @return array
294
	 */
295
	public function jsonSerialize(): array {
296
		return	[
297
			'id'        	=> $this->getId(),
298
			'user'          => $this->getId(),
299
			'userId'        => $this->getId(),
300
			'type'       	=> $this->getType(),
301
			'displayName'	=> $this->getDisplayName(),
302
			'organisation'	=> $this->getOrganisation(),
303
			'emailAddress'	=> $this->getEmailAddress(),
304
			'language'		=> $this->getLanguage(),
305
			'desc' 			=> $this->getDescription(),
306
			'icon'			=> $this->getIcon(),
307
			'categories'	=> $this->getCategories(),
308
			'isNoUser'		=> $this->getIsNoUser(),
309
		];
310
	}
311
}
312