1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2017 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 FormZ project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\Formz\Domain\Model; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Core\Core; |
17
|
|
|
use Romm\Formz\Domain\Model\DataObject\FormMetadataObject; |
18
|
|
|
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Contains metadata for a form. |
22
|
|
|
* |
23
|
|
|
* It can be used to store arbitrary data that will be persisted from a request |
24
|
|
|
* to another (if the form is bound to at least one persistence service). |
25
|
|
|
* |
26
|
|
|
* The form is identified with a unique hash, which is used to retrieve the |
27
|
|
|
* metadata instance |
28
|
|
|
* . |
29
|
|
|
*/ |
30
|
|
|
class FormMetadata extends AbstractEntity |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $hash; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $className; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $identifier; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var \Romm\Formz\Domain\Model\DataObject\FormMetadataObject |
49
|
|
|
*/ |
50
|
|
|
protected $data; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $hash |
54
|
|
|
* @param string $className |
55
|
|
|
* @param string $identifier |
56
|
|
|
* @param FormMetadataObject $data |
57
|
|
|
*/ |
58
|
|
|
public function __construct($hash, $className, $identifier, FormMetadataObject $data) |
59
|
|
|
{ |
60
|
|
|
$this->hash = $hash; |
61
|
|
|
$this->className = $className; |
62
|
|
|
$this->identifier = $identifier; |
63
|
|
|
$this->data = $data; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getHash() |
70
|
|
|
{ |
71
|
|
|
return $this->hash; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getIdentifier() |
78
|
|
|
{ |
79
|
|
|
return $this->identifier; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $identifier |
84
|
|
|
*/ |
85
|
|
|
public function setIdentifier($identifier) |
86
|
|
|
{ |
87
|
|
|
$this->identifier = $identifier; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function getClassName() |
94
|
|
|
{ |
95
|
|
|
return $this->className; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
|
|
public function hasIdentifier() |
102
|
|
|
{ |
103
|
|
|
return null !== $this->identifier; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return FormMetadataObject |
108
|
|
|
*/ |
109
|
|
|
public function getData() |
110
|
|
|
{ |
111
|
|
|
return $this->data; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Commits the last changes of this instance in database. |
116
|
|
|
*/ |
117
|
|
|
public function commit() |
118
|
|
|
{ |
119
|
|
|
$persistenceManager = Core::get()->getPersistenceManager(); |
120
|
|
|
|
121
|
|
|
if (null === $this->getUid()) { |
122
|
|
|
$persistenceManager->add($this); |
123
|
|
|
} else { |
124
|
|
|
$persistenceManager->update($this); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$persistenceManager->persistAll(); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|