Completed
Push — master ( 9466d5...cf3e21 )
by René
18s queued 15s
created

Poll   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 14
eloc 49
c 0
b 0
f 0
dl 0
loc 91
ccs 0
cts 33
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 18 1
A getDisplayName() 0 6 2
B deserializeArray() 0 12 11
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
			'allowMaybe' => intval($this->allowMaybe),
130
			'settings' => $this->settings,
131
			'voteLimit' => intval($this->voteLimit),
132
			'showResults' => $this->showResults,
133
			'adminAccess' => intVal($this->adminAccess),
134
			'ownerDisplayName' => $this->getDisplayName()
135
		];
136
	}
137
138
	public function deserializeArray($array) {
139
		$this->setTitle(isset($array['title']) ? $array['title'] : $this->getTitle());
140
		$this->setDescription(isset($array['description']) ? $array['description'] : $this->getDescription());
141
		$this->setAccess(isset($array['access']) ? $array['access'] : $this->getAccess());
142
		$this->setExpire(isset($array['expire']) ? $array['expire'] : $this->getExpire());
143
		$this->setAnonymous(isset($array['anonymous']) ? $array['anonymous'] : $this->getAnonymous());
144
		$this->setAllowMaybe(isset($array['allowMaybe']) ? $array['allowMaybe'] : $this->getAllowMaybe());
145
		$this->setVoteLimit(isset($array['voteLimit']) ? $array['voteLimit'] : $this->getVoteLimit());
146
		$this->setShowResults(isset($array['showResults']) ? $array['showResults'] : $this->getShowResults());
147
		$this->setDeleted(isset($array['deleted']) ? $array['deleted'] : $this->getDeleted());
148
		$this->setAdminAccess(isset($array['adminAccess']) ? $array['adminAccess'] : $this->getAdminAccess());
149
		return $this;
150
	}
151
152
	private function getDisplayName() {
153
154
		if (\OC::$server->getUserManager()->get($this->owner) instanceof IUser) {
155
			return \OC::$server->getUserManager()->get($this->owner)->getDisplayName();
156
		} else {
157
			return $this->owner;
158
		}
159
	}
160
}
161