Passed
Pull Request — master (#1193)
by René
04:25
created

Poll::setAdminAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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 int getCreated()
43
 * @method void setCreated(integer $value)
44
 * @method int getExpire()
45
 * @method void setExpire(integer $value)
46
 * @method int getDeleted()
47
 * @method void setDeleted(integer $value)
48
 * @method string getAccess()
49
 * @method void setAccess(string $value)
50
 * @method int getAnonymous()
51
 * @method void setAnonymous(integer $value)
52
 * @method int getFullAnonymous()
53
 * @method void setFullAnonymous(integer $value)
54
 * @method int 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 int getVoteLimit()
61
 * @method void setVoteLimit(integer $value)
62
 * @method string getShowResults()
63
 * @method void setShowResults(string $value)
64
 * @method int getAdminAccess()
65
 * @method void setAdminAccess(integer $value)
66
 * @method int getImportant()
67
 * @method void setImportant(integer $value)
68
 */
69
class Poll extends Entity implements JsonSerializable {
70
	public const TYPE_DATE = 'datePoll';
71
	public const TYPE_TEXT = 'textPoll';
72
73
	/** @var string $type */
74
	protected $type;
75
76
	/** @var string $title */
77
	protected $title;
78
79
	/** @var string $description */
80
	protected $description;
81
82
	/** @var string $owner */
83
	protected $owner;
84
85
	/** @var int $created */
86
	protected $created;
87
88
	/** @var int $expire */
89
	protected $expire;
90
91
	/** @var int $deleted */
92
	protected $deleted;
93
94
	/** @var string $access */
95
	protected $access;
96
97
	/** @var int $anonymous */
98
	protected $anonymous;
99
100
	/** @var int $fullAnonymous */
101
	protected $fullAnonymous;
102
103
	/** @var int $allowMaybe */
104
	protected $allowMaybe;
105
106
	/** @var string $options */
107
	protected $options;
108
109
	/** @var string $settings*/
110
	protected $settings;
111
112
	/** @var int $voteLimit*/
113
	protected $voteLimit;
114
115
	/** @var string $showResults */
116
	protected $showResults;
117
118
	/** @var int $adminAccess*/
119
	protected $adminAccess;
120
121
	/** @var int $important*/
122
	protected $important;
123
124
	public function jsonSerialize() {
125
		return [
126
			'id' => intval($this->id),
127
			'type' => $this->type,
128
			'title' => $this->title,
129
			'description' => $this->description,
130
			'owner' => $this->owner,
131
			'created' => intval($this->created),
132
			'expire' => intval($this->expire),
133
			'deleted' => intval($this->deleted),
134
			'access' => $this->access,
135
			'anonymous' => intval($this->anonymous),
136
			'allowMaybe' => intval($this->allowMaybe),
137
			'settings' => $this->settings,
138
			'voteLimit' => intval($this->voteLimit),
139
			'showResults' => $this->showResults === 'expired' ? 'closed' : $this->showResults,
140
			'adminAccess' => intVal($this->adminAccess),
141
			'ownerDisplayName' => $this->getDisplayName(),
142
			'important' => intVal($this->important)
143
		];
144
	}
145
146
	public function deserializeArray($array) {
147
		$this->setTitle(isset($array['title']) ? $array['title'] : $this->getTitle());
148
		$this->setDescription(isset($array['description']) ? $array['description'] : $this->getDescription());
149
		$this->setAccess(isset($array['access']) ? $array['access'] : $this->getAccess());
150
		$this->setExpire(isset($array['expire']) ? $array['expire'] : $this->getExpire());
151
		$this->setAnonymous(isset($array['anonymous']) ? $array['anonymous'] : $this->getAnonymous());
152
		$this->setAllowMaybe(isset($array['allowMaybe']) ? $array['allowMaybe'] : $this->getAllowMaybe());
153
		$this->setVoteLimit(isset($array['voteLimit']) ? $array['voteLimit'] : $this->getVoteLimit());
154
		$this->setShowResults(isset($array['showResults']) ? $array['showResults'] : $this->getShowResults());
155
		$this->setDeleted(isset($array['deleted']) ? $array['deleted'] : $this->getDeleted());
156
		$this->setAdminAccess(isset($array['adminAccess']) ? $array['adminAccess'] : $this->getAdminAccess());
157
		$this->setImportant(isset($array['important']) ? $array['important'] : $this->getImportant());
158
		return $this;
159
	}
160
161
	public function setAnonymous($value) {
162
		$this->anonymous = intval($value);
163
	}
164
165
	public function setAllowMaybe($value) {
166
		$this->allowMaybe = intval($value);
167
	}
168
169
	public function setAdminAccess($value) {
170
		$this->adminAccess = intval($value);
171
	}
172
173
	public function setImportant($value) {
174
		$this->important = intval($value);
175
	}
176
177
	private function getDisplayName() {
178
		if (\OC::$server->getUserManager()->get($this->owner) instanceof IUser) {
179
			return \OC::$server->getUserManager()->get($this->owner)->getDisplayName();
180
		} else {
181
			return $this->owner;
182
		}
183
	}
184
}
185