Completed
Push — master ( 8c9351...52e005 )
by Bram
04:57
created

CheckInController::getCheckedInCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * CheckInController.php
4
 *
5
 * @author Bram de Leeuw
6
 * Date: 07/04/17
7
 */
8
9
namespace Broarm\EventTickets;
10
11
use Page_Controller;
12
use Permission;
13
use PermissionProvider;
14
use Security;
15
use SSViewer;
16
17
/**
18
 * Class CheckInController
19
 *
20
 * @mixin TicketExtension
21
 *
22
 * @package Broarm\EventTickets
23
 */
24
class CheckInController extends Page_Controller implements PermissionProvider
25
{
26
    const NO_CODE = -3;
27
    const NO_ATTENDEES = -2;
28
    const CODE_NOT_FOUND = -1;
29
    const ALREADY_CHECKED_IN = 0;
30
    const SUCCESS = 1;
31
32
    private static $allowed_actions = array(
0 ignored issues
show
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
33
        'CheckInForm'
34
    );
35
36
    public function init()
37
    {
38
        // Check if the current user has permissions to check in guest
39
        if (!Permission::check('HANDLE_CHECK_IN')) {
40
            Security::permissionFailure();
41
        }
42
43
        $params = $this->getURLParams();
44
        if (isset($params['ID']) && !in_array($params['ID'], self::config()->get('allowed_actions'))) {
45
            $form = CheckInForm::create($this);
46
            $form->doCheckIn(array('TicketCode' => $params['ID']), $form);
47
            $this->redirect($this->Link());
48
        }
49
50
        parent::init();
51
    }
52
53
    /**
54
     * Get the check in form
55
     *
56
     * @return CheckInForm
57
     */
58
    public function CheckInForm()
59
    {
60
        return new CheckInForm($this);
61
    }
62
63
    /**
64
     * Force the controller action
65
     *
66
     * @param string $action
67
     *
68
     * @return SSViewer
69
     */
70
    public function getViewer($action)
71
    {
72
        if ($action === 'index') {
73
            $action = 'checkin';
74
        }
75
76
        return parent::getViewer($action);
77
    }
78
79
    /**
80
     * Get a relative link to the current controller
81
     * Needed to handle the form
82
     *
83
     * @param null $action
84
     *
85
     * @return string
86
     */
87
    public function Link($action = null)
88
    {
89
        if (!$action) {
90
            $action = 'checkin';
91
        }
92
93
        return $this->dataRecord->RelativeLink($action);
94
    }
95
96
    /**
97
     * Provide permissions required for ticket check in
98
     *
99
     * @return array
100
     */
101
    public function providePermissions()
102
    {
103
        return array(
104
            'HANDLE_CHECK_IN' => array(
105
                'name' => _t('TicketControllerExtension.HANDLE_CHECK_IN', 'Is authorized to handle ticket check in'),
106
                'category' => _t('TicketControllerExtension.PERMISSIONS_CAT', 'Event tickets'),
107
            )
108
        );
109
    }
110
}
111