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