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\Middleware\Item\Step\Service; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Configuration\Form\Step\Step\Step; |
17
|
|
|
|
18
|
|
|
class FormStepPersistence |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $objectHash; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $validatedSteps = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $stepsFormValues = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $configurationHash |
37
|
|
|
*/ |
38
|
|
|
public function __construct($configurationHash) |
39
|
|
|
{ |
40
|
|
|
$this->objectHash = $configurationHash; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Step $step |
45
|
|
|
*/ |
46
|
|
|
public function markStepAsValidated(Step $step) |
47
|
|
|
{ |
48
|
|
|
$this->validatedSteps[] = $step->getName(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param Step $step |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
|
|
public function stepWasValidated(Step $step) |
56
|
|
|
{ |
57
|
|
|
return in_array($step->getName(), $this->validatedSteps); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param Step $step |
62
|
|
|
* @param array $formValues |
63
|
|
|
*/ |
64
|
|
|
public function addStepFormValues(Step $step, array $formValues) |
65
|
|
|
{ |
66
|
|
|
$this->stepsFormValues[$step->getName()] = $formValues; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param Step $step |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
public function hasStepFormValues(Step $step) |
74
|
|
|
{ |
75
|
|
|
return true === array_key_exists($step->getName(), $this->stepsFormValues); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param Step $step |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
public function getStepFormValues(Step $step) |
83
|
|
|
{ |
84
|
|
|
return $this->stepsFormValues[$step->getName()]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
|
|
public function hasData() |
91
|
|
|
{ |
92
|
|
|
return false === empty($this->validatedSteps) |
93
|
|
|
&& false === empty($this->stepsFormValues); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getObjectHash() |
100
|
|
|
{ |
101
|
|
|
return $this->objectHash; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string $hash |
106
|
|
|
*/ |
107
|
|
|
public function refreshObjectHash($hash) |
108
|
|
|
{ |
109
|
|
|
$this->objectHash = $hash; |
110
|
|
|
$this->validatedSteps = []; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|