Passed
Pull Request — master (#1169)
by René
06:00
created

Share::getDisplayName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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\Db;
25
26
use JsonSerializable;
27
28
use OCP\IUser;
29
use OCP\AppFramework\Db\Entity;
30
use OCA\Polls\Model\UserGroupClass;
31
32
/**
33
 * @method string getId()
34
 * @method void setId(integer $value)
35
 * @method string getToken()
36
 * @method void setToken(string $value)
37
 * @method string getType()
38
 * @method void setType(string $value)
39
 * @method int getPollId()
40
 * @method void setPollId(integer $value)
41
 * @method string getUserId()
42
 * @method void setUserId(string $value)
43
 * @method string getUserEmail()
44
 * @method void setUserEmail(string $value)
45
 * @method int getInvitationSent()
46
 * @method void setInvitationSent(integer $value)
47
 * @method int getDisplayName()
48
 * @method void setDisplayName(string $value)
49
 */
50
class Share extends Entity implements JsonSerializable {
51
	public const TYPE_USER = 'user';
52
	public const TYPE_EMAIL = 'email';
53
	public const TYPE_CIRCLE = 'circle';
54
	public const TYPE_GROUP = 'group';
55
	public const TYPE_CONTACTGROUP = 'contactGroup';
56
	public const TYPE_CONTACT = 'contact';
57
	public const TYPE_PUBLIC = 'public';
58
	public const TYPE_EXTERNAL = 'external';
59
60
	/** @var string $token */
61
	protected $token;
62
63
	/** @var string $type */
64
	protected $type;
65
66
	/** @var int $pollId */
67
	protected $pollId;
68
69
	/** @var string $userId */
70
	protected $userId;
71
72
	/** @var string $userEmail */
73
	protected $userEmail;
74
75
	/** @var string $invitationSent */
76
	protected $invitationSent;
77
78
	/** @var string $displayName */
79
	protected $displayName;
80
81
	public function jsonSerialize() {
82
		return [
83
			'id' => intval($this->id),
84
			'token' => $this->token,
85
			'type' => $this->type,
86
			'pollId' => intval($this->pollId),
87
			'userId' => $this->userId,
88
			'userEmail' => $this->userEmail,
89
			'invitationSent' => intval($this->invitationSent),
90
			'displayName' => $this->displayName,
91
			'externalUser' => $this->externalUser(),
92
			'shareeDetail' => UserGroupClass::getUserGroupChild($this->type, $this->userId)
93
		];
94
	}
95
96
	private function externalUser() {
97
		return (!\OC::$server->getUserManager()->get($this->userId) instanceof IUser);
98
	}
99
}
100