1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\libraries\rest_api\calculations; |
4
|
|
|
|
5
|
|
|
use EE_Attendee; |
6
|
|
|
use EE_Error; |
7
|
|
|
use EEM_Attendee; |
8
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
9
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
10
|
|
|
use EventEspresso\core\libraries\rest_api\calculations\Base as Calculations_Base; |
11
|
|
|
use EventEspresso\core\libraries\rest_api\controllers\model\Base; |
|
|
|
|
12
|
|
|
use InvalidArgumentException; |
13
|
|
|
use WP_REST_Request; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Attendee |
17
|
|
|
* adds calculated fields to the REST API output for the /attendees/ endpoint |
18
|
|
|
* |
19
|
|
|
* @package EventEspresso\core\libraries\rest_api\calculations |
20
|
|
|
* @author Brent Christensen |
21
|
|
|
* @since $VID:$ |
22
|
|
|
*/ |
23
|
|
|
class Attendee extends Calculations_Base |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @since $VID:$ |
28
|
|
|
* @param $wpdb_row |
29
|
|
|
* @return EE_Attendee|\EE_Base_Class |
30
|
|
|
* @throws EE_Error |
31
|
|
|
* @throws InvalidArgumentException |
32
|
|
|
* @throws InvalidDataTypeException |
33
|
|
|
* @throws InvalidInterfaceException |
34
|
|
|
*/ |
35
|
|
|
private static function getAttendeeObject($wpdb_row) |
36
|
|
|
{ |
37
|
|
|
$attendee = null; |
38
|
|
View Code Duplication |
if (is_array($wpdb_row) && isset($wpdb_row['Attendee_CPT.ID']) && absint($wpdb_row['Attendee_CPT.ID'])) { |
39
|
|
|
$attendee = EEM_Attendee::instance()->get_one_by_ID($wpdb_row['Attendee_CPT.ID']); |
40
|
|
|
} |
41
|
|
|
return $attendee; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param array $wpdb_row |
47
|
|
|
* @param WP_REST_Request $request |
48
|
|
|
* @param Base $controller |
49
|
|
|
* @since $VID:$ |
50
|
|
|
* @return string |
51
|
|
|
* @throws EE_Error |
52
|
|
|
* @throws InvalidArgumentException |
53
|
|
|
* @throws InvalidDataTypeException |
54
|
|
|
* @throws InvalidInterfaceException |
55
|
|
|
*/ |
56
|
|
|
public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller) |
57
|
|
|
{ |
58
|
|
|
$attendee = Attendee::getAttendeeObject($wpdb_row); |
59
|
|
|
if (! $attendee instanceof EE_Attendee) { |
60
|
|
|
return ''; |
61
|
|
|
} |
62
|
|
|
$avatar = get_avatar_url($attendee->email()); |
63
|
|
|
return $avatar ? $avatar : ''; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are 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.php
However, as
OtherDir/Foo.php
does 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: