Completed
Branch BUG/double-ampersand-in-regist... (7dce02)
by
unknown
131:59 queued 62:17
created

Attendee   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A userAvatar() 0 11 5
A schemaForCalculations() 0 12 1
1
<?php
2
3
namespace EventEspresso\core\libraries\rest_api\calculations;
4
5
use EventEspresso\core\libraries\rest_api\calculations\Base as AttendeeCalculationsBase;
6
use EventEspresso\core\libraries\rest_api\controllers\model\Base as AttendeeControllerBase;
7
use WP_REST_Request;
8
9
/**
10
 * Class Attendee
11
 * adds calculated fields to the  REST API output for the /attendees/ endpoint
12
 *
13
 * @package EventEspresso\core\libraries\rest_api\calculations
14
 * @author  Brent Christensen
15
 * @since   4.9.66.p
16
 */
17
class Attendee extends AttendeeCalculationsBase
18
{
19
20
    /**
21
     * @param array                  $wpdb_row
22
     * @param WP_REST_Request        $request
23
     * @param AttendeeControllerBase $controller
24
     * @since 4.9.66.p
25
     * @return string
26
     */
27
    public function userAvatar(array $wpdb_row, WP_REST_Request $request, AttendeeControllerBase $controller)
28
    {
29
        if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) {
30
            $email_address = $wpdb_row['Attendee_Meta.ATT_email'];
31
        }
32
        if (empty($email_address)) {
33
            return '';
34
        }
35
        $avatar = get_avatar_url($email_address);
36
        return $avatar ? $avatar : '';
37
    }
38
39
40
    /**
41
     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
42
     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
43
     *
44
     * @since $VID:$
45
     * @return array
46
     */
47
    public function schemaForCalculations()
48
    {
49
        return array(
50
            'user_avatar' => array(
51
                'description' => esc_html__(
52
                    'The avatar url for the attendee (if available).',
53
                    'event_espresso'
54
                ),
55
                'type'        => 'string',
56
            ),
57
        );
58
    }
59
}
60