Completed
Branch ADMIN-REFRESH (acf4af)
by
unknown
05:37 queued 02:47
created
admin_pages/registrations/EE_Registrations_List_Table.class.php 1 patch
Indentation   +1001 added lines, -1001 removed lines patch added patch discarded remove patch
@@ -15,724 +15,724 @@  discard block
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * @var Registrations_Admin_Page
20
-     */
21
-    protected $_admin_page;
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    private $_status;
27
-
28
-    /**
29
-     * An array of transaction details for the related transaction to the registration being processed.
30
-     * This is set via the _set_related_details method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_transaction_details = [];
35
-
36
-    /**
37
-     * An array of event details for the related event to the registration being processed.
38
-     * This is set via the _set_related_details method.
39
-     *
40
-     * @var array
41
-     */
42
-    protected $_event_details = [];
43
-
44
-
45
-    /**
46
-     * @param Registrations_Admin_Page $admin_page
47
-     */
48
-    public function __construct(Registrations_Admin_Page $admin_page)
49
-    {
50
-        $req_data = $admin_page->get_request_data();
51
-        if (! empty($req_data['event_id'])) {
52
-            $extra_query_args = [];
53
-            foreach ($admin_page->get_views() as $view_details) {
54
-                $extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
55
-            }
56
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57
-        }
58
-        parent::__construct($admin_page);
59
-        $this->_status = $this->_admin_page->get_registration_status_array();
60
-    }
61
-
62
-
63
-    /**
64
-     * @return void
65
-     * @throws EE_Error
66
-     */
67
-    protected function _setup_data()
68
-    {
69
-        $this->_data           = $this->_admin_page->get_registrations($this->_per_page);
70
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
71
-    }
72
-
73
-
74
-    /**
75
-     * @return void
76
-     */
77
-    protected function _set_properties()
78
-    {
79
-        $return_url          = $this->getReturnUrl();
80
-        $this->_wp_list_args = [
81
-            'singular' => esc_html__('registration', 'event_espresso'),
82
-            'plural'   => esc_html__('registrations', 'event_espresso'),
83
-            'ajax'     => true,
84
-            'screen'   => $this->_admin_page->get_current_screen()->id,
85
-        ];
86
-        $req_data            = $this->_admin_page->get_request_data();
87
-        if (isset($req_data['event_id'])) {
88
-            $this->_columns        = [
89
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
90
-                'id'          => esc_html__('ID', 'event_espresso'),
91
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
92
-                'ATT_email'        => esc_html__('Email', 'event_espresso'),
93
-                '_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
94
-                'PRC_amount'       => esc_html__('TKT Price', 'event_espresso'),
95
-                '_REG_final_price' => esc_html__('Final Price', 'event_espresso'),
96
-                'TXN_total'        => esc_html__('Total Txn', 'event_espresso'),
97
-                'TXN_paid'         => esc_html__('Paid', 'event_espresso'),
98
-                'actions' => $this->actionsColumnHeader(),
99
-            ];
100
-            $this->_bottom_buttons = [
101
-                'report' => [
102
-                    'route'         => 'registrations_report',
103
-                    'extra_request' => [
104
-                        'EVT_ID'     => $this->_req_data['event_id'] ?? null,
105
-                        'return_url' => $return_url,
106
-                    ],
107
-                ],
108
-            ];
109
-        } else {
110
-            $this->_columns        = [
111
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
112
-                'id'          => esc_html__('ID', 'event_espresso'),
113
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
114
-                '_REG_date'        => esc_html__('TXN Date', 'event_espresso'),
115
-                'event_name'       => esc_html__('Event', 'event_espresso'),
116
-                'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
117
-                '_REG_final_price' => esc_html__('Price', 'event_espresso'),
118
-                '_REG_paid'        => esc_html__('Paid', 'event_espresso'),
119
-                'actions' => $this->actionsColumnHeader(),
120
-            ];
121
-            $this->_bottom_buttons = [
122
-                'report_all' => [
123
-                    'route'         => 'registrations_report',
124
-                    'extra_request' => [
125
-                        'return_url' => $return_url,
126
-                    ],
127
-                ],
128
-            ];
129
-        }
130
-        $this->_bottom_buttons['report_filtered'] = [
131
-            'route'         => 'registrations_report',
132
-            'extra_request' => [
133
-                'use_filters' => true,
134
-                'return_url'  => $return_url,
135
-            ],
136
-        ];
137
-        $filters                                  = array_diff_key(
138
-            $this->_req_data,
139
-            array_flip(
140
-                [
141
-                    'page',
142
-                    'action',
143
-                    'default_nonce',
144
-                ]
145
-            )
146
-        );
147
-        if (! empty($filters)) {
148
-            $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
149
-        }
150
-        $this->_primary_column   = 'id';
151
-        $this->_sortable_columns = [
152
-            '_REG_date'     => ['_REG_date' => true],   // true means its already sorted
153
-            /**
154
-             * Allows users to change the default sort if they wish.
155
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
156
-             * name.
157
-             */
158
-            'ATT_fname'     => [
159
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
160
-                true,
161
-                $this,
162
-            ]
163
-                ? ['ATT_lname' => false]
164
-                : ['ATT_fname' => false],
165
-            'event_name'    => ['event_name' => false],
166
-            'DTT_EVT_start' => ['DTT_EVT_start' => false],
167
-            'id'       => ['REG_ID' => false],
168
-        ];
169
-        $this->_hidden_columns   = [];
170
-    }
171
-
172
-
173
-    /**
174
-     * This simply sets up the row class for the table rows.
175
-     * Allows for easier overriding of child methods for setting up sorting.
176
-     *
177
-     * @param EE_Registration $registration the current item
178
-     * @return string
179
-     */
180
-    protected function _get_row_class($registration)
181
-    {
182
-        $class = parent::_get_row_class($registration);
183
-        if ($this->_has_checkbox_column) {
184
-            $class .= ' has-checkbox-column';
185
-        }
186
-        return $class;
187
-    }
188
-
189
-
190
-    /**
191
-     * Set the $_transaction_details property if not set yet.
192
-     *
193
-     * @param EE_Registration $registration
194
-     * @throws EE_Error
195
-     * @throws InvalidArgumentException
196
-     * @throws ReflectionException
197
-     * @throws InvalidDataTypeException
198
-     * @throws InvalidInterfaceException
199
-     */
200
-    protected function _set_related_details(EE_Registration $registration)
201
-    {
202
-        $transaction                = $registration->get_first_related('Transaction');
203
-        $status                     = $transaction instanceof EE_Transaction
204
-            ? $transaction->status_ID()
205
-            : EEM_Transaction::failed_status_code;
206
-        $this->_transaction_details = [
207
-            'transaction' => $transaction,
208
-            'status'      => $status,
209
-            'id'          => $transaction instanceof EE_Transaction
210
-                ? $transaction->ID()
211
-                : 0,
212
-            'title_attr'  => sprintf(
213
-                esc_html__('View Transaction Details (%s)', 'event_espresso'),
214
-                EEH_Template::pretty_status($status, false, 'sentence')
215
-            ),
216
-        ];
217
-        try {
218
-            $event = $registration->event();
219
-        } catch (EntityNotFoundException $e) {
220
-            $event = null;
221
-        }
222
-        $status               = $event instanceof EE_Event
223
-            ? $event->get_active_status()
224
-            : EE_Datetime::inactive;
225
-        $this->_event_details = [
226
-            'event'      => $event,
227
-            'status'     => $status,
228
-            'id'         => $event instanceof EE_Event
229
-                ? $event->ID()
230
-                : 0,
231
-            'title_attr' => sprintf(
232
-                esc_html__('Edit Event (%s)', 'event_espresso'),
233
-                EEH_Template::pretty_status($status, false, 'sentence')
234
-            ),
235
-        ];
236
-    }
237
-
238
-
239
-    /**
240
-     *    _get_table_filters
241
-     *
242
-     * @return array
243
-     */
244
-    protected function _get_table_filters()
245
-    {
246
-        $filters = [];
247
-        // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
248
-        // methods.
249
-        $cur_date     = $this->_req_data['month_range'] ?? '';
250
-        $cur_category = $this->_req_data['EVT_CAT'] ?? -1;
251
-        $reg_status   = $this->_req_data['_reg_status'] ?? '';
252
-        $filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
253
-        $filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
254
-        $status       = [];
255
-        $status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
256
-        foreach ($this->_status as $key => $value) {
257
-            $status[] = ['id' => $key, 'text' => $value];
258
-        }
259
-        if ($this->_view !== 'incomplete') {
260
-            $filters[] = EEH_Form_Fields::select_input(
261
-                '_reg_status',
262
-                $status,
263
-                isset($this->_req_data['_reg_status'])
264
-                    ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
265
-                    : ''
266
-            );
267
-        }
268
-        if (isset($this->_req_data['event_id'])) {
269
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
270
-        }
271
-        return $filters;
272
-    }
273
-
274
-
275
-    /**
276
-     * @return void
277
-     * @throws EE_Error
278
-     * @throws InvalidArgumentException
279
-     * @throws InvalidDataTypeException
280
-     * @throws InvalidInterfaceException
281
-     */
282
-    protected function _add_view_counts()
283
-    {
284
-        $this->_views['all']['count']   = $this->_total_registrations();
285
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
286
-        $this->_views['today']['count'] = $this->_total_registrations_today();
287
-        if (
288
-            EE_Registry::instance()->CAP->current_user_can(
289
-                'ee_delete_registrations',
290
-                'espresso_registrations_trash_registrations'
291
-            )
292
-        ) {
293
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
294
-            $this->_views['trash']['count']      = $this->_total_registrations('trash');
295
-        }
296
-    }
297
-
298
-
299
-    /**
300
-     * @param string $view
301
-     * @return int
302
-     * @throws EE_Error
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidDataTypeException
305
-     * @throws InvalidInterfaceException
306
-     */
307
-    protected function _total_registrations($view = '')
308
-    {
309
-        $_where = [];
310
-        $EVT_ID = isset($this->_req_data['event_id'])
311
-            ? absint($this->_req_data['event_id'])
312
-            : false;
313
-        if ($EVT_ID) {
314
-            $_where['EVT_ID'] = $EVT_ID;
315
-        }
316
-        switch ($view) {
317
-            case 'trash':
318
-                return EEM_Registration::instance()->count_deleted([$_where]);
319
-            case 'incomplete':
320
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
321
-                break;
322
-            default:
323
-                $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
324
-        }
325
-        return EEM_Registration::instance()->count([$_where]);
326
-    }
327
-
328
-
329
-    /**
330
-     * @return int
331
-     * @throws EE_Error
332
-     * @throws InvalidArgumentException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    protected function _total_registrations_this_month()
337
-    {
338
-        $EVT_ID          = isset($this->_req_data['event_id'])
339
-            ? absint($this->_req_data['event_id'])
340
-            : false;
341
-        $_where          = $EVT_ID
342
-            ? ['EVT_ID' => $EVT_ID]
343
-            : [];
344
-        $this_year_r     = date('Y', current_time('timestamp'));
345
-        $time_start      = ' 00:00:00';
346
-        $time_end        = ' 23:59:59';
347
-        $this_month_r    = date('m', current_time('timestamp'));
348
-        $days_this_month = date('t', current_time('timestamp'));
349
-        // setup date query.
350
-        $beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
351
-            'REG_date',
352
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
353
-            'Y-m-d H:i:s'
354
-        );
355
-        $end_string         = EEM_Registration::instance()->convert_datetime_for_query(
356
-            'REG_date',
357
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
358
-            'Y-m-d H:i:s'
359
-        );
360
-        $_where['REG_date'] = [
361
-            'BETWEEN',
362
-            [
363
-                $beginning_string,
364
-                $end_string,
365
-            ],
366
-        ];
367
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
368
-        return EEM_Registration::instance()->count([$_where]);
369
-    }
370
-
371
-
372
-    /**
373
-     * @return int
374
-     * @throws EE_Error
375
-     * @throws InvalidArgumentException
376
-     * @throws InvalidDataTypeException
377
-     * @throws InvalidInterfaceException
378
-     */
379
-    protected function _total_registrations_today()
380
-    {
381
-        $EVT_ID             = isset($this->_req_data['event_id'])
382
-            ? absint($this->_req_data['event_id'])
383
-            : false;
384
-        $_where             = $EVT_ID
385
-            ? ['EVT_ID' => $EVT_ID]
386
-            : [];
387
-        $current_date       = date('Y-m-d', current_time('timestamp'));
388
-        $time_start         = ' 00:00:00';
389
-        $time_end           = ' 23:59:59';
390
-        $_where['REG_date'] = [
391
-            'BETWEEN',
392
-            [
393
-                EEM_Registration::instance()->convert_datetime_for_query(
394
-                    'REG_date',
395
-                    $current_date . $time_start,
396
-                    'Y-m-d H:i:s'
397
-                ),
398
-                EEM_Registration::instance()->convert_datetime_for_query(
399
-                    'REG_date',
400
-                    $current_date . $time_end,
401
-                    'Y-m-d H:i:s'
402
-                ),
403
-            ],
404
-        ];
405
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
406
-        return EEM_Registration::instance()->count([$_where]);
407
-    }
408
-
409
-
410
-    /**
411
-     * @param EE_Registration $registration
412
-     * @return string
413
-     * @throws EE_Error
414
-     * @throws InvalidArgumentException
415
-     * @throws InvalidDataTypeException
416
-     * @throws InvalidInterfaceException
417
-     * @throws ReflectionException
418
-     */
419
-    public function column_cb($registration)
420
-    {
421
-        /** checkbox/lock **/
422
-        $REG_ID = $registration->ID();
423
-        $transaction   = $registration->get_first_related('Transaction');
424
-        $payment_count = $transaction instanceof EE_Transaction
425
-            ? $transaction->count_related('Payment')
426
-            : 0;
427
-        $content = $payment_count > 0 || ! EE_Registry::instance()->CAP->current_user_can(
428
-            'ee_edit_registration',
429
-            'registration_list_table_checkbox_input',
430
-            $REG_ID
431
-        )
432
-            ? '<input disabled type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />
18
+	/**
19
+	 * @var Registrations_Admin_Page
20
+	 */
21
+	protected $_admin_page;
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private $_status;
27
+
28
+	/**
29
+	 * An array of transaction details for the related transaction to the registration being processed.
30
+	 * This is set via the _set_related_details method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_transaction_details = [];
35
+
36
+	/**
37
+	 * An array of event details for the related event to the registration being processed.
38
+	 * This is set via the _set_related_details method.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected $_event_details = [];
43
+
44
+
45
+	/**
46
+	 * @param Registrations_Admin_Page $admin_page
47
+	 */
48
+	public function __construct(Registrations_Admin_Page $admin_page)
49
+	{
50
+		$req_data = $admin_page->get_request_data();
51
+		if (! empty($req_data['event_id'])) {
52
+			$extra_query_args = [];
53
+			foreach ($admin_page->get_views() as $view_details) {
54
+				$extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
55
+			}
56
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57
+		}
58
+		parent::__construct($admin_page);
59
+		$this->_status = $this->_admin_page->get_registration_status_array();
60
+	}
61
+
62
+
63
+	/**
64
+	 * @return void
65
+	 * @throws EE_Error
66
+	 */
67
+	protected function _setup_data()
68
+	{
69
+		$this->_data           = $this->_admin_page->get_registrations($this->_per_page);
70
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return void
76
+	 */
77
+	protected function _set_properties()
78
+	{
79
+		$return_url          = $this->getReturnUrl();
80
+		$this->_wp_list_args = [
81
+			'singular' => esc_html__('registration', 'event_espresso'),
82
+			'plural'   => esc_html__('registrations', 'event_espresso'),
83
+			'ajax'     => true,
84
+			'screen'   => $this->_admin_page->get_current_screen()->id,
85
+		];
86
+		$req_data            = $this->_admin_page->get_request_data();
87
+		if (isset($req_data['event_id'])) {
88
+			$this->_columns        = [
89
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
90
+				'id'          => esc_html__('ID', 'event_espresso'),
91
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
92
+				'ATT_email'        => esc_html__('Email', 'event_espresso'),
93
+				'_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
94
+				'PRC_amount'       => esc_html__('TKT Price', 'event_espresso'),
95
+				'_REG_final_price' => esc_html__('Final Price', 'event_espresso'),
96
+				'TXN_total'        => esc_html__('Total Txn', 'event_espresso'),
97
+				'TXN_paid'         => esc_html__('Paid', 'event_espresso'),
98
+				'actions' => $this->actionsColumnHeader(),
99
+			];
100
+			$this->_bottom_buttons = [
101
+				'report' => [
102
+					'route'         => 'registrations_report',
103
+					'extra_request' => [
104
+						'EVT_ID'     => $this->_req_data['event_id'] ?? null,
105
+						'return_url' => $return_url,
106
+					],
107
+				],
108
+			];
109
+		} else {
110
+			$this->_columns        = [
111
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
112
+				'id'          => esc_html__('ID', 'event_espresso'),
113
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
114
+				'_REG_date'        => esc_html__('TXN Date', 'event_espresso'),
115
+				'event_name'       => esc_html__('Event', 'event_espresso'),
116
+				'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
117
+				'_REG_final_price' => esc_html__('Price', 'event_espresso'),
118
+				'_REG_paid'        => esc_html__('Paid', 'event_espresso'),
119
+				'actions' => $this->actionsColumnHeader(),
120
+			];
121
+			$this->_bottom_buttons = [
122
+				'report_all' => [
123
+					'route'         => 'registrations_report',
124
+					'extra_request' => [
125
+						'return_url' => $return_url,
126
+					],
127
+				],
128
+			];
129
+		}
130
+		$this->_bottom_buttons['report_filtered'] = [
131
+			'route'         => 'registrations_report',
132
+			'extra_request' => [
133
+				'use_filters' => true,
134
+				'return_url'  => $return_url,
135
+			],
136
+		];
137
+		$filters                                  = array_diff_key(
138
+			$this->_req_data,
139
+			array_flip(
140
+				[
141
+					'page',
142
+					'action',
143
+					'default_nonce',
144
+				]
145
+			)
146
+		);
147
+		if (! empty($filters)) {
148
+			$this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
149
+		}
150
+		$this->_primary_column   = 'id';
151
+		$this->_sortable_columns = [
152
+			'_REG_date'     => ['_REG_date' => true],   // true means its already sorted
153
+			/**
154
+			 * Allows users to change the default sort if they wish.
155
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
156
+			 * name.
157
+			 */
158
+			'ATT_fname'     => [
159
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
160
+				true,
161
+				$this,
162
+			]
163
+				? ['ATT_lname' => false]
164
+				: ['ATT_fname' => false],
165
+			'event_name'    => ['event_name' => false],
166
+			'DTT_EVT_start' => ['DTT_EVT_start' => false],
167
+			'id'       => ['REG_ID' => false],
168
+		];
169
+		$this->_hidden_columns   = [];
170
+	}
171
+
172
+
173
+	/**
174
+	 * This simply sets up the row class for the table rows.
175
+	 * Allows for easier overriding of child methods for setting up sorting.
176
+	 *
177
+	 * @param EE_Registration $registration the current item
178
+	 * @return string
179
+	 */
180
+	protected function _get_row_class($registration)
181
+	{
182
+		$class = parent::_get_row_class($registration);
183
+		if ($this->_has_checkbox_column) {
184
+			$class .= ' has-checkbox-column';
185
+		}
186
+		return $class;
187
+	}
188
+
189
+
190
+	/**
191
+	 * Set the $_transaction_details property if not set yet.
192
+	 *
193
+	 * @param EE_Registration $registration
194
+	 * @throws EE_Error
195
+	 * @throws InvalidArgumentException
196
+	 * @throws ReflectionException
197
+	 * @throws InvalidDataTypeException
198
+	 * @throws InvalidInterfaceException
199
+	 */
200
+	protected function _set_related_details(EE_Registration $registration)
201
+	{
202
+		$transaction                = $registration->get_first_related('Transaction');
203
+		$status                     = $transaction instanceof EE_Transaction
204
+			? $transaction->status_ID()
205
+			: EEM_Transaction::failed_status_code;
206
+		$this->_transaction_details = [
207
+			'transaction' => $transaction,
208
+			'status'      => $status,
209
+			'id'          => $transaction instanceof EE_Transaction
210
+				? $transaction->ID()
211
+				: 0,
212
+			'title_attr'  => sprintf(
213
+				esc_html__('View Transaction Details (%s)', 'event_espresso'),
214
+				EEH_Template::pretty_status($status, false, 'sentence')
215
+			),
216
+		];
217
+		try {
218
+			$event = $registration->event();
219
+		} catch (EntityNotFoundException $e) {
220
+			$event = null;
221
+		}
222
+		$status               = $event instanceof EE_Event
223
+			? $event->get_active_status()
224
+			: EE_Datetime::inactive;
225
+		$this->_event_details = [
226
+			'event'      => $event,
227
+			'status'     => $status,
228
+			'id'         => $event instanceof EE_Event
229
+				? $event->ID()
230
+				: 0,
231
+			'title_attr' => sprintf(
232
+				esc_html__('Edit Event (%s)', 'event_espresso'),
233
+				EEH_Template::pretty_status($status, false, 'sentence')
234
+			),
235
+		];
236
+	}
237
+
238
+
239
+	/**
240
+	 *    _get_table_filters
241
+	 *
242
+	 * @return array
243
+	 */
244
+	protected function _get_table_filters()
245
+	{
246
+		$filters = [];
247
+		// todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
248
+		// methods.
249
+		$cur_date     = $this->_req_data['month_range'] ?? '';
250
+		$cur_category = $this->_req_data['EVT_CAT'] ?? -1;
251
+		$reg_status   = $this->_req_data['_reg_status'] ?? '';
252
+		$filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
253
+		$filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
254
+		$status       = [];
255
+		$status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
256
+		foreach ($this->_status as $key => $value) {
257
+			$status[] = ['id' => $key, 'text' => $value];
258
+		}
259
+		if ($this->_view !== 'incomplete') {
260
+			$filters[] = EEH_Form_Fields::select_input(
261
+				'_reg_status',
262
+				$status,
263
+				isset($this->_req_data['_reg_status'])
264
+					? strtoupper(sanitize_key($this->_req_data['_reg_status']))
265
+					: ''
266
+			);
267
+		}
268
+		if (isset($this->_req_data['event_id'])) {
269
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
270
+		}
271
+		return $filters;
272
+	}
273
+
274
+
275
+	/**
276
+	 * @return void
277
+	 * @throws EE_Error
278
+	 * @throws InvalidArgumentException
279
+	 * @throws InvalidDataTypeException
280
+	 * @throws InvalidInterfaceException
281
+	 */
282
+	protected function _add_view_counts()
283
+	{
284
+		$this->_views['all']['count']   = $this->_total_registrations();
285
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
286
+		$this->_views['today']['count'] = $this->_total_registrations_today();
287
+		if (
288
+			EE_Registry::instance()->CAP->current_user_can(
289
+				'ee_delete_registrations',
290
+				'espresso_registrations_trash_registrations'
291
+			)
292
+		) {
293
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
294
+			$this->_views['trash']['count']      = $this->_total_registrations('trash');
295
+		}
296
+	}
297
+
298
+
299
+	/**
300
+	 * @param string $view
301
+	 * @return int
302
+	 * @throws EE_Error
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidDataTypeException
305
+	 * @throws InvalidInterfaceException
306
+	 */
307
+	protected function _total_registrations($view = '')
308
+	{
309
+		$_where = [];
310
+		$EVT_ID = isset($this->_req_data['event_id'])
311
+			? absint($this->_req_data['event_id'])
312
+			: false;
313
+		if ($EVT_ID) {
314
+			$_where['EVT_ID'] = $EVT_ID;
315
+		}
316
+		switch ($view) {
317
+			case 'trash':
318
+				return EEM_Registration::instance()->count_deleted([$_where]);
319
+			case 'incomplete':
320
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
321
+				break;
322
+			default:
323
+				$_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
324
+		}
325
+		return EEM_Registration::instance()->count([$_where]);
326
+	}
327
+
328
+
329
+	/**
330
+	 * @return int
331
+	 * @throws EE_Error
332
+	 * @throws InvalidArgumentException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	protected function _total_registrations_this_month()
337
+	{
338
+		$EVT_ID          = isset($this->_req_data['event_id'])
339
+			? absint($this->_req_data['event_id'])
340
+			: false;
341
+		$_where          = $EVT_ID
342
+			? ['EVT_ID' => $EVT_ID]
343
+			: [];
344
+		$this_year_r     = date('Y', current_time('timestamp'));
345
+		$time_start      = ' 00:00:00';
346
+		$time_end        = ' 23:59:59';
347
+		$this_month_r    = date('m', current_time('timestamp'));
348
+		$days_this_month = date('t', current_time('timestamp'));
349
+		// setup date query.
350
+		$beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
351
+			'REG_date',
352
+			$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
353
+			'Y-m-d H:i:s'
354
+		);
355
+		$end_string         = EEM_Registration::instance()->convert_datetime_for_query(
356
+			'REG_date',
357
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
358
+			'Y-m-d H:i:s'
359
+		);
360
+		$_where['REG_date'] = [
361
+			'BETWEEN',
362
+			[
363
+				$beginning_string,
364
+				$end_string,
365
+			],
366
+		];
367
+		$_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
368
+		return EEM_Registration::instance()->count([$_where]);
369
+	}
370
+
371
+
372
+	/**
373
+	 * @return int
374
+	 * @throws EE_Error
375
+	 * @throws InvalidArgumentException
376
+	 * @throws InvalidDataTypeException
377
+	 * @throws InvalidInterfaceException
378
+	 */
379
+	protected function _total_registrations_today()
380
+	{
381
+		$EVT_ID             = isset($this->_req_data['event_id'])
382
+			? absint($this->_req_data['event_id'])
383
+			: false;
384
+		$_where             = $EVT_ID
385
+			? ['EVT_ID' => $EVT_ID]
386
+			: [];
387
+		$current_date       = date('Y-m-d', current_time('timestamp'));
388
+		$time_start         = ' 00:00:00';
389
+		$time_end           = ' 23:59:59';
390
+		$_where['REG_date'] = [
391
+			'BETWEEN',
392
+			[
393
+				EEM_Registration::instance()->convert_datetime_for_query(
394
+					'REG_date',
395
+					$current_date . $time_start,
396
+					'Y-m-d H:i:s'
397
+				),
398
+				EEM_Registration::instance()->convert_datetime_for_query(
399
+					'REG_date',
400
+					$current_date . $time_end,
401
+					'Y-m-d H:i:s'
402
+				),
403
+			],
404
+		];
405
+		$_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
406
+		return EEM_Registration::instance()->count([$_where]);
407
+	}
408
+
409
+
410
+	/**
411
+	 * @param EE_Registration $registration
412
+	 * @return string
413
+	 * @throws EE_Error
414
+	 * @throws InvalidArgumentException
415
+	 * @throws InvalidDataTypeException
416
+	 * @throws InvalidInterfaceException
417
+	 * @throws ReflectionException
418
+	 */
419
+	public function column_cb($registration)
420
+	{
421
+		/** checkbox/lock **/
422
+		$REG_ID = $registration->ID();
423
+		$transaction   = $registration->get_first_related('Transaction');
424
+		$payment_count = $transaction instanceof EE_Transaction
425
+			? $transaction->count_related('Payment')
426
+			: 0;
427
+		$content = $payment_count > 0 || ! EE_Registry::instance()->CAP->current_user_can(
428
+			'ee_edit_registration',
429
+			'registration_list_table_checkbox_input',
430
+			$REG_ID
431
+		)
432
+			? '<input disabled type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />
433 433
                 <span class="dashicons dashicons-lock"></span>'
434
-            : '<input type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />';
435
-
436
-        return $this->columnContent('cb', $content, 'center');
437
-    }
438
-
439
-
440
-    /**
441
-     * @param EE_Registration $registration
442
-     * @return string
443
-     * @throws EE_Error
444
-     * @throws InvalidArgumentException
445
-     * @throws InvalidDataTypeException
446
-     * @throws InvalidInterfaceException
447
-     * @throws ReflectionException
448
-     */
449
-    public function column_id(EE_Registration $registration)
450
-    {
451
-        $content  = $registration->ID();
452
-        $content .= '<span class="show-on-mobile-view-only">';
453
-        $content  .= $this->column_ATT_fname($registration, false);
454
-        $content .= '</span>';
455
-
456
-        return $this->columnContent('id', $content, 'end');
457
-    }
458
-
459
-
460
-    /**
461
-     * @param EE_Registration $registration
462
-     * @return string
463
-     * @throws EE_Error
464
-     * @throws InvalidArgumentException
465
-     * @throws InvalidDataTypeException
466
-     * @throws InvalidInterfaceException
467
-     * @throws ReflectionException
468
-     */
469
-    public function column_ATT_fname(EE_Registration $registration, $prep_content = true)
470
-    {
471
-        $attendee      = $registration->attendee();
472
-        $edit_link_url  = EE_Admin_Page::add_query_args_and_nonce(
473
-            [
474
-                'action'  => 'view_registration',
475
-                '_REG_ID' => $registration->ID(),
476
-            ],
477
-            REG_ADMIN_URL
478
-        );
479
-        $attendee_name = $attendee instanceof EE_Attendee
480
-            ? $attendee->full_name()
481
-            : '';
482
-
483
-        $status        = esc_attr($registration->status_ID());
484
-        $pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
485
-
486
-        $content = '
434
+			: '<input type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />';
435
+
436
+		return $this->columnContent('cb', $content, 'center');
437
+	}
438
+
439
+
440
+	/**
441
+	 * @param EE_Registration $registration
442
+	 * @return string
443
+	 * @throws EE_Error
444
+	 * @throws InvalidArgumentException
445
+	 * @throws InvalidDataTypeException
446
+	 * @throws InvalidInterfaceException
447
+	 * @throws ReflectionException
448
+	 */
449
+	public function column_id(EE_Registration $registration)
450
+	{
451
+		$content  = $registration->ID();
452
+		$content .= '<span class="show-on-mobile-view-only">';
453
+		$content  .= $this->column_ATT_fname($registration, false);
454
+		$content .= '</span>';
455
+
456
+		return $this->columnContent('id', $content, 'end');
457
+	}
458
+
459
+
460
+	/**
461
+	 * @param EE_Registration $registration
462
+	 * @return string
463
+	 * @throws EE_Error
464
+	 * @throws InvalidArgumentException
465
+	 * @throws InvalidDataTypeException
466
+	 * @throws InvalidInterfaceException
467
+	 * @throws ReflectionException
468
+	 */
469
+	public function column_ATT_fname(EE_Registration $registration, $prep_content = true)
470
+	{
471
+		$attendee      = $registration->attendee();
472
+		$edit_link_url  = EE_Admin_Page::add_query_args_and_nonce(
473
+			[
474
+				'action'  => 'view_registration',
475
+				'_REG_ID' => $registration->ID(),
476
+			],
477
+			REG_ADMIN_URL
478
+		);
479
+		$attendee_name = $attendee instanceof EE_Attendee
480
+			? $attendee->full_name()
481
+			: '';
482
+
483
+		$status        = esc_attr($registration->status_ID());
484
+		$pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
485
+
486
+		$content = '
487 487
         <div class="ee-layout-row">
488 488
             <span aria-label="' . $pretty_status . '" 
489 489
                   class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"
490 490
             ></span>';
491 491
 
492
-        $content .= EE_Registry::instance()->CAP->current_user_can(
493
-            'ee_read_registration',
494
-            'espresso_registrations_view_registration',
495
-            $registration->ID()
496
-        )
497
-            ? '
492
+		$content .= EE_Registry::instance()->CAP->current_user_can(
493
+			'ee_read_registration',
494
+			'espresso_registrations_view_registration',
495
+			$registration->ID()
496
+		)
497
+			? '
498 498
             <a  href="' . $edit_link_url . '"  
499 499
                 class="row-title ee-status-color--' . $status . ' ee-aria-tooltip" 
500 500
                 aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '"
501 501
             >
502 502
                 ' . $attendee_name . '
503 503
             </a>'
504
-            : $attendee_name;
505
-
506
-        $content .= $registration->count() === 1
507
-            ? '<sup><span class="dashicons dashicons-star-filled gold-icon"></span></sup>'
508
-            : '';
509
-
510
-        $transaction   = $registration->get_first_related('Transaction');
511
-        $payment_count = $transaction instanceof EE_Transaction
512
-            ? $transaction->count_related('Payment')
513
-            : 0;
514
-
515
-        // append group count to name
516
-        $content .= '<span class="reg-count-group-size">';
517
-        $content .= sprintf(
518
-            esc_html__('(%1$s / %2$s)', 'event_espresso'),
519
-            $registration->count(),
520
-            $registration->group_size()
521
-        );
522
-        $content .= '</span>
504
+			: $attendee_name;
505
+
506
+		$content .= $registration->count() === 1
507
+			? '<sup><span class="dashicons dashicons-star-filled gold-icon"></span></sup>'
508
+			: '';
509
+
510
+		$transaction   = $registration->get_first_related('Transaction');
511
+		$payment_count = $transaction instanceof EE_Transaction
512
+			? $transaction->count_related('Payment')
513
+			: 0;
514
+
515
+		// append group count to name
516
+		$content .= '<span class="reg-count-group-size">';
517
+		$content .= sprintf(
518
+			esc_html__('(%1$s / %2$s)', 'event_espresso'),
519
+			$registration->count(),
520
+			$registration->group_size()
521
+		);
522
+		$content .= '</span>
523 523
         </div>';
524 524
 
525
-        // append reg_code
526
-        $content .= sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $registration->get('REG_code'));
527
-        $action = ['_REG_ID' => $registration->ID()];
528
-        if (isset($this->_req_data['event_id'])) {
529
-            $action['event_id'] = $registration->event_ID();
530
-        }
531
-        // trash/restore/delete actions
532
-        $actions = [];
533
-        if (
534
-            $this->_view !== 'trash'
535
-            && $payment_count === 0
536
-            && EE_Registry::instance()->CAP->current_user_can(
537
-                'ee_delete_registration',
538
-                'espresso_registrations_trash_registrations',
539
-                $registration->ID()
540
-            )
541
-        ) {
542
-            $action['action'] = 'trash_registrations';
543
-            $trash_link_url    = EE_Admin_Page::add_query_args_and_nonce(
544
-                $action,
545
-                REG_ADMIN_URL
546
-            );
547
-            $actions['trash'] = '<a class="ee-aria-tooltip" href="'
548
-                                . $trash_link_url
549
-                                . '" aria-label="'
550
-                                . esc_attr__('Trash Registration', 'event_espresso')
551
-                                . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
552
-        } elseif ($this->_view === 'trash') {
553
-            // restore registration link
554
-            if (
555
-                EE_Registry::instance()->CAP->current_user_can(
556
-                    'ee_delete_registration',
557
-                    'espresso_registrations_restore_registrations',
558
-                    $registration->ID()
559
-                )
560
-            ) {
561
-                $action['action']   = 'restore_registrations';
562
-                $restore_link_url    = EE_Admin_Page::add_query_args_and_nonce(
563
-                    $action,
564
-                    REG_ADMIN_URL
565
-                );
566
-                $actions['restore'] = '<a class="ee-aria-tooltip" href="'
567
-                                      . $restore_link_url
568
-                                      . '" aria-label="'
569
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
570
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
571
-            }
572
-            if (
573
-                EE_Registry::instance()->CAP->current_user_can(
574
-                    'ee_delete_registration',
575
-                    'espresso_registrations_ee_delete_registrations',
576
-                    $registration->ID()
577
-                )
578
-            ) {
579
-                $action['action']  = 'delete_registrations';
580
-                $delete_link_url    = EE_Admin_Page::add_query_args_and_nonce(
581
-                    $action,
582
-                    REG_ADMIN_URL
583
-                );
584
-                $actions['delete'] = '<a class="ee-aria-tooltip" href="'
585
-                                     . $delete_link_url
586
-                                     . '" aria-label="'
587
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
588
-                                     . '">'
589
-                                     . esc_html__('Delete', 'event_espresso')
590
-                                     . '</a>';
591
-            }
592
-        }
593
-        $content = sprintf('%1$s %2$s', $content, $this->row_actions($actions));
594
-
595
-        return $prep_content ? $this->columnContent('ATT_fname', $content) : $content;
596
-    }
597
-
598
-
599
-    /**
600
-     * @param EE_Registration $registration
601
-     * @return string
602
-     * @throws EE_Error
603
-     * @throws InvalidArgumentException
604
-     * @throws InvalidDataTypeException
605
-     * @throws InvalidInterfaceException
606
-     * @throws ReflectionException
607
-     */
608
-    public function column__REG_date(EE_Registration $registration, $prep_content = true)
609
-    {
610
-        $this->_set_related_details($registration);
611
-        // Build row actions
612
-        $view_link_url = EE_Admin_Page::add_query_args_and_nonce(
613
-            [
614
-                'action' => 'view_transaction',
615
-                'TXN_ID' => $this->_transaction_details['id'],
616
-            ],
617
-            TXN_ADMIN_URL
618
-        );
619
-        $content    = EE_Registry::instance()->CAP->current_user_can(
620
-            'ee_read_transaction',
621
-            'espresso_transactions_view_transaction'
622
-        )
623
-            ? '<a class="ee-aria-tooltip ee-status-color--' . $this->_transaction_details['status'] . '" href="'
624
-              . $view_link_url
625
-              . '" aria-label="'
626
-              . esc_attr($this->_transaction_details['title_attr'])
627
-              . '">'
628
-              . $registration->get_i18n_datetime('REG_date', 'M jS Y g:i a')
629
-              . '</a>'
630
-            : $registration->get_i18n_datetime('REG_date');
631
-
632
-        // $content .= ' <span class="ee-status-text-small">'
633
-        //             . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
634
-        //             . '</span>';
635
-
636
-        return $prep_content ? $this->columnContent('_REG_date', $content) : $content;
637
-    }
638
-
639
-
640
-    /**
641
-     * @param EE_Registration $registration
642
-     * @return string
643
-     * @throws EE_Error
644
-     * @throws InvalidArgumentException
645
-     * @throws InvalidDataTypeException
646
-     * @throws InvalidInterfaceException
647
-     * @throws ReflectionException
648
-     */
649
-    public function column_event_name(EE_Registration $registration)
650
-    {
651
-        $this->_set_related_details($registration);
652
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
653
-        $EVT_ID     = $registration->event_ID();
654
-        $event_name = $registration->event_name();
655
-        $event_name =
656
-            $event_name
657
-                ?: esc_html__("No Associated Event", 'event_espresso');
658
-        $event_name = wp_trim_words($event_name, 30, '...');
659
-        if ($EVT_ID) {
660
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
661
-                ['action' => 'edit', 'post' => $EVT_ID],
662
-                EVENTS_ADMIN_URL
663
-            );
664
-            $edit_event              =
665
-                EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
666
-                    ? '<a class="ee-aria-tooltip ee-status-color--'
667
-                      . $this->_event_details['status']
668
-                      . '" href="'
669
-                      . $edit_event_url
670
-                      . '" aria-label="'
671
-                      . esc_attr($this->_event_details['title_attr'])
672
-                      . '">'
673
-                      . $event_name
674
-                      . '</a>'
675
-                    : $event_name;
676
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
677
-            $actions['event_filter'] = '
525
+		// append reg_code
526
+		$content .= sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $registration->get('REG_code'));
527
+		$action = ['_REG_ID' => $registration->ID()];
528
+		if (isset($this->_req_data['event_id'])) {
529
+			$action['event_id'] = $registration->event_ID();
530
+		}
531
+		// trash/restore/delete actions
532
+		$actions = [];
533
+		if (
534
+			$this->_view !== 'trash'
535
+			&& $payment_count === 0
536
+			&& EE_Registry::instance()->CAP->current_user_can(
537
+				'ee_delete_registration',
538
+				'espresso_registrations_trash_registrations',
539
+				$registration->ID()
540
+			)
541
+		) {
542
+			$action['action'] = 'trash_registrations';
543
+			$trash_link_url    = EE_Admin_Page::add_query_args_and_nonce(
544
+				$action,
545
+				REG_ADMIN_URL
546
+			);
547
+			$actions['trash'] = '<a class="ee-aria-tooltip" href="'
548
+								. $trash_link_url
549
+								. '" aria-label="'
550
+								. esc_attr__('Trash Registration', 'event_espresso')
551
+								. '">' . esc_html__('Trash', 'event_espresso') . '</a>';
552
+		} elseif ($this->_view === 'trash') {
553
+			// restore registration link
554
+			if (
555
+				EE_Registry::instance()->CAP->current_user_can(
556
+					'ee_delete_registration',
557
+					'espresso_registrations_restore_registrations',
558
+					$registration->ID()
559
+				)
560
+			) {
561
+				$action['action']   = 'restore_registrations';
562
+				$restore_link_url    = EE_Admin_Page::add_query_args_and_nonce(
563
+					$action,
564
+					REG_ADMIN_URL
565
+				);
566
+				$actions['restore'] = '<a class="ee-aria-tooltip" href="'
567
+									  . $restore_link_url
568
+									  . '" aria-label="'
569
+									  . esc_attr__('Restore Registration', 'event_espresso') . '">'
570
+									  . esc_html__('Restore', 'event_espresso') . '</a>';
571
+			}
572
+			if (
573
+				EE_Registry::instance()->CAP->current_user_can(
574
+					'ee_delete_registration',
575
+					'espresso_registrations_ee_delete_registrations',
576
+					$registration->ID()
577
+				)
578
+			) {
579
+				$action['action']  = 'delete_registrations';
580
+				$delete_link_url    = EE_Admin_Page::add_query_args_and_nonce(
581
+					$action,
582
+					REG_ADMIN_URL
583
+				);
584
+				$actions['delete'] = '<a class="ee-aria-tooltip" href="'
585
+									 . $delete_link_url
586
+									 . '" aria-label="'
587
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
588
+									 . '">'
589
+									 . esc_html__('Delete', 'event_espresso')
590
+									 . '</a>';
591
+			}
592
+		}
593
+		$content = sprintf('%1$s %2$s', $content, $this->row_actions($actions));
594
+
595
+		return $prep_content ? $this->columnContent('ATT_fname', $content) : $content;
596
+	}
597
+
598
+
599
+	/**
600
+	 * @param EE_Registration $registration
601
+	 * @return string
602
+	 * @throws EE_Error
603
+	 * @throws InvalidArgumentException
604
+	 * @throws InvalidDataTypeException
605
+	 * @throws InvalidInterfaceException
606
+	 * @throws ReflectionException
607
+	 */
608
+	public function column__REG_date(EE_Registration $registration, $prep_content = true)
609
+	{
610
+		$this->_set_related_details($registration);
611
+		// Build row actions
612
+		$view_link_url = EE_Admin_Page::add_query_args_and_nonce(
613
+			[
614
+				'action' => 'view_transaction',
615
+				'TXN_ID' => $this->_transaction_details['id'],
616
+			],
617
+			TXN_ADMIN_URL
618
+		);
619
+		$content    = EE_Registry::instance()->CAP->current_user_can(
620
+			'ee_read_transaction',
621
+			'espresso_transactions_view_transaction'
622
+		)
623
+			? '<a class="ee-aria-tooltip ee-status-color--' . $this->_transaction_details['status'] . '" href="'
624
+			  . $view_link_url
625
+			  . '" aria-label="'
626
+			  . esc_attr($this->_transaction_details['title_attr'])
627
+			  . '">'
628
+			  . $registration->get_i18n_datetime('REG_date', 'M jS Y g:i a')
629
+			  . '</a>'
630
+			: $registration->get_i18n_datetime('REG_date');
631
+
632
+		// $content .= ' <span class="ee-status-text-small">'
633
+		//             . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
634
+		//             . '</span>';
635
+
636
+		return $prep_content ? $this->columnContent('_REG_date', $content) : $content;
637
+	}
638
+
639
+
640
+	/**
641
+	 * @param EE_Registration $registration
642
+	 * @return string
643
+	 * @throws EE_Error
644
+	 * @throws InvalidArgumentException
645
+	 * @throws InvalidDataTypeException
646
+	 * @throws InvalidInterfaceException
647
+	 * @throws ReflectionException
648
+	 */
649
+	public function column_event_name(EE_Registration $registration)
650
+	{
651
+		$this->_set_related_details($registration);
652
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
653
+		$EVT_ID     = $registration->event_ID();
654
+		$event_name = $registration->event_name();
655
+		$event_name =
656
+			$event_name
657
+				?: esc_html__("No Associated Event", 'event_espresso');
658
+		$event_name = wp_trim_words($event_name, 30, '...');
659
+		if ($EVT_ID) {
660
+			$edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
661
+				['action' => 'edit', 'post' => $EVT_ID],
662
+				EVENTS_ADMIN_URL
663
+			);
664
+			$edit_event              =
665
+				EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
666
+					? '<a class="ee-aria-tooltip ee-status-color--'
667
+					  . $this->_event_details['status']
668
+					  . '" href="'
669
+					  . $edit_event_url
670
+					  . '" aria-label="'
671
+					  . esc_attr($this->_event_details['title_attr'])
672
+					  . '">'
673
+					  . $event_name
674
+					  . '</a>'
675
+					: $event_name;
676
+			$edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
677
+			$actions['event_filter'] = '
678 678
                 <a  class="ee-aria-tooltip ee-event-filter-link" href="' . $edit_event_url . '" 
679 679
                     aria-label="' . sprintf(
680
-                        esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
681
-                        $event_name
682
-                    ) .'">
680
+						esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
681
+						$event_name
682
+					) .'">
683 683
                     <span class="dashicons dashicons-groups dashicons--small"></span>'
684
-                    . esc_html__('View Registrations', 'event_espresso') .
685
-                '</a>';
686
-        } else {
687
-            $edit_event              = $event_name;
688
-            $actions['event_filter'] = '';
689
-        }
690
-        $content = sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
691
-
692
-        return $this->columnContent('event_name', $content);
693
-    }
694
-
695
-
696
-    /**
697
-     * @param EE_Registration $registration
698
-     * @return string
699
-     * @throws EE_Error
700
-     * @throws InvalidArgumentException
701
-     * @throws InvalidDataTypeException
702
-     * @throws InvalidInterfaceException
703
-     * @throws ReflectionException
704
-     */
705
-    public function column_DTT_EVT_start(EE_Registration $registration)
706
-    {
707
-        $datetime_strings = [];
708
-        $ticket           = $registration->ticket();
709
-        if ($ticket instanceof EE_Ticket) {
710
-            $remove_defaults = ['default_where_conditions' => 'none'];
711
-            $datetimes       = $ticket->datetimes($remove_defaults);
712
-            foreach ($datetimes as $datetime) {
713
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a');
714
-            }
715
-            $content = $this->generateDisplayForDatetimes($datetime_strings);
716
-        } else {
717
-            $content = esc_html__('There is no ticket on this registration', 'event_espresso');
718
-        }
719
-        return $this->columnContent('DTT_EVT_start', $content);
720
-    }
721
-
722
-
723
-    /**
724
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
725
-     *
726
-     * @param array $datetime_strings
727
-     * @return string
728
-     */
729
-    public function generateDisplayForDatetimes(array $datetime_strings): string
730
-    {
731
-        // $content       = '<div class="ee-registration-event-datetimes-container">';
732
-        // get first item for initial visibility
733
-        $content = array_shift($datetime_strings);
734
-        if (! empty($datetime_strings)) {
735
-            $content .= '
684
+					. esc_html__('View Registrations', 'event_espresso') .
685
+				'</a>';
686
+		} else {
687
+			$edit_event              = $event_name;
688
+			$actions['event_filter'] = '';
689
+		}
690
+		$content = sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
691
+
692
+		return $this->columnContent('event_name', $content);
693
+	}
694
+
695
+
696
+	/**
697
+	 * @param EE_Registration $registration
698
+	 * @return string
699
+	 * @throws EE_Error
700
+	 * @throws InvalidArgumentException
701
+	 * @throws InvalidDataTypeException
702
+	 * @throws InvalidInterfaceException
703
+	 * @throws ReflectionException
704
+	 */
705
+	public function column_DTT_EVT_start(EE_Registration $registration)
706
+	{
707
+		$datetime_strings = [];
708
+		$ticket           = $registration->ticket();
709
+		if ($ticket instanceof EE_Ticket) {
710
+			$remove_defaults = ['default_where_conditions' => 'none'];
711
+			$datetimes       = $ticket->datetimes($remove_defaults);
712
+			foreach ($datetimes as $datetime) {
713
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a');
714
+			}
715
+			$content = $this->generateDisplayForDatetimes($datetime_strings);
716
+		} else {
717
+			$content = esc_html__('There is no ticket on this registration', 'event_espresso');
718
+		}
719
+		return $this->columnContent('DTT_EVT_start', $content);
720
+	}
721
+
722
+
723
+	/**
724
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
725
+	 *
726
+	 * @param array $datetime_strings
727
+	 * @return string
728
+	 */
729
+	public function generateDisplayForDatetimes(array $datetime_strings): string
730
+	{
731
+		// $content       = '<div class="ee-registration-event-datetimes-container">';
732
+		// get first item for initial visibility
733
+		$content = array_shift($datetime_strings);
734
+		if (! empty($datetime_strings)) {
735
+			$content .= '
736 736
                 <div class="ee-registration-event-datetimes-container-wrap">
737 737
                     <button aria-label="' . esc_attr__('Click to view all dates', 'event_espresso') . '" 
738 738
                           class="ee-aria-tooltip button button--secondary button--tiny button--icon-only ee-js ee-more-datetimes-toggle"
@@ -743,348 +743,348 @@  discard block
 block discarded – undo
743 743
                         ' . implode("", $datetime_strings) . '
744 744
                     </div>
745 745
                 </div>';
746
-        }
747
-        // $content .= '</div>';
748
-        return $content;
749
-    }
750
-
751
-
752
-    /**
753
-     * @param EE_Registration $registration
754
-     * @return string
755
-     * @throws EE_Error
756
-     * @throws InvalidArgumentException
757
-     * @throws InvalidDataTypeException
758
-     * @throws InvalidInterfaceException
759
-     * @throws ReflectionException
760
-     */
761
-    public function column_ATT_email(EE_Registration $registration)
762
-    {
763
-        $attendee = $registration->get_first_related('Attendee');
764
-        $content = ! $attendee instanceof EE_Attendee
765
-            ? esc_html__('No attached contact record.', 'event_espresso')
766
-            : $attendee->email();
767
-        return $this->columnContent('ATT_email', $content);
768
-    }
769
-
770
-
771
-    /**
772
-     * @param EE_Registration $registration
773
-     * @return string
774
-     */
775
-    public function column__REG_count(EE_Registration $registration)
776
-    {
777
-        $content = sprintf(esc_html__('%1$s / %2$s', 'event_espresso'), $registration->count(), $registration->group_size());
778
-        return $this->columnContent('_REG_count', $content);
779
-    }
780
-
781
-
782
-    /**
783
-     * @param EE_Registration $registration
784
-     * @return string
785
-     * @throws EE_Error
786
-     * @throws ReflectionException
787
-     */
788
-    public function column_PRC_amount(EE_Registration $registration)
789
-    {
790
-        $ticket   = $registration->ticket();
791
-        $req_data = $this->_admin_page->get_request_data();
792
-
793
-        $content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
794
-            ? '<div class="TKT_name">' . $ticket->name() . '</div>'
795
-            : '';
746
+		}
747
+		// $content .= '</div>';
748
+		return $content;
749
+	}
750
+
751
+
752
+	/**
753
+	 * @param EE_Registration $registration
754
+	 * @return string
755
+	 * @throws EE_Error
756
+	 * @throws InvalidArgumentException
757
+	 * @throws InvalidDataTypeException
758
+	 * @throws InvalidInterfaceException
759
+	 * @throws ReflectionException
760
+	 */
761
+	public function column_ATT_email(EE_Registration $registration)
762
+	{
763
+		$attendee = $registration->get_first_related('Attendee');
764
+		$content = ! $attendee instanceof EE_Attendee
765
+			? esc_html__('No attached contact record.', 'event_espresso')
766
+			: $attendee->email();
767
+		return $this->columnContent('ATT_email', $content);
768
+	}
769
+
770
+
771
+	/**
772
+	 * @param EE_Registration $registration
773
+	 * @return string
774
+	 */
775
+	public function column__REG_count(EE_Registration $registration)
776
+	{
777
+		$content = sprintf(esc_html__('%1$s / %2$s', 'event_espresso'), $registration->count(), $registration->group_size());
778
+		return $this->columnContent('_REG_count', $content);
779
+	}
780
+
781
+
782
+	/**
783
+	 * @param EE_Registration $registration
784
+	 * @return string
785
+	 * @throws EE_Error
786
+	 * @throws ReflectionException
787
+	 */
788
+	public function column_PRC_amount(EE_Registration $registration)
789
+	{
790
+		$ticket   = $registration->ticket();
791
+		$req_data = $this->_admin_page->get_request_data();
792
+
793
+		$content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
794
+			? '<div class="TKT_name">' . $ticket->name() . '</div>'
795
+			: '';
796 796
         
797
-        $payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
798
-        $content .= $registration->final_price() > 0
799
-            ? '<span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
797
+		$payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
798
+		$content .= $registration->final_price() > 0
799
+			? '<span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
800 800
                 ' . $registration->pretty_final_price() . '
801 801
                </span>'
802
-            // free event
803
-            : '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
804
-
805
-        return $this->columnContent('PRC_amount', $content, 'end');
806
-    }
807
-
808
-
809
-    /**
810
-     * @param EE_Registration $registration
811
-     * @return string
812
-     * @throws EE_Error
813
-     * @throws ReflectionException
814
-     */
815
-    public function column__REG_final_price(EE_Registration $registration)
816
-    {
817
-        $ticket   = $registration->ticket();
818
-        $req_data = $this->_admin_page->get_request_data();
819
-        $content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
820
-            ? ''
821
-            : '<span class="TKT_name ee-status-color--' . $ticket->ticket_status() . '">' . $ticket->name() . '</span> ';
822
-
823
-        $content  .= '
802
+			// free event
803
+			: '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
804
+
805
+		return $this->columnContent('PRC_amount', $content, 'end');
806
+	}
807
+
808
+
809
+	/**
810
+	 * @param EE_Registration $registration
811
+	 * @return string
812
+	 * @throws EE_Error
813
+	 * @throws ReflectionException
814
+	 */
815
+	public function column__REG_final_price(EE_Registration $registration)
816
+	{
817
+		$ticket   = $registration->ticket();
818
+		$req_data = $this->_admin_page->get_request_data();
819
+		$content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
820
+			? ''
821
+			: '<span class="TKT_name ee-status-color--' . $ticket->ticket_status() . '">' . $ticket->name() . '</span> ';
822
+
823
+		$content  .= '
824 824
             <span class="reg-overview-paid-event-spn">
825 825
                 ' . $registration->pretty_final_price() . '
826 826
             </span>';
827
-        return $this->columnContent('_REG_final_price', $content, 'end');
828
-    }
829
-
830
-
831
-    /**
832
-     * @param EE_Registration $registration
833
-     * @return string
834
-     * @throws EE_Error
835
-     */
836
-    public function column__REG_paid(EE_Registration $registration)
837
-    {
838
-        $payment_method      = $registration->payment_method();
839
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
840
-            ? $payment_method->admin_name()
841
-            : esc_html__('Unknown', 'event_espresso');
842
-
843
-        $payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
844
-        $content        = '
827
+		return $this->columnContent('_REG_final_price', $content, 'end');
828
+	}
829
+
830
+
831
+	/**
832
+	 * @param EE_Registration $registration
833
+	 * @return string
834
+	 * @throws EE_Error
835
+	 */
836
+	public function column__REG_paid(EE_Registration $registration)
837
+	{
838
+		$payment_method      = $registration->payment_method();
839
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
840
+			? $payment_method->admin_name()
841
+			: esc_html__('Unknown', 'event_espresso');
842
+
843
+		$payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
844
+		$content        = '
845 845
             <span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
846 846
                 ' . $registration->pretty_paid() . '
847 847
             </span>';
848
-        if ($registration->paid() > 0) {
849
-            $content .= '<span class="ee-status-text-small">'
850
-                        . sprintf(
851
-                            esc_html__('...via %s', 'event_espresso'),
852
-                            $payment_method_name
853
-                        )
854
-                        . '</span>';
855
-        }
856
-        return $this->columnContent('_REG_paid', $content, 'end');
857
-    }
858
-
859
-
860
-    /**
861
-     * @param EE_Registration $registration
862
-     * @return string
863
-     * @throws EE_Error
864
-     * @throws EntityNotFoundException
865
-     * @throws InvalidArgumentException
866
-     * @throws InvalidDataTypeException
867
-     * @throws InvalidInterfaceException
868
-     * @throws ReflectionException
869
-     */
870
-    public function column_TXN_total(EE_Registration $registration)
871
-    {
872
-        if ($registration->transaction()) {
873
-            $view_txn_link_url = EE_Admin_Page::add_query_args_and_nonce(
874
-                [
875
-                    'action' => 'view_transaction',
876
-                    'TXN_ID' => $registration->transaction_ID(),
877
-                ],
878
-                TXN_ADMIN_URL
879
-            );
880
-            $content = EE_Registry::instance()->CAP->current_user_can(
881
-                'ee_read_transaction',
882
-                'espresso_transactions_view_transaction',
883
-                $registration->transaction_ID()
884
-            )
885
-                ? '
848
+		if ($registration->paid() > 0) {
849
+			$content .= '<span class="ee-status-text-small">'
850
+						. sprintf(
851
+							esc_html__('...via %s', 'event_espresso'),
852
+							$payment_method_name
853
+						)
854
+						. '</span>';
855
+		}
856
+		return $this->columnContent('_REG_paid', $content, 'end');
857
+	}
858
+
859
+
860
+	/**
861
+	 * @param EE_Registration $registration
862
+	 * @return string
863
+	 * @throws EE_Error
864
+	 * @throws EntityNotFoundException
865
+	 * @throws InvalidArgumentException
866
+	 * @throws InvalidDataTypeException
867
+	 * @throws InvalidInterfaceException
868
+	 * @throws ReflectionException
869
+	 */
870
+	public function column_TXN_total(EE_Registration $registration)
871
+	{
872
+		if ($registration->transaction()) {
873
+			$view_txn_link_url = EE_Admin_Page::add_query_args_and_nonce(
874
+				[
875
+					'action' => 'view_transaction',
876
+					'TXN_ID' => $registration->transaction_ID(),
877
+				],
878
+				TXN_ADMIN_URL
879
+			);
880
+			$content = EE_Registry::instance()->CAP->current_user_can(
881
+				'ee_read_transaction',
882
+				'espresso_transactions_view_transaction',
883
+				$registration->transaction_ID()
884
+			)
885
+				? '
886 886
                     <a class="ee-aria-tooltip ee-status-color--' . $registration->transaction()->status_ID() . '" 
887 887
                         href="' . $view_txn_link_url . '" 
888 888
                         aria-label="' . esc_attr__('View Transaction', 'event_espresso') . '"
889 889
                     >
890 890
                         ' . $registration->transaction()->pretty_total() . '
891 891
                     </a>'
892
-                : $registration->transaction()->pretty_total();
893
-        } else {
894
-            $content = esc_html__("None", "event_espresso");
895
-        }
896
-        return $this->columnContent('TXN_total', $content, 'end');
897
-    }
898
-
899
-
900
-    /**
901
-     * @param EE_Registration $registration
902
-     * @return string
903
-     * @throws EE_Error
904
-     * @throws EntityNotFoundException
905
-     * @throws InvalidArgumentException
906
-     * @throws InvalidDataTypeException
907
-     * @throws InvalidInterfaceException
908
-     * @throws ReflectionException
909
-     */
910
-    public function column_TXN_paid(EE_Registration $registration)
911
-    {
912
-        $content = '&nbsp;';
913
-        $align = 'end';
914
-        if ($registration->count() === 1) {
915
-            $transaction = $registration->transaction()
916
-                ? $registration->transaction()
917
-                : EE_Transaction::new_instance();
918
-            if ($transaction->paid() >= $transaction->total()) {
919
-                $align = 'center';
920
-                $content = '<span class="dashicons dashicons-yes green-icon"></span>';
921
-            } else {
922
-                $view_txn_link_url = EE_Admin_Page::add_query_args_and_nonce(
923
-                    [
924
-                        'action' => 'view_transaction',
925
-                        'TXN_ID' => $registration->transaction_ID(),
926
-                    ],
927
-                    TXN_ADMIN_URL
928
-                );
929
-                $content = EE_Registry::instance()->CAP->current_user_can(
930
-                    'ee_read_transaction',
931
-                    'espresso_transactions_view_transaction',
932
-                    $registration->transaction_ID()
933
-                )
934
-                    ? '
892
+				: $registration->transaction()->pretty_total();
893
+		} else {
894
+			$content = esc_html__("None", "event_espresso");
895
+		}
896
+		return $this->columnContent('TXN_total', $content, 'end');
897
+	}
898
+
899
+
900
+	/**
901
+	 * @param EE_Registration $registration
902
+	 * @return string
903
+	 * @throws EE_Error
904
+	 * @throws EntityNotFoundException
905
+	 * @throws InvalidArgumentException
906
+	 * @throws InvalidDataTypeException
907
+	 * @throws InvalidInterfaceException
908
+	 * @throws ReflectionException
909
+	 */
910
+	public function column_TXN_paid(EE_Registration $registration)
911
+	{
912
+		$content = '&nbsp;';
913
+		$align = 'end';
914
+		if ($registration->count() === 1) {
915
+			$transaction = $registration->transaction()
916
+				? $registration->transaction()
917
+				: EE_Transaction::new_instance();
918
+			if ($transaction->paid() >= $transaction->total()) {
919
+				$align = 'center';
920
+				$content = '<span class="dashicons dashicons-yes green-icon"></span>';
921
+			} else {
922
+				$view_txn_link_url = EE_Admin_Page::add_query_args_and_nonce(
923
+					[
924
+						'action' => 'view_transaction',
925
+						'TXN_ID' => $registration->transaction_ID(),
926
+					],
927
+					TXN_ADMIN_URL
928
+				);
929
+				$content = EE_Registry::instance()->CAP->current_user_can(
930
+					'ee_read_transaction',
931
+					'espresso_transactions_view_transaction',
932
+					$registration->transaction_ID()
933
+				)
934
+					? '
935 935
                     <a class="ee-aria-tooltip ee-status-color--' . $transaction->status_ID() . '" 
936 936
                         href="' . $view_txn_link_url . '"  
937 937
                         aria-label="' . esc_attr__('View Transaction', 'event_espresso') . '"
938 938
                     >
939 939
                         ' . $registration->transaction()->pretty_paid() . '
940 940
                     </a>'
941
-                    :  $registration->transaction()->pretty_paid();
942
-            }
943
-        }
944
-        return $this->columnContent('TXN_paid', $content, $align);
945
-    }
946
-
947
-
948
-    /**
949
-     * @param EE_Registration $registration
950
-     * @return string
951
-     * @throws EE_Error
952
-     * @throws InvalidArgumentException
953
-     * @throws InvalidDataTypeException
954
-     * @throws InvalidInterfaceException
955
-     * @throws ReflectionException
956
-     */
957
-    public function column_actions(EE_Registration $registration)
958
-    {
959
-        $actions  = [];
960
-        $attendee = $registration->attendee();
961
-        $this->_set_related_details($registration);
962
-
963
-        // Build row actions
964
-        if (
965
-            EE_Registry::instance()->CAP->current_user_can(
966
-                'ee_read_registration',
967
-                'espresso_registrations_view_registration',
968
-                $registration->ID()
969
-            )
970
-        ) {
971
-            $view_link_url = EE_Admin_Page::add_query_args_and_nonce(
972
-                [
973
-                    'action'  => 'view_registration',
974
-                    '_REG_ID' => $registration->ID(),
975
-                ],
976
-                REG_ADMIN_URL
977
-            );
978
-            $actions['view_lnk'] = '
941
+					:  $registration->transaction()->pretty_paid();
942
+			}
943
+		}
944
+		return $this->columnContent('TXN_paid', $content, $align);
945
+	}
946
+
947
+
948
+	/**
949
+	 * @param EE_Registration $registration
950
+	 * @return string
951
+	 * @throws EE_Error
952
+	 * @throws InvalidArgumentException
953
+	 * @throws InvalidDataTypeException
954
+	 * @throws InvalidInterfaceException
955
+	 * @throws ReflectionException
956
+	 */
957
+	public function column_actions(EE_Registration $registration)
958
+	{
959
+		$actions  = [];
960
+		$attendee = $registration->attendee();
961
+		$this->_set_related_details($registration);
962
+
963
+		// Build row actions
964
+		if (
965
+			EE_Registry::instance()->CAP->current_user_can(
966
+				'ee_read_registration',
967
+				'espresso_registrations_view_registration',
968
+				$registration->ID()
969
+			)
970
+		) {
971
+			$view_link_url = EE_Admin_Page::add_query_args_and_nonce(
972
+				[
973
+					'action'  => 'view_registration',
974
+					'_REG_ID' => $registration->ID(),
975
+				],
976
+				REG_ADMIN_URL
977
+			);
978
+			$actions['view_lnk'] = '
979 979
                 <a href="' . $view_link_url . '" aria-label="'
980
-                . esc_attr__('View Registration Details', 'event_espresso')
981
-                . '" class="ee-aria-tooltip button button--icon-only">
980
+				. esc_attr__('View Registration Details', 'event_espresso')
981
+				. '" class="ee-aria-tooltip button button--icon-only">
982 982
 				    <span class="dashicons dashicons-clipboard"></span>
983 983
 			    </a>';
984
-        }
985
-
986
-        if (
987
-            $attendee instanceof EE_Attendee
988
-            && EE_Registry::instance()->CAP->current_user_can(
989
-                'ee_edit_contacts',
990
-                'espresso_registrations_edit_attendee'
991
-            )
992
-        ) {
993
-            $edit_link_url = EE_Admin_Page::add_query_args_and_nonce(
994
-                [
995
-                    'action' => 'edit_attendee',
996
-                    'post'   => $registration->attendee_ID(),
997
-                ],
998
-                REG_ADMIN_URL
999
-            );
1000
-            $actions['edit_lnk'] = '
984
+		}
985
+
986
+		if (
987
+			$attendee instanceof EE_Attendee
988
+			&& EE_Registry::instance()->CAP->current_user_can(
989
+				'ee_edit_contacts',
990
+				'espresso_registrations_edit_attendee'
991
+			)
992
+		) {
993
+			$edit_link_url = EE_Admin_Page::add_query_args_and_nonce(
994
+				[
995
+					'action' => 'edit_attendee',
996
+					'post'   => $registration->attendee_ID(),
997
+				],
998
+				REG_ADMIN_URL
999
+			);
1000
+			$actions['edit_lnk'] = '
1001 1001
                 <a href="' . $edit_link_url . '" 
1002 1002
                    aria-label="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" 
1003 1003
                    class="ee-aria-tooltip button button--secondary button--icon-only"
1004 1004
                 >
1005 1005
                     <span class="dashicons dashicons-admin-users"></span>
1006 1006
                 </a>';
1007
-        }
1008
-
1009
-        if (
1010
-            $attendee instanceof EE_Attendee
1011
-            && EE_Registry::instance()->CAP->current_user_can(
1012
-                'ee_send_message',
1013
-                'espresso_registrations_resend_registration',
1014
-                $registration->ID()
1015
-            )
1016
-        ) {
1017
-            $resend_reg_link_url = EE_Admin_Page::add_query_args_and_nonce(
1018
-                [
1019
-                    'action'  => 'resend_registration',
1020
-                    '_REG_ID' => $registration->ID(),
1021
-                ],
1022
-                REG_ADMIN_URL,
1023
-                true
1024
-            );
1025
-            $actions['resend_reg_lnk'] = '
1007
+		}
1008
+
1009
+		if (
1010
+			$attendee instanceof EE_Attendee
1011
+			&& EE_Registry::instance()->CAP->current_user_can(
1012
+				'ee_send_message',
1013
+				'espresso_registrations_resend_registration',
1014
+				$registration->ID()
1015
+			)
1016
+		) {
1017
+			$resend_reg_link_url = EE_Admin_Page::add_query_args_and_nonce(
1018
+				[
1019
+					'action'  => 'resend_registration',
1020
+					'_REG_ID' => $registration->ID(),
1021
+				],
1022
+				REG_ADMIN_URL,
1023
+				true
1024
+			);
1025
+			$actions['resend_reg_lnk'] = '
1026 1026
 			    <a href="' . $resend_reg_link_url . '" aria-label="'
1027
-                . esc_attr__('Resend Registration Details', 'event_espresso')
1028
-                . '" class="ee-aria-tooltip button button--icon-only">
1027
+				. esc_attr__('Resend Registration Details', 'event_espresso')
1028
+				. '" class="ee-aria-tooltip button button--icon-only">
1029 1029
 			        <span class="dashicons dashicons-email-alt"></span>
1030 1030
 			    </a>';
1031
-        }
1032
-
1033
-        if (
1034
-            EE_Registry::instance()->CAP->current_user_can(
1035
-                'ee_read_transaction',
1036
-                'espresso_transactions_view_transaction',
1037
-                $this->_transaction_details['id']
1038
-            )
1039
-        ) {
1040
-            $view_txn_link_url        = EE_Admin_Page::add_query_args_and_nonce(
1041
-                [
1042
-                    'action' => 'view_transaction',
1043
-                    'TXN_ID' => $this->_transaction_details['id'],
1044
-                ],
1045
-                TXN_ADMIN_URL
1046
-            );
1047
-            $actions['view_txn_lnk'] = '
1031
+		}
1032
+
1033
+		if (
1034
+			EE_Registry::instance()->CAP->current_user_can(
1035
+				'ee_read_transaction',
1036
+				'espresso_transactions_view_transaction',
1037
+				$this->_transaction_details['id']
1038
+			)
1039
+		) {
1040
+			$view_txn_link_url        = EE_Admin_Page::add_query_args_and_nonce(
1041
+				[
1042
+					'action' => 'view_transaction',
1043
+					'TXN_ID' => $this->_transaction_details['id'],
1044
+				],
1045
+				TXN_ADMIN_URL
1046
+			);
1047
+			$actions['view_txn_lnk'] = '
1048 1048
                 <a class="ee-aria-tooltip button button--icon-only" 
1049 1049
                    href="' . $view_txn_link_url . '"  
1050 1050
                    aria-label="' . $this->_transaction_details['title_attr'] . '"
1051 1051
                 >
1052 1052
                     <span class="dashicons dashicons-cart"></span>
1053 1053
                 </a>';
1054
-        }
1055
-
1056
-        // only show invoice link if message type is active.
1057
-        if (
1058
-            $attendee instanceof EE_Attendee
1059
-            && $registration->is_primary_registrant()
1060
-            && EEH_MSG_Template::is_mt_active('invoice')
1061
-        ) {
1062
-            $actions['dl_invoice_lnk'] = '
1054
+		}
1055
+
1056
+		// only show invoice link if message type is active.
1057
+		if (
1058
+			$attendee instanceof EE_Attendee
1059
+			&& $registration->is_primary_registrant()
1060
+			&& EEH_MSG_Template::is_mt_active('invoice')
1061
+		) {
1062
+			$actions['dl_invoice_lnk'] = '
1063 1063
                 <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso')
1064
-                . '" target="_blank" href="' . $registration->invoice_url() . '" class="ee-aria-tooltip button button--icon-only">
1064
+				. '" target="_blank" href="' . $registration->invoice_url() . '" class="ee-aria-tooltip button button--icon-only">
1065 1065
                     <span class="dashicons dashicons-media-spreadsheet"></span>
1066 1066
                 </a>';
1067
-        }
1067
+		}
1068 1068
 
1069
-        // message list table link (filtered by REG_ID
1070
-        if (
1071
-            EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')
1072
-        ) {
1073
-            $actions['filtered_messages_link'] = '
1069
+		// message list table link (filtered by REG_ID
1070
+		if (
1071
+			EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')
1072
+		) {
1073
+			$actions['filtered_messages_link'] = '
1074 1074
                 ' . EEH_MSG_Template::get_message_action_link(
1075
-                'see_notifications_for',
1076
-                null,
1077
-                ['_REG_ID' => $registration->ID()]
1078
-            );
1079
-        }
1080
-
1081
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $registration, $this);
1082
-        $content = $this->_action_string(
1083
-            implode('', $actions),
1084
-            $registration,
1085
-            'div',
1086
-            'reg-overview-actions ee-list-table-actions'
1087
-        );
1088
-        return $this->columnContent('actions', $this->actionsModalMenu($content));
1089
-    }
1075
+				'see_notifications_for',
1076
+				null,
1077
+				['_REG_ID' => $registration->ID()]
1078
+			);
1079
+		}
1080
+
1081
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $registration, $this);
1082
+		$content = $this->_action_string(
1083
+			implode('', $actions),
1084
+			$registration,
1085
+			'div',
1086
+			'reg-overview-actions ee-list-table-actions'
1087
+		);
1088
+		return $this->columnContent('actions', $this->actionsModalMenu($content));
1089
+	}
1090 1090
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Event.class.php 2 patches
Indentation   +1529 added lines, -1529 removed lines patch added patch discarded remove patch
@@ -16,1533 +16,1533 @@
 block discarded – undo
16 16
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
17 17
 {
18 18
 
19
-    /**
20
-     * cached value for the the logical active status for the event
21
-     *
22
-     * @see get_active_status()
23
-     * @var string
24
-     */
25
-    protected $_active_status = '';
26
-
27
-    /**
28
-     * This is just used for caching the Primary Datetime for the Event on initial retrieval
29
-     *
30
-     * @var EE_Datetime
31
-     */
32
-    protected $_Primary_Datetime;
33
-
34
-    /**
35
-     * @var EventSpacesCalculator $available_spaces_calculator
36
-     */
37
-    protected $available_spaces_calculator;
38
-
39
-
40
-    /**
41
-     * @param array  $props_n_values          incoming values
42
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
43
-     *                                        used.)
44
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
45
-     *                                        date_format and the second value is the time format
46
-     * @return EE_Event
47
-     * @throws EE_Error
48
-     * @throws ReflectionException
49
-     */
50
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
51
-    {
52
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
53
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
54
-    }
55
-
56
-
57
-    /**
58
-     * @param array  $props_n_values  incoming values from the database
59
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
60
-     *                                the website will be used.
61
-     * @return EE_Event
62
-     * @throws EE_Error
63
-     * @throws ReflectionException
64
-     */
65
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
66
-    {
67
-        return new self($props_n_values, true, $timezone);
68
-    }
69
-
70
-
71
-    /**
72
-     * @return EventSpacesCalculator
73
-     * @throws \EE_Error
74
-     */
75
-    public function getAvailableSpacesCalculator()
76
-    {
77
-        if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
78
-            $this->available_spaces_calculator = new EventSpacesCalculator($this);
79
-        }
80
-        return $this->available_spaces_calculator;
81
-    }
82
-
83
-
84
-    /**
85
-     * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
86
-     *
87
-     * @param string $field_name
88
-     * @param mixed  $field_value
89
-     * @param bool   $use_default
90
-     * @throws EE_Error
91
-     * @throws ReflectionException
92
-     */
93
-    public function set($field_name, $field_value, $use_default = false)
94
-    {
95
-        switch ($field_name) {
96
-            case 'status':
97
-                $this->set_status($field_value, $use_default);
98
-                break;
99
-            default:
100
-                parent::set($field_name, $field_value, $use_default);
101
-        }
102
-    }
103
-
104
-
105
-    /**
106
-     *    set_status
107
-     * Checks if event status is being changed to SOLD OUT
108
-     * and updates event meta data with previous event status
109
-     * so that we can revert things if/when the event is no longer sold out
110
-     *
111
-     * @access public
112
-     * @param string $new_status
113
-     * @param bool   $use_default
114
-     * @return void
115
-     * @throws EE_Error
116
-     * @throws ReflectionException
117
-     */
118
-    public function set_status($new_status = null, $use_default = false)
119
-    {
120
-        // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
121
-        if (empty($new_status) && ! $use_default) {
122
-            return;
123
-        }
124
-        // get current Event status
125
-        $old_status = $this->status();
126
-        // if status has changed
127
-        if ($old_status !== $new_status) {
128
-            // TO sold_out
129
-            if ($new_status === EEM_Event::sold_out) {
130
-                // save the previous event status so that we can revert if the event is no longer sold out
131
-                $this->add_post_meta('_previous_event_status', $old_status);
132
-                do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
133
-            // OR FROM  sold_out
134
-            } elseif ($old_status === EEM_Event::sold_out) {
135
-                $this->delete_post_meta('_previous_event_status');
136
-                do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
137
-            }
138
-            // clear out the active status so that it gets reset the next time it is requested
139
-            $this->_active_status = null;
140
-            // update status
141
-            parent::set('status', $new_status, $use_default);
142
-            do_action('AHEE__EE_Event__set_status__after_update', $this);
143
-            return;
144
-        }
145
-        // even though the old value matches the new value, it's still good to
146
-        // allow the parent set method to have a say
147
-        parent::set('status', $new_status, $use_default);
148
-    }
149
-
150
-
151
-    /**
152
-     * Gets all the datetimes for this event
153
-     *
154
-     * @param array $query_params @see
155
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
156
-     * @return EE_Base_Class[]|EE_Datetime[]
157
-     * @throws EE_Error
158
-     * @throws ReflectionException
159
-     */
160
-    public function datetimes($query_params = array())
161
-    {
162
-        return $this->get_many_related('Datetime', $query_params);
163
-    }
164
-
165
-
166
-    /**
167
-     * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
168
-     *
169
-     * @return EE_Base_Class[]|EE_Datetime[]
170
-     * @throws EE_Error
171
-     * @throws ReflectionException
172
-     */
173
-    public function datetimes_in_chronological_order()
174
-    {
175
-        return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
176
-    }
177
-
178
-
179
-    /**
180
-     * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
181
-     * @darren, we should probably UNSET timezone on the EEM_Datetime model
182
-     * after running our query, so that this timezone isn't set for EVERY query
183
-     * on EEM_Datetime for the rest of the request, no?
184
-     *
185
-     * @param boolean $show_expired whether or not to include expired events
186
-     * @param boolean $show_deleted whether or not to include deleted events
187
-     * @param null    $limit
188
-     * @return EE_Datetime[]
189
-     * @throws EE_Error
190
-     * @throws ReflectionException
191
-     */
192
-    public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
193
-    {
194
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
195
-            $this->ID(),
196
-            $show_expired,
197
-            $show_deleted,
198
-            $limit
199
-        );
200
-    }
201
-
202
-
203
-    /**
204
-     * Returns one related datetime. Mostly only used by some legacy code.
205
-     *
206
-     * @return EE_Base_Class|EE_Datetime
207
-     * @throws EE_Error
208
-     * @throws ReflectionException
209
-     */
210
-    public function first_datetime()
211
-    {
212
-        return $this->get_first_related('Datetime');
213
-    }
214
-
215
-
216
-    /**
217
-     * Returns the 'primary' datetime for the event
218
-     *
219
-     * @param bool $try_to_exclude_expired
220
-     * @param bool $try_to_exclude_deleted
221
-     * @return EE_Datetime
222
-     * @throws EE_Error
223
-     * @throws ReflectionException
224
-     */
225
-    public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
226
-    {
227
-        if (! empty($this->_Primary_Datetime)) {
228
-            return $this->_Primary_Datetime;
229
-        }
230
-        $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
231
-            $this->ID(),
232
-            $try_to_exclude_expired,
233
-            $try_to_exclude_deleted
234
-        );
235
-        return $this->_Primary_Datetime;
236
-    }
237
-
238
-
239
-    /**
240
-     * Gets all the tickets available for purchase of this event
241
-     *
242
-     * @param array $query_params @see
243
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
244
-     * @return EE_Base_Class[]|EE_Ticket[]
245
-     * @throws EE_Error
246
-     * @throws ReflectionException
247
-     */
248
-    public function tickets($query_params = array())
249
-    {
250
-        // first get all datetimes
251
-        $datetimes = $this->datetimes_ordered();
252
-        if (! $datetimes) {
253
-            return array();
254
-        }
255
-        $datetime_ids = array();
256
-        foreach ($datetimes as $datetime) {
257
-            $datetime_ids[] = $datetime->ID();
258
-        }
259
-        $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
260
-        // if incoming $query_params has where conditions let's merge but not override existing.
261
-        if (is_array($query_params) && isset($query_params[0])) {
262
-            $where_params = array_merge($query_params[0], $where_params);
263
-            unset($query_params[0]);
264
-        }
265
-        // now add $where_params to $query_params
266
-        $query_params[0] = $where_params;
267
-        return EEM_Ticket::instance()->get_all($query_params);
268
-    }
269
-
270
-
271
-    /**
272
-     * get all unexpired untrashed tickets
273
-     *
274
-     * @return EE_Ticket[]
275
-     * @throws EE_Error
276
-     */
277
-    public function active_tickets()
278
-    {
279
-        return $this->tickets(
280
-            array(
281
-                array(
282
-                    'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
283
-                    'TKT_deleted'  => false,
284
-                ),
285
-            )
286
-        );
287
-    }
288
-
289
-
290
-    /**
291
-     * @return bool
292
-     * @throws EE_Error
293
-     * @throws ReflectionException
294
-     */
295
-    public function additional_limit()
296
-    {
297
-        return $this->get('EVT_additional_limit');
298
-    }
299
-
300
-
301
-    /**
302
-     * @return bool
303
-     * @throws EE_Error
304
-     * @throws ReflectionException
305
-     */
306
-    public function allow_overflow()
307
-    {
308
-        return $this->get('EVT_allow_overflow');
309
-    }
310
-
311
-
312
-    /**
313
-     * @return bool
314
-     * @throws EE_Error
315
-     * @throws ReflectionException
316
-     */
317
-    public function created()
318
-    {
319
-        return $this->get('EVT_created');
320
-    }
321
-
322
-
323
-    /**
324
-     * @return bool
325
-     * @throws EE_Error
326
-     * @throws ReflectionException
327
-     */
328
-    public function description()
329
-    {
330
-        return $this->get('EVT_desc');
331
-    }
332
-
333
-
334
-    /**
335
-     * Runs do_shortcode and wpautop on the description
336
-     *
337
-     * @return string of html
338
-     * @throws EE_Error
339
-     * @throws ReflectionException
340
-     */
341
-    public function description_filtered()
342
-    {
343
-        return $this->get_pretty('EVT_desc');
344
-    }
345
-
346
-
347
-    /**
348
-     * @return bool
349
-     * @throws EE_Error
350
-     * @throws ReflectionException
351
-     */
352
-    public function display_description()
353
-    {
354
-        return $this->get('EVT_display_desc');
355
-    }
356
-
357
-
358
-    /**
359
-     * @return bool
360
-     * @throws EE_Error
361
-     * @throws ReflectionException
362
-     */
363
-    public function display_ticket_selector()
364
-    {
365
-        return (bool) $this->get('EVT_display_ticket_selector');
366
-    }
367
-
368
-
369
-    /**
370
-     * @return string
371
-     * @throws EE_Error
372
-     * @throws ReflectionException
373
-     */
374
-    public function external_url()
375
-    {
376
-        return $this->get('EVT_external_URL');
377
-    }
378
-
379
-
380
-    /**
381
-     * @return bool
382
-     * @throws EE_Error
383
-     * @throws ReflectionException
384
-     */
385
-    public function member_only()
386
-    {
387
-        return $this->get('EVT_member_only');
388
-    }
389
-
390
-
391
-    /**
392
-     * @return bool
393
-     * @throws EE_Error
394
-     * @throws ReflectionException
395
-     */
396
-    public function phone()
397
-    {
398
-        return $this->get('EVT_phone');
399
-    }
400
-
401
-
402
-    /**
403
-     * @return bool
404
-     * @throws EE_Error
405
-     * @throws ReflectionException
406
-     */
407
-    public function modified()
408
-    {
409
-        return $this->get('EVT_modified');
410
-    }
411
-
412
-
413
-    /**
414
-     * @return bool
415
-     * @throws EE_Error
416
-     * @throws ReflectionException
417
-     */
418
-    public function name()
419
-    {
420
-        return $this->get('EVT_name');
421
-    }
422
-
423
-
424
-    /**
425
-     * @return bool
426
-     * @throws EE_Error
427
-     * @throws ReflectionException
428
-     */
429
-    public function order()
430
-    {
431
-        return $this->get('EVT_order');
432
-    }
433
-
434
-
435
-    /**
436
-     * @return bool|string
437
-     * @throws EE_Error
438
-     * @throws ReflectionException
439
-     */
440
-    public function default_registration_status()
441
-    {
442
-        $event_default_registration_status = $this->get('EVT_default_registration_status');
443
-        return ! empty($event_default_registration_status)
444
-            ? $event_default_registration_status
445
-            : EE_Registry::instance()->CFG->registration->default_STS_ID;
446
-    }
447
-
448
-
449
-    /**
450
-     * @param int  $num_words
451
-     * @param null $more
452
-     * @param bool $not_full_desc
453
-     * @return bool|string
454
-     * @throws EE_Error
455
-     * @throws ReflectionException
456
-     */
457
-    public function short_description($num_words = 55, $more = null, $not_full_desc = false)
458
-    {
459
-        $short_desc = $this->get('EVT_short_desc');
460
-        if (! empty($short_desc) || $not_full_desc) {
461
-            return $short_desc;
462
-        }
463
-        $full_desc = $this->get('EVT_desc');
464
-        return wp_trim_words($full_desc, $num_words, $more);
465
-    }
466
-
467
-
468
-    /**
469
-     * @return bool
470
-     * @throws EE_Error
471
-     * @throws ReflectionException
472
-     */
473
-    public function slug()
474
-    {
475
-        return $this->get('EVT_slug');
476
-    }
477
-
478
-
479
-    /**
480
-     * @return bool
481
-     * @throws EE_Error
482
-     * @throws ReflectionException
483
-     */
484
-    public function timezone_string()
485
-    {
486
-        return $this->get('EVT_timezone_string');
487
-    }
488
-
489
-
490
-    /**
491
-     * @return bool
492
-     * @throws EE_Error
493
-     * @throws ReflectionException
494
-     */
495
-    public function visible_on()
496
-    {
497
-        return $this->get('EVT_visible_on');
498
-    }
499
-
500
-
501
-    /**
502
-     * @return int
503
-     * @throws EE_Error
504
-     * @throws ReflectionException
505
-     */
506
-    public function wp_user()
507
-    {
508
-        return $this->get('EVT_wp_user');
509
-    }
510
-
511
-
512
-    /**
513
-     * @return bool
514
-     * @throws EE_Error
515
-     * @throws ReflectionException
516
-     */
517
-    public function donations()
518
-    {
519
-        return $this->get('EVT_donations');
520
-    }
521
-
522
-
523
-    /**
524
-     * @param $limit
525
-     * @throws EE_Error
526
-     */
527
-    public function set_additional_limit($limit)
528
-    {
529
-        $this->set('EVT_additional_limit', $limit);
530
-    }
531
-
532
-
533
-    /**
534
-     * @param $created
535
-     * @throws EE_Error
536
-     */
537
-    public function set_created($created)
538
-    {
539
-        $this->set('EVT_created', $created);
540
-    }
541
-
542
-
543
-    /**
544
-     * @param $desc
545
-     * @throws EE_Error
546
-     */
547
-    public function set_description($desc)
548
-    {
549
-        $this->set('EVT_desc', $desc);
550
-    }
551
-
552
-
553
-    /**
554
-     * @param $display_desc
555
-     * @throws EE_Error
556
-     */
557
-    public function set_display_description($display_desc)
558
-    {
559
-        $this->set('EVT_display_desc', $display_desc);
560
-    }
561
-
562
-
563
-    /**
564
-     * @param $display_ticket_selector
565
-     * @throws EE_Error
566
-     */
567
-    public function set_display_ticket_selector($display_ticket_selector)
568
-    {
569
-        $this->set('EVT_display_ticket_selector', $display_ticket_selector);
570
-    }
571
-
572
-
573
-    /**
574
-     * @param $external_url
575
-     * @throws EE_Error
576
-     */
577
-    public function set_external_url($external_url)
578
-    {
579
-        $this->set('EVT_external_URL', $external_url);
580
-    }
581
-
582
-
583
-    /**
584
-     * @param $member_only
585
-     * @throws EE_Error
586
-     */
587
-    public function set_member_only($member_only)
588
-    {
589
-        $this->set('EVT_member_only', $member_only);
590
-    }
591
-
592
-
593
-    /**
594
-     * @param $event_phone
595
-     * @throws EE_Error
596
-     */
597
-    public function set_event_phone($event_phone)
598
-    {
599
-        $this->set('EVT_phone', $event_phone);
600
-    }
601
-
602
-
603
-    /**
604
-     * @param $modified
605
-     * @throws EE_Error
606
-     */
607
-    public function set_modified($modified)
608
-    {
609
-        $this->set('EVT_modified', $modified);
610
-    }
611
-
612
-
613
-    /**
614
-     * @param $name
615
-     * @throws EE_Error
616
-     */
617
-    public function set_name($name)
618
-    {
619
-        $this->set('EVT_name', $name);
620
-    }
621
-
622
-
623
-    /**
624
-     * @param $order
625
-     * @throws EE_Error
626
-     */
627
-    public function set_order($order)
628
-    {
629
-        $this->set('EVT_order', $order);
630
-    }
631
-
632
-
633
-    /**
634
-     * @param $short_desc
635
-     * @throws EE_Error
636
-     */
637
-    public function set_short_description($short_desc)
638
-    {
639
-        $this->set('EVT_short_desc', $short_desc);
640
-    }
641
-
642
-
643
-    /**
644
-     * @param $slug
645
-     * @throws EE_Error
646
-     */
647
-    public function set_slug($slug)
648
-    {
649
-        $this->set('EVT_slug', $slug);
650
-    }
651
-
652
-
653
-    /**
654
-     * @param $timezone_string
655
-     * @throws EE_Error
656
-     */
657
-    public function set_timezone_string($timezone_string)
658
-    {
659
-        $this->set('EVT_timezone_string', $timezone_string);
660
-    }
661
-
662
-
663
-    /**
664
-     * @param $visible_on
665
-     * @throws EE_Error
666
-     */
667
-    public function set_visible_on($visible_on)
668
-    {
669
-        $this->set('EVT_visible_on', $visible_on);
670
-    }
671
-
672
-
673
-    /**
674
-     * @param $wp_user
675
-     * @throws EE_Error
676
-     */
677
-    public function set_wp_user($wp_user)
678
-    {
679
-        $this->set('EVT_wp_user', $wp_user);
680
-    }
681
-
682
-
683
-    /**
684
-     * @param $default_registration_status
685
-     * @throws EE_Error
686
-     */
687
-    public function set_default_registration_status($default_registration_status)
688
-    {
689
-        $this->set('EVT_default_registration_status', $default_registration_status);
690
-    }
691
-
692
-
693
-    /**
694
-     * @param $donations
695
-     * @throws EE_Error
696
-     */
697
-    public function set_donations($donations)
698
-    {
699
-        $this->set('EVT_donations', $donations);
700
-    }
701
-
702
-
703
-    /**
704
-     * Adds a venue to this event
705
-     *
706
-     * @param int|EE_Venue /int $venue_id_or_obj
707
-     * @return EE_Base_Class|EE_Venue
708
-     * @throws EE_Error
709
-     * @throws ReflectionException
710
-     */
711
-    public function add_venue($venue_id_or_obj): EE_Venue
712
-    {
713
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
714
-    }
715
-
716
-
717
-    /**
718
-     * Removes a venue from the event
719
-     *
720
-     * @param EE_Venue /int $venue_id_or_obj
721
-     * @return EE_Base_Class|EE_Venue
722
-     * @throws EE_Error
723
-     * @throws ReflectionException
724
-     */
725
-    public function remove_venue($venue_id_or_obj): EE_Venue
726
-    {
727
-        $venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue();
728
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
729
-    }
730
-
731
-
732
-    /**
733
-     * Gets the venue related to the event. May provide additional $query_params if desired
734
-     *
735
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
736
-     * @return int
737
-     * @throws EE_Error
738
-     * @throws ReflectionException
739
-     */
740
-    public function venue_ID(array $query_params = array()): int
741
-    {
742
-        $venue = $this->get_first_related('Venue', $query_params);
743
-        return $venue instanceof EE_Venue ? $venue->ID() : 0;
744
-    }
745
-
746
-
747
-    /**
748
-     * Gets the venue related to the event. May provide additional $query_params if desired
749
-     *
750
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
751
-     * @return EE_Base_Class|EE_Venue
752
-     * @throws EE_Error
753
-     * @throws ReflectionException
754
-     */
755
-    public function venue(array $query_params = array())
756
-    {
757
-        return $this->get_first_related('Venue', $query_params);
758
-    }
759
-
760
-
761
-    /**
762
-     * @param array $query_params
763
-     * @return EE_Base_Class[]|EE_Venue[]
764
-     * @throws EE_Error
765
-     * @throws ReflectionException
766
-     * @deprecated $VID:$
767
-     */
768
-    public function venues(array $query_params = array()): array
769
-    {
770
-        return [$this->venue($query_params)];
771
-    }
772
-
773
-
774
-    /**
775
-     * check if event id is present and if event is published
776
-     *
777
-     * @access public
778
-     * @return boolean true yes, false no
779
-     * @throws EE_Error
780
-     * @throws ReflectionException
781
-     */
782
-    private function _has_ID_and_is_published()
783
-    {
784
-        // first check if event id is present and not NULL,
785
-        // then check if this event is published (or any of the equivalent "published" statuses)
786
-        return
787
-            $this->ID() && $this->ID() !== null
788
-            && (
789
-                $this->status() === 'publish'
790
-                || $this->status() === EEM_Event::sold_out
791
-                || $this->status() === EEM_Event::postponed
792
-                || $this->status() === EEM_Event::cancelled
793
-            );
794
-    }
795
-
796
-
797
-    /**
798
-     * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
799
-     *
800
-     * @access public
801
-     * @return boolean true yes, false no
802
-     * @throws EE_Error
803
-     * @throws ReflectionException
804
-     */
805
-    public function is_upcoming()
806
-    {
807
-        // check if event id is present and if this event is published
808
-        if ($this->is_inactive()) {
809
-            return false;
810
-        }
811
-        // set initial value
812
-        $upcoming = false;
813
-        // next let's get all datetimes and loop through them
814
-        $datetimes = $this->datetimes_in_chronological_order();
815
-        foreach ($datetimes as $datetime) {
816
-            if ($datetime instanceof EE_Datetime) {
817
-                // if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
818
-                if ($datetime->is_expired()) {
819
-                    continue;
820
-                }
821
-                // if this dtt is active then we return false.
822
-                if ($datetime->is_active()) {
823
-                    return false;
824
-                }
825
-                // otherwise let's check upcoming status
826
-                $upcoming = $datetime->is_upcoming();
827
-            }
828
-        }
829
-        return $upcoming;
830
-    }
831
-
832
-
833
-    /**
834
-     * @return bool
835
-     * @throws EE_Error
836
-     * @throws ReflectionException
837
-     */
838
-    public function is_active()
839
-    {
840
-        // check if event id is present and if this event is published
841
-        if ($this->is_inactive()) {
842
-            return false;
843
-        }
844
-        // set initial value
845
-        $active = false;
846
-        // next let's get all datetimes and loop through them
847
-        $datetimes = $this->datetimes_in_chronological_order();
848
-        foreach ($datetimes as $datetime) {
849
-            if ($datetime instanceof EE_Datetime) {
850
-                // if this dtt is expired then we continue cause one of the other datetimes might be active.
851
-                if ($datetime->is_expired()) {
852
-                    continue;
853
-                }
854
-                // if this dtt is upcoming then we return false.
855
-                if ($datetime->is_upcoming()) {
856
-                    return false;
857
-                }
858
-                // otherwise let's check active status
859
-                $active = $datetime->is_active();
860
-            }
861
-        }
862
-        return $active;
863
-    }
864
-
865
-
866
-    /**
867
-     * @return bool
868
-     * @throws EE_Error
869
-     * @throws ReflectionException
870
-     */
871
-    public function is_expired()
872
-    {
873
-        // check if event id is present and if this event is published
874
-        if ($this->is_inactive()) {
875
-            return false;
876
-        }
877
-        // set initial value
878
-        $expired = false;
879
-        // first let's get all datetimes and loop through them
880
-        $datetimes = $this->datetimes_in_chronological_order();
881
-        foreach ($datetimes as $datetime) {
882
-            if ($datetime instanceof EE_Datetime) {
883
-                // if this dtt is upcoming or active then we return false.
884
-                if ($datetime->is_upcoming() || $datetime->is_active()) {
885
-                    return false;
886
-                }
887
-                // otherwise let's check active status
888
-                $expired = $datetime->is_expired();
889
-            }
890
-        }
891
-        return $expired;
892
-    }
893
-
894
-
895
-    /**
896
-     * @return bool
897
-     * @throws EE_Error
898
-     */
899
-    public function is_inactive()
900
-    {
901
-        // check if event id is present and if this event is published
902
-        if ($this->_has_ID_and_is_published()) {
903
-            return false;
904
-        }
905
-        return true;
906
-    }
907
-
908
-
909
-    /**
910
-     * calculate spaces remaining based on "saleable" tickets
911
-     *
912
-     * @param array $tickets
913
-     * @param bool  $filtered
914
-     * @return int|float
915
-     * @throws EE_Error
916
-     * @throws DomainException
917
-     * @throws UnexpectedEntityException
918
-     */
919
-    public function spaces_remaining($tickets = array(), $filtered = true)
920
-    {
921
-        $this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
922
-        $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
923
-        return $filtered
924
-            ? apply_filters(
925
-                'FHEE_EE_Event__spaces_remaining',
926
-                $spaces_remaining,
927
-                $this,
928
-                $tickets
929
-            )
930
-            : $spaces_remaining;
931
-    }
932
-
933
-
934
-    /**
935
-     *    perform_sold_out_status_check
936
-     *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
937
-     *    available... if NOT, then the event status will get toggled to 'sold_out'
938
-     *
939
-     * @return bool    return the ACTUAL sold out state.
940
-     * @throws EE_Error
941
-     * @throws DomainException
942
-     * @throws UnexpectedEntityException
943
-     * @throws ReflectionException
944
-     */
945
-    public function perform_sold_out_status_check()
946
-    {
947
-        // get all tickets
948
-        $tickets = $this->tickets(
949
-            array(
950
-                'default_where_conditions' => 'none',
951
-                'order_by' => array('TKT_qty' => 'ASC'),
952
-            )
953
-        );
954
-        $all_expired = true;
955
-        foreach ($tickets as $ticket) {
956
-            if (! $ticket->is_expired()) {
957
-                $all_expired = false;
958
-                break;
959
-            }
960
-        }
961
-        // if all the tickets are just expired, then don't update the event status to sold out
962
-        if ($all_expired) {
963
-            return true;
964
-        }
965
-        $spaces_remaining = $this->spaces_remaining($tickets);
966
-        if ($spaces_remaining < 1) {
967
-            if ($this->status() !== EEM_Event::post_status_private) {
968
-                $this->set_status(EEM_Event::sold_out);
969
-                $this->save();
970
-            }
971
-            $sold_out = true;
972
-        } else {
973
-            $sold_out = false;
974
-            // was event previously marked as sold out ?
975
-            if ($this->status() === EEM_Event::sold_out) {
976
-                // revert status to previous value, if it was set
977
-                $previous_event_status = $this->get_post_meta('_previous_event_status', true);
978
-                if ($previous_event_status) {
979
-                    $this->set_status($previous_event_status);
980
-                    $this->save();
981
-                }
982
-            }
983
-        }
984
-        do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
985
-        return $sold_out;
986
-    }
987
-
988
-
989
-    /**
990
-     * This returns the total remaining spaces for sale on this event.
991
-     *
992
-     * @uses EE_Event::total_available_spaces()
993
-     * @return float|int
994
-     * @throws EE_Error
995
-     * @throws DomainException
996
-     * @throws UnexpectedEntityException
997
-     */
998
-    public function spaces_remaining_for_sale()
999
-    {
1000
-        return $this->total_available_spaces(true);
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * This returns the total spaces available for an event
1006
-     * while considering all the qtys on the tickets and the reg limits
1007
-     * on the datetimes attached to this event.
1008
-     *
1009
-     * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
1010
-     *                              If this is false, then we return the most tickets that could ever be sold
1011
-     *                              for this event with the datetime and tickets setup on the event under optimal
1012
-     *                              selling conditions.  Otherwise we return a live calculation of spaces available
1013
-     *                              based on tickets sold.  Depending on setup and stage of sales, this
1014
-     *                              may appear to equal remaining tickets.  However, the more tickets are
1015
-     *                              sold out, the more accurate the "live" total is.
1016
-     * @return float|int
1017
-     * @throws EE_Error
1018
-     * @throws DomainException
1019
-     * @throws UnexpectedEntityException
1020
-     */
1021
-    public function total_available_spaces($consider_sold = false)
1022
-    {
1023
-        $spaces_available = $consider_sold
1024
-            ? $this->getAvailableSpacesCalculator()->spacesRemaining()
1025
-            : $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
1026
-        return apply_filters(
1027
-            'FHEE_EE_Event__total_available_spaces__spaces_available',
1028
-            $spaces_available,
1029
-            $this,
1030
-            $this->getAvailableSpacesCalculator()->getDatetimes(),
1031
-            $this->getAvailableSpacesCalculator()->getActiveTickets()
1032
-        );
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * Checks if the event is set to sold out
1038
-     *
1039
-     * @param  bool $actual whether or not to perform calculations to not only figure the
1040
-     *                      actual status but also to flip the status if necessary to sold
1041
-     *                      out If false, we just check the existing status of the event
1042
-     * @return boolean
1043
-     * @throws EE_Error
1044
-     */
1045
-    public function is_sold_out($actual = false)
1046
-    {
1047
-        if (! $actual) {
1048
-            return $this->status() === EEM_Event::sold_out;
1049
-        }
1050
-        return $this->perform_sold_out_status_check();
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * Checks if the event is marked as postponed
1056
-     *
1057
-     * @return boolean
1058
-     */
1059
-    public function is_postponed()
1060
-    {
1061
-        return $this->status() === EEM_Event::postponed;
1062
-    }
1063
-
1064
-
1065
-    /**
1066
-     * Checks if the event is marked as cancelled
1067
-     *
1068
-     * @return boolean
1069
-     */
1070
-    public function is_cancelled()
1071
-    {
1072
-        return $this->status() === EEM_Event::cancelled;
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * Get the logical active status in a hierarchical order for all the datetimes.  Note
1078
-     * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1079
-     * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1080
-     * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1081
-     * the event is considered expired.
1082
-     * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1083
-     * status set on the EVENT when it is not published and thus is done
1084
-     *
1085
-     * @param bool $reset
1086
-     * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1087
-     * @throws EE_Error
1088
-     * @throws ReflectionException
1089
-     */
1090
-    public function get_active_status($reset = false)
1091
-    {
1092
-        // if the active status has already been set, then just use that value (unless we are resetting it)
1093
-        if (! empty($this->_active_status) && ! $reset) {
1094
-            return $this->_active_status;
1095
-        }
1096
-        // first check if event id is present on this object
1097
-        if (! $this->ID()) {
1098
-            return false;
1099
-        }
1100
-        $where_params_for_event = array(array('EVT_ID' => $this->ID()));
1101
-        // if event is published:
1102
-        if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1103
-            // active?
1104
-            if (
1105
-                EEM_Datetime::instance()->get_datetime_count_for_status(
1106
-                    EE_Datetime::active,
1107
-                    $where_params_for_event
1108
-                ) > 0
1109
-            ) {
1110
-                $this->_active_status = EE_Datetime::active;
1111
-            } else {
1112
-                // upcoming?
1113
-                if (
1114
-                    EEM_Datetime::instance()->get_datetime_count_for_status(
1115
-                        EE_Datetime::upcoming,
1116
-                        $where_params_for_event
1117
-                    ) > 0
1118
-                ) {
1119
-                    $this->_active_status = EE_Datetime::upcoming;
1120
-                } else {
1121
-                    // expired?
1122
-                    if (
1123
-                        EEM_Datetime::instance()->get_datetime_count_for_status(
1124
-                            EE_Datetime::expired,
1125
-                            $where_params_for_event
1126
-                        ) > 0
1127
-                    ) {
1128
-                        $this->_active_status = EE_Datetime::expired;
1129
-                    } else {
1130
-                        // it would be odd if things make it this far because it basically means there are no datetime's
1131
-                        // attached to the event.  So in this case it will just be considered inactive.
1132
-                        $this->_active_status = EE_Datetime::inactive;
1133
-                    }
1134
-                }
1135
-            }
1136
-        } else {
1137
-            // the event is not published, so let's just set it's active status according to its' post status
1138
-            switch ($this->status()) {
1139
-                case EEM_Event::sold_out:
1140
-                    $this->_active_status = EE_Datetime::sold_out;
1141
-                    break;
1142
-                case EEM_Event::cancelled:
1143
-                    $this->_active_status = EE_Datetime::cancelled;
1144
-                    break;
1145
-                case EEM_Event::postponed:
1146
-                    $this->_active_status = EE_Datetime::postponed;
1147
-                    break;
1148
-                default:
1149
-                    $this->_active_status = EE_Datetime::inactive;
1150
-            }
1151
-        }
1152
-        return $this->_active_status;
1153
-    }
1154
-
1155
-
1156
-    /**
1157
-     *    pretty_active_status
1158
-     *
1159
-     * @access public
1160
-     * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1161
-     * @return mixed void|string
1162
-     * @throws EE_Error
1163
-     * @throws ReflectionException
1164
-     */
1165
-    public function pretty_active_status($echo = true)
1166
-    {
1167
-        $active_status = $this->get_active_status();
1168
-        $status = '<span class="ee-status ee-status-bg--' . esc_attr($active_status) . ' event-active-status-' .
1169
-                  esc_attr($active_status) . '">'
1170
-                  . EEH_Template::pretty_status($active_status, false, 'sentence')
1171
-                  . '</span>';
1172
-        if ($echo) {
1173
-            echo $status; // already escaped
1174
-            return '';
1175
-        }
1176
-        return $status; // already escaped
1177
-    }
1178
-
1179
-
1180
-    /**
1181
-     * @return bool|int
1182
-     * @throws EE_Error
1183
-     * @throws ReflectionException
1184
-     */
1185
-    public function get_number_of_tickets_sold()
1186
-    {
1187
-        $tkt_sold = 0;
1188
-        if (! $this->ID()) {
1189
-            return 0;
1190
-        }
1191
-        $datetimes = $this->datetimes();
1192
-        foreach ($datetimes as $datetime) {
1193
-            if ($datetime instanceof EE_Datetime) {
1194
-                $tkt_sold += $datetime->sold();
1195
-            }
1196
-        }
1197
-        return $tkt_sold;
1198
-    }
1199
-
1200
-
1201
-    /**
1202
-     * This just returns a count of all the registrations for this event
1203
-     *
1204
-     * @access  public
1205
-     * @return int
1206
-     * @throws EE_Error
1207
-     */
1208
-    public function get_count_of_all_registrations()
1209
-    {
1210
-        return EEM_Event::instance()->count_related($this, 'Registration');
1211
-    }
1212
-
1213
-
1214
-    /**
1215
-     * This returns the ticket with the earliest start time that is
1216
-     * available for this event (across all datetimes attached to the event)
1217
-     *
1218
-     * @return EE_Base_Class|EE_Ticket|null
1219
-     * @throws EE_Error
1220
-     * @throws ReflectionException
1221
-     */
1222
-    public function get_ticket_with_earliest_start_time()
1223
-    {
1224
-        $where['Datetime.EVT_ID'] = $this->ID();
1225
-        $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1226
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1227
-    }
1228
-
1229
-
1230
-    /**
1231
-     * This returns the ticket with the latest end time that is available
1232
-     * for this event (across all datetimes attached to the event)
1233
-     *
1234
-     * @return EE_Base_Class|EE_Ticket|null
1235
-     * @throws EE_Error
1236
-     * @throws ReflectionException
1237
-     */
1238
-    public function get_ticket_with_latest_end_time()
1239
-    {
1240
-        $where['Datetime.EVT_ID'] = $this->ID();
1241
-        $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1242
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1243
-    }
1244
-
1245
-
1246
-    /**
1247
-     * This returns the number of different ticket types currently on sale for this event.
1248
-     *
1249
-     * @return int
1250
-     * @throws EE_Error
1251
-     * @throws ReflectionException
1252
-     */
1253
-    public function countTicketsOnSale()
1254
-    {
1255
-        $where = array(
1256
-            'Datetime.EVT_ID' => $this->ID(),
1257
-            'TKT_start_date'  => array('<', time()),
1258
-            'TKT_end_date'    => array('>', time()),
1259
-        );
1260
-        return EEM_Ticket::instance()->count(array($where));
1261
-    }
1262
-
1263
-
1264
-    /**
1265
-     * This returns whether there are any tickets on sale for this event.
1266
-     *
1267
-     * @return bool true = YES tickets on sale.
1268
-     * @throws EE_Error
1269
-     */
1270
-    public function tickets_on_sale()
1271
-    {
1272
-        return $this->countTicketsOnSale() > 0;
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * Gets the URL for viewing this event on the front-end. Overrides parent
1278
-     * to check for an external URL first
1279
-     *
1280
-     * @return string
1281
-     * @throws EE_Error
1282
-     */
1283
-    public function get_permalink()
1284
-    {
1285
-        if ($this->external_url()) {
1286
-            return $this->external_url();
1287
-        }
1288
-        return parent::get_permalink();
1289
-    }
1290
-
1291
-
1292
-    /**
1293
-     * Gets the first term for 'espresso_event_categories' we can find
1294
-     *
1295
-     * @param array $query_params @see
1296
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1297
-     * @return EE_Base_Class|EE_Term|null
1298
-     * @throws EE_Error
1299
-     * @throws ReflectionException
1300
-     */
1301
-    public function first_event_category($query_params = array())
1302
-    {
1303
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1304
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1305
-        return EEM_Term::instance()->get_one($query_params);
1306
-    }
1307
-
1308
-
1309
-    /**
1310
-     * Gets all terms for 'espresso_event_categories' we can find
1311
-     *
1312
-     * @param array $query_params
1313
-     * @return EE_Base_Class[]|EE_Term[]
1314
-     * @throws EE_Error
1315
-     * @throws ReflectionException
1316
-     */
1317
-    public function get_all_event_categories($query_params = array())
1318
-    {
1319
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1320
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1321
-        return EEM_Term::instance()->get_all($query_params);
1322
-    }
1323
-
1324
-
1325
-    /**
1326
-     * Adds a question group to this event
1327
-     *
1328
-     * @param EE_Question_Group|int $question_group_id_or_obj
1329
-     * @param bool $for_primary if true, the question group will be added for the primary
1330
-     *                                           registrant, if false will be added for others. default: false
1331
-     * @return EE_Base_Class|EE_Question_Group
1332
-     * @throws EE_Error
1333
-     * @throws InvalidArgumentException
1334
-     * @throws InvalidDataTypeException
1335
-     * @throws InvalidInterfaceException
1336
-     * @throws ReflectionException
1337
-     */
1338
-    public function add_question_group($question_group_id_or_obj, $for_primary = false)
1339
-    {
1340
-        // If the row already exists, it will be updated. If it doesn't, it will be inserted.
1341
-        // That's in EE_HABTM_Relation::add_relation_to().
1342
-        return $this->_add_relation_to(
1343
-            $question_group_id_or_obj,
1344
-            'Question_Group',
1345
-            [
1346
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true
1347
-            ]
1348
-        );
1349
-    }
1350
-
1351
-
1352
-    /**
1353
-     * Removes a question group from the event
1354
-     *
1355
-     * @param EE_Question_Group|int $question_group_id_or_obj
1356
-     * @param bool $for_primary if true, the question group will be removed from the primary
1357
-     *                                           registrant, if false will be removed from others. default: false
1358
-     * @return EE_Base_Class|EE_Question_Group
1359
-     * @throws EE_Error
1360
-     * @throws InvalidArgumentException
1361
-     * @throws ReflectionException
1362
-     * @throws InvalidDataTypeException
1363
-     * @throws InvalidInterfaceException
1364
-     */
1365
-    public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1366
-    {
1367
-        // If the question group is used for the other type (primary or additional)
1368
-        // then just update it. If not, delete it outright.
1369
-        $existing_relation = $this->get_first_related(
1370
-            'Event_Question_Group',
1371
-            [
1372
-                [
1373
-                    'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj)
1374
-                ]
1375
-            ]
1376
-        );
1377
-        $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1378
-        $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1379
-        if ($existing_relation->get($other_field) === false) {
1380
-            // Delete it. It's now no longer for primary or additional question groups.
1381
-            return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
1382
-        }
1383
-        // Just update it. They'll still use this question group for the other category
1384
-        $existing_relation->save(
1385
-            [
1386
-                $field_to_update => false
1387
-            ]
1388
-        );
1389
-    }
1390
-
1391
-
1392
-    /**
1393
-     * Gets all the question groups, ordering them by QSG_order ascending
1394
-     *
1395
-     * @param array $query_params @see
1396
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1397
-     * @return EE_Base_Class[]|EE_Question_Group[]
1398
-     * @throws EE_Error
1399
-     * @throws ReflectionException
1400
-     */
1401
-    public function question_groups($query_params = array())
1402
-    {
1403
-        $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1404
-        return $this->get_many_related('Question_Group', $query_params);
1405
-    }
1406
-
1407
-
1408
-    /**
1409
-     * Implementation for EEI_Has_Icon interface method.
1410
-     *
1411
-     * @see EEI_Visual_Representation for comments
1412
-     * @return string
1413
-     */
1414
-    public function get_icon()
1415
-    {
1416
-        return '<span class="dashicons dashicons-flag"></span>';
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     * Implementation for EEI_Admin_Links interface method.
1422
-     *
1423
-     * @see EEI_Admin_Links for comments
1424
-     * @return string
1425
-     * @throws EE_Error
1426
-     */
1427
-    public function get_admin_details_link()
1428
-    {
1429
-        return $this->get_admin_edit_link();
1430
-    }
1431
-
1432
-
1433
-    /**
1434
-     * Implementation for EEI_Admin_Links interface method.
1435
-     *
1436
-     * @return string
1437
-     * @throws EE_Error*@throws ReflectionException
1438
-     * @see EEI_Admin_Links for comments
1439
-     */
1440
-    public function get_admin_edit_link()
1441
-    {
1442
-        return EEH_URL::add_query_args_and_nonce(
1443
-            array(
1444
-                'page'   => 'espresso_events',
1445
-                'action' => 'edit',
1446
-                'post'   => $this->ID(),
1447
-            ),
1448
-            admin_url('admin.php')
1449
-        );
1450
-    }
1451
-
1452
-
1453
-    /**
1454
-     * Implementation for EEI_Admin_Links interface method.
1455
-     *
1456
-     * @see EEI_Admin_Links for comments
1457
-     * @return string
1458
-     */
1459
-    public function get_admin_settings_link()
1460
-    {
1461
-        return EEH_URL::add_query_args_and_nonce(
1462
-            array(
1463
-                'page'   => 'espresso_events',
1464
-                'action' => 'default_event_settings',
1465
-            ),
1466
-            admin_url('admin.php')
1467
-        );
1468
-    }
1469
-
1470
-
1471
-    /**
1472
-     * Implementation for EEI_Admin_Links interface method.
1473
-     *
1474
-     * @see EEI_Admin_Links for comments
1475
-     * @return string
1476
-     */
1477
-    public function get_admin_overview_link()
1478
-    {
1479
-        return EEH_URL::add_query_args_and_nonce(
1480
-            array(
1481
-                'page'   => 'espresso_events',
1482
-                'action' => 'default',
1483
-            ),
1484
-            admin_url('admin.php')
1485
-        );
1486
-    }
1487
-
1488
-
1489
-    /**
1490
-     * @return string|null
1491
-     * @throws EE_Error
1492
-     * @throws ReflectionException
1493
-     */
1494
-    public function registrationFormUuid(): ?string
1495
-    {
1496
-        return $this->get('FSC_UUID');
1497
-    }
1498
-
1499
-
1500
-    /**
1501
-     * Gets all the form sections for this event
1502
-     *
1503
-     * @return EE_Base_Class[]|EE_Form_Section[]
1504
-     * @throws EE_Error
1505
-     * @throws ReflectionException
1506
-     */
1507
-    public function registrationForm()
1508
-    {
1509
-        $FSC_UUID = $this->registrationFormUuid();
1510
-
1511
-        if (empty($FSC_UUID)) {
1512
-            return [];
1513
-        }
1514
-
1515
-        return EEM_Form_Section::instance()->get_all([
1516
-            [
1517
-                'OR' => [
1518
-                    'FSC_UUID'      => $FSC_UUID, // top level form
1519
-                    'FSC_belongsTo' => $FSC_UUID, // child form sections
1520
-                ]
1521
-                ],
1522
-            'order_by' => ['FSC_order' => 'ASC'],
1523
-        ]);
1524
-    }
1525
-
1526
-
1527
-    /**
1528
-     * @param string $UUID
1529
-     * @throws EE_Error
1530
-     */
1531
-    public function setRegistrationFormUuid(string $UUID): void
1532
-    {
1533
-        if (! Cuid::isCuid($UUID)) {
1534
-            throw new InvalidArgumentException(
1535
-                sprintf(
1536
-                /* translators: 1: UUID value, 2: UUID generator function. */
1537
-                    esc_html__(
1538
-                        'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.',
1539
-                        'event_espresso'
1540
-                    ),
1541
-                    $UUID,
1542
-                    '`Cuid::cuid()`'
1543
-                )
1544
-            );
1545
-        }
1546
-        $this->set('FSC_UUID', $UUID);
1547
-    }
19
+	/**
20
+	 * cached value for the the logical active status for the event
21
+	 *
22
+	 * @see get_active_status()
23
+	 * @var string
24
+	 */
25
+	protected $_active_status = '';
26
+
27
+	/**
28
+	 * This is just used for caching the Primary Datetime for the Event on initial retrieval
29
+	 *
30
+	 * @var EE_Datetime
31
+	 */
32
+	protected $_Primary_Datetime;
33
+
34
+	/**
35
+	 * @var EventSpacesCalculator $available_spaces_calculator
36
+	 */
37
+	protected $available_spaces_calculator;
38
+
39
+
40
+	/**
41
+	 * @param array  $props_n_values          incoming values
42
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
43
+	 *                                        used.)
44
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
45
+	 *                                        date_format and the second value is the time format
46
+	 * @return EE_Event
47
+	 * @throws EE_Error
48
+	 * @throws ReflectionException
49
+	 */
50
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
51
+	{
52
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
53
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
54
+	}
55
+
56
+
57
+	/**
58
+	 * @param array  $props_n_values  incoming values from the database
59
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
60
+	 *                                the website will be used.
61
+	 * @return EE_Event
62
+	 * @throws EE_Error
63
+	 * @throws ReflectionException
64
+	 */
65
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
66
+	{
67
+		return new self($props_n_values, true, $timezone);
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return EventSpacesCalculator
73
+	 * @throws \EE_Error
74
+	 */
75
+	public function getAvailableSpacesCalculator()
76
+	{
77
+		if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
78
+			$this->available_spaces_calculator = new EventSpacesCalculator($this);
79
+		}
80
+		return $this->available_spaces_calculator;
81
+	}
82
+
83
+
84
+	/**
85
+	 * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
86
+	 *
87
+	 * @param string $field_name
88
+	 * @param mixed  $field_value
89
+	 * @param bool   $use_default
90
+	 * @throws EE_Error
91
+	 * @throws ReflectionException
92
+	 */
93
+	public function set($field_name, $field_value, $use_default = false)
94
+	{
95
+		switch ($field_name) {
96
+			case 'status':
97
+				$this->set_status($field_value, $use_default);
98
+				break;
99
+			default:
100
+				parent::set($field_name, $field_value, $use_default);
101
+		}
102
+	}
103
+
104
+
105
+	/**
106
+	 *    set_status
107
+	 * Checks if event status is being changed to SOLD OUT
108
+	 * and updates event meta data with previous event status
109
+	 * so that we can revert things if/when the event is no longer sold out
110
+	 *
111
+	 * @access public
112
+	 * @param string $new_status
113
+	 * @param bool   $use_default
114
+	 * @return void
115
+	 * @throws EE_Error
116
+	 * @throws ReflectionException
117
+	 */
118
+	public function set_status($new_status = null, $use_default = false)
119
+	{
120
+		// if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
121
+		if (empty($new_status) && ! $use_default) {
122
+			return;
123
+		}
124
+		// get current Event status
125
+		$old_status = $this->status();
126
+		// if status has changed
127
+		if ($old_status !== $new_status) {
128
+			// TO sold_out
129
+			if ($new_status === EEM_Event::sold_out) {
130
+				// save the previous event status so that we can revert if the event is no longer sold out
131
+				$this->add_post_meta('_previous_event_status', $old_status);
132
+				do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
133
+			// OR FROM  sold_out
134
+			} elseif ($old_status === EEM_Event::sold_out) {
135
+				$this->delete_post_meta('_previous_event_status');
136
+				do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
137
+			}
138
+			// clear out the active status so that it gets reset the next time it is requested
139
+			$this->_active_status = null;
140
+			// update status
141
+			parent::set('status', $new_status, $use_default);
142
+			do_action('AHEE__EE_Event__set_status__after_update', $this);
143
+			return;
144
+		}
145
+		// even though the old value matches the new value, it's still good to
146
+		// allow the parent set method to have a say
147
+		parent::set('status', $new_status, $use_default);
148
+	}
149
+
150
+
151
+	/**
152
+	 * Gets all the datetimes for this event
153
+	 *
154
+	 * @param array $query_params @see
155
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
156
+	 * @return EE_Base_Class[]|EE_Datetime[]
157
+	 * @throws EE_Error
158
+	 * @throws ReflectionException
159
+	 */
160
+	public function datetimes($query_params = array())
161
+	{
162
+		return $this->get_many_related('Datetime', $query_params);
163
+	}
164
+
165
+
166
+	/**
167
+	 * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
168
+	 *
169
+	 * @return EE_Base_Class[]|EE_Datetime[]
170
+	 * @throws EE_Error
171
+	 * @throws ReflectionException
172
+	 */
173
+	public function datetimes_in_chronological_order()
174
+	{
175
+		return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
176
+	}
177
+
178
+
179
+	/**
180
+	 * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
181
+	 * @darren, we should probably UNSET timezone on the EEM_Datetime model
182
+	 * after running our query, so that this timezone isn't set for EVERY query
183
+	 * on EEM_Datetime for the rest of the request, no?
184
+	 *
185
+	 * @param boolean $show_expired whether or not to include expired events
186
+	 * @param boolean $show_deleted whether or not to include deleted events
187
+	 * @param null    $limit
188
+	 * @return EE_Datetime[]
189
+	 * @throws EE_Error
190
+	 * @throws ReflectionException
191
+	 */
192
+	public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
193
+	{
194
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
195
+			$this->ID(),
196
+			$show_expired,
197
+			$show_deleted,
198
+			$limit
199
+		);
200
+	}
201
+
202
+
203
+	/**
204
+	 * Returns one related datetime. Mostly only used by some legacy code.
205
+	 *
206
+	 * @return EE_Base_Class|EE_Datetime
207
+	 * @throws EE_Error
208
+	 * @throws ReflectionException
209
+	 */
210
+	public function first_datetime()
211
+	{
212
+		return $this->get_first_related('Datetime');
213
+	}
214
+
215
+
216
+	/**
217
+	 * Returns the 'primary' datetime for the event
218
+	 *
219
+	 * @param bool $try_to_exclude_expired
220
+	 * @param bool $try_to_exclude_deleted
221
+	 * @return EE_Datetime
222
+	 * @throws EE_Error
223
+	 * @throws ReflectionException
224
+	 */
225
+	public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
226
+	{
227
+		if (! empty($this->_Primary_Datetime)) {
228
+			return $this->_Primary_Datetime;
229
+		}
230
+		$this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
231
+			$this->ID(),
232
+			$try_to_exclude_expired,
233
+			$try_to_exclude_deleted
234
+		);
235
+		return $this->_Primary_Datetime;
236
+	}
237
+
238
+
239
+	/**
240
+	 * Gets all the tickets available for purchase of this event
241
+	 *
242
+	 * @param array $query_params @see
243
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
244
+	 * @return EE_Base_Class[]|EE_Ticket[]
245
+	 * @throws EE_Error
246
+	 * @throws ReflectionException
247
+	 */
248
+	public function tickets($query_params = array())
249
+	{
250
+		// first get all datetimes
251
+		$datetimes = $this->datetimes_ordered();
252
+		if (! $datetimes) {
253
+			return array();
254
+		}
255
+		$datetime_ids = array();
256
+		foreach ($datetimes as $datetime) {
257
+			$datetime_ids[] = $datetime->ID();
258
+		}
259
+		$where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
260
+		// if incoming $query_params has where conditions let's merge but not override existing.
261
+		if (is_array($query_params) && isset($query_params[0])) {
262
+			$where_params = array_merge($query_params[0], $where_params);
263
+			unset($query_params[0]);
264
+		}
265
+		// now add $where_params to $query_params
266
+		$query_params[0] = $where_params;
267
+		return EEM_Ticket::instance()->get_all($query_params);
268
+	}
269
+
270
+
271
+	/**
272
+	 * get all unexpired untrashed tickets
273
+	 *
274
+	 * @return EE_Ticket[]
275
+	 * @throws EE_Error
276
+	 */
277
+	public function active_tickets()
278
+	{
279
+		return $this->tickets(
280
+			array(
281
+				array(
282
+					'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
283
+					'TKT_deleted'  => false,
284
+				),
285
+			)
286
+		);
287
+	}
288
+
289
+
290
+	/**
291
+	 * @return bool
292
+	 * @throws EE_Error
293
+	 * @throws ReflectionException
294
+	 */
295
+	public function additional_limit()
296
+	{
297
+		return $this->get('EVT_additional_limit');
298
+	}
299
+
300
+
301
+	/**
302
+	 * @return bool
303
+	 * @throws EE_Error
304
+	 * @throws ReflectionException
305
+	 */
306
+	public function allow_overflow()
307
+	{
308
+		return $this->get('EVT_allow_overflow');
309
+	}
310
+
311
+
312
+	/**
313
+	 * @return bool
314
+	 * @throws EE_Error
315
+	 * @throws ReflectionException
316
+	 */
317
+	public function created()
318
+	{
319
+		return $this->get('EVT_created');
320
+	}
321
+
322
+
323
+	/**
324
+	 * @return bool
325
+	 * @throws EE_Error
326
+	 * @throws ReflectionException
327
+	 */
328
+	public function description()
329
+	{
330
+		return $this->get('EVT_desc');
331
+	}
332
+
333
+
334
+	/**
335
+	 * Runs do_shortcode and wpautop on the description
336
+	 *
337
+	 * @return string of html
338
+	 * @throws EE_Error
339
+	 * @throws ReflectionException
340
+	 */
341
+	public function description_filtered()
342
+	{
343
+		return $this->get_pretty('EVT_desc');
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return bool
349
+	 * @throws EE_Error
350
+	 * @throws ReflectionException
351
+	 */
352
+	public function display_description()
353
+	{
354
+		return $this->get('EVT_display_desc');
355
+	}
356
+
357
+
358
+	/**
359
+	 * @return bool
360
+	 * @throws EE_Error
361
+	 * @throws ReflectionException
362
+	 */
363
+	public function display_ticket_selector()
364
+	{
365
+		return (bool) $this->get('EVT_display_ticket_selector');
366
+	}
367
+
368
+
369
+	/**
370
+	 * @return string
371
+	 * @throws EE_Error
372
+	 * @throws ReflectionException
373
+	 */
374
+	public function external_url()
375
+	{
376
+		return $this->get('EVT_external_URL');
377
+	}
378
+
379
+
380
+	/**
381
+	 * @return bool
382
+	 * @throws EE_Error
383
+	 * @throws ReflectionException
384
+	 */
385
+	public function member_only()
386
+	{
387
+		return $this->get('EVT_member_only');
388
+	}
389
+
390
+
391
+	/**
392
+	 * @return bool
393
+	 * @throws EE_Error
394
+	 * @throws ReflectionException
395
+	 */
396
+	public function phone()
397
+	{
398
+		return $this->get('EVT_phone');
399
+	}
400
+
401
+
402
+	/**
403
+	 * @return bool
404
+	 * @throws EE_Error
405
+	 * @throws ReflectionException
406
+	 */
407
+	public function modified()
408
+	{
409
+		return $this->get('EVT_modified');
410
+	}
411
+
412
+
413
+	/**
414
+	 * @return bool
415
+	 * @throws EE_Error
416
+	 * @throws ReflectionException
417
+	 */
418
+	public function name()
419
+	{
420
+		return $this->get('EVT_name');
421
+	}
422
+
423
+
424
+	/**
425
+	 * @return bool
426
+	 * @throws EE_Error
427
+	 * @throws ReflectionException
428
+	 */
429
+	public function order()
430
+	{
431
+		return $this->get('EVT_order');
432
+	}
433
+
434
+
435
+	/**
436
+	 * @return bool|string
437
+	 * @throws EE_Error
438
+	 * @throws ReflectionException
439
+	 */
440
+	public function default_registration_status()
441
+	{
442
+		$event_default_registration_status = $this->get('EVT_default_registration_status');
443
+		return ! empty($event_default_registration_status)
444
+			? $event_default_registration_status
445
+			: EE_Registry::instance()->CFG->registration->default_STS_ID;
446
+	}
447
+
448
+
449
+	/**
450
+	 * @param int  $num_words
451
+	 * @param null $more
452
+	 * @param bool $not_full_desc
453
+	 * @return bool|string
454
+	 * @throws EE_Error
455
+	 * @throws ReflectionException
456
+	 */
457
+	public function short_description($num_words = 55, $more = null, $not_full_desc = false)
458
+	{
459
+		$short_desc = $this->get('EVT_short_desc');
460
+		if (! empty($short_desc) || $not_full_desc) {
461
+			return $short_desc;
462
+		}
463
+		$full_desc = $this->get('EVT_desc');
464
+		return wp_trim_words($full_desc, $num_words, $more);
465
+	}
466
+
467
+
468
+	/**
469
+	 * @return bool
470
+	 * @throws EE_Error
471
+	 * @throws ReflectionException
472
+	 */
473
+	public function slug()
474
+	{
475
+		return $this->get('EVT_slug');
476
+	}
477
+
478
+
479
+	/**
480
+	 * @return bool
481
+	 * @throws EE_Error
482
+	 * @throws ReflectionException
483
+	 */
484
+	public function timezone_string()
485
+	{
486
+		return $this->get('EVT_timezone_string');
487
+	}
488
+
489
+
490
+	/**
491
+	 * @return bool
492
+	 * @throws EE_Error
493
+	 * @throws ReflectionException
494
+	 */
495
+	public function visible_on()
496
+	{
497
+		return $this->get('EVT_visible_on');
498
+	}
499
+
500
+
501
+	/**
502
+	 * @return int
503
+	 * @throws EE_Error
504
+	 * @throws ReflectionException
505
+	 */
506
+	public function wp_user()
507
+	{
508
+		return $this->get('EVT_wp_user');
509
+	}
510
+
511
+
512
+	/**
513
+	 * @return bool
514
+	 * @throws EE_Error
515
+	 * @throws ReflectionException
516
+	 */
517
+	public function donations()
518
+	{
519
+		return $this->get('EVT_donations');
520
+	}
521
+
522
+
523
+	/**
524
+	 * @param $limit
525
+	 * @throws EE_Error
526
+	 */
527
+	public function set_additional_limit($limit)
528
+	{
529
+		$this->set('EVT_additional_limit', $limit);
530
+	}
531
+
532
+
533
+	/**
534
+	 * @param $created
535
+	 * @throws EE_Error
536
+	 */
537
+	public function set_created($created)
538
+	{
539
+		$this->set('EVT_created', $created);
540
+	}
541
+
542
+
543
+	/**
544
+	 * @param $desc
545
+	 * @throws EE_Error
546
+	 */
547
+	public function set_description($desc)
548
+	{
549
+		$this->set('EVT_desc', $desc);
550
+	}
551
+
552
+
553
+	/**
554
+	 * @param $display_desc
555
+	 * @throws EE_Error
556
+	 */
557
+	public function set_display_description($display_desc)
558
+	{
559
+		$this->set('EVT_display_desc', $display_desc);
560
+	}
561
+
562
+
563
+	/**
564
+	 * @param $display_ticket_selector
565
+	 * @throws EE_Error
566
+	 */
567
+	public function set_display_ticket_selector($display_ticket_selector)
568
+	{
569
+		$this->set('EVT_display_ticket_selector', $display_ticket_selector);
570
+	}
571
+
572
+
573
+	/**
574
+	 * @param $external_url
575
+	 * @throws EE_Error
576
+	 */
577
+	public function set_external_url($external_url)
578
+	{
579
+		$this->set('EVT_external_URL', $external_url);
580
+	}
581
+
582
+
583
+	/**
584
+	 * @param $member_only
585
+	 * @throws EE_Error
586
+	 */
587
+	public function set_member_only($member_only)
588
+	{
589
+		$this->set('EVT_member_only', $member_only);
590
+	}
591
+
592
+
593
+	/**
594
+	 * @param $event_phone
595
+	 * @throws EE_Error
596
+	 */
597
+	public function set_event_phone($event_phone)
598
+	{
599
+		$this->set('EVT_phone', $event_phone);
600
+	}
601
+
602
+
603
+	/**
604
+	 * @param $modified
605
+	 * @throws EE_Error
606
+	 */
607
+	public function set_modified($modified)
608
+	{
609
+		$this->set('EVT_modified', $modified);
610
+	}
611
+
612
+
613
+	/**
614
+	 * @param $name
615
+	 * @throws EE_Error
616
+	 */
617
+	public function set_name($name)
618
+	{
619
+		$this->set('EVT_name', $name);
620
+	}
621
+
622
+
623
+	/**
624
+	 * @param $order
625
+	 * @throws EE_Error
626
+	 */
627
+	public function set_order($order)
628
+	{
629
+		$this->set('EVT_order', $order);
630
+	}
631
+
632
+
633
+	/**
634
+	 * @param $short_desc
635
+	 * @throws EE_Error
636
+	 */
637
+	public function set_short_description($short_desc)
638
+	{
639
+		$this->set('EVT_short_desc', $short_desc);
640
+	}
641
+
642
+
643
+	/**
644
+	 * @param $slug
645
+	 * @throws EE_Error
646
+	 */
647
+	public function set_slug($slug)
648
+	{
649
+		$this->set('EVT_slug', $slug);
650
+	}
651
+
652
+
653
+	/**
654
+	 * @param $timezone_string
655
+	 * @throws EE_Error
656
+	 */
657
+	public function set_timezone_string($timezone_string)
658
+	{
659
+		$this->set('EVT_timezone_string', $timezone_string);
660
+	}
661
+
662
+
663
+	/**
664
+	 * @param $visible_on
665
+	 * @throws EE_Error
666
+	 */
667
+	public function set_visible_on($visible_on)
668
+	{
669
+		$this->set('EVT_visible_on', $visible_on);
670
+	}
671
+
672
+
673
+	/**
674
+	 * @param $wp_user
675
+	 * @throws EE_Error
676
+	 */
677
+	public function set_wp_user($wp_user)
678
+	{
679
+		$this->set('EVT_wp_user', $wp_user);
680
+	}
681
+
682
+
683
+	/**
684
+	 * @param $default_registration_status
685
+	 * @throws EE_Error
686
+	 */
687
+	public function set_default_registration_status($default_registration_status)
688
+	{
689
+		$this->set('EVT_default_registration_status', $default_registration_status);
690
+	}
691
+
692
+
693
+	/**
694
+	 * @param $donations
695
+	 * @throws EE_Error
696
+	 */
697
+	public function set_donations($donations)
698
+	{
699
+		$this->set('EVT_donations', $donations);
700
+	}
701
+
702
+
703
+	/**
704
+	 * Adds a venue to this event
705
+	 *
706
+	 * @param int|EE_Venue /int $venue_id_or_obj
707
+	 * @return EE_Base_Class|EE_Venue
708
+	 * @throws EE_Error
709
+	 * @throws ReflectionException
710
+	 */
711
+	public function add_venue($venue_id_or_obj): EE_Venue
712
+	{
713
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
714
+	}
715
+
716
+
717
+	/**
718
+	 * Removes a venue from the event
719
+	 *
720
+	 * @param EE_Venue /int $venue_id_or_obj
721
+	 * @return EE_Base_Class|EE_Venue
722
+	 * @throws EE_Error
723
+	 * @throws ReflectionException
724
+	 */
725
+	public function remove_venue($venue_id_or_obj): EE_Venue
726
+	{
727
+		$venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue();
728
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
729
+	}
730
+
731
+
732
+	/**
733
+	 * Gets the venue related to the event. May provide additional $query_params if desired
734
+	 *
735
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
736
+	 * @return int
737
+	 * @throws EE_Error
738
+	 * @throws ReflectionException
739
+	 */
740
+	public function venue_ID(array $query_params = array()): int
741
+	{
742
+		$venue = $this->get_first_related('Venue', $query_params);
743
+		return $venue instanceof EE_Venue ? $venue->ID() : 0;
744
+	}
745
+
746
+
747
+	/**
748
+	 * Gets the venue related to the event. May provide additional $query_params if desired
749
+	 *
750
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
751
+	 * @return EE_Base_Class|EE_Venue
752
+	 * @throws EE_Error
753
+	 * @throws ReflectionException
754
+	 */
755
+	public function venue(array $query_params = array())
756
+	{
757
+		return $this->get_first_related('Venue', $query_params);
758
+	}
759
+
760
+
761
+	/**
762
+	 * @param array $query_params
763
+	 * @return EE_Base_Class[]|EE_Venue[]
764
+	 * @throws EE_Error
765
+	 * @throws ReflectionException
766
+	 * @deprecated $VID:$
767
+	 */
768
+	public function venues(array $query_params = array()): array
769
+	{
770
+		return [$this->venue($query_params)];
771
+	}
772
+
773
+
774
+	/**
775
+	 * check if event id is present and if event is published
776
+	 *
777
+	 * @access public
778
+	 * @return boolean true yes, false no
779
+	 * @throws EE_Error
780
+	 * @throws ReflectionException
781
+	 */
782
+	private function _has_ID_and_is_published()
783
+	{
784
+		// first check if event id is present and not NULL,
785
+		// then check if this event is published (or any of the equivalent "published" statuses)
786
+		return
787
+			$this->ID() && $this->ID() !== null
788
+			&& (
789
+				$this->status() === 'publish'
790
+				|| $this->status() === EEM_Event::sold_out
791
+				|| $this->status() === EEM_Event::postponed
792
+				|| $this->status() === EEM_Event::cancelled
793
+			);
794
+	}
795
+
796
+
797
+	/**
798
+	 * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
799
+	 *
800
+	 * @access public
801
+	 * @return boolean true yes, false no
802
+	 * @throws EE_Error
803
+	 * @throws ReflectionException
804
+	 */
805
+	public function is_upcoming()
806
+	{
807
+		// check if event id is present and if this event is published
808
+		if ($this->is_inactive()) {
809
+			return false;
810
+		}
811
+		// set initial value
812
+		$upcoming = false;
813
+		// next let's get all datetimes and loop through them
814
+		$datetimes = $this->datetimes_in_chronological_order();
815
+		foreach ($datetimes as $datetime) {
816
+			if ($datetime instanceof EE_Datetime) {
817
+				// if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
818
+				if ($datetime->is_expired()) {
819
+					continue;
820
+				}
821
+				// if this dtt is active then we return false.
822
+				if ($datetime->is_active()) {
823
+					return false;
824
+				}
825
+				// otherwise let's check upcoming status
826
+				$upcoming = $datetime->is_upcoming();
827
+			}
828
+		}
829
+		return $upcoming;
830
+	}
831
+
832
+
833
+	/**
834
+	 * @return bool
835
+	 * @throws EE_Error
836
+	 * @throws ReflectionException
837
+	 */
838
+	public function is_active()
839
+	{
840
+		// check if event id is present and if this event is published
841
+		if ($this->is_inactive()) {
842
+			return false;
843
+		}
844
+		// set initial value
845
+		$active = false;
846
+		// next let's get all datetimes and loop through them
847
+		$datetimes = $this->datetimes_in_chronological_order();
848
+		foreach ($datetimes as $datetime) {
849
+			if ($datetime instanceof EE_Datetime) {
850
+				// if this dtt is expired then we continue cause one of the other datetimes might be active.
851
+				if ($datetime->is_expired()) {
852
+					continue;
853
+				}
854
+				// if this dtt is upcoming then we return false.
855
+				if ($datetime->is_upcoming()) {
856
+					return false;
857
+				}
858
+				// otherwise let's check active status
859
+				$active = $datetime->is_active();
860
+			}
861
+		}
862
+		return $active;
863
+	}
864
+
865
+
866
+	/**
867
+	 * @return bool
868
+	 * @throws EE_Error
869
+	 * @throws ReflectionException
870
+	 */
871
+	public function is_expired()
872
+	{
873
+		// check if event id is present and if this event is published
874
+		if ($this->is_inactive()) {
875
+			return false;
876
+		}
877
+		// set initial value
878
+		$expired = false;
879
+		// first let's get all datetimes and loop through them
880
+		$datetimes = $this->datetimes_in_chronological_order();
881
+		foreach ($datetimes as $datetime) {
882
+			if ($datetime instanceof EE_Datetime) {
883
+				// if this dtt is upcoming or active then we return false.
884
+				if ($datetime->is_upcoming() || $datetime->is_active()) {
885
+					return false;
886
+				}
887
+				// otherwise let's check active status
888
+				$expired = $datetime->is_expired();
889
+			}
890
+		}
891
+		return $expired;
892
+	}
893
+
894
+
895
+	/**
896
+	 * @return bool
897
+	 * @throws EE_Error
898
+	 */
899
+	public function is_inactive()
900
+	{
901
+		// check if event id is present and if this event is published
902
+		if ($this->_has_ID_and_is_published()) {
903
+			return false;
904
+		}
905
+		return true;
906
+	}
907
+
908
+
909
+	/**
910
+	 * calculate spaces remaining based on "saleable" tickets
911
+	 *
912
+	 * @param array $tickets
913
+	 * @param bool  $filtered
914
+	 * @return int|float
915
+	 * @throws EE_Error
916
+	 * @throws DomainException
917
+	 * @throws UnexpectedEntityException
918
+	 */
919
+	public function spaces_remaining($tickets = array(), $filtered = true)
920
+	{
921
+		$this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
922
+		$spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
923
+		return $filtered
924
+			? apply_filters(
925
+				'FHEE_EE_Event__spaces_remaining',
926
+				$spaces_remaining,
927
+				$this,
928
+				$tickets
929
+			)
930
+			: $spaces_remaining;
931
+	}
932
+
933
+
934
+	/**
935
+	 *    perform_sold_out_status_check
936
+	 *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
937
+	 *    available... if NOT, then the event status will get toggled to 'sold_out'
938
+	 *
939
+	 * @return bool    return the ACTUAL sold out state.
940
+	 * @throws EE_Error
941
+	 * @throws DomainException
942
+	 * @throws UnexpectedEntityException
943
+	 * @throws ReflectionException
944
+	 */
945
+	public function perform_sold_out_status_check()
946
+	{
947
+		// get all tickets
948
+		$tickets = $this->tickets(
949
+			array(
950
+				'default_where_conditions' => 'none',
951
+				'order_by' => array('TKT_qty' => 'ASC'),
952
+			)
953
+		);
954
+		$all_expired = true;
955
+		foreach ($tickets as $ticket) {
956
+			if (! $ticket->is_expired()) {
957
+				$all_expired = false;
958
+				break;
959
+			}
960
+		}
961
+		// if all the tickets are just expired, then don't update the event status to sold out
962
+		if ($all_expired) {
963
+			return true;
964
+		}
965
+		$spaces_remaining = $this->spaces_remaining($tickets);
966
+		if ($spaces_remaining < 1) {
967
+			if ($this->status() !== EEM_Event::post_status_private) {
968
+				$this->set_status(EEM_Event::sold_out);
969
+				$this->save();
970
+			}
971
+			$sold_out = true;
972
+		} else {
973
+			$sold_out = false;
974
+			// was event previously marked as sold out ?
975
+			if ($this->status() === EEM_Event::sold_out) {
976
+				// revert status to previous value, if it was set
977
+				$previous_event_status = $this->get_post_meta('_previous_event_status', true);
978
+				if ($previous_event_status) {
979
+					$this->set_status($previous_event_status);
980
+					$this->save();
981
+				}
982
+			}
983
+		}
984
+		do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
985
+		return $sold_out;
986
+	}
987
+
988
+
989
+	/**
990
+	 * This returns the total remaining spaces for sale on this event.
991
+	 *
992
+	 * @uses EE_Event::total_available_spaces()
993
+	 * @return float|int
994
+	 * @throws EE_Error
995
+	 * @throws DomainException
996
+	 * @throws UnexpectedEntityException
997
+	 */
998
+	public function spaces_remaining_for_sale()
999
+	{
1000
+		return $this->total_available_spaces(true);
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * This returns the total spaces available for an event
1006
+	 * while considering all the qtys on the tickets and the reg limits
1007
+	 * on the datetimes attached to this event.
1008
+	 *
1009
+	 * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
1010
+	 *                              If this is false, then we return the most tickets that could ever be sold
1011
+	 *                              for this event with the datetime and tickets setup on the event under optimal
1012
+	 *                              selling conditions.  Otherwise we return a live calculation of spaces available
1013
+	 *                              based on tickets sold.  Depending on setup and stage of sales, this
1014
+	 *                              may appear to equal remaining tickets.  However, the more tickets are
1015
+	 *                              sold out, the more accurate the "live" total is.
1016
+	 * @return float|int
1017
+	 * @throws EE_Error
1018
+	 * @throws DomainException
1019
+	 * @throws UnexpectedEntityException
1020
+	 */
1021
+	public function total_available_spaces($consider_sold = false)
1022
+	{
1023
+		$spaces_available = $consider_sold
1024
+			? $this->getAvailableSpacesCalculator()->spacesRemaining()
1025
+			: $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
1026
+		return apply_filters(
1027
+			'FHEE_EE_Event__total_available_spaces__spaces_available',
1028
+			$spaces_available,
1029
+			$this,
1030
+			$this->getAvailableSpacesCalculator()->getDatetimes(),
1031
+			$this->getAvailableSpacesCalculator()->getActiveTickets()
1032
+		);
1033
+	}
1034
+
1035
+
1036
+	/**
1037
+	 * Checks if the event is set to sold out
1038
+	 *
1039
+	 * @param  bool $actual whether or not to perform calculations to not only figure the
1040
+	 *                      actual status but also to flip the status if necessary to sold
1041
+	 *                      out If false, we just check the existing status of the event
1042
+	 * @return boolean
1043
+	 * @throws EE_Error
1044
+	 */
1045
+	public function is_sold_out($actual = false)
1046
+	{
1047
+		if (! $actual) {
1048
+			return $this->status() === EEM_Event::sold_out;
1049
+		}
1050
+		return $this->perform_sold_out_status_check();
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * Checks if the event is marked as postponed
1056
+	 *
1057
+	 * @return boolean
1058
+	 */
1059
+	public function is_postponed()
1060
+	{
1061
+		return $this->status() === EEM_Event::postponed;
1062
+	}
1063
+
1064
+
1065
+	/**
1066
+	 * Checks if the event is marked as cancelled
1067
+	 *
1068
+	 * @return boolean
1069
+	 */
1070
+	public function is_cancelled()
1071
+	{
1072
+		return $this->status() === EEM_Event::cancelled;
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * Get the logical active status in a hierarchical order for all the datetimes.  Note
1078
+	 * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1079
+	 * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1080
+	 * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1081
+	 * the event is considered expired.
1082
+	 * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1083
+	 * status set on the EVENT when it is not published and thus is done
1084
+	 *
1085
+	 * @param bool $reset
1086
+	 * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1087
+	 * @throws EE_Error
1088
+	 * @throws ReflectionException
1089
+	 */
1090
+	public function get_active_status($reset = false)
1091
+	{
1092
+		// if the active status has already been set, then just use that value (unless we are resetting it)
1093
+		if (! empty($this->_active_status) && ! $reset) {
1094
+			return $this->_active_status;
1095
+		}
1096
+		// first check if event id is present on this object
1097
+		if (! $this->ID()) {
1098
+			return false;
1099
+		}
1100
+		$where_params_for_event = array(array('EVT_ID' => $this->ID()));
1101
+		// if event is published:
1102
+		if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1103
+			// active?
1104
+			if (
1105
+				EEM_Datetime::instance()->get_datetime_count_for_status(
1106
+					EE_Datetime::active,
1107
+					$where_params_for_event
1108
+				) > 0
1109
+			) {
1110
+				$this->_active_status = EE_Datetime::active;
1111
+			} else {
1112
+				// upcoming?
1113
+				if (
1114
+					EEM_Datetime::instance()->get_datetime_count_for_status(
1115
+						EE_Datetime::upcoming,
1116
+						$where_params_for_event
1117
+					) > 0
1118
+				) {
1119
+					$this->_active_status = EE_Datetime::upcoming;
1120
+				} else {
1121
+					// expired?
1122
+					if (
1123
+						EEM_Datetime::instance()->get_datetime_count_for_status(
1124
+							EE_Datetime::expired,
1125
+							$where_params_for_event
1126
+						) > 0
1127
+					) {
1128
+						$this->_active_status = EE_Datetime::expired;
1129
+					} else {
1130
+						// it would be odd if things make it this far because it basically means there are no datetime's
1131
+						// attached to the event.  So in this case it will just be considered inactive.
1132
+						$this->_active_status = EE_Datetime::inactive;
1133
+					}
1134
+				}
1135
+			}
1136
+		} else {
1137
+			// the event is not published, so let's just set it's active status according to its' post status
1138
+			switch ($this->status()) {
1139
+				case EEM_Event::sold_out:
1140
+					$this->_active_status = EE_Datetime::sold_out;
1141
+					break;
1142
+				case EEM_Event::cancelled:
1143
+					$this->_active_status = EE_Datetime::cancelled;
1144
+					break;
1145
+				case EEM_Event::postponed:
1146
+					$this->_active_status = EE_Datetime::postponed;
1147
+					break;
1148
+				default:
1149
+					$this->_active_status = EE_Datetime::inactive;
1150
+			}
1151
+		}
1152
+		return $this->_active_status;
1153
+	}
1154
+
1155
+
1156
+	/**
1157
+	 *    pretty_active_status
1158
+	 *
1159
+	 * @access public
1160
+	 * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1161
+	 * @return mixed void|string
1162
+	 * @throws EE_Error
1163
+	 * @throws ReflectionException
1164
+	 */
1165
+	public function pretty_active_status($echo = true)
1166
+	{
1167
+		$active_status = $this->get_active_status();
1168
+		$status = '<span class="ee-status ee-status-bg--' . esc_attr($active_status) . ' event-active-status-' .
1169
+				  esc_attr($active_status) . '">'
1170
+				  . EEH_Template::pretty_status($active_status, false, 'sentence')
1171
+				  . '</span>';
1172
+		if ($echo) {
1173
+			echo $status; // already escaped
1174
+			return '';
1175
+		}
1176
+		return $status; // already escaped
1177
+	}
1178
+
1179
+
1180
+	/**
1181
+	 * @return bool|int
1182
+	 * @throws EE_Error
1183
+	 * @throws ReflectionException
1184
+	 */
1185
+	public function get_number_of_tickets_sold()
1186
+	{
1187
+		$tkt_sold = 0;
1188
+		if (! $this->ID()) {
1189
+			return 0;
1190
+		}
1191
+		$datetimes = $this->datetimes();
1192
+		foreach ($datetimes as $datetime) {
1193
+			if ($datetime instanceof EE_Datetime) {
1194
+				$tkt_sold += $datetime->sold();
1195
+			}
1196
+		}
1197
+		return $tkt_sold;
1198
+	}
1199
+
1200
+
1201
+	/**
1202
+	 * This just returns a count of all the registrations for this event
1203
+	 *
1204
+	 * @access  public
1205
+	 * @return int
1206
+	 * @throws EE_Error
1207
+	 */
1208
+	public function get_count_of_all_registrations()
1209
+	{
1210
+		return EEM_Event::instance()->count_related($this, 'Registration');
1211
+	}
1212
+
1213
+
1214
+	/**
1215
+	 * This returns the ticket with the earliest start time that is
1216
+	 * available for this event (across all datetimes attached to the event)
1217
+	 *
1218
+	 * @return EE_Base_Class|EE_Ticket|null
1219
+	 * @throws EE_Error
1220
+	 * @throws ReflectionException
1221
+	 */
1222
+	public function get_ticket_with_earliest_start_time()
1223
+	{
1224
+		$where['Datetime.EVT_ID'] = $this->ID();
1225
+		$query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1226
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1227
+	}
1228
+
1229
+
1230
+	/**
1231
+	 * This returns the ticket with the latest end time that is available
1232
+	 * for this event (across all datetimes attached to the event)
1233
+	 *
1234
+	 * @return EE_Base_Class|EE_Ticket|null
1235
+	 * @throws EE_Error
1236
+	 * @throws ReflectionException
1237
+	 */
1238
+	public function get_ticket_with_latest_end_time()
1239
+	{
1240
+		$where['Datetime.EVT_ID'] = $this->ID();
1241
+		$query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1242
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1243
+	}
1244
+
1245
+
1246
+	/**
1247
+	 * This returns the number of different ticket types currently on sale for this event.
1248
+	 *
1249
+	 * @return int
1250
+	 * @throws EE_Error
1251
+	 * @throws ReflectionException
1252
+	 */
1253
+	public function countTicketsOnSale()
1254
+	{
1255
+		$where = array(
1256
+			'Datetime.EVT_ID' => $this->ID(),
1257
+			'TKT_start_date'  => array('<', time()),
1258
+			'TKT_end_date'    => array('>', time()),
1259
+		);
1260
+		return EEM_Ticket::instance()->count(array($where));
1261
+	}
1262
+
1263
+
1264
+	/**
1265
+	 * This returns whether there are any tickets on sale for this event.
1266
+	 *
1267
+	 * @return bool true = YES tickets on sale.
1268
+	 * @throws EE_Error
1269
+	 */
1270
+	public function tickets_on_sale()
1271
+	{
1272
+		return $this->countTicketsOnSale() > 0;
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * Gets the URL for viewing this event on the front-end. Overrides parent
1278
+	 * to check for an external URL first
1279
+	 *
1280
+	 * @return string
1281
+	 * @throws EE_Error
1282
+	 */
1283
+	public function get_permalink()
1284
+	{
1285
+		if ($this->external_url()) {
1286
+			return $this->external_url();
1287
+		}
1288
+		return parent::get_permalink();
1289
+	}
1290
+
1291
+
1292
+	/**
1293
+	 * Gets the first term for 'espresso_event_categories' we can find
1294
+	 *
1295
+	 * @param array $query_params @see
1296
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1297
+	 * @return EE_Base_Class|EE_Term|null
1298
+	 * @throws EE_Error
1299
+	 * @throws ReflectionException
1300
+	 */
1301
+	public function first_event_category($query_params = array())
1302
+	{
1303
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1304
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1305
+		return EEM_Term::instance()->get_one($query_params);
1306
+	}
1307
+
1308
+
1309
+	/**
1310
+	 * Gets all terms for 'espresso_event_categories' we can find
1311
+	 *
1312
+	 * @param array $query_params
1313
+	 * @return EE_Base_Class[]|EE_Term[]
1314
+	 * @throws EE_Error
1315
+	 * @throws ReflectionException
1316
+	 */
1317
+	public function get_all_event_categories($query_params = array())
1318
+	{
1319
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1320
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1321
+		return EEM_Term::instance()->get_all($query_params);
1322
+	}
1323
+
1324
+
1325
+	/**
1326
+	 * Adds a question group to this event
1327
+	 *
1328
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1329
+	 * @param bool $for_primary if true, the question group will be added for the primary
1330
+	 *                                           registrant, if false will be added for others. default: false
1331
+	 * @return EE_Base_Class|EE_Question_Group
1332
+	 * @throws EE_Error
1333
+	 * @throws InvalidArgumentException
1334
+	 * @throws InvalidDataTypeException
1335
+	 * @throws InvalidInterfaceException
1336
+	 * @throws ReflectionException
1337
+	 */
1338
+	public function add_question_group($question_group_id_or_obj, $for_primary = false)
1339
+	{
1340
+		// If the row already exists, it will be updated. If it doesn't, it will be inserted.
1341
+		// That's in EE_HABTM_Relation::add_relation_to().
1342
+		return $this->_add_relation_to(
1343
+			$question_group_id_or_obj,
1344
+			'Question_Group',
1345
+			[
1346
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true
1347
+			]
1348
+		);
1349
+	}
1350
+
1351
+
1352
+	/**
1353
+	 * Removes a question group from the event
1354
+	 *
1355
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1356
+	 * @param bool $for_primary if true, the question group will be removed from the primary
1357
+	 *                                           registrant, if false will be removed from others. default: false
1358
+	 * @return EE_Base_Class|EE_Question_Group
1359
+	 * @throws EE_Error
1360
+	 * @throws InvalidArgumentException
1361
+	 * @throws ReflectionException
1362
+	 * @throws InvalidDataTypeException
1363
+	 * @throws InvalidInterfaceException
1364
+	 */
1365
+	public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1366
+	{
1367
+		// If the question group is used for the other type (primary or additional)
1368
+		// then just update it. If not, delete it outright.
1369
+		$existing_relation = $this->get_first_related(
1370
+			'Event_Question_Group',
1371
+			[
1372
+				[
1373
+					'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj)
1374
+				]
1375
+			]
1376
+		);
1377
+		$field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1378
+		$other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1379
+		if ($existing_relation->get($other_field) === false) {
1380
+			// Delete it. It's now no longer for primary or additional question groups.
1381
+			return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
1382
+		}
1383
+		// Just update it. They'll still use this question group for the other category
1384
+		$existing_relation->save(
1385
+			[
1386
+				$field_to_update => false
1387
+			]
1388
+		);
1389
+	}
1390
+
1391
+
1392
+	/**
1393
+	 * Gets all the question groups, ordering them by QSG_order ascending
1394
+	 *
1395
+	 * @param array $query_params @see
1396
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1397
+	 * @return EE_Base_Class[]|EE_Question_Group[]
1398
+	 * @throws EE_Error
1399
+	 * @throws ReflectionException
1400
+	 */
1401
+	public function question_groups($query_params = array())
1402
+	{
1403
+		$query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1404
+		return $this->get_many_related('Question_Group', $query_params);
1405
+	}
1406
+
1407
+
1408
+	/**
1409
+	 * Implementation for EEI_Has_Icon interface method.
1410
+	 *
1411
+	 * @see EEI_Visual_Representation for comments
1412
+	 * @return string
1413
+	 */
1414
+	public function get_icon()
1415
+	{
1416
+		return '<span class="dashicons dashicons-flag"></span>';
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 * Implementation for EEI_Admin_Links interface method.
1422
+	 *
1423
+	 * @see EEI_Admin_Links for comments
1424
+	 * @return string
1425
+	 * @throws EE_Error
1426
+	 */
1427
+	public function get_admin_details_link()
1428
+	{
1429
+		return $this->get_admin_edit_link();
1430
+	}
1431
+
1432
+
1433
+	/**
1434
+	 * Implementation for EEI_Admin_Links interface method.
1435
+	 *
1436
+	 * @return string
1437
+	 * @throws EE_Error*@throws ReflectionException
1438
+	 * @see EEI_Admin_Links for comments
1439
+	 */
1440
+	public function get_admin_edit_link()
1441
+	{
1442
+		return EEH_URL::add_query_args_and_nonce(
1443
+			array(
1444
+				'page'   => 'espresso_events',
1445
+				'action' => 'edit',
1446
+				'post'   => $this->ID(),
1447
+			),
1448
+			admin_url('admin.php')
1449
+		);
1450
+	}
1451
+
1452
+
1453
+	/**
1454
+	 * Implementation for EEI_Admin_Links interface method.
1455
+	 *
1456
+	 * @see EEI_Admin_Links for comments
1457
+	 * @return string
1458
+	 */
1459
+	public function get_admin_settings_link()
1460
+	{
1461
+		return EEH_URL::add_query_args_and_nonce(
1462
+			array(
1463
+				'page'   => 'espresso_events',
1464
+				'action' => 'default_event_settings',
1465
+			),
1466
+			admin_url('admin.php')
1467
+		);
1468
+	}
1469
+
1470
+
1471
+	/**
1472
+	 * Implementation for EEI_Admin_Links interface method.
1473
+	 *
1474
+	 * @see EEI_Admin_Links for comments
1475
+	 * @return string
1476
+	 */
1477
+	public function get_admin_overview_link()
1478
+	{
1479
+		return EEH_URL::add_query_args_and_nonce(
1480
+			array(
1481
+				'page'   => 'espresso_events',
1482
+				'action' => 'default',
1483
+			),
1484
+			admin_url('admin.php')
1485
+		);
1486
+	}
1487
+
1488
+
1489
+	/**
1490
+	 * @return string|null
1491
+	 * @throws EE_Error
1492
+	 * @throws ReflectionException
1493
+	 */
1494
+	public function registrationFormUuid(): ?string
1495
+	{
1496
+		return $this->get('FSC_UUID');
1497
+	}
1498
+
1499
+
1500
+	/**
1501
+	 * Gets all the form sections for this event
1502
+	 *
1503
+	 * @return EE_Base_Class[]|EE_Form_Section[]
1504
+	 * @throws EE_Error
1505
+	 * @throws ReflectionException
1506
+	 */
1507
+	public function registrationForm()
1508
+	{
1509
+		$FSC_UUID = $this->registrationFormUuid();
1510
+
1511
+		if (empty($FSC_UUID)) {
1512
+			return [];
1513
+		}
1514
+
1515
+		return EEM_Form_Section::instance()->get_all([
1516
+			[
1517
+				'OR' => [
1518
+					'FSC_UUID'      => $FSC_UUID, // top level form
1519
+					'FSC_belongsTo' => $FSC_UUID, // child form sections
1520
+				]
1521
+				],
1522
+			'order_by' => ['FSC_order' => 'ASC'],
1523
+		]);
1524
+	}
1525
+
1526
+
1527
+	/**
1528
+	 * @param string $UUID
1529
+	 * @throws EE_Error
1530
+	 */
1531
+	public function setRegistrationFormUuid(string $UUID): void
1532
+	{
1533
+		if (! Cuid::isCuid($UUID)) {
1534
+			throw new InvalidArgumentException(
1535
+				sprintf(
1536
+				/* translators: 1: UUID value, 2: UUID generator function. */
1537
+					esc_html__(
1538
+						'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.',
1539
+						'event_espresso'
1540
+					),
1541
+					$UUID,
1542
+					'`Cuid::cuid()`'
1543
+				)
1544
+			);
1545
+		}
1546
+		$this->set('FSC_UUID', $UUID);
1547
+	}
1548 1548
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function getAvailableSpacesCalculator()
76 76
     {
77
-        if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
77
+        if ( ! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
78 78
             $this->available_spaces_calculator = new EventSpacesCalculator($this);
79 79
         }
80 80
         return $this->available_spaces_calculator;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      */
225 225
     public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
226 226
     {
227
-        if (! empty($this->_Primary_Datetime)) {
227
+        if ( ! empty($this->_Primary_Datetime)) {
228 228
             return $this->_Primary_Datetime;
229 229
         }
230 230
         $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
     {
250 250
         // first get all datetimes
251 251
         $datetimes = $this->datetimes_ordered();
252
-        if (! $datetimes) {
252
+        if ( ! $datetimes) {
253 253
             return array();
254 254
         }
255 255
         $datetime_ids = array();
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
     public function short_description($num_words = 55, $more = null, $not_full_desc = false)
458 458
     {
459 459
         $short_desc = $this->get('EVT_short_desc');
460
-        if (! empty($short_desc) || $not_full_desc) {
460
+        if ( ! empty($short_desc) || $not_full_desc) {
461 461
             return $short_desc;
462 462
         }
463 463
         $full_desc = $this->get('EVT_desc');
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
         );
954 954
         $all_expired = true;
955 955
         foreach ($tickets as $ticket) {
956
-            if (! $ticket->is_expired()) {
956
+            if ( ! $ticket->is_expired()) {
957 957
                 $all_expired = false;
958 958
                 break;
959 959
             }
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      */
1045 1045
     public function is_sold_out($actual = false)
1046 1046
     {
1047
-        if (! $actual) {
1047
+        if ( ! $actual) {
1048 1048
             return $this->status() === EEM_Event::sold_out;
1049 1049
         }
1050 1050
         return $this->perform_sold_out_status_check();
@@ -1090,11 +1090,11 @@  discard block
 block discarded – undo
1090 1090
     public function get_active_status($reset = false)
1091 1091
     {
1092 1092
         // if the active status has already been set, then just use that value (unless we are resetting it)
1093
-        if (! empty($this->_active_status) && ! $reset) {
1093
+        if ( ! empty($this->_active_status) && ! $reset) {
1094 1094
             return $this->_active_status;
1095 1095
         }
1096 1096
         // first check if event id is present on this object
1097
-        if (! $this->ID()) {
1097
+        if ( ! $this->ID()) {
1098 1098
             return false;
1099 1099
         }
1100 1100
         $where_params_for_event = array(array('EVT_ID' => $this->ID()));
@@ -1165,8 +1165,8 @@  discard block
 block discarded – undo
1165 1165
     public function pretty_active_status($echo = true)
1166 1166
     {
1167 1167
         $active_status = $this->get_active_status();
1168
-        $status = '<span class="ee-status ee-status-bg--' . esc_attr($active_status) . ' event-active-status-' .
1169
-                  esc_attr($active_status) . '">'
1168
+        $status = '<span class="ee-status ee-status-bg--'.esc_attr($active_status).' event-active-status-'.
1169
+                  esc_attr($active_status).'">'
1170 1170
                   . EEH_Template::pretty_status($active_status, false, 'sentence')
1171 1171
                   . '</span>';
1172 1172
         if ($echo) {
@@ -1185,7 +1185,7 @@  discard block
 block discarded – undo
1185 1185
     public function get_number_of_tickets_sold()
1186 1186
     {
1187 1187
         $tkt_sold = 0;
1188
-        if (! $this->ID()) {
1188
+        if ( ! $this->ID()) {
1189 1189
             return 0;
1190 1190
         }
1191 1191
         $datetimes = $this->datetimes();
@@ -1375,7 +1375,7 @@  discard block
 block discarded – undo
1375 1375
             ]
1376 1376
         );
1377 1377
         $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1378
-        $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1378
+        $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext( ! $for_primary);
1379 1379
         if ($existing_relation->get($other_field) === false) {
1380 1380
             // Delete it. It's now no longer for primary or additional question groups.
1381 1381
             return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
@@ -1530,7 +1530,7 @@  discard block
 block discarded – undo
1530 1530
      */
1531 1531
     public function setRegistrationFormUuid(string $UUID): void
1532 1532
     {
1533
-        if (! Cuid::isCuid($UUID)) {
1533
+        if ( ! Cuid::isCuid($UUID)) {
1534 1534
             throw new InvalidArgumentException(
1535 1535
                 sprintf(
1536 1536
                 /* translators: 1: UUID value, 2: UUID generator function. */
Please login to merge, or discard this patch.