|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EWW\Dpf\Domain\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use TypeError; |
|
7
|
|
|
use TYPO3\CMS\Core\FormProtection\FormProtectionFactory; |
|
8
|
|
|
|
|
9
|
|
|
/* |
|
10
|
|
|
* This file is part of the TYPO3 CMS project. |
|
11
|
|
|
* |
|
12
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
13
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
14
|
|
|
* of the License, or any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* For the full copyright and license information, please read the |
|
17
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
18
|
|
|
* |
|
19
|
|
|
* The TYPO3 project - inspiring people to share! |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
class DocumentForm extends AbstractFormElement |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string CSRF token for this form |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $csrfToken; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* |
|
32
|
|
|
* @var integer |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $documentUid; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* |
|
38
|
|
|
* @var boolean |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $primaryFileMandatory; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $fedoraPid; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $files; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* |
|
56
|
|
|
* @var string |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $objectState; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* |
|
62
|
|
|
* @var boolean |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $valid = false; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* |
|
68
|
|
|
* @var string |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $processNumber; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var bool |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $temporary; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var string |
|
79
|
|
|
*/ |
|
80
|
|
|
protected $comment = ''; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Assign and persist CSRF token for later form validation. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $csrfToken |
|
86
|
|
|
*/ |
|
87
|
|
|
public function generateCsrfToken() |
|
88
|
|
|
{ |
|
89
|
|
|
$formProtection = FormProtectionFactory::get(); |
|
90
|
|
|
$this->csrfToken = $formProtection->generateToken('DocumentForm', 'construct', 'DocumentForm'); |
|
91
|
|
|
$formProtection->persistSessionToken(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Set the CSRF token for this form |
|
96
|
|
|
* |
|
97
|
|
|
* Used when creating a new instance from request form data. |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $csrfToken CSRF token to set |
|
100
|
|
|
* @throws Exception if the given string is empty. |
|
101
|
|
|
* @throws TypeError if the given string is null |
|
102
|
|
|
*/ |
|
103
|
|
|
public function setCsrfToken(string $csrfToken) |
|
104
|
|
|
{ |
|
105
|
|
|
if ($csrfToken === "") |
|
106
|
|
|
{ |
|
107
|
|
|
throw new Exception("A forms CSRF token cannot be empty"); |
|
108
|
|
|
} |
|
109
|
|
|
$this->csrfToken = $csrfToken; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Returns the CSRF token of this form |
|
115
|
|
|
* |
|
116
|
|
|
* @return string CSRF token for this form |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getCsrfToken() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->csrfToken; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Validates this forms assigned CSRF token with token stored in the TYPO3 session. |
|
126
|
|
|
* |
|
127
|
|
|
* @return bool True, is CSRF token is considered valid. False if the token is invalid or missing. |
|
128
|
|
|
*/ |
|
129
|
|
|
public function hasValidCsrfToken() |
|
130
|
|
|
{ |
|
131
|
|
|
$formProtection = FormProtectionFactory::get(); |
|
132
|
|
|
return $formProtection->validateToken($this->csrfToken, 'DocumentForm', 'construct', 'DocumentForm'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* |
|
137
|
|
|
* @return integer |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getDocumentUid() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->documentUid; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* |
|
146
|
|
|
* @param integer $documentUid |
|
147
|
|
|
*/ |
|
148
|
|
|
public function setDocumentUid($documentUid) |
|
149
|
|
|
{ |
|
150
|
|
|
$this->documentUid = $documentUid; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* |
|
155
|
|
|
* @return boolean |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getPrimaryFileMandatory() |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->primaryFileMandatory; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* |
|
164
|
|
|
* @param boolean $primaryFileMandatory |
|
165
|
|
|
*/ |
|
166
|
|
|
public function setPrimaryFileMandatory($primaryFileMandatory) |
|
167
|
|
|
{ |
|
168
|
|
|
$this->primaryFileMandatory = boolval($primaryFileMandatory); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* |
|
173
|
|
|
* @return string |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getFedoraPid() |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->fedoraPid; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* |
|
182
|
|
|
* @param string $fedoraPid |
|
183
|
|
|
*/ |
|
184
|
|
|
public function setFedoraPid($fedoraPid) |
|
185
|
|
|
{ |
|
186
|
|
|
$this->fedoraPid = $fedoraPid; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function getFiles() |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->files; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @return bool |
|
196
|
|
|
*/ |
|
197
|
|
|
public function hasFiles() |
|
198
|
|
|
{ |
|
199
|
|
|
return is_array($this->files) && !empty($this->files); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public function setFiles($files) |
|
203
|
|
|
{ |
|
204
|
|
|
$this->files = $files; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
public function addFile($file) |
|
208
|
|
|
{ |
|
209
|
|
|
$this->files[] = $file; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @return bool |
|
214
|
|
|
*/ |
|
215
|
|
|
public function getValid() |
|
216
|
|
|
{ |
|
217
|
|
|
return $this->valid; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @param bool $valid |
|
222
|
|
|
*/ |
|
223
|
|
|
public function setValid($valid) |
|
224
|
|
|
{ |
|
225
|
|
|
$this->valid = boolval($valid); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
public function getFileNames() |
|
229
|
|
|
{ |
|
230
|
|
|
$fileNames = array(); |
|
231
|
|
|
foreach ($this->getFiles() as $file) { |
|
232
|
|
|
$fileNames[] = $file->getTitle(); |
|
233
|
|
|
} |
|
234
|
|
|
return $fileNames; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Sets the process number |
|
239
|
|
|
* |
|
240
|
|
|
* @return string |
|
241
|
|
|
*/ |
|
242
|
|
|
public function getProcessNumber() |
|
243
|
|
|
{ |
|
244
|
|
|
return $this->processNumber; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Gets the process number |
|
249
|
|
|
* |
|
250
|
|
|
* @param string $processNumber |
|
251
|
|
|
*/ |
|
252
|
|
|
public function setProcessNumber($processNumber) |
|
253
|
|
|
{ |
|
254
|
|
|
$this->processNumber = $processNumber; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* Returns if a document is a temporary document. |
|
259
|
|
|
* |
|
260
|
|
|
* @return bool |
|
261
|
|
|
*/ |
|
262
|
|
|
public function isTemporary() |
|
263
|
|
|
{ |
|
264
|
|
|
return $this->temporary; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* Sets if a document is a temporary document or not. |
|
269
|
|
|
* @param bool $temporary |
|
270
|
|
|
*/ |
|
271
|
|
|
public function setTemporary($temporary) |
|
272
|
|
|
{ |
|
273
|
|
|
$this->temporary = boolval($temporary); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* @return string |
|
278
|
|
|
*/ |
|
279
|
|
|
public function getComment() |
|
280
|
|
|
{ |
|
281
|
|
|
return $this->comment; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* @param string $comment |
|
286
|
|
|
*/ |
|
287
|
|
|
public function setComment($comment) |
|
288
|
|
|
{ |
|
289
|
|
|
$this->comment = $comment; |
|
290
|
|
|
} |
|
291
|
|
|
} |
|
292
|
|
|
|