Passed
Pull Request — master (#1128)
by René
04:45
created

Email::getIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
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 $type;
0 ignored issues
show
introduced by
The private property $type is not used, and could be removed.
Loading history...
41
42
	/** @var string */
43
	private $displayName = '';
44
45
	/** @var string */
46
	private $desc = '';
0 ignored issues
show
introduced by
The private property $desc is not used, and could be removed.
Loading history...
47
48
	/** @var string */
49
	private $emailAddress = '';
50
51
	/** @var array */
52
	private $contact;
0 ignored issues
show
introduced by
The private property $contact is not used, and could be removed.
Loading history...
53
54
	/**
55
	 * User constructor.
56
	 * @param $type
57
	 * @param $id
58
	 * @param $emailAddress
59
	 * @param $displayName
60
	 */
61
	public function __construct(
62
		$id,
63
		$emailAddress = '',
64
		$displayName = ''
65
	) {
66
		$this->id = $id;
67
		$this->emailAddress = $emailAddress;
68
		$this->displayName = $displayName;
69
70
		$this->l10n = \OC::$server->getL10N('polls');
71
	}
72
73
	/**
74
	 * Get id
75
	 * @NoAdminRequired
76
	 * @return String
77
	 */
78
	public function getId() {
79
		return $this->id;
80
	}
81
82
	/**
83
	 * getUser
84
	 * @NoAdminRequired
85
	 * @return String
86
	 */
87
	public function getUser() {
88
		return $this->id;
89
	}
90
91
	/**
92
	 * Get user type
93
	 * @NoAdminRequired
94
	 * @return String
95
	 */
96
	public function getType() {
97
		return self::TYPE;
98
	}
99
100
	/**
101
	 * Get language of user, if type = TYPE_USER
102
	 * @NoAdminRequired
103
	 * @return String
104
	 */
105
	public function getLanguage() {
106
		return '';
107
	}
108
109
	/**
110
	 * Get displayName
111
	 * @NoAdminRequired
112
	 * @return String
113
	 */
114
	public function getDisplayName() {
115
		if ($this->displayName) {
116
			return $this->displayName;
117
		}
118
		return $this->id;
119
	}
120
121
	/**
122
	 * Get additional description, if available
123
	 * @NoAdminRequired
124
	 * @return String
125
	 */
126
	public function getDesc() {
127
		return \OC::$server->getL10N('polls')->t('External Email');
128
	}
129
130
	/**
131
	 * Get email address
132
	 * @NoAdminRequired
133
	 * @return String
134
	 */
135
	public function getEmailAddress() {
136
		if ($this->emailAddress) {
137
			return $this->emailAddress;
138
		}
139
		return $this->id;
140
	}
141
142
	/**
143
	 * Get organisation, if type = TYPE_CONTACT
144
	 * @NoAdminRequired
145
	 * @return String
146
	 */
147
	public function getOrganisation() {
148
		return '';
149
	}
150
151
	/**
152
	 * Get icon class
153
	 * @NoAdminRequired
154
	 * @return String
155
	 */
156
	public function getIcon() {
157
		return 'icon-mail';
158
	}
159
160
	// no search right now
161
	public static function search($query) {
162
		return [];
163
	}
164
165
	/**
166
	 * @return array
167
	 */
168
	public function jsonSerialize(): array {
169
		return	[
170
			'id'        	=> $this->id,
171
			'user'          => $this->id,
172
			'type'       	=> $this->getType(),
173
			'displayName'	=> $this->getDisplayName(),
174
			'organisation'	=> $this->getOrganisation(),
175
			'emailAddress'	=> $this->getEmailAddress(),
176
			'desc' 			=> $this->getDesc(),
177
			'icon'			=> $this->getIcon(),
178
			'isNoUser'		=> true,
179
			'isGuest'		=> true,
180
		];
181
	}
182
}
183