|
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
|
|
|
/** |
|
7
|
|
|
* |
|
8
|
|
|
* Class Registration |
|
9
|
|
|
* |
|
10
|
|
|
* |
|
11
|
|
|
* |
|
12
|
|
|
* @package Registration Espresso |
|
13
|
|
|
* @subpackage |
|
14
|
|
|
* @author Mike Nelson |
|
15
|
|
|
* @since $VID:$ |
|
16
|
|
|
* |
|
17
|
|
|
*/ |
|
18
|
|
|
if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
19
|
|
|
exit( 'No direct script access allowed' ); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
class Registration extends Calculations_Base { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Calculates the checkin status for each datetime this registration has access to |
|
26
|
|
|
* |
|
27
|
|
|
* @param array $wpdb_row |
|
28
|
|
|
* @param \WP_REST_Request $request |
|
29
|
|
|
* @param Base $controller |
|
30
|
|
|
* @return int |
|
31
|
|
|
* @throws \EE_Error |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function datetime_checkin_stati( $wpdb_row, $request, $controller ){ |
|
|
|
|
|
|
34
|
|
|
if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Registration.REG_ID' ] ) ) { |
|
35
|
|
|
$reg = \EEM_Registration::instance()->get_one_by_ID( $wpdb_row[ 'Registration.REG_ID' ] ); |
|
36
|
|
|
} else { |
|
37
|
|
|
$reg = null; |
|
38
|
|
|
} |
|
39
|
|
|
if( ! $reg instanceof \EE_Registration |
|
40
|
|
|
) { |
|
41
|
|
|
throw new \EE_Error( |
|
42
|
|
|
sprintf( |
|
43
|
|
|
__( 'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found', 'event_espresso' ), |
|
44
|
|
|
$wpdb_row[ 'Registration.REG_ID' ], |
|
45
|
|
|
print_r( $wpdb_row, true ) |
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
$datetime_ids = \EEM_Datetime::instance()->get_col( |
|
50
|
|
|
array( |
|
51
|
|
|
array( |
|
52
|
|
|
'Ticket.TKT_ID' => $reg->ticket_ID() |
|
53
|
|
|
) |
|
54
|
|
|
) |
|
55
|
|
|
); |
|
56
|
|
|
$checkin_stati = array(); |
|
57
|
|
|
foreach( $datetime_ids as $datetime_id ) { |
|
58
|
|
|
$status = $reg->check_in_status_for_datetime( $datetime_id ); |
|
59
|
|
|
switch( $status ) { |
|
60
|
|
|
case \EE_Registration::checkin_status_out: |
|
61
|
|
|
$status_pretty = 'OUT'; |
|
62
|
|
|
break; |
|
63
|
|
|
case \EE_Registration::checkin_status_in: |
|
64
|
|
|
$status_pretty = 'IN'; |
|
65
|
|
|
break; |
|
66
|
|
|
case \EE_Registration::checkin_status_never: |
|
67
|
|
|
default: |
|
68
|
|
|
$status_pretty = 'NEVER'; |
|
69
|
|
|
break; |
|
70
|
|
|
} |
|
71
|
|
|
$checkin_stati[ $datetime_id ] = $status_pretty; |
|
72
|
|
|
} |
|
73
|
|
|
return $checkin_stati; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
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: