Completed
Pull Request — master (#1038)
by René
06:51 queued 55s
created

Share   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 22
c 0
b 0
f 0
dl 0
loc 46
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 12 1
A getDisplayName() 0 6 2
A externalUser() 0 2 1
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
31
/**
32
 * @method string getId()
33
 * @method void setId(integer $value)
34
 * @method string getToken()
35
 * @method void setToken(string $value)
36
 * @method string getType()
37
 * @method void setType(string $value)
38
 * @method int getPollId()
39
 * @method void setPollId(integer $value)
40
 * @method string getUserId()
41
 * @method void setUserId(string $value)
42
 * @method string getUserEmail()
43
 * @method void setUserEmail(string $value)
44
 * @method int getInvitationSent()
45
 * @method void setInvitationSent(integer $value)
46
 */
47
class Share extends Entity implements JsonSerializable {
48
49
	/** @var string $token */
50
	protected $token;
51
52
	/** @var string $type */
53
	protected $type;
54
55
	/** @var int $pollId */
56
	protected $pollId;
57
58
	/** @var string $userId */
59
	protected $userId;
60
61
	/** @var string $userEmail */
62
	protected $userEmail;
63
64
	/** @var string $invitationSent */
65
	protected $invitationSent;
66
67
	public function jsonSerialize() {
68
69
		return [
70
			'id' => intval($this->id),
71
			'token' => $this->token,
72
			'type' => $this->type,
73
			'pollId' => intval($this->pollId),
74
			'userId' => $this->userId,
75
			'userEmail' => $this->userEmail,
76
			'invitationSent' => intval($this->invitationSent),
77
			'displayName' => $this->getDisplayName(),
78
			'externalUser' => $this->externalUser()
79
		];
80
	}
81
82
	private function getDisplayName() {
83
84
		if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) {
85
			return \OC::$server->getUserManager()->get($this->userId)->getDisplayName();
86
		} else {
87
			return $this->userId;
88
		}
89
	}
90
91
	private function externalUser() {
92
		return (!\OC::$server->getUserManager()->get($this->userId) instanceof IUser);
93
	}
94
95
}
96