|
1
|
|
|
<?php |
|
2
|
|
|
namespace EventEspresso\core\libraries\rest_api\calculations; |
|
3
|
|
|
|
|
4
|
|
|
use EventEspresso\core\libraries\rest_api\calculations\Base as Calculations_Base; |
|
5
|
|
|
use EventEspresso\core\libraries\rest_api\controllers\model\Base; |
|
|
|
|
|
|
6
|
|
|
use EEM_Registration; |
|
7
|
|
|
use EE_Registration; |
|
8
|
|
|
use EEM_Datetime; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class Registration |
|
12
|
|
|
* |
|
13
|
|
|
* @package Registration Espresso |
|
14
|
|
|
* @subpackage |
|
15
|
|
|
* @author Mike Nelson |
|
16
|
|
|
* @since $VID:$ |
|
17
|
|
|
*/ |
|
18
|
|
|
if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
19
|
|
|
exit('No direct script access allowed'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
class Registration extends Calculations_Base |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Calculates the checkin status for each datetime this registration has access to |
|
29
|
|
|
* |
|
30
|
|
|
* @param array $wpdb_row |
|
31
|
|
|
* @param \WP_REST_Request $request |
|
32
|
|
|
* @param Base $controller |
|
33
|
|
|
* @return array |
|
34
|
|
|
* @throws \EE_Error |
|
35
|
|
|
*/ |
|
36
|
|
|
public static function datetimeCheckinStati($wpdb_row, $request, $controller) |
|
37
|
|
|
{ |
|
38
|
|
|
if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) { |
|
39
|
|
|
$reg = EEM_Registration::instance()->get_one_by_ID($wpdb_row['Registration.REG_ID']); |
|
40
|
|
|
} else { |
|
41
|
|
|
$reg = null; |
|
42
|
|
|
} |
|
43
|
|
|
if (! $reg instanceof EE_Registration |
|
44
|
|
|
) { |
|
45
|
|
|
throw new \EE_Error( |
|
46
|
|
|
sprintf( |
|
47
|
|
|
__( |
|
48
|
|
|
// @codingStandardsIgnoreStart |
|
49
|
|
|
'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found', |
|
50
|
|
|
// @codingStandardsIgnoreEnd |
|
51
|
|
|
'event_espresso' |
|
52
|
|
|
), |
|
53
|
|
|
$wpdb_row['Registration.REG_ID'], |
|
54
|
|
|
print_r($wpdb_row, true) |
|
55
|
|
|
) |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
$datetime_ids = EEM_Datetime::instance()->get_col( |
|
59
|
|
|
array( |
|
60
|
|
|
array( |
|
61
|
|
|
'Ticket.TKT_ID' => $reg->ticket_ID(), |
|
62
|
|
|
), |
|
63
|
|
|
'default_where_conditions' => \EEM_Base::default_where_conditions_minimum_all |
|
64
|
|
|
) |
|
65
|
|
|
); |
|
66
|
|
|
$checkin_stati = array(); |
|
67
|
|
|
foreach ($datetime_ids as $datetime_id) { |
|
68
|
|
|
$status = $reg->check_in_status_for_datetime($datetime_id); |
|
69
|
|
|
switch ($status) { |
|
70
|
|
|
case EE_Registration::checkin_status_out: |
|
71
|
|
|
$status_pretty = 'OUT'; |
|
72
|
|
|
break; |
|
73
|
|
|
case EE_Registration::checkin_status_in: |
|
74
|
|
|
$status_pretty = 'IN'; |
|
75
|
|
|
break; |
|
76
|
|
|
case EE_Registration::checkin_status_never: |
|
77
|
|
|
default: |
|
78
|
|
|
$status_pretty = 'NEVER'; |
|
79
|
|
|
break; |
|
80
|
|
|
} |
|
81
|
|
|
$checkin_stati[$datetime_id] = $status_pretty; |
|
82
|
|
|
} |
|
83
|
|
|
return $checkin_stati; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: