Completed
Branch master (4bd299)
by
unknown
04:49
created
core/db_models/EEM_Datetime.model.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                 ),
122 122
             ],
123 123
         ];
124
-        $this->_model_relations        = [
124
+        $this->_model_relations = [
125 125
             'Ticket'          => new EE_HABTM_Relation('Datetime_Ticket'),
126 126
             'Event'           => new EE_Belongs_To_Relation(),
127 127
             'Checkin'         => new EE_Has_Many_Relation(),
@@ -131,19 +131,19 @@  discard block
 block discarded – undo
131 131
         $this->model_chain_to_password = $path_to_event_model;
132 132
         $this->_model_chain_to_wp_user = $path_to_event_model;
133 133
         // this model is generally available for reading
134
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
134
+        $this->_cap_restriction_generators[EEM_Base::caps_read] =
135 135
             new EE_Restriction_Generator_Event_Related_Public(
136 136
                 $path_to_event_model
137 137
             );
138
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
138
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
139 139
             new EE_Restriction_Generator_Event_Related_Protected(
140 140
                 $path_to_event_model
141 141
             );
142
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
142
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] =
143 143
             new EE_Restriction_Generator_Event_Related_Protected(
144 144
                 $path_to_event_model
145 145
             );
146
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
146
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] =
147 147
             new EE_Restriction_Generator_Event_Related_Protected(
148 148
                 $path_to_event_model,
149 149
                 EEM_Base::caps_edit
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
          * @param int $end_data Unix timestamp representing now + 30 days in seconds.
186 186
          * @return int Unix timestamp
187 187
          */
188
-        $end_date       = apply_filters(
188
+        $end_date = apply_filters(
189 189
             'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
190 190
             $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
191 191
         );
@@ -251,10 +251,10 @@  discard block
 block discarded – undo
251 251
      */
252 252
     private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time)
253 253
     {
254
-        if (! is_array($start_time)) {
254
+        if ( ! is_array($start_time)) {
255 255
             throw new InvalidDataTypeException('start_time', $start_time, 'array');
256 256
         }
257
-        if (! is_array($end_time)) {
257
+        if ( ! is_array($end_time)) {
258 258
             throw new InvalidDataTypeException('end_time', $end_time, 'array');
259 259
         }
260 260
         if (count($start_time) !== 2) {
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      */
290 290
     public function get_all_event_dates($EVT_ID = 0)
291 291
     {
292
-        if (! $EVT_ID) { // on add_new_event event_id gets set to 0
292
+        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
293 293
             return $this->create_new_blank_datetime();
294 294
         }
295 295
         $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
             $query_params,
427 427
             EEM_Base::default_where_conditions_this_only
428 428
         );
429
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
429
+        $query_params = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
430 430
         return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
431 431
     }
432 432
 
@@ -587,14 +587,14 @@  discard block
 block discarded – undo
587 587
         $query_params['group_by'] = ['dtt_year', 'dtt_month'];
588 588
         $query_params             = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC');
589 589
 
590
-        $query_interval    = EEH_DTT_Helper::get_sql_query_interval_for_offset(
590
+        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset(
591 591
             $this->get_timezone(),
592 592
             'DTT_EVT_start'
593 593
         );
594 594
         $columns_to_select = [
595
-            'dtt_year'      => ['YEAR(' . $query_interval . ')', '%s'],
596
-            'dtt_month'     => ['MONTHNAME(' . $query_interval . ')', '%s'],
597
-            'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'],
595
+            'dtt_year'      => ['YEAR('.$query_interval.')', '%s'],
596
+            'dtt_month'     => ['MONTHNAME('.$query_interval.')', '%s'],
597
+            'dtt_month_num' => ['MONTH('.$query_interval.')', '%s'],
598 598
         ];
599 599
         return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
600 600
     }
@@ -676,17 +676,17 @@  discard block
 block discarded – undo
676 676
                 ['DTT_EVT_end' => ['<', time()]]
677 677
             ),
678 678
         ];
679
-        if (! empty($stati_to_include)) {
679
+        if ( ! empty($stati_to_include)) {
680 680
             foreach (array_keys($status_query_args) as $status) {
681
-                if (! in_array($status, $stati_to_include, true)) {
682
-                    unset($status_query_args[ $status ]);
681
+                if ( ! in_array($status, $stati_to_include, true)) {
682
+                    unset($status_query_args[$status]);
683 683
                 }
684 684
             }
685 685
         }
686 686
         // loop through and query counts for each stati.
687 687
         $status_query_results = [];
688 688
         foreach ($status_query_args as $status => $status_where_conditions) {
689
-            $status_query_results[ $status ] = EEM_Datetime::count(
689
+            $status_query_results[$status] = EEM_Datetime::count(
690 690
                 [$status_where_conditions],
691 691
                 'DTT_ID',
692 692
                 true
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
     public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = [])
708 708
     {
709 709
         $count = $this->get_datetime_counts_by_status([$status], $query_params);
710
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
710
+        return ! empty($count[$status]) ? $count[$status] : 0;
711 711
     }
712 712
 
713 713
 
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
      */
807 807
     private function addExpiredWhereParams(array $where_params, bool $include_expired = true)
808 808
     {
809
-        if (! $include_expired) {
809
+        if ( ! $include_expired) {
810 810
             $where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)];
811 811
         }
812 812
         return $where_params;
Please login to merge, or discard this patch.
Indentation   +839 added lines, -839 removed lines patch added patch discarded remove patch
@@ -16,843 +16,843 @@
 block discarded – undo
16 16
  */
17 17
 class EEM_Datetime extends EEM_Soft_Delete_Base
18 18
 {
19
-    /**
20
-     * @var EEM_Datetime $_instance
21
-     */
22
-    protected static $_instance;
23
-
24
-
25
-    /**
26
-     * private constructor to prevent direct creation
27
-     *
28
-     * @param string|null $timezone A string representing the timezone we want to set for returned Date Time Strings
29
-     *                              (and any incoming timezone data that gets saved).
30
-     *                              Note this just sends the timezone info to the date time model field objects.
31
-     *                              Default is NULL
32
-     *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
33
-     * @throws EE_Error
34
-     */
35
-    protected function __construct(?string $timezone = '')
36
-    {
37
-        $this->singular_item           = esc_html__('Datetime', 'event_espresso');
38
-        $this->plural_item             = esc_html__('Datetimes', 'event_espresso');
39
-        $this->_tables                 = [
40
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
41
-        ];
42
-        $this->_fields                 = [
43
-            'Datetime' => [
44
-                'DTT_ID'          => new EE_Primary_Key_Int_Field(
45
-                    'DTT_ID',
46
-                    esc_html__('Datetime ID', 'event_espresso')
47
-                ),
48
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
49
-                    'EVT_ID',
50
-                    esc_html__('Event ID', 'event_espresso'),
51
-                    false,
52
-                    0,
53
-                    'Event'
54
-                ),
55
-                'VNU_ID'          => new EE_Foreign_Key_Int_Field(
56
-                    'VNU_ID',
57
-                    __('Venue ID', 'event_espresso'),
58
-                    false,
59
-                    0,
60
-                    'Venue'
61
-                ),
62
-                'DTT_name'        => new EE_Plain_Text_Field(
63
-                    'DTT_name',
64
-                    esc_html__('Datetime Name', 'event_espresso'),
65
-                    false,
66
-                    ''
67
-                ),
68
-                'DTT_description' => new EE_Post_Content_Field(
69
-                    'DTT_description',
70
-                    esc_html__('Description for Datetime', 'event_espresso'),
71
-                    false,
72
-                    ''
73
-                ),
74
-                'DTT_EVT_start'   => new EE_Datetime_Field(
75
-                    'DTT_EVT_start',
76
-                    esc_html__('Start time/date of Event', 'event_espresso'),
77
-                    false,
78
-                    EE_Datetime_Field::now,
79
-                    $timezone
80
-                ),
81
-                'DTT_EVT_end'     => new EE_Datetime_Field(
82
-                    'DTT_EVT_end',
83
-                    esc_html__('End time/date of Event', 'event_espresso'),
84
-                    false,
85
-                    EE_Datetime_Field::now,
86
-                    $timezone
87
-                ),
88
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
89
-                    'DTT_reg_limit',
90
-                    esc_html__('Registration Limit for this time', 'event_espresso'),
91
-                    false,
92
-                    EE_INF
93
-                ),
94
-                'DTT_sold'        => new EE_Integer_Field(
95
-                    'DTT_sold',
96
-                    esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
97
-                    false,
98
-                    0
99
-                ),
100
-                'DTT_reserved'    => new EE_Integer_Field(
101
-                    'DTT_reserved',
102
-                    esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
103
-                    false,
104
-                    0
105
-                ),
106
-                'DTT_is_primary'  => new EE_Boolean_Field(
107
-                    'DTT_is_primary',
108
-                    esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
109
-                    false,
110
-                    false
111
-                ),
112
-                'DTT_order'       => new EE_Integer_Field(
113
-                    'DTT_order',
114
-                    esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
115
-                    false,
116
-                    0
117
-                ),
118
-                'DTT_parent'      => new EE_Integer_Field(
119
-                    'DTT_parent',
120
-                    esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
121
-                    true,
122
-                    0
123
-                ),
124
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
125
-                    'DTT_deleted',
126
-                    esc_html__('Flag indicating datetime is archived', 'event_espresso'),
127
-                    false,
128
-                    false
129
-                ),
130
-            ],
131
-        ];
132
-        $this->_model_relations        = [
133
-            'Ticket'          => new EE_HABTM_Relation('Datetime_Ticket'),
134
-            'Event'           => new EE_Belongs_To_Relation(),
135
-            'Checkin'         => new EE_Has_Many_Relation(),
136
-            'Datetime_Ticket' => new EE_Has_Many_Relation(),
137
-            'Venue'           => new EE_Belongs_To_Relation(),
138
-        ];
139
-        $path_to_event_model           = 'Event';
140
-        $this->model_chain_to_password = $path_to_event_model;
141
-        $this->_model_chain_to_wp_user = $path_to_event_model;
142
-        // this model is generally available for reading
143
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
144
-            new EE_Restriction_Generator_Event_Related_Public(
145
-                $path_to_event_model
146
-            );
147
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
148
-            new EE_Restriction_Generator_Event_Related_Protected(
149
-                $path_to_event_model
150
-            );
151
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
152
-            new EE_Restriction_Generator_Event_Related_Protected(
153
-                $path_to_event_model
154
-            );
155
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
156
-            new EE_Restriction_Generator_Event_Related_Protected(
157
-                $path_to_event_model,
158
-                EEM_Base::caps_edit
159
-            );
160
-        parent::__construct($timezone);
161
-    }
162
-
163
-
164
-    /**
165
-     * create new blank datetime
166
-     *
167
-     * @access public
168
-     * @return EE_Datetime[] array on success, FALSE on fail
169
-     * @throws EE_Error
170
-     * @throws InvalidArgumentException
171
-     * @throws InvalidDataTypeException
172
-     * @throws ReflectionException
173
-     * @throws InvalidInterfaceException
174
-     */
175
-    public function create_new_blank_datetime()
176
-    {
177
-        // makes sure timezone is always set.
178
-        $timezone_string = $this->get_timezone();
179
-        /**
180
-         * Filters the initial start date for the new datetime.
181
-         * Any time included in this value will be overridden later so use additional filters to modify the time.
182
-         *
183
-         * @param int $start_date Unix timestamp representing now + 30 days in seconds.
184
-         * @return int Unix timestamp
185
-         */
186
-        $start_date = apply_filters(
187
-            'FHEE__EEM_Datetime__create_new_blank_datetime__start_date',
188
-            $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS
189
-        );
190
-        /**
191
-         * Filters the initial end date for the new datetime.
192
-         * Any time included in this value will be overridden later so use additional filters to modify the time.
193
-         *
194
-         * @param int $end_data Unix timestamp representing now + 30 days in seconds.
195
-         * @return int Unix timestamp
196
-         */
197
-        $end_date       = apply_filters(
198
-            'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
199
-            $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
200
-        );
201
-        $blank_datetime = EE_Datetime::new_instance(
202
-            [
203
-                'DTT_EVT_start' => $start_date,
204
-                'DTT_EVT_end'   => $end_date,
205
-                'DTT_order'     => 1,
206
-                'DTT_reg_limit' => EE_INF_IN_DB,
207
-            ],
208
-            $timezone_string
209
-        );
210
-        /**
211
-         * Filters the initial start time and format for the new EE_Datetime instance.
212
-         *
213
-         * @param array $start_time An array having size 2.  First element is the time, second element is the time
214
-         *                          format.
215
-         * @return array
216
-         */
217
-        $start_time = apply_filters(
218
-            'FHEE__EEM_Datetime__create_new_blank_datetime__start_time',
219
-            ['8am', 'ga']
220
-        );
221
-        /**
222
-         * Filters the initial end time and format for the new EE_Datetime instance.
223
-         *
224
-         * @param array $end_time An array having size 2.  First element is the time, second element is the time
225
-         *                        format
226
-         * @return array
227
-         */
228
-        $end_time = apply_filters(
229
-            'FHEE__EEM_Datetime__create_new_blank_datetime__end_time',
230
-            ['5pm', 'ga']
231
-        );
232
-        $this->validateStartAndEndTimeForBlankDate($start_time, $end_time);
233
-        $blank_datetime->set_start_time(
234
-            $this->convert_datetime_for_query(
235
-                'DTT_EVT_start',
236
-                $start_time[0],
237
-                $start_time[1],
238
-                $timezone_string
239
-            )
240
-        );
241
-        $blank_datetime->set_end_time(
242
-            $this->convert_datetime_for_query(
243
-                'DTT_EVT_end',
244
-                $end_time[0],
245
-                $end_time[1],
246
-                $timezone_string
247
-            )
248
-        );
249
-        return [$blank_datetime];
250
-    }
251
-
252
-
253
-    /**
254
-     * Validates whether the start_time and end_time are in the expected format.
255
-     *
256
-     * @param array $start_time
257
-     * @param array $end_time
258
-     * @throws InvalidArgumentException
259
-     * @throws InvalidDataTypeException
260
-     */
261
-    private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time)
262
-    {
263
-        if (! is_array($start_time)) {
264
-            throw new InvalidDataTypeException('start_time', $start_time, 'array');
265
-        }
266
-        if (! is_array($end_time)) {
267
-            throw new InvalidDataTypeException('end_time', $end_time, 'array');
268
-        }
269
-        if (count($start_time) !== 2) {
270
-            throw new InvalidArgumentException(
271
-                sprintf(
272
-                    'The variable %1$s is expected to be an array with two elements.  The first item in the '
273
-                    . 'array should be a valid time string, the second item in the array should be a valid time format',
274
-                    '$start_time'
275
-                )
276
-            );
277
-        }
278
-        if (count($end_time) !== 2) {
279
-            throw new InvalidArgumentException(
280
-                sprintf(
281
-                    'The variable %1$s is expected to be an array with two elements.  The first item in the '
282
-                    . 'array should be a valid time string, the second item in the array should be a valid time format',
283
-                    '$end_time'
284
-                )
285
-            );
286
-        }
287
-    }
288
-
289
-
290
-    /**
291
-     * get event start date from db
292
-     *
293
-     * @access public
294
-     * @param int $EVT_ID
295
-     * @return EE_Datetime[] array on success, FALSE on fail
296
-     * @throws EE_Error
297
-     * @throws ReflectionException
298
-     */
299
-    public function get_all_event_dates($EVT_ID = 0)
300
-    {
301
-        if (! $EVT_ID) { // on add_new_event event_id gets set to 0
302
-            return $this->create_new_blank_datetime();
303
-        }
304
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
305
-        if (empty($results)) {
306
-            return $this->create_new_blank_datetime();
307
-        }
308
-        return $results;
309
-    }
310
-
311
-
312
-    /**
313
-     * get all datetimes attached to an event ordered by the DTT_order field
314
-     *
315
-     * @public
316
-     * @param int     $EVT_ID     event id
317
-     * @param boolean $include_expired
318
-     * @param boolean $include_deleted
319
-     * @param int     $limit      If included then limit the count of results by
320
-     *                            the given number
321
-     * @return EE_Datetime[]
322
-     * @throws EE_Error
323
-     */
324
-    public function get_datetimes_for_event_ordered_by_DTT_order(
325
-        int $EVT_ID,
326
-        bool $include_expired = true,
327
-        bool $include_deleted = true,
328
-        $limit = 0
329
-    ) {
330
-        $prev_data_prep_value = $this->prepModelForQuery();
331
-        $where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
332
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
333
-        $query_params         = $this->addDefaultWhereConditions($query_params);
334
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
335
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
336
-    }
337
-
338
-
339
-    /**
340
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance".
341
-     * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
342
-     * and then the earlier datetimes are the most important.
343
-     * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
344
-     *
345
-     * @param int $EVT_ID
346
-     * @param int $limit
347
-     * @return EE_Datetime[]|EE_Base_Class[]
348
-     * @throws EE_Error
349
-     */
350
-    public function get_datetimes_for_event_ordered_by_importance(int $EVT_ID, $limit = 0)
351
-    {
352
-        $query_params[0] = ['Event.EVT_ID' => absint($EVT_ID)];
353
-        $query_params    = $this->addDefaultWhereConditions($query_params);
354
-        $query_params    = $this->addDefaultQueryParams($query_params, $limit);
355
-        return $this->get_all($query_params);
356
-    }
357
-
358
-
359
-    /**
360
-     * @param int     $EVT_ID
361
-     * @param boolean $include_expired
362
-     * @param boolean $include_deleted
363
-     * @return EE_Datetime
364
-     * @throws EE_Error
365
-     */
366
-    public function get_oldest_datetime_for_event(
367
-        int $EVT_ID,
368
-        bool $include_expired = false,
369
-        bool $include_deleted = false
370
-    ) {
371
-        $results = $this->get_datetimes_for_event_ordered_by_start_time(
372
-            $EVT_ID,
373
-            $include_expired,
374
-            $include_deleted,
375
-            1
376
-        );
377
-        if ($results) {
378
-            return array_shift($results);
379
-        }
380
-        return null;
381
-    }
382
-
383
-
384
-    /**
385
-     * Gets the 'primary' datetime for an event.
386
-     *
387
-     * @param int  $EVT_ID
388
-     * @param bool $try_to_exclude_expired
389
-     * @param bool $try_to_exclude_deleted
390
-     * @return EE_Datetime
391
-     * @throws EE_Error
392
-     */
393
-    public function get_primary_datetime_for_event(
394
-        int $EVT_ID,
395
-        bool $try_to_exclude_expired = true,
396
-        bool $try_to_exclude_deleted = true
397
-    ) {
398
-        if ($try_to_exclude_expired) {
399
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
400
-            if ($non_expired) {
401
-                return $non_expired;
402
-            }
403
-        }
404
-        if ($try_to_exclude_deleted) {
405
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
406
-            if ($expired_even) {
407
-                return $expired_even;
408
-            }
409
-        }
410
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
411
-    }
412
-
413
-
414
-    /**
415
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
416
-     * only by start date
417
-     *
418
-     * @param int     $EVT_ID
419
-     * @param boolean $include_expired
420
-     * @param boolean $include_deleted
421
-     * @param int     $limit
422
-     * @return EE_Datetime[]
423
-     * @throws EE_Error
424
-     */
425
-    public function get_datetimes_for_event_ordered_by_start_time(
426
-        int $EVT_ID,
427
-        bool $include_expired = true,
428
-        bool $include_deleted = true,
429
-        $limit = 0
430
-    ) {
431
-        $prev_data_prep_value = $this->prepModelForQuery();
432
-        $where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
433
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
434
-        $query_params         = $this->addDefaultWhereConditions(
435
-            $query_params,
436
-            EEM_Base::default_where_conditions_this_only
437
-        );
438
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
439
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
440
-    }
441
-
442
-
443
-    /**
444
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
445
-     * only by start date
446
-     *
447
-     * @param int     $TKT_ID
448
-     * @param boolean $include_expired
449
-     * @param boolean $include_deleted
450
-     * @param int     $limit
451
-     * @return EE_Datetime[]
452
-     * @throws EE_Error
453
-     */
454
-    public function get_datetimes_for_ticket_ordered_by_start_time(
455
-        int $TKT_ID,
456
-        bool $include_expired = true,
457
-        bool $include_deleted = true,
458
-        $limit = 0
459
-    ) {
460
-        $prev_data_prep_value = $this->prepModelForQuery();
461
-        $where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
462
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
463
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit);
464
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
465
-    }
466
-
467
-
468
-    /**
469
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
470
-     * datetimes.
471
-     *
472
-     * @param int      $TKT_ID           ID of ticket to retrieve the datetimes for
473
-     * @param boolean  $include_expired  whether to include expired datetimes or not
474
-     * @param boolean  $include_deleted  whether to include trashed datetimes or not.
475
-     * @param int|null $limit            if null, no limit, if int then limit results by
476
-     *                                   that number
477
-     * @return EE_Datetime[]
478
-     * @throws EE_Error
479
-     */
480
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
481
-        int $TKT_ID,
482
-        bool $include_expired = true,
483
-        bool $include_deleted = true,
484
-        $limit = 0
485
-    ) {
486
-        $prev_data_prep_value = $this->prepModelForQuery();
487
-        $where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
488
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
489
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
490
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
491
-    }
492
-
493
-
494
-    /**
495
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
496
-     * reason it doesn't exist, we consider the earliest event the most important)
497
-     *
498
-     * @param int $EVT_ID
499
-     * @return EE_Datetime
500
-     * @throws EE_Error
501
-     */
502
-    public function get_most_important_datetime_for_event(int $EVT_ID)
503
-    {
504
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
505
-        if ($results) {
506
-            return array_shift($results);
507
-        }
508
-        return null;
509
-    }
510
-
511
-
512
-    /**
513
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
514
-     * grouped by month and year.
515
-     *
516
-     * @param array  $where_params       @see
517
-     *                                   https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
518
-     * @param string $evt_active_status  A string representing the evt active status to filter the months by.
519
-     *                                   Can be:
520
-     *                                   - '' = no filter
521
-     *                                   - upcoming = Published events with at least one upcoming datetime.
522
-     *                                   - expired = Events with all datetimes expired.
523
-     *                                   - active = Events that are published and have at least one datetime that
524
-     *                                   starts before now and ends after now.
525
-     *                                   - inactive = Events that are either not published.
526
-     * @return stdClass[]
527
-     * @throws EE_Error
528
-     * @throws InvalidArgumentException
529
-     * @throws InvalidArgumentException
530
-     */
531
-    public function get_dtt_months_and_years(array $where_params, $evt_active_status = '')
532
-    {
533
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
534
-        $current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
535
-        switch ($evt_active_status) {
536
-            case 'upcoming':
537
-                $where_params['Event.status'] = 'publish';
538
-                // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
539
-                if (isset($where_params['DTT_EVT_start'])) {
540
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
541
-                }
542
-                $where_params['DTT_EVT_start'] = ['>', $current_time_for_DTT_EVT_start];
543
-                break;
544
-            case 'expired':
545
-                if (isset($where_params['Event.status'])) {
546
-                    unset($where_params['Event.status']);
547
-                }
548
-                // get events to exclude
549
-                $exclude_query[0] = array_merge(
550
-                    $where_params,
551
-                    ['DTT_EVT_end' => ['>', $current_time_for_DTT_EVT_end]]
552
-                );
553
-                // first get all events that have datetimes where its not expired.
554
-                $event_ids = $this->_get_all_wpdb_results(
555
-                    $exclude_query,
556
-                    OBJECT_K,
557
-                    'Datetime.EVT_ID'
558
-                );
559
-                $event_ids = array_keys($event_ids);
560
-                if (isset($where_params['DTT_EVT_end'])) {
561
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
562
-                }
563
-                $where_params['DTT_EVT_end']  = ['<', $current_time_for_DTT_EVT_end];
564
-                $where_params['Event.EVT_ID'] = ['NOT IN', $event_ids];
565
-                break;
566
-            case 'active':
567
-                $where_params['Event.status'] = 'publish';
568
-                if (isset($where_params['DTT_EVT_start'])) {
569
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
570
-                }
571
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
572
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
573
-                }
574
-                $where_params['DTT_EVT_start'] = ['<', $current_time_for_DTT_EVT_start];
575
-                $where_params['DTT_EVT_end']   = ['>', $current_time_for_DTT_EVT_end];
576
-                break;
577
-            case 'inactive':
578
-                if (isset($where_params['Event.status'])) {
579
-                    unset($where_params['Event.status']);
580
-                }
581
-                if (isset($where_params['OR'])) {
582
-                    $where_params['AND']['OR'] = $where_params['OR'];
583
-                }
584
-                if (isset($where_params['DTT_EVT_end'])) {
585
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
586
-                    unset($where_params['DTT_EVT_end']);
587
-                }
588
-                if (isset($where_params['DTT_EVT_start'])) {
589
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
590
-                    unset($where_params['DTT_EVT_start']);
591
-                }
592
-                $where_params['AND']['Event.status'] = ['!=', 'publish'];
593
-                break;
594
-        }
595
-        $query_params[0]          = $where_params;
596
-        $query_params['group_by'] = ['dtt_year', 'dtt_month'];
597
-        $query_params             = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC');
598
-
599
-        $query_interval    = EEH_DTT_Helper::get_sql_query_interval_for_offset(
600
-            $this->get_timezone(),
601
-            'DTT_EVT_start'
602
-        );
603
-        $columns_to_select = [
604
-            'dtt_year'      => ['YEAR(' . $query_interval . ')', '%s'],
605
-            'dtt_month'     => ['MONTHNAME(' . $query_interval . ')', '%s'],
606
-            'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'],
607
-        ];
608
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
609
-    }
610
-
611
-
612
-    /**
613
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
614
-     * for the tickets for each datetime)
615
-     *
616
-     * @param EE_Base_Class[]|EE_Datetime[] $datetimes
617
-     * @throws EE_Error
618
-     * @throws ReflectionException
619
-     */
620
-    public function update_sold(array $datetimes)
621
-    {
622
-        EE_Error::doing_it_wrong(
623
-            __FUNCTION__,
624
-            esc_html__(
625
-                'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
626
-                'event_espresso'
627
-            ),
628
-            '4.9.32.rc.005'
629
-        );
630
-        foreach ($datetimes as $datetime) {
631
-            $datetime->update_sold();
632
-        }
633
-    }
634
-
635
-
636
-    /**
637
-     *    Gets the total number of tickets available at a particular datetime
638
-     *    (does NOT take into account the datetime's spaces available)
639
-     *
640
-     * @param int   $DTT_ID
641
-     * @param array $query_params
642
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
643
-     *             tickets attached to datetime then FALSE is returned.
644
-     * @throws EE_Error
645
-     * @throws ReflectionException
646
-     */
647
-    public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = [])
648
-    {
649
-        $datetime = $this->get_one_by_ID($DTT_ID);
650
-        if ($datetime instanceof EE_Datetime) {
651
-            return $datetime->tickets_remaining($query_params);
652
-        }
653
-        return 0;
654
-    }
655
-
656
-
657
-    /**
658
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
659
-     *
660
-     * @param array $stati_to_include  If included you can restrict the statuses we return counts for by including the
661
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
662
-     *                                 for all valid stati.
663
-     * @param array $query_params      If included can be used to refine the conditions for returning the count (i.e.
664
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
665
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
666
-     * @throws EE_Error
667
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
668
-     *                                 EE_Datetime::expired
669
-     */
670
-    public function get_datetime_counts_by_status(array $stati_to_include = [], array $query_params = [])
671
-    {
672
-        // only accept where conditions for this query.
673
-        $_where            = isset($query_params[0]) ? $query_params[0] : [];
674
-        $status_query_args = [
675
-            EE_Datetime::active   => array_merge(
676
-                $_where,
677
-                ['DTT_EVT_start' => ['<', time()], 'DTT_EVT_end' => ['>', time()]]
678
-            ),
679
-            EE_Datetime::upcoming => array_merge(
680
-                $_where,
681
-                ['DTT_EVT_start' => ['>', time()]]
682
-            ),
683
-            EE_Datetime::expired  => array_merge(
684
-                $_where,
685
-                ['DTT_EVT_end' => ['<', time()]]
686
-            ),
687
-        ];
688
-        if (! empty($stati_to_include)) {
689
-            foreach (array_keys($status_query_args) as $status) {
690
-                if (! in_array($status, $stati_to_include, true)) {
691
-                    unset($status_query_args[ $status ]);
692
-                }
693
-            }
694
-        }
695
-        // loop through and query counts for each stati.
696
-        $status_query_results = [];
697
-        foreach ($status_query_args as $status => $status_where_conditions) {
698
-            $status_query_results[ $status ] = EEM_Datetime::count(
699
-                [$status_where_conditions],
700
-                'DTT_ID',
701
-                true
702
-            );
703
-        }
704
-        return $status_query_results;
705
-    }
706
-
707
-
708
-    /**
709
-     * Returns the specific count for a given Datetime status matching any given query_params.
710
-     *
711
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
712
-     * @param array  $query_params
713
-     * @return int
714
-     * @throws EE_Error
715
-     */
716
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = [])
717
-    {
718
-        $count = $this->get_datetime_counts_by_status([$status], $query_params);
719
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
720
-    }
721
-
722
-
723
-    /**
724
-     * @return bool|int
725
-     * @since   5.0.0.p
726
-     */
727
-    private function prepModelForQuery()
728
-    {
729
-        $prev_data_prep_value = $this->get_assumption_concerning_values_already_prepared_by_model_object();
730
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
731
-        return $prev_data_prep_value;
732
-    }
733
-
734
-
735
-    /**
736
-     * @param array    $query_params
737
-     * @param bool|int $prev_data_prep_value
738
-     * @return EE_Base_Class[]|EE_Datetime[]
739
-     * @throws EE_Error
740
-     * @since   5.0.0.p
741
-     */
742
-    private function getDatetimesAndRestoreModel(array $query_params, $prev_data_prep_value)
743
-    {
744
-        $result = $this->get_all($query_params);
745
-        $this->assume_values_already_prepared_by_model_object($prev_data_prep_value);
746
-        return $result;
747
-    }
748
-
749
-
750
-    /**
751
-     * @param array  $query_params
752
-     * @param int    $limit
753
-     * @param string $order_by
754
-     * @param string $order
755
-     * @return array
756
-     * @since   5.0.0.p
757
-     */
758
-    private function addDefaultQueryParams(array $query_params, $limit = 0, $order_by = 'DTT_EVT_start', $order = 'ASC')
759
-    {
760
-        $query_params = $this->addOrderByQueryParams($query_params, $order_by, $order);
761
-        $query_params = $this->addLimitQueryParams($query_params, $limit);
762
-        return $query_params;
763
-    }
764
-
765
-
766
-    /**
767
-     * @param array  $query_params
768
-     * @param string $default_where_conditions
769
-     * @return array
770
-     * @since   5.0.0.p
771
-     */
772
-    private function addDefaultWhereConditions(
773
-        array $query_params,
774
-        $default_where_conditions = EEM_Base::default_where_conditions_none
775
-    ) {
776
-        $query_params['default_where_conditions'] = $default_where_conditions;
777
-        return $query_params;
778
-    }
779
-
780
-
781
-    /**
782
-     * @param array $where_params
783
-     * @param bool  $include_deleted
784
-     * @param bool  $include_expired
785
-     * @return array
786
-     * @since   5.0.0.p
787
-     */
788
-    private function addDefaultWhereParams(
789
-        array $where_params,
790
-        bool $include_deleted = true,
791
-        bool $include_expired = true
792
-    ) {
793
-        $where_params = $this->addExpiredWhereParams($where_params, $include_expired);
794
-        $where_params = $this->addDeletedWhereParams($where_params, $include_deleted);
795
-        return $where_params;
796
-    }
797
-
798
-
799
-    /**
800
-     * @param array $where_params
801
-     * @param bool  $include_deleted
802
-     * @return array
803
-     * @since   5.0.0.p
804
-     */
805
-    private function addDeletedWhereParams(array $where_params, bool $include_deleted = true)
806
-    {
807
-        $deleted                     = $include_deleted ? [true, false] : [false];
808
-        $where_params['DTT_deleted'] = ['IN', $deleted];
809
-        return $where_params;
810
-    }
811
-
812
-
813
-    /**
814
-     * @param array $where_params
815
-     * @param bool  $include_expired
816
-     * @return array
817
-     * @since   5.0.0.p
818
-     */
819
-    private function addExpiredWhereParams(array $where_params, bool $include_expired = true)
820
-    {
821
-        if (! $include_expired) {
822
-            $where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)];
823
-        }
824
-        return $where_params;
825
-    }
826
-
827
-
828
-    /**
829
-     * @param array $query_params
830
-     * @param int   $limit
831
-     * @return array
832
-     * @since   5.0.0.p
833
-     */
834
-    private function addLimitQueryParams(array $query_params, $limit = 0)
835
-    {
836
-        if ($limit) {
837
-            $query_params['limit'] = $limit;
838
-        }
839
-        return $query_params;
840
-    }
841
-
842
-
843
-    /**
844
-     * @param array  $query_params
845
-     * @param string $order_by
846
-     * @param string $order
847
-     * @return array
848
-     * @since   5.0.0.p
849
-     */
850
-    private function addOrderByQueryParams(array $query_params, $order_by = 'DTT_EVT_start', $order = 'ASC')
851
-    {
852
-        $order                    = $order === 'ASC' ? 'ASC' : 'DESC';
853
-        $valid_order_columns      = ['DTT_ID', 'DTT_EVT_start', 'DTT_EVT_end', 'DTT_order'];
854
-        $order_by                 = in_array($order_by, $valid_order_columns, true) ? $order_by : 'DTT_EVT_start';
855
-        $query_params['order_by'] = [$order_by => $order];
856
-        return $query_params;
857
-    }
19
+	/**
20
+	 * @var EEM_Datetime $_instance
21
+	 */
22
+	protected static $_instance;
23
+
24
+
25
+	/**
26
+	 * private constructor to prevent direct creation
27
+	 *
28
+	 * @param string|null $timezone A string representing the timezone we want to set for returned Date Time Strings
29
+	 *                              (and any incoming timezone data that gets saved).
30
+	 *                              Note this just sends the timezone info to the date time model field objects.
31
+	 *                              Default is NULL
32
+	 *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
33
+	 * @throws EE_Error
34
+	 */
35
+	protected function __construct(?string $timezone = '')
36
+	{
37
+		$this->singular_item           = esc_html__('Datetime', 'event_espresso');
38
+		$this->plural_item             = esc_html__('Datetimes', 'event_espresso');
39
+		$this->_tables                 = [
40
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
41
+		];
42
+		$this->_fields                 = [
43
+			'Datetime' => [
44
+				'DTT_ID'          => new EE_Primary_Key_Int_Field(
45
+					'DTT_ID',
46
+					esc_html__('Datetime ID', 'event_espresso')
47
+				),
48
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
49
+					'EVT_ID',
50
+					esc_html__('Event ID', 'event_espresso'),
51
+					false,
52
+					0,
53
+					'Event'
54
+				),
55
+				'VNU_ID'          => new EE_Foreign_Key_Int_Field(
56
+					'VNU_ID',
57
+					__('Venue ID', 'event_espresso'),
58
+					false,
59
+					0,
60
+					'Venue'
61
+				),
62
+				'DTT_name'        => new EE_Plain_Text_Field(
63
+					'DTT_name',
64
+					esc_html__('Datetime Name', 'event_espresso'),
65
+					false,
66
+					''
67
+				),
68
+				'DTT_description' => new EE_Post_Content_Field(
69
+					'DTT_description',
70
+					esc_html__('Description for Datetime', 'event_espresso'),
71
+					false,
72
+					''
73
+				),
74
+				'DTT_EVT_start'   => new EE_Datetime_Field(
75
+					'DTT_EVT_start',
76
+					esc_html__('Start time/date of Event', 'event_espresso'),
77
+					false,
78
+					EE_Datetime_Field::now,
79
+					$timezone
80
+				),
81
+				'DTT_EVT_end'     => new EE_Datetime_Field(
82
+					'DTT_EVT_end',
83
+					esc_html__('End time/date of Event', 'event_espresso'),
84
+					false,
85
+					EE_Datetime_Field::now,
86
+					$timezone
87
+				),
88
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
89
+					'DTT_reg_limit',
90
+					esc_html__('Registration Limit for this time', 'event_espresso'),
91
+					false,
92
+					EE_INF
93
+				),
94
+				'DTT_sold'        => new EE_Integer_Field(
95
+					'DTT_sold',
96
+					esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
97
+					false,
98
+					0
99
+				),
100
+				'DTT_reserved'    => new EE_Integer_Field(
101
+					'DTT_reserved',
102
+					esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
103
+					false,
104
+					0
105
+				),
106
+				'DTT_is_primary'  => new EE_Boolean_Field(
107
+					'DTT_is_primary',
108
+					esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
109
+					false,
110
+					false
111
+				),
112
+				'DTT_order'       => new EE_Integer_Field(
113
+					'DTT_order',
114
+					esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
115
+					false,
116
+					0
117
+				),
118
+				'DTT_parent'      => new EE_Integer_Field(
119
+					'DTT_parent',
120
+					esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
121
+					true,
122
+					0
123
+				),
124
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
125
+					'DTT_deleted',
126
+					esc_html__('Flag indicating datetime is archived', 'event_espresso'),
127
+					false,
128
+					false
129
+				),
130
+			],
131
+		];
132
+		$this->_model_relations        = [
133
+			'Ticket'          => new EE_HABTM_Relation('Datetime_Ticket'),
134
+			'Event'           => new EE_Belongs_To_Relation(),
135
+			'Checkin'         => new EE_Has_Many_Relation(),
136
+			'Datetime_Ticket' => new EE_Has_Many_Relation(),
137
+			'Venue'           => new EE_Belongs_To_Relation(),
138
+		];
139
+		$path_to_event_model           = 'Event';
140
+		$this->model_chain_to_password = $path_to_event_model;
141
+		$this->_model_chain_to_wp_user = $path_to_event_model;
142
+		// this model is generally available for reading
143
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
144
+			new EE_Restriction_Generator_Event_Related_Public(
145
+				$path_to_event_model
146
+			);
147
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
148
+			new EE_Restriction_Generator_Event_Related_Protected(
149
+				$path_to_event_model
150
+			);
151
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
152
+			new EE_Restriction_Generator_Event_Related_Protected(
153
+				$path_to_event_model
154
+			);
155
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
156
+			new EE_Restriction_Generator_Event_Related_Protected(
157
+				$path_to_event_model,
158
+				EEM_Base::caps_edit
159
+			);
160
+		parent::__construct($timezone);
161
+	}
162
+
163
+
164
+	/**
165
+	 * create new blank datetime
166
+	 *
167
+	 * @access public
168
+	 * @return EE_Datetime[] array on success, FALSE on fail
169
+	 * @throws EE_Error
170
+	 * @throws InvalidArgumentException
171
+	 * @throws InvalidDataTypeException
172
+	 * @throws ReflectionException
173
+	 * @throws InvalidInterfaceException
174
+	 */
175
+	public function create_new_blank_datetime()
176
+	{
177
+		// makes sure timezone is always set.
178
+		$timezone_string = $this->get_timezone();
179
+		/**
180
+		 * Filters the initial start date for the new datetime.
181
+		 * Any time included in this value will be overridden later so use additional filters to modify the time.
182
+		 *
183
+		 * @param int $start_date Unix timestamp representing now + 30 days in seconds.
184
+		 * @return int Unix timestamp
185
+		 */
186
+		$start_date = apply_filters(
187
+			'FHEE__EEM_Datetime__create_new_blank_datetime__start_date',
188
+			$this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS
189
+		);
190
+		/**
191
+		 * Filters the initial end date for the new datetime.
192
+		 * Any time included in this value will be overridden later so use additional filters to modify the time.
193
+		 *
194
+		 * @param int $end_data Unix timestamp representing now + 30 days in seconds.
195
+		 * @return int Unix timestamp
196
+		 */
197
+		$end_date       = apply_filters(
198
+			'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
199
+			$this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
200
+		);
201
+		$blank_datetime = EE_Datetime::new_instance(
202
+			[
203
+				'DTT_EVT_start' => $start_date,
204
+				'DTT_EVT_end'   => $end_date,
205
+				'DTT_order'     => 1,
206
+				'DTT_reg_limit' => EE_INF_IN_DB,
207
+			],
208
+			$timezone_string
209
+		);
210
+		/**
211
+		 * Filters the initial start time and format for the new EE_Datetime instance.
212
+		 *
213
+		 * @param array $start_time An array having size 2.  First element is the time, second element is the time
214
+		 *                          format.
215
+		 * @return array
216
+		 */
217
+		$start_time = apply_filters(
218
+			'FHEE__EEM_Datetime__create_new_blank_datetime__start_time',
219
+			['8am', 'ga']
220
+		);
221
+		/**
222
+		 * Filters the initial end time and format for the new EE_Datetime instance.
223
+		 *
224
+		 * @param array $end_time An array having size 2.  First element is the time, second element is the time
225
+		 *                        format
226
+		 * @return array
227
+		 */
228
+		$end_time = apply_filters(
229
+			'FHEE__EEM_Datetime__create_new_blank_datetime__end_time',
230
+			['5pm', 'ga']
231
+		);
232
+		$this->validateStartAndEndTimeForBlankDate($start_time, $end_time);
233
+		$blank_datetime->set_start_time(
234
+			$this->convert_datetime_for_query(
235
+				'DTT_EVT_start',
236
+				$start_time[0],
237
+				$start_time[1],
238
+				$timezone_string
239
+			)
240
+		);
241
+		$blank_datetime->set_end_time(
242
+			$this->convert_datetime_for_query(
243
+				'DTT_EVT_end',
244
+				$end_time[0],
245
+				$end_time[1],
246
+				$timezone_string
247
+			)
248
+		);
249
+		return [$blank_datetime];
250
+	}
251
+
252
+
253
+	/**
254
+	 * Validates whether the start_time and end_time are in the expected format.
255
+	 *
256
+	 * @param array $start_time
257
+	 * @param array $end_time
258
+	 * @throws InvalidArgumentException
259
+	 * @throws InvalidDataTypeException
260
+	 */
261
+	private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time)
262
+	{
263
+		if (! is_array($start_time)) {
264
+			throw new InvalidDataTypeException('start_time', $start_time, 'array');
265
+		}
266
+		if (! is_array($end_time)) {
267
+			throw new InvalidDataTypeException('end_time', $end_time, 'array');
268
+		}
269
+		if (count($start_time) !== 2) {
270
+			throw new InvalidArgumentException(
271
+				sprintf(
272
+					'The variable %1$s is expected to be an array with two elements.  The first item in the '
273
+					. 'array should be a valid time string, the second item in the array should be a valid time format',
274
+					'$start_time'
275
+				)
276
+			);
277
+		}
278
+		if (count($end_time) !== 2) {
279
+			throw new InvalidArgumentException(
280
+				sprintf(
281
+					'The variable %1$s is expected to be an array with two elements.  The first item in the '
282
+					. 'array should be a valid time string, the second item in the array should be a valid time format',
283
+					'$end_time'
284
+				)
285
+			);
286
+		}
287
+	}
288
+
289
+
290
+	/**
291
+	 * get event start date from db
292
+	 *
293
+	 * @access public
294
+	 * @param int $EVT_ID
295
+	 * @return EE_Datetime[] array on success, FALSE on fail
296
+	 * @throws EE_Error
297
+	 * @throws ReflectionException
298
+	 */
299
+	public function get_all_event_dates($EVT_ID = 0)
300
+	{
301
+		if (! $EVT_ID) { // on add_new_event event_id gets set to 0
302
+			return $this->create_new_blank_datetime();
303
+		}
304
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
305
+		if (empty($results)) {
306
+			return $this->create_new_blank_datetime();
307
+		}
308
+		return $results;
309
+	}
310
+
311
+
312
+	/**
313
+	 * get all datetimes attached to an event ordered by the DTT_order field
314
+	 *
315
+	 * @public
316
+	 * @param int     $EVT_ID     event id
317
+	 * @param boolean $include_expired
318
+	 * @param boolean $include_deleted
319
+	 * @param int     $limit      If included then limit the count of results by
320
+	 *                            the given number
321
+	 * @return EE_Datetime[]
322
+	 * @throws EE_Error
323
+	 */
324
+	public function get_datetimes_for_event_ordered_by_DTT_order(
325
+		int $EVT_ID,
326
+		bool $include_expired = true,
327
+		bool $include_deleted = true,
328
+		$limit = 0
329
+	) {
330
+		$prev_data_prep_value = $this->prepModelForQuery();
331
+		$where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
332
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
333
+		$query_params         = $this->addDefaultWhereConditions($query_params);
334
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
335
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
336
+	}
337
+
338
+
339
+	/**
340
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance".
341
+	 * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
342
+	 * and then the earlier datetimes are the most important.
343
+	 * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
344
+	 *
345
+	 * @param int $EVT_ID
346
+	 * @param int $limit
347
+	 * @return EE_Datetime[]|EE_Base_Class[]
348
+	 * @throws EE_Error
349
+	 */
350
+	public function get_datetimes_for_event_ordered_by_importance(int $EVT_ID, $limit = 0)
351
+	{
352
+		$query_params[0] = ['Event.EVT_ID' => absint($EVT_ID)];
353
+		$query_params    = $this->addDefaultWhereConditions($query_params);
354
+		$query_params    = $this->addDefaultQueryParams($query_params, $limit);
355
+		return $this->get_all($query_params);
356
+	}
357
+
358
+
359
+	/**
360
+	 * @param int     $EVT_ID
361
+	 * @param boolean $include_expired
362
+	 * @param boolean $include_deleted
363
+	 * @return EE_Datetime
364
+	 * @throws EE_Error
365
+	 */
366
+	public function get_oldest_datetime_for_event(
367
+		int $EVT_ID,
368
+		bool $include_expired = false,
369
+		bool $include_deleted = false
370
+	) {
371
+		$results = $this->get_datetimes_for_event_ordered_by_start_time(
372
+			$EVT_ID,
373
+			$include_expired,
374
+			$include_deleted,
375
+			1
376
+		);
377
+		if ($results) {
378
+			return array_shift($results);
379
+		}
380
+		return null;
381
+	}
382
+
383
+
384
+	/**
385
+	 * Gets the 'primary' datetime for an event.
386
+	 *
387
+	 * @param int  $EVT_ID
388
+	 * @param bool $try_to_exclude_expired
389
+	 * @param bool $try_to_exclude_deleted
390
+	 * @return EE_Datetime
391
+	 * @throws EE_Error
392
+	 */
393
+	public function get_primary_datetime_for_event(
394
+		int $EVT_ID,
395
+		bool $try_to_exclude_expired = true,
396
+		bool $try_to_exclude_deleted = true
397
+	) {
398
+		if ($try_to_exclude_expired) {
399
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
400
+			if ($non_expired) {
401
+				return $non_expired;
402
+			}
403
+		}
404
+		if ($try_to_exclude_deleted) {
405
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
406
+			if ($expired_even) {
407
+				return $expired_even;
408
+			}
409
+		}
410
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
416
+	 * only by start date
417
+	 *
418
+	 * @param int     $EVT_ID
419
+	 * @param boolean $include_expired
420
+	 * @param boolean $include_deleted
421
+	 * @param int     $limit
422
+	 * @return EE_Datetime[]
423
+	 * @throws EE_Error
424
+	 */
425
+	public function get_datetimes_for_event_ordered_by_start_time(
426
+		int $EVT_ID,
427
+		bool $include_expired = true,
428
+		bool $include_deleted = true,
429
+		$limit = 0
430
+	) {
431
+		$prev_data_prep_value = $this->prepModelForQuery();
432
+		$where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
433
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
434
+		$query_params         = $this->addDefaultWhereConditions(
435
+			$query_params,
436
+			EEM_Base::default_where_conditions_this_only
437
+		);
438
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
439
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
440
+	}
441
+
442
+
443
+	/**
444
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
445
+	 * only by start date
446
+	 *
447
+	 * @param int     $TKT_ID
448
+	 * @param boolean $include_expired
449
+	 * @param boolean $include_deleted
450
+	 * @param int     $limit
451
+	 * @return EE_Datetime[]
452
+	 * @throws EE_Error
453
+	 */
454
+	public function get_datetimes_for_ticket_ordered_by_start_time(
455
+		int $TKT_ID,
456
+		bool $include_expired = true,
457
+		bool $include_deleted = true,
458
+		$limit = 0
459
+	) {
460
+		$prev_data_prep_value = $this->prepModelForQuery();
461
+		$where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
462
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
463
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit);
464
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
465
+	}
466
+
467
+
468
+	/**
469
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
470
+	 * datetimes.
471
+	 *
472
+	 * @param int      $TKT_ID           ID of ticket to retrieve the datetimes for
473
+	 * @param boolean  $include_expired  whether to include expired datetimes or not
474
+	 * @param boolean  $include_deleted  whether to include trashed datetimes or not.
475
+	 * @param int|null $limit            if null, no limit, if int then limit results by
476
+	 *                                   that number
477
+	 * @return EE_Datetime[]
478
+	 * @throws EE_Error
479
+	 */
480
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
481
+		int $TKT_ID,
482
+		bool $include_expired = true,
483
+		bool $include_deleted = true,
484
+		$limit = 0
485
+	) {
486
+		$prev_data_prep_value = $this->prepModelForQuery();
487
+		$where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
488
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
489
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
490
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
491
+	}
492
+
493
+
494
+	/**
495
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
496
+	 * reason it doesn't exist, we consider the earliest event the most important)
497
+	 *
498
+	 * @param int $EVT_ID
499
+	 * @return EE_Datetime
500
+	 * @throws EE_Error
501
+	 */
502
+	public function get_most_important_datetime_for_event(int $EVT_ID)
503
+	{
504
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
505
+		if ($results) {
506
+			return array_shift($results);
507
+		}
508
+		return null;
509
+	}
510
+
511
+
512
+	/**
513
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
514
+	 * grouped by month and year.
515
+	 *
516
+	 * @param array  $where_params       @see
517
+	 *                                   https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
518
+	 * @param string $evt_active_status  A string representing the evt active status to filter the months by.
519
+	 *                                   Can be:
520
+	 *                                   - '' = no filter
521
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
522
+	 *                                   - expired = Events with all datetimes expired.
523
+	 *                                   - active = Events that are published and have at least one datetime that
524
+	 *                                   starts before now and ends after now.
525
+	 *                                   - inactive = Events that are either not published.
526
+	 * @return stdClass[]
527
+	 * @throws EE_Error
528
+	 * @throws InvalidArgumentException
529
+	 * @throws InvalidArgumentException
530
+	 */
531
+	public function get_dtt_months_and_years(array $where_params, $evt_active_status = '')
532
+	{
533
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
534
+		$current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
535
+		switch ($evt_active_status) {
536
+			case 'upcoming':
537
+				$where_params['Event.status'] = 'publish';
538
+				// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
539
+				if (isset($where_params['DTT_EVT_start'])) {
540
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
541
+				}
542
+				$where_params['DTT_EVT_start'] = ['>', $current_time_for_DTT_EVT_start];
543
+				break;
544
+			case 'expired':
545
+				if (isset($where_params['Event.status'])) {
546
+					unset($where_params['Event.status']);
547
+				}
548
+				// get events to exclude
549
+				$exclude_query[0] = array_merge(
550
+					$where_params,
551
+					['DTT_EVT_end' => ['>', $current_time_for_DTT_EVT_end]]
552
+				);
553
+				// first get all events that have datetimes where its not expired.
554
+				$event_ids = $this->_get_all_wpdb_results(
555
+					$exclude_query,
556
+					OBJECT_K,
557
+					'Datetime.EVT_ID'
558
+				);
559
+				$event_ids = array_keys($event_ids);
560
+				if (isset($where_params['DTT_EVT_end'])) {
561
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
562
+				}
563
+				$where_params['DTT_EVT_end']  = ['<', $current_time_for_DTT_EVT_end];
564
+				$where_params['Event.EVT_ID'] = ['NOT IN', $event_ids];
565
+				break;
566
+			case 'active':
567
+				$where_params['Event.status'] = 'publish';
568
+				if (isset($where_params['DTT_EVT_start'])) {
569
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
570
+				}
571
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
572
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
573
+				}
574
+				$where_params['DTT_EVT_start'] = ['<', $current_time_for_DTT_EVT_start];
575
+				$where_params['DTT_EVT_end']   = ['>', $current_time_for_DTT_EVT_end];
576
+				break;
577
+			case 'inactive':
578
+				if (isset($where_params['Event.status'])) {
579
+					unset($where_params['Event.status']);
580
+				}
581
+				if (isset($where_params['OR'])) {
582
+					$where_params['AND']['OR'] = $where_params['OR'];
583
+				}
584
+				if (isset($where_params['DTT_EVT_end'])) {
585
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
586
+					unset($where_params['DTT_EVT_end']);
587
+				}
588
+				if (isset($where_params['DTT_EVT_start'])) {
589
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
590
+					unset($where_params['DTT_EVT_start']);
591
+				}
592
+				$where_params['AND']['Event.status'] = ['!=', 'publish'];
593
+				break;
594
+		}
595
+		$query_params[0]          = $where_params;
596
+		$query_params['group_by'] = ['dtt_year', 'dtt_month'];
597
+		$query_params             = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC');
598
+
599
+		$query_interval    = EEH_DTT_Helper::get_sql_query_interval_for_offset(
600
+			$this->get_timezone(),
601
+			'DTT_EVT_start'
602
+		);
603
+		$columns_to_select = [
604
+			'dtt_year'      => ['YEAR(' . $query_interval . ')', '%s'],
605
+			'dtt_month'     => ['MONTHNAME(' . $query_interval . ')', '%s'],
606
+			'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'],
607
+		];
608
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
609
+	}
610
+
611
+
612
+	/**
613
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
614
+	 * for the tickets for each datetime)
615
+	 *
616
+	 * @param EE_Base_Class[]|EE_Datetime[] $datetimes
617
+	 * @throws EE_Error
618
+	 * @throws ReflectionException
619
+	 */
620
+	public function update_sold(array $datetimes)
621
+	{
622
+		EE_Error::doing_it_wrong(
623
+			__FUNCTION__,
624
+			esc_html__(
625
+				'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
626
+				'event_espresso'
627
+			),
628
+			'4.9.32.rc.005'
629
+		);
630
+		foreach ($datetimes as $datetime) {
631
+			$datetime->update_sold();
632
+		}
633
+	}
634
+
635
+
636
+	/**
637
+	 *    Gets the total number of tickets available at a particular datetime
638
+	 *    (does NOT take into account the datetime's spaces available)
639
+	 *
640
+	 * @param int   $DTT_ID
641
+	 * @param array $query_params
642
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
643
+	 *             tickets attached to datetime then FALSE is returned.
644
+	 * @throws EE_Error
645
+	 * @throws ReflectionException
646
+	 */
647
+	public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = [])
648
+	{
649
+		$datetime = $this->get_one_by_ID($DTT_ID);
650
+		if ($datetime instanceof EE_Datetime) {
651
+			return $datetime->tickets_remaining($query_params);
652
+		}
653
+		return 0;
654
+	}
655
+
656
+
657
+	/**
658
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
659
+	 *
660
+	 * @param array $stati_to_include  If included you can restrict the statuses we return counts for by including the
661
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
662
+	 *                                 for all valid stati.
663
+	 * @param array $query_params      If included can be used to refine the conditions for returning the count (i.e.
664
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
665
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
666
+	 * @throws EE_Error
667
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
668
+	 *                                 EE_Datetime::expired
669
+	 */
670
+	public function get_datetime_counts_by_status(array $stati_to_include = [], array $query_params = [])
671
+	{
672
+		// only accept where conditions for this query.
673
+		$_where            = isset($query_params[0]) ? $query_params[0] : [];
674
+		$status_query_args = [
675
+			EE_Datetime::active   => array_merge(
676
+				$_where,
677
+				['DTT_EVT_start' => ['<', time()], 'DTT_EVT_end' => ['>', time()]]
678
+			),
679
+			EE_Datetime::upcoming => array_merge(
680
+				$_where,
681
+				['DTT_EVT_start' => ['>', time()]]
682
+			),
683
+			EE_Datetime::expired  => array_merge(
684
+				$_where,
685
+				['DTT_EVT_end' => ['<', time()]]
686
+			),
687
+		];
688
+		if (! empty($stati_to_include)) {
689
+			foreach (array_keys($status_query_args) as $status) {
690
+				if (! in_array($status, $stati_to_include, true)) {
691
+					unset($status_query_args[ $status ]);
692
+				}
693
+			}
694
+		}
695
+		// loop through and query counts for each stati.
696
+		$status_query_results = [];
697
+		foreach ($status_query_args as $status => $status_where_conditions) {
698
+			$status_query_results[ $status ] = EEM_Datetime::count(
699
+				[$status_where_conditions],
700
+				'DTT_ID',
701
+				true
702
+			);
703
+		}
704
+		return $status_query_results;
705
+	}
706
+
707
+
708
+	/**
709
+	 * Returns the specific count for a given Datetime status matching any given query_params.
710
+	 *
711
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
712
+	 * @param array  $query_params
713
+	 * @return int
714
+	 * @throws EE_Error
715
+	 */
716
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = [])
717
+	{
718
+		$count = $this->get_datetime_counts_by_status([$status], $query_params);
719
+		return ! empty($count[ $status ]) ? $count[ $status ] : 0;
720
+	}
721
+
722
+
723
+	/**
724
+	 * @return bool|int
725
+	 * @since   5.0.0.p
726
+	 */
727
+	private function prepModelForQuery()
728
+	{
729
+		$prev_data_prep_value = $this->get_assumption_concerning_values_already_prepared_by_model_object();
730
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
731
+		return $prev_data_prep_value;
732
+	}
733
+
734
+
735
+	/**
736
+	 * @param array    $query_params
737
+	 * @param bool|int $prev_data_prep_value
738
+	 * @return EE_Base_Class[]|EE_Datetime[]
739
+	 * @throws EE_Error
740
+	 * @since   5.0.0.p
741
+	 */
742
+	private function getDatetimesAndRestoreModel(array $query_params, $prev_data_prep_value)
743
+	{
744
+		$result = $this->get_all($query_params);
745
+		$this->assume_values_already_prepared_by_model_object($prev_data_prep_value);
746
+		return $result;
747
+	}
748
+
749
+
750
+	/**
751
+	 * @param array  $query_params
752
+	 * @param int    $limit
753
+	 * @param string $order_by
754
+	 * @param string $order
755
+	 * @return array
756
+	 * @since   5.0.0.p
757
+	 */
758
+	private function addDefaultQueryParams(array $query_params, $limit = 0, $order_by = 'DTT_EVT_start', $order = 'ASC')
759
+	{
760
+		$query_params = $this->addOrderByQueryParams($query_params, $order_by, $order);
761
+		$query_params = $this->addLimitQueryParams($query_params, $limit);
762
+		return $query_params;
763
+	}
764
+
765
+
766
+	/**
767
+	 * @param array  $query_params
768
+	 * @param string $default_where_conditions
769
+	 * @return array
770
+	 * @since   5.0.0.p
771
+	 */
772
+	private function addDefaultWhereConditions(
773
+		array $query_params,
774
+		$default_where_conditions = EEM_Base::default_where_conditions_none
775
+	) {
776
+		$query_params['default_where_conditions'] = $default_where_conditions;
777
+		return $query_params;
778
+	}
779
+
780
+
781
+	/**
782
+	 * @param array $where_params
783
+	 * @param bool  $include_deleted
784
+	 * @param bool  $include_expired
785
+	 * @return array
786
+	 * @since   5.0.0.p
787
+	 */
788
+	private function addDefaultWhereParams(
789
+		array $where_params,
790
+		bool $include_deleted = true,
791
+		bool $include_expired = true
792
+	) {
793
+		$where_params = $this->addExpiredWhereParams($where_params, $include_expired);
794
+		$where_params = $this->addDeletedWhereParams($where_params, $include_deleted);
795
+		return $where_params;
796
+	}
797
+
798
+
799
+	/**
800
+	 * @param array $where_params
801
+	 * @param bool  $include_deleted
802
+	 * @return array
803
+	 * @since   5.0.0.p
804
+	 */
805
+	private function addDeletedWhereParams(array $where_params, bool $include_deleted = true)
806
+	{
807
+		$deleted                     = $include_deleted ? [true, false] : [false];
808
+		$where_params['DTT_deleted'] = ['IN', $deleted];
809
+		return $where_params;
810
+	}
811
+
812
+
813
+	/**
814
+	 * @param array $where_params
815
+	 * @param bool  $include_expired
816
+	 * @return array
817
+	 * @since   5.0.0.p
818
+	 */
819
+	private function addExpiredWhereParams(array $where_params, bool $include_expired = true)
820
+	{
821
+		if (! $include_expired) {
822
+			$where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)];
823
+		}
824
+		return $where_params;
825
+	}
826
+
827
+
828
+	/**
829
+	 * @param array $query_params
830
+	 * @param int   $limit
831
+	 * @return array
832
+	 * @since   5.0.0.p
833
+	 */
834
+	private function addLimitQueryParams(array $query_params, $limit = 0)
835
+	{
836
+		if ($limit) {
837
+			$query_params['limit'] = $limit;
838
+		}
839
+		return $query_params;
840
+	}
841
+
842
+
843
+	/**
844
+	 * @param array  $query_params
845
+	 * @param string $order_by
846
+	 * @param string $order
847
+	 * @return array
848
+	 * @since   5.0.0.p
849
+	 */
850
+	private function addOrderByQueryParams(array $query_params, $order_by = 'DTT_EVT_start', $order = 'ASC')
851
+	{
852
+		$order                    = $order === 'ASC' ? 'ASC' : 'DESC';
853
+		$valid_order_columns      = ['DTT_ID', 'DTT_EVT_start', 'DTT_EVT_end', 'DTT_order'];
854
+		$order_by                 = in_array($order_by, $valid_order_columns, true) ? $order_by : 'DTT_EVT_start';
855
+		$query_params['order_by'] = [$order_by => $order];
856
+		return $query_params;
857
+	}
858 858
 }
Please login to merge, or discard this patch.
core/services/routing/Route.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
     private function loadDataNode()
252 252
     {
253 253
         $data_node_fqcn = $this->dataNodeClass();
254
-        if (! empty($data_node_fqcn)) {
254
+        if ( ! empty($data_node_fqcn)) {
255 255
             $data_node = $this->loader->getShared($data_node_fqcn);
256 256
             $this->setDataNode($data_node);
257 257
         }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      */
280 280
     private function verifyIsHandled($handled)
281 281
     {
282
-        if (! is_bool($handled)) {
282
+        if ( ! is_bool($handled)) {
283 283
             throw new DomainException(
284 284
                 esc_html__(
285 285
                     'Route::requestHandler() must return a boolean to indicate whether the request has been handled or not.',
Please login to merge, or discard this patch.
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -28,271 +28,271 @@
 block discarded – undo
28 28
  */
29 29
 abstract class Route implements RouteInterface, RequiresCapCheckInterface
30 30
 {
31
-    /**
32
-     * @var AssetManagerInterface $asset_manager
33
-     */
34
-    protected $asset_manager;
35
-
36
-    /**
37
-     * @var EE_Dependency_Map $dependency_map
38
-     */
39
-    protected $dependency_map;
40
-
41
-    /**
42
-     * @var JsonDataNode $data_node
43
-     */
44
-    protected $data_node;
45
-
46
-    /**
47
-     * @var LoaderInterface $loader
48
-     */
49
-    protected $loader;
50
-
51
-    /**
52
-     * @var RequestInterface $request
53
-     */
54
-    protected $request;
55
-
56
-    /**
57
-     * @var RouteMatchSpecificationInterface $specification
58
-     */
59
-    protected $specification;
60
-
61
-    /**
62
-     * @var boolean $handled
63
-     */
64
-    private $handled = false;
65
-
66
-    /**
67
-     * @var array $default_dependencies
68
-     */
69
-    protected static $default_dependencies = [
70
-        'EE_Dependency_Map'                           => EE_Dependency_Map::load_from_cache,
71
-        'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
72
-        'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
73
-    ];
74
-
75
-    /**
76
-     * @var array $full_dependencies
77
-     */
78
-    protected static $full_dependencies = [
79
-        'EE_Dependency_Map'                             => EE_Dependency_Map::load_from_cache,
80
-        'EventEspresso\core\services\loaders\Loader'    => EE_Dependency_Map::load_from_cache,
81
-        'EventEspresso\core\services\request\Request'   => EE_Dependency_Map::load_from_cache,
82
-        'EventEspresso\core\services\json\JsonDataNode' => EE_Dependency_Map::load_from_cache,
83
-        RouteMatchSpecificationInterface::class         => EE_Dependency_Map::load_from_cache,
84
-    ];
85
-
86
-
87
-    /**
88
-     * Route constructor.
89
-     *
90
-     * @param EE_Dependency_Map                     $dependency_map
91
-     * @param LoaderInterface                       $loader
92
-     * @param RequestInterface                      $request
93
-     * @param JsonDataNode|null                     $data_node
94
-     * @param RouteMatchSpecificationInterface|null $specification
95
-     */
96
-    public function __construct(
97
-        EE_Dependency_Map $dependency_map,
98
-        LoaderInterface $loader,
99
-        RequestInterface $request,
100
-        JsonDataNode $data_node = null,
101
-        RouteMatchSpecificationInterface $specification = null
102
-    ) {
103
-        $this->dependency_map = $dependency_map;
104
-        $this->data_node      = $data_node;
105
-        $this->loader         = $loader;
106
-        $this->request        = $request;
107
-        $this->setSpecification($specification);
108
-    }
109
-
110
-
111
-    /**
112
-     * @return void
113
-     */
114
-    abstract protected function registerDependencies();
115
-
116
-
117
-    /**
118
-     * implements logic required to run during request
119
-     *
120
-     * @return bool
121
-     */
122
-    abstract protected function requestHandler(): bool;
123
-
124
-
125
-    /**
126
-     * called just before matchesCurrentRequest()
127
-     * and allows Route to perform any setup required such as calling setSpecification()
128
-     *
129
-     * @return void
130
-     */
131
-    public function initialize()
132
-    {
133
-        // do nothing by default
134
-    }
135
-
136
-
137
-    /**
138
-     * returns true if the current request matches this route
139
-     * child classes can override and use Request directly to match route with request
140
-     * or supply a RouteMatchSpecification class and just use the below
141
-     *
142
-     * @return bool
143
-     */
144
-    public function matchesCurrentRequest(): bool
145
-    {
146
-        return $this->specification instanceof RouteMatchSpecificationInterface
147
-               && $this->specification->isMatchingRoute();
148
-    }
149
-
150
-
151
-    /**
152
-     * returns the FQCN for this route's JsonDataNode
153
-     *
154
-     * @return string
155
-     */
156
-    protected function dataNodeClass(): string
157
-    {
158
-        return '';
159
-    }
160
-
161
-
162
-    public function getCapCheck()
163
-    {
164
-        return new PublicCapabilities('', 'access Event Espresso route');
165
-    }
166
-
167
-
168
-    /**
169
-     * @return array
170
-     */
171
-    public static function getDefaultDependencies(): array
172
-    {
173
-        return self::$default_dependencies;
174
-    }
175
-
176
-
177
-    /**
178
-     * @return array
179
-     */
180
-    public static function getFullDependencies(): array
181
-    {
182
-        return self::$full_dependencies;
183
-    }
184
-
185
-
186
-    /**
187
-     * @param JsonDataNode|null $data_node
188
-     */
189
-    protected function setDataNode(JsonDataNode $data_node = null)
190
-    {
191
-        $this->data_node = $data_node;
192
-    }
193
-
194
-
195
-    /**
196
-     * @param RouteMatchSpecificationInterface|null $specification
197
-     */
198
-    protected function setSpecification(RouteMatchSpecificationInterface $specification = null)
199
-    {
200
-        $this->specification = $specification;
201
-    }
202
-
203
-
204
-    /**
205
-     * @return JsonDataNode
206
-     */
207
-    public function dataNode(): ?JsonDataNode
208
-    {
209
-        return $this->data_node;
210
-    }
211
-
212
-
213
-    /**
214
-     * runs route requestHandler() if
215
-     *      - route has not previously been handled
216
-     *      - route specification matches for current request
217
-     * sets route handled property based on results returned by requestHandler()
218
-     *
219
-     * @return bool
220
-     */
221
-    public function handleRequest(): bool
222
-    {
223
-        if ($this->isNotHandled()) {
224
-            $this->initialize();
225
-            if ($this->matchesCurrentRequest()) {
226
-                do_action('AHEE__EventEspresso_core_domain_entities_routes_handlers_Route__handleRequest', $this);
227
-                $this->registerDependencies();
228
-                $this->loadDataNode();
229
-                $this->verifyIsHandled($this->requestHandler());
230
-            }
231
-        }
232
-        return $this->handled;
233
-    }
234
-
235
-
236
-    /**
237
-     * @return bool
238
-     */
239
-    final public function isHandled(): bool
240
-    {
241
-        return $this->handled;
242
-    }
243
-
244
-
245
-    /**
246
-     * @return bool
247
-     */
248
-    final public function isNotHandled(): bool
249
-    {
250
-        return ! $this->handled;
251
-    }
252
-
253
-
254
-    /**
255
-     * @return void
256
-     */
257
-    private function loadDataNode()
258
-    {
259
-        $data_node_fqcn = $this->dataNodeClass();
260
-        if (! empty($data_node_fqcn)) {
261
-            $data_node = $this->loader->getShared($data_node_fqcn);
262
-            $this->setDataNode($data_node);
263
-        }
264
-    }
265
-
266
-
267
-    /**
268
-     * @param string $domain_fqcn
269
-     */
270
-    public function initializeBaristaForDomain(string $domain_fqcn)
271
-    {
272
-        if (apply_filters('FHEE__load_Barista', true)) {
273
-            /** @var BaristaFactory $factory */
274
-            $factory = $this->loader->getShared(BaristaFactory::class);
275
-            $barista = $factory->createFromDomainClass($domain_fqcn);
276
-            if ($barista instanceof BaristaInterface) {
277
-                $barista->initialize();
278
-            }
279
-        }
280
-    }
281
-
282
-
283
-    /**
284
-     * @var bool
285
-     */
286
-    private function verifyIsHandled($handled)
287
-    {
288
-        if (! is_bool($handled)) {
289
-            throw new DomainException(
290
-                esc_html__(
291
-                    'Route::requestHandler() must return a boolean to indicate whether the request has been handled or not.',
292
-                    'event_espresso'
293
-                )
294
-            );
295
-        }
296
-        $this->handled = filter_var($handled, FILTER_VALIDATE_BOOLEAN);
297
-    }
31
+	/**
32
+	 * @var AssetManagerInterface $asset_manager
33
+	 */
34
+	protected $asset_manager;
35
+
36
+	/**
37
+	 * @var EE_Dependency_Map $dependency_map
38
+	 */
39
+	protected $dependency_map;
40
+
41
+	/**
42
+	 * @var JsonDataNode $data_node
43
+	 */
44
+	protected $data_node;
45
+
46
+	/**
47
+	 * @var LoaderInterface $loader
48
+	 */
49
+	protected $loader;
50
+
51
+	/**
52
+	 * @var RequestInterface $request
53
+	 */
54
+	protected $request;
55
+
56
+	/**
57
+	 * @var RouteMatchSpecificationInterface $specification
58
+	 */
59
+	protected $specification;
60
+
61
+	/**
62
+	 * @var boolean $handled
63
+	 */
64
+	private $handled = false;
65
+
66
+	/**
67
+	 * @var array $default_dependencies
68
+	 */
69
+	protected static $default_dependencies = [
70
+		'EE_Dependency_Map'                           => EE_Dependency_Map::load_from_cache,
71
+		'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
72
+		'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
73
+	];
74
+
75
+	/**
76
+	 * @var array $full_dependencies
77
+	 */
78
+	protected static $full_dependencies = [
79
+		'EE_Dependency_Map'                             => EE_Dependency_Map::load_from_cache,
80
+		'EventEspresso\core\services\loaders\Loader'    => EE_Dependency_Map::load_from_cache,
81
+		'EventEspresso\core\services\request\Request'   => EE_Dependency_Map::load_from_cache,
82
+		'EventEspresso\core\services\json\JsonDataNode' => EE_Dependency_Map::load_from_cache,
83
+		RouteMatchSpecificationInterface::class         => EE_Dependency_Map::load_from_cache,
84
+	];
85
+
86
+
87
+	/**
88
+	 * Route constructor.
89
+	 *
90
+	 * @param EE_Dependency_Map                     $dependency_map
91
+	 * @param LoaderInterface                       $loader
92
+	 * @param RequestInterface                      $request
93
+	 * @param JsonDataNode|null                     $data_node
94
+	 * @param RouteMatchSpecificationInterface|null $specification
95
+	 */
96
+	public function __construct(
97
+		EE_Dependency_Map $dependency_map,
98
+		LoaderInterface $loader,
99
+		RequestInterface $request,
100
+		JsonDataNode $data_node = null,
101
+		RouteMatchSpecificationInterface $specification = null
102
+	) {
103
+		$this->dependency_map = $dependency_map;
104
+		$this->data_node      = $data_node;
105
+		$this->loader         = $loader;
106
+		$this->request        = $request;
107
+		$this->setSpecification($specification);
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return void
113
+	 */
114
+	abstract protected function registerDependencies();
115
+
116
+
117
+	/**
118
+	 * implements logic required to run during request
119
+	 *
120
+	 * @return bool
121
+	 */
122
+	abstract protected function requestHandler(): bool;
123
+
124
+
125
+	/**
126
+	 * called just before matchesCurrentRequest()
127
+	 * and allows Route to perform any setup required such as calling setSpecification()
128
+	 *
129
+	 * @return void
130
+	 */
131
+	public function initialize()
132
+	{
133
+		// do nothing by default
134
+	}
135
+
136
+
137
+	/**
138
+	 * returns true if the current request matches this route
139
+	 * child classes can override and use Request directly to match route with request
140
+	 * or supply a RouteMatchSpecification class and just use the below
141
+	 *
142
+	 * @return bool
143
+	 */
144
+	public function matchesCurrentRequest(): bool
145
+	{
146
+		return $this->specification instanceof RouteMatchSpecificationInterface
147
+			   && $this->specification->isMatchingRoute();
148
+	}
149
+
150
+
151
+	/**
152
+	 * returns the FQCN for this route's JsonDataNode
153
+	 *
154
+	 * @return string
155
+	 */
156
+	protected function dataNodeClass(): string
157
+	{
158
+		return '';
159
+	}
160
+
161
+
162
+	public function getCapCheck()
163
+	{
164
+		return new PublicCapabilities('', 'access Event Espresso route');
165
+	}
166
+
167
+
168
+	/**
169
+	 * @return array
170
+	 */
171
+	public static function getDefaultDependencies(): array
172
+	{
173
+		return self::$default_dependencies;
174
+	}
175
+
176
+
177
+	/**
178
+	 * @return array
179
+	 */
180
+	public static function getFullDependencies(): array
181
+	{
182
+		return self::$full_dependencies;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @param JsonDataNode|null $data_node
188
+	 */
189
+	protected function setDataNode(JsonDataNode $data_node = null)
190
+	{
191
+		$this->data_node = $data_node;
192
+	}
193
+
194
+
195
+	/**
196
+	 * @param RouteMatchSpecificationInterface|null $specification
197
+	 */
198
+	protected function setSpecification(RouteMatchSpecificationInterface $specification = null)
199
+	{
200
+		$this->specification = $specification;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @return JsonDataNode
206
+	 */
207
+	public function dataNode(): ?JsonDataNode
208
+	{
209
+		return $this->data_node;
210
+	}
211
+
212
+
213
+	/**
214
+	 * runs route requestHandler() if
215
+	 *      - route has not previously been handled
216
+	 *      - route specification matches for current request
217
+	 * sets route handled property based on results returned by requestHandler()
218
+	 *
219
+	 * @return bool
220
+	 */
221
+	public function handleRequest(): bool
222
+	{
223
+		if ($this->isNotHandled()) {
224
+			$this->initialize();
225
+			if ($this->matchesCurrentRequest()) {
226
+				do_action('AHEE__EventEspresso_core_domain_entities_routes_handlers_Route__handleRequest', $this);
227
+				$this->registerDependencies();
228
+				$this->loadDataNode();
229
+				$this->verifyIsHandled($this->requestHandler());
230
+			}
231
+		}
232
+		return $this->handled;
233
+	}
234
+
235
+
236
+	/**
237
+	 * @return bool
238
+	 */
239
+	final public function isHandled(): bool
240
+	{
241
+		return $this->handled;
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return bool
247
+	 */
248
+	final public function isNotHandled(): bool
249
+	{
250
+		return ! $this->handled;
251
+	}
252
+
253
+
254
+	/**
255
+	 * @return void
256
+	 */
257
+	private function loadDataNode()
258
+	{
259
+		$data_node_fqcn = $this->dataNodeClass();
260
+		if (! empty($data_node_fqcn)) {
261
+			$data_node = $this->loader->getShared($data_node_fqcn);
262
+			$this->setDataNode($data_node);
263
+		}
264
+	}
265
+
266
+
267
+	/**
268
+	 * @param string $domain_fqcn
269
+	 */
270
+	public function initializeBaristaForDomain(string $domain_fqcn)
271
+	{
272
+		if (apply_filters('FHEE__load_Barista', true)) {
273
+			/** @var BaristaFactory $factory */
274
+			$factory = $this->loader->getShared(BaristaFactory::class);
275
+			$barista = $factory->createFromDomainClass($domain_fqcn);
276
+			if ($barista instanceof BaristaInterface) {
277
+				$barista->initialize();
278
+			}
279
+		}
280
+	}
281
+
282
+
283
+	/**
284
+	 * @var bool
285
+	 */
286
+	private function verifyIsHandled($handled)
287
+	{
288
+		if (! is_bool($handled)) {
289
+			throw new DomainException(
290
+				esc_html__(
291
+					'Route::requestHandler() must return a boolean to indicate whether the request has been handled or not.',
292
+					'event_espresso'
293
+				)
294
+			);
295
+		}
296
+		$this->handled = filter_var($handled, FILTER_VALIDATE_BOOLEAN);
297
+	}
298 298
 }
Please login to merge, or discard this patch.
core/services/addon/AddonManager.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     {
81 81
         // set autoloaders for all of the classes implementing the legacy EEI_Plugin_API
82 82
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
83
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
83
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
84 84
     }
85 85
 
86 86
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     private function registerAddon(AddonApiVersion $addon)
121 121
     {
122 122
         // first register addon namespace so that FQCNs resolve correctly
123
-        $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()) . '/src/');
123
+        $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()).'/src/');
124 124
         // then allow add-on to perform any other setup that relied on PSR4 autoloading
125 125
         $addon->initialize();
126 126
         // now register each addon based on it's API version
Please login to merge, or discard this patch.
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -23,95 +23,95 @@
 block discarded – undo
23 23
  */
24 24
 class AddonManager
25 25
 {
26
-    private AddonCollection          $addons;
26
+	private AddonCollection          $addons;
27 27
 
28
-    private IncompatibleAddonHandler $incompatible_addon_handler;
28
+	private IncompatibleAddonHandler $incompatible_addon_handler;
29 29
 
30
-    private Psr4Autoloader           $psr4_loader;
30
+	private Psr4Autoloader           $psr4_loader;
31 31
 
32
-    private RegisterV1Addon          $register_v1_addon;
32
+	private RegisterV1Addon          $register_v1_addon;
33 33
 
34
-    private ThirdPartyPluginHandler  $third_party_plugin_handler;
34
+	private ThirdPartyPluginHandler  $third_party_plugin_handler;
35 35
 
36 36
 
37
-    /**
38
-     * AddonManager constructor.
39
-     *
40
-     * @param AddonCollection          $addons
41
-     * @param Psr4Autoloader           $psr4_loader
42
-     * @param RegisterV1Addon          $register_v1_addon
43
-     * @param IncompatibleAddonHandler $incompatible_addon_handler
44
-     * @param ThirdPartyPluginHandler  $third_party_plugin_handler
45
-     */
46
-    public function __construct(
47
-        AddonCollection $addons,
48
-        Psr4Autoloader $psr4_loader,
49
-        RegisterV1Addon $register_v1_addon,
50
-        IncompatibleAddonHandler $incompatible_addon_handler,
51
-        ThirdPartyPluginHandler $third_party_plugin_handler
52
-    ) {
53
-        $this->addons                     = $addons;
54
-        $this->psr4_loader                = $psr4_loader;
55
-        $this->register_v1_addon          = $register_v1_addon;
56
-        $this->incompatible_addon_handler = $incompatible_addon_handler;
57
-        $this->third_party_plugin_handler = $third_party_plugin_handler;
58
-    }
37
+	/**
38
+	 * AddonManager constructor.
39
+	 *
40
+	 * @param AddonCollection          $addons
41
+	 * @param Psr4Autoloader           $psr4_loader
42
+	 * @param RegisterV1Addon          $register_v1_addon
43
+	 * @param IncompatibleAddonHandler $incompatible_addon_handler
44
+	 * @param ThirdPartyPluginHandler  $third_party_plugin_handler
45
+	 */
46
+	public function __construct(
47
+		AddonCollection $addons,
48
+		Psr4Autoloader $psr4_loader,
49
+		RegisterV1Addon $register_v1_addon,
50
+		IncompatibleAddonHandler $incompatible_addon_handler,
51
+		ThirdPartyPluginHandler $third_party_plugin_handler
52
+	) {
53
+		$this->addons                     = $addons;
54
+		$this->psr4_loader                = $psr4_loader;
55
+		$this->register_v1_addon          = $register_v1_addon;
56
+		$this->incompatible_addon_handler = $incompatible_addon_handler;
57
+		$this->third_party_plugin_handler = $third_party_plugin_handler;
58
+	}
59 59
 
60 60
 
61
-    /**
62
-     * @throws Exception
63
-     */
64
-    public function initialize()
65
-    {
66
-        // set autoloaders for all of the classes implementing the legacy EEI_Plugin_API
67
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
68
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
69
-    }
61
+	/**
62
+	 * @throws Exception
63
+	 */
64
+	public function initialize()
65
+	{
66
+		// set autoloaders for all of the classes implementing the legacy EEI_Plugin_API
67
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
68
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * @throws Exception
74
-     * @throws Throwable
75
-     */
76
-    public function loadAddons()
77
-    {
78
-        try {
79
-            $this->incompatible_addon_handler->deactivateIncompatibleAddons();
80
-            // legacy add-on API
81
-            do_action('AHEE__EE_System__load_espresso_addons');
82
-            // new add-on API that uses versioning
83
-            do_action(
84
-                'AHEE__EventEspresso_core_services_addon_AddonManager__initialize__addons',
85
-                $this->addons,
86
-                espresso_version()
87
-            );
88
-            // addons are responsible for loading their AddonApiVersion into the AddonCollection
89
-            foreach ($this->addons as $addon) {
90
-                if ($addon instanceof AddonApiVersion) {
91
-                    $this->registerAddon($addon);
92
-                }
93
-            }
94
-            $this->third_party_plugin_handler->loadPlugins();
95
-            do_action('AHEE__EE_System__load_espresso_addons__complete');
96
-        } catch (Exception $exception) {
97
-            new ExceptionStackTraceDisplay($exception);
98
-        }
99
-    }
72
+	/**
73
+	 * @throws Exception
74
+	 * @throws Throwable
75
+	 */
76
+	public function loadAddons()
77
+	{
78
+		try {
79
+			$this->incompatible_addon_handler->deactivateIncompatibleAddons();
80
+			// legacy add-on API
81
+			do_action('AHEE__EE_System__load_espresso_addons');
82
+			// new add-on API that uses versioning
83
+			do_action(
84
+				'AHEE__EventEspresso_core_services_addon_AddonManager__initialize__addons',
85
+				$this->addons,
86
+				espresso_version()
87
+			);
88
+			// addons are responsible for loading their AddonApiVersion into the AddonCollection
89
+			foreach ($this->addons as $addon) {
90
+				if ($addon instanceof AddonApiVersion) {
91
+					$this->registerAddon($addon);
92
+				}
93
+			}
94
+			$this->third_party_plugin_handler->loadPlugins();
95
+			do_action('AHEE__EE_System__load_espresso_addons__complete');
96
+		} catch (Exception $exception) {
97
+			new ExceptionStackTraceDisplay($exception);
98
+		}
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * @param AddonApiVersion $addon
104
-     * @throws EE_Error
105
-     */
106
-    private function registerAddon(AddonApiVersion $addon)
107
-    {
108
-        // first register addon namespace so that FQCNs resolve correctly
109
-        $this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()) . '/src/');
110
-        // then allow add-on to perform any other setup that relied on PSR4 autoloading
111
-        $addon->initialize();
112
-        // now register each addon based on it's API version
113
-        if ($addon instanceof AddonApiV1) {
114
-            $this->register_v1_addon->register($addon);
115
-        }
116
-    }
102
+	/**
103
+	 * @param AddonApiVersion $addon
104
+	 * @throws EE_Error
105
+	 */
106
+	private function registerAddon(AddonApiVersion $addon)
107
+	{
108
+		// first register addon namespace so that FQCNs resolve correctly
109
+		$this->psr4_loader->addNamespace($addon->getNamespace(), dirname($addon->mainFile()) . '/src/');
110
+		// then allow add-on to perform any other setup that relied on PSR4 autoloading
111
+		$addon->initialize();
112
+		// now register each addon based on it's API version
113
+		if ($addon instanceof AddonApiV1) {
114
+			$this->register_v1_addon->register($addon);
115
+		}
116
+	}
117 117
 }
Please login to merge, or discard this patch.
core/services/addon/api/IncompatibleAddonHandler.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
         string $load_callback,
44 44
         string $plugin_file_constant
45 45
     ) {
46
-        if (! defined($version_constant)) {
46
+        if ( ! defined($version_constant)) {
47 47
             return;
48 48
         }
49 49
         $addon_version = constant($version_constant);
50 50
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
51 51
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
52
-            if (! function_exists('deactivate_plugins')) {
53
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
52
+            if ( ! function_exists('deactivate_plugins')) {
53
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
54 54
             }
55 55
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
56 56
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
                     $min_version_required
65 65
                 ),
66 66
                 __FILE__,
67
-                __FUNCTION__ . "({$addon_name})",
67
+                __FUNCTION__."({$addon_name})",
68 68
                 __LINE__
69 69
             );
70 70
             EE_Error::get_notices(false, true);
Please login to merge, or discard this patch.
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -6,80 +6,80 @@
 block discarded – undo
6 6
 
7 7
 class IncompatibleAddonHandler
8 8
 {
9
-    /**
10
-     * @return void
11
-     */
12
-    public function deactivateIncompatibleAddons()
13
-    {
14
-        static $done = false;
15
-        if ($done) {
16
-            return;
17
-        }
18
-        $this->deactivateIncompatibleAddon(
19
-            'Wait Lists',
20
-            'EE_WAIT_LISTS_VERSION',
21
-            '1.0.0.beta.074',
22
-            'load_espresso_wait_lists',
23
-            'EE_WAIT_LISTS_PLUGIN_FILE'
24
-        );
25
-        $this->deactivateIncompatibleAddon(
26
-            'Automated Upcoming Event Notifications',
27
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
28
-            '1.0.0.beta.091',
29
-            'load_espresso_automated_upcoming_event_notification',
30
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
31
-        );
32
-        // $this->deactivateIncompatibleAddon(
33
-        //     'WP Users Integration',
34
-        //     'EE_WPUSERS_VERSION',
35
-        //     '2.1.0.rc.003',
36
-        //     'load_ee_core_wpusers',
37
-        //     'EE_WPUSERS_PLUGIN_FILE'
38
-        // );
39
-        $done = true;
40
-    }
9
+	/**
10
+	 * @return void
11
+	 */
12
+	public function deactivateIncompatibleAddons()
13
+	{
14
+		static $done = false;
15
+		if ($done) {
16
+			return;
17
+		}
18
+		$this->deactivateIncompatibleAddon(
19
+			'Wait Lists',
20
+			'EE_WAIT_LISTS_VERSION',
21
+			'1.0.0.beta.074',
22
+			'load_espresso_wait_lists',
23
+			'EE_WAIT_LISTS_PLUGIN_FILE'
24
+		);
25
+		$this->deactivateIncompatibleAddon(
26
+			'Automated Upcoming Event Notifications',
27
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
28
+			'1.0.0.beta.091',
29
+			'load_espresso_automated_upcoming_event_notification',
30
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
31
+		);
32
+		// $this->deactivateIncompatibleAddon(
33
+		//     'WP Users Integration',
34
+		//     'EE_WPUSERS_VERSION',
35
+		//     '2.1.0.rc.003',
36
+		//     'load_ee_core_wpusers',
37
+		//     'EE_WPUSERS_PLUGIN_FILE'
38
+		// );
39
+		$done = true;
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * @param string $addon_name
45
-     * @param string $version_constant
46
-     * @param string $min_version_required
47
-     * @param string $load_callback
48
-     * @param string $plugin_file_constant
49
-     * @return void
50
-     */
51
-    private function deactivateIncompatibleAddon(
52
-        string $addon_name,
53
-        string $version_constant,
54
-        string $min_version_required,
55
-        string $load_callback,
56
-        string $plugin_file_constant
57
-    ) {
58
-        if (! defined($version_constant)) {
59
-            return;
60
-        }
61
-        $addon_version = constant($version_constant);
62
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
63
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
64
-            if (! function_exists('deactivate_plugins')) {
65
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
66
-            }
67
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
68
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
69
-            EE_Error::add_error(
70
-                sprintf(
71
-                    esc_html__(
72
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
73
-                        'event_espresso'
74
-                    ),
75
-                    $addon_name,
76
-                    $min_version_required
77
-                ),
78
-                __FILE__,
79
-                __FUNCTION__ . "({$addon_name})",
80
-                __LINE__
81
-            );
82
-            EE_Error::get_notices(false, true);
83
-        }
84
-    }
43
+	/**
44
+	 * @param string $addon_name
45
+	 * @param string $version_constant
46
+	 * @param string $min_version_required
47
+	 * @param string $load_callback
48
+	 * @param string $plugin_file_constant
49
+	 * @return void
50
+	 */
51
+	private function deactivateIncompatibleAddon(
52
+		string $addon_name,
53
+		string $version_constant,
54
+		string $min_version_required,
55
+		string $load_callback,
56
+		string $plugin_file_constant
57
+	) {
58
+		if (! defined($version_constant)) {
59
+			return;
60
+		}
61
+		$addon_version = constant($version_constant);
62
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
63
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
64
+			if (! function_exists('deactivate_plugins')) {
65
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
66
+			}
67
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
68
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
69
+			EE_Error::add_error(
70
+				sprintf(
71
+					esc_html__(
72
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
73
+						'event_espresso'
74
+					),
75
+					$addon_name,
76
+					$min_version_required
77
+				),
78
+				__FILE__,
79
+				__FUNCTION__ . "({$addon_name})",
80
+				__LINE__
81
+			);
82
+			EE_Error::get_notices(false, true);
83
+		}
84
+	}
85 85
 }
Please login to merge, or discard this patch.
core/services/addon/api/AddonApiVersion.php 2 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -19,286 +19,286 @@
 block discarded – undo
19 19
  */
20 20
 abstract class AddonApiVersion
21 21
 {
22
-    const V1 = 1;
23
-
24
-    /**
25
-     * @var int one of the API_VERSION_* constants from above
26
-     */
27
-    private $api_version;
28
-
29
-    /**
30
-     * @var DomainInterface
31
-     */
32
-    private $domain;
33
-
34
-    /**
35
-     * @var Version minimum version of EE core that the add-on will work with
36
-     */
37
-    private $min_core_version;
38
-
39
-    /**
40
-     * @var Version minimum version of WP core that the add-on will work with
41
-     */
42
-    private $min_wp_version;
43
-
44
-    /**
45
-     * @var string  PascalCase identifier for the add-on.
46
-     *              IMPORTANT! there must be a class of the same name in the root of the add-ons /src/domain/ folder
47
-     */
48
-    private $name;
49
-
50
-    /**
51
-     * @var string
52
-     */
53
-    private $addon_namespace;
54
-
55
-    /**
56
-     * @var FilePath
57
-     */
58
-    private $main_file;
59
-
60
-    /**
61
-     * @var string
62
-     */
63
-    private $slug;
64
-
65
-    /**
66
-     * @var Version the current add-on version
67
-     */
68
-    private $version;
69
-
70
-
71
-    /**
72
-     * Bootstrap constructor.
73
-     *
74
-     * @param string $slug
75
-     * @param string $name
76
-     * @param string $namespace
77
-     * @param string $version
78
-     * @param string $min_core_version
79
-     * @param string $main_file
80
-     * @param int    $api_version
81
-     */
82
-    protected function __construct(
83
-        string $slug,
84
-        string $name,
85
-        string $namespace,
86
-        string $version,
87
-        string $min_core_version,
88
-        string $main_file,
89
-        int $api_version
90
-    ) {
91
-        $this->setSlug($slug);
92
-        $this->setName($name);
93
-        $this->setNamespace($namespace);
94
-        $this->setMinCoreVersion($min_core_version);
95
-        $this->setMainFile($main_file);
96
-        $this->setVersion($version);
97
-        $this->setApiVersion($api_version);
98
-    }
99
-
100
-
101
-    /**
102
-     * @return void
103
-     */
104
-    public function initialize(): void
105
-    {
106
-        $this->domain = DomainFactory::create(
107
-            "{$this->addon_namespace}\\domain\\Domain",
108
-            $this->main_file,
109
-            $this->version
110
-        );
111
-    }
112
-
113
-
114
-    /**
115
-     * @return int[]
116
-     */
117
-    private function validApiVersions(): array
118
-    {
119
-        return [
120
-            AddonApiVersion::V1,
121
-        ];
122
-    }
123
-
124
-
125
-    /**
126
-     * @param int $api_version
127
-     */
128
-    private function setApiVersion(int $api_version): void
129
-    {
130
-        if (! in_array($api_version, $this->validApiVersions())) {
131
-            throw new DomainException(
132
-                esc_html__(
133
-                    'Invalid Add-on API Version! Please use one of the EventEspresso\core\domain\entities\addon\Bootstrap class constants',
134
-                    'event_espresso'
135
-                )
136
-            );
137
-        }
138
-        $this->api_version = $api_version;
139
-    }
140
-
141
-
142
-    /**
143
-     * @param string $main_file
144
-     */
145
-    public function setMainFile(string $main_file): void
146
-    {
147
-        $this->main_file = new FilePath($main_file);
148
-    }
149
-
150
-
151
-    /**
152
-     * @param string $min_core_version
153
-     */
154
-    private function setMinCoreVersion(string $min_core_version): void
155
-    {
156
-        $this->min_core_version = Version::fromString($min_core_version);
157
-    }
158
-
159
-
160
-    /**
161
-     * @param string $name
162
-     */
163
-    public function setName(string $name): void
164
-    {
165
-        $this->name = $name;
166
-    }
167
-
168
-
169
-    /**
170
-     * @param string $namespace
171
-     */
172
-    private function setNamespace(string $namespace): void
173
-    {
174
-        $this->addon_namespace = $namespace;
175
-    }
176
-
177
-
178
-    /**
179
-     * @param string $slug
180
-     */
181
-    private function setSlug(string $slug): void
182
-    {
183
-        $valid_slug = sanitize_key($slug);
184
-        if ($slug !== $valid_slug) {
185
-            throw new DomainException(
186
-                esc_html__(
187
-                    'Invalid Add-on "slug"! Please ensure that slug only uses lowercase characters and dashes.',
188
-                    'event_espresso'
189
-                )
190
-            );
191
-        }
192
-        $this->slug = $valid_slug;
193
-    }
194
-
195
-
196
-    /**
197
-     * @param string $version
198
-     */
199
-    public function setVersion(string $version): void
200
-    {
201
-        $this->version = Version::fromString($version);
202
-    }
203
-
204
-
205
-    /**
206
-     * @return int
207
-     */
208
-    public function apiVersion(): int
209
-    {
210
-        return $this->api_version;
211
-    }
212
-
213
-
214
-    /**
215
-     * @return DomainInterface
216
-     */
217
-    public function domain(): DomainInterface
218
-    {
219
-        return $this->domain;
220
-    }
221
-
222
-
223
-    /**
224
-     * @return Version|null
225
-     */
226
-    public function minCoreVersion(): ?Version
227
-    {
228
-        return $this->min_core_version;
229
-    }
230
-
231
-
232
-    /**
233
-     * @return Version|null
234
-     */
235
-    public function minWpVersion(): ?Version
236
-    {
237
-        return $this->min_wp_version;
238
-    }
239
-
240
-
241
-    /**
242
-     * @param string $min_wp_version
243
-     */
244
-    public function setMinWpVersion(string $min_wp_version = EE_MIN_WP_VER_REQUIRED): void
245
-    {
246
-        $this->min_wp_version = Version::fromString($min_wp_version);
247
-    }
248
-
249
-
250
-    /**
251
-     * @return string
252
-     */
253
-    public function name(): string
254
-    {
255
-        return $this->name;
256
-    }
257
-
258
-
259
-    /**
260
-     * FQCN for the domain's EE_Addon class
261
-     *
262
-     * @return string
263
-     */
264
-    public function fqcn(): string
265
-    {
266
-        return "{$this->addon_namespace}\\domain\\{$this->name}";
267
-    }
268
-
269
-
270
-    /**
271
-     * @return string
272
-     */
273
-    public function getNamespace(): string
274
-    {
275
-        return $this->addon_namespace;
276
-    }
277
-
278
-
279
-    /**
280
-     * @return FilePath
281
-     */
282
-    public function mainFile(): FilePath
283
-    {
284
-        return $this->main_file;
285
-    }
286
-
287
-
288
-    /**
289
-     * @return string
290
-     */
291
-    public function slug(): string
292
-    {
293
-        return $this->slug;
294
-    }
295
-
296
-
297
-    /**
298
-     * @return Version
299
-     */
300
-    public function version(): Version
301
-    {
302
-        return $this->version;
303
-    }
22
+	const V1 = 1;
23
+
24
+	/**
25
+	 * @var int one of the API_VERSION_* constants from above
26
+	 */
27
+	private $api_version;
28
+
29
+	/**
30
+	 * @var DomainInterface
31
+	 */
32
+	private $domain;
33
+
34
+	/**
35
+	 * @var Version minimum version of EE core that the add-on will work with
36
+	 */
37
+	private $min_core_version;
38
+
39
+	/**
40
+	 * @var Version minimum version of WP core that the add-on will work with
41
+	 */
42
+	private $min_wp_version;
43
+
44
+	/**
45
+	 * @var string  PascalCase identifier for the add-on.
46
+	 *              IMPORTANT! there must be a class of the same name in the root of the add-ons /src/domain/ folder
47
+	 */
48
+	private $name;
49
+
50
+	/**
51
+	 * @var string
52
+	 */
53
+	private $addon_namespace;
54
+
55
+	/**
56
+	 * @var FilePath
57
+	 */
58
+	private $main_file;
59
+
60
+	/**
61
+	 * @var string
62
+	 */
63
+	private $slug;
64
+
65
+	/**
66
+	 * @var Version the current add-on version
67
+	 */
68
+	private $version;
69
+
70
+
71
+	/**
72
+	 * Bootstrap constructor.
73
+	 *
74
+	 * @param string $slug
75
+	 * @param string $name
76
+	 * @param string $namespace
77
+	 * @param string $version
78
+	 * @param string $min_core_version
79
+	 * @param string $main_file
80
+	 * @param int    $api_version
81
+	 */
82
+	protected function __construct(
83
+		string $slug,
84
+		string $name,
85
+		string $namespace,
86
+		string $version,
87
+		string $min_core_version,
88
+		string $main_file,
89
+		int $api_version
90
+	) {
91
+		$this->setSlug($slug);
92
+		$this->setName($name);
93
+		$this->setNamespace($namespace);
94
+		$this->setMinCoreVersion($min_core_version);
95
+		$this->setMainFile($main_file);
96
+		$this->setVersion($version);
97
+		$this->setApiVersion($api_version);
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return void
103
+	 */
104
+	public function initialize(): void
105
+	{
106
+		$this->domain = DomainFactory::create(
107
+			"{$this->addon_namespace}\\domain\\Domain",
108
+			$this->main_file,
109
+			$this->version
110
+		);
111
+	}
112
+
113
+
114
+	/**
115
+	 * @return int[]
116
+	 */
117
+	private function validApiVersions(): array
118
+	{
119
+		return [
120
+			AddonApiVersion::V1,
121
+		];
122
+	}
123
+
124
+
125
+	/**
126
+	 * @param int $api_version
127
+	 */
128
+	private function setApiVersion(int $api_version): void
129
+	{
130
+		if (! in_array($api_version, $this->validApiVersions())) {
131
+			throw new DomainException(
132
+				esc_html__(
133
+					'Invalid Add-on API Version! Please use one of the EventEspresso\core\domain\entities\addon\Bootstrap class constants',
134
+					'event_espresso'
135
+				)
136
+			);
137
+		}
138
+		$this->api_version = $api_version;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param string $main_file
144
+	 */
145
+	public function setMainFile(string $main_file): void
146
+	{
147
+		$this->main_file = new FilePath($main_file);
148
+	}
149
+
150
+
151
+	/**
152
+	 * @param string $min_core_version
153
+	 */
154
+	private function setMinCoreVersion(string $min_core_version): void
155
+	{
156
+		$this->min_core_version = Version::fromString($min_core_version);
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param string $name
162
+	 */
163
+	public function setName(string $name): void
164
+	{
165
+		$this->name = $name;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param string $namespace
171
+	 */
172
+	private function setNamespace(string $namespace): void
173
+	{
174
+		$this->addon_namespace = $namespace;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @param string $slug
180
+	 */
181
+	private function setSlug(string $slug): void
182
+	{
183
+		$valid_slug = sanitize_key($slug);
184
+		if ($slug !== $valid_slug) {
185
+			throw new DomainException(
186
+				esc_html__(
187
+					'Invalid Add-on "slug"! Please ensure that slug only uses lowercase characters and dashes.',
188
+					'event_espresso'
189
+				)
190
+			);
191
+		}
192
+		$this->slug = $valid_slug;
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param string $version
198
+	 */
199
+	public function setVersion(string $version): void
200
+	{
201
+		$this->version = Version::fromString($version);
202
+	}
203
+
204
+
205
+	/**
206
+	 * @return int
207
+	 */
208
+	public function apiVersion(): int
209
+	{
210
+		return $this->api_version;
211
+	}
212
+
213
+
214
+	/**
215
+	 * @return DomainInterface
216
+	 */
217
+	public function domain(): DomainInterface
218
+	{
219
+		return $this->domain;
220
+	}
221
+
222
+
223
+	/**
224
+	 * @return Version|null
225
+	 */
226
+	public function minCoreVersion(): ?Version
227
+	{
228
+		return $this->min_core_version;
229
+	}
230
+
231
+
232
+	/**
233
+	 * @return Version|null
234
+	 */
235
+	public function minWpVersion(): ?Version
236
+	{
237
+		return $this->min_wp_version;
238
+	}
239
+
240
+
241
+	/**
242
+	 * @param string $min_wp_version
243
+	 */
244
+	public function setMinWpVersion(string $min_wp_version = EE_MIN_WP_VER_REQUIRED): void
245
+	{
246
+		$this->min_wp_version = Version::fromString($min_wp_version);
247
+	}
248
+
249
+
250
+	/**
251
+	 * @return string
252
+	 */
253
+	public function name(): string
254
+	{
255
+		return $this->name;
256
+	}
257
+
258
+
259
+	/**
260
+	 * FQCN for the domain's EE_Addon class
261
+	 *
262
+	 * @return string
263
+	 */
264
+	public function fqcn(): string
265
+	{
266
+		return "{$this->addon_namespace}\\domain\\{$this->name}";
267
+	}
268
+
269
+
270
+	/**
271
+	 * @return string
272
+	 */
273
+	public function getNamespace(): string
274
+	{
275
+		return $this->addon_namespace;
276
+	}
277
+
278
+
279
+	/**
280
+	 * @return FilePath
281
+	 */
282
+	public function mainFile(): FilePath
283
+	{
284
+		return $this->main_file;
285
+	}
286
+
287
+
288
+	/**
289
+	 * @return string
290
+	 */
291
+	public function slug(): string
292
+	{
293
+		return $this->slug;
294
+	}
295
+
296
+
297
+	/**
298
+	 * @return Version
299
+	 */
300
+	public function version(): Version
301
+	{
302
+		return $this->version;
303
+	}
304 304
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@
 block discarded – undo
127 127
      */
128 128
     private function setApiVersion(int $api_version): void
129 129
     {
130
-        if (! in_array($api_version, $this->validApiVersions())) {
130
+        if ( ! in_array($api_version, $this->validApiVersions())) {
131 131
             throw new DomainException(
132 132
                 esc_html__(
133 133
                     'Invalid Add-on API Version! Please use one of the EventEspresso\core\domain\entities\addon\Bootstrap class constants',
Please login to merge, or discard this patch.
core/services/addon/api/ThirdPartyPluginHandler.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
             && ! function_exists('json_basic_auth_handler')
43 43
             && ! function_exists('json_basic_auth_error')
44 44
         ) {
45
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
45
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth/basic-auth.php';
46 46
         }
47 47
     }
48 48
 }
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -7,43 +7,43 @@
 block discarded – undo
7 7
 class ThirdPartyPluginHandler
8 8
 {
9 9
 
10
-    /**
11
-     * @var RequestInterface $request
12
-     */
13
-    private $request;
14
-
15
-
16
-    /**
17
-     * ThirdPartyPluginHandler constructor.
18
-     *
19
-     * @param RequestInterface $request
20
-     */
21
-    public function __construct(RequestInterface $request)
22
-    {
23
-        $this->request = $request;
24
-    }
25
-
26
-
27
-    public function loadPlugins()
28
-    {
29
-        $this->wpApiBasicAuth();
30
-    }
31
-
32
-
33
-    private function wpApiBasicAuth()
34
-    {
35
-        // if the WP API basic auth plugin isn't already loaded, load it now.
36
-        // We want it for mobile apps. Just include the entire plugin
37
-        // also, don't load the basic auth when a plugin is getting activated, because
38
-        // it could be the basic auth plugin, and it doesn't check if its methods are already defined
39
-        // and causes a fatal error
40
-        if (
41
-            ($this->request->isWordPressApi() || $this->request->isApi())
42
-            && ! $this->request->isActivation()
43
-            && ! function_exists('json_basic_auth_handler')
44
-            && ! function_exists('json_basic_auth_error')
45
-        ) {
46
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
47
-        }
48
-    }
10
+	/**
11
+	 * @var RequestInterface $request
12
+	 */
13
+	private $request;
14
+
15
+
16
+	/**
17
+	 * ThirdPartyPluginHandler constructor.
18
+	 *
19
+	 * @param RequestInterface $request
20
+	 */
21
+	public function __construct(RequestInterface $request)
22
+	{
23
+		$this->request = $request;
24
+	}
25
+
26
+
27
+	public function loadPlugins()
28
+	{
29
+		$this->wpApiBasicAuth();
30
+	}
31
+
32
+
33
+	private function wpApiBasicAuth()
34
+	{
35
+		// if the WP API basic auth plugin isn't already loaded, load it now.
36
+		// We want it for mobile apps. Just include the entire plugin
37
+		// also, don't load the basic auth when a plugin is getting activated, because
38
+		// it could be the basic auth plugin, and it doesn't check if its methods are already defined
39
+		// and causes a fatal error
40
+		if (
41
+			($this->request->isWordPressApi() || $this->request->isApi())
42
+			&& ! $this->request->isActivation()
43
+			&& ! function_exists('json_basic_auth_handler')
44
+			&& ! function_exists('json_basic_auth_error')
45
+		) {
46
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
47
+		}
48
+	}
49 49
 }
Please login to merge, or discard this patch.
core/services/addon/api/v1/LegacyModelApi.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -5,95 +5,95 @@
 block discarded – undo
5 5
 class LegacyModelApi
6 6
 {
7 7
 
8
-    /**
9
-     * @var string path to EE_* entity classes
10
-     */
11
-    private $entity_classes;
12
-
13
-    /**
14
-     * @var string path to EEM_* entity model classes
15
-     */
16
-    private $entity_models;
17
-
18
-    /**
19
-     * @var string path to EEE_* entity class extensions
20
-     */
21
-    private $entity_class_extensions;
22
-
23
-    /**
24
-     * @var string path to EEME_* entity model class extensions
25
-     */
26
-    private $entity_model_extensions;
27
-
28
-
29
-    /**
30
-     * @return string
31
-     */
32
-    public function entityClasses(): string
33
-    {
34
-        return $this->entity_classes;
35
-    }
36
-
37
-
38
-    /**
39
-     * @param string $entity_classes
40
-     */
41
-    public function addEntityClasses(string $entity_classes): void
42
-    {
43
-        $this->entity_classes = $entity_classes;
44
-    }
45
-
46
-
47
-    /**
48
-     * @return string
49
-     */
50
-    public function entityModels(): string
51
-    {
52
-        return $this->entity_models;
53
-    }
54
-
55
-
56
-    /**
57
-     * @param string $entity_models
58
-     */
59
-    public function addEntityModels(string $entity_models): void
60
-    {
61
-        $this->entity_models = $entity_models;
62
-    }
63
-
64
-
65
-    /**
66
-     * @return string
67
-     */
68
-    public function entityClassExtensions(): string
69
-    {
70
-        return $this->entity_class_extensions;
71
-    }
72
-
73
-
74
-    /**
75
-     * @param string $entity_class_extensions
76
-     */
77
-    public function addEntityClassExtensions(string $entity_class_extensions): void
78
-    {
79
-        $this->entity_class_extensions = $entity_class_extensions;
80
-    }
81
-
82
-
83
-    /**
84
-     * @return string
85
-     */
86
-    public function entityModelExtensions(): string
87
-    {
88
-        return $this->entity_model_extensions;
89
-    }
90
-
91
-
92
-    /**
93
-     * @param string $entity_model_extensions
94
-     */
95
-    public function addEntityModelExtensions(string $entity_model_extensions): void
96
-    {
97
-        $this->entity_model_extensions = $entity_model_extensions;
98
-    }
8
+	/**
9
+	 * @var string path to EE_* entity classes
10
+	 */
11
+	private $entity_classes;
12
+
13
+	/**
14
+	 * @var string path to EEM_* entity model classes
15
+	 */
16
+	private $entity_models;
17
+
18
+	/**
19
+	 * @var string path to EEE_* entity class extensions
20
+	 */
21
+	private $entity_class_extensions;
22
+
23
+	/**
24
+	 * @var string path to EEME_* entity model class extensions
25
+	 */
26
+	private $entity_model_extensions;
27
+
28
+
29
+	/**
30
+	 * @return string
31
+	 */
32
+	public function entityClasses(): string
33
+	{
34
+		return $this->entity_classes;
35
+	}
36
+
37
+
38
+	/**
39
+	 * @param string $entity_classes
40
+	 */
41
+	public function addEntityClasses(string $entity_classes): void
42
+	{
43
+		$this->entity_classes = $entity_classes;
44
+	}
45
+
46
+
47
+	/**
48
+	 * @return string
49
+	 */
50
+	public function entityModels(): string
51
+	{
52
+		return $this->entity_models;
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param string $entity_models
58
+	 */
59
+	public function addEntityModels(string $entity_models): void
60
+	{
61
+		$this->entity_models = $entity_models;
62
+	}
63
+
64
+
65
+	/**
66
+	 * @return string
67
+	 */
68
+	public function entityClassExtensions(): string
69
+	{
70
+		return $this->entity_class_extensions;
71
+	}
72
+
73
+
74
+	/**
75
+	 * @param string $entity_class_extensions
76
+	 */
77
+	public function addEntityClassExtensions(string $entity_class_extensions): void
78
+	{
79
+		$this->entity_class_extensions = $entity_class_extensions;
80
+	}
81
+
82
+
83
+	/**
84
+	 * @return string
85
+	 */
86
+	public function entityModelExtensions(): string
87
+	{
88
+		return $this->entity_model_extensions;
89
+	}
90
+
91
+
92
+	/**
93
+	 * @param string $entity_model_extensions
94
+	 */
95
+	public function addEntityModelExtensions(string $entity_model_extensions): void
96
+	{
97
+		$this->entity_model_extensions = $entity_model_extensions;
98
+	}
99 99
 }
Please login to merge, or discard this patch.
core/services/addon/api/v1/RegisterAddon.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -8,26 +8,26 @@
 block discarded – undo
8 8
 
9 9
 class RegisterAddon
10 10
 {
11
-    /**
12
-     * @param AddonApiV1 $addon
13
-     * @throws EE_Error
14
-     */
15
-    public function register(AddonApiV1 $addon)
16
-    {
17
-        EE_Register_Addon::register(
18
-            $addon->fqcn(),
19
-            [
20
-                'version'               => $addon->version(),
21
-                'plugin_slug'           => $addon->slug(),
22
-                'min_core_version'      => $addon->minCoreVersion(),
23
-                'min_wp_version'        => $addon->minWpVersion(),
24
-                'main_file_path'        => $addon->mainFile(),
25
-                'dms_paths'             => [$addon->dataMigrationScripts()],
26
-                'class_paths'           => [$addon->entityClasses()],
27
-                'model_paths'           => [$addon->entityModels()],
28
-                'class_extension_paths' => [$addon->entityClassExtensions()],
29
-                'model_extension_paths' => [$addon->entityModelExtensions()],
30
-            ]
31
-        );
32
-    }
11
+	/**
12
+	 * @param AddonApiV1 $addon
13
+	 * @throws EE_Error
14
+	 */
15
+	public function register(AddonApiV1 $addon)
16
+	{
17
+		EE_Register_Addon::register(
18
+			$addon->fqcn(),
19
+			[
20
+				'version'               => $addon->version(),
21
+				'plugin_slug'           => $addon->slug(),
22
+				'min_core_version'      => $addon->minCoreVersion(),
23
+				'min_wp_version'        => $addon->minWpVersion(),
24
+				'main_file_path'        => $addon->mainFile(),
25
+				'dms_paths'             => [$addon->dataMigrationScripts()],
26
+				'class_paths'           => [$addon->entityClasses()],
27
+				'model_paths'           => [$addon->entityModels()],
28
+				'class_extension_paths' => [$addon->entityClassExtensions()],
29
+				'model_extension_paths' => [$addon->entityModelExtensions()],
30
+			]
31
+		);
32
+	}
33 33
 }
Please login to merge, or discard this patch.
core/services/addon/api/v1/AddonApi.php 1 patch
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -7,135 +7,135 @@
 block discarded – undo
7 7
 class AddonApi extends AddonApiVersion
8 8
 {
9 9
 
10
-    /**
11
-     * @var DataMigrationApi
12
-     */
13
-    private $data_migration_api;
14
-
15
-    /**
16
-     * @var LegacyModelApi
17
-     */
18
-    private $legacy_model_api;
19
-
20
-
21
-    /**
22
-     * Bootstrap constructor.
23
-     *
24
-     * @param string $slug
25
-     * @param string $name
26
-     * @param string $namespace
27
-     * @param string $version
28
-     * @param string $min_core_version
29
-     * @param string $main_file
30
-     */
31
-    public function __construct(
32
-        string $slug,
33
-        string $name,
34
-        string $namespace,
35
-        string $version,
36
-        string $min_core_version,
37
-        string $main_file
38
-    ) {
39
-        parent::__construct(
40
-            $slug,
41
-            $name,
42
-            $namespace,
43
-            $version,
44
-            $min_core_version,
45
-            $main_file,
46
-            AddonApiVersion::V1
47
-        );
48
-        $this->legacy_model_api = new LegacyModelApi();
49
-        $this->data_migration_api = new DataMigrationApi();
50
-    }
51
-
52
-
53
-    /**
54
-     * @return string
55
-     */
56
-    public function dataMigrationScripts(): string
57
-    {
58
-        return $this->data_migration_api->dataMigrationScripts();
59
-    }
60
-
61
-
62
-    /**
63
-     * @param string $data_migration_scripts
64
-     */
65
-    public function addDataMigrationScripts(string $data_migration_scripts): void
66
-    {
67
-        $this->data_migration_api->addDataMigrationScripts($data_migration_scripts);
68
-    }
69
-
70
-
71
-    /**
72
-     * @return string
73
-     */
74
-    public function entityClasses(): string
75
-    {
76
-        return $this->legacy_model_api->entityClasses();
77
-    }
78
-
79
-
80
-    /**
81
-     * @param string $entity_classes
82
-     */
83
-    public function addEntityClasses(string $entity_classes): void
84
-    {
85
-        $this->legacy_model_api->addEntityClasses($entity_classes);
86
-    }
87
-
88
-
89
-    /**
90
-     * @return string
91
-     */
92
-    public function entityModels(): string
93
-    {
94
-        return $this->legacy_model_api->entityModels();
95
-    }
96
-
97
-
98
-    /**
99
-     * @param string $entity_models
100
-     */
101
-    public function addEntityModels(string $entity_models): void
102
-    {
103
-        $this->legacy_model_api->addEntityModels($entity_models);
104
-    }
105
-
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function entityClassExtensions(): string
111
-    {
112
-        return $this->legacy_model_api->entityClassExtensions();
113
-    }
114
-
115
-
116
-    /**
117
-     * @param string $entity_class_extensions
118
-     */
119
-    public function addEntityClassExtensions(string $entity_class_extensions): void
120
-    {
121
-        $this->legacy_model_api->addEntityClassExtensions($entity_class_extensions);
122
-    }
123
-
124
-
125
-    /**
126
-     * @return string
127
-     */
128
-    public function entityModelExtensions(): string
129
-    {
130
-        return $this->legacy_model_api->entityModelExtensions();
131
-    }
132
-
133
-
134
-    /**
135
-     * @param string $entity_model_extensions
136
-     */
137
-    public function addEntityModelExtensions(string $entity_model_extensions): void
138
-    {
139
-        $this->legacy_model_api->addEntityModelExtensions($entity_model_extensions);
140
-    }
10
+	/**
11
+	 * @var DataMigrationApi
12
+	 */
13
+	private $data_migration_api;
14
+
15
+	/**
16
+	 * @var LegacyModelApi
17
+	 */
18
+	private $legacy_model_api;
19
+
20
+
21
+	/**
22
+	 * Bootstrap constructor.
23
+	 *
24
+	 * @param string $slug
25
+	 * @param string $name
26
+	 * @param string $namespace
27
+	 * @param string $version
28
+	 * @param string $min_core_version
29
+	 * @param string $main_file
30
+	 */
31
+	public function __construct(
32
+		string $slug,
33
+		string $name,
34
+		string $namespace,
35
+		string $version,
36
+		string $min_core_version,
37
+		string $main_file
38
+	) {
39
+		parent::__construct(
40
+			$slug,
41
+			$name,
42
+			$namespace,
43
+			$version,
44
+			$min_core_version,
45
+			$main_file,
46
+			AddonApiVersion::V1
47
+		);
48
+		$this->legacy_model_api = new LegacyModelApi();
49
+		$this->data_migration_api = new DataMigrationApi();
50
+	}
51
+
52
+
53
+	/**
54
+	 * @return string
55
+	 */
56
+	public function dataMigrationScripts(): string
57
+	{
58
+		return $this->data_migration_api->dataMigrationScripts();
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param string $data_migration_scripts
64
+	 */
65
+	public function addDataMigrationScripts(string $data_migration_scripts): void
66
+	{
67
+		$this->data_migration_api->addDataMigrationScripts($data_migration_scripts);
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return string
73
+	 */
74
+	public function entityClasses(): string
75
+	{
76
+		return $this->legacy_model_api->entityClasses();
77
+	}
78
+
79
+
80
+	/**
81
+	 * @param string $entity_classes
82
+	 */
83
+	public function addEntityClasses(string $entity_classes): void
84
+	{
85
+		$this->legacy_model_api->addEntityClasses($entity_classes);
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return string
91
+	 */
92
+	public function entityModels(): string
93
+	{
94
+		return $this->legacy_model_api->entityModels();
95
+	}
96
+
97
+
98
+	/**
99
+	 * @param string $entity_models
100
+	 */
101
+	public function addEntityModels(string $entity_models): void
102
+	{
103
+		$this->legacy_model_api->addEntityModels($entity_models);
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function entityClassExtensions(): string
111
+	{
112
+		return $this->legacy_model_api->entityClassExtensions();
113
+	}
114
+
115
+
116
+	/**
117
+	 * @param string $entity_class_extensions
118
+	 */
119
+	public function addEntityClassExtensions(string $entity_class_extensions): void
120
+	{
121
+		$this->legacy_model_api->addEntityClassExtensions($entity_class_extensions);
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return string
127
+	 */
128
+	public function entityModelExtensions(): string
129
+	{
130
+		return $this->legacy_model_api->entityModelExtensions();
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param string $entity_model_extensions
136
+	 */
137
+	public function addEntityModelExtensions(string $entity_model_extensions): void
138
+	{
139
+		$this->legacy_model_api->addEntityModelExtensions($entity_model_extensions);
140
+	}
141 141
 }
Please login to merge, or discard this patch.