-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathForm.php
More file actions
203 lines (189 loc) Β· 6.07 KB
/
Form.php
File metadata and controls
203 lines (189 loc) Β· 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Forms\Db;
use OCA\Forms\Constants;
use OCA\Forms\ResponseDefinitions;
use OCP\AppFramework\Db\Entity;
/**
* @psalm-import-type FormsAccess from ResponseDefinitions
* @method string getHash()
* @method void setHash(string $value)
* @method string getTitle()
* @method void setTitle(string $value)
* @method string getDescription()
* @method void setDescription(string $value)
* @method string getOwnerId()
* @method void setOwnerId(string $value)
* @method int|null getFileId()
* @method void setFileId(int|null $value)
* @method string|null getFileFormat()
* @method void setFileFormat(string|null $value)
* @method int getCreated()
* @method void setCreated(int $value)
* @method int getExpires()
* @method void setExpires(int $value)
* @method int getIsAnonymous()
* @method void setIsAnonymous(bool $value)
* @method int getSubmitMultiple()
* @method void setSubmitMultiple(bool $value)
* @method int getAllowEditSubmissions()
* @method void setAllowEditSubmissions(bool $value)
* @method int getShowExpiration()
* @method void setShowExpiration(bool $value)
* @method int getLastUpdated()
* @method void setLastUpdated(int $value)
* @method string|null getSubmissionMessage()
* @method void setSubmissionMessage(string|null $value)
* @method int getState()
* @psalm-method 0|1|2 getState()
* @method void setState(int|null $value)
* @psalm-method void setState(0|1|2|null $value)
* @method string getLockedBy()
* @method void setLockedBy(string|null $value)
* @method int getLockedUntil()
* @method void setLockedUntil(int|null $value)
* @method int getConfirmationEmailEnabled()
* @method void setConfirmationEmailEnabled(bool $value)
* @method string|null getConfirmationEmailSubject()
* @method void setConfirmationEmailSubject(string|null $value)
* @method string|null getConfirmationEmailBody()
* @method void setConfirmationEmailBody(string|null $value)
*/
class Form extends Entity {
protected $hash;
protected $title;
protected $description;
protected $ownerId;
protected $fileId;
protected $fileFormat;
protected $accessEnum;
protected $created;
protected $expires;
protected $isAnonymous;
protected $submitMultiple;
protected $allowEditSubmissions;
protected $showExpiration;
protected $submissionMessage;
protected $lastUpdated;
protected $state;
protected $lockedBy;
protected $lockedUntil;
protected $confirmationEmailEnabled;
protected $confirmationEmailSubject;
protected $confirmationEmailBody;
/**
* Form constructor.
*/
public function __construct() {
$this->addType('created', 'integer');
$this->addType('expires', 'integer');
$this->addType('isAnonymous', 'boolean');
$this->addType('submitMultiple', 'boolean');
$this->addType('allowEditSubmissions', 'boolean');
$this->addType('showExpiration', 'boolean');
$this->addType('lastUpdated', 'integer');
$this->addType('state', 'integer');
$this->addType('lockedBy', 'string');
$this->addType('lockedUntil', 'integer');
$this->addType('confirmationEmailEnabled', 'boolean');
}
// JSON-Decoding of access-column.
/**
* @return FormsAccess
*/
public function getAccess(): array {
$accessEnum = $this->getAccessEnum();
$access = [];
switch ($accessEnum) {
case Constants::FORM_ACCESS_NOPUBLICSHARE:
$access['permitAllUsers'] = false;
$access['showToAllUsers'] = false;
break;
case Constants::FORM_ACCESS_PERMITALLUSERS:
$access['permitAllUsers'] = true;
$access['showToAllUsers'] = false;
break;
case Constants::FORM_ACCESS_SHOWTOALLUSERS:
$access['permitAllUsers'] = true;
$access['showToAllUsers'] = true;
break;
}
return $access;
}
// JSON-Encoding of access-column.
/**
* @param FormsAccess $access
*/
public function setAccess(array $access): void {
// No further permissions -> 0
// Permit all users, but don't show in navigation -> 1
// Permit all users and show in navigation -> 2
if (!$access['permitAllUsers']) {
// no permit means no public share
$value = Constants::FORM_ACCESS_NOPUBLICSHARE;
} elseif ($access['showToAllUsers']) {
// permit all + show to all
$value = Constants::FORM_ACCESS_SHOWTOALLUSERS;
} else {
// only permit all but not shown to all
$value = Constants::FORM_ACCESS_PERMITALLUSERS;
}
$this->setAccessEnum($value);
}
/**
* @return array{
* id: int,
* hash: string,
* title: string,
* description: string,
* ownerId: string,
* fileId: ?int,
* fileFormat: ?string,
* created: int,
* access: FormsAccess,
* expires: int,
* isAnonymous: bool,
* submitMultiple: bool,
* allowEditSubmissions: bool,
* showExpiration: bool,
* lastUpdated: int,
* submissionMessage: ?string,
* state: 0|1|2,
* lockedBy: ?string,
* lockedUntil: ?int,
* confirmationEmailEnabled: bool,
* confirmationEmailSubject: ?string,
* confirmationEmailBody: ?string,
* }
*/
public function read() {
return [
'id' => $this->getId(),
'hash' => $this->getHash(),
'title' => (string)$this->getTitle(),
'description' => (string)$this->getDescription(),
'ownerId' => $this->getOwnerId(),
'fileId' => $this->getFileId(),
'fileFormat' => $this->getFileFormat(),
'created' => $this->getCreated(),
'access' => $this->getAccess(),
'expires' => (int)$this->getExpires(),
'isAnonymous' => (bool)$this->getIsAnonymous(),
'submitMultiple' => (bool)$this->getSubmitMultiple(),
'allowEditSubmissions' => (bool)$this->getAllowEditSubmissions(),
'showExpiration' => (bool)$this->getShowExpiration(),
'lastUpdated' => (int)$this->getLastUpdated(),
'submissionMessage' => $this->getSubmissionMessage(),
'state' => $this->getState(),
'lockedBy' => $this->getLockedBy(),
'lockedUntil' => $this->getLockedUntil(),
'confirmationEmailEnabled' => (bool)$this->getConfirmationEmailEnabled(),
'confirmationEmailSubject' => $this->getConfirmationEmailSubject(),
'confirmationEmailBody' => $this->getConfirmationEmailBody(),
];
}
}