1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\libraries\rest_api\calculations; |
4
|
|
|
|
5
|
|
|
use EE_Checkin; |
6
|
|
|
use EE_Error; |
7
|
|
|
use EEM_Base; |
8
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
9
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
10
|
|
|
use EventEspresso\core\libraries\rest_api\calculations\Base as RegistrationCalculationBase; |
11
|
|
|
use EventEspresso\core\libraries\rest_api\controllers\model\Base as RegistrationControllerBase; |
12
|
|
|
use EEM_Registration; |
13
|
|
|
use EE_Registration; |
14
|
|
|
use EEM_Datetime; |
15
|
|
|
use InvalidArgumentException; |
16
|
|
|
use WP_REST_Request; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Registration |
20
|
|
|
* |
21
|
|
|
* @package Registration Espresso |
22
|
|
|
* @subpackage |
23
|
|
|
* @author Mike Nelson |
24
|
|
|
*/ |
25
|
|
|
class Registration extends RegistrationCalculationBase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var EEM_Registration |
29
|
|
|
*/ |
30
|
|
|
protected $registration_model; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Registration constructor. |
34
|
|
|
* @param EEM_Registration $registration_model |
35
|
|
|
*/ |
36
|
|
|
public function __construct(EEM_Registration $registration_model) |
37
|
|
|
{ |
38
|
|
|
$this->registration_model = $registration_model; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Calculates the checkin status for each datetime this registration has access to |
43
|
|
|
* |
44
|
|
|
* @param array $wpdb_row |
45
|
|
|
* @param WP_REST_Request $request |
46
|
|
|
* @param RegistrationControllerBase $controller |
47
|
|
|
* @return array |
48
|
|
|
* @throws EE_Error |
49
|
|
|
* @throws InvalidDataTypeException |
50
|
|
|
* @throws InvalidInterfaceException |
51
|
|
|
* @throws InvalidArgumentException |
52
|
|
|
*/ |
53
|
|
|
public function datetimeCheckinStati($wpdb_row, $request, $controller) |
54
|
|
|
{ |
55
|
|
|
if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) { |
56
|
|
|
$reg = $this->registration_model->get_one_by_ID($wpdb_row['Registration.REG_ID']); |
57
|
|
|
} else { |
58
|
|
|
$reg = null; |
59
|
|
|
} |
60
|
|
|
if (! $reg instanceof EE_Registration |
61
|
|
|
) { |
62
|
|
|
throw new EE_Error( |
63
|
|
|
sprintf( |
64
|
|
|
__( |
65
|
|
|
// @codingStandardsIgnoreStart |
66
|
|
|
'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found', |
67
|
|
|
// @codingStandardsIgnoreEnd |
68
|
|
|
'event_espresso' |
69
|
|
|
), |
70
|
|
|
$wpdb_row['Registration.REG_ID'], |
71
|
|
|
print_r($wpdb_row, true) |
72
|
|
|
) |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
$datetime_ids = EEM_Datetime::instance()->get_col( |
76
|
|
|
[ |
77
|
|
|
[ |
78
|
|
|
'Ticket.TKT_ID' => $reg->ticket_ID(), |
79
|
|
|
], |
80
|
|
|
'default_where_conditions' => EEM_Base::default_where_conditions_minimum_all, |
81
|
|
|
] |
82
|
|
|
); |
83
|
|
|
$checkin_stati = array(); |
84
|
|
|
foreach ($datetime_ids as $datetime_id) { |
85
|
|
|
$status = $reg->check_in_status_for_datetime($datetime_id); |
86
|
|
|
switch ($status) { |
87
|
|
|
case EE_Checkin::status_checked_out: |
88
|
|
|
$status_pretty = 'OUT'; |
89
|
|
|
break; |
90
|
|
|
case EE_Checkin::status_checked_in: |
91
|
|
|
$status_pretty = 'IN'; |
92
|
|
|
break; |
93
|
|
|
case EE_Checkin::status_checked_never: |
94
|
|
|
default: |
95
|
|
|
$status_pretty = 'NEVER'; |
96
|
|
|
break; |
97
|
|
|
} |
98
|
|
|
$checkin_stati[ $datetime_id ] = $status_pretty; |
99
|
|
|
} |
100
|
|
|
return $checkin_stati; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Provides an array for all the calculations possible that outlines a json schema for those calculations. |
106
|
|
|
* Array is indexed by calculation (snake case) and value is the schema for that calculation. |
107
|
|
|
* |
108
|
|
|
* @since $VID:$ |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
|
|
public function schemaForCalculations() |
112
|
|
|
{ |
113
|
|
|
return array( |
114
|
|
|
'datetime_checkin_stati' => array( |
115
|
|
|
'description' => esc_html__( |
116
|
|
|
'Returns the checkin status for each datetime this registration has access to.', |
117
|
|
|
'event_espresso' |
118
|
|
|
), |
119
|
|
|
'type' => 'object', |
120
|
|
|
'properties' => array(), |
121
|
|
|
'additionalProperties' => array( |
122
|
|
|
'description' => esc_html( |
123
|
|
|
'Keys are date-time ids and values are the check-in status', |
124
|
|
|
'event_espresso' |
125
|
|
|
), |
126
|
|
|
'type' => 'string' |
127
|
|
|
), |
128
|
|
|
), |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|