|
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
|
1 |
|
public function createFileMetadataAction() |
|
25
|
|
|
{ |
|
26
|
1 |
|
return new FileMetadataActionEmbedded(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Provides an instance of FileMetadata |
|
31
|
|
|
* |
|
32
|
|
|
* @return FileMetadata |
|
33
|
|
|
*/ |
|
34
|
2 |
|
public function createFileMataData() |
|
35
|
|
|
{ |
|
36
|
2 |
|
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
|
1 |
|
public function initiateFileMataData( |
|
53
|
|
|
$id, |
|
54
|
|
|
$size, |
|
55
|
|
|
$filename, |
|
56
|
|
|
$mimetype, |
|
57
|
|
|
array $actions = [], |
|
58
|
|
|
$additionalInfo = '', |
|
59
|
|
|
$additionalProps = [] |
|
60
|
|
|
) { |
|
61
|
1 |
|
$now = new \DateTime(); |
|
62
|
1 |
|
$meta = $this->createFileMataData(); |
|
63
|
1 |
|
$meta->setId($id); |
|
64
|
|
|
$meta |
|
65
|
1 |
|
->setSize((int) $size) |
|
66
|
1 |
|
->setFilename($filename) |
|
67
|
1 |
|
->setMime($mimetype) |
|
68
|
1 |
|
->setCreatedate($now) |
|
69
|
1 |
|
->setModificationdate($now) |
|
70
|
1 |
|
->setAction($actions) |
|
71
|
1 |
|
->setAdditionalInformation($additionalInfo) |
|
72
|
1 |
|
->setAdditionalProperties($additionalProps); |
|
73
|
|
|
|
|
74
|
1 |
|
return $meta; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Provides an instance of FileLinks |
|
79
|
|
|
* |
|
80
|
|
|
* @return FileLinks |
|
81
|
|
|
*/ |
|
82
|
2 |
|
public function createFileLink() |
|
83
|
|
|
{ |
|
84
|
2 |
|
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
|
1 |
|
public function initializeFileLinks($type, $reference) |
|
96
|
|
|
{ |
|
97
|
1 |
|
$link = $this->createFileLink(); |
|
98
|
|
|
$link |
|
99
|
1 |
|
->setRef($reference) |
|
100
|
1 |
|
->setType($type); |
|
101
|
|
|
|
|
102
|
1 |
|
return $link; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|