1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CheckInForm.php |
4
|
|
|
* |
5
|
|
|
* @author Bram de Leeuw |
6
|
|
|
* Date: 07/04/17 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Broarm\EventTickets; |
10
|
|
|
|
11
|
|
|
use FieldList; |
12
|
|
|
use Form; |
13
|
|
|
use FormAction; |
14
|
|
|
use RequiredFields; |
15
|
|
|
use TextField; |
16
|
|
|
|
17
|
|
|
class CheckInForm extends Form |
18
|
|
|
{ |
19
|
|
|
public function __construct($controller, $name = 'CheckInForm') |
20
|
|
|
{ |
21
|
|
|
$fields = FieldList::create( |
22
|
|
|
TextField::create('TicketCode', _t('CheckInForm.TICKET_CODE', 'Ticket code')) |
23
|
|
|
->setAttribute('autofocus', true) |
|
|
|
|
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
$actions = FieldList::create( |
27
|
|
|
FormAction::create('doCheckIn', _t('CheckInForm.CheckIn', 'Check in')) |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$required = new RequiredFields(array('TicketCode')); |
31
|
|
|
parent::__construct($controller, $name, $fields, $actions, $required); |
32
|
|
|
$this->extend('onAfterConstruct'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Do the check in, if all checks pass return a success |
37
|
|
|
* |
38
|
|
|
* @param $data |
39
|
|
|
* @param CheckInForm $form |
40
|
|
|
* |
41
|
|
|
* @return \SS_HTTPResponse |
42
|
|
|
*/ |
43
|
|
|
public function doCheckIn($data, CheckInForm $form) |
44
|
|
|
{ |
45
|
|
|
/** @var CheckInController $controller */ |
46
|
|
|
$controller = $form->getController(); |
47
|
|
|
$validator = CheckInValidator::create(); |
48
|
|
|
$result = $validator->validate($data['TicketCode']); |
49
|
|
|
switch ($result['Code']) { |
50
|
|
|
case CheckInValidator::MESSAGE_CHECK_OUT_SUCCESS: |
51
|
|
|
$validator->getAttendee()->checkOut(); |
52
|
|
|
break; |
53
|
|
|
case CheckInValidator::MESSAGE_CHECK_IN_SUCCESS: |
54
|
|
|
$validator->getAttendee()->checkIn(); |
55
|
|
|
break; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$form->sessionMessage($result['Message'], strtolower($result['Type']), false); |
59
|
|
|
$this->extend('onAfterCheckIn', $response, $form, $result); |
60
|
|
|
return $response ? $response : $controller->redirect($controller->Link()); |
61
|
|
|
} |
62
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: