Passed
Pull Request — master (#207)
by
unknown
12:49
created

DocumentForm::setFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
    private $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
    public function setFiles($files)
195
    {
196
        $this->files = $files;
197
    }
198
199
    public function addFile($file)
200
    {
201
        $this->files[] = $file;
202
    }
203
204
    /**
205
     * @return bool
206
     */
207
    public function getValid()
208
    {
209
        return $this->valid;
210
    }
211
212
    /**
213
     * @param bool $valid
214
     */
215
    public function setValid($valid)
216
    {
217
        $this->valid = boolval($valid);
218
    }
219
220
    public function getFileNames()
221
    {
222
        $fileNames = array();
223
        foreach ($this->getFiles() as $file) {
224
            $fileNames[] = $file->getTitle();
225
        }
226
        return $fileNames;
227
    }
228
229
    /**
230
     * Sets the process number
231
     *
232
     * @return string
233
     */
234
    public function getProcessNumber()
235
    {
236
        return $this->processNumber;
237
    }
238
239
    /**
240
     * Gets the process number
241
     *
242
     * @param string $processNumber
243
     */
244
    public function setProcessNumber($processNumber)
245
    {
246
        $this->processNumber = $processNumber;
247
    }
248
249
    /**
250
     * Returns if a document is a temporary document.
251
     *
252
     * @return bool
253
     */
254
    public function isTemporary()
255
    {
256
        return $this->temporary;
257
    }
258
259
    /**
260
     * Sets if a document is a temporary document or not.
261
     * @param bool $temporary
262
     */
263
    public function setTemporary($temporary)
264
    {
265
        $this->temporary = boolval($temporary);
266
    }
267
268
    /**
269
     * @return string
270
     */
271
    public function getComment()
272
    {
273
        return $this->comment;
274
    }
275
276
    /**
277
     * @param string $comment
278
     */
279
    public function setComment($comment)
280
    {
281
        $this->comment = $comment;
282
    }
283
}
284