|
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
|
|
|
use OCA\Polls\Model\User; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @method string getType() |
|
36
|
|
|
* @method void setType(string $value) |
|
37
|
|
|
* @method string getTitle() |
|
38
|
|
|
* @method void setTitle(string $value) |
|
39
|
|
|
* @method string getDescription() |
|
40
|
|
|
* @method void setDescription(string $value) |
|
41
|
|
|
* @method string getOwner() |
|
42
|
|
|
* @method void setOwner(string $value) |
|
43
|
|
|
* @method int getCreated() |
|
44
|
|
|
* @method void setCreated(integer $value) |
|
45
|
|
|
* @method int getExpire() |
|
46
|
|
|
* @method void setExpire(integer $value) |
|
47
|
|
|
* @method int getDeleted() |
|
48
|
|
|
* @method void setDeleted(integer $value) |
|
49
|
|
|
* @method string getAccess() |
|
50
|
|
|
* @method void setAccess(string $value) |
|
51
|
|
|
* @method int getAnonymous() |
|
52
|
|
|
* @method void setAnonymous(integer $value) |
|
53
|
|
|
* @method int getFullAnonymous() |
|
54
|
|
|
* @method void setFullAnonymous(integer $value) |
|
55
|
|
|
* @method int getallowComment() |
|
56
|
|
|
* @method void setallowComment(integer $value) |
|
57
|
|
|
* @method int getAllowMaybe() |
|
58
|
|
|
* @method void setAllowMaybe(integer $value) |
|
59
|
|
|
* @method string getAllowProposals() |
|
60
|
|
|
* @method void setAllowProposals(string $value) |
|
61
|
|
|
* @method int getProposalsExpire() |
|
62
|
|
|
* @method void setProposalsExpire(integer $value) |
|
63
|
|
|
* @method string getOptions() |
|
64
|
|
|
* @method void setOptions(string $value) |
|
65
|
|
|
* @method string getSettings() |
|
66
|
|
|
* @method void setSettings(string $value) |
|
67
|
|
|
* @method int getVoteLimit() |
|
68
|
|
|
* @method void setVoteLimit(integer $value) |
|
69
|
|
|
* @method int getOptionLimit() |
|
70
|
|
|
* @method void setOptionLimit(integer $value) |
|
71
|
|
|
* @method string getShowResults() |
|
72
|
|
|
* @method void setShowResults(string $value) |
|
73
|
|
|
* @method int getAdminAccess() |
|
74
|
|
|
* @method void setAdminAccess(integer $value) |
|
75
|
|
|
* @method int getImportant() |
|
76
|
|
|
* @method void setImportant(integer $value) |
|
77
|
|
|
* @method int getHideBookedUp() |
|
78
|
|
|
* @method void setHideBookedUp(integer $value) |
|
79
|
|
|
*/ |
|
80
|
|
|
class Poll extends Entity implements JsonSerializable { |
|
81
|
|
|
public const TYPE_DATE = 'datePoll'; |
|
82
|
|
|
public const TYPE_TEXT = 'textPoll'; |
|
83
|
|
|
public const ACCESS_HIDDEN = 'hidden'; |
|
84
|
|
|
public const ACCESS_PUBLIC = 'public'; |
|
85
|
|
|
public const SHOW_RESULTS_ALWAYS = 'always'; |
|
86
|
|
|
public const SHOW_RESULTS_CLOSED = 'closed'; |
|
87
|
|
|
public const SHOW_RESULTS_NEVER = 'never'; |
|
88
|
|
|
public const PROPOSAL_DISALLOW = 'disallow'; |
|
89
|
|
|
public const PROPOSAL_ALLOW = 'allow'; |
|
90
|
|
|
public const PROPOSAL_RELEASE = 'release'; |
|
91
|
|
|
|
|
92
|
|
|
/** @var string $type */ |
|
93
|
|
|
protected $type; |
|
94
|
|
|
|
|
95
|
|
|
/** @var string $title */ |
|
96
|
|
|
protected $title; |
|
97
|
|
|
|
|
98
|
|
|
/** @var string $description */ |
|
99
|
|
|
protected $description; |
|
100
|
|
|
|
|
101
|
|
|
/** @var string $owner */ |
|
102
|
|
|
protected $owner; |
|
103
|
|
|
|
|
104
|
|
|
/** @var int $created */ |
|
105
|
|
|
protected $created; |
|
106
|
|
|
|
|
107
|
|
|
/** @var int $expire */ |
|
108
|
|
|
protected $expire; |
|
109
|
|
|
|
|
110
|
|
|
/** @var int $deleted */ |
|
111
|
|
|
protected $deleted; |
|
112
|
|
|
|
|
113
|
|
|
/** @var string $access */ |
|
114
|
|
|
protected $access; |
|
115
|
|
|
|
|
116
|
|
|
/** @var int $anonymous */ |
|
117
|
|
|
protected $anonymous; |
|
118
|
|
|
|
|
119
|
|
|
/** @var int $fullAnonymous */ |
|
120
|
|
|
protected $fullAnonymous; |
|
121
|
|
|
|
|
122
|
|
|
/** @var int $allowMaybe */ |
|
123
|
|
|
protected $allowMaybe; |
|
124
|
|
|
|
|
125
|
|
|
/** @var string $allowProposals */ |
|
126
|
|
|
protected $allowProposals; |
|
127
|
|
|
|
|
128
|
|
|
/** @var string $proposalsExpire */ |
|
129
|
|
|
protected $proposalsExpire; |
|
130
|
|
|
|
|
131
|
|
|
/** @var string $options */ |
|
132
|
|
|
protected $options; |
|
133
|
|
|
|
|
134
|
|
|
/** @var string $settings*/ |
|
135
|
|
|
protected $settings; |
|
136
|
|
|
|
|
137
|
|
|
/** @var int $voteLimit*/ |
|
138
|
|
|
protected $voteLimit; |
|
139
|
|
|
|
|
140
|
|
|
/** @var int $optionLimit*/ |
|
141
|
|
|
protected $optionLimit; |
|
142
|
|
|
|
|
143
|
|
|
/** @var string $showResults */ |
|
144
|
|
|
protected $showResults; |
|
145
|
|
|
|
|
146
|
|
|
/** @var int $adminAccess*/ |
|
147
|
|
|
protected $adminAccess; |
|
148
|
|
|
|
|
149
|
|
|
/** @var int $important*/ |
|
150
|
|
|
protected $important; |
|
151
|
|
|
|
|
152
|
|
|
/** @var int $allowComment*/ |
|
153
|
|
|
protected $allowComment; |
|
154
|
|
|
|
|
155
|
|
|
/** @var int $hideBookedUp*/ |
|
156
|
|
|
protected $hideBookedUp; |
|
157
|
|
|
|
|
158
|
|
|
public function jsonSerialize() { |
|
159
|
|
|
return [ |
|
160
|
|
|
'id' => intval($this->id), |
|
161
|
|
|
'type' => $this->type, |
|
162
|
|
|
'title' => $this->title, |
|
163
|
|
|
'description' => $this->description, |
|
164
|
|
|
'descriptionSafe' => $this->getDescriptionSafe(), |
|
165
|
|
|
'owner' => $this->owner, |
|
166
|
|
|
'created' => intval($this->created), |
|
167
|
|
|
'expire' => intval($this->expire), |
|
168
|
|
|
'deleted' => intval($this->deleted), |
|
169
|
|
|
'access' => $this->access, |
|
170
|
|
|
'anonymous' => intval($this->anonymous), |
|
171
|
|
|
'allowComment' => intval($this->allowComment), |
|
172
|
|
|
'allowMaybe' => intval($this->allowMaybe), |
|
173
|
|
|
'allowProposals' => $this->allowProposals, |
|
174
|
|
|
'proposalsExpire' => intval($this->proposalsExpire), |
|
175
|
|
|
'settings' => $this->settings, |
|
176
|
|
|
'voteLimit' => intval($this->voteLimit), |
|
177
|
|
|
'optionLimit' => intval($this->optionLimit), |
|
178
|
|
|
'showResults' => $this->showResults === 'expired' ? Poll::SHOW_RESULTS_CLOSED : $this->showResults, |
|
179
|
|
|
'adminAccess' => intVal($this->adminAccess), |
|
180
|
|
|
'ownerDisplayName' => $this->getDisplayName(), |
|
181
|
|
|
'important' => intVal($this->important), |
|
182
|
|
|
'hideBookedUp' => intVal($this->hideBookedUp) |
|
183
|
|
|
]; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @return static |
|
188
|
|
|
*/ |
|
189
|
|
|
public function deserializeArray(array $array): self { |
|
190
|
|
|
$this->setTitle($array['title'] ?? $this->getTitle()); |
|
191
|
|
|
$this->setDescription($array['description'] ?? $this->getDescription()); |
|
192
|
|
|
$this->setAccess($array['access'] ?? $this->getAccess()); |
|
193
|
|
|
$this->setExpire($array['expire'] ?? $this->getExpire()); |
|
194
|
|
|
$this->setAnonymous($array['anonymous'] ?? $this->getAnonymous()); |
|
195
|
|
|
$this->setallowComment($array['allowComment'] ?? $this->getallowComment()); |
|
196
|
|
|
$this->setAllowMaybe($array['allowMaybe'] ?? $this->getAllowMaybe()); |
|
197
|
|
|
$this->setAllowProposals($array['allowProposals'] ?? $this->getAllowProposals()); |
|
198
|
|
|
$this->setProposalsExpire($array['proposalsExpire'] ?? $this->getProposalsExpire()); |
|
199
|
|
|
$this->setVoteLimit($array['voteLimit'] ?? $this->getVoteLimit()); |
|
200
|
|
|
$this->setOptionLimit($array['optionLimit'] ?? $this->getOptionLimit()); |
|
201
|
|
|
$this->setShowResults($array['showResults'] ?? $this->getShowResults()); |
|
202
|
|
|
$this->setDeleted($array['deleted'] ?? $this->getDeleted()); |
|
203
|
|
|
$this->setAdminAccess($array['adminAccess'] ?? $this->getAdminAccess()); |
|
204
|
|
|
$this->setImportant($array['important'] ?? $this->getImportant()); |
|
205
|
|
|
$this->setHideBookedUp($array['hideBookedUp'] ?? $this->getHideBookedUp()); |
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function getExpired(): bool { |
|
210
|
|
|
return ( |
|
211
|
|
|
$this->getExpire() > 0 |
|
212
|
|
|
&& $this->getExpire() < time() |
|
213
|
|
|
); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
public function getProposalsExpired(): bool { |
|
217
|
|
|
return ( |
|
218
|
|
|
$this->getProposalsExpire() > 0 |
|
219
|
|
|
&& $this->getProposalsExpire() < time() |
|
220
|
|
|
); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function getDescriptionSafe() { |
|
224
|
|
|
return htmlspecialchars($this->description); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
private function getDisplayName(): string { |
|
228
|
|
|
return \OC::$server->getUserManager()->get($this->owner) instanceof IUser |
|
229
|
|
|
? \OC::$server->getUserManager()->get($this->owner)->getDisplayName() |
|
230
|
|
|
: $this->owner; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
public function getOwnerUserObject(): User { |
|
234
|
|
|
return new User($this->owner); |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
|