1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Broarm\EventTickets; |
4
|
|
|
|
5
|
|
|
use Object; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* CheckInValidator.php |
9
|
|
|
* |
10
|
|
|
* @author Bram de Leeuw |
11
|
|
|
* Date: 14/06/2017 |
12
|
|
|
*/ |
13
|
|
|
class CheckInValidator extends Object |
14
|
|
|
{ |
15
|
|
|
const MESSAGE_ERROR = 'MESSAGE_ERROR'; |
16
|
|
|
const MESSAGE_NO_CODE = 'MESSAGE_NO_CODE'; |
17
|
|
|
const MESSAGE_CODE_NOT_FOUND = 'MESSAGE_CODE_NOT_FOUND'; |
18
|
|
|
const MESSAGE_TICKET_CANCELLED = 'MESSAGE_TICKET_CANCELLED'; |
19
|
|
|
const MESSAGE_ALREADY_CHECKED_IN = 'MESSAGE_ALREADY_CHECKED_IN'; |
20
|
|
|
const MESSAGE_CHECK_OUT_SUCCESS = 'MESSAGE_CHECK_OUT_SUCCESS'; |
21
|
|
|
const MESSAGE_CHECK_IN_SUCCESS = 'MESSAGE_CHECK_IN_SUCCESS'; |
22
|
|
|
|
23
|
|
|
const MESSAGE_TYPE_GOOD = 'Good'; |
24
|
|
|
const MESSAGE_TYPE_WARNING = 'Warning'; |
25
|
|
|
const MESSAGE_TYPE_BAD = 'Bad'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Allow people to check in and out |
29
|
|
|
* |
30
|
|
|
* @config |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
private static $allow_checkout = false; |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Attendee |
37
|
|
|
*/ |
38
|
|
|
protected $attendee = null; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Validate the given ticket code |
42
|
|
|
* |
43
|
|
|
* @param null|string $ticketCode |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function validate($ticketCode = null) |
48
|
|
|
{ |
49
|
|
|
if (filter_var($ticketCode, FILTER_VALIDATE_URL)) { |
50
|
|
|
$asURL = explode('/', parse_url($ticketCode, PHP_URL_PATH)); |
51
|
|
|
$ticketCode = end($asURL); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Check if a code is given to the validator |
55
|
|
|
if (!isset($ticketCode)) { |
56
|
|
|
return array( |
57
|
|
|
'Code' => self::MESSAGE_NO_CODE, |
58
|
|
|
'Message' => self::message(self::MESSAGE_NO_CODE), |
59
|
|
|
'Type' => self::MESSAGE_TYPE_BAD |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Check if a ticket exists with the given ticket code |
64
|
|
|
if (!$this->attendee = Attendee::get()->find('TicketCode', $ticketCode)) { |
|
|
|
|
65
|
|
|
return array( |
66
|
|
|
'Code' => self::MESSAGE_CODE_NOT_FOUND, |
67
|
|
|
'Message' => self::message(self::MESSAGE_CODE_NOT_FOUND), |
68
|
|
|
'Type' => self::MESSAGE_TYPE_BAD |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// Check if the reservation is not canceled |
73
|
|
|
if (!(bool)$this->attendee->Event()->getGuestList()->find('ID', $this->attendee->ID)) { |
74
|
|
|
return array( |
75
|
|
|
'Code' => self::MESSAGE_TICKET_CANCELLED, |
76
|
|
|
'Message' => self::message(self::MESSAGE_TICKET_CANCELLED), |
77
|
|
|
'Type' => self::MESSAGE_TYPE_BAD |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// Check if the ticket is already checked in and not allowed to check out |
82
|
|
View Code Duplication |
elseif ((bool)$this->attendee->CheckedIn && !(bool)self::config()->get('allow_checkout')) { |
|
|
|
|
83
|
|
|
return array( |
84
|
|
|
'Code' => self::MESSAGE_ALREADY_CHECKED_IN, |
85
|
|
|
'Message' => self::message(self::MESSAGE_ALREADY_CHECKED_IN), |
86
|
|
|
'Type' => self::MESSAGE_TYPE_BAD |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// Successfully checked out |
91
|
|
View Code Duplication |
elseif ((bool)$this->attendee->CheckedIn && (bool)self::config()->get('allow_checkout')) { |
|
|
|
|
92
|
|
|
return array( |
93
|
|
|
'Code' => self::MESSAGE_CHECK_OUT_SUCCESS, |
94
|
|
|
'Message' => self::message(self::MESSAGE_CHECK_OUT_SUCCESS), |
95
|
|
|
'Type' => self::MESSAGE_TYPE_WARNING |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// Successfully checked in |
100
|
|
|
else return array( |
101
|
|
|
'Code' => self::MESSAGE_CHECK_IN_SUCCESS, |
102
|
|
|
'Message' => self::message(self::MESSAGE_CHECK_IN_SUCCESS), |
103
|
|
|
'Type' => self::MESSAGE_TYPE_GOOD |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get the attendee instance |
109
|
|
|
* |
110
|
|
|
* @return Attendee |
111
|
|
|
*/ |
112
|
|
|
public function getAttendee() |
113
|
|
|
{ |
114
|
|
|
return $this->attendee; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Translate the given type to a readable message |
119
|
|
|
* |
120
|
|
|
* @param $message string |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
private static function message($message) { |
125
|
|
|
return _t("CheckInValidator.$message", $message); |
126
|
|
|
} |
127
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.