Completed
Branch Gutenberg/block-manager (d3ae85)
by
unknown
81:22 queued 67:41
created

ExportCheckins::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\services\admin\privacy\export;
4
5
use EE_Registration;
6
use EEM_Checkin;
7
use EventEspresso\core\services\privacy\export\PersonalDataExporterInterface;
8
9
/**
10
 * Class ExportCheckins
11
 * Returns data about when the user checked in or out of events
12
 *
13
 * @package        Event Espresso
14
 * @author         Mike Nelson
15
 * @since          $VID:$
16
 */
17
class ExportCheckins implements PersonalDataExporterInterface
18
{
19
    /**
20
     * @var EEM_Checkin
21
     */
22
    protected $checkin_model;
23
24
    /**
25
     * ExportCheckins constructor.
26
     *
27
     * @param EEM_Checkin $checkin_model
28
     */
29
    public function __construct(EEM_Checkin $checkin_model)
30
    {
31
        $this->checkin_model = $checkin_model;
32
    }
33
34
35
    /**
36
     * Returns data for export.
37
     *
38
     * @param string    $email_address ,
39
     * @param int       $page          starts at 1, not 0
40
     * @return array {
41
     * @type array      $data          {
42
     * @type array {
43
     * @type string     $group_id      (not translated, same for all exports)
44
     * @type string     $group_label   (translated string)
45
     * @type string|int $item_id
46
     * @type array      $data          {
47
     * @type array {
48
     * @type string     $name          what's shown in the left-column of the export row
49
     * @type string     $value         what's showin the right-column of the export row
50
     *                                 }
51
     *                                 }
52
     *                                 }
53
     *                                 }
54
     *                                 }
55
     */
56
    public function export($email_address, $page = 1)
57
    {
58
        $page_size = 10;
59
        $checkins = $this->checkin_model->get_all(
60
            array(
61
                array(
62
                    'Registration.Attendee.ATT_email' => $email_address,
63
                ),
64
                'limit'      => array(
65
                    ($page - 1) * $page_size,
66
                    $page_size,
67
                ),
68
                'force_join' => array('Registration.Event'),
69
            )
70
        );
71
72
        if (empty($checkins)) {
73
            return array(
74
                'data' => array(),
75
                'done' => true,
76
            );
77
        }
78
79
        $export_items = array();
80
        foreach ($checkins as $checkin) {
81
            $reg = $checkin->get_first_related('Registration');
82
            if ($reg instanceof EE_Registration) {
83
                $event_name = $reg->event_name();
84
            } else {
85
                $event_name = esc_html__('Unknown', 'event_espresso');
86
            }
87
            $export_items[] =
88
                array(
89
                    'group_id'    => 'check-ins',
90
                    'group_label' => esc_html__('Event Check-Ins', 'event_espresso'),
91
                    'item_id'     => $checkin->ID(),
92
                    'data'        => array(
93
                        array(
94
                            'name'  => esc_html__('Time', 'event_espresso'),
95
                            'value' => $checkin->get_pretty('CHK_timestamp'),
96
                        ),
97
                        array(
98
                            'name'  => esc_html__('Check in/out', 'event_espresso'),
99
                            'value' => $checkin->get('CHK_in')
100
                                ? esc_html__('In', 'event_espresso')
101
                                : esc_html__('Out', 'event_espresso'),
102
                        ),
103
                        array(
104
                            'name'  => esc_html__('Event', 'event_espresso'),
105
                            'value' => $event_name,
106
                        ),
107
                    ),
108
                );
109
        }
110
        return array(
111
            'data' => $export_items,
112
            'done' => true,
113
        );
114
    }
115
116
    /**
117
     * Gets the Translated name of this exporter
118
     *
119
     * @return string
120
     */
121
    public function name()
122
    {
123
        return esc_html__('Event Espresso Checkins Exporter', 'event_espresso');
124
    }
125
}
126
// End of file ExportCheckins.php
127
// Location: EventEspresso\core\domain\services\admin\privacy\export/ExportCheckins.php
128