Passed
Pull Request — master (#1216)
by René
04:01
created

UserGroupClass::getOrganisation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 1
c 3
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\InvalidShareType;
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
	 * @NoAdminRequired
95
	 * @return String
96
	 */
97
	public function getId() {
98
		return $this->id;
99
	}
100
101
	/**
102
	 * getPublicId
103
	 * @NoAdminRequired
104
	 * @return String
105
	 */
106
	public function getPublicId() {
107
		return $this->id;
108
	}
109
110
	/**
111
	 * getUser
112
	 * @NoAdminRequired
113
	 * @return String
114
	 */
115
	public function getUser() {
116
		return $this->id;
117
	}
118
119
	/**
120
	 * getType
121
	 * @NoAdminRequired
122
	 * @return String
123
	 */
124
	public function getType() {
125
		return $this->type;
126
	}
127
128
	/**
129
	 * getLanguage
130
	 * @NoAdminRequired
131
	 * @return String
132
	 */
133
	public function getLanguage() {
134
		return $this->language;
135
	}
136
137
	/**
138
	 * getDisplayName
139
	 * @NoAdminRequired
140
	 * @return String
141
	 */
142
	public function getDisplayName() {
143
		return $this->displayName;
144
	}
145
146
	/**
147
	 * getDescription
148
	 * @NoAdminRequired
149
	 * @return String
150
	 */
151
	public function getDescription() {
152
		return $this->description;
153
	}
154
155
	/**
156
	 * getIcon
157
	 * @NoAdminRequired
158
	 * @return String
159
	 */
160
	public function getIcon() {
161
		return $this->icon;
162
	}
163
164
	/**
165
	 * getEmailAddress
166
	 * @NoAdminRequired
167
	 * @return String
168
	 */
169
	public function getEmailAddress() {
170
		return $this->emailAddress;
171
	}
172
173
	/**
174
	 * getOrganisation
175
	 * @NoAdminRequired
176
	 * @return String
177
	 */
178
	public function getOrganisation() {
179
		return $this->organisation;
180
	}
181
182
	/**
183
	 * getCategories
184
	 * @NoAdminRequired
185
	 * @return Array
186
	 */
187
	public function getCategories() {
188
		return $this->categories;
189
	}
190
191
	/**
192
	 * getOrganisation
193
	 * @NoAdminRequired
194
	 * @return String
195
	 */
196
	public function getIsNoUser() {
197
		return $this->isNoUser;
198
	}
199
200
	/**
201
	 * setType
202
	 * @NoAdminRequired
203
	 * @param string $type
204
	 * @return String
205
	 */
206
	public function setType($type) {
207
		$this->type = $type;
208
		return $this->type;
209
	}
210
211
	/**
212
	 * setDisplayName
213
	 * @NoAdminRequired
214
	 * @param string $displayName
215
	 * @return String
216
	 */
217
	public function setDisplayName($displayName) {
218
		$this->displayName = $displayName;
219
		return $this->displayName;
220
	}
221
222
	/**
223
	 * setDescription
224
	 * @NoAdminRequired
225
	 * @param string $description
226
	 * @return String
227
	 */
228
	public function setDescription($description) {
229
		$this->description = $description;
230
		return $this->description;
231
	}
232
233
	/**
234
	 * setEmailAddress
235
	 * @NoAdminRequired
236
	 * @param string $emailAddress
237
	 * @return String
238
	 */
239
	public function setEmailAddress($emailAddress) {
240
		$this->emailAddress = $emailAddress;
241
		return $this->emailAddress;
242
	}
243
244
	/**
245
	 * setLanguage
246
	 * @NoAdminRequired
247
	 * @param string $language
248
	 * @return String
249
	 */
250
	public function setLanguage($language) {
251
		$this->language = $language;
252
		return $this->language;
253
	}
254
255
	/**
256
	 * setOrganisation
257
	 * @NoAdminRequired
258
	 * @param string $organisation
259
	 * @return String
260
	 */
261
	public function setOrganisation($organisation) {
262
		$this->organisation = $organisation;
263
		return $this->organisation;
264
	}
265
266
	/**
267
	 * search
268
	 * @NoAdminRequired
269
	 * @return Array
270
	 */
271
	public static function search() {
272
		return [];
273
	}
274
275
	public static function getUserGroupChild($type, $id, $displayName = '', $emailAddress = '') {
276
		switch ($type) {
277
			case Group::TYPE:
278
				return new Group($id);
279
			case Circle::TYPE:
280
				return new Circle($id);
281
			case Contact::TYPE:
282
				return new Contact($id);
283
			case ContactGroup::TYPE:
284
				return new ContactGroup($id);
285
			case User::TYPE:
286
				return new User($id);
287
			case Email::TYPE:
288
				return new Email($id);
289
			case self::TYPE_PUBLIC:
290
				return new GenericUser($id, self::TYPE_PUBLIC);
291
			case self::TYPE_EXTERNAL:
292
				return new GenericUser($id, self::TYPE_EXTERNAL, $displayName, $emailAddress);
293
			default:
294
				throw new InvalidShareType('Invalid share type (' . $type . ')');
295
			}
296
	}
297
298
	/**
299
	 * @return array
300
	 */
301
	public function jsonSerialize(): array {
302
		return	[
303
			'id'        	=> $this->getId(),
304
			'user'          => $this->getId(),
305
			'userId'        => $this->getId(),
306
			'type'       	=> $this->getType(),
307
			'displayName'	=> $this->getDisplayName(),
308
			'organisation'	=> $this->getOrganisation(),
309
			'emailAddress'	=> $this->getEmailAddress(),
310
			'language'		=> $this->getLanguage(),
311
			'desc' 			=> $this->getDescription(),
312
			'icon'			=> $this->getIcon(),
313
			'categories'	=> $this->getCategories(),
314
			'isNoUser'		=> $this->getIsNoUser(),
315
		];
316
	}
317
}
318