|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CheckoutStepController.php |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bram de Leeuw |
|
6
|
|
|
* Date: 16/03/17 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Broarm\EventTickets; |
|
10
|
|
|
|
|
11
|
|
|
use Page_Controller; |
|
12
|
|
|
use SSViewer; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class CheckoutStepController |
|
16
|
|
|
* |
|
17
|
|
|
* @package Broarm\EventTickets |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class CheckoutStepController extends Page_Controller |
|
20
|
|
|
{ |
|
21
|
|
|
protected $step = null; |
|
22
|
|
|
|
|
23
|
|
|
public function init() |
|
24
|
|
|
{ |
|
25
|
|
|
// If the step is not a registered step exit |
|
26
|
|
|
if (!in_array($this->step, CheckoutSteps::getSteps())) { |
|
27
|
|
|
$this->redirect($this->Link('/')); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
// If no ReservationSession exists redirect back to the base event controller |
|
31
|
|
|
elseif (empty(ReservationSession::get())) { |
|
32
|
|
|
$this->redirect($this->Link('/')); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// If the reservation has been processed end the session and redirect |
|
36
|
|
|
elseif (ReservationSession::get()->Status === 'PAID' && $this->step != 'success') { |
|
37
|
|
|
ReservationSession::end(); |
|
38
|
|
|
$this->redirect($this->Link('/')); |
|
39
|
|
|
} else { |
|
40
|
|
|
parent::init(); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Force the controller action |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $action |
|
48
|
|
|
* |
|
49
|
|
|
* @return SSViewer |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getViewer($action) |
|
52
|
|
|
{ |
|
53
|
|
|
if ($action === 'index') { |
|
54
|
|
|
$action = $this->step; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return parent::getViewer($action); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get a relative link to the current controller |
|
62
|
|
|
* |
|
63
|
|
|
* @param null $action |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function Link($action = null) |
|
68
|
|
|
{ |
|
69
|
|
|
if (!$action) { |
|
70
|
|
|
$action = $this->step; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $this->dataRecord->RelativeLink($action); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get a link to the next step |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getNextStepLink() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->Link(CheckoutSteps::nextStep($this->step)); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get the checkout steps |
|
88
|
|
|
* |
|
89
|
|
|
* @return \ArrayList |
|
90
|
|
|
*/ |
|
91
|
|
|
public function CheckoutSteps() |
|
92
|
|
|
{ |
|
93
|
|
|
return CheckoutSteps::get($this); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|