1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* factory to provide File documents |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\FileBundle; |
7
|
|
|
|
8
|
|
|
use GravitonDyn\FileBundle\Document\FileMetadataEmbedded; |
9
|
|
|
use GravitonDyn\FileBundle\Document\FileMetadataActionEmbedded; |
10
|
|
|
use GravitonDyn\FileBundle\Document\FileLinksEmbedded; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
14
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
15
|
|
|
* @link http://swisscom.ch |
16
|
|
|
*/ |
17
|
|
|
class FileDocumentFactory |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Provides an instance of FileMetadataAction |
21
|
|
|
* |
22
|
|
|
* @return FileMetadataAction |
23
|
|
|
*/ |
24
|
|
|
public function createFileMetadataAction() |
25
|
|
|
{ |
26
|
|
|
return new FileMetadataActionEmbedded(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Provides an instance of FileMetadata |
31
|
|
|
* |
32
|
|
|
* @return FileMetadata |
33
|
|
|
*/ |
34
|
|
|
public function createFileMataData() |
35
|
|
|
{ |
36
|
|
|
return new FileMetadataEmbedded(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Provides an instance of FileMetadata |
41
|
|
|
* |
42
|
|
|
* @param string $id Identifier of the file. |
43
|
|
|
* @param int $size Size of the file. |
44
|
|
|
* @param string $filename Name of the file. |
45
|
|
|
* @param string $mimetype Mime-Type of the file. |
46
|
|
|
* @param array $actions List of actions to be executed. |
47
|
|
|
* @param string $additionalInfo Additional file information. |
48
|
|
|
* @param array $additionalProps Additional file properties for example for printing |
49
|
|
|
* |
50
|
|
|
* @return FileMetadata |
51
|
|
|
*/ |
52
|
|
|
public function initiateFileMataData( |
53
|
|
|
$id, |
54
|
|
|
$size, |
55
|
|
|
$filename, |
56
|
|
|
$mimetype, |
57
|
|
|
array $actions = [], |
58
|
|
|
$additionalInfo = '', |
59
|
|
|
$additionalProps = [] |
60
|
|
|
) { |
61
|
|
|
$now = new \DateTime(); |
62
|
|
|
$meta = $this->createFileMataData(); |
63
|
|
|
$meta->setId($id); |
64
|
|
|
$meta |
65
|
|
|
->setSize((int) $size) |
66
|
|
|
->setFilename($filename) |
67
|
|
|
->setMime($mimetype) |
68
|
|
|
->setCreatedate($now) |
69
|
|
|
->setModificationdate($now) |
70
|
|
|
->setAction($actions) |
71
|
|
|
->setAdditionalInformation($additionalInfo) |
72
|
|
|
->setAdditionalProperties($additionalProps); |
73
|
|
|
|
74
|
|
|
return $meta; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Provides an instance of FileLinks |
79
|
|
|
* |
80
|
|
|
* @return FileLinks |
81
|
|
|
*/ |
82
|
|
|
public function createFileLink() |
83
|
|
|
{ |
84
|
|
|
return new FileLinksEmbedded(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Sets up a FileLinks instance. |
89
|
|
|
* |
90
|
|
|
* @param string $type Type of the reference |
91
|
|
|
* @param string $reference Actual reference |
92
|
|
|
* |
93
|
|
|
* @return FileLinks |
94
|
|
|
*/ |
95
|
|
|
public function initializeFileLinks($type, $reference) |
96
|
|
|
{ |
97
|
|
|
$link = $this->createFileLink(); |
98
|
|
|
$link |
99
|
|
|
->setRef($reference) |
100
|
|
|
->setType($type); |
101
|
|
|
|
102
|
|
|
return $link; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|