Completed
Pull Request — master (#794)
by René
04:12
created

Share::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 2
rs 10
c 0
b 0
f 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\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 integer 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
 */
45
class Share extends Entity implements JsonSerializable {
46
47
	/** @var string $token */
48
	protected $token;
49
50
	/** @var string $type */
51
	protected $type;
52
53
	/** @var int $pollId */
54
	protected $pollId;
55
56
	/** @var string $userId */
57
	protected $userId;
58
59
	/** @var string $userEmail */
60
	protected $userEmail;
61
62
	public function jsonSerialize() {
63
64
		return [
65
			'id' => intval($this->id),
66
			'token' => $this->token,
67
			'type' => $this->type,
68
			'pollId' => intval($this->pollId),
69
			'userId' => $this->userId,
70
			'userEmail' => $this->userEmail,
71
			'displayName' => $this->getDisplayName()
72
		];
73
	}
74
75
	private function getDisplayName() {
76
77
		if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) {
78
			return \OC::$server->getUserManager()->get($this->userId)->getDisplayName();
79
		} else {
80
			return $this->userId;
81
		}
82
	}
83
}
84