Completed
Branch master (7421d0)
by
unknown
11:25 queued 06:55
created
core/db_models/EEM_Registration.model.php 2 patches
Indentation   +863 added lines, -863 removed lines patch added patch discarded remove patch
@@ -15,812 +15,812 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class EEM_Registration extends EEM_Soft_Delete_Base
17 17
 {
18
-    /**
19
-     * The value of REG_count for a primary registrant
20
-     */
21
-    const PRIMARY_REGISTRANT_COUNT = 1;
22
-
23
-    /**
24
-     * @depecated 5.0.20.p  use RegStatus::INCOMPLETE instead
25
-     */
26
-    const status_id_incomplete = 'RIC';
27
-
28
-    /**
29
-     * @depecated 5.0.20.p  use RegStatus::AWAITING_REVIEW instead
30
-     */
31
-    const status_id_not_approved = 'RNA';
32
-
33
-    /**
34
-     * @depecated 5.0.20.p  use RegStatus::PENDING_PAYMENT instead
35
-     */
36
-    const status_id_pending_payment = 'RPP';
37
-
38
-    /**
39
-     * @depecated 5.0.20.p  use RegStatus::WAIT_LIST instead
40
-     */
41
-    const status_id_wait_list = 'RWL';
42
-
43
-    /**
44
-     * @depecated 5.0.20.p  use RegStatus::APPROVED instead
45
-     */
46
-    const status_id_approved = 'RAP';
47
-
48
-    /**
49
-     * @depecated 5.0.20.p  use RegStatus::CANCELLED instead
50
-     */
51
-    const status_id_cancelled = 'RCN';
52
-
53
-    /**
54
-     * @depecated 5.0.20.p  use RegStatus::DECLINED instead
55
-     */
56
-    const status_id_declined = 'RDC';
57
-
58
-
59
-    protected static ?EEM_Registration $_instance       = null;
60
-
61
-    protected ?TableAnalysis           $_table_analysis = null;
62
-
63
-    /**
64
-     * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
65
-     * are status codes (eg, approved, cancelled, etc)
66
-     *
67
-     * @var array|null
68
-     */
69
-    private static array $_reg_status = [];
70
-
71
-
72
-    /**
73
-     * private constructor to prevent direct creation
74
-     *
75
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
76
-     *                              any incoming timezone data that gets saved). Note this just sends the timezone info
77
-     *                              to the date time model field objects.  Default is NULL (and will be assumed using
78
-     *                              the set timezone in the 'timezone_string' wp option)
79
-     * @throws EE_Error
80
-     * @throws ReflectionException
81
-     */
82
-    protected function __construct(?string $timezone = '')
83
-    {
84
-        $this->_table_analysis         = EE_Registry::instance()->create('TableAnalysis', [], true);
85
-        $this->singular_item           = esc_html__('Registration', 'event_espresso');
86
-        $this->plural_item             = esc_html__('Registrations', 'event_espresso');
87
-        $this->_tables                 = [
88
-            'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
89
-        ];
90
-        $this->_fields                 = [
91
-            'Registration' => [
92
-                'REG_ID'           => new EE_Primary_Key_Int_Field(
93
-                    'REG_ID',
94
-                    esc_html__('Registration ID', 'event_espresso')
95
-                ),
96
-                'EVT_ID'           => new EE_Foreign_Key_Int_Field(
97
-                    'EVT_ID',
98
-                    esc_html__('Event ID', 'event_espresso'),
99
-                    false,
100
-                    0,
101
-                    'Event'
102
-                ),
103
-                'ATT_ID'           => new EE_Foreign_Key_Int_Field(
104
-                    'ATT_ID',
105
-                    esc_html__('Attendee ID', 'event_espresso'),
106
-                    false,
107
-                    0,
108
-                    'Attendee'
109
-                ),
110
-                'TXN_ID'           => new EE_Foreign_Key_Int_Field(
111
-                    'TXN_ID',
112
-                    esc_html__('Transaction ID', 'event_espresso'),
113
-                    false,
114
-                    0,
115
-                    'Transaction'
116
-                ),
117
-                'TKT_ID'           => new EE_Foreign_Key_Int_Field(
118
-                    'TKT_ID',
119
-                    esc_html__('Ticket ID', 'event_espresso'),
120
-                    false,
121
-                    0,
122
-                    'Ticket'
123
-                ),
124
-                'STS_ID'           => new EE_Foreign_Key_String_Field(
125
-                    'STS_ID',
126
-                    esc_html__('Status ID', 'event_espresso'),
127
-                    false,
128
-                    RegStatus::INCOMPLETE,
129
-                    'Status'
130
-                ),
131
-                'REG_date'         => new EE_Datetime_Field(
132
-                    'REG_date',
133
-                    esc_html__('Time registration occurred', 'event_espresso'),
134
-                    false,
135
-                    EE_Datetime_Field::now,
136
-                    $timezone
137
-                ),
138
-                'REG_final_price'  => new EE_Money_Field(
139
-                    'REG_final_price',
140
-                    esc_html__('Registration\'s share of the transaction total', 'event_espresso'),
141
-                    false,
142
-                    0
143
-                ),
144
-                'REG_paid'         => new EE_Money_Field(
145
-                    'REG_paid',
146
-                    esc_html__('Amount paid to date towards registration', 'event_espresso'),
147
-                    false,
148
-                    0
149
-                ),
150
-                'REG_session'      => new EE_Plain_Text_Field(
151
-                    'REG_session',
152
-                    esc_html__('Session ID of registration', 'event_espresso'),
153
-                    false,
154
-                    ''
155
-                ),
156
-                'REG_code'         => new EE_Plain_Text_Field(
157
-                    'REG_code',
158
-                    esc_html__('Unique Code for this registration', 'event_espresso'),
159
-                    false,
160
-                    ''
161
-                ),
162
-                'REG_url_link'     => new EE_Plain_Text_Field(
163
-                    'REG_url_link',
164
-                    esc_html__('String to be used in URL for identifying registration', 'event_espresso'),
165
-                    false,
166
-                    ''
167
-                ),
168
-                'REG_count'        => new EE_Integer_Field(
169
-                    'REG_count',
170
-                    esc_html__('Count of this registration in the group registration', 'event_espresso'),
171
-                    true,
172
-                    1
173
-                ),
174
-                'REG_group_size'   => new EE_Integer_Field(
175
-                    'REG_group_size',
176
-                    esc_html__('Number of registrations on this group', 'event_espresso'),
177
-                    false,
178
-                    1
179
-                ),
180
-                'REG_att_is_going' => new EE_Boolean_Field(
181
-                    'REG_att_is_going',
182
-                    esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'),
183
-                    false,
184
-                    false
185
-                ),
186
-                'REG_deleted'      => new EE_Trashed_Flag_Field(
187
-                    'REG_deleted',
188
-                    esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'),
189
-                    false,
190
-                    false
191
-                ),
192
-            ],
193
-        ];
194
-        $this->_model_relations        = [
195
-            'Event'                => new EE_Belongs_To_Relation(),
196
-            'Attendee'             => new EE_Belongs_To_Relation(),
197
-            'Transaction'          => new EE_Belongs_To_Relation(),
198
-            'Ticket'               => new EE_Belongs_To_Relation(),
199
-            'Status'               => new EE_Belongs_To_Relation(),
200
-            'Answer'               => new EE_Has_Many_Relation(),
201
-            'Checkin'              => new EE_Has_Many_Relation(),
202
-            'Registration_Payment' => new EE_Has_Many_Relation(),
203
-            'Payment'              => new EE_HABTM_Relation('Registration_Payment'),
204
-            'Message'              => new EE_Has_Many_Any_Relation(false),
205
-            // allow deletes even if there are messages in the queue related
206
-        ];
207
-        $this->_model_chain_to_wp_user = 'Event';
208
-        parent::__construct($timezone);
209
-    }
210
-
211
-
212
-    /**
213
-     * a list of ALL valid registration statuses currently in use within the system
214
-     * generated by combining the filterable active and inactive reg status arrays
215
-     *
216
-     * @return array
217
-     */
218
-    public static function reg_statuses(): array
219
-    {
220
-        return array_unique(
221
-            array_merge(
222
-                EEM_Registration::active_reg_statuses(),
223
-                EEM_Registration::inactive_reg_statuses()
224
-            )
225
-        );
226
-    }
227
-
228
-
229
-    /**
230
-     * reg_statuses_that_allow_payment
231
-     * a filterable list of registration statuses that allow a registrant to make a payment
232
-     *
233
-     * @access public
234
-     * @return array
235
-     */
236
-    public static function reg_statuses_that_allow_payment(): array
237
-    {
238
-        return (array) apply_filters(
239
-            'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
240
-            [
241
-                RegStatus::APPROVED,
242
-                RegStatus::PENDING_PAYMENT,
243
-            ]
244
-        );
245
-    }
246
-
247
-
248
-    /**
249
-     * active_reg_statuses
250
-     * a filterable list of registration statuses that are considered active
251
-     *
252
-     * @access public
253
-     * @return array
254
-     */
255
-    public static function active_reg_statuses(): array
256
-    {
257
-        return (array) apply_filters(
258
-            'FHEE__EEM_Registration__active_reg_statuses',
259
-            [
260
-                RegStatus::APPROVED,
261
-                RegStatus::PENDING_PAYMENT,
262
-                RegStatus::WAIT_LIST,
263
-                RegStatus::AWAITING_REVIEW,
264
-            ]
265
-        );
266
-    }
267
-
268
-
269
-    /**
270
-     * inactive_reg_statuses
271
-     * a filterable list of registration statuses that are not considered active
272
-     *
273
-     * @access public
274
-     * @return array
275
-     */
276
-    public static function inactive_reg_statuses(): array
277
-    {
278
-        return (array) apply_filters(
279
-            'FHEE__EEM_Registration__inactive_reg_statuses',
280
-            [
281
-                RegStatus::INCOMPLETE,
282
-                RegStatus::CANCELLED,
283
-                RegStatus::DECLINED,
284
-            ]
285
-        );
286
-    }
287
-
288
-
289
-    /**
290
-     *    closed_reg_statuses
291
-     *    a filterable list of registration statuses that are considered "closed"
292
-     * meaning they should not be considered in any calculations involving monies owing
293
-     *
294
-     * @access public
295
-     * @return array
296
-     */
297
-    public static function closed_reg_statuses(): array
298
-    {
299
-        return (array) apply_filters(
300
-            'FHEE__EEM_Registration__closed_reg_statuses',
301
-            [
302
-                RegStatus::CANCELLED,
303
-                RegStatus::DECLINED,
304
-                RegStatus::WAIT_LIST,
305
-            ]
306
-        );
307
-    }
308
-
309
-
310
-    /**
311
-     * get list of registration statuses
312
-     *
313
-     * @param array $exclude    The status ids to exclude from the returned results
314
-     * @param bool  $translated If true will return the values as singular localized strings
315
-     * @return array
316
-     * @throws EE_Error
317
-     * @throws ReflectionException
318
-     */
319
-    public static function reg_status_array(array $exclude = [], bool $translated = false): array
320
-    {
321
-        if (empty(self::$_reg_status)) {
322
-            EEM_Registration::instance()->_get_registration_status_array($exclude);
323
-        } elseif ($exclude) {
324
-            foreach ($exclude as $excluded_status) {
325
-                unset(self::$_reg_status[ $excluded_status ]);
326
-            }
327
-        }
328
-        return $translated
329
-            ? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
330
-            : self::$_reg_status;
331
-    }
332
-
333
-
334
-    /**
335
-     * get list of registration statuses
336
-     *
337
-     * @param array $exclude
338
-     * @param bool  $recurse
339
-     * @return void
340
-     * @throws EE_Error
341
-     * @throws ReflectionException
342
-     */
343
-    private function _get_registration_status_array(array $exclude = [], bool $recurse = true)
344
-    {
345
-        // in the very rare circumstance that we are deleting a model's table's data
346
-        // and the table hasn't actually been created, this could have an error
347
-        /** @type WPDB $wpdb */
348
-        global $wpdb;
349
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
350
-            $results           = $wpdb->get_results(
351
-                "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
352
-            );
353
-            self::$_reg_status = [];
354
-            foreach ($results as $status) {
355
-                if (! in_array($status->STS_ID, $exclude, true)) {
356
-                    self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
357
-                }
358
-            }
359
-        }
360
-        // in case reg status codes have been deleted from db
361
-        if ($recurse && empty(self::$_reg_status)) {
362
-            EEH_Activation::insert_default_status_codes();
363
-            $this->_get_registration_status_array($exclude, false);
364
-        }
365
-    }
366
-
367
-
368
-    /**
369
-     * Gets the injected table analyzer, or throws an exception
370
-     *
371
-     * @return TableAnalysis
372
-     * @throws EE_Error
373
-     */
374
-    protected function _get_table_analysis(): TableAnalysis
375
-    {
376
-        if ($this->_table_analysis instanceof TableAnalysis) {
377
-            return $this->_table_analysis;
378
-        }
379
-        throw new EE_Error(
380
-            sprintf(
381
-                esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
382
-                get_class($this)
383
-            )
384
-        );
385
-    }
386
-
387
-
388
-    /**
389
-     * This returns a wpdb->results array of all registration date month and years matching the incoming query params
390
-     * and grouped by month and year.
391
-     *
392
-     * @param array $where_params
393
-     * @return bool|stdClass[]
394
-     * @throws EE_Error
395
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
396
-     */
397
-    public function get_reg_months_and_years(array $where_params)
398
-    {
399
-        $query_params[0]          = $where_params;
400
-        $query_params['group_by'] = ['reg_year', 'reg_month'];
401
-        $query_params['order_by'] = ['REG_date' => 'DESC'];
402
-        $columns_to_select        = [
403
-            'reg_year'  => ['YEAR(REG_date)', '%s'],
404
-            'reg_month' => ['MONTHNAME(REG_date)', '%s'],
405
-        ];
406
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
407
-    }
408
-
409
-
410
-    /**
411
-     * retrieve ALL registrations for a particular Attendee from db
412
-     *
413
-     * @param int $ATT_ID
414
-     * @return EE_Registration[]|bool|null
415
-     * @throws EE_Error
416
-     * @throws ReflectionException
417
-     */
418
-    public function get_all_registrations_for_attendee(int $ATT_ID = 0): ?array
419
-    {
420
-        if (! $ATT_ID) {
421
-            return null;
422
-        }
423
-        return $this->get_all([['ATT_ID' => $ATT_ID]]);
424
-    }
425
-
426
-
427
-    /**
428
-     * Gets a registration given their REG_url_link. Yes, this should usually
429
-     * be passed via a GET parameter.
430
-     *
431
-     * @param string $REG_url_link
432
-     * @return EE_Registration|null
433
-     * @throws EE_Error
434
-     */
435
-    public function get_registration_for_reg_url_link(string $REG_url_link): ?EE_Registration
436
-    {
437
-        if (! $REG_url_link) {
438
-            return null;
439
-        }
440
-        return $this->get_one([['REG_url_link' => $REG_url_link]]);
441
-    }
442
-
443
-
444
-    /**
445
-     *        retrieve registration for a specific transaction attendee from db
446
-     *
447
-     * @access        public
448
-     * @param int $TXN_ID
449
-     * @param int $ATT_ID
450
-     * @param int $att_nmbr    in case the ATT_ID is the same for multiple registrations (same details used) then the
451
-     *                         attendee number is required
452
-     * @return EE_Registration|null array on success, FALSE on fail
453
-     * @throws EE_Error
454
-     */
455
-    public function get_registration_for_transaction_attendee(int $TXN_ID = 0, int $ATT_ID = 0, int $att_nmbr = 0):
456
-    ?EE_Registration {
457
-        return $this->get_one(
458
-            [
459
-                [
460
-                    'TXN_ID' => $TXN_ID,
461
-                    'ATT_ID' => $ATT_ID,
462
-                ],
463
-                'limit' => [min($att_nmbr - 1, 0), 1],
464
-            ]
465
-        );
466
-    }
467
-
468
-
469
-    /**
470
-     *        get the number of registrations per day  for the Registration Admin page Reports Tab.
471
-     *        (doesn't utilize models because it's a fairly specialized query)
472
-     *
473
-     * @access        public
474
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
475
-     * @return EE_Registration[]|bool|null with properties regDate and total
476
-     * @throws EE_Error
477
-     */
478
-    public function get_registrations_per_day_report(string $period = '-1 month')
479
-    {
480
-        $sql_date = $this->convert_datetime_for_query(
481
-            'REG_date',
482
-            date('Y-m-d H:i:s', strtotime($period)),
483
-            'Y-m-d H:i:s',
484
-            'UTC'
485
-        );
486
-        $where    = [
487
-            'REG_date' => ['>=', $sql_date],
488
-            'STS_ID'   => ['!=', RegStatus::INCOMPLETE],
489
-        ];
490
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
491
-            $where['Event.EVT_wp_user'] = get_current_user_id();
492
-        }
493
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
494
-        return $this->_get_all_wpdb_results(
495
-            [
496
-                $where,
497
-                'group_by' => 'regDate',
498
-                'order_by' => ['REG_date' => 'ASC'],
499
-            ],
500
-            OBJECT,
501
-            [
502
-                'regDate' => ['DATE(' . $query_interval . ')', '%s'],
503
-                'total'   => ['count(REG_ID)', '%d'],
504
-            ]
505
-        );
506
-    }
507
-
508
-
509
-    /**
510
-     * Get the number of registrations per day including the count of registrations for each Registration Status.
511
-     * Note: RegStatus::INCOMPLETE registrations are excluded from the results.
512
-     *
513
-     * @param string $period
514
-     * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
515
-     * @throws EE_Error
516
-     *                    (i.e. RAP)
517
-     * @throws EE_Error|ReflectionException
518
-     */
519
-    public function get_registrations_per_day_and_per_status_report(string $period = '-1 month'): array
520
-    {
521
-        global $wpdb;
522
-        $registration_table = $wpdb->prefix . 'esp_registration';
523
-        $event_table        = $wpdb->posts;
524
-        $sql_date           = date('Y-m-d H:i:s', strtotime($period));
525
-        // prepare the query interval for displaying offset
526
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
527
-        // inner date query
528
-        $inner_date_query = "SELECT DISTINCT REG_date from $registration_table ";
529
-        $inner_where      = ' WHERE';
530
-        // exclude events not authored by user if permissions in effect
531
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
532
-            $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
533
-            $inner_where      .= ' post_author = ' . get_current_user_id() . ' AND';
534
-        }
535
-        $inner_where      .= " REG_date >= '$sql_date'";
536
-        $inner_date_query .= $inner_where;
537
-        // start main query
538
-        $select       = "SELECT DATE($query_interval) as Registration_REG_date, ";
539
-        $join         = '';
540
-        $join_parts   = [];
541
-        $select_parts = [];
542
-        // loop through registration stati to do parts for each status.
543
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
544
-            if ($STS_ID === RegStatus::INCOMPLETE) {
545
-                continue;
546
-            }
547
-            $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
548
-            $join_parts[]   =
549
-                "$registration_table AS $STS_code ON $STS_code.REG_date = dates.REG_date AND $STS_code.STS_ID = '$STS_ID'";
550
-        }
551
-        // setup the selects
552
-        $select .= implode(', ', $select_parts);
553
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
554
-        // setup the joins
555
-        $join .= implode(' LEFT JOIN ', $join_parts);
556
-        // now let's put it all together
557
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
558
-        // and execute it
559
-        return $wpdb->get_results($query, ARRAY_A);
560
-    }
561
-
562
-
563
-    /**
564
-     *        get the number of registrations per event  for the Registration Admin page Reports Tab
565
-     *
566
-     * @access        public
567
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
568
-     * @return stdClass[] each with properties event_name, reg_limit, and total
569
-     * @throws EE_Error
570
-     */
571
-    public function get_registrations_per_event_report(string $period = '-1 month'): array
572
-    {
573
-        $date_sql = $this->convert_datetime_for_query(
574
-            'REG_date',
575
-            date('Y-m-d H:i:s', strtotime($period)),
576
-            'Y-m-d H:i:s',
577
-            'UTC'
578
-        );
579
-        $where    = [
580
-            'REG_date' => ['>=', $date_sql],
581
-            'STS_ID'   => ['!=', RegStatus::INCOMPLETE],
582
-        ];
583
-        if (
584
-            ! EE_Registry::instance()->CAP->current_user_can(
585
-                'ee_read_others_registrations',
586
-                'reg_per_event_report'
587
-            )
588
-        ) {
589
-            $where['Event.EVT_wp_user'] = get_current_user_id();
590
-        }
591
-        return $this->_get_all_wpdb_results(
592
-            [
593
-                $where,
594
-                'group_by' => 'Event.EVT_name',
595
-                'order_by' => 'Event.EVT_name',
596
-                'limit'    => [0, 24],
597
-            ],
598
-            OBJECT,
599
-            [
600
-                'event_name' => ['Event_CPT.post_title', '%s'],
601
-                'total'      => ['COUNT(REG_ID)', '%s'],
602
-            ]
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * Get the number of registrations per event grouped by registration status.
609
-     * Note: RegStatus::INCOMPLETE registrations are excluded from the results.
610
-     *
611
-     * @param string $period
612
-     * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
613
-     *                    (i.e. RAP)
614
-     * @throws EE_Error
615
-     * @throws ReflectionException
616
-     */
617
-    public function get_registrations_per_event_and_per_status_report(string $period = '-1 month'): array
618
-    {
619
-        global $wpdb;
620
-        $registration_table = $wpdb->prefix . 'esp_registration';
621
-        $event_table        = $wpdb->posts;
622
-        $sql_date           = date('Y-m-d H:i:s', strtotime($period));
623
-        // inner date query
624
-        $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
625
-        $inner_where      = ' WHERE';
626
-        // exclude events not authored by user if permissions in effect
627
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
628
-            $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
629
-            $inner_where      .= ' post_author = ' . get_current_user_id() . ' AND';
630
-        }
631
-        $inner_where      .= " REG_date >= '$sql_date'";
632
-        $inner_date_query .= $inner_where;
633
-        // build main query
634
-        $select       = 'SELECT Event.post_title as Registration_Event, ';
635
-        $join         = '';
636
-        $join_parts   = [];
637
-        $select_parts = [];
638
-        // loop through registration stati to do parts for each status.
639
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
640
-            if ($STS_ID === RegStatus::INCOMPLETE) {
641
-                continue;
642
-            }
643
-            $select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
644
-            $join_parts[]   =
645
-                "$registration_table AS $STS_code ON $STS_code.EVT_ID = dates.EVT_ID AND $STS_code.STS_ID = '$STS_ID' AND $STS_code.REG_date = dates.REG_date";
646
-        }
647
-        // setup the selects
648
-        $select .= implode(', ', $select_parts);
649
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
650
-        // setup remaining joins
651
-        $join .= implode(' LEFT JOIN ', $join_parts);
652
-        // now put it all together
653
-        $query = $select . $join . ' GROUP BY Registration_Event';
654
-        // and execute
655
-        return $wpdb->get_results($query, ARRAY_A);
656
-    }
657
-
658
-
659
-    /**
660
-     * Returns the EE_Registration of the primary attendee on the transaction id provided
661
-     *
662
-     * @param int $TXN_ID
663
-     * @return EE_Registration|null
664
-     * @throws EE_Error
665
-     */
666
-    public function get_primary_registration_for_transaction_ID(int $TXN_ID = 0): ?EE_Registration
667
-    {
668
-        if (! $TXN_ID) {
669
-            return null;
670
-        }
671
-        return $this->get_one(
672
-            [
673
-                [
674
-                    'TXN_ID'    => $TXN_ID,
675
-                    'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
676
-                ],
677
-            ]
678
-        );
679
-    }
680
-
681
-
682
-    /**
683
-     *        get_event_registration_count
684
-     *
685
-     * @access public
686
-     * @param int     $EVT_ID
687
-     * @param boolean $for_incomplete_payments
688
-     * @return int
689
-     * @throws EE_Error
690
-     */
691
-    public function get_event_registration_count(int $EVT_ID, bool $for_incomplete_payments = false): int
692
-    {
693
-        // we only count approved registrations towards registration limits
694
-        $query_params = [['EVT_ID' => $EVT_ID, 'STS_ID' => RegStatus::APPROVED]];
695
-        if ($for_incomplete_payments) {
696
-            $query_params[0]['Transaction.STS_ID'] = ['!=', EEM_Transaction::complete_status_code];
697
-        }
698
-        return $this->count($query_params);
699
-    }
700
-
701
-
702
-    /**
703
-     * Deletes all registrations with no transactions. Note that this needs to be very efficient
704
-     * and so it uses wpdb directly. Also, we can't put a limit on this because MySQL doesn't allow a limit on a delete
705
-     * when joining tables like this.
706
-     *
707
-     * @return int|bool number deleted
708
-     * @throws EE_Error
709
-     * @throws ReflectionException
710
-     * @global WPDB $wpdb
711
-     */
712
-    public function delete_registrations_with_no_transaction()
713
-    {
714
-        /** @type WPDB $wpdb */
715
-        global $wpdb;
716
-        return $wpdb->query(
717
-            'DELETE r FROM '
718
-            . $this->table()
719
-            . ' r LEFT JOIN '
720
-            . EEM_Transaction::instance()->table()
721
-            . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL'
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     *  Count registrations checked into (or out of) a datetime
728
-     *
729
-     * @param int  $DTT_ID     datetime ID
730
-     * @param bool $checked_in whether to count registrations checked IN or OUT
731
-     * @return int
732
-     * @throws EE_Error
733
-     * @throws ReflectionException
734
-     * @throws ReflectionException
735
-     */
736
-    public function count_registrations_checked_into_datetime(int $DTT_ID, bool $checked_in = true): int
737
-    {
738
-        global $wpdb;
739
-        // subquery to get latest checkin
740
-        $query = $wpdb->prepare(
741
-            'SELECT '
742
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
743
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
744
-            . '( SELECT '
745
-            . 'max( CHK_timestamp ) AS latest_checkin, '
746
-            . 'REG_ID AS REG_ID '
747
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
748
-            . 'WHERE DTT_ID=%d '
749
-            . 'GROUP BY REG_ID'
750
-            . ') AS most_recent_checkin_per_reg '
751
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
752
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
753
-            . 'WHERE '
754
-            . 'checkins.CHK_in=%d',
755
-            $DTT_ID,
756
-            $checked_in
757
-        );
758
-        return (int) $wpdb->get_var($query);
759
-    }
760
-
761
-
762
-    /**
763
-     *  Count registrations checked into (or out of) an event.
764
-     *
765
-     * @param int  $EVT_ID     event ID
766
-     * @param bool $checked_in whether to count registrations checked IN or OUT
767
-     * @return int
768
-     * @throws EE_Error
769
-     * @throws ReflectionException
770
-     * @throws ReflectionException
771
-     * @throws ReflectionException
772
-     */
773
-    public function count_registrations_checked_into_event(int $EVT_ID, bool $checked_in = true): int
774
-    {
775
-        global $wpdb;
776
-        // subquery to get latest checkin
777
-        $query = $wpdb->prepare(
778
-            'SELECT '
779
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
780
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
781
-            . '( SELECT '
782
-            . 'max( CHK_timestamp ) AS latest_checkin, '
783
-            . 'REG_ID AS REG_ID '
784
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
785
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
786
-            . 'ON c.DTT_ID=d.DTT_ID '
787
-            . 'WHERE d.EVT_ID=%d '
788
-            . 'GROUP BY REG_ID'
789
-            . ') AS most_recent_checkin_per_reg '
790
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
791
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
792
-            . 'WHERE '
793
-            . 'checkins.CHK_in=%d',
794
-            $EVT_ID,
795
-            $checked_in
796
-        );
797
-        return (int) $wpdb->get_var($query);
798
-    }
799
-
800
-
801
-    /**
802
-     * The purpose of this method is to retrieve an array of
803
-     * EE_Registration objects that represent the latest registration
804
-     * for each ATT_ID given in the function argument.
805
-     *
806
-     * @param array $attendee_ids
807
-     * @return EE_Registration[]|bool|null
808
-     * @throws EE_Error
809
-     * @throws ReflectionException
810
-     */
811
-    public function get_latest_registration_for_each_of_given_contacts(array $attendee_ids = [])
812
-    {
813
-        // first do a native wp_query to get the latest REG_ID's matching these attendees.
814
-        global $wpdb;
815
-        $registration_table = $wpdb->prefix . 'esp_registration';
816
-        $attendee_table     = $wpdb->posts;
817
-        $attendee_ids       = is_array($attendee_ids)
818
-            ? array_map('absint', $attendee_ids)
819
-            : [(int) $attendee_ids];
820
-        $ATT_IDs            = implode(',', $attendee_ids);
821
-        // first we do a query to get the registration ids
822
-        // (because a group by before order by causes the order by to be ignored.)
823
-        $registration_id_query = "
18
+	/**
19
+	 * The value of REG_count for a primary registrant
20
+	 */
21
+	const PRIMARY_REGISTRANT_COUNT = 1;
22
+
23
+	/**
24
+	 * @depecated 5.0.20.p  use RegStatus::INCOMPLETE instead
25
+	 */
26
+	const status_id_incomplete = 'RIC';
27
+
28
+	/**
29
+	 * @depecated 5.0.20.p  use RegStatus::AWAITING_REVIEW instead
30
+	 */
31
+	const status_id_not_approved = 'RNA';
32
+
33
+	/**
34
+	 * @depecated 5.0.20.p  use RegStatus::PENDING_PAYMENT instead
35
+	 */
36
+	const status_id_pending_payment = 'RPP';
37
+
38
+	/**
39
+	 * @depecated 5.0.20.p  use RegStatus::WAIT_LIST instead
40
+	 */
41
+	const status_id_wait_list = 'RWL';
42
+
43
+	/**
44
+	 * @depecated 5.0.20.p  use RegStatus::APPROVED instead
45
+	 */
46
+	const status_id_approved = 'RAP';
47
+
48
+	/**
49
+	 * @depecated 5.0.20.p  use RegStatus::CANCELLED instead
50
+	 */
51
+	const status_id_cancelled = 'RCN';
52
+
53
+	/**
54
+	 * @depecated 5.0.20.p  use RegStatus::DECLINED instead
55
+	 */
56
+	const status_id_declined = 'RDC';
57
+
58
+
59
+	protected static ?EEM_Registration $_instance       = null;
60
+
61
+	protected ?TableAnalysis           $_table_analysis = null;
62
+
63
+	/**
64
+	 * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
65
+	 * are status codes (eg, approved, cancelled, etc)
66
+	 *
67
+	 * @var array|null
68
+	 */
69
+	private static array $_reg_status = [];
70
+
71
+
72
+	/**
73
+	 * private constructor to prevent direct creation
74
+	 *
75
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
76
+	 *                              any incoming timezone data that gets saved). Note this just sends the timezone info
77
+	 *                              to the date time model field objects.  Default is NULL (and will be assumed using
78
+	 *                              the set timezone in the 'timezone_string' wp option)
79
+	 * @throws EE_Error
80
+	 * @throws ReflectionException
81
+	 */
82
+	protected function __construct(?string $timezone = '')
83
+	{
84
+		$this->_table_analysis         = EE_Registry::instance()->create('TableAnalysis', [], true);
85
+		$this->singular_item           = esc_html__('Registration', 'event_espresso');
86
+		$this->plural_item             = esc_html__('Registrations', 'event_espresso');
87
+		$this->_tables                 = [
88
+			'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
89
+		];
90
+		$this->_fields                 = [
91
+			'Registration' => [
92
+				'REG_ID'           => new EE_Primary_Key_Int_Field(
93
+					'REG_ID',
94
+					esc_html__('Registration ID', 'event_espresso')
95
+				),
96
+				'EVT_ID'           => new EE_Foreign_Key_Int_Field(
97
+					'EVT_ID',
98
+					esc_html__('Event ID', 'event_espresso'),
99
+					false,
100
+					0,
101
+					'Event'
102
+				),
103
+				'ATT_ID'           => new EE_Foreign_Key_Int_Field(
104
+					'ATT_ID',
105
+					esc_html__('Attendee ID', 'event_espresso'),
106
+					false,
107
+					0,
108
+					'Attendee'
109
+				),
110
+				'TXN_ID'           => new EE_Foreign_Key_Int_Field(
111
+					'TXN_ID',
112
+					esc_html__('Transaction ID', 'event_espresso'),
113
+					false,
114
+					0,
115
+					'Transaction'
116
+				),
117
+				'TKT_ID'           => new EE_Foreign_Key_Int_Field(
118
+					'TKT_ID',
119
+					esc_html__('Ticket ID', 'event_espresso'),
120
+					false,
121
+					0,
122
+					'Ticket'
123
+				),
124
+				'STS_ID'           => new EE_Foreign_Key_String_Field(
125
+					'STS_ID',
126
+					esc_html__('Status ID', 'event_espresso'),
127
+					false,
128
+					RegStatus::INCOMPLETE,
129
+					'Status'
130
+				),
131
+				'REG_date'         => new EE_Datetime_Field(
132
+					'REG_date',
133
+					esc_html__('Time registration occurred', 'event_espresso'),
134
+					false,
135
+					EE_Datetime_Field::now,
136
+					$timezone
137
+				),
138
+				'REG_final_price'  => new EE_Money_Field(
139
+					'REG_final_price',
140
+					esc_html__('Registration\'s share of the transaction total', 'event_espresso'),
141
+					false,
142
+					0
143
+				),
144
+				'REG_paid'         => new EE_Money_Field(
145
+					'REG_paid',
146
+					esc_html__('Amount paid to date towards registration', 'event_espresso'),
147
+					false,
148
+					0
149
+				),
150
+				'REG_session'      => new EE_Plain_Text_Field(
151
+					'REG_session',
152
+					esc_html__('Session ID of registration', 'event_espresso'),
153
+					false,
154
+					''
155
+				),
156
+				'REG_code'         => new EE_Plain_Text_Field(
157
+					'REG_code',
158
+					esc_html__('Unique Code for this registration', 'event_espresso'),
159
+					false,
160
+					''
161
+				),
162
+				'REG_url_link'     => new EE_Plain_Text_Field(
163
+					'REG_url_link',
164
+					esc_html__('String to be used in URL for identifying registration', 'event_espresso'),
165
+					false,
166
+					''
167
+				),
168
+				'REG_count'        => new EE_Integer_Field(
169
+					'REG_count',
170
+					esc_html__('Count of this registration in the group registration', 'event_espresso'),
171
+					true,
172
+					1
173
+				),
174
+				'REG_group_size'   => new EE_Integer_Field(
175
+					'REG_group_size',
176
+					esc_html__('Number of registrations on this group', 'event_espresso'),
177
+					false,
178
+					1
179
+				),
180
+				'REG_att_is_going' => new EE_Boolean_Field(
181
+					'REG_att_is_going',
182
+					esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'),
183
+					false,
184
+					false
185
+				),
186
+				'REG_deleted'      => new EE_Trashed_Flag_Field(
187
+					'REG_deleted',
188
+					esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'),
189
+					false,
190
+					false
191
+				),
192
+			],
193
+		];
194
+		$this->_model_relations        = [
195
+			'Event'                => new EE_Belongs_To_Relation(),
196
+			'Attendee'             => new EE_Belongs_To_Relation(),
197
+			'Transaction'          => new EE_Belongs_To_Relation(),
198
+			'Ticket'               => new EE_Belongs_To_Relation(),
199
+			'Status'               => new EE_Belongs_To_Relation(),
200
+			'Answer'               => new EE_Has_Many_Relation(),
201
+			'Checkin'              => new EE_Has_Many_Relation(),
202
+			'Registration_Payment' => new EE_Has_Many_Relation(),
203
+			'Payment'              => new EE_HABTM_Relation('Registration_Payment'),
204
+			'Message'              => new EE_Has_Many_Any_Relation(false),
205
+			// allow deletes even if there are messages in the queue related
206
+		];
207
+		$this->_model_chain_to_wp_user = 'Event';
208
+		parent::__construct($timezone);
209
+	}
210
+
211
+
212
+	/**
213
+	 * a list of ALL valid registration statuses currently in use within the system
214
+	 * generated by combining the filterable active and inactive reg status arrays
215
+	 *
216
+	 * @return array
217
+	 */
218
+	public static function reg_statuses(): array
219
+	{
220
+		return array_unique(
221
+			array_merge(
222
+				EEM_Registration::active_reg_statuses(),
223
+				EEM_Registration::inactive_reg_statuses()
224
+			)
225
+		);
226
+	}
227
+
228
+
229
+	/**
230
+	 * reg_statuses_that_allow_payment
231
+	 * a filterable list of registration statuses that allow a registrant to make a payment
232
+	 *
233
+	 * @access public
234
+	 * @return array
235
+	 */
236
+	public static function reg_statuses_that_allow_payment(): array
237
+	{
238
+		return (array) apply_filters(
239
+			'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
240
+			[
241
+				RegStatus::APPROVED,
242
+				RegStatus::PENDING_PAYMENT,
243
+			]
244
+		);
245
+	}
246
+
247
+
248
+	/**
249
+	 * active_reg_statuses
250
+	 * a filterable list of registration statuses that are considered active
251
+	 *
252
+	 * @access public
253
+	 * @return array
254
+	 */
255
+	public static function active_reg_statuses(): array
256
+	{
257
+		return (array) apply_filters(
258
+			'FHEE__EEM_Registration__active_reg_statuses',
259
+			[
260
+				RegStatus::APPROVED,
261
+				RegStatus::PENDING_PAYMENT,
262
+				RegStatus::WAIT_LIST,
263
+				RegStatus::AWAITING_REVIEW,
264
+			]
265
+		);
266
+	}
267
+
268
+
269
+	/**
270
+	 * inactive_reg_statuses
271
+	 * a filterable list of registration statuses that are not considered active
272
+	 *
273
+	 * @access public
274
+	 * @return array
275
+	 */
276
+	public static function inactive_reg_statuses(): array
277
+	{
278
+		return (array) apply_filters(
279
+			'FHEE__EEM_Registration__inactive_reg_statuses',
280
+			[
281
+				RegStatus::INCOMPLETE,
282
+				RegStatus::CANCELLED,
283
+				RegStatus::DECLINED,
284
+			]
285
+		);
286
+	}
287
+
288
+
289
+	/**
290
+	 *    closed_reg_statuses
291
+	 *    a filterable list of registration statuses that are considered "closed"
292
+	 * meaning they should not be considered in any calculations involving monies owing
293
+	 *
294
+	 * @access public
295
+	 * @return array
296
+	 */
297
+	public static function closed_reg_statuses(): array
298
+	{
299
+		return (array) apply_filters(
300
+			'FHEE__EEM_Registration__closed_reg_statuses',
301
+			[
302
+				RegStatus::CANCELLED,
303
+				RegStatus::DECLINED,
304
+				RegStatus::WAIT_LIST,
305
+			]
306
+		);
307
+	}
308
+
309
+
310
+	/**
311
+	 * get list of registration statuses
312
+	 *
313
+	 * @param array $exclude    The status ids to exclude from the returned results
314
+	 * @param bool  $translated If true will return the values as singular localized strings
315
+	 * @return array
316
+	 * @throws EE_Error
317
+	 * @throws ReflectionException
318
+	 */
319
+	public static function reg_status_array(array $exclude = [], bool $translated = false): array
320
+	{
321
+		if (empty(self::$_reg_status)) {
322
+			EEM_Registration::instance()->_get_registration_status_array($exclude);
323
+		} elseif ($exclude) {
324
+			foreach ($exclude as $excluded_status) {
325
+				unset(self::$_reg_status[ $excluded_status ]);
326
+			}
327
+		}
328
+		return $translated
329
+			? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
330
+			: self::$_reg_status;
331
+	}
332
+
333
+
334
+	/**
335
+	 * get list of registration statuses
336
+	 *
337
+	 * @param array $exclude
338
+	 * @param bool  $recurse
339
+	 * @return void
340
+	 * @throws EE_Error
341
+	 * @throws ReflectionException
342
+	 */
343
+	private function _get_registration_status_array(array $exclude = [], bool $recurse = true)
344
+	{
345
+		// in the very rare circumstance that we are deleting a model's table's data
346
+		// and the table hasn't actually been created, this could have an error
347
+		/** @type WPDB $wpdb */
348
+		global $wpdb;
349
+		if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
350
+			$results           = $wpdb->get_results(
351
+				"SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
352
+			);
353
+			self::$_reg_status = [];
354
+			foreach ($results as $status) {
355
+				if (! in_array($status->STS_ID, $exclude, true)) {
356
+					self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
357
+				}
358
+			}
359
+		}
360
+		// in case reg status codes have been deleted from db
361
+		if ($recurse && empty(self::$_reg_status)) {
362
+			EEH_Activation::insert_default_status_codes();
363
+			$this->_get_registration_status_array($exclude, false);
364
+		}
365
+	}
366
+
367
+
368
+	/**
369
+	 * Gets the injected table analyzer, or throws an exception
370
+	 *
371
+	 * @return TableAnalysis
372
+	 * @throws EE_Error
373
+	 */
374
+	protected function _get_table_analysis(): TableAnalysis
375
+	{
376
+		if ($this->_table_analysis instanceof TableAnalysis) {
377
+			return $this->_table_analysis;
378
+		}
379
+		throw new EE_Error(
380
+			sprintf(
381
+				esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
382
+				get_class($this)
383
+			)
384
+		);
385
+	}
386
+
387
+
388
+	/**
389
+	 * This returns a wpdb->results array of all registration date month and years matching the incoming query params
390
+	 * and grouped by month and year.
391
+	 *
392
+	 * @param array $where_params
393
+	 * @return bool|stdClass[]
394
+	 * @throws EE_Error
395
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
396
+	 */
397
+	public function get_reg_months_and_years(array $where_params)
398
+	{
399
+		$query_params[0]          = $where_params;
400
+		$query_params['group_by'] = ['reg_year', 'reg_month'];
401
+		$query_params['order_by'] = ['REG_date' => 'DESC'];
402
+		$columns_to_select        = [
403
+			'reg_year'  => ['YEAR(REG_date)', '%s'],
404
+			'reg_month' => ['MONTHNAME(REG_date)', '%s'],
405
+		];
406
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
407
+	}
408
+
409
+
410
+	/**
411
+	 * retrieve ALL registrations for a particular Attendee from db
412
+	 *
413
+	 * @param int $ATT_ID
414
+	 * @return EE_Registration[]|bool|null
415
+	 * @throws EE_Error
416
+	 * @throws ReflectionException
417
+	 */
418
+	public function get_all_registrations_for_attendee(int $ATT_ID = 0): ?array
419
+	{
420
+		if (! $ATT_ID) {
421
+			return null;
422
+		}
423
+		return $this->get_all([['ATT_ID' => $ATT_ID]]);
424
+	}
425
+
426
+
427
+	/**
428
+	 * Gets a registration given their REG_url_link. Yes, this should usually
429
+	 * be passed via a GET parameter.
430
+	 *
431
+	 * @param string $REG_url_link
432
+	 * @return EE_Registration|null
433
+	 * @throws EE_Error
434
+	 */
435
+	public function get_registration_for_reg_url_link(string $REG_url_link): ?EE_Registration
436
+	{
437
+		if (! $REG_url_link) {
438
+			return null;
439
+		}
440
+		return $this->get_one([['REG_url_link' => $REG_url_link]]);
441
+	}
442
+
443
+
444
+	/**
445
+	 *        retrieve registration for a specific transaction attendee from db
446
+	 *
447
+	 * @access        public
448
+	 * @param int $TXN_ID
449
+	 * @param int $ATT_ID
450
+	 * @param int $att_nmbr    in case the ATT_ID is the same for multiple registrations (same details used) then the
451
+	 *                         attendee number is required
452
+	 * @return EE_Registration|null array on success, FALSE on fail
453
+	 * @throws EE_Error
454
+	 */
455
+	public function get_registration_for_transaction_attendee(int $TXN_ID = 0, int $ATT_ID = 0, int $att_nmbr = 0):
456
+	?EE_Registration {
457
+		return $this->get_one(
458
+			[
459
+				[
460
+					'TXN_ID' => $TXN_ID,
461
+					'ATT_ID' => $ATT_ID,
462
+				],
463
+				'limit' => [min($att_nmbr - 1, 0), 1],
464
+			]
465
+		);
466
+	}
467
+
468
+
469
+	/**
470
+	 *        get the number of registrations per day  for the Registration Admin page Reports Tab.
471
+	 *        (doesn't utilize models because it's a fairly specialized query)
472
+	 *
473
+	 * @access        public
474
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
475
+	 * @return EE_Registration[]|bool|null with properties regDate and total
476
+	 * @throws EE_Error
477
+	 */
478
+	public function get_registrations_per_day_report(string $period = '-1 month')
479
+	{
480
+		$sql_date = $this->convert_datetime_for_query(
481
+			'REG_date',
482
+			date('Y-m-d H:i:s', strtotime($period)),
483
+			'Y-m-d H:i:s',
484
+			'UTC'
485
+		);
486
+		$where    = [
487
+			'REG_date' => ['>=', $sql_date],
488
+			'STS_ID'   => ['!=', RegStatus::INCOMPLETE],
489
+		];
490
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
491
+			$where['Event.EVT_wp_user'] = get_current_user_id();
492
+		}
493
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
494
+		return $this->_get_all_wpdb_results(
495
+			[
496
+				$where,
497
+				'group_by' => 'regDate',
498
+				'order_by' => ['REG_date' => 'ASC'],
499
+			],
500
+			OBJECT,
501
+			[
502
+				'regDate' => ['DATE(' . $query_interval . ')', '%s'],
503
+				'total'   => ['count(REG_ID)', '%d'],
504
+			]
505
+		);
506
+	}
507
+
508
+
509
+	/**
510
+	 * Get the number of registrations per day including the count of registrations for each Registration Status.
511
+	 * Note: RegStatus::INCOMPLETE registrations are excluded from the results.
512
+	 *
513
+	 * @param string $period
514
+	 * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
515
+	 * @throws EE_Error
516
+	 *                    (i.e. RAP)
517
+	 * @throws EE_Error|ReflectionException
518
+	 */
519
+	public function get_registrations_per_day_and_per_status_report(string $period = '-1 month'): array
520
+	{
521
+		global $wpdb;
522
+		$registration_table = $wpdb->prefix . 'esp_registration';
523
+		$event_table        = $wpdb->posts;
524
+		$sql_date           = date('Y-m-d H:i:s', strtotime($period));
525
+		// prepare the query interval for displaying offset
526
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
527
+		// inner date query
528
+		$inner_date_query = "SELECT DISTINCT REG_date from $registration_table ";
529
+		$inner_where      = ' WHERE';
530
+		// exclude events not authored by user if permissions in effect
531
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
532
+			$inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
533
+			$inner_where      .= ' post_author = ' . get_current_user_id() . ' AND';
534
+		}
535
+		$inner_where      .= " REG_date >= '$sql_date'";
536
+		$inner_date_query .= $inner_where;
537
+		// start main query
538
+		$select       = "SELECT DATE($query_interval) as Registration_REG_date, ";
539
+		$join         = '';
540
+		$join_parts   = [];
541
+		$select_parts = [];
542
+		// loop through registration stati to do parts for each status.
543
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
544
+			if ($STS_ID === RegStatus::INCOMPLETE) {
545
+				continue;
546
+			}
547
+			$select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
548
+			$join_parts[]   =
549
+				"$registration_table AS $STS_code ON $STS_code.REG_date = dates.REG_date AND $STS_code.STS_ID = '$STS_ID'";
550
+		}
551
+		// setup the selects
552
+		$select .= implode(', ', $select_parts);
553
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
554
+		// setup the joins
555
+		$join .= implode(' LEFT JOIN ', $join_parts);
556
+		// now let's put it all together
557
+		$query = $select . $join . ' GROUP BY Registration_REG_date';
558
+		// and execute it
559
+		return $wpdb->get_results($query, ARRAY_A);
560
+	}
561
+
562
+
563
+	/**
564
+	 *        get the number of registrations per event  for the Registration Admin page Reports Tab
565
+	 *
566
+	 * @access        public
567
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
568
+	 * @return stdClass[] each with properties event_name, reg_limit, and total
569
+	 * @throws EE_Error
570
+	 */
571
+	public function get_registrations_per_event_report(string $period = '-1 month'): array
572
+	{
573
+		$date_sql = $this->convert_datetime_for_query(
574
+			'REG_date',
575
+			date('Y-m-d H:i:s', strtotime($period)),
576
+			'Y-m-d H:i:s',
577
+			'UTC'
578
+		);
579
+		$where    = [
580
+			'REG_date' => ['>=', $date_sql],
581
+			'STS_ID'   => ['!=', RegStatus::INCOMPLETE],
582
+		];
583
+		if (
584
+			! EE_Registry::instance()->CAP->current_user_can(
585
+				'ee_read_others_registrations',
586
+				'reg_per_event_report'
587
+			)
588
+		) {
589
+			$where['Event.EVT_wp_user'] = get_current_user_id();
590
+		}
591
+		return $this->_get_all_wpdb_results(
592
+			[
593
+				$where,
594
+				'group_by' => 'Event.EVT_name',
595
+				'order_by' => 'Event.EVT_name',
596
+				'limit'    => [0, 24],
597
+			],
598
+			OBJECT,
599
+			[
600
+				'event_name' => ['Event_CPT.post_title', '%s'],
601
+				'total'      => ['COUNT(REG_ID)', '%s'],
602
+			]
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * Get the number of registrations per event grouped by registration status.
609
+	 * Note: RegStatus::INCOMPLETE registrations are excluded from the results.
610
+	 *
611
+	 * @param string $period
612
+	 * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
613
+	 *                    (i.e. RAP)
614
+	 * @throws EE_Error
615
+	 * @throws ReflectionException
616
+	 */
617
+	public function get_registrations_per_event_and_per_status_report(string $period = '-1 month'): array
618
+	{
619
+		global $wpdb;
620
+		$registration_table = $wpdb->prefix . 'esp_registration';
621
+		$event_table        = $wpdb->posts;
622
+		$sql_date           = date('Y-m-d H:i:s', strtotime($period));
623
+		// inner date query
624
+		$inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
625
+		$inner_where      = ' WHERE';
626
+		// exclude events not authored by user if permissions in effect
627
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
628
+			$inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
629
+			$inner_where      .= ' post_author = ' . get_current_user_id() . ' AND';
630
+		}
631
+		$inner_where      .= " REG_date >= '$sql_date'";
632
+		$inner_date_query .= $inner_where;
633
+		// build main query
634
+		$select       = 'SELECT Event.post_title as Registration_Event, ';
635
+		$join         = '';
636
+		$join_parts   = [];
637
+		$select_parts = [];
638
+		// loop through registration stati to do parts for each status.
639
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
640
+			if ($STS_ID === RegStatus::INCOMPLETE) {
641
+				continue;
642
+			}
643
+			$select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
644
+			$join_parts[]   =
645
+				"$registration_table AS $STS_code ON $STS_code.EVT_ID = dates.EVT_ID AND $STS_code.STS_ID = '$STS_ID' AND $STS_code.REG_date = dates.REG_date";
646
+		}
647
+		// setup the selects
648
+		$select .= implode(', ', $select_parts);
649
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
650
+		// setup remaining joins
651
+		$join .= implode(' LEFT JOIN ', $join_parts);
652
+		// now put it all together
653
+		$query = $select . $join . ' GROUP BY Registration_Event';
654
+		// and execute
655
+		return $wpdb->get_results($query, ARRAY_A);
656
+	}
657
+
658
+
659
+	/**
660
+	 * Returns the EE_Registration of the primary attendee on the transaction id provided
661
+	 *
662
+	 * @param int $TXN_ID
663
+	 * @return EE_Registration|null
664
+	 * @throws EE_Error
665
+	 */
666
+	public function get_primary_registration_for_transaction_ID(int $TXN_ID = 0): ?EE_Registration
667
+	{
668
+		if (! $TXN_ID) {
669
+			return null;
670
+		}
671
+		return $this->get_one(
672
+			[
673
+				[
674
+					'TXN_ID'    => $TXN_ID,
675
+					'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
676
+				],
677
+			]
678
+		);
679
+	}
680
+
681
+
682
+	/**
683
+	 *        get_event_registration_count
684
+	 *
685
+	 * @access public
686
+	 * @param int     $EVT_ID
687
+	 * @param boolean $for_incomplete_payments
688
+	 * @return int
689
+	 * @throws EE_Error
690
+	 */
691
+	public function get_event_registration_count(int $EVT_ID, bool $for_incomplete_payments = false): int
692
+	{
693
+		// we only count approved registrations towards registration limits
694
+		$query_params = [['EVT_ID' => $EVT_ID, 'STS_ID' => RegStatus::APPROVED]];
695
+		if ($for_incomplete_payments) {
696
+			$query_params[0]['Transaction.STS_ID'] = ['!=', EEM_Transaction::complete_status_code];
697
+		}
698
+		return $this->count($query_params);
699
+	}
700
+
701
+
702
+	/**
703
+	 * Deletes all registrations with no transactions. Note that this needs to be very efficient
704
+	 * and so it uses wpdb directly. Also, we can't put a limit on this because MySQL doesn't allow a limit on a delete
705
+	 * when joining tables like this.
706
+	 *
707
+	 * @return int|bool number deleted
708
+	 * @throws EE_Error
709
+	 * @throws ReflectionException
710
+	 * @global WPDB $wpdb
711
+	 */
712
+	public function delete_registrations_with_no_transaction()
713
+	{
714
+		/** @type WPDB $wpdb */
715
+		global $wpdb;
716
+		return $wpdb->query(
717
+			'DELETE r FROM '
718
+			. $this->table()
719
+			. ' r LEFT JOIN '
720
+			. EEM_Transaction::instance()->table()
721
+			. ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL'
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 *  Count registrations checked into (or out of) a datetime
728
+	 *
729
+	 * @param int  $DTT_ID     datetime ID
730
+	 * @param bool $checked_in whether to count registrations checked IN or OUT
731
+	 * @return int
732
+	 * @throws EE_Error
733
+	 * @throws ReflectionException
734
+	 * @throws ReflectionException
735
+	 */
736
+	public function count_registrations_checked_into_datetime(int $DTT_ID, bool $checked_in = true): int
737
+	{
738
+		global $wpdb;
739
+		// subquery to get latest checkin
740
+		$query = $wpdb->prepare(
741
+			'SELECT '
742
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
743
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
744
+			. '( SELECT '
745
+			. 'max( CHK_timestamp ) AS latest_checkin, '
746
+			. 'REG_ID AS REG_ID '
747
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' '
748
+			. 'WHERE DTT_ID=%d '
749
+			. 'GROUP BY REG_ID'
750
+			. ') AS most_recent_checkin_per_reg '
751
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
752
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
753
+			. 'WHERE '
754
+			. 'checkins.CHK_in=%d',
755
+			$DTT_ID,
756
+			$checked_in
757
+		);
758
+		return (int) $wpdb->get_var($query);
759
+	}
760
+
761
+
762
+	/**
763
+	 *  Count registrations checked into (or out of) an event.
764
+	 *
765
+	 * @param int  $EVT_ID     event ID
766
+	 * @param bool $checked_in whether to count registrations checked IN or OUT
767
+	 * @return int
768
+	 * @throws EE_Error
769
+	 * @throws ReflectionException
770
+	 * @throws ReflectionException
771
+	 * @throws ReflectionException
772
+	 */
773
+	public function count_registrations_checked_into_event(int $EVT_ID, bool $checked_in = true): int
774
+	{
775
+		global $wpdb;
776
+		// subquery to get latest checkin
777
+		$query = $wpdb->prepare(
778
+			'SELECT '
779
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
780
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
781
+			. '( SELECT '
782
+			. 'max( CHK_timestamp ) AS latest_checkin, '
783
+			. 'REG_ID AS REG_ID '
784
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
785
+			. 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
786
+			. 'ON c.DTT_ID=d.DTT_ID '
787
+			. 'WHERE d.EVT_ID=%d '
788
+			. 'GROUP BY REG_ID'
789
+			. ') AS most_recent_checkin_per_reg '
790
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
791
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
792
+			. 'WHERE '
793
+			. 'checkins.CHK_in=%d',
794
+			$EVT_ID,
795
+			$checked_in
796
+		);
797
+		return (int) $wpdb->get_var($query);
798
+	}
799
+
800
+
801
+	/**
802
+	 * The purpose of this method is to retrieve an array of
803
+	 * EE_Registration objects that represent the latest registration
804
+	 * for each ATT_ID given in the function argument.
805
+	 *
806
+	 * @param array $attendee_ids
807
+	 * @return EE_Registration[]|bool|null
808
+	 * @throws EE_Error
809
+	 * @throws ReflectionException
810
+	 */
811
+	public function get_latest_registration_for_each_of_given_contacts(array $attendee_ids = [])
812
+	{
813
+		// first do a native wp_query to get the latest REG_ID's matching these attendees.
814
+		global $wpdb;
815
+		$registration_table = $wpdb->prefix . 'esp_registration';
816
+		$attendee_table     = $wpdb->posts;
817
+		$attendee_ids       = is_array($attendee_ids)
818
+			? array_map('absint', $attendee_ids)
819
+			: [(int) $attendee_ids];
820
+		$ATT_IDs            = implode(',', $attendee_ids);
821
+		// first we do a query to get the registration ids
822
+		// (because a group by before order by causes the order by to be ignored.)
823
+		$registration_id_query = "
824 824
 			SELECT registrations.registration_ids as registration_id
825 825
 			FROM (
826 826
 				SELECT
@@ -834,61 +834,61 @@  discard block
 block discarded – undo
834 834
 			  ) AS registrations
835 835
 			  GROUP BY registrations.attendee_ids
836 836
 		";
837
-        $registration_ids      = $wpdb->get_results($registration_id_query, ARRAY_A);
838
-        if (empty($registration_ids)) {
839
-            return [];
840
-        }
841
-        $ids_for_model_query = [];
842
-        // let's flatten the ids so they can be used in the model query.
843
-        foreach ($registration_ids as $registration_id) {
844
-            if (isset($registration_id['registration_id'])) {
845
-                $ids_for_model_query[] = $registration_id['registration_id'];
846
-            }
847
-        }
848
-        // construct query
849
-        $_where = [
850
-            'REG_ID' => ['IN', $ids_for_model_query],
851
-        ];
852
-        return $this->get_all([$_where]);
853
-    }
854
-
855
-
856
-    /**
857
-     * returns a count of registrations for the supplied event having the status as specified
858
-     *
859
-     * @param int          $EVT_ID
860
-     * @param array|string $statuses
861
-     * @return int
862
-     * @throws InvalidArgumentException
863
-     * @throws InvalidStatusException
864
-     * @throws EE_Error
865
-     */
866
-    public function event_reg_count_for_statuses(int $EVT_ID, $statuses = []): int
867
-    {
868
-        $EVT_ID = absint($EVT_ID);
869
-        if (! $EVT_ID) {
870
-            throw new InvalidArgumentException(
871
-                esc_html__('An invalid Event ID was supplied.', 'event_espresso')
872
-            );
873
-        }
874
-        $statuses = is_array($statuses) ? $statuses : [$statuses];
875
-        $statuses = ! empty($statuses) ? $statuses : [RegStatus::APPROVED];
876
-
877
-        $valid_reg_statuses = EEM_Registration::reg_statuses();
878
-        foreach ($statuses as $status) {
879
-            if (! in_array($status, $valid_reg_statuses, true)) {
880
-                throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
881
-            }
882
-        }
883
-        return $this->count(
884
-            [
885
-                [
886
-                    'EVT_ID' => $EVT_ID,
887
-                    'STS_ID' => ['IN', $statuses],
888
-                ],
889
-            ],
890
-            'REG_ID',
891
-            true
892
-        );
893
-    }
837
+		$registration_ids      = $wpdb->get_results($registration_id_query, ARRAY_A);
838
+		if (empty($registration_ids)) {
839
+			return [];
840
+		}
841
+		$ids_for_model_query = [];
842
+		// let's flatten the ids so they can be used in the model query.
843
+		foreach ($registration_ids as $registration_id) {
844
+			if (isset($registration_id['registration_id'])) {
845
+				$ids_for_model_query[] = $registration_id['registration_id'];
846
+			}
847
+		}
848
+		// construct query
849
+		$_where = [
850
+			'REG_ID' => ['IN', $ids_for_model_query],
851
+		];
852
+		return $this->get_all([$_where]);
853
+	}
854
+
855
+
856
+	/**
857
+	 * returns a count of registrations for the supplied event having the status as specified
858
+	 *
859
+	 * @param int          $EVT_ID
860
+	 * @param array|string $statuses
861
+	 * @return int
862
+	 * @throws InvalidArgumentException
863
+	 * @throws InvalidStatusException
864
+	 * @throws EE_Error
865
+	 */
866
+	public function event_reg_count_for_statuses(int $EVT_ID, $statuses = []): int
867
+	{
868
+		$EVT_ID = absint($EVT_ID);
869
+		if (! $EVT_ID) {
870
+			throw new InvalidArgumentException(
871
+				esc_html__('An invalid Event ID was supplied.', 'event_espresso')
872
+			);
873
+		}
874
+		$statuses = is_array($statuses) ? $statuses : [$statuses];
875
+		$statuses = ! empty($statuses) ? $statuses : [RegStatus::APPROVED];
876
+
877
+		$valid_reg_statuses = EEM_Registration::reg_statuses();
878
+		foreach ($statuses as $status) {
879
+			if (! in_array($status, $valid_reg_statuses, true)) {
880
+				throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
881
+			}
882
+		}
883
+		return $this->count(
884
+			[
885
+				[
886
+					'EVT_ID' => $EVT_ID,
887
+					'STS_ID' => ['IN', $statuses],
888
+				],
889
+			],
890
+			'REG_ID',
891
+			true
892
+		);
893
+	}
894 894
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                 ),
192 192
             ],
193 193
         ];
194
-        $this->_model_relations        = [
194
+        $this->_model_relations = [
195 195
             'Event'                => new EE_Belongs_To_Relation(),
196 196
             'Attendee'             => new EE_Belongs_To_Relation(),
197 197
             'Transaction'          => new EE_Belongs_To_Relation(),
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
             EEM_Registration::instance()->_get_registration_status_array($exclude);
323 323
         } elseif ($exclude) {
324 324
             foreach ($exclude as $excluded_status) {
325
-                unset(self::$_reg_status[ $excluded_status ]);
325
+                unset(self::$_reg_status[$excluded_status]);
326 326
             }
327 327
         }
328 328
         return $translated
@@ -346,14 +346,14 @@  discard block
 block discarded – undo
346 346
         // and the table hasn't actually been created, this could have an error
347 347
         /** @type WPDB $wpdb */
348 348
         global $wpdb;
349
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
349
+        if ($this->_get_table_analysis()->tableExists($wpdb->prefix.'esp_status')) {
350 350
             $results           = $wpdb->get_results(
351 351
                 "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
352 352
             );
353 353
             self::$_reg_status = [];
354 354
             foreach ($results as $status) {
355
-                if (! in_array($status->STS_ID, $exclude, true)) {
356
-                    self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
355
+                if ( ! in_array($status->STS_ID, $exclude, true)) {
356
+                    self::$_reg_status[$status->STS_ID] = $status->STS_code;
357 357
                 }
358 358
             }
359 359
         }
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
      */
418 418
     public function get_all_registrations_for_attendee(int $ATT_ID = 0): ?array
419 419
     {
420
-        if (! $ATT_ID) {
420
+        if ( ! $ATT_ID) {
421 421
             return null;
422 422
         }
423 423
         return $this->get_all([['ATT_ID' => $ATT_ID]]);
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
      */
435 435
     public function get_registration_for_reg_url_link(string $REG_url_link): ?EE_Registration
436 436
     {
437
-        if (! $REG_url_link) {
437
+        if ( ! $REG_url_link) {
438 438
             return null;
439 439
         }
440 440
         return $this->get_one([['REG_url_link' => $REG_url_link]]);
@@ -483,11 +483,11 @@  discard block
 block discarded – undo
483 483
             'Y-m-d H:i:s',
484 484
             'UTC'
485 485
         );
486
-        $where    = [
486
+        $where = [
487 487
             'REG_date' => ['>=', $sql_date],
488 488
             'STS_ID'   => ['!=', RegStatus::INCOMPLETE],
489 489
         ];
490
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
490
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
491 491
             $where['Event.EVT_wp_user'] = get_current_user_id();
492 492
         }
493 493
         $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
             ],
500 500
             OBJECT,
501 501
             [
502
-                'regDate' => ['DATE(' . $query_interval . ')', '%s'],
502
+                'regDate' => ['DATE('.$query_interval.')', '%s'],
503 503
                 'total'   => ['count(REG_ID)', '%d'],
504 504
             ]
505 505
         );
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
     public function get_registrations_per_day_and_per_status_report(string $period = '-1 month'): array
520 520
     {
521 521
         global $wpdb;
522
-        $registration_table = $wpdb->prefix . 'esp_registration';
522
+        $registration_table = $wpdb->prefix.'esp_registration';
523 523
         $event_table        = $wpdb->posts;
524 524
         $sql_date           = date('Y-m-d H:i:s', strtotime($period));
525 525
         // prepare the query interval for displaying offset
@@ -528,9 +528,9 @@  discard block
 block discarded – undo
528 528
         $inner_date_query = "SELECT DISTINCT REG_date from $registration_table ";
529 529
         $inner_where      = ' WHERE';
530 530
         // exclude events not authored by user if permissions in effect
531
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
531
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
532 532
             $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
533
-            $inner_where      .= ' post_author = ' . get_current_user_id() . ' AND';
533
+            $inner_where      .= ' post_author = '.get_current_user_id().' AND';
534 534
         }
535 535
         $inner_where      .= " REG_date >= '$sql_date'";
536 536
         $inner_date_query .= $inner_where;
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
         // setup the joins
555 555
         $join .= implode(' LEFT JOIN ', $join_parts);
556 556
         // now let's put it all together
557
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
557
+        $query = $select.$join.' GROUP BY Registration_REG_date';
558 558
         // and execute it
559 559
         return $wpdb->get_results($query, ARRAY_A);
560 560
     }
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
             'Y-m-d H:i:s',
577 577
             'UTC'
578 578
         );
579
-        $where    = [
579
+        $where = [
580 580
             'REG_date' => ['>=', $date_sql],
581 581
             'STS_ID'   => ['!=', RegStatus::INCOMPLETE],
582 582
         ];
@@ -617,16 +617,16 @@  discard block
 block discarded – undo
617 617
     public function get_registrations_per_event_and_per_status_report(string $period = '-1 month'): array
618 618
     {
619 619
         global $wpdb;
620
-        $registration_table = $wpdb->prefix . 'esp_registration';
620
+        $registration_table = $wpdb->prefix.'esp_registration';
621 621
         $event_table        = $wpdb->posts;
622 622
         $sql_date           = date('Y-m-d H:i:s', strtotime($period));
623 623
         // inner date query
624 624
         $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
625 625
         $inner_where      = ' WHERE';
626 626
         // exclude events not authored by user if permissions in effect
627
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
627
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
628 628
             $inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
629
-            $inner_where      .= ' post_author = ' . get_current_user_id() . ' AND';
629
+            $inner_where      .= ' post_author = '.get_current_user_id().' AND';
630 630
         }
631 631
         $inner_where      .= " REG_date >= '$sql_date'";
632 632
         $inner_date_query .= $inner_where;
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
         // setup remaining joins
651 651
         $join .= implode(' LEFT JOIN ', $join_parts);
652 652
         // now put it all together
653
-        $query = $select . $join . ' GROUP BY Registration_Event';
653
+        $query = $select.$join.' GROUP BY Registration_Event';
654 654
         // and execute
655 655
         return $wpdb->get_results($query, ARRAY_A);
656 656
     }
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
      */
666 666
     public function get_primary_registration_for_transaction_ID(int $TXN_ID = 0): ?EE_Registration
667 667
     {
668
-        if (! $TXN_ID) {
668
+        if ( ! $TXN_ID) {
669 669
             return null;
670 670
         }
671 671
         return $this->get_one(
@@ -740,11 +740,11 @@  discard block
 block discarded – undo
740 740
         $query = $wpdb->prepare(
741 741
             'SELECT '
742 742
             . 'COUNT( DISTINCT checkins.REG_ID ) '
743
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
743
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
744 744
             . '( SELECT '
745 745
             . 'max( CHK_timestamp ) AS latest_checkin, '
746 746
             . 'REG_ID AS REG_ID '
747
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
747
+            . 'FROM '.EEM_Checkin::instance()->table().' '
748 748
             . 'WHERE DTT_ID=%d '
749 749
             . 'GROUP BY REG_ID'
750 750
             . ') AS most_recent_checkin_per_reg '
@@ -777,12 +777,12 @@  discard block
 block discarded – undo
777 777
         $query = $wpdb->prepare(
778 778
             'SELECT '
779 779
             . 'COUNT( DISTINCT checkins.REG_ID ) '
780
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
780
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
781 781
             . '( SELECT '
782 782
             . 'max( CHK_timestamp ) AS latest_checkin, '
783 783
             . 'REG_ID AS REG_ID '
784
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
785
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
784
+            . 'FROM '.EEM_Checkin::instance()->table().' AS c '
785
+            . 'INNER JOIN '.EEM_Datetime::instance()->table().' AS d '
786 786
             . 'ON c.DTT_ID=d.DTT_ID '
787 787
             . 'WHERE d.EVT_ID=%d '
788 788
             . 'GROUP BY REG_ID'
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
     {
813 813
         // first do a native wp_query to get the latest REG_ID's matching these attendees.
814 814
         global $wpdb;
815
-        $registration_table = $wpdb->prefix . 'esp_registration';
815
+        $registration_table = $wpdb->prefix.'esp_registration';
816 816
         $attendee_table     = $wpdb->posts;
817 817
         $attendee_ids       = is_array($attendee_ids)
818 818
             ? array_map('absint', $attendee_ids)
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
 			  ) AS registrations
835 835
 			  GROUP BY registrations.attendee_ids
836 836
 		";
837
-        $registration_ids      = $wpdb->get_results($registration_id_query, ARRAY_A);
837
+        $registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A);
838 838
         if (empty($registration_ids)) {
839 839
             return [];
840 840
         }
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
     public function event_reg_count_for_statuses(int $EVT_ID, $statuses = []): int
867 867
     {
868 868
         $EVT_ID = absint($EVT_ID);
869
-        if (! $EVT_ID) {
869
+        if ( ! $EVT_ID) {
870 870
             throw new InvalidArgumentException(
871 871
                 esc_html__('An invalid Event ID was supplied.', 'event_espresso')
872 872
             );
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 
877 877
         $valid_reg_statuses = EEM_Registration::reg_statuses();
878 878
         foreach ($statuses as $status) {
879
-            if (! in_array($status, $valid_reg_statuses, true)) {
879
+            if ( ! in_array($status, $valid_reg_statuses, true)) {
880 880
                 throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
881 881
             }
882 882
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Status.model.php 1 patch
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -12,308 +12,308 @@
 block discarded – undo
12 12
  */
13 13
 class EEM_Status extends EEM_Base
14 14
 {
15
-    protected static ?EEM_Status $_instance = null;
15
+	protected static ?EEM_Status $_instance = null;
16 16
 
17 17
 
18
-    /**
19
-     * @param string|null $timezone
20
-     * @throws EE_Error
21
-     */
22
-    protected function __construct(?string $timezone = '')
23
-    {
24
-        $this->singular_item    = esc_html__('Status', 'event_espresso');
25
-        $this->plural_item      = esc_html__('Stati', 'event_espresso');
26
-        $this->_tables          = [
27
-            'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
28
-        ];
29
-        $this->_fields          = [
30
-            'StatusTable' => [
31
-                'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')),
32
-                'STS_code'     => new EE_Plain_Text_Field(
33
-                    'STS_code', esc_html__('Status Code', 'event_espresso'), false, ''
34
-                ),
35
-                'STS_type'     => new EE_Enum_Text_Field(
36
-                    'STS_type',
37
-                    esc_html__("Type", "event_espresso"),
38
-                    false,
39
-                    'event',
40
-                    [
41
-                        'event'        => esc_html__("Event", "event_espresso"),// deprecated
42
-                        'registration' => esc_html__("Registration", "event_espresso"),
43
-                        'transaction'  => esc_html__("Transaction", "event_espresso"),
44
-                        'payment'      => esc_html__("Payment", "event_espresso"),
45
-                        'email'        => esc_html__("Email", "event_espresso"),
46
-                        'message'      => esc_html__("Message", "event_espresso"),
47
-                    ]
48
-                ),
49
-                'STS_can_edit' => new EE_Boolean_Field(
50
-                    'STS_can_edit',
51
-                    esc_html__('Editable?', 'event_espresso'),
52
-                    false,
53
-                    false
54
-                ),
55
-                'STS_desc'     => new EE_Simple_HTML_Field(
56
-                    'STS_desc',
57
-                    esc_html__("Description", "event_espresso"),
58
-                    false,
59
-                    ''
60
-                ),
61
-                'STS_open'     => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false),
62
-            ],
63
-        ];
64
-        $this->_model_relations = [
65
-            'Registration' => new EE_Has_Many_Relation(),
66
-            'Transaction'  => new EE_Has_Many_Relation(),
67
-            'Payment'      => new EE_Has_Many_Relation(),
68
-        ];
69
-        // this model is generally available for reading
70
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
18
+	/**
19
+	 * @param string|null $timezone
20
+	 * @throws EE_Error
21
+	 */
22
+	protected function __construct(?string $timezone = '')
23
+	{
24
+		$this->singular_item    = esc_html__('Status', 'event_espresso');
25
+		$this->plural_item      = esc_html__('Stati', 'event_espresso');
26
+		$this->_tables          = [
27
+			'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
28
+		];
29
+		$this->_fields          = [
30
+			'StatusTable' => [
31
+				'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')),
32
+				'STS_code'     => new EE_Plain_Text_Field(
33
+					'STS_code', esc_html__('Status Code', 'event_espresso'), false, ''
34
+				),
35
+				'STS_type'     => new EE_Enum_Text_Field(
36
+					'STS_type',
37
+					esc_html__("Type", "event_espresso"),
38
+					false,
39
+					'event',
40
+					[
41
+						'event'        => esc_html__("Event", "event_espresso"),// deprecated
42
+						'registration' => esc_html__("Registration", "event_espresso"),
43
+						'transaction'  => esc_html__("Transaction", "event_espresso"),
44
+						'payment'      => esc_html__("Payment", "event_espresso"),
45
+						'email'        => esc_html__("Email", "event_espresso"),
46
+						'message'      => esc_html__("Message", "event_espresso"),
47
+					]
48
+				),
49
+				'STS_can_edit' => new EE_Boolean_Field(
50
+					'STS_can_edit',
51
+					esc_html__('Editable?', 'event_espresso'),
52
+					false,
53
+					false
54
+				),
55
+				'STS_desc'     => new EE_Simple_HTML_Field(
56
+					'STS_desc',
57
+					esc_html__("Description", "event_espresso"),
58
+					false,
59
+					''
60
+				),
61
+				'STS_open'     => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false),
62
+			],
63
+		];
64
+		$this->_model_relations = [
65
+			'Registration' => new EE_Has_Many_Relation(),
66
+			'Transaction'  => new EE_Has_Many_Relation(),
67
+			'Payment'      => new EE_Has_Many_Relation(),
68
+		];
69
+		// this model is generally available for reading
70
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
71 71
 
72
-        parent::__construct($timezone);
73
-    }
72
+		parent::__construct($timezone);
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * This method provides the localized singular or plural string for a given status id
78
-     *
79
-     * @param array   $statuses  This should be an array of statuses in the format array( $status_id, $status_code ).
80
-     *                           That way if there isn't a translation in the index we'll return the default code.
81
-     * @param boolean $plural    Whether to return plural string or not. Note, nearly all of the plural strings are the
82
-     *                           same as the singular (in English), however, this may NOT be the case with other
83
-     *                           languages
84
-     * @param string  $schema    This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
85
-     *                           the status string returned ( UPPER, lower, Sentence)
86
-     * @return array             an array of translated strings for the incoming status id.
87
-     * @throws EE_Error
88
-     */
89
-    public function localized_status($statuses, $plural = false, $schema = 'upper')
90
-    {
91
-        // note these are all in lower case because ucwords() on upper case will NOT convert.
92
-        $translation_array = [
93
-            RegStatus::PENDING_PAYMENT => [
94
-                esc_html__('pending payment', 'event_espresso'), // singular
95
-                esc_html__('pending payments', 'event_espresso'), // plural
96
-            ],
97
-            RegStatus::APPROVED        => [
98
-                esc_html__('approved', 'event_espresso'), // singular
99
-                esc_html__('approved', 'event_espresso'), // plural
100
-            ],
101
-            RegStatus::AWAITING_REVIEW    => [
102
-                esc_html__('not approved / awaiting review', 'event_espresso'),
103
-                esc_html__('not approved / awaiting review', 'event_espresso'),
104
-            ],
105
-            RegStatus::CANCELLED       => [
106
-                esc_html__('cancelled', 'event_espresso'),
107
-                esc_html__('cancelled', 'event_espresso'),
108
-            ],
109
-            RegStatus::INCOMPLETE      => [
110
-                esc_html__('incomplete', 'event_espresso'),
111
-                esc_html__('incomplete', 'event_espresso'),
112
-            ],
113
-            RegStatus::DECLINED        => [
114
-                esc_html__('declined', 'event_espresso'),
115
-                esc_html__('declined', 'event_espresso'),
116
-            ],
117
-            RegStatus::WAIT_LIST       => [
118
-                esc_html__('wait list', 'event_espresso'),
119
-                esc_html__('wait list', 'event_espresso'),
120
-            ],
121
-            EEM_Transaction::overpaid_status_code       => [
122
-                esc_html__('overpaid', 'event_espresso'),
123
-                esc_html__('overpaid', 'event_espresso'),
124
-            ],
125
-            EEM_Transaction::complete_status_code       => [
126
-                esc_html__('complete', 'event_espresso'),
127
-                esc_html__('complete', 'event_espresso'),
128
-            ],
129
-            EEM_Transaction::incomplete_status_code     => [
130
-                esc_html__('incomplete', 'event_espresso'),
131
-                esc_html__('incomplete', 'event_espresso'),
132
-            ],
133
-            EEM_Transaction::failed_status_code         => [
134
-                esc_html__('failed', 'event_espresso'),
135
-                esc_html__('failed', 'event_espresso'),
136
-            ],
137
-            EEM_Transaction::abandoned_status_code      => [
138
-                esc_html__('abandoned', 'event_espresso'),
139
-                esc_html__('abandoned', 'event_espresso'),
140
-            ],
141
-            EEM_Payment::status_id_approved             => [
142
-                esc_html__('accepted', 'event_espresso'),
143
-                esc_html__('accepted', 'event_espresso'),
144
-            ],
145
-            EEM_Payment::status_id_pending              => [
146
-                esc_html__('pending', 'event_espresso'),
147
-                esc_html__('pending', 'event_espresso'),
148
-            ],
149
-            EEM_Payment::status_id_cancelled            => [
150
-                esc_html__('cancelled', 'event_espresso'),
151
-                esc_html__('cancelled', 'event_espresso'),
152
-            ],
153
-            EEM_Payment::status_id_declined             => [
154
-                esc_html__('declined', 'event_espresso'),
155
-                esc_html__('declined', 'event_espresso'),
156
-            ],
157
-            EEM_Payment::status_id_failed               => [
158
-                esc_html__('failed', 'event_espresso'),
159
-                esc_html__('failed', 'event_espresso'),
160
-            ],
161
-            // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
162
-            EEM_Event::sold_out                         => [
163
-                esc_html__('sold out', 'event_espresso'),
164
-                esc_html__('sold out', 'event_espresso'),
165
-            ],
166
-            EEM_Event::postponed                        => [
167
-                esc_html__('postponed', 'event_espresso'),
168
-                esc_html__('Postponed', 'event_espresso'),
169
-            ],
170
-            EEM_Event::cancelled                        => [
171
-                esc_html__('cancelled', 'event_espresso'),
172
-                esc_html__('cancelled', 'event_espresso'),
173
-            ],
174
-            EE_Ticket::archived                         => [
175
-                esc_html__('archived', 'event_espresso'),
176
-                esc_html__('archived', 'event_espresso'),
177
-            ],
178
-            EE_Ticket::expired                          => [
179
-                esc_html__('expired', 'event_espresso'),
180
-                esc_html__('expired', 'event_espresso'),
181
-            ],
182
-            EE_Ticket::sold_out                         => [
183
-                esc_html__('sold out', 'event_espresso'),
184
-                esc_html__('sold out', 'event_espresso'),
185
-            ],
186
-            EE_Ticket::pending                          => [
187
-                esc_html__('upcoming', 'event_espresso'),
188
-                esc_html__('upcoming', 'event_espresso'),
189
-            ],
190
-            EE_Ticket::onsale                           => [
191
-                esc_html__('on sale', 'event_espresso'),
192
-                esc_html__('on sale', 'event_espresso'),
193
-            ],
194
-            EE_Datetime::cancelled                      => [
195
-                esc_html__('cancelled', 'event_espresso'),
196
-                esc_html__('cancelled', 'event_espresso'),
197
-            ],
198
-            EE_Datetime::sold_out                       => [
199
-                esc_html__('sold out', 'event_espresso'),
200
-                esc_html__('sold out', 'event_espresso'),
201
-            ],
202
-            EE_Datetime::expired                        => [
203
-                esc_html__('expired', 'event_espresso'),
204
-                esc_html__('expired', 'event_espresso'),
205
-            ],
206
-            EE_Datetime::inactive                       => [
207
-                esc_html__('inactive', 'event_espresso'),
208
-                esc_html__('inactive', 'event_espresso'),
209
-            ],
210
-            EE_Datetime::upcoming                       => [
211
-                esc_html__('upcoming', 'event_espresso'),
212
-                esc_html__('upcoming', 'event_espresso'),
213
-            ],
214
-            EE_Datetime::active                         => [
215
-                esc_html__('active', 'event_espresso'),
216
-                esc_html__('active', 'event_espresso'),
217
-            ],
218
-            EE_Datetime::postponed                      => [
219
-                esc_html__('postponed', 'event_espresso'),
220
-                esc_html__('postponed', 'event_espresso'),
221
-            ],
222
-            // messages related
223
-            EEM_Message::status_sent                    => [
224
-                esc_html__('sent', 'event_espresso'),
225
-                esc_html__('sent', 'event_espresso'),
226
-            ],
227
-            EEM_Message::status_idle                    => [
228
-                esc_html__('queued for sending', 'event_espresso'),
229
-                esc_html__('queued for sending', 'event_espresso'),
230
-            ],
231
-            EEM_Message::status_failed                  => [
232
-                esc_html__('failed', 'event_espresso'),
233
-                esc_html__('failed', 'event_espresso'),
234
-            ],
235
-            EEM_Message::status_debug_only              => [
236
-                esc_html__('debug only', 'event_espresso'),
237
-                esc_html__('debug only', 'event_espresso'),
238
-            ],
239
-            EEM_Message::status_messenger_executing     => [
240
-                esc_html__('messenger is executing', 'event_espresso'),
241
-                esc_html__('messenger is executing', 'event_espresso'),
242
-            ],
243
-            EEM_Message::status_resend                  => [
244
-                esc_html__('queued for resending', 'event_espresso'),
245
-                esc_html__('queued for resending', 'event_espresso'),
246
-            ],
247
-            EEM_Message::status_incomplete              => [
248
-                esc_html__('queued for generating', 'event_espresso'),
249
-                esc_html__('queued for generating', 'event_espresso'),
250
-            ],
251
-            EEM_Message::status_retry                   => [
252
-                esc_html__('failed sending, can be retried', 'event_espresso'),
253
-                esc_html__('failed sending, can be retried', 'event_espresso'),
254
-            ],
255
-            EEM_CPT_Base::post_status_publish           => [
256
-                esc_html__('published', 'event_espresso'),
257
-                esc_html__('published', 'event_espresso'),
258
-            ],
259
-            EEM_CPT_Base::post_status_future            => [
260
-                esc_html__('scheduled', 'event_espresso'),
261
-                esc_html__('scheduled', 'event_espresso'),
262
-            ],
263
-            EEM_CPT_Base::post_status_draft             => [
264
-                esc_html__('draft', 'event_espresso'),
265
-                esc_html__('draft', 'event_espresso'),
266
-            ],
267
-            EEM_CPT_Base::post_status_pending           => [
268
-                esc_html__('pending', 'event_espresso'),
269
-                esc_html__('pending', 'event_espresso'),
270
-            ],
271
-            EEM_CPT_Base::post_status_private           => [
272
-                esc_html__('private', 'event_espresso'),
273
-                esc_html__('private', 'event_espresso'),
274
-            ],
275
-            EEM_CPT_Base::post_status_trashed           => [
276
-                esc_html__('trashed', 'event_espresso'),
277
-                esc_html__('trashed', 'event_espresso'),
278
-            ],
279
-        ];
76
+	/**
77
+	 * This method provides the localized singular or plural string for a given status id
78
+	 *
79
+	 * @param array   $statuses  This should be an array of statuses in the format array( $status_id, $status_code ).
80
+	 *                           That way if there isn't a translation in the index we'll return the default code.
81
+	 * @param boolean $plural    Whether to return plural string or not. Note, nearly all of the plural strings are the
82
+	 *                           same as the singular (in English), however, this may NOT be the case with other
83
+	 *                           languages
84
+	 * @param string  $schema    This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
85
+	 *                           the status string returned ( UPPER, lower, Sentence)
86
+	 * @return array             an array of translated strings for the incoming status id.
87
+	 * @throws EE_Error
88
+	 */
89
+	public function localized_status($statuses, $plural = false, $schema = 'upper')
90
+	{
91
+		// note these are all in lower case because ucwords() on upper case will NOT convert.
92
+		$translation_array = [
93
+			RegStatus::PENDING_PAYMENT => [
94
+				esc_html__('pending payment', 'event_espresso'), // singular
95
+				esc_html__('pending payments', 'event_espresso'), // plural
96
+			],
97
+			RegStatus::APPROVED        => [
98
+				esc_html__('approved', 'event_espresso'), // singular
99
+				esc_html__('approved', 'event_espresso'), // plural
100
+			],
101
+			RegStatus::AWAITING_REVIEW    => [
102
+				esc_html__('not approved / awaiting review', 'event_espresso'),
103
+				esc_html__('not approved / awaiting review', 'event_espresso'),
104
+			],
105
+			RegStatus::CANCELLED       => [
106
+				esc_html__('cancelled', 'event_espresso'),
107
+				esc_html__('cancelled', 'event_espresso'),
108
+			],
109
+			RegStatus::INCOMPLETE      => [
110
+				esc_html__('incomplete', 'event_espresso'),
111
+				esc_html__('incomplete', 'event_espresso'),
112
+			],
113
+			RegStatus::DECLINED        => [
114
+				esc_html__('declined', 'event_espresso'),
115
+				esc_html__('declined', 'event_espresso'),
116
+			],
117
+			RegStatus::WAIT_LIST       => [
118
+				esc_html__('wait list', 'event_espresso'),
119
+				esc_html__('wait list', 'event_espresso'),
120
+			],
121
+			EEM_Transaction::overpaid_status_code       => [
122
+				esc_html__('overpaid', 'event_espresso'),
123
+				esc_html__('overpaid', 'event_espresso'),
124
+			],
125
+			EEM_Transaction::complete_status_code       => [
126
+				esc_html__('complete', 'event_espresso'),
127
+				esc_html__('complete', 'event_espresso'),
128
+			],
129
+			EEM_Transaction::incomplete_status_code     => [
130
+				esc_html__('incomplete', 'event_espresso'),
131
+				esc_html__('incomplete', 'event_espresso'),
132
+			],
133
+			EEM_Transaction::failed_status_code         => [
134
+				esc_html__('failed', 'event_espresso'),
135
+				esc_html__('failed', 'event_espresso'),
136
+			],
137
+			EEM_Transaction::abandoned_status_code      => [
138
+				esc_html__('abandoned', 'event_espresso'),
139
+				esc_html__('abandoned', 'event_espresso'),
140
+			],
141
+			EEM_Payment::status_id_approved             => [
142
+				esc_html__('accepted', 'event_espresso'),
143
+				esc_html__('accepted', 'event_espresso'),
144
+			],
145
+			EEM_Payment::status_id_pending              => [
146
+				esc_html__('pending', 'event_espresso'),
147
+				esc_html__('pending', 'event_espresso'),
148
+			],
149
+			EEM_Payment::status_id_cancelled            => [
150
+				esc_html__('cancelled', 'event_espresso'),
151
+				esc_html__('cancelled', 'event_espresso'),
152
+			],
153
+			EEM_Payment::status_id_declined             => [
154
+				esc_html__('declined', 'event_espresso'),
155
+				esc_html__('declined', 'event_espresso'),
156
+			],
157
+			EEM_Payment::status_id_failed               => [
158
+				esc_html__('failed', 'event_espresso'),
159
+				esc_html__('failed', 'event_espresso'),
160
+			],
161
+			// following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
162
+			EEM_Event::sold_out                         => [
163
+				esc_html__('sold out', 'event_espresso'),
164
+				esc_html__('sold out', 'event_espresso'),
165
+			],
166
+			EEM_Event::postponed                        => [
167
+				esc_html__('postponed', 'event_espresso'),
168
+				esc_html__('Postponed', 'event_espresso'),
169
+			],
170
+			EEM_Event::cancelled                        => [
171
+				esc_html__('cancelled', 'event_espresso'),
172
+				esc_html__('cancelled', 'event_espresso'),
173
+			],
174
+			EE_Ticket::archived                         => [
175
+				esc_html__('archived', 'event_espresso'),
176
+				esc_html__('archived', 'event_espresso'),
177
+			],
178
+			EE_Ticket::expired                          => [
179
+				esc_html__('expired', 'event_espresso'),
180
+				esc_html__('expired', 'event_espresso'),
181
+			],
182
+			EE_Ticket::sold_out                         => [
183
+				esc_html__('sold out', 'event_espresso'),
184
+				esc_html__('sold out', 'event_espresso'),
185
+			],
186
+			EE_Ticket::pending                          => [
187
+				esc_html__('upcoming', 'event_espresso'),
188
+				esc_html__('upcoming', 'event_espresso'),
189
+			],
190
+			EE_Ticket::onsale                           => [
191
+				esc_html__('on sale', 'event_espresso'),
192
+				esc_html__('on sale', 'event_espresso'),
193
+			],
194
+			EE_Datetime::cancelled                      => [
195
+				esc_html__('cancelled', 'event_espresso'),
196
+				esc_html__('cancelled', 'event_espresso'),
197
+			],
198
+			EE_Datetime::sold_out                       => [
199
+				esc_html__('sold out', 'event_espresso'),
200
+				esc_html__('sold out', 'event_espresso'),
201
+			],
202
+			EE_Datetime::expired                        => [
203
+				esc_html__('expired', 'event_espresso'),
204
+				esc_html__('expired', 'event_espresso'),
205
+			],
206
+			EE_Datetime::inactive                       => [
207
+				esc_html__('inactive', 'event_espresso'),
208
+				esc_html__('inactive', 'event_espresso'),
209
+			],
210
+			EE_Datetime::upcoming                       => [
211
+				esc_html__('upcoming', 'event_espresso'),
212
+				esc_html__('upcoming', 'event_espresso'),
213
+			],
214
+			EE_Datetime::active                         => [
215
+				esc_html__('active', 'event_espresso'),
216
+				esc_html__('active', 'event_espresso'),
217
+			],
218
+			EE_Datetime::postponed                      => [
219
+				esc_html__('postponed', 'event_espresso'),
220
+				esc_html__('postponed', 'event_espresso'),
221
+			],
222
+			// messages related
223
+			EEM_Message::status_sent                    => [
224
+				esc_html__('sent', 'event_espresso'),
225
+				esc_html__('sent', 'event_espresso'),
226
+			],
227
+			EEM_Message::status_idle                    => [
228
+				esc_html__('queued for sending', 'event_espresso'),
229
+				esc_html__('queued for sending', 'event_espresso'),
230
+			],
231
+			EEM_Message::status_failed                  => [
232
+				esc_html__('failed', 'event_espresso'),
233
+				esc_html__('failed', 'event_espresso'),
234
+			],
235
+			EEM_Message::status_debug_only              => [
236
+				esc_html__('debug only', 'event_espresso'),
237
+				esc_html__('debug only', 'event_espresso'),
238
+			],
239
+			EEM_Message::status_messenger_executing     => [
240
+				esc_html__('messenger is executing', 'event_espresso'),
241
+				esc_html__('messenger is executing', 'event_espresso'),
242
+			],
243
+			EEM_Message::status_resend                  => [
244
+				esc_html__('queued for resending', 'event_espresso'),
245
+				esc_html__('queued for resending', 'event_espresso'),
246
+			],
247
+			EEM_Message::status_incomplete              => [
248
+				esc_html__('queued for generating', 'event_espresso'),
249
+				esc_html__('queued for generating', 'event_espresso'),
250
+			],
251
+			EEM_Message::status_retry                   => [
252
+				esc_html__('failed sending, can be retried', 'event_espresso'),
253
+				esc_html__('failed sending, can be retried', 'event_espresso'),
254
+			],
255
+			EEM_CPT_Base::post_status_publish           => [
256
+				esc_html__('published', 'event_espresso'),
257
+				esc_html__('published', 'event_espresso'),
258
+			],
259
+			EEM_CPT_Base::post_status_future            => [
260
+				esc_html__('scheduled', 'event_espresso'),
261
+				esc_html__('scheduled', 'event_espresso'),
262
+			],
263
+			EEM_CPT_Base::post_status_draft             => [
264
+				esc_html__('draft', 'event_espresso'),
265
+				esc_html__('draft', 'event_espresso'),
266
+			],
267
+			EEM_CPT_Base::post_status_pending           => [
268
+				esc_html__('pending', 'event_espresso'),
269
+				esc_html__('pending', 'event_espresso'),
270
+			],
271
+			EEM_CPT_Base::post_status_private           => [
272
+				esc_html__('private', 'event_espresso'),
273
+				esc_html__('private', 'event_espresso'),
274
+			],
275
+			EEM_CPT_Base::post_status_trashed           => [
276
+				esc_html__('trashed', 'event_espresso'),
277
+				esc_html__('trashed', 'event_espresso'),
278
+			],
279
+		];
280 280
 
281
-        $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
281
+		$translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
282 282
 
283
-        if (! is_array($statuses)) {
284
-            throw new EE_Error(
285
-                esc_html__(
286
-                    'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
287
-                    'event_espresso'
288
-                )
289
-            );
290
-        }
283
+		if (! is_array($statuses)) {
284
+			throw new EE_Error(
285
+				esc_html__(
286
+					'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
287
+					'event_espresso'
288
+				)
289
+			);
290
+		}
291 291
 
292
-        $translation = [];
292
+		$translation = [];
293 293
 
294
-        foreach ($statuses as $id => $code) {
295
-            if (isset($translation_array[ $id ])) {
296
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
297
-            } else {
298
-                $translation[ $id ] = $code;
299
-            }
294
+		foreach ($statuses as $id => $code) {
295
+			if (isset($translation_array[ $id ])) {
296
+				$translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
297
+			} else {
298
+				$translation[ $id ] = $code;
299
+			}
300 300
 
301
-            // schema
302
-            switch ($schema) {
303
-                case 'lower':
304
-                    $translation[ $id ] = strtolower(
305
-                        $translation[ $id ]
306
-                    ); // even though these start in lower case, this will catch any statuses added via filter.
307
-                    break;
308
-                case 'sentence':
309
-                    $translation[ $id ] = ucwords($translation[ $id ]);
310
-                    break;
311
-                case 'upper':
312
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
313
-                    break;
314
-            }
315
-        }
301
+			// schema
302
+			switch ($schema) {
303
+				case 'lower':
304
+					$translation[ $id ] = strtolower(
305
+						$translation[ $id ]
306
+					); // even though these start in lower case, this will catch any statuses added via filter.
307
+					break;
308
+				case 'sentence':
309
+					$translation[ $id ] = ucwords($translation[ $id ]);
310
+					break;
311
+				case 'upper':
312
+					$translation[ $id ] = strtoupper($translation[ $id ]);
313
+					break;
314
+			}
315
+		}
316 316
 
317
-        return $translation;
318
-    }
317
+		return $translation;
318
+	}
319 319
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 1 patch
Indentation   +949 added lines, -949 removed lines patch added patch discarded remove patch
@@ -15,953 +15,953 @@
 block discarded – undo
15 15
  */
16 16
 class EEM_Event extends EEM_CPT_Base
17 17
 {
18
-    /**
19
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
20
-     * event
21
-     */
22
-    const sold_out = 'sold_out';
23
-
24
-    /**
25
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
26
-     * date)
27
-     */
28
-    const postponed = 'postponed';
29
-
30
-    /**
31
-     * constant used by status(), indicating that the event will no longer occur
32
-     */
33
-    const cancelled = 'cancelled';
34
-
35
-
36
-    protected static string $_default_reg_status;
37
-
38
-    protected static int $_default_additional_limit = 10;
39
-
40
-    protected static ?EEM_Event $_instance = null;
41
-
42
-
43
-    /**
44
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
45
-     *
46
-     * @param string|null $timezone
47
-     * @throws EE_Error
48
-     * @throws ReflectionException
49
-     */
50
-    protected function __construct(?string $timezone = '')
51
-    {
52
-        EE_Registry::instance()->load_model('Registration');
53
-        $this->singular_item = esc_html__('Event', 'event_espresso');
54
-        $this->plural_item   = esc_html__('Events', 'event_espresso');
55
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
56
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
57
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
58
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
59
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
60
-        //  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
61
-        $this->_custom_stati       = apply_filters(
62
-            'AFEE__EEM_Event__construct___custom_stati',
63
-            [
64
-                EEM_Event::cancelled => [
65
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
66
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
67
-                ],
68
-                EEM_Event::postponed => [
69
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
70
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
71
-                ],
72
-                EEM_Event::sold_out  => [
73
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
74
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
75
-                ],
76
-            ]
77
-        );
78
-        self::$_default_reg_status = empty(self::$_default_reg_status)
79
-            ? RegStatus::PENDING_PAYMENT
80
-            : self::$_default_reg_status;
81
-        $this->_tables             = [
82
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
83
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
84
-        ];
85
-        $this->_fields             = [
86
-            'Event_CPT'  => [
87
-                'EVT_ID'         => new EE_Primary_Key_Int_Field(
88
-                    'ID',
89
-                    esc_html__('Post ID for Event', 'event_espresso')
90
-                ),
91
-                'EVT_name'       => new EE_Plain_Text_Field(
92
-                    'post_title',
93
-                    esc_html__('Event Name', 'event_espresso'),
94
-                    false,
95
-                    ''
96
-                ),
97
-                'EVT_desc'       => new EE_Post_Content_Field(
98
-                    'post_content',
99
-                    esc_html__('Event Description', 'event_espresso'),
100
-                    false,
101
-                    ''
102
-                ),
103
-                'EVT_slug'       => new EE_Slug_Field(
104
-                    'post_name',
105
-                    esc_html__('Event Slug', 'event_espresso'),
106
-                    false,
107
-                    ''
108
-                ),
109
-                'EVT_created'    => new EE_Datetime_Field(
110
-                    'post_date',
111
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
112
-                    false,
113
-                    EE_Datetime_Field::now
114
-                ),
115
-                'EVT_short_desc' => new EE_Simple_HTML_Field(
116
-                    'post_excerpt',
117
-                    esc_html__('Event Short Description', 'event_espresso'),
118
-                    false,
119
-                    ''
120
-                ),
121
-                'EVT_modified'   => new EE_Datetime_Field(
122
-                    'post_modified',
123
-                    esc_html__('Date/Time Event Modified', 'event_espresso'),
124
-                    false,
125
-                    EE_Datetime_Field::now
126
-                ),
127
-                'EVT_wp_user'    => new EE_WP_User_Field(
128
-                    'post_author',
129
-                    esc_html__('Event Creator ID', 'event_espresso'),
130
-                    false
131
-                ),
132
-                'parent'         => new EE_Integer_Field(
133
-                    'post_parent',
134
-                    esc_html__('Event Parent ID', 'event_espresso'),
135
-                    false,
136
-                    0
137
-                ),
138
-                'EVT_order'      => new EE_Integer_Field(
139
-                    'menu_order',
140
-                    esc_html__('Event Menu Order', 'event_espresso'),
141
-                    false,
142
-                    1
143
-                ),
144
-                'post_type'      => new EE_WP_Post_Type_Field(EspressoPostType::EVENTS),
145
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
146
-                'status'         => new EE_WP_Post_Status_Field(
147
-                    'post_status',
148
-                    esc_html__('Event Status', 'event_espresso'),
149
-                    false,
150
-                    'draft',
151
-                    $this->_custom_stati
152
-                ),
153
-                'password'       => new EE_Password_Field(
154
-                    'post_password',
155
-                    esc_html__('Password', 'event_espresso'),
156
-                    false,
157
-                    '',
158
-                    [
159
-                        'EVT_desc',
160
-                        'EVT_short_desc',
161
-                        'EVT_display_desc',
162
-                        'EVT_display_ticket_selector',
163
-                        'EVT_visible_on',
164
-                        'EVT_additional_limit',
165
-                        'EVT_default_registration_status',
166
-                        'EVT_member_only',
167
-                        'EVT_phone',
168
-                        'EVT_allow_overflow',
169
-                        'EVT_timezone_string',
170
-                        'EVT_external_URL',
171
-                        'EVT_donations',
172
-                    ]
173
-                ),
174
-            ],
175
-            'Event_Meta' => [
176
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field(
177
-                    'EVTM_ID',
178
-                    esc_html__('Event Meta Row ID', 'event_espresso'),
179
-                    false
180
-                ),
181
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
182
-                    'EVT_ID',
183
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
184
-                    false
185
-                ),
186
-                'VNU_ID'                          => new EE_Foreign_Key_Int_Field(
187
-                    'VNU_ID',
188
-                    __('Venue ID', 'event_espresso'),
189
-                    false,
190
-                    0,
191
-                    'Venue'
192
-                ),
193
-                'EVT_display_desc'                => new EE_Boolean_Field(
194
-                    'EVT_display_desc',
195
-                    esc_html__('Display Description Flag', 'event_espresso'),
196
-                    false,
197
-                    true
198
-                ),
199
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field(
200
-                    'EVT_display_ticket_selector',
201
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'),
202
-                    false,
203
-                    true
204
-                ),
205
-                'EVT_visible_on'                  => new EE_Datetime_Field(
206
-                    'EVT_visible_on',
207
-                    esc_html__('Event Visible Date', 'event_espresso'),
208
-                    true,
209
-                    EE_Datetime_Field::now
210
-                ),
211
-                'EVT_additional_limit'            => new EE_Integer_Field(
212
-                    'EVT_additional_limit',
213
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
214
-                    false,
215
-                    self::$_default_additional_limit
216
-                ),
217
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
218
-                    'EVT_default_registration_status',
219
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'),
220
-                    false,
221
-                    EEM_Event::$_default_reg_status,
222
-                    EEM_Registration::reg_status_array()
223
-                ),
224
-                'EVT_member_only'                 => new EE_Boolean_Field(
225
-                    'EVT_member_only',
226
-                    esc_html__('Member-Only Event Flag', 'event_espresso'),
227
-                    false,
228
-                    false
229
-                ),
230
-                'EVT_phone'                       => new EE_Plain_Text_Field(
231
-                    'EVT_phone',
232
-                    esc_html__('Event Phone Number', 'event_espresso'),
233
-                    false,
234
-                    ''
235
-                ),
236
-                'EVT_allow_overflow'              => new EE_Boolean_Field(
237
-                    'EVT_allow_overflow',
238
-                    esc_html__('Allow Overflow on Event', 'event_espresso'),
239
-                    false,
240
-                    false
241
-                ),
242
-                'EVT_timezone_string'             => new EE_Plain_Text_Field(
243
-                    'EVT_timezone_string',
244
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'),
245
-                    false,
246
-                    ''
247
-                ),
248
-                'EVT_external_URL'                => new EE_Plain_Text_Field(
249
-                    'EVT_external_URL',
250
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
251
-                    true
252
-                ),
253
-                'EVT_donations'                   => new EE_Boolean_Field(
254
-                    'EVT_donations',
255
-                    esc_html__('Accept Donations?', 'event_espresso'),
256
-                    false,
257
-                    false
258
-                ),
259
-                'FSC_UUID'                        => new EE_Foreign_Key_String_Field(
260
-                    'FSC_UUID',
261
-                    esc_html__('Registration Form UUID (universally unique identifier)', 'event_espresso'),
262
-                    true,
263
-                    null,
264
-                    'Form_Section',
265
-                    false
266
-                ),
267
-            ],
268
-        ];
269
-        $this->_model_relations    = [
270
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
271
-            'Datetime'               => new EE_Has_Many_Relation(),
272
-            'Event_Question_Group'   => new EE_Has_Many_Relation(),
273
-            'Form_Section'           => new EE_Belongs_To_Relation(),
274
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
275
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
276
-            'Registration'           => new EE_Has_Many_Relation(),
277
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
278
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
279
-            'Venue'                  => new EE_Belongs_To_Relation(),
280
-            'WP_User'                => new EE_Belongs_To_Relation(),
281
-        ];
282
-        // this model is generally available for reading
283
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
284
-        $this->model_chain_to_password                            = '';
285
-        parent::__construct($timezone);
286
-    }
287
-
288
-
289
-    /**
290
-     * @param string $default_reg_status
291
-     * @throws EE_Error
292
-     * @throws EE_Error
293
-     */
294
-    public static function set_default_reg_status($default_reg_status)
295
-    {
296
-        self::$_default_reg_status = $default_reg_status;
297
-        // if EEM_Event has already been instantiated,
298
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
299
-        if (self::$_instance instanceof EEM_Event) {
300
-            $default_reg_status = new EE_Enum_Text_Field(
301
-                'EVT_default_registration_status',
302
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
303
-                false,
304
-                $default_reg_status,
305
-                EEM_Registration::reg_status_array()
306
-            );
307
-            $default_reg_status->_construct_finalize(
308
-                'Event_Meta',
309
-                'EVT_default_registration_status',
310
-                'EEM_Event'
311
-            );
312
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
313
-        }
314
-    }
315
-
316
-
317
-    /**
318
-     * Used to override the default for the additional limit field.
319
-     *
320
-     * @param $additional_limit
321
-     */
322
-    public static function set_default_additional_limit($additional_limit)
323
-    {
324
-        self::$_default_additional_limit = (int) $additional_limit;
325
-        if (self::$_instance instanceof EEM_Event) {
326
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
327
-                'EVT_additional_limit',
328
-                esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
329
-                false,
330
-                self::$_default_additional_limit
331
-            );
332
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
333
-                'Event_Meta',
334
-                'EVT_additional_limit',
335
-                'EEM_Event'
336
-            );
337
-        }
338
-    }
339
-
340
-
341
-    /**
342
-     * Return what is currently set as the default additional limit for the event.
343
-     *
344
-     * @return int
345
-     */
346
-    public static function get_default_additional_limit()
347
-    {
348
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
349
-    }
350
-
351
-
352
-    /**
353
-     * get_question_groups
354
-     *
355
-     * @return array
356
-     * @throws EE_Error
357
-     * @throws ReflectionException
358
-     */
359
-    public function get_all_question_groups()
360
-    {
361
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
362
-            [
363
-                ['QSG_deleted' => false],
364
-                'order_by' => ['QSG_order' => 'ASC'],
365
-            ]
366
-        );
367
-    }
368
-
369
-
370
-    /**
371
-     * get_question_groups
372
-     *
373
-     * @param int $EVT_ID
374
-     * @return array|bool
375
-     * @throws EE_Error
376
-     * @throws ReflectionException
377
-     */
378
-    public function get_all_event_question_groups($EVT_ID = 0)
379
-    {
380
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
381
-            EE_Error::add_error(
382
-                esc_html__(
383
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
384
-                    'event_espresso'
385
-                ),
386
-                __FILE__,
387
-                __FUNCTION__,
388
-                __LINE__
389
-            );
390
-            return false;
391
-        }
392
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
393
-            [
394
-                ['EVT_ID' => $EVT_ID],
395
-            ]
396
-        );
397
-    }
398
-
399
-
400
-    /**
401
-     * get_question_groups
402
-     *
403
-     * @param int     $EVT_ID
404
-     * @param boolean $for_primary_attendee
405
-     * @return array|bool
406
-     * @throws EE_Error
407
-     * @throws InvalidArgumentException
408
-     * @throws ReflectionException
409
-     * @throws InvalidDataTypeException
410
-     * @throws InvalidInterfaceException
411
-     */
412
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
413
-    {
414
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
415
-            EE_Error::add_error(
416
-                esc_html__(
417
-                // @codingStandardsIgnoreStart
418
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
419
-                    // @codingStandardsIgnoreEnd
420
-                    'event_espresso'
421
-                ),
422
-                __FILE__,
423
-                __FUNCTION__,
424
-                __LINE__
425
-            );
426
-            return false;
427
-        }
428
-        $query_params = [
429
-            [
430
-                'EVT_ID'                                                                         => $EVT_ID,
431
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true,
432
-            ],
433
-        ];
434
-        if ($for_primary_attendee) {
435
-            $query_params[0]['EQG_primary'] = true;
436
-        } else {
437
-            $query_params[0]['EQG_additional'] = true;
438
-        }
439
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
440
-    }
441
-
442
-
443
-    /**
444
-     * get_question_groups
445
-     *
446
-     * @param int             $EVT_ID
447
-     * @param EE_Registration $registration
448
-     * @return array|bool
449
-     * @throws EE_Error
450
-     * @throws InvalidArgumentException
451
-     * @throws InvalidDataTypeException
452
-     * @throws InvalidInterfaceException
453
-     * @throws ReflectionException
454
-     */
455
-    public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
456
-    {
457
-        if (! absint($EVT_ID)) {
458
-            EE_Error::add_error(
459
-                esc_html__(
460
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
461
-                    'event_espresso'
462
-                ),
463
-                __FILE__,
464
-                __FUNCTION__,
465
-                __LINE__
466
-            );
467
-            return false;
468
-        }
469
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
470
-            [
471
-                [
472
-                    'Event_Question_Group.EVT_ID' => $EVT_ID,
473
-                    'Event_Question_Group.'
474
-                    . EEM_Event_Question_Group::instance()->fieldNameForContext(
475
-                        $registration->is_primary_registrant()
476
-                    )                             => true,
477
-                ],
478
-                'order_by' => ['QSG_order' => 'ASC'],
479
-            ]
480
-        );
481
-    }
482
-
483
-
484
-    /**
485
-     * get_question_target_db_column
486
-     *
487
-     * @param string $QSG_IDs csv list of $QSG IDs
488
-     * @return array|bool
489
-     * @throws EE_Error
490
-     * @throws ReflectionException
491
-     */
492
-    public function get_questions_in_groups($QSG_IDs = '')
493
-    {
494
-        if (empty($QSG_IDs)) {
495
-            EE_Error::add_error(
496
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
497
-                __FILE__,
498
-                __FUNCTION__,
499
-                __LINE__
500
-            );
501
-            return false;
502
-        }
503
-        return EE_Registry::instance()->load_model('Question')->get_all(
504
-            [
505
-                [
506
-                    'Question_Group.QSG_ID' => ['IN', $QSG_IDs],
507
-                    'QST_deleted'           => false,
508
-                    'QST_admin_only'        => is_admin(),
509
-                ],
510
-                'order_by' => 'QST_order',
511
-            ]
512
-        );
513
-    }
514
-
515
-
516
-    /**
517
-     * get_options_for_question
518
-     *
519
-     * @param string $QST_IDs csv list of $QST IDs
520
-     * @return array|bool
521
-     * @throws EE_Error
522
-     * @throws ReflectionException
523
-     */
524
-    public function get_options_for_question($QST_IDs)
525
-    {
526
-        if (empty($QST_IDs)) {
527
-            EE_Error::add_error(
528
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
529
-                __FILE__,
530
-                __FUNCTION__,
531
-                __LINE__
532
-            );
533
-            return false;
534
-        }
535
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
536
-            [
537
-                [
538
-                    'Question.QST_ID' => ['IN', $QST_IDs],
539
-                    'QSO_deleted'     => false,
540
-                ],
541
-                'order_by' => 'QSO_ID',
542
-            ]
543
-        );
544
-    }
545
-
546
-
547
-    /**
548
-     * Gets all events that are published
549
-     * and have event start time earlier than now and an event end time later than now
550
-     *
551
-     * @param array $query_params  An array of query params to further filter on
552
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
553
-     * @param bool  $count         whether to return the count or not (default FALSE)
554
-     * @return EE_Event[]|int
555
-     * @throws EE_Error
556
-     * @throws ReflectionException
557
-     */
558
-    public function get_active_events($query_params, $count = false)
559
-    {
560
-        if (array_key_exists(0, $query_params)) {
561
-            $where_params = $query_params[0];
562
-            unset($query_params[0]);
563
-        } else {
564
-            $where_params = [];
565
-        }
566
-        // if we have count make sure we don't include group by
567
-        if ($count && isset($query_params['group_by'])) {
568
-            unset($query_params['group_by']);
569
-        }
570
-        // add status query
571
-        $where_params = $this->set_where_conditions_for_status($where_params);
572
-        // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
573
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
574
-            $where_params['Datetime.DTT_EVT_start******'] = [
575
-                '<',
576
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
577
-            ];
578
-        } else {
579
-            $where_params['Datetime.DTT_EVT_start'] = [
580
-                '<',
581
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
582
-            ];
583
-        }
584
-        $where_params = $this->set_where_conditions_for_end_datetime($where_params);
585
-        return $this->_get_count_or_all($query_params, $where_params, $count);
586
-    }
587
-
588
-
589
-    /**
590
-     * get all events that are published and have an event start time later than now
591
-     *
592
-     * @param array $query_params  An array of query params to further filter on
593
-     *                             (Note that status and DTT_EVT_start will be overridden)
594
-     * @param bool  $count         whether to return the count or not (default FALSE)
595
-     * @return EE_Event[]|int
596
-     * @throws EE_Error
597
-     * @throws ReflectionException
598
-     */
599
-    public function get_upcoming_events($query_params, $count = false)
600
-    {
601
-        if (array_key_exists(0, $query_params)) {
602
-            $where_params = $query_params[0];
603
-            unset($query_params[0]);
604
-        } else {
605
-            $where_params = [];
606
-        }
607
-        // if we have count make sure we don't include group by
608
-        if ($count && isset($query_params['group_by'])) {
609
-            unset($query_params['group_by']);
610
-        }
611
-        // add status query
612
-        $where_params = $this->set_where_conditions_for_status($where_params);
613
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
614
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
615
-            $where_params['Datetime.DTT_EVT_start*****'] = [
616
-                '>',
617
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
618
-            ];
619
-        } else {
620
-            $where_params['Datetime.DTT_EVT_start'] = [
621
-                '>',
622
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
623
-            ];
624
-        }
625
-        return $this->_get_count_or_all($query_params, $where_params, $count);
626
-    }
627
-
628
-
629
-    /**
630
-     * Gets all events that are published
631
-     * and have an event end time later than now
632
-     *
633
-     * @param array $query_params  An array of query params to further filter on
634
-     *                             (note that status and DTT_EVT_end will be overridden)
635
-     * @param bool  $count         whether to return the count or not (default FALSE)
636
-     * @return EE_Event[]|int
637
-     * @throws EE_Error
638
-     * @throws ReflectionException
639
-     */
640
-    public function get_active_and_upcoming_events($query_params, $count = false)
641
-    {
642
-        if (array_key_exists(0, $query_params)) {
643
-            $where_params = $query_params[0];
644
-            unset($query_params[0]);
645
-        } else {
646
-            $where_params = [];
647
-        }
648
-        // if we have count make sure we don't include group by
649
-        if ($count && isset($query_params['group_by'])) {
650
-            unset($query_params['group_by']);
651
-        }
652
-        // add status query
653
-        $where_params = $this->set_where_conditions_for_status($where_params);
654
-        // add where params for DTT_EVT_end
655
-        $where_params = $this->set_where_conditions_for_end_datetime($where_params);
656
-        return $this->_get_count_or_all($query_params, $where_params, $count);
657
-    }
658
-
659
-
660
-    /**
661
-     * This only returns events that are expired.
662
-     * They may still be published but all their datetimes have expired.
663
-     *
664
-     * @param array $query_params  An array of query params to further filter on
665
-     *                             (note that status and DTT_EVT_end will be overridden)
666
-     * @param bool  $count         whether to return the count or not (default FALSE)
667
-     * @return EE_Event[]|int
668
-     * @throws EE_Error
669
-     * @throws ReflectionException
670
-     */
671
-    public function get_expired_events($query_params, $count = false)
672
-    {
673
-        $where_params = isset($query_params[0])
674
-            ? $query_params[0]
675
-            : [];
676
-        // if we have count make sure we don't include group by
677
-        if ($count && isset($query_params['group_by'])) {
678
-            unset($query_params['group_by']);
679
-        }
680
-        // let's add specific query_params for active_events
681
-        // keep in mind this will override any sent status in the query AND any date queries.
682
-        if (isset($where_params['status'])) {
683
-            unset($where_params['status']);
684
-        }
685
-        // first get all events that have datetimes where its not expired.
686
-        $event_ids = $this->get_all_not_expired_event_ids($query_params);
687
-        // if we have any additional query_params, let's add them to the 'AND' condition
688
-        $and_condition = [
689
-            'Datetime.DTT_EVT_end' => ['<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')],
690
-            'EVT_ID'               => ['NOT IN', $event_ids],
691
-        ];
692
-        if (isset($where_params['OR'])) {
693
-            $and_condition['OR'] = $where_params['OR'];
694
-            unset($where_params['OR']);
695
-        }
696
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
697
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
698
-            unset($where_params['Datetime.DTT_EVT_end']);
699
-        }
700
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
701
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
702
-            unset($where_params['Datetime.DTT_EVT_start']);
703
-        }
704
-        // merge remaining $where params with the and conditions.
705
-        $where_params['AND'] = array_merge($and_condition, $where_params);
706
-        return $this->_get_count_or_all($query_params, $where_params, $count);
707
-    }
708
-
709
-
710
-    /**
711
-     * @param array $query_params
712
-     * @return int[]
713
-     * @throws EE_Error
714
-     * @throws ReflectionException
715
-     */
716
-    public function get_all_not_expired_event_ids(array $query_params = []): array
717
-    {
718
-        $query_params[0] = [
719
-            'Datetime.DTT_EVT_end' => [
720
-                '>',
721
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
722
-            ],
723
-        ];
724
-        $event_ids       = $this->_get_all_wpdb_results($query_params, OBJECT_K, 'Event_CPT.ID');
725
-        return array_keys($event_ids);
726
-    }
727
-
728
-
729
-    /**
730
-     * This basically just returns the events that do not have the publish status.
731
-     *
732
-     * @param array   $query_params  An array of query params to further filter on
733
-     *                               (note that status will be overwritten)
734
-     * @param boolean $count         whether to return the count or not (default FALSE)
735
-     * @return EE_Event[]|int
736
-     * @throws EE_Error
737
-     * @throws ReflectionException
738
-     */
739
-    public function get_inactive_events($query_params, $count = false)
740
-    {
741
-        $where_params = isset($query_params[0])
742
-            ? $query_params[0]
743
-            : [];
744
-        // let's add in specific query_params for inactive events.
745
-        if (isset($where_params['status'])) {
746
-            unset($where_params['status']);
747
-        }
748
-        // if we have count make sure we don't include group by
749
-        if ($count && isset($query_params['group_by'])) {
750
-            unset($query_params['group_by']);
751
-        }
752
-        // if we have any additional query_params, let's add them to the 'AND' condition
753
-        $where_params['AND']['status'] = ['!=', 'publish'];
754
-        if (isset($where_params['OR'])) {
755
-            $where_params['AND']['OR'] = $where_params['OR'];
756
-            unset($where_params['OR']);
757
-        }
758
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
759
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
760
-            unset($where_params['Datetime.DTT_EVT_end']);
761
-        }
762
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
763
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
764
-            unset($where_params['Datetime.DTT_EVT_start']);
765
-        }
766
-        return $this->_get_count_or_all($query_params, $where_params, $count);
767
-    }
768
-
769
-
770
-    /**
771
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
772
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
773
-     * attached to the event. See parent for param descriptions
774
-     *
775
-     * @param        $id_or_obj
776
-     * @param        $other_model_id_or_obj
777
-     * @param string $relationName
778
-     * @param array  $where_query
779
-     * @return EE_Base_Class
780
-     * @throws EE_Error
781
-     * @throws ReflectionException
782
-     */
783
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = [])
784
-    {
785
-        if ($relationName === 'Price') {
786
-            // let's get the PRC object for the given ID to make sure that we aren't dealing with a default
787
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
788
-            // if EVT_ID = 0, then this is a default
789
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
790
-                // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
791
-                $prc_chk->set('PRC_ID', 0);
792
-            }
793
-            // run parent
794
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
795
-        }
796
-        // otherwise carry on as normal
797
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
798
-    }
799
-
800
-
801
-    /**
802
-     * @param array $where_params
803
-     * @return array
804
-     */
805
-    public function set_where_conditions_for_status(array $where_params): array
806
-    {
807
-        // let's add specific query_params for active_events
808
-        // keep in mind this will override any sent status in the query AND any date queries.
809
-        // we need to pull events with a status of publish and sold_out
810
-        $event_status = ['publish', EEM_Event::sold_out];
811
-        // check if the user can read private events and if so add the 'private status to the where params'
812
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
813
-            $event_status[] = 'private';
814
-        }
815
-        $where_params['status'] = ['IN', $event_status];
816
-        return $where_params;
817
-    }
818
-
819
-
820
-    /**
821
-     * @param array $where_params
822
-     * @return array
823
-     * @throws EE_Error
824
-     * @throws ReflectionException
825
-     */
826
-    public function set_where_conditions_for_end_datetime(array $where_params): array
827
-    {
828
-        $end_date_field_name = isset($where_params['Datetime.DTT_EVT_end'])
829
-            ? 'Datetime.DTT_EVT_end*****'
830
-            // prevents overwrite of existing where condition
831
-            : 'Datetime.DTT_EVT_end';
832
-
833
-        $where_params[ $end_date_field_name ] = [
834
-            '>',
835
-            EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
836
-        ];
837
-
838
-        return $where_params;
839
-    }
840
-
841
-
842
-    /**
843
-     * @param array $query_params
844
-     * @param array $where_params
845
-     * @param bool  $count
846
-     * @return EE_Soft_Delete_Base_Class[]|int
847
-     * @throws EE_Error
848
-     * @throws ReflectionException
849
-     */
850
-    protected function _get_count_or_all(array $query_params, array $where_params, bool $count = false)
851
-    {
852
-        $query_params[0] = $where_params;
853
-        // don't use $query_params with count()
854
-        // because we don't want to include additional query clauses like "GROUP BY"
855
-        return $count
856
-            ? $this->count([$where_params], 'EVT_ID', true)
857
-            : $this->get_all($query_params);
858
-    }
859
-
860
-
861
-    /******************** DEPRECATED METHODS ********************/
862
-
863
-
864
-    /**
865
-     * _get_question_target_db_column
866
-     *
867
-     * @param EE_Registration $registration    (so existing answers for registration are included)
868
-     * @param int             $EVT_ID          so all question groups are included for event (not just answers from
869
-     *                                         registration).
870
-     * @return    array
871
-     * @throws ReflectionException
872
-     * @throws EE_Error
873
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
874
-     *                                         EE_Registration_Custom_Questions_Form located in
875
-     *                                         admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
876
-     * @access     public
877
-     */
878
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
879
-    {
880
-        if (empty($EVT_ID)) {
881
-            throw new EE_Error(
882
-                esc_html__(
883
-                    'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
884
-                    'event_espresso'
885
-                )
886
-            );
887
-        }
888
-        $questions = [];
889
-        // get all question groups for event
890
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
891
-        if (! empty($qgs)) {
892
-            foreach ($qgs as $qg) {
893
-                $qsts                                    = $qg->questions();
894
-                $questions[ $qg->ID() ]                  = $qg->model_field_array();
895
-                $questions[ $qg->ID() ]['QSG_questions'] = [];
896
-                foreach ($qsts as $qst) {
897
-                    if ($qst->is_system_question()) {
898
-                        continue;
899
-                    }
900
-                    $answer                                                                   =
901
-                        EEM_Answer::instance()->get_one(
902
-                            [
903
-                                [
904
-                                    'QST_ID' => $qst->ID(),
905
-                                    'REG_ID' => $registration->ID(),
906
-                                ],
907
-                            ]
908
-                        );
909
-                    $answer                                                                   =
910
-                        $answer instanceof EE_Answer
911
-                            ? $answer
912
-                            : EEM_Answer::instance()->create_default_object();
913
-                    $qst_name                                                                 = $qstn_id = $qst->ID();
914
-                    $ans_id                                                                   = $answer->ID();
915
-                    $qst_name                                                                 = ! empty($ans_id)
916
-                        ? '[' . $qst_name . '][' . $ans_id . ']'
917
-                        : '[' . $qst_name . ']';
918
-                    $input_name                                                               = '';
919
-                    $input_id                                                                 =
920
-                        sanitize_key($qst->display_text());
921
-                    $input_class                                                              = '';
922
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]                    =
923
-                        $qst->model_field_array();
924
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name']  = 'qstn'
925
-                                                                                                . $input_name
926
-                                                                                                . $qst_name;
927
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id']    =
928
-                        $input_id . '-' . $qstn_id;
929
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
930
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options']     = [];
931
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj']         = $qst;
932
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj']         = $answer;
933
-                    // leave responses as-is, don't convert stuff into html entities please!
934
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
935
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
936
-                        $QSOs = $qst->options(true, $answer->value());
937
-                        if (is_array($QSOs)) {
938
-                            foreach ($QSOs as $QSO_ID => $QSO) {
939
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] =
940
-                                    $QSO->model_field_array();
941
-                            }
942
-                        }
943
-                    }
944
-                }
945
-            }
946
-        }
947
-        return $questions;
948
-    }
949
-
950
-
951
-    /**
952
-     * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
953
-     *                             or an stdClass where each property is the name of a column,
954
-     * @return EE_Base_Class
955
-     * @throws EE_Error
956
-     * @throws ReflectionException
957
-     */
958
-    public function instantiate_class_from_array_or_object($cols_n_values)
959
-    {
960
-        $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
961
-        if ($classInstance instanceof EE_Event) {
962
-            // events have their timezone defined in the DB, so use it immediately
963
-            $this->set_timezone($classInstance->get_timezone());
964
-        }
965
-        return $classInstance;
966
-    }
18
+	/**
19
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
20
+	 * event
21
+	 */
22
+	const sold_out = 'sold_out';
23
+
24
+	/**
25
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
26
+	 * date)
27
+	 */
28
+	const postponed = 'postponed';
29
+
30
+	/**
31
+	 * constant used by status(), indicating that the event will no longer occur
32
+	 */
33
+	const cancelled = 'cancelled';
34
+
35
+
36
+	protected static string $_default_reg_status;
37
+
38
+	protected static int $_default_additional_limit = 10;
39
+
40
+	protected static ?EEM_Event $_instance = null;
41
+
42
+
43
+	/**
44
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
45
+	 *
46
+	 * @param string|null $timezone
47
+	 * @throws EE_Error
48
+	 * @throws ReflectionException
49
+	 */
50
+	protected function __construct(?string $timezone = '')
51
+	{
52
+		EE_Registry::instance()->load_model('Registration');
53
+		$this->singular_item = esc_html__('Event', 'event_espresso');
54
+		$this->plural_item   = esc_html__('Events', 'event_espresso');
55
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
56
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
57
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
58
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
59
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
60
+		//  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
61
+		$this->_custom_stati       = apply_filters(
62
+			'AFEE__EEM_Event__construct___custom_stati',
63
+			[
64
+				EEM_Event::cancelled => [
65
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
66
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
67
+				],
68
+				EEM_Event::postponed => [
69
+					'label'  => esc_html__('Postponed', 'event_espresso'),
70
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
71
+				],
72
+				EEM_Event::sold_out  => [
73
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
74
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
75
+				],
76
+			]
77
+		);
78
+		self::$_default_reg_status = empty(self::$_default_reg_status)
79
+			? RegStatus::PENDING_PAYMENT
80
+			: self::$_default_reg_status;
81
+		$this->_tables             = [
82
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
83
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
84
+		];
85
+		$this->_fields             = [
86
+			'Event_CPT'  => [
87
+				'EVT_ID'         => new EE_Primary_Key_Int_Field(
88
+					'ID',
89
+					esc_html__('Post ID for Event', 'event_espresso')
90
+				),
91
+				'EVT_name'       => new EE_Plain_Text_Field(
92
+					'post_title',
93
+					esc_html__('Event Name', 'event_espresso'),
94
+					false,
95
+					''
96
+				),
97
+				'EVT_desc'       => new EE_Post_Content_Field(
98
+					'post_content',
99
+					esc_html__('Event Description', 'event_espresso'),
100
+					false,
101
+					''
102
+				),
103
+				'EVT_slug'       => new EE_Slug_Field(
104
+					'post_name',
105
+					esc_html__('Event Slug', 'event_espresso'),
106
+					false,
107
+					''
108
+				),
109
+				'EVT_created'    => new EE_Datetime_Field(
110
+					'post_date',
111
+					esc_html__('Date/Time Event Created', 'event_espresso'),
112
+					false,
113
+					EE_Datetime_Field::now
114
+				),
115
+				'EVT_short_desc' => new EE_Simple_HTML_Field(
116
+					'post_excerpt',
117
+					esc_html__('Event Short Description', 'event_espresso'),
118
+					false,
119
+					''
120
+				),
121
+				'EVT_modified'   => new EE_Datetime_Field(
122
+					'post_modified',
123
+					esc_html__('Date/Time Event Modified', 'event_espresso'),
124
+					false,
125
+					EE_Datetime_Field::now
126
+				),
127
+				'EVT_wp_user'    => new EE_WP_User_Field(
128
+					'post_author',
129
+					esc_html__('Event Creator ID', 'event_espresso'),
130
+					false
131
+				),
132
+				'parent'         => new EE_Integer_Field(
133
+					'post_parent',
134
+					esc_html__('Event Parent ID', 'event_espresso'),
135
+					false,
136
+					0
137
+				),
138
+				'EVT_order'      => new EE_Integer_Field(
139
+					'menu_order',
140
+					esc_html__('Event Menu Order', 'event_espresso'),
141
+					false,
142
+					1
143
+				),
144
+				'post_type'      => new EE_WP_Post_Type_Field(EspressoPostType::EVENTS),
145
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
146
+				'status'         => new EE_WP_Post_Status_Field(
147
+					'post_status',
148
+					esc_html__('Event Status', 'event_espresso'),
149
+					false,
150
+					'draft',
151
+					$this->_custom_stati
152
+				),
153
+				'password'       => new EE_Password_Field(
154
+					'post_password',
155
+					esc_html__('Password', 'event_espresso'),
156
+					false,
157
+					'',
158
+					[
159
+						'EVT_desc',
160
+						'EVT_short_desc',
161
+						'EVT_display_desc',
162
+						'EVT_display_ticket_selector',
163
+						'EVT_visible_on',
164
+						'EVT_additional_limit',
165
+						'EVT_default_registration_status',
166
+						'EVT_member_only',
167
+						'EVT_phone',
168
+						'EVT_allow_overflow',
169
+						'EVT_timezone_string',
170
+						'EVT_external_URL',
171
+						'EVT_donations',
172
+					]
173
+				),
174
+			],
175
+			'Event_Meta' => [
176
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field(
177
+					'EVTM_ID',
178
+					esc_html__('Event Meta Row ID', 'event_espresso'),
179
+					false
180
+				),
181
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
182
+					'EVT_ID',
183
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
184
+					false
185
+				),
186
+				'VNU_ID'                          => new EE_Foreign_Key_Int_Field(
187
+					'VNU_ID',
188
+					__('Venue ID', 'event_espresso'),
189
+					false,
190
+					0,
191
+					'Venue'
192
+				),
193
+				'EVT_display_desc'                => new EE_Boolean_Field(
194
+					'EVT_display_desc',
195
+					esc_html__('Display Description Flag', 'event_espresso'),
196
+					false,
197
+					true
198
+				),
199
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field(
200
+					'EVT_display_ticket_selector',
201
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'),
202
+					false,
203
+					true
204
+				),
205
+				'EVT_visible_on'                  => new EE_Datetime_Field(
206
+					'EVT_visible_on',
207
+					esc_html__('Event Visible Date', 'event_espresso'),
208
+					true,
209
+					EE_Datetime_Field::now
210
+				),
211
+				'EVT_additional_limit'            => new EE_Integer_Field(
212
+					'EVT_additional_limit',
213
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
214
+					false,
215
+					self::$_default_additional_limit
216
+				),
217
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
218
+					'EVT_default_registration_status',
219
+					esc_html__('Default Registration Status on this Event', 'event_espresso'),
220
+					false,
221
+					EEM_Event::$_default_reg_status,
222
+					EEM_Registration::reg_status_array()
223
+				),
224
+				'EVT_member_only'                 => new EE_Boolean_Field(
225
+					'EVT_member_only',
226
+					esc_html__('Member-Only Event Flag', 'event_espresso'),
227
+					false,
228
+					false
229
+				),
230
+				'EVT_phone'                       => new EE_Plain_Text_Field(
231
+					'EVT_phone',
232
+					esc_html__('Event Phone Number', 'event_espresso'),
233
+					false,
234
+					''
235
+				),
236
+				'EVT_allow_overflow'              => new EE_Boolean_Field(
237
+					'EVT_allow_overflow',
238
+					esc_html__('Allow Overflow on Event', 'event_espresso'),
239
+					false,
240
+					false
241
+				),
242
+				'EVT_timezone_string'             => new EE_Plain_Text_Field(
243
+					'EVT_timezone_string',
244
+					esc_html__('Timezone (name) for Event times', 'event_espresso'),
245
+					false,
246
+					''
247
+				),
248
+				'EVT_external_URL'                => new EE_Plain_Text_Field(
249
+					'EVT_external_URL',
250
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
251
+					true
252
+				),
253
+				'EVT_donations'                   => new EE_Boolean_Field(
254
+					'EVT_donations',
255
+					esc_html__('Accept Donations?', 'event_espresso'),
256
+					false,
257
+					false
258
+				),
259
+				'FSC_UUID'                        => new EE_Foreign_Key_String_Field(
260
+					'FSC_UUID',
261
+					esc_html__('Registration Form UUID (universally unique identifier)', 'event_espresso'),
262
+					true,
263
+					null,
264
+					'Form_Section',
265
+					false
266
+				),
267
+			],
268
+		];
269
+		$this->_model_relations    = [
270
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
271
+			'Datetime'               => new EE_Has_Many_Relation(),
272
+			'Event_Question_Group'   => new EE_Has_Many_Relation(),
273
+			'Form_Section'           => new EE_Belongs_To_Relation(),
274
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
275
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
276
+			'Registration'           => new EE_Has_Many_Relation(),
277
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
278
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
279
+			'Venue'                  => new EE_Belongs_To_Relation(),
280
+			'WP_User'                => new EE_Belongs_To_Relation(),
281
+		];
282
+		// this model is generally available for reading
283
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
284
+		$this->model_chain_to_password                            = '';
285
+		parent::__construct($timezone);
286
+	}
287
+
288
+
289
+	/**
290
+	 * @param string $default_reg_status
291
+	 * @throws EE_Error
292
+	 * @throws EE_Error
293
+	 */
294
+	public static function set_default_reg_status($default_reg_status)
295
+	{
296
+		self::$_default_reg_status = $default_reg_status;
297
+		// if EEM_Event has already been instantiated,
298
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
299
+		if (self::$_instance instanceof EEM_Event) {
300
+			$default_reg_status = new EE_Enum_Text_Field(
301
+				'EVT_default_registration_status',
302
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
303
+				false,
304
+				$default_reg_status,
305
+				EEM_Registration::reg_status_array()
306
+			);
307
+			$default_reg_status->_construct_finalize(
308
+				'Event_Meta',
309
+				'EVT_default_registration_status',
310
+				'EEM_Event'
311
+			);
312
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
313
+		}
314
+	}
315
+
316
+
317
+	/**
318
+	 * Used to override the default for the additional limit field.
319
+	 *
320
+	 * @param $additional_limit
321
+	 */
322
+	public static function set_default_additional_limit($additional_limit)
323
+	{
324
+		self::$_default_additional_limit = (int) $additional_limit;
325
+		if (self::$_instance instanceof EEM_Event) {
326
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
327
+				'EVT_additional_limit',
328
+				esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
329
+				false,
330
+				self::$_default_additional_limit
331
+			);
332
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
333
+				'Event_Meta',
334
+				'EVT_additional_limit',
335
+				'EEM_Event'
336
+			);
337
+		}
338
+	}
339
+
340
+
341
+	/**
342
+	 * Return what is currently set as the default additional limit for the event.
343
+	 *
344
+	 * @return int
345
+	 */
346
+	public static function get_default_additional_limit()
347
+	{
348
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
349
+	}
350
+
351
+
352
+	/**
353
+	 * get_question_groups
354
+	 *
355
+	 * @return array
356
+	 * @throws EE_Error
357
+	 * @throws ReflectionException
358
+	 */
359
+	public function get_all_question_groups()
360
+	{
361
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
362
+			[
363
+				['QSG_deleted' => false],
364
+				'order_by' => ['QSG_order' => 'ASC'],
365
+			]
366
+		);
367
+	}
368
+
369
+
370
+	/**
371
+	 * get_question_groups
372
+	 *
373
+	 * @param int $EVT_ID
374
+	 * @return array|bool
375
+	 * @throws EE_Error
376
+	 * @throws ReflectionException
377
+	 */
378
+	public function get_all_event_question_groups($EVT_ID = 0)
379
+	{
380
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
381
+			EE_Error::add_error(
382
+				esc_html__(
383
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
384
+					'event_espresso'
385
+				),
386
+				__FILE__,
387
+				__FUNCTION__,
388
+				__LINE__
389
+			);
390
+			return false;
391
+		}
392
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
393
+			[
394
+				['EVT_ID' => $EVT_ID],
395
+			]
396
+		);
397
+	}
398
+
399
+
400
+	/**
401
+	 * get_question_groups
402
+	 *
403
+	 * @param int     $EVT_ID
404
+	 * @param boolean $for_primary_attendee
405
+	 * @return array|bool
406
+	 * @throws EE_Error
407
+	 * @throws InvalidArgumentException
408
+	 * @throws ReflectionException
409
+	 * @throws InvalidDataTypeException
410
+	 * @throws InvalidInterfaceException
411
+	 */
412
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
413
+	{
414
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
415
+			EE_Error::add_error(
416
+				esc_html__(
417
+				// @codingStandardsIgnoreStart
418
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
419
+					// @codingStandardsIgnoreEnd
420
+					'event_espresso'
421
+				),
422
+				__FILE__,
423
+				__FUNCTION__,
424
+				__LINE__
425
+			);
426
+			return false;
427
+		}
428
+		$query_params = [
429
+			[
430
+				'EVT_ID'                                                                         => $EVT_ID,
431
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true,
432
+			],
433
+		];
434
+		if ($for_primary_attendee) {
435
+			$query_params[0]['EQG_primary'] = true;
436
+		} else {
437
+			$query_params[0]['EQG_additional'] = true;
438
+		}
439
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
440
+	}
441
+
442
+
443
+	/**
444
+	 * get_question_groups
445
+	 *
446
+	 * @param int             $EVT_ID
447
+	 * @param EE_Registration $registration
448
+	 * @return array|bool
449
+	 * @throws EE_Error
450
+	 * @throws InvalidArgumentException
451
+	 * @throws InvalidDataTypeException
452
+	 * @throws InvalidInterfaceException
453
+	 * @throws ReflectionException
454
+	 */
455
+	public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
456
+	{
457
+		if (! absint($EVT_ID)) {
458
+			EE_Error::add_error(
459
+				esc_html__(
460
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
461
+					'event_espresso'
462
+				),
463
+				__FILE__,
464
+				__FUNCTION__,
465
+				__LINE__
466
+			);
467
+			return false;
468
+		}
469
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
470
+			[
471
+				[
472
+					'Event_Question_Group.EVT_ID' => $EVT_ID,
473
+					'Event_Question_Group.'
474
+					. EEM_Event_Question_Group::instance()->fieldNameForContext(
475
+						$registration->is_primary_registrant()
476
+					)                             => true,
477
+				],
478
+				'order_by' => ['QSG_order' => 'ASC'],
479
+			]
480
+		);
481
+	}
482
+
483
+
484
+	/**
485
+	 * get_question_target_db_column
486
+	 *
487
+	 * @param string $QSG_IDs csv list of $QSG IDs
488
+	 * @return array|bool
489
+	 * @throws EE_Error
490
+	 * @throws ReflectionException
491
+	 */
492
+	public function get_questions_in_groups($QSG_IDs = '')
493
+	{
494
+		if (empty($QSG_IDs)) {
495
+			EE_Error::add_error(
496
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
497
+				__FILE__,
498
+				__FUNCTION__,
499
+				__LINE__
500
+			);
501
+			return false;
502
+		}
503
+		return EE_Registry::instance()->load_model('Question')->get_all(
504
+			[
505
+				[
506
+					'Question_Group.QSG_ID' => ['IN', $QSG_IDs],
507
+					'QST_deleted'           => false,
508
+					'QST_admin_only'        => is_admin(),
509
+				],
510
+				'order_by' => 'QST_order',
511
+			]
512
+		);
513
+	}
514
+
515
+
516
+	/**
517
+	 * get_options_for_question
518
+	 *
519
+	 * @param string $QST_IDs csv list of $QST IDs
520
+	 * @return array|bool
521
+	 * @throws EE_Error
522
+	 * @throws ReflectionException
523
+	 */
524
+	public function get_options_for_question($QST_IDs)
525
+	{
526
+		if (empty($QST_IDs)) {
527
+			EE_Error::add_error(
528
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
529
+				__FILE__,
530
+				__FUNCTION__,
531
+				__LINE__
532
+			);
533
+			return false;
534
+		}
535
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
536
+			[
537
+				[
538
+					'Question.QST_ID' => ['IN', $QST_IDs],
539
+					'QSO_deleted'     => false,
540
+				],
541
+				'order_by' => 'QSO_ID',
542
+			]
543
+		);
544
+	}
545
+
546
+
547
+	/**
548
+	 * Gets all events that are published
549
+	 * and have event start time earlier than now and an event end time later than now
550
+	 *
551
+	 * @param array $query_params  An array of query params to further filter on
552
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
553
+	 * @param bool  $count         whether to return the count or not (default FALSE)
554
+	 * @return EE_Event[]|int
555
+	 * @throws EE_Error
556
+	 * @throws ReflectionException
557
+	 */
558
+	public function get_active_events($query_params, $count = false)
559
+	{
560
+		if (array_key_exists(0, $query_params)) {
561
+			$where_params = $query_params[0];
562
+			unset($query_params[0]);
563
+		} else {
564
+			$where_params = [];
565
+		}
566
+		// if we have count make sure we don't include group by
567
+		if ($count && isset($query_params['group_by'])) {
568
+			unset($query_params['group_by']);
569
+		}
570
+		// add status query
571
+		$where_params = $this->set_where_conditions_for_status($where_params);
572
+		// if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
573
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
574
+			$where_params['Datetime.DTT_EVT_start******'] = [
575
+				'<',
576
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
577
+			];
578
+		} else {
579
+			$where_params['Datetime.DTT_EVT_start'] = [
580
+				'<',
581
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
582
+			];
583
+		}
584
+		$where_params = $this->set_where_conditions_for_end_datetime($where_params);
585
+		return $this->_get_count_or_all($query_params, $where_params, $count);
586
+	}
587
+
588
+
589
+	/**
590
+	 * get all events that are published and have an event start time later than now
591
+	 *
592
+	 * @param array $query_params  An array of query params to further filter on
593
+	 *                             (Note that status and DTT_EVT_start will be overridden)
594
+	 * @param bool  $count         whether to return the count or not (default FALSE)
595
+	 * @return EE_Event[]|int
596
+	 * @throws EE_Error
597
+	 * @throws ReflectionException
598
+	 */
599
+	public function get_upcoming_events($query_params, $count = false)
600
+	{
601
+		if (array_key_exists(0, $query_params)) {
602
+			$where_params = $query_params[0];
603
+			unset($query_params[0]);
604
+		} else {
605
+			$where_params = [];
606
+		}
607
+		// if we have count make sure we don't include group by
608
+		if ($count && isset($query_params['group_by'])) {
609
+			unset($query_params['group_by']);
610
+		}
611
+		// add status query
612
+		$where_params = $this->set_where_conditions_for_status($where_params);
613
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
614
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
615
+			$where_params['Datetime.DTT_EVT_start*****'] = [
616
+				'>',
617
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
618
+			];
619
+		} else {
620
+			$where_params['Datetime.DTT_EVT_start'] = [
621
+				'>',
622
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
623
+			];
624
+		}
625
+		return $this->_get_count_or_all($query_params, $where_params, $count);
626
+	}
627
+
628
+
629
+	/**
630
+	 * Gets all events that are published
631
+	 * and have an event end time later than now
632
+	 *
633
+	 * @param array $query_params  An array of query params to further filter on
634
+	 *                             (note that status and DTT_EVT_end will be overridden)
635
+	 * @param bool  $count         whether to return the count or not (default FALSE)
636
+	 * @return EE_Event[]|int
637
+	 * @throws EE_Error
638
+	 * @throws ReflectionException
639
+	 */
640
+	public function get_active_and_upcoming_events($query_params, $count = false)
641
+	{
642
+		if (array_key_exists(0, $query_params)) {
643
+			$where_params = $query_params[0];
644
+			unset($query_params[0]);
645
+		} else {
646
+			$where_params = [];
647
+		}
648
+		// if we have count make sure we don't include group by
649
+		if ($count && isset($query_params['group_by'])) {
650
+			unset($query_params['group_by']);
651
+		}
652
+		// add status query
653
+		$where_params = $this->set_where_conditions_for_status($where_params);
654
+		// add where params for DTT_EVT_end
655
+		$where_params = $this->set_where_conditions_for_end_datetime($where_params);
656
+		return $this->_get_count_or_all($query_params, $where_params, $count);
657
+	}
658
+
659
+
660
+	/**
661
+	 * This only returns events that are expired.
662
+	 * They may still be published but all their datetimes have expired.
663
+	 *
664
+	 * @param array $query_params  An array of query params to further filter on
665
+	 *                             (note that status and DTT_EVT_end will be overridden)
666
+	 * @param bool  $count         whether to return the count or not (default FALSE)
667
+	 * @return EE_Event[]|int
668
+	 * @throws EE_Error
669
+	 * @throws ReflectionException
670
+	 */
671
+	public function get_expired_events($query_params, $count = false)
672
+	{
673
+		$where_params = isset($query_params[0])
674
+			? $query_params[0]
675
+			: [];
676
+		// if we have count make sure we don't include group by
677
+		if ($count && isset($query_params['group_by'])) {
678
+			unset($query_params['group_by']);
679
+		}
680
+		// let's add specific query_params for active_events
681
+		// keep in mind this will override any sent status in the query AND any date queries.
682
+		if (isset($where_params['status'])) {
683
+			unset($where_params['status']);
684
+		}
685
+		// first get all events that have datetimes where its not expired.
686
+		$event_ids = $this->get_all_not_expired_event_ids($query_params);
687
+		// if we have any additional query_params, let's add them to the 'AND' condition
688
+		$and_condition = [
689
+			'Datetime.DTT_EVT_end' => ['<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')],
690
+			'EVT_ID'               => ['NOT IN', $event_ids],
691
+		];
692
+		if (isset($where_params['OR'])) {
693
+			$and_condition['OR'] = $where_params['OR'];
694
+			unset($where_params['OR']);
695
+		}
696
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
697
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
698
+			unset($where_params['Datetime.DTT_EVT_end']);
699
+		}
700
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
701
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
702
+			unset($where_params['Datetime.DTT_EVT_start']);
703
+		}
704
+		// merge remaining $where params with the and conditions.
705
+		$where_params['AND'] = array_merge($and_condition, $where_params);
706
+		return $this->_get_count_or_all($query_params, $where_params, $count);
707
+	}
708
+
709
+
710
+	/**
711
+	 * @param array $query_params
712
+	 * @return int[]
713
+	 * @throws EE_Error
714
+	 * @throws ReflectionException
715
+	 */
716
+	public function get_all_not_expired_event_ids(array $query_params = []): array
717
+	{
718
+		$query_params[0] = [
719
+			'Datetime.DTT_EVT_end' => [
720
+				'>',
721
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
722
+			],
723
+		];
724
+		$event_ids       = $this->_get_all_wpdb_results($query_params, OBJECT_K, 'Event_CPT.ID');
725
+		return array_keys($event_ids);
726
+	}
727
+
728
+
729
+	/**
730
+	 * This basically just returns the events that do not have the publish status.
731
+	 *
732
+	 * @param array   $query_params  An array of query params to further filter on
733
+	 *                               (note that status will be overwritten)
734
+	 * @param boolean $count         whether to return the count or not (default FALSE)
735
+	 * @return EE_Event[]|int
736
+	 * @throws EE_Error
737
+	 * @throws ReflectionException
738
+	 */
739
+	public function get_inactive_events($query_params, $count = false)
740
+	{
741
+		$where_params = isset($query_params[0])
742
+			? $query_params[0]
743
+			: [];
744
+		// let's add in specific query_params for inactive events.
745
+		if (isset($where_params['status'])) {
746
+			unset($where_params['status']);
747
+		}
748
+		// if we have count make sure we don't include group by
749
+		if ($count && isset($query_params['group_by'])) {
750
+			unset($query_params['group_by']);
751
+		}
752
+		// if we have any additional query_params, let's add them to the 'AND' condition
753
+		$where_params['AND']['status'] = ['!=', 'publish'];
754
+		if (isset($where_params['OR'])) {
755
+			$where_params['AND']['OR'] = $where_params['OR'];
756
+			unset($where_params['OR']);
757
+		}
758
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
759
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
760
+			unset($where_params['Datetime.DTT_EVT_end']);
761
+		}
762
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
763
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
764
+			unset($where_params['Datetime.DTT_EVT_start']);
765
+		}
766
+		return $this->_get_count_or_all($query_params, $where_params, $count);
767
+	}
768
+
769
+
770
+	/**
771
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
772
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
773
+	 * attached to the event. See parent for param descriptions
774
+	 *
775
+	 * @param        $id_or_obj
776
+	 * @param        $other_model_id_or_obj
777
+	 * @param string $relationName
778
+	 * @param array  $where_query
779
+	 * @return EE_Base_Class
780
+	 * @throws EE_Error
781
+	 * @throws ReflectionException
782
+	 */
783
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = [])
784
+	{
785
+		if ($relationName === 'Price') {
786
+			// let's get the PRC object for the given ID to make sure that we aren't dealing with a default
787
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
788
+			// if EVT_ID = 0, then this is a default
789
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
790
+				// let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
791
+				$prc_chk->set('PRC_ID', 0);
792
+			}
793
+			// run parent
794
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
795
+		}
796
+		// otherwise carry on as normal
797
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
798
+	}
799
+
800
+
801
+	/**
802
+	 * @param array $where_params
803
+	 * @return array
804
+	 */
805
+	public function set_where_conditions_for_status(array $where_params): array
806
+	{
807
+		// let's add specific query_params for active_events
808
+		// keep in mind this will override any sent status in the query AND any date queries.
809
+		// we need to pull events with a status of publish and sold_out
810
+		$event_status = ['publish', EEM_Event::sold_out];
811
+		// check if the user can read private events and if so add the 'private status to the where params'
812
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
813
+			$event_status[] = 'private';
814
+		}
815
+		$where_params['status'] = ['IN', $event_status];
816
+		return $where_params;
817
+	}
818
+
819
+
820
+	/**
821
+	 * @param array $where_params
822
+	 * @return array
823
+	 * @throws EE_Error
824
+	 * @throws ReflectionException
825
+	 */
826
+	public function set_where_conditions_for_end_datetime(array $where_params): array
827
+	{
828
+		$end_date_field_name = isset($where_params['Datetime.DTT_EVT_end'])
829
+			? 'Datetime.DTT_EVT_end*****'
830
+			// prevents overwrite of existing where condition
831
+			: 'Datetime.DTT_EVT_end';
832
+
833
+		$where_params[ $end_date_field_name ] = [
834
+			'>',
835
+			EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
836
+		];
837
+
838
+		return $where_params;
839
+	}
840
+
841
+
842
+	/**
843
+	 * @param array $query_params
844
+	 * @param array $where_params
845
+	 * @param bool  $count
846
+	 * @return EE_Soft_Delete_Base_Class[]|int
847
+	 * @throws EE_Error
848
+	 * @throws ReflectionException
849
+	 */
850
+	protected function _get_count_or_all(array $query_params, array $where_params, bool $count = false)
851
+	{
852
+		$query_params[0] = $where_params;
853
+		// don't use $query_params with count()
854
+		// because we don't want to include additional query clauses like "GROUP BY"
855
+		return $count
856
+			? $this->count([$where_params], 'EVT_ID', true)
857
+			: $this->get_all($query_params);
858
+	}
859
+
860
+
861
+	/******************** DEPRECATED METHODS ********************/
862
+
863
+
864
+	/**
865
+	 * _get_question_target_db_column
866
+	 *
867
+	 * @param EE_Registration $registration    (so existing answers for registration are included)
868
+	 * @param int             $EVT_ID          so all question groups are included for event (not just answers from
869
+	 *                                         registration).
870
+	 * @return    array
871
+	 * @throws ReflectionException
872
+	 * @throws EE_Error
873
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
874
+	 *                                         EE_Registration_Custom_Questions_Form located in
875
+	 *                                         admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
876
+	 * @access     public
877
+	 */
878
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
879
+	{
880
+		if (empty($EVT_ID)) {
881
+			throw new EE_Error(
882
+				esc_html__(
883
+					'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
884
+					'event_espresso'
885
+				)
886
+			);
887
+		}
888
+		$questions = [];
889
+		// get all question groups for event
890
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
891
+		if (! empty($qgs)) {
892
+			foreach ($qgs as $qg) {
893
+				$qsts                                    = $qg->questions();
894
+				$questions[ $qg->ID() ]                  = $qg->model_field_array();
895
+				$questions[ $qg->ID() ]['QSG_questions'] = [];
896
+				foreach ($qsts as $qst) {
897
+					if ($qst->is_system_question()) {
898
+						continue;
899
+					}
900
+					$answer                                                                   =
901
+						EEM_Answer::instance()->get_one(
902
+							[
903
+								[
904
+									'QST_ID' => $qst->ID(),
905
+									'REG_ID' => $registration->ID(),
906
+								],
907
+							]
908
+						);
909
+					$answer                                                                   =
910
+						$answer instanceof EE_Answer
911
+							? $answer
912
+							: EEM_Answer::instance()->create_default_object();
913
+					$qst_name                                                                 = $qstn_id = $qst->ID();
914
+					$ans_id                                                                   = $answer->ID();
915
+					$qst_name                                                                 = ! empty($ans_id)
916
+						? '[' . $qst_name . '][' . $ans_id . ']'
917
+						: '[' . $qst_name . ']';
918
+					$input_name                                                               = '';
919
+					$input_id                                                                 =
920
+						sanitize_key($qst->display_text());
921
+					$input_class                                                              = '';
922
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]                    =
923
+						$qst->model_field_array();
924
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name']  = 'qstn'
925
+																								. $input_name
926
+																								. $qst_name;
927
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id']    =
928
+						$input_id . '-' . $qstn_id;
929
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
930
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options']     = [];
931
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj']         = $qst;
932
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj']         = $answer;
933
+					// leave responses as-is, don't convert stuff into html entities please!
934
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
935
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
936
+						$QSOs = $qst->options(true, $answer->value());
937
+						if (is_array($QSOs)) {
938
+							foreach ($QSOs as $QSO_ID => $QSO) {
939
+								$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] =
940
+									$QSO->model_field_array();
941
+							}
942
+						}
943
+					}
944
+				}
945
+			}
946
+		}
947
+		return $questions;
948
+	}
949
+
950
+
951
+	/**
952
+	 * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
953
+	 *                             or an stdClass where each property is the name of a column,
954
+	 * @return EE_Base_Class
955
+	 * @throws EE_Error
956
+	 * @throws ReflectionException
957
+	 */
958
+	public function instantiate_class_from_array_or_object($cols_n_values)
959
+	{
960
+		$classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
961
+		if ($classInstance instanceof EE_Event) {
962
+			// events have their timezone defined in the DB, so use it immediately
963
+			$this->set_timezone($classInstance->get_timezone());
964
+		}
965
+		return $classInstance;
966
+	}
967 967
 }
Please login to merge, or discard this patch.
form_sections/strategies/layout/EE_Form_Section_Layout_Base.strategy.php 2 patches
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -11,175 +11,175 @@  discard block
 block discarded – undo
11 11
  */
12 12
 abstract class EE_Form_Section_Layout_Base
13 13
 {
14
-    /**
15
-     * Form section to lay out
16
-     *
17
-     * @var EE_Form_Section_Proper
18
-     */
19
-    protected $_form_section;
20
-
21
-
22
-
23
-    /**
24
-     *  __construct
25
-     */
26
-    public function __construct()
27
-    {
28
-    }
29
-
30
-
31
-
32
-    /**
33
-     * The form section on which this strategy is to perform
34
-     *
35
-     * @param EE_Form_Section_Proper $form
36
-     */
37
-    public function _construct_finalize(EE_Form_Section_Proper $form)
38
-    {
39
-        $this->_form_section = $form;
40
-    }
41
-
42
-
43
-
44
-    /**
45
-     * @return EE_Form_Section_Proper
46
-     */
47
-    public function form_section()
48
-    {
49
-        return $this->_form_section;
50
-    }
51
-
52
-
53
-
54
-    /**
55
-     * Also has teh side effect of enqueuing any needed JS and CSS for
56
-     * this form.
57
-     * Creates all the HTML necessary for displaying this form, its inputs, and
58
-     * proper subsections.
59
-     * Returns the HTML
60
-     *
61
-     * @return string HTML for displaying
62
-     * @throws EE_Error
63
-     */
64
-    public function layout_form()
65
-    {
66
-        $html = '';
67
-        // layout_form_begin
68
-        $html .= apply_filters(
69
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(),
70
-            $this->layout_form_begin(),
71
-            $this->_form_section
72
-        );
73
-        // layout_form_loop
74
-        $html .= apply_filters(
75
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(),
76
-            $this->layout_form_loop(),
77
-            $this->_form_section
78
-        );
79
-        // layout_form_end
80
-        $html .= apply_filters(
81
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(),
82
-            $this->layout_form_end(),
83
-            $this->_form_section
84
-        );
85
-        return $this->add_form_section_hooks_and_filters($html);
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * @return string
92
-     * @throws EE_Error
93
-     */
94
-    public function layout_form_loop()
95
-    {
96
-        $html = '';
97
-        foreach ($this->_form_section->subsections() as $name => $subsection) {
98
-            if ($subsection instanceof EE_Form_Input_Base) {
99
-                $html .= apply_filters(
100
-                    'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'
101
-                    . $name . '__in_' . $this->_form_section->name(),
102
-                    $this->layout_input($subsection),
103
-                    $this->_form_section,
104
-                    $subsection
105
-                );
106
-            } elseif ($subsection instanceof EE_Form_Section_Base) {
107
-                $html .= apply_filters(
108
-                    'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'
109
-                    . $name . '__in_' . $this->_form_section->name(),
110
-                    $this->layout_subsection($subsection),
111
-                    $this->_form_section,
112
-                    $subsection
113
-                );
114
-            }
115
-        }
116
-        return $html;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * Should be used to start teh form section (Eg a table tag, or a div tag, etc.)
123
-     *
124
-     * @return string
125
-     */
126
-    abstract public function layout_form_begin();
127
-
128
-
129
-
130
-    /**
131
-     * Should be used to end the form section (eg a /table tag, or a /div tag, etc.)
132
-     *
133
-     * @return string
134
-     */
135
-    abstract public function layout_form_end();
136
-
137
-
138
-
139
-    /**
140
-     * Should be used internally by layout_form() to lay out each input (eg, if this layout
141
-     * is putting each input in a row of its own, this should probably be called by a
142
-     *  foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop.
143
-     * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely
144
-     * customize the form's layout, but would like to make use of it for laying out
145
-     * 'easy-to-layout' inputs
146
-     *
147
-     * @param EE_Form_Input_Base $input
148
-     * @return string html
149
-     */
150
-    abstract public function layout_input($input);
151
-
152
-
153
-
154
-    /**
155
-     * Similar to layout_input(), should be used internally by layout_form() within a
156
-     * loop to lay out each proper subsection. Unlike layout_input(), however, it is assumed
157
-     * that the proper subsection will lay out its container, label, etc on its own.
158
-     *
159
-     * @param EE_Form_Section_Base $subsection
160
-     * @return string html
161
-     */
162
-    abstract public function layout_subsection($subsection);
163
-
164
-
165
-    /**
166
-     * Gets the HTML for the label tag and its contents for the input
167
-     *
168
-     * @param EE_Form_Input_Base $input
169
-     * @return string
170
-     * @throws EE_Error
171
-     */
172
-    public function display_label($input)
173
-    {
174
-        $label_text = $input->html_label_text();
175
-        if (! $label_text || $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
176
-            return '';
177
-        }
178
-        $class = $input->required()
179
-            ? 'ee-required-label ' . $input->html_label_class()
180
-            : $input->html_label_class();
181
-        $label_text .= $input->required() ? '<span class="ee-asterisk">*</span>' : '';
182
-        return '
14
+	/**
15
+	 * Form section to lay out
16
+	 *
17
+	 * @var EE_Form_Section_Proper
18
+	 */
19
+	protected $_form_section;
20
+
21
+
22
+
23
+	/**
24
+	 *  __construct
25
+	 */
26
+	public function __construct()
27
+	{
28
+	}
29
+
30
+
31
+
32
+	/**
33
+	 * The form section on which this strategy is to perform
34
+	 *
35
+	 * @param EE_Form_Section_Proper $form
36
+	 */
37
+	public function _construct_finalize(EE_Form_Section_Proper $form)
38
+	{
39
+		$this->_form_section = $form;
40
+	}
41
+
42
+
43
+
44
+	/**
45
+	 * @return EE_Form_Section_Proper
46
+	 */
47
+	public function form_section()
48
+	{
49
+		return $this->_form_section;
50
+	}
51
+
52
+
53
+
54
+	/**
55
+	 * Also has teh side effect of enqueuing any needed JS and CSS for
56
+	 * this form.
57
+	 * Creates all the HTML necessary for displaying this form, its inputs, and
58
+	 * proper subsections.
59
+	 * Returns the HTML
60
+	 *
61
+	 * @return string HTML for displaying
62
+	 * @throws EE_Error
63
+	 */
64
+	public function layout_form()
65
+	{
66
+		$html = '';
67
+		// layout_form_begin
68
+		$html .= apply_filters(
69
+			'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(),
70
+			$this->layout_form_begin(),
71
+			$this->_form_section
72
+		);
73
+		// layout_form_loop
74
+		$html .= apply_filters(
75
+			'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(),
76
+			$this->layout_form_loop(),
77
+			$this->_form_section
78
+		);
79
+		// layout_form_end
80
+		$html .= apply_filters(
81
+			'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(),
82
+			$this->layout_form_end(),
83
+			$this->_form_section
84
+		);
85
+		return $this->add_form_section_hooks_and_filters($html);
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * @return string
92
+	 * @throws EE_Error
93
+	 */
94
+	public function layout_form_loop()
95
+	{
96
+		$html = '';
97
+		foreach ($this->_form_section->subsections() as $name => $subsection) {
98
+			if ($subsection instanceof EE_Form_Input_Base) {
99
+				$html .= apply_filters(
100
+					'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'
101
+					. $name . '__in_' . $this->_form_section->name(),
102
+					$this->layout_input($subsection),
103
+					$this->_form_section,
104
+					$subsection
105
+				);
106
+			} elseif ($subsection instanceof EE_Form_Section_Base) {
107
+				$html .= apply_filters(
108
+					'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'
109
+					. $name . '__in_' . $this->_form_section->name(),
110
+					$this->layout_subsection($subsection),
111
+					$this->_form_section,
112
+					$subsection
113
+				);
114
+			}
115
+		}
116
+		return $html;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * Should be used to start teh form section (Eg a table tag, or a div tag, etc.)
123
+	 *
124
+	 * @return string
125
+	 */
126
+	abstract public function layout_form_begin();
127
+
128
+
129
+
130
+	/**
131
+	 * Should be used to end the form section (eg a /table tag, or a /div tag, etc.)
132
+	 *
133
+	 * @return string
134
+	 */
135
+	abstract public function layout_form_end();
136
+
137
+
138
+
139
+	/**
140
+	 * Should be used internally by layout_form() to lay out each input (eg, if this layout
141
+	 * is putting each input in a row of its own, this should probably be called by a
142
+	 *  foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop.
143
+	 * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely
144
+	 * customize the form's layout, but would like to make use of it for laying out
145
+	 * 'easy-to-layout' inputs
146
+	 *
147
+	 * @param EE_Form_Input_Base $input
148
+	 * @return string html
149
+	 */
150
+	abstract public function layout_input($input);
151
+
152
+
153
+
154
+	/**
155
+	 * Similar to layout_input(), should be used internally by layout_form() within a
156
+	 * loop to lay out each proper subsection. Unlike layout_input(), however, it is assumed
157
+	 * that the proper subsection will lay out its container, label, etc on its own.
158
+	 *
159
+	 * @param EE_Form_Section_Base $subsection
160
+	 * @return string html
161
+	 */
162
+	abstract public function layout_subsection($subsection);
163
+
164
+
165
+	/**
166
+	 * Gets the HTML for the label tag and its contents for the input
167
+	 *
168
+	 * @param EE_Form_Input_Base $input
169
+	 * @return string
170
+	 * @throws EE_Error
171
+	 */
172
+	public function display_label($input)
173
+	{
174
+		$label_text = $input->html_label_text();
175
+		if (! $label_text || $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
176
+			return '';
177
+		}
178
+		$class = $input->required()
179
+			? 'ee-required-label ' . $input->html_label_class()
180
+			: $input->html_label_class();
181
+		$label_text .= $input->required() ? '<span class="ee-asterisk">*</span>' : '';
182
+		return '
183 183
         <label id="' . $input->html_label_id() . '"
184 184
                class="' . $class . '"
185 185
                style="' . $input->html_label_style() . '"
@@ -187,102 +187,102 @@  discard block
 block discarded – undo
187 187
         >
188 188
             ' . $label_text . '
189 189
         </label>';
190
-    }
191
-
192
-
193
-
194
-    /**
195
-     * Gets the HTML for all the form's form-wide errors (ie, errors which
196
-     * are not for specific inputs. E.g., if two inputs somehow disagree,
197
-     * those errors would probably be on the form section, not one of its inputs)
198
-     * @return string
199
-     */
200
-    public function display_form_wide_errors()
201
-    {
202
-        $html = '';
203
-        if ($this->_form_section->get_validation_errors()) {
204
-            $html .= "<div class='ee-form-wide-errors'>";
205
-            // get all the errors on THIS form section (errors which aren't
206
-            // for specific inputs, but instead for the entire form section)
207
-            foreach ($this->_form_section->get_validation_errors() as $error) {
208
-                $html .= $error->getMessage() . '<br>';
209
-            }
210
-            $html .= '</div>';
211
-        }
212
-        return apply_filters(
213
-            'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors',
214
-            $html,
215
-            $this
216
-        );
217
-    }
218
-
219
-
220
-    /**
221
-     * returns the HTML for the server-side validation errors for the specified input
222
-     * Note that if JS is enabled, it should remove these and instead
223
-     * populate the form's errors in the jquery validate fashion
224
-     * using the localized data provided to the JS
225
-     *
226
-     * @param EE_Form_Input_Base $input
227
-     * @return string
228
-     * @throws EE_Error
229
-     */
230
-    public function display_errors($input)
231
-    {
232
-        if ($input->get_validation_errors()) {
233
-            return "<label  id='"
234
-                   . $input->html_id()
235
-                   . "-error' class='error' for='{$input->html_name()}'>"
236
-                   . $input->get_validation_error_string()
237
-                   . '</label>';
238
-        }
239
-        return '';
240
-    }
241
-
242
-
243
-    /**
244
-     * Displays the help span for the specified input
245
-     *
246
-     * @param EE_Form_Input_Base $input
247
-     * @return string
248
-     * @throws EE_Error
249
-     */
250
-    public function display_help_text($input)
251
-    {
252
-        $help_text = $input->html_help_text();
253
-        if (! $help_text) {
254
-            return '';
255
-        }
256
-        $tag = is_admin() ? 'p' : 'span';
257
-        return '
190
+	}
191
+
192
+
193
+
194
+	/**
195
+	 * Gets the HTML for all the form's form-wide errors (ie, errors which
196
+	 * are not for specific inputs. E.g., if two inputs somehow disagree,
197
+	 * those errors would probably be on the form section, not one of its inputs)
198
+	 * @return string
199
+	 */
200
+	public function display_form_wide_errors()
201
+	{
202
+		$html = '';
203
+		if ($this->_form_section->get_validation_errors()) {
204
+			$html .= "<div class='ee-form-wide-errors'>";
205
+			// get all the errors on THIS form section (errors which aren't
206
+			// for specific inputs, but instead for the entire form section)
207
+			foreach ($this->_form_section->get_validation_errors() as $error) {
208
+				$html .= $error->getMessage() . '<br>';
209
+			}
210
+			$html .= '</div>';
211
+		}
212
+		return apply_filters(
213
+			'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors',
214
+			$html,
215
+			$this
216
+		);
217
+	}
218
+
219
+
220
+	/**
221
+	 * returns the HTML for the server-side validation errors for the specified input
222
+	 * Note that if JS is enabled, it should remove these and instead
223
+	 * populate the form's errors in the jquery validate fashion
224
+	 * using the localized data provided to the JS
225
+	 *
226
+	 * @param EE_Form_Input_Base $input
227
+	 * @return string
228
+	 * @throws EE_Error
229
+	 */
230
+	public function display_errors($input)
231
+	{
232
+		if ($input->get_validation_errors()) {
233
+			return "<label  id='"
234
+				   . $input->html_id()
235
+				   . "-error' class='error' for='{$input->html_name()}'>"
236
+				   . $input->get_validation_error_string()
237
+				   . '</label>';
238
+		}
239
+		return '';
240
+	}
241
+
242
+
243
+	/**
244
+	 * Displays the help span for the specified input
245
+	 *
246
+	 * @param EE_Form_Input_Base $input
247
+	 * @return string
248
+	 * @throws EE_Error
249
+	 */
250
+	public function display_help_text($input)
251
+	{
252
+		$help_text = $input->html_help_text();
253
+		if (! $help_text) {
254
+			return '';
255
+		}
256
+		$tag = is_admin() ? 'p' : 'span';
257
+		return '
258 258
         <' . $tag . ' id="' . esc_attr($input->html_id()) . '-help"
259 259
               class="' . esc_attr($input->html_help_class()) . '"
260 260
               style="' . esc_attr($input->html_help_style()) . '"
261 261
         >
262 262
             ' . $help_text . '
263 263
         </' . $tag . '>';
264
-    }
265
-
266
-
267
-    /**
268
-     * Does an action and hook onto the end of teh form
269
-     *
270
-     * @param string $html
271
-     * @return string
272
-     * @throws EE_Error
273
-     */
274
-    public function add_form_section_hooks_and_filters($html)
275
-    {
276
-        // replace dashes and spaces with underscores
277
-        $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id());
278
-        do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section);
279
-        $html = (string) apply_filters(
280
-            'AFEE__Form_Section_Layout__' . $hook_name . '__html',
281
-            $html,
282
-            $this->_form_section
283
-        );
284
-        $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->';
285
-        $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->';
286
-        return $html;
287
-    }
264
+	}
265
+
266
+
267
+	/**
268
+	 * Does an action and hook onto the end of teh form
269
+	 *
270
+	 * @param string $html
271
+	 * @return string
272
+	 * @throws EE_Error
273
+	 */
274
+	public function add_form_section_hooks_and_filters($html)
275
+	{
276
+		// replace dashes and spaces with underscores
277
+		$hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id());
278
+		do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section);
279
+		$html = (string) apply_filters(
280
+			'AFEE__Form_Section_Layout__' . $hook_name . '__html',
281
+			$html,
282
+			$this->_form_section
283
+		);
284
+		$html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->';
285
+		$html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->';
286
+		return $html;
287
+	}
288 288
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -66,19 +66,19 @@  discard block
 block discarded – undo
66 66
         $html = '';
67 67
         // layout_form_begin
68 68
         $html .= apply_filters(
69
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(),
69
+            'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(),
70 70
             $this->layout_form_begin(),
71 71
             $this->_form_section
72 72
         );
73 73
         // layout_form_loop
74 74
         $html .= apply_filters(
75
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(),
75
+            'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(),
76 76
             $this->layout_form_loop(),
77 77
             $this->_form_section
78 78
         );
79 79
         // layout_form_end
80 80
         $html .= apply_filters(
81
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(),
81
+            'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(),
82 82
             $this->layout_form_end(),
83 83
             $this->_form_section
84 84
         );
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             if ($subsection instanceof EE_Form_Input_Base) {
99 99
                 $html .= apply_filters(
100 100
                     'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'
101
-                    . $name . '__in_' . $this->_form_section->name(),
101
+                    . $name.'__in_'.$this->_form_section->name(),
102 102
                     $this->layout_input($subsection),
103 103
                     $this->_form_section,
104 104
                     $subsection
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
             } elseif ($subsection instanceof EE_Form_Section_Base) {
107 107
                 $html .= apply_filters(
108 108
                     'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'
109
-                    . $name . '__in_' . $this->_form_section->name(),
109
+                    . $name.'__in_'.$this->_form_section->name(),
110 110
                     $this->layout_subsection($subsection),
111 111
                     $this->_form_section,
112 112
                     $subsection
@@ -172,20 +172,20 @@  discard block
 block discarded – undo
172 172
     public function display_label($input)
173 173
     {
174 174
         $label_text = $input->html_label_text();
175
-        if (! $label_text || $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
175
+        if ( ! $label_text || $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
176 176
             return '';
177 177
         }
178 178
         $class = $input->required()
179
-            ? 'ee-required-label ' . $input->html_label_class()
179
+            ? 'ee-required-label '.$input->html_label_class()
180 180
             : $input->html_label_class();
181 181
         $label_text .= $input->required() ? '<span class="ee-asterisk">*</span>' : '';
182 182
         return '
183
-        <label id="' . $input->html_label_id() . '"
184
-               class="' . $class . '"
185
-               style="' . $input->html_label_style() . '"
186
-               for="' . $input->html_id() . '"
183
+        <label id="' . $input->html_label_id().'"
184
+               class="' . $class.'"
185
+               style="' . $input->html_label_style().'"
186
+               for="' . $input->html_id().'"
187 187
         >
188
-            ' . $label_text . '
188
+            ' . $label_text.'
189 189
         </label>';
190 190
     }
191 191
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
             // get all the errors on THIS form section (errors which aren't
206 206
             // for specific inputs, but instead for the entire form section)
207 207
             foreach ($this->_form_section->get_validation_errors() as $error) {
208
-                $html .= $error->getMessage() . '<br>';
208
+                $html .= $error->getMessage().'<br>';
209 209
             }
210 210
             $html .= '</div>';
211 211
         }
@@ -250,17 +250,17 @@  discard block
 block discarded – undo
250 250
     public function display_help_text($input)
251 251
     {
252 252
         $help_text = $input->html_help_text();
253
-        if (! $help_text) {
253
+        if ( ! $help_text) {
254 254
             return '';
255 255
         }
256 256
         $tag = is_admin() ? 'p' : 'span';
257 257
         return '
258
-        <' . $tag . ' id="' . esc_attr($input->html_id()) . '-help"
259
-              class="' . esc_attr($input->html_help_class()) . '"
260
-              style="' . esc_attr($input->html_help_style()) . '"
258
+        <' . $tag.' id="'.esc_attr($input->html_id()).'-help"
259
+              class="' . esc_attr($input->html_help_class()).'"
260
+              style="' . esc_attr($input->html_help_style()).'"
261 261
         >
262
-            ' . $help_text . '
263
-        </' . $tag . '>';
262
+            ' . $help_text.'
263
+        </' . $tag.'>';
264 264
     }
265 265
 
266 266
 
@@ -275,14 +275,14 @@  discard block
 block discarded – undo
275 275
     {
276 276
         // replace dashes and spaces with underscores
277 277
         $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id());
278
-        do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section);
278
+        do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section);
279 279
         $html = (string) apply_filters(
280
-            'AFEE__Form_Section_Layout__' . $hook_name . '__html',
280
+            'AFEE__Form_Section_Layout__'.$hook_name.'__html',
281 281
             $html,
282 282
             $this->_form_section
283 283
         );
284
-        $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->';
285
-        $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->';
284
+        $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->';
285
+        $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->';
286 286
         return $html;
287 287
     }
288 288
 }
Please login to merge, or discard this patch.
form_sections/strategies/layout/EE_Admin_Two_Column_Layout.strategy.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -6,85 +6,85 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Admin_Two_Column_Layout extends EE_Two_Column_Layout
8 8
 {
9
-    /**
10
-     * @param EE_Form_Section_Proper $form
11
-     */
12
-    public function _construct_finalize(EE_Form_Section_Proper $form)
13
-    {
14
-        parent::_construct_finalize($form);
15
-        $this->_form_section->set_html_class('ee-admin-two-column-layout form-table');
16
-    }
9
+	/**
10
+	 * @param EE_Form_Section_Proper $form
11
+	 */
12
+	public function _construct_finalize(EE_Form_Section_Proper $form)
13
+	{
14
+		parent::_construct_finalize($form);
15
+		$this->_form_section->set_html_class('ee-admin-two-column-layout form-table');
16
+	}
17 17
 
18 18
 
19
-    /**
20
-     * Overriding the parent table layout to include <tbody> tags
21
-     *
22
-     * @param array $additional_args
23
-     * @return string
24
-     * @throws EE_Error
25
-     */
26
-    public function layout_form_begin($additional_args = array())
27
-    {
28
-        return parent::layout_form_begin($additional_args);
29
-    }
19
+	/**
20
+	 * Overriding the parent table layout to include <tbody> tags
21
+	 *
22
+	 * @param array $additional_args
23
+	 * @return string
24
+	 * @throws EE_Error
25
+	 */
26
+	public function layout_form_begin($additional_args = array())
27
+	{
28
+		return parent::layout_form_begin($additional_args);
29
+	}
30 30
 
31 31
 
32 32
 
33
-    /**
34
-     * Lays out the row for the input, including label and errors
35
-     *
36
-     * @param EE_Form_Input_Base $input
37
-     * @return string
38
-     * @throws EE_Error
39
-     */
40
-    public function layout_input($input)
41
-    {
42
-        if (
43
-            $input->get_display_strategy() instanceof EE_Select_Display_Strategy
44
-            || $input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy
45
-            || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy
46
-            || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy
47
-        ) {
48
-            $html_class = $input->html_class();
49
-            $html_class = strpos($html_class, 'ee-input-width') === false
50
-                ? "$html_class ee-input-width--big"
51
-                : $html_class;
52
-            $input->set_html_class($html_class);
53
-        }
54
-        if ($input instanceof EE_Text_Area_Input) {
55
-            $input->set_rows(4);
56
-            $input->set_cols(60);
57
-        }
58
-        $input_html = $input->get_html_for_input();
59
-        // maybe add errors and help text ?
60
-        $input_html .= $input->get_html_for_errors() !== ''
61
-            ? EEH_HTML::nl() . $input->get_html_for_errors()
62
-            : '';
63
-        $input_html .= $input->get_html_for_help() !== ''
64
-            ? EEH_HTML::nl() . $input->get_html_for_help()
65
-            : '';
66
-        $input_html .= $input->extraContainerHtml() !== ''
67
-            ? EEH_HTML::nl() . $input->extraContainerHtml()
68
-            : '';
69
-        // overriding parent to add wp admin specific things.
70
-        $html = '';
71
-        if ($input instanceof EE_Hidden_Input) {
72
-            $html .= EEH_HTML::no_row($input->get_html_for_input());
73
-            // $html .= $input->get_html_for_input();
74
-        } else {
75
-            $html .= EEH_HTML::tr(
76
-                EEH_HTML::th(
77
-                    $input->get_html_for_label(),
78
-                    '',
79
-                    '',
80
-                    '',
81
-                    'scope="row"'
82
-                )
83
-                . EEH_HTML::td($input_html),
84
-                sanitize_key($input->html_id()) . '-tr',
85
-                $input->layoutContainerClass()
86
-            );
87
-        }
88
-        return $html;
89
-    }
33
+	/**
34
+	 * Lays out the row for the input, including label and errors
35
+	 *
36
+	 * @param EE_Form_Input_Base $input
37
+	 * @return string
38
+	 * @throws EE_Error
39
+	 */
40
+	public function layout_input($input)
41
+	{
42
+		if (
43
+			$input->get_display_strategy() instanceof EE_Select_Display_Strategy
44
+			|| $input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy
45
+			|| $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy
46
+			|| $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy
47
+		) {
48
+			$html_class = $input->html_class();
49
+			$html_class = strpos($html_class, 'ee-input-width') === false
50
+				? "$html_class ee-input-width--big"
51
+				: $html_class;
52
+			$input->set_html_class($html_class);
53
+		}
54
+		if ($input instanceof EE_Text_Area_Input) {
55
+			$input->set_rows(4);
56
+			$input->set_cols(60);
57
+		}
58
+		$input_html = $input->get_html_for_input();
59
+		// maybe add errors and help text ?
60
+		$input_html .= $input->get_html_for_errors() !== ''
61
+			? EEH_HTML::nl() . $input->get_html_for_errors()
62
+			: '';
63
+		$input_html .= $input->get_html_for_help() !== ''
64
+			? EEH_HTML::nl() . $input->get_html_for_help()
65
+			: '';
66
+		$input_html .= $input->extraContainerHtml() !== ''
67
+			? EEH_HTML::nl() . $input->extraContainerHtml()
68
+			: '';
69
+		// overriding parent to add wp admin specific things.
70
+		$html = '';
71
+		if ($input instanceof EE_Hidden_Input) {
72
+			$html .= EEH_HTML::no_row($input->get_html_for_input());
73
+			// $html .= $input->get_html_for_input();
74
+		} else {
75
+			$html .= EEH_HTML::tr(
76
+				EEH_HTML::th(
77
+					$input->get_html_for_label(),
78
+					'',
79
+					'',
80
+					'',
81
+					'scope="row"'
82
+				)
83
+				. EEH_HTML::td($input_html),
84
+				sanitize_key($input->html_id()) . '-tr',
85
+				$input->layoutContainerClass()
86
+			);
87
+		}
88
+		return $html;
89
+	}
90 90
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
         $input_html = $input->get_html_for_input();
59 59
         // maybe add errors and help text ?
60 60
         $input_html .= $input->get_html_for_errors() !== ''
61
-            ? EEH_HTML::nl() . $input->get_html_for_errors()
61
+            ? EEH_HTML::nl().$input->get_html_for_errors()
62 62
             : '';
63 63
         $input_html .= $input->get_html_for_help() !== ''
64
-            ? EEH_HTML::nl() . $input->get_html_for_help()
64
+            ? EEH_HTML::nl().$input->get_html_for_help()
65 65
             : '';
66 66
         $input_html .= $input->extraContainerHtml() !== ''
67
-            ? EEH_HTML::nl() . $input->extraContainerHtml()
67
+            ? EEH_HTML::nl().$input->extraContainerHtml()
68 68
             : '';
69 69
         // overriding parent to add wp admin specific things.
70 70
         $html = '';
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
                     'scope="row"'
82 82
                 )
83 83
                 . EEH_HTML::td($input_html),
84
-                sanitize_key($input->html_id()) . '-tr',
84
+                sanitize_key($input->html_id()).'-tr',
85 85
                 $input->layoutContainerClass()
86 86
             );
