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

Poll::getDisplayName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author Vinzenz Rosenkranz <[email protected]>
6
 * @author Kai Schröer <[email protected]>
7
 * @author René Gieling <[email protected]>
8
*
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 *  This program is free software: you can redistribute it and/or modify
12
 *  it under the terms of the GNU Affero General Public License as
13
 *  published by the Free Software Foundation, either version 3 of the
14
 *  License, or (at your option) any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU Affero General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU Affero General Public License
22
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OCA\Polls\Db;
27
28
use JsonSerializable;
29
30
use OCP\IUser;
31
use OCP\AppFramework\Db\Entity;
32
33
/**
34
 * @method string getType()
35
 * @method void setType(string $value)
36
 * @method string getTitle()
37
 * @method void setTitle(string $value)
38
 * @method string getDescription()
39
 * @method void setDescription(string $value)
40
 * @method string getOwner()
41
 * @method void setOwner(string $value)
42
 * @method integer getCreated()
43
 * @method void setCreated(integer $value)
44
 * @method integer getExpire()
45
 * @method void setExpire(integer $value)
46
 * @method integer getDeleted()
47
 * @method void setDeleted(integer $value)
48
 * @method string getAccess()
49
 * @method void setAccess(string $value)
50
 * @method integer getAnonymous()
51
 * @method void setAnonymous(integer $value)
52
 * @method integer getFullAnonymous()
53
 * @method void setFullAnonymous(integer $value)
54
 * @method integer getAllowMaybe()
55
 * @method void setAllowMaybe(integer $value)
56
 * @method string getOptions()
57
 * @method void setOptions(string $value)
58
 * @method string getSettings()
59
 * @method void setSettings(string $value)
60
 * @method integer getVoteLimit()
61
 * @method void setVoteLimit(integer $value)
62
 * @method string getShowResults()
63
 * @method void setShowResults(string $value)
64
 * @method integer getAdminAccess()
65
 * @method void setAdminAccess(integer $value)
66
 */
67
class Poll extends Entity implements JsonSerializable {
68
69
	/** @var string $type */
70
	protected $type;
71
72
	/** @var string $title */
73
	protected $title;
74
75
	/** @var string $description */
76
	protected $description;
77
78
	/** @var string $owner */
79
	protected $owner;
80
81
	/** @var int $created */
82
	protected $created;
83
84
	/** @var int $expire */
85
	protected $expire;
86
87
	/** @var int $deleted */
88
	protected $deleted;
89
90
	/** @var string $access */
91
	protected $access;
92
93
	/** @var int $anonymous */
94
	protected $anonymous;
95
96
	/** @var int $fullAnonymous */
97
	protected $fullAnonymous;
98
99
	/** @var int $allowMaybe */
100
	protected $allowMaybe;
101
102
	/** @var string $options */
103
	protected $options;
104
105
	/** @var string $settings*/
106
	protected $settings;
107
108
	/** @var int $voteLimit*/
109
	protected $voteLimit;
110
111
	/** @var string $showResults */
112
	protected $showResults;
113
114
	/** @var int $adminAccess*/
115
	protected $adminAccess;
116
117
	public function jsonSerialize() {
118
		return [
119
			'id' => intval($this->id),
120
			'type' => $this->type,
121
			'title' => $this->title,
122
			'description' => $this->description,
123
			'owner' => $this->owner,
124
			'created' => intval($this->created),
125
			'expire' => intval($this->expire),
126
			'deleted' => intval($this->deleted),
127
			'access' => $this->access,
128
			'anonymous' => intval($this->anonymous),
129
			'fullAnonymous' => intval($this->fullAnonymous),
130
			'allowMaybe' => intval($this->allowMaybe),
131
			'options' => $this->options,
132
			'settings' => $this->settings,
133
			'voteLimit' => intval($this->voteLimit),
134
			'showResults' => $this->showResults,
135
			'adminAccess' => intVal($this->adminAccess),
136
			'ownerDisplayName' => $this->getDisplayName()
137
		];
138
	}
139
140
	private function getDisplayName() {
141
142
		if (\OC::$server->getUserManager()->get($this->owner) instanceof IUser) {
143
			return \OC::$server->getUserManager()->get($this->owner)->getDisplayName();
144
		} else {
145
			return $this->owner;
146
		}
147
	}
148
}
149