1
|
|
|
<?php |
2
|
|
|
namespace EWW\Dpf\Domain\Model; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* File |
19
|
|
|
*/ |
20
|
|
|
class File extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* title |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $title = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* label |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $label = ''; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* download |
39
|
|
|
* |
40
|
|
|
* @var boolean |
41
|
|
|
*/ |
42
|
|
|
protected $download; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* archive |
46
|
|
|
* |
47
|
|
|
* @var boolean |
48
|
|
|
*/ |
49
|
|
|
protected $archive; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* fileGroupDeleted |
53
|
|
|
* |
54
|
|
|
* @var boolean |
55
|
|
|
*/ |
56
|
|
|
protected $fileGroupDeleted; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* contentType |
60
|
|
|
* |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
protected $contentType = ''; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* link |
67
|
|
|
* |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
protected $link = ''; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* status |
74
|
|
|
* |
75
|
|
|
* @var string |
76
|
|
|
*/ |
77
|
|
|
protected $status; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* primaryFile |
81
|
|
|
* |
82
|
|
|
* @var boolean |
83
|
|
|
*/ |
84
|
|
|
protected $primaryFile; |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* fileIdentifier |
89
|
|
|
* |
90
|
|
|
* @var string |
91
|
|
|
*/ |
92
|
|
|
protected $fileIdentifier = ''; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* datastreamIdentifier |
96
|
|
|
* |
97
|
|
|
* @var string |
98
|
|
|
*/ |
99
|
|
|
protected $datastreamIdentifier; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* document |
103
|
|
|
* |
104
|
|
|
* @var \EWW\Dpf\Domain\Model\Document |
105
|
|
|
*/ |
106
|
|
|
protected $document = null; |
107
|
|
|
|
108
|
|
|
const STATUS_REMOTE = "remote"; |
109
|
|
|
const STATUS_DELETED = "deleted"; |
110
|
|
|
const STATUS_CHANGED = "changed"; |
111
|
|
|
const STATUS_ADDED = "added"; |
112
|
|
|
|
113
|
|
|
const PRIMARY_DATASTREAM_IDENTIFIER = 'ATT-0'; |
114
|
|
|
const DATASTREAM_IDENTIFIER_PREFIX = 'ATT-'; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Returns the title |
118
|
|
|
* |
119
|
|
|
* @return string $title |
120
|
|
|
*/ |
121
|
|
|
public function getTitle() |
122
|
|
|
{ |
123
|
|
|
return $this->title; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Sets the title |
128
|
|
|
* |
129
|
|
|
* @param string $title |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function setTitle($title) |
133
|
|
|
{ |
134
|
|
|
$this->title = $title; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns the label |
139
|
|
|
* |
140
|
|
|
* @return string $label |
141
|
|
|
*/ |
142
|
|
|
public function getLabel() |
143
|
|
|
{ |
144
|
|
|
return $this->label; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Sets the label |
149
|
|
|
* |
150
|
|
|
* @param string $label |
151
|
|
|
* @return void |
152
|
|
|
*/ |
153
|
|
|
public function setLabel($label) |
154
|
|
|
{ |
155
|
|
|
$this->label = $label; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Returns the download |
160
|
|
|
* |
161
|
|
|
* @return boolean $download |
162
|
|
|
*/ |
163
|
|
|
public function getDownload() |
164
|
|
|
{ |
165
|
|
|
return $this->download; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Sets the download |
170
|
|
|
* |
171
|
|
|
* @param boolean $download |
172
|
|
|
* @return void |
173
|
|
|
*/ |
174
|
|
|
public function setDownload($download) |
175
|
|
|
{ |
176
|
|
|
$this->download = boolval($download); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Returns the arcive |
181
|
|
|
* |
182
|
|
|
* @return boolean $archive |
183
|
|
|
*/ |
184
|
|
|
public function getArchive() |
185
|
|
|
{ |
186
|
|
|
return $this->archive; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Sets the archive |
191
|
|
|
* |
192
|
|
|
* @param boolean $archive |
193
|
|
|
* @return void |
194
|
|
|
*/ |
195
|
|
|
public function setArchive($archive) |
196
|
|
|
{ |
197
|
|
|
$this->archive = boolval($archive); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Returns the fileGroupDeleted |
202
|
|
|
* |
203
|
|
|
* @return boolean $fileGroupDeleted |
204
|
|
|
*/ |
205
|
|
|
public function isFileGroupDeleted() |
206
|
|
|
{ |
207
|
|
|
return $this->fileGroupDeleted; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Sets the fileGroupDeleted |
212
|
|
|
* |
213
|
|
|
* @return boolean $fileGroupDeleted |
214
|
|
|
*/ |
215
|
|
|
public function setFileGroupDeleted($fileGroupDeleted) |
216
|
|
|
{ |
217
|
|
|
$this->fileGroupDeleted = boolval($fileGroupDeleted); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Returns the contentType |
222
|
|
|
* |
223
|
|
|
* @return string $contentType |
224
|
|
|
*/ |
225
|
|
|
public function getContentType() |
226
|
|
|
{ |
227
|
|
|
return $this->contentType; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Sets the contentType |
232
|
|
|
* |
233
|
|
|
* @param string $contentType |
234
|
|
|
* @return void |
235
|
|
|
*/ |
236
|
|
|
public function setContentType($contentType) |
237
|
|
|
{ |
238
|
|
|
$this->contentType = $contentType; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Returns the link |
243
|
|
|
* |
244
|
|
|
* @return string $link |
245
|
|
|
*/ |
246
|
|
|
public function getLink() |
247
|
|
|
{ |
248
|
|
|
return $this->link; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Sets the link |
253
|
|
|
* |
254
|
|
|
* @param string $link |
255
|
|
|
* @return void |
256
|
|
|
*/ |
257
|
|
|
public function setLink($link) |
258
|
|
|
{ |
259
|
|
|
$this->link = $link; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Returns the status |
264
|
|
|
* |
265
|
|
|
* @return string $status |
266
|
|
|
*/ |
267
|
|
|
public function getStatus() |
268
|
|
|
{ |
269
|
|
|
return $this->status; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Sets the status |
274
|
|
|
* |
275
|
|
|
* @param string $status |
276
|
|
|
* @return void |
277
|
|
|
*/ |
278
|
|
|
public function setStatus($status) |
279
|
|
|
{ |
280
|
|
|
$this->status = $status; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Returns the document |
285
|
|
|
* |
286
|
|
|
* @return \EWW\Dpf\Domain\Model\Document $document |
287
|
|
|
*/ |
288
|
|
|
public function getDocument() |
289
|
|
|
{ |
290
|
|
|
return $this->document; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Sets the document |
295
|
|
|
* |
296
|
|
|
* @param \EWW\Dpf\Domain\Model\Document $document |
297
|
|
|
* @return void |
298
|
|
|
*/ |
299
|
|
|
public function setDocument(\EWW\Dpf\Domain\Model\Document $document) |
300
|
|
|
{ |
301
|
|
|
$this->document = $document; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Returns the primaryFile |
306
|
|
|
* |
307
|
|
|
* @return boolean $primaryFile |
308
|
|
|
*/ |
309
|
|
|
public function getPrimaryFile() |
310
|
|
|
{ |
311
|
|
|
return $this->primaryFile; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Sets the primaryFile |
316
|
|
|
* |
317
|
|
|
* @param boolean $primaryFile |
318
|
|
|
* @return void |
319
|
|
|
*/ |
320
|
|
|
public function setPrimaryFile($primaryFile) |
321
|
|
|
{ |
322
|
|
|
$this->primaryFile = boolval($primaryFile); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* Returns the boolean state of primaryFile |
327
|
|
|
* |
328
|
|
|
* @return boolean |
329
|
|
|
*/ |
330
|
|
|
public function isPrimaryFile() |
331
|
|
|
{ |
332
|
|
|
return $this->primaryFile; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Returns the datastreamIdentifier |
337
|
|
|
* |
338
|
|
|
* @return string $datastreamIdentifier |
339
|
|
|
*/ |
340
|
|
|
public function getDatastreamIdentifier() |
341
|
|
|
{ |
342
|
|
|
return $this->datastreamIdentifier; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Sets the datastreamIdentifier |
347
|
|
|
* |
348
|
|
|
* @param string $datastreamIdentifier |
349
|
|
|
* @return void |
350
|
|
|
*/ |
351
|
|
|
public function setDatastreamIdentifier($datastreamIdentifier) |
352
|
|
|
{ |
353
|
|
|
$this->datastreamIdentifier = $datastreamIdentifier; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Copies the data of the given file object into the current file object. |
358
|
|
|
* |
359
|
|
|
* @param File $fileToCopy |
360
|
|
|
* @return $this |
361
|
|
|
* @throws \TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException |
362
|
|
|
*/ |
363
|
|
|
public function copy(File $fileToCopy) { |
364
|
|
|
$availableProperties = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettablePropertyNames($fileToCopy); |
365
|
|
|
$newFile = $this; |
366
|
|
|
|
367
|
|
|
foreach ($availableProperties as $propertyName) { |
368
|
|
|
if (\TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($newFile, $propertyName) |
369
|
|
|
&& !in_array($propertyName, array('uid','pid'))) { |
370
|
|
|
|
371
|
|
|
$propertyValue = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($fileToCopy, $propertyName); |
372
|
|
|
\TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($newFile, $propertyName, $propertyValue); |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
return $this; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* Gets the full url of the file. |
381
|
|
|
* |
382
|
|
|
* @return string |
383
|
|
|
*/ |
384
|
|
|
public function getUrl() |
385
|
|
|
{ |
386
|
|
|
$url = $this->getLink(); |
387
|
|
|
|
388
|
|
|
// FIXME: Checking for "datastreams" in the URL is Fedora 3 specific, for Fedora 4 we need a better solution. |
389
|
|
|
if (strpos(strtolower($url), "datastreams") === false) { |
390
|
|
|
// File is a locally uploaded file, therefor we need to |
391
|
|
|
// determine the path |
392
|
|
|
$uploadFileUrl = new \EWW\Dpf\Helper\UploadFileUrl; |
393
|
|
|
$fileName = pathInfo($url, PATHINFO_BASENAME); |
394
|
|
|
$url = $uploadFileUrl->getUploadUrl() . "/" . $fileName; |
|
|
|
|
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
return $url; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* @return string |
402
|
|
|
*/ |
403
|
|
|
public function getFileIdentifier(): string |
404
|
|
|
{ |
405
|
|
|
return $this->fileIdentifier; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* @param string $fileIdentifier |
410
|
|
|
*/ |
411
|
|
|
public function setFileIdentifier(string $fileIdentifier): void |
412
|
|
|
{ |
413
|
|
|
$this->fileIdentifier = $fileIdentifier; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* @return bool |
418
|
|
|
*/ |
419
|
|
|
public function isNewFileHref(): bool |
420
|
|
|
{ |
421
|
|
|
return $this->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_ADDED || |
422
|
|
|
$this->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_CHANGED; |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* @return string |
427
|
|
|
*/ |
428
|
|
|
public function isDeleted(): string |
429
|
|
|
{ |
430
|
|
|
return $this->getStatus() == \EWW\Dpf\Domain\Model\File::STATUS_DELETED; |
|
|
|
|
431
|
|
|
} |
432
|
|
|
} |
433
|
|
|
|