87 87
         }
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Display_Strategy_Base.strategy.php 1 patch
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -10,242 +10,242 @@
 block discarded – undo
10 10
  */
11 11
 abstract class EE_Display_Strategy_Base extends EE_Form_Input_Strategy_Base
12 12
 {
13
-    /**
14
-     * @var string $_tag
15
-     */
16
-    protected string $_tag = '';
17
-
18
-
19
-    /**
20
-     * returns HTML and javascript related to the displaying of this input
21
-     *
22
-     * @return string
23
-     */
24
-    abstract public function display(): string;
25
-
26
-
27
-    /**
28
-     * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars
29
-     * is already there
30
-     *
31
-     * @param string $string - the string being processed
32
-     * @param string $chars  - exact string of characters to remove
33
-     * @return string
34
-     */
35
-    protected function _remove_chars(string $string = '', string $chars = '-'): string
36
-    {
37
-        $char_length = strlen($chars) * -1;
38
-        // if last three characters of string is  " - ", then remove it
39
-        return substr($string, $char_length) === $chars
40
-            ? substr($string, 0, $char_length)
41
-            : $string;
42
-    }
43
-
44
-
45
-    /**
46
-     * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not
47
-     * already there
48
-     *
49
-     * @param string $string - the string being processed
50
-     * @param string $chars  - exact string of characters to be added to end of string
51
-     * @return string
52
-     */
53
-    protected function _append_chars(string $string = '', string $chars = '-'): string
54
-    {
55
-        return $this->_remove_chars($string, $chars) . $chars;
56
-    }
57
-
58
-
59
-    /**
60
-     * Gets the HTML IDs of all the inputs
61
-     *
62
-     * @param bool $add_pound_sign
63
-     * @return array
64
-     * @throws EE_Error
65
-     */
66
-    public function get_html_input_ids(bool $add_pound_sign = false): array
67
-    {
68
-        return [$this->get_input()->html_id($add_pound_sign)];
69
-    }
70
-
71
-
72
-    /**
73
-     * Adds js variables for localization to the $other_js_data. These should be put
74
-     * in each form's "other_data" javascript object.
75
-     *
76
-     * @param array $other_js_data
77
-     * @return array
78
-     */
79
-    public function get_other_js_data(array $other_js_data = []): array
80
-    {
81
-        return $other_js_data;
82
-    }
83
-
84
-
85
-    /**
86
-     * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style.
87
-     * This should be called during wp_enqueue_scripts
88
-     */
89
-    public function enqueue_js()
90
-    {
91
-    }
92
-
93
-
94
-    /**
95
-     * returns string like: '<tag'
96
-     *
97
-     * @param string $tag
98
-     * @return string
99
-     */
100
-    protected function _opening_tag(string $tag): string
101
-    {
102
-        $this->_tag = $tag;
103
-        return "<$this->_tag";
104
-    }
105
-
106
-
107
-    /**
108
-     * returns string like: '</tag>
109
-     *
110
-     * @return string
111
-     */
112
-    protected function _closing_tag(): string
113
-    {
114
-        return "</$this->_tag>";
115
-    }
116
-
117
-
118
-    /**
119
-     * returns string like: '/>'
120
-     *
121
-     * @return string
122
-     */
123
-    protected function _close_tag(): string
124
-    {
125
-        return '/>';
126
-    }
127
-
128
-
129
-    /**
130
-     * returns an array of standard HTML attributes that get added to nearly all inputs,
131
-     * where string keys represent named attributes like id, class, etc
132
-     * and numeric keys represent single attributes like 'required'.
133
-     * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use
134
-     * it.
135
-     *
136
-     * @return array
137
-     * @throws EE_Error
138
-     */
139
-    protected function _standard_attributes_array(): array
140
-    {
141
-        return [
142
-            'name'  => $this->_input->html_name(),
143
-            'id'    => $this->_input->html_id(),
144
-            'class' => $this->_input->html_class(true),
145
-            0       => ['required', $this->_input->required()],
146
-            1       => $this->_input->other_html_attributes(),
147
-            'style' => $this->_input->html_style(),
148
-        ];
149
-    }
150
-
151
-
152
-    /**
153
-     * sets the attributes using the incoming array
154
-     * and returns a string of all attributes rendered as valid HTML
155
-     *
156
-     * @param array $attributes
157
-     * @return string
158
-     */
159
-    protected function _attributes_string(array $attributes = []): string
160
-    {
161
-        $attributes        = apply_filters(
162
-            'FHEE__EE_Display_Strategy_Base__attributes_string__attributes',
163
-            $attributes,
164
-            $this,
165
-            $this->_input
166
-        );
167
-        $attributes_string = '';
168
-        foreach ($attributes as $attribute => $value) {
169
-            if ($attribute !== 'value' && empty($value)) {
170
-                continue;
171
-            }
172
-            if (is_numeric($attribute)) {
173
-                $add = true;
174
-                if (is_array($value)) {
175
-                    $attribute = $value[0] ?? '';
176
-                    $add       = $value[1] ?? false;
177
-                } else {
178
-                    $attribute = $value;
179
-                }
180
-                $attributes_string .= $this->_single_attribute($attribute, $add);
181
-            } else {
182
-                $attributes_string .= $this->_attribute($attribute, $value);
183
-            }
184
-        }
185
-        return $attributes_string;
186
-    }
187
-
188
-
189
-    /**
190
-     * returns string like: ' attribute="value"'
191
-     * returns an empty string if $value is null
192
-     *
193
-     * @param string $attribute
194
-     * @param string $value
195
-     * @return string
196
-     */
197
-    protected function _attribute(string $attribute, string $value = ''): string
198
-    {
199
-        if ($value === null) {
200
-            return '';
201
-        }
202
-        $value = esc_attr($value);
203
-        return " $attribute=\"$value\"";
204
-    }
205
-
206
-
207
-    /**
208
-     * returns string like: ' data-attribute-one="value-one" data-attribute-two="value-two"'
209
-     *
210
-     * @param array $data
211
-     * @return string
212
-     */
213
-    protected function dataAttributesString(array $data): string
214
-    {
215
-        $data_attributes = '';
216
-        foreach ($data as $attribute => $value) {
217
-            $data_attributes .= $this->_data_attribute($attribute, $value);
218
-        }
219
-        return $data_attributes;
220
-    }
221
-
222
-
223
-    /**
224
-     * returns string like: ' data-attribute="value"'
225
-     * returns an empty string if $value is null
226
-     *
227
-     * @param string $attribute
228
-     * @param string $value
229
-     * @return string
230
-     */
231
-    protected function _data_attribute(string $attribute, string $value = ''): string
232
-    {
233
-        $attribute = strpos($attribute, 'data-') !== 0 ? "data-$attribute" : $attribute;
234
-        return $this->_attribute($attribute, $value);
235
-    }
236
-
237
-
238
-    /**
239
-     * returns string like: ' attribute' if $add is true
240
-     *
241
-     * @param string  $attribute
242
-     * @param boolean $add
243
-     * @return string
244
-     */
245
-    protected function _single_attribute(string $attribute, bool $add = true): string
246
-    {
247
-        return $add
248
-            ? " $attribute"
249
-            : '';
250
-    }
13
+	/**
14
+	 * @var string $_tag
15
+	 */
16
+	protected string $_tag = '';
17
+
18
+
19
+	/**
20
+	 * returns HTML and javascript related to the displaying of this input
21
+	 *
22
+	 * @return string
23
+	 */
24
+	abstract public function display(): string;
25
+
26
+
27
+	/**
28
+	 * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars
29
+	 * is already there
30
+	 *
31
+	 * @param string $string - the string being processed
32
+	 * @param string $chars  - exact string of characters to remove
33
+	 * @return string
34
+	 */
35
+	protected function _remove_chars(string $string = '', string $chars = '-'): string
36
+	{
37
+		$char_length = strlen($chars) * -1;
38
+		// if last three characters of string is  " - ", then remove it
39
+		return substr($string, $char_length) === $chars
40
+			? substr($string, 0, $char_length)
41
+			: $string;
42
+	}
43
+
44
+
45
+	/**
46
+	 * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not
47
+	 * already there
48
+	 *
49
+	 * @param string $string - the string being processed
50
+	 * @param string $chars  - exact string of characters to be added to end of string
51
+	 * @return string
52
+	 */
53
+	protected function _append_chars(string $string = '', string $chars = '-'): string
54
+	{
55
+		return $this->_remove_chars($string, $chars) . $chars;
56
+	}
57
+
58
+
59
+	/**
60
+	 * Gets the HTML IDs of all the inputs
61
+	 *
62
+	 * @param bool $add_pound_sign
63
+	 * @return array
64
+	 * @throws EE_Error
65
+	 */
66
+	public function get_html_input_ids(bool $add_pound_sign = false): array
67
+	{
68
+		return [$this->get_input()->html_id($add_pound_sign)];
69
+	}
70
+
71
+
72
+	/**
73
+	 * Adds js variables for localization to the $other_js_data. These should be put
74
+	 * in each form's "other_data" javascript object.
75
+	 *
76
+	 * @param array $other_js_data
77
+	 * @return array
78
+	 */
79
+	public function get_other_js_data(array $other_js_data = []): array
80
+	{
81
+		return $other_js_data;
82
+	}
83
+
84
+
85
+	/**
86
+	 * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style.
87
+	 * This should be called during wp_enqueue_scripts
88
+	 */
89
+	public function enqueue_js()
90
+	{
91
+	}
92
+
93
+
94
+	/**
95
+	 * returns string like: '<tag'
96
+	 *
97
+	 * @param string $tag
98
+	 * @return string
99
+	 */
100
+	protected function _opening_tag(string $tag): string
101
+	{
102
+		$this->_tag = $tag;
103
+		return "<$this->_tag";
104
+	}
105
+
106
+
107
+	/**
108
+	 * returns string like: '</tag>
109
+	 *
110
+	 * @return string
111
+	 */
112
+	protected function _closing_tag(): string
113
+	{
114
+		return "</$this->_tag>";
115
+	}
116
+
117
+
118
+	/**
119
+	 * returns string like: '/>'
120
+	 *
121
+	 * @return string
122
+	 */
123
+	protected function _close_tag(): string
124
+	{
125
+		return '/>';
126
+	}
127
+
128
+
129
+	/**
130
+	 * returns an array of standard HTML attributes that get added to nearly all inputs,
131
+	 * where string keys represent named attributes like id, class, etc
132
+	 * and numeric keys represent single attributes like 'required'.
133
+	 * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use
134
+	 * it.
135
+	 *
136
+	 * @return array
137
+	 * @throws EE_Error
138
+	 */
139
+	protected function _standard_attributes_array(): array
140
+	{
141
+		return [
142
+			'name'  => $this->_input->html_name(),
143
+			'id'    => $this->_input->html_id(),
144
+			'class' => $this->_input->html_class(true),
145
+			0       => ['required', $this->_input->required()],
146
+			1       => $this->_input->other_html_attributes(),
147
+			'style' => $this->_input->html_style(),
148
+		];
149
+	}
150
+
151
+
152
+	/**
153
+	 * sets the attributes using the incoming array
154
+	 * and returns a string of all attributes rendered as valid HTML
155
+	 *
156
+	 * @param array $attributes
157
+	 * @return string
158
+	 */
159
+	protected function _attributes_string(array $attributes = []): string
160
+	{
161
+		$attributes        = apply_filters(
162
+			'FHEE__EE_Display_Strategy_Base__attributes_string__attributes',
163
+			$attributes,
164
+			$this,
165
+			$this->_input
166
+		);
167
+		$attributes_string = '';
168
+		foreach ($attributes as $attribute => $value) {
169
+			if ($attribute !== 'value' && empty($value)) {
170
+				continue;
171
+			}
172
+			if (is_numeric($attribute)) {
173
+				$add = true;
174
+				if (is_array($value)) {
175
+					$attribute = $value[0] ?? '';
176
+					$add       = $value[1] ?? false;
177
+				} else {
178
+					$attribute = $value;
179
+				}
180
+				$attributes_string .= $this->_single_attribute($attribute, $add);
181
+			} else {
182
+				$attributes_string .= $this->_attribute($attribute, $value);
183
+			}
184
+		}
185
+		return $attributes_string;
186
+	}
187
+
188
+
189
+	/**
190
+	 * returns string like: ' attribute="value"'
191
+	 * returns an empty string if $value is null
192
+	 *
193
+	 * @param string $attribute
194
+	 * @param string $value
195
+	 * @return string
196
+	 */
197
+	protected function _attribute(string $attribute, string $value = ''): string
198
+	{
199
+		if ($value === null) {
200
+			return '';
201
+		}
202
+		$value = esc_attr($value);
203
+		return " $attribute=\"$value\"";
204
+	}
205
+
206
+
207
+	/**
208
+	 * returns string like: ' data-attribute-one="value-one" data-attribute-two="value-two"'
209
+	 *
210
+	 * @param array $data
211
+	 * @return string
212
+	 */
213
+	protected function dataAttributesString(array $data): string
214
+	{
215
+		$data_attributes = '';
216
+		foreach ($data as $attribute => $value) {
217
+			$data_attributes .= $this->_data_attribute($attribute, $value);
218
+		}
219
+		return $data_attributes;
220
+	}
221
+
222
+
223
+	/**
224
+	 * returns string like: ' data-attribute="value"'
225
+	 * returns an empty string if $value is null
226
+	 *
227
+	 * @param string $attribute
228
+	 * @param string $value
229
+	 * @return string
230
+	 */
231
+	protected function _data_attribute(string $attribute, string $value = ''): string
232
+	{
233
+		$attribute = strpos($attribute, 'data-') !== 0 ? "data-$attribute" : $attribute;
234
+		return $this->_attribute($attribute, $value);
235
+	}
236
+
237
+
238
+	/**
239
+	 * returns string like: ' attribute' if $add is true
240
+	 *
241
+	 * @param string  $attribute
242
+	 * @param boolean $add
243
+	 * @return string
244
+	 */
245
+	protected function _single_attribute(string $attribute, bool $add = true): string
246
+	{
247
+		return $add
248
+			? " $attribute"
249
+			: '';
250
+	}
251 251
 }
Please login to merge, or discard this patch.
strategies/display/EE_Text_Input_Display_Strategy.strategy.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -14,61 +14,61 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Text_Input_Display_Strategy extends EE_Display_Strategy_Base
16 16
 {
17
-    /**
18
-     * The html "type" attribute value. default is "text"
19
-     *
20
-     * @var string
21
-     */
22
-    protected string $_type;
17
+	/**
18
+	 * The html "type" attribute value. default is "text"
19
+	 *
20
+	 * @var string
21
+	 */
22
+	protected string $_type;
23 23
 
24 24
 
25
-    /**
26
-     * @param string $type
27
-     */
28
-    public function __construct(string $type = 'text')
29
-    {
30
-        $this->_type = $type;
31
-        parent::__construct();
32
-    }
25
+	/**
26
+	 * @param string $type
27
+	 */
28
+	public function __construct(string $type = 'text')
29
+	{
30
+		$this->_type = $type;
31
+		parent::__construct();
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * Gets the html "type" attribute's value
37
-     *
38
-     * @return string
39
-     */
40
-    public function get_type(): string
41
-    {
42
-        if (
43
-            $this->_type === 'email'
44
-            && ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', true)
45
-        ) {
46
-            return 'text';
47
-        }
48
-        return $this->_type;
49
-    }
35
+	/**
36
+	 * Gets the html "type" attribute's value
37
+	 *
38
+	 * @return string
39
+	 */
40
+	public function get_type(): string
41
+	{
42
+		if (
43
+			$this->_type === 'email'
44
+			&& ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', true)
45
+		) {
46
+			return 'text';
47
+		}
48
+		return $this->_type;
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * @return string of html to display the field
54
-     * @throws EE_Error
55
-     */
56
-    public function display(): string
57
-    {
58
-        $input = '<input type="' . $this->get_type() . '"';
59
-        $input .= ' name="' . $this->_input->html_name() . '"';
60
-        $input .= ' id="' . $this->_input->html_id() . '"';
61
-        $class = $this->_input->required()
62
-            ? $this->_input->required_css_class() . ' ' . $this->_input->html_class()
63
-            : $this->_input->html_class();
64
-        $input .= ' class="' . $class . '"';
65
-        // add html5 required
66
-        $input .= $this->_input->required() ? ' required' : '';
67
-        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
68
-        $input .= ' style="' . $this->_input->html_style() . '"';
69
-        $input .= $this->_input->other_html_attributes();
70
-        $input .= $this->dataAttributesString($this->_input->dataAttributes());
71
-        $input .= '/>';
72
-        return $input;
73
-    }
52
+	/**
53
+	 * @return string of html to display the field
54
+	 * @throws EE_Error
55
+	 */
56
+	public function display(): string
57
+	{
58
+		$input = '<input type="' . $this->get_type() . '"';
59
+		$input .= ' name="' . $this->_input->html_name() . '"';
60
+		$input .= ' id="' . $this->_input->html_id() . '"';
61
+		$class = $this->_input->required()
62
+			? $this->_input->required_css_class() . ' ' . $this->_input->html_class()
63
+			: $this->_input->html_class();
64
+		$input .= ' class="' . $class . '"';
65
+		// add html5 required
66
+		$input .= $this->_input->required() ? ' required' : '';
67
+		$input .= ' value="' . $this->_input->raw_value_in_form() . '"';
68
+		$input .= ' style="' . $this->_input->html_style() . '"';
69
+		$input .= $this->_input->other_html_attributes();
70
+		$input .= $this->dataAttributesString($this->_input->dataAttributes());
71
+		$input .= '/>';
72
+		return $input;
73
+	}
74 74
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -55,17 +55,17 @@
 block discarded – undo
55 55
      */
56 56
     public function display(): string
57 57
     {
58
-        $input = '<input type="' . $this->get_type() . '"';
59
-        $input .= ' name="' . $this->_input->html_name() . '"';
60
-        $input .= ' id="' . $this->_input->html_id() . '"';
58
+        $input = '<input type="'.$this->get_type().'"';
59
+        $input .= ' name="'.$this->_input->html_name().'"';
60
+        $input .= ' id="'.$this->_input->html_id().'"';
61 61
         $class = $this->_input->required()
62
-            ? $this->_input->required_css_class() . ' ' . $this->_input->html_class()
62
+            ? $this->_input->required_css_class().' '.$this->_input->html_class()
63 63
             : $this->_input->html_class();
64
-        $input .= ' class="' . $class . '"';
64
+        $input .= ' class="'.$class.'"';
65 65
         // add html5 required
66 66
         $input .= $this->_input->required() ? ' required' : '';
67
-        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
68
-        $input .= ' style="' . $this->_input->html_style() . '"';
67
+        $input .= ' value="'.$this->_input->raw_value_in_form().'"';
68
+        $input .= ' style="'.$this->_input->html_style().'"';
69 69
         $input .= $this->_input->other_html_attributes();
70 70
         $input .= $this->dataAttributesString($this->_input->dataAttributes());
71 71
         $input .= '/>';
Please login to merge, or discard this patch.
strategies/display/EE_Select_Multiple_Display_Strategy.strategy.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -9,67 +9,67 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Select_Multiple_Display_Strategy extends EE_Select_Display_Strategy
11 11
 {
12
-    /**
13
-     * @return string of html to display the field
14
-     * @throws EE_Error
15
-     */
16
-    public function display(): string
17
-    {
18
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
19
-            throw new EE_Error(
20
-                esc_html__(
21
-                    'Cannot use Select Multiple Display Strategy with an input that doesn\'t have options',
22
-                    "event_espresso"
23
-                )
24
-            );
25
-        }
12
+	/**
13
+	 * @return string of html to display the field
14
+	 * @throws EE_Error
15
+	 */
16
+	public function display(): string
17
+	{
18
+		if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
19
+			throw new EE_Error(
20
+				esc_html__(
21
+					'Cannot use Select Multiple Display Strategy with an input that doesn\'t have options',
22
+					"event_espresso"
23
+				)
24
+			);
25
+		}
26 26
 
27
-        $html = EEH_HTML::nl(0, 'select');
28
-        $html .= '<select multiple';
29
-        $html .= ' id="' . $this->_input->html_id() . '"';
30
-        $html .= ' name="' . $this->_input->html_name() . '[]"';
31
-        $class = $this->_input->required()
32
-            ? $this->_input->required_css_class() . ' ' . $this->_input->html_class()
33
-            : $this->_input->html_class();
34
-        $html .= ' class="' . $class . '"';
35
-        // add html5 required
36
-        $html .= $this->_input->required()
37
-            ? ' required'
38
-            : '';
39
-        $html .= ' style="' . $this->_input->html_style() . '"';
40
-        $html .= $this->_input->other_html_attributes();
41
-        $html .= $this->dataAttributesString($this->_input->dataAttributes());
42
-        $html .= '>';
27
+		$html = EEH_HTML::nl(0, 'select');
28
+		$html .= '<select multiple';
29
+		$html .= ' id="' . $this->_input->html_id() . '"';
30
+		$html .= ' name="' . $this->_input->html_name() . '[]"';
31
+		$class = $this->_input->required()
32
+			? $this->_input->required_css_class() . ' ' . $this->_input->html_class()
33
+			: $this->_input->html_class();
34
+		$html .= ' class="' . $class . '"';
35
+		// add html5 required
36
+		$html .= $this->_input->required()
37
+			? ' required'
38
+			: '';
39
+		$html .= ' style="' . $this->_input->html_style() . '"';
40
+		$html .= $this->_input->other_html_attributes();
41
+		$html .= $this->dataAttributesString($this->_input->dataAttributes());
42
+		$html .= '>';
43 43
 
44
-        EEH_HTML::indent(1, 'select');
45
-        if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
46
-            throw new EE_Error(
47
-                esc_html__(
48
-                    "Select multiple display strategy does not allow for nested arrays of options.",
49
-                    "event_espresso"
50
-                )
51
-            );
52
-        } else {
53
-            $html .= $this->_display_options($this->_input->options());
54
-        }
44
+		EEH_HTML::indent(1, 'select');
45
+		if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
46
+			throw new EE_Error(
47
+				esc_html__(
48
+					"Select multiple display strategy does not allow for nested arrays of options.",
49
+					"event_espresso"
50
+				)
51
+			);
52
+		} else {
53
+			$html .= $this->_display_options($this->_input->options());
54
+		}
55 55
 
56
-        $html .= EEH_HTML::nl(-1, 'select') . "</select>";
57
-        return $html;
58
-    }
56
+		$html .= EEH_HTML::nl(-1, 'select') . "</select>";
57
+		return $html;
58
+	}
59 59
 
60 60
 
61
-    /**
62
-     * Checks if that $value is one of the selected ones
63
-     *
64
-     * @param string|int $value unnormalized value option (string)
65
-     * @return bool
66
-     */
67
-    protected function _check_if_option_selected($value): bool
68
-    {
69
-        $selected_options = $this->_input->raw_value();
70
-        if (empty($selected_options)) {
71
-            return false;
72
-        }
73
-        return in_array($value, $selected_options);
74
-    }
61
+	/**
62
+	 * Checks if that $value is one of the selected ones
63
+	 *
64
+	 * @param string|int $value unnormalized value option (string)
65
+	 * @return bool
66
+	 */
67
+	protected function _check_if_option_selected($value): bool
68
+	{
69
+		$selected_options = $this->_input->raw_value();
70
+		if (empty($selected_options)) {
71
+			return false;
72
+		}
73
+		return in_array($value, $selected_options);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
      */
16 16
     public function display(): string
17 17
     {
18
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
18
+        if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
19 19
             throw new EE_Error(
20 20
                 esc_html__(
21 21
                     'Cannot use Select Multiple Display Strategy with an input that doesn\'t have options',
@@ -26,17 +26,17 @@  discard block
 block discarded – undo
26 26
 
27 27
         $html = EEH_HTML::nl(0, 'select');
28 28
         $html .= '<select multiple';
29
-        $html .= ' id="' . $this->_input->html_id() . '"';
30
-        $html .= ' name="' . $this->_input->html_name() . '[]"';
29
+        $html .= ' id="'.$this->_input->html_id().'"';
30
+        $html .= ' name="'.$this->_input->html_name().'[]"';
31 31
         $class = $this->_input->required()
32
-            ? $this->_input->required_css_class() . ' ' . $this->_input->html_class()
32
+            ? $this->_input->required_css_class().' '.$this->_input->html_class()
33 33
             : $this->_input->html_class();
34
-        $html .= ' class="' . $class . '"';
34
+        $html .= ' class="'.$class.'"';
35 35
         // add html5 required
36 36
         $html .= $this->_input->required()
37 37
             ? ' required'
38 38
             : '';
39
-        $html .= ' style="' . $this->_input->html_style() . '"';
39
+        $html .= ' style="'.$this->_input->html_style().'"';
40 40
         $html .= $this->_input->other_html_attributes();
41 41
         $html .= $this->dataAttributesString($this->_input->dataAttributes());
42 42
         $html .= '>';
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
             $html .= $this->_display_options($this->_input->options());
54 54
         }
55 55
 
56
-        $html .= EEH_HTML::nl(-1, 'select') . "</select>";
56
+        $html .= EEH_HTML::nl(-1, 'select')."</select>";
57 57
         return $html;
58 58
     }
59 59
 
Please login to merge, or discard this patch.
strategies/display/EE_Submit_Input_Display_Strategy.strategy.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,31 +9,31 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Submit_Input_Display_Strategy extends EE_Display_Strategy_Base
11 11
 {
12
-    /**
13
-     * @return string of html to display the input
14
-     * @throws EE_Error
15
-     */
16
-    public function display(): string
17
-    {
18
-        $default_value = $this->_input->get_default();
19
-        if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) {
20
-            $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value);
21
-        }
22
-        $html = $this->_opening_tag('input');
23
-        $html .= $this->_attributes_string(
24
-            array_merge(
25
-                $this->_standard_attributes_array(),
26
-                [
27
-                    'type'  => 'submit',
28
-                    'value' => $default_value,
29
-                    // overwrite the standard id with the backwards compatible one
30
-                    'id'    => $this->_input->html_id() . '-submit',
31
-                    'class' => $this->_input->html_class() . ' ' . $this->_input->button_css_attributes(),
32
-                ]
33
-            )
34
-        );
35
-        $html .= $this->dataAttributesString($this->_input->dataAttributes());
36
-        $html .= $this->_close_tag();
37
-        return $html;
38
-    }
12
+	/**
13
+	 * @return string of html to display the input
14
+	 * @throws EE_Error
15
+	 */
16
+	public function display(): string
17
+	{
18
+		$default_value = $this->_input->get_default();
19
+		if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) {
20
+			$default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value);
21
+		}
22
+		$html = $this->_opening_tag('input');
23
+		$html .= $this->_attributes_string(
24
+			array_merge(
25
+				$this->_standard_attributes_array(),
26
+				[
27
+					'type'  => 'submit',
28
+					'value' => $default_value,
29
+					// overwrite the standard id with the backwards compatible one
30
+					'id'    => $this->_input->html_id() . '-submit',
31
+					'class' => $this->_input->html_class() . ' ' . $this->_input->button_css_attributes(),
32
+				]
33
+			)
34
+		);
35
+		$html .= $this->dataAttributesString($this->_input->dataAttributes());
36
+		$html .= $this->_close_tag();
37
+		return $html;
38
+	}
39 39
 }
Please login to merge, or discard this patch.