|
1
|
|
|
<?php |
|
2
|
|
|
namespace EventEspresso\core\services\progress_steps; |
|
3
|
|
|
|
|
4
|
|
|
use EE_Request; |
|
5
|
|
|
use EventEspresso\Core\Exceptions\InvalidClassException; |
|
6
|
|
|
use EventEspresso\Core\Exceptions\InvalidDataTypeException; |
|
7
|
|
|
use EventEspresso\Core\Exceptions\InvalidIdentifierException; |
|
8
|
|
|
use EventEspresso\Core\Exceptions\InvalidInterfaceException; |
|
9
|
|
|
use EventEspresso\core\services\collections\Collection; |
|
10
|
|
|
use EventEspresso\core\services\collections\CollectionInterface; |
|
11
|
|
|
use EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface; |
|
12
|
|
|
|
|
13
|
|
|
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
14
|
|
|
exit( 'No direct script access allowed' ); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class ProgressStepManager |
|
21
|
|
|
* Description |
|
22
|
|
|
* |
|
23
|
|
|
* @package Event Espresso |
|
24
|
|
|
* @subpackage core |
|
25
|
|
|
* @author Brent Christensen |
|
26
|
|
|
* @since $VID:$ |
|
27
|
|
|
*/ |
|
28
|
|
|
class ProgressStepManager { |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var ProgressStepInterface[] $collection |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $collection; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string $default_step |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $default_step; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var ProgressStepsDisplayInterface $display_strategy |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $display_strategy; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var EE_Request $request |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $request; |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* ProgressStepManager constructor |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $display_strategy_name |
|
56
|
|
|
* @param string $default_step |
|
57
|
|
|
* @param CollectionInterface $collection |
|
58
|
|
|
* @param \EE_Request $request |
|
59
|
|
|
* @throws InvalidClassException |
|
60
|
|
|
* @throws InvalidDataTypeException |
|
61
|
|
|
* @throws InvalidInterfaceException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct( |
|
64
|
|
|
$display_strategy_name = 'number_bubbles', |
|
65
|
|
|
$default_step = '', |
|
66
|
|
|
CollectionInterface $collection = null, |
|
67
|
|
|
EE_Request $request = null |
|
68
|
|
|
) { |
|
69
|
|
|
$this->setDisplayStrategy( $display_strategy_name ); |
|
70
|
|
|
$this->setDefaultStep( $default_step ); |
|
71
|
|
|
if ( ! $collection instanceof CollectionInterface ) { |
|
72
|
|
|
$collection = new Collection( '\EventEspresso\core\services\progress_steps\ProgressStepInterface' ); |
|
73
|
|
|
} |
|
74
|
|
|
$this->collection = $collection; |
|
|
|
|
|
|
75
|
|
|
if ( ! $request instanceof EE_Request ) { |
|
76
|
|
|
$request = \EE_Registry::instance()->load_core( 'Request' ); |
|
77
|
|
|
} |
|
78
|
|
|
$this->request = $request; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param string $display_strategy_name |
|
85
|
|
|
* @throws InvalidDataTypeException |
|
86
|
|
|
* @throws InvalidClassException |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function setDisplayStrategy( $display_strategy_name = 'number_bubbles' ) { |
|
89
|
|
|
if ( ! is_string( $display_strategy_name ) ) { |
|
90
|
|
|
throw new InvalidDataTypeException( '$display_strategy_name', $display_strategy_name, 'string' ); |
|
91
|
|
|
} |
|
92
|
|
|
// build up FQCN from incoming display strategy folder name |
|
93
|
|
|
$display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\'; |
|
94
|
|
|
$display_strategy_class .= $display_strategy_name . '\\'; |
|
95
|
|
|
$display_strategy_class .= str_replace( ' ', '', ucwords( str_replace( '_', ' ', $display_strategy_name ) ) ); |
|
96
|
|
|
$display_strategy_class .= 'ProgressStepsDisplay'; |
|
97
|
|
|
$display_strategy_class = apply_filters( |
|
98
|
|
|
'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class', |
|
99
|
|
|
$display_strategy_class |
|
100
|
|
|
); |
|
101
|
|
|
if ( ! class_exists( $display_strategy_class ) ) { |
|
102
|
|
|
throw new InvalidClassException( $display_strategy_class ); |
|
103
|
|
|
} |
|
104
|
|
|
$display_strategy = new $display_strategy_class(); |
|
105
|
|
|
if ( ! $display_strategy instanceof ProgressStepsDisplayInterface ) { |
|
106
|
|
|
throw new InvalidClassException( |
|
107
|
|
|
$display_strategy_class, |
|
108
|
|
|
sprintf( |
|
109
|
|
|
__( 'The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso' ), |
|
110
|
|
|
$display_strategy_class, |
|
111
|
|
|
'\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface' |
|
112
|
|
|
) |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
$this->display_strategy = $display_strategy; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param string $default_step |
|
122
|
|
|
* @throws InvalidDataTypeException |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setDefaultStep( $default_step ) { |
|
125
|
|
|
if ( ! is_string( $default_step ) ) { |
|
126
|
|
|
throw new InvalidDataTypeException( '$default_step', $default_step, 'string' ); |
|
127
|
|
|
} |
|
128
|
|
|
$this->default_step = $default_step; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param string $step |
|
135
|
|
|
* @throws \EventEspresso\Core\Exceptions\InvalidIdentifierException |
|
136
|
|
|
*/ |
|
137
|
|
|
public function setCurrentStep( $step = '' ) { |
|
138
|
|
|
// use incoming value if it's set, otherwise use request param if it's set, otherwise use default |
|
139
|
|
|
$step = ! empty( $step ) |
|
140
|
|
|
? $step |
|
141
|
|
|
: $this->request->get( 'ee-step', $this->default_step ); |
|
142
|
|
|
// grab the step previously known as current, in case we need to revert |
|
143
|
|
|
$current_current_step = $this->collection->current(); |
|
|
|
|
|
|
144
|
|
|
// verify that requested step exists |
|
145
|
|
|
if ( ! $this->collection->has( $step ) ) { |
|
|
|
|
|
|
146
|
|
|
throw new InvalidIdentifierException( $step, $this->default_step ); |
|
147
|
|
|
} |
|
148
|
|
|
if ( $this->collection->setCurrent( $step ) ) { |
|
|
|
|
|
|
149
|
|
|
// if the old boss is the same as the new boss, then nothing changes |
|
150
|
|
|
if ( $this->collection->current() !== $current_current_step ) { |
|
|
|
|
|
|
151
|
|
|
$current_current_step->setIsCurrent( false ); |
|
152
|
|
|
} |
|
153
|
|
|
$this->collection->current()->setIsCurrent(); |
|
|
|
|
|
|
154
|
|
|
} else { |
|
155
|
|
|
$this->collection->setCurrent( $current_current_step->id() ); |
|
|
|
|
|
|
156
|
|
|
$current_current_step->setIsCurrent( true ); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return ProgressStepInterface |
|
164
|
|
|
*/ |
|
165
|
|
|
public function currentStep() { |
|
166
|
|
|
return $this->collection->current(); |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return ProgressStepInterface |
|
173
|
|
|
*/ |
|
174
|
|
|
public function nextStep() { |
|
175
|
|
|
return $this->collection->next(); |
|
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @return void |
|
182
|
|
|
*/ |
|
183
|
|
|
public function enqueueStylesAndScripts() { |
|
184
|
|
|
$this->display_strategy->enqueueStylesAndScripts(); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* echos out HTML |
|
191
|
|
|
* |
|
192
|
|
|
* @return void |
|
193
|
|
|
*/ |
|
194
|
|
|
public function displaySteps() { |
|
195
|
|
|
echo \EEH_Template::display_template( |
|
196
|
|
|
$this->display_strategy->getTemplate(), |
|
197
|
|
|
array( 'progress_steps' => $this->collection ), |
|
198
|
|
|
true |
|
199
|
|
|
); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
// End of file ProgressStepManager.php |
|
205
|
|
|
// Location: core/services/progress_steps/ProgressStepManager.php |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..