Passed
Pull Request — master (#1128)
by René
06:43
created

Email::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 12
rs 9.9
c 1
b 0
f 0
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
25
namespace OCA\Polls\Model;
26
27
use OCP\IL10N;
28
use OCA\Polls\Interfaces\IUserObj;
29
30
class Email implements \JsonSerializable, IUserObj {
31
	public const TYPE = 'email';
32
33
	/** @var IL10N */
34
	private $l10n;
35
36
	/** @var string */
37
	private $id;
38
39
	/** @var string */
40
	private $displayName = '';
41
42
	/** @var string */
43
	private $emailAddress = '';
44
45
	/**
46
	 * User constructor.
47
	 * @param $id
48
	 * @param $emailAddress
49
	 * @param $displayName
50
	 */
51
	public function __construct(
52
		$id,
53
		$emailAddress = '',
54
		$displayName = ''
55
	) {
56
		$this->id = $id;
57
		$this->emailAddress = $emailAddress;
58
		$this->displayName = $displayName;
59
60
		$this->l10n = \OC::$server->getL10N('polls');
61
	}
62
63
	/**
64
	 * Get id
65
	 * @NoAdminRequired
66
	 * @return String
67
	 */
68
	public function getId() {
69
		return $this->id;
70
	}
71
72
	/**
73
	 * getUser
74
	 * @NoAdminRequired
75
	 * @return String
76
	 */
77
	public function getUser() {
78
		return $this->id;
79
	}
80
81
	/**
82
	 * Get user type
83
	 * @NoAdminRequired
84
	 * @return String
85
	 */
86
	public function getType() {
87
		return self::TYPE;
88
	}
89
90
	/**
91
	 * @NoAdminRequired
92
	 * @return String
93
	 */
94
	public function getLanguage() {
95
		return '';
96
	}
97
98
	/**
99
	 * Get displayName
100
	 * @NoAdminRequired
101
	 * @return String
102
	 */
103
	public function getDisplayName() {
104
		if ($this->displayName) {
105
			return $this->displayName;
106
		}
107
		return $this->id;
108
	}
109
110
	/**
111
	 * Get additional description, if available
112
	 * @NoAdminRequired
113
	 * @return String
114
	 */
115
	public function getDescription() {
116
		return \OC::$server->getL10N('polls')->t('External Email');
117
	}
118
119
	/**
120
	 * Get email address
121
	 * @NoAdminRequired
122
	 * @return String
123
	 */
124
	public function getEmailAddress() {
125
		if ($this->emailAddress) {
126
			return $this->emailAddress;
127
		}
128
		return $this->id;
129
	}
130
131
	/**
132
	 * @NoAdminRequired
133
	 * @return String
134
	 */
135
	public function getOrganisation() {
136
		return '';
137
	}
138
139
	/**
140
	 * Get icon class
141
	 * @NoAdminRequired
142
	 * @return String
143
	 */
144
	public function getIcon() {
145
		return 'icon-mail';
146
	}
147
148
	// no search right now
149
	public static function search($query) {
150
		return [];
151
	}
152
153
	/**
154
	 * @return array
155
	 */
156
	public function jsonSerialize(): array {
157
		return	[
158
			'id'        	=> $this->id,
159
			'user'          => $this->id,
160
			'type'       	=> $this->getType(),
161
			'displayName'	=> $this->getDisplayName(),
162
			'organisation'	=> $this->getOrganisation(),
163
			'emailAddress'	=> $this->getEmailAddress(),
164
			'desc' 			=> $this->getDescription(),
165
			'icon'			=> $this->getIcon(),
166
			'isNoUser'		=> true,
167
			'isGuest'		=> true,
168
		];
169
	}
170
}
171