|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CheckoutSteps.php |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bram de Leeuw |
|
6
|
|
|
* Date: 29/03/17 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Broarm\EventTickets; |
|
10
|
|
|
|
|
11
|
|
|
use ArrayList; |
|
12
|
|
|
use Controller; |
|
13
|
|
|
use SS_Object; |
|
14
|
|
|
use ViewableData; |
|
15
|
|
|
|
|
16
|
|
|
class CheckoutSteps extends SS_Object |
|
17
|
|
|
{ |
|
18
|
|
|
private static $checkout_steps = array( |
|
19
|
|
|
'register', |
|
20
|
|
|
'summary', |
|
21
|
|
|
'success' |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Return the first step |
|
26
|
|
|
* |
|
27
|
|
|
* @return string |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function start() |
|
30
|
|
|
{ |
|
31
|
|
|
$steps = self::getSteps(); |
|
32
|
|
|
return $steps[0]; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Return the next step |
|
37
|
|
|
* |
|
38
|
|
|
* @param $step |
|
39
|
|
|
* |
|
40
|
|
|
* @return null |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function nextStep($step) |
|
43
|
|
|
{ |
|
44
|
|
|
$steps = self::getSteps(); |
|
45
|
|
|
$key = self::getStepIndex($step) + 1; |
|
46
|
|
|
if (key_exists($key, $steps)) { |
|
47
|
|
|
return $steps[$key]; |
|
48
|
|
|
} else { |
|
49
|
|
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Return an unique array of steps |
|
55
|
|
|
* |
|
56
|
|
|
* @return array |
|
57
|
|
|
*/ |
|
58
|
|
|
public static function getSteps() |
|
59
|
|
|
{ |
|
60
|
|
|
return array_unique(self::config()->get('checkout_steps')); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the formatted steps |
|
65
|
|
|
* |
|
66
|
|
|
* @param CheckoutStepController $controller |
|
67
|
|
|
* |
|
68
|
|
|
* @return ArrayList |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function get(CheckoutStepController $controller) |
|
71
|
|
|
{ |
|
72
|
|
|
$list = new ArrayList(); |
|
73
|
|
|
$steps = self::getSteps(); |
|
74
|
|
|
foreach ($steps as $step) { |
|
75
|
|
|
$data = new ViewableData(); |
|
76
|
|
|
$data->Link = $controller->Link($step); |
|
77
|
|
|
$data->Title = _t("CheckoutSteps.$step", ucfirst($step)); |
|
78
|
|
|
$data->InPast = self::inPast($step, $controller); |
|
79
|
|
|
$data->InFuture = self::inFuture($step, $controller); |
|
80
|
|
|
$data->Current = self::current($step, $controller); |
|
81
|
|
|
$list->add($data); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $list; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get the index of the given step |
|
89
|
|
|
* |
|
90
|
|
|
* @param $step |
|
91
|
|
|
* |
|
92
|
|
|
* @return mixed |
|
93
|
|
|
*/ |
|
94
|
|
|
private static function getStepIndex($step) { |
|
95
|
|
|
$steps = self::getSteps(); |
|
96
|
|
|
return array_search($step, array_unique($steps)); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Check if the step is in the past |
|
101
|
|
|
* |
|
102
|
|
|
* @param $step |
|
103
|
|
|
* @param CheckoutStepController $controller |
|
104
|
|
|
* |
|
105
|
|
|
* @return bool |
|
106
|
|
|
*/ |
|
107
|
|
|
private static function inPast($step, CheckoutStepController $controller) |
|
108
|
|
|
{ |
|
109
|
|
|
$currentStep = $controller->getURLParams()['Action']; |
|
110
|
|
|
return self::getStepIndex($step) < self::getStepIndex($currentStep); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Check if the step is in the future |
|
115
|
|
|
* |
|
116
|
|
|
* @param $step |
|
117
|
|
|
* @param CheckoutStepController $controller |
|
118
|
|
|
* |
|
119
|
|
|
* @return bool |
|
120
|
|
|
*/ |
|
121
|
|
|
private static function inFuture($step, CheckoutStepController $controller) |
|
122
|
|
|
{ |
|
123
|
|
|
$currentStep = $controller->getURLParams()['Action']; |
|
124
|
|
|
return self::getStepIndex($step) > self::getStepIndex($currentStep); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Check at the current step |
|
129
|
|
|
* |
|
130
|
|
|
* @param $step |
|
131
|
|
|
* @param CheckoutStepController $controller |
|
132
|
|
|
* |
|
133
|
|
|
* @return bool |
|
134
|
|
|
*/ |
|
135
|
|
|
private static function current($step, CheckoutStepController $controller) |
|
136
|
|
|
{ |
|
137
|
|
|
$currentStep = $controller->getURLParams()['Action']; |
|
138
|
|
|
return self::getStepIndex($step) === self::getStepIndex($currentStep); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|