Completed
Branch master (44537d)
by
unknown
14:30 queued 10:03
created
core/domain/values/TimeFormat.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -4,33 +4,33 @@
 block discarded – undo
4 4
 
5 5
 class TimeFormat extends BaseFormat
6 6
 {
7
-    protected const DEFAULT_FORMAT = 'H:i:s';
8
-    protected const WORDPRESS_FORMAT_OPTION_NAME = 'time_format';
7
+	protected const DEFAULT_FORMAT = 'H:i:s';
8
+	protected const WORDPRESS_FORMAT_OPTION_NAME = 'time_format';
9 9
 
10
-    protected static array   $allowed_chars  = [
11
-        'a',
12
-        'A',
13
-        'B',
14
-        'g',
15
-        'G',
16
-        'h',
17
-        'H',
18
-        'i',
19
-        's',
20
-        'u',
21
-        'v',
22
-        'e',
23
-        'I',
24
-        'O',
25
-        'P',
26
-        'T',
27
-        'Z',
28
-        ':',
29
-        '-',
30
-        ',',
31
-        '.',
32
-        ' ',
33
-    ];
10
+	protected static array   $allowed_chars  = [
11
+		'a',
12
+		'A',
13
+		'B',
14
+		'g',
15
+		'G',
16
+		'h',
17
+		'H',
18
+		'i',
19
+		's',
20
+		'u',
21
+		'v',
22
+		'e',
23
+		'I',
24
+		'O',
25
+		'P',
26
+		'T',
27
+		'Z',
28
+		':',
29
+		'-',
30
+		',',
31
+		'.',
32
+		' ',
33
+	];
34 34
 
35
-    protected static ?string $wordpress_format = null;
35
+	protected static ?string $wordpress_format = null;
36 36
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
     protected const DEFAULT_FORMAT = 'H:i:s';
8 8
     protected const WORDPRESS_FORMAT_OPTION_NAME = 'time_format';
9 9
 
10
-    protected static array   $allowed_chars  = [
10
+    protected static array   $allowed_chars = [
11 11
         'a',
12 12
         'A',
13 13
         'B',
Please login to merge, or discard this patch.
core/domain/values/BaseFormat.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -4,44 +4,44 @@
 block discarded – undo
4 4
 
5 5
 abstract class BaseFormat
6 6
 {
7
-    protected string $format;
8
-
9
-    public function __construct(?string $format)
10
-    {
11
-        if (static::$wordpress_format === null) {
12
-            static::$wordpress_format = get_option(static::WORDPRESS_FORMAT_OPTION_NAME, static::DEFAULT_FORMAT);
13
-        }
14
-        $this->format = $this->sanitizeDateFormat($format ?: static::$wordpress_format);
15
-    }
16
-
17
-
18
-    protected function sanitizeDateFormat(string $format): string
19
-    {
20
-        $sanitized_format = '';
21
-        for ($i = 0; $i < strlen($format); $i++) {
22
-            $char = substr($format, $i, 1);
23
-            // first check if the previous character was a backslash
24
-            if (substr($format, $i-1, 1) === '\\') {
25
-                // escaped characters are allowed
26
-                $sanitized_format .= "\\$char";
27
-                continue;
28
-            }
29
-            if (in_array($char, static::$allowed_chars)) {
30
-                $sanitized_format .= $char;
31
-            }
32
-        }
33
-        return $sanitized_format;
34
-    }
35
-
36
-
37
-    public function format(): string
38
-    {
39
-        return $this->format;
40
-    }
41
-
42
-
43
-    public function __toString(): string
44
-    {
45
-        return $this->format();
46
-    }
7
+	protected string $format;
8
+
9
+	public function __construct(?string $format)
10
+	{
11
+		if (static::$wordpress_format === null) {
12
+			static::$wordpress_format = get_option(static::WORDPRESS_FORMAT_OPTION_NAME, static::DEFAULT_FORMAT);
13
+		}
14
+		$this->format = $this->sanitizeDateFormat($format ?: static::$wordpress_format);
15
+	}
16
+
17
+
18
+	protected function sanitizeDateFormat(string $format): string
19
+	{
20
+		$sanitized_format = '';
21
+		for ($i = 0; $i < strlen($format); $i++) {
22
+			$char = substr($format, $i, 1);
23
+			// first check if the previous character was a backslash
24
+			if (substr($format, $i-1, 1) === '\\') {
25
+				// escaped characters are allowed
26
+				$sanitized_format .= "\\$char";
27
+				continue;
28
+			}
29
+			if (in_array($char, static::$allowed_chars)) {
30
+				$sanitized_format .= $char;
31
+			}
32
+		}
33
+		return $sanitized_format;
34
+	}
35
+
36
+
37
+	public function format(): string
38
+	{
39
+		return $this->format;
40
+	}
41
+
42
+
43
+	public function __toString(): string
44
+	{
45
+		return $this->format();
46
+	}
47 47
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket.model.php 2 patches
Indentation   +486 added lines, -486 removed lines patch added patch discarded remove patch
@@ -13,490 +13,490 @@
 block discarded – undo
13 13
  */
14 14
 class EEM_Ticket extends EEM_Soft_Delete_Base
15 15
 {
16
-    /**
17
-     * the following constants define where tickets can be viewed throughout the UI
18
-     *  TICKET_VISIBILITY_NONE          - will not be displayed anywhere
19
-     *  TICKET_VISIBILITY_PUBLIC        - basically displayed everywhere
20
-     *  TICKET_VISIBILITY_MEMBERS_ONLY  - displayed to any logged-in user
21
-     *  TICKET_VISIBILITY_ADMINS_ONLY   - displayed to any logged-in user that is an admin
22
-     *  TICKET_VISIBILITY_ADMIN_UI_ONLY - only displayed in the admin, never publicly
23
-     */
24
-    public const TICKET_VISIBILITY_NONE_KEY            = 'NONE';
25
-
26
-    public const TICKET_VISIBILITY_NONE_VALUE          = 0;
27
-
28
-    public const TICKET_VISIBILITY_PUBLIC_KEY          = 'PUBLIC';
29
-
30
-    public const TICKET_VISIBILITY_PUBLIC_VALUE        = 100;
31
-
32
-    public const TICKET_VISIBILITY_MEMBERS_ONLY_KEY    = 'MEMBERS_ONLY';
33
-
34
-    public const TICKET_VISIBILITY_MEMBERS_ONLY_VALUE  = 200;
35
-
36
-    public const TICKET_VISIBILITY_ADMINS_ONLY_KEY     = 'ADMINS_ONLY';
37
-
38
-    public const TICKET_VISIBILITY_ADMINS_ONLY_VALUE   = 300;
39
-
40
-    public const TICKET_VISIBILITY_ADMIN_UI_ONLY_KEY   = 'ADMIN_UI_ONLY';
41
-
42
-    public const TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE = 400;
43
-
44
-
45
-    /**
46
-     * defines where tickets can be viewed throughout the UI
47
-     *
48
-     * @var array
49
-     */
50
-    private $ticket_visibility;
51
-
52
-    /**
53
-     * private instance of the EEM_Ticket object
54
-     *
55
-     * @var EEM_Ticket $_instance
56
-     */
57
-    protected static $_instance;
58
-
59
-
60
-    /**
61
-     * private constructor to prevent direct creation
62
-     *
63
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
64
-     *                              (and any incoming timezone data that gets saved).
65
-     *                              Note this just sends the timezone info to the date time model field objects.
66
-     *                              Default is NULL
67
-     *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
68
-     * @throws EE_Error
69
-     * @throws ReflectionException
70
-     */
71
-    protected function __construct(?string $timezone = '')
72
-    {
73
-        $this->singular_item = esc_html__('Ticket', 'event_espresso');
74
-        $this->plural_item   = esc_html__('Tickets', 'event_espresso');
75
-        $this->_tables       = [
76
-            'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'),
77
-        ];
78
-        $this->parseTicketVisibilityOptions();
79
-        $this->_fields          = [
80
-            'Ticket' => [
81
-                'TKT_ID'                => new EE_Primary_Key_Int_Field(
82
-                    'TKT_ID',
83
-                    esc_html__('Ticket ID', 'event_espresso')
84
-                ),
85
-                'TTM_ID'                => new EE_Foreign_Key_Int_Field(
86
-                    'TTM_ID',
87
-                    esc_html__('Ticket Template ID', 'event_espresso'),
88
-                    false,
89
-                    0,
90
-                    'Ticket_Template'
91
-                ),
92
-                'TKT_name'              => new EE_Plain_Text_Field(
93
-                    'TKT_name',
94
-                    esc_html__('Ticket Name', 'event_espresso'),
95
-                    false,
96
-                    ''
97
-                ),
98
-                'TKT_description'       => new EE_Post_Content_Field(
99
-                    'TKT_description',
100
-                    esc_html__('Description of Ticket', 'event_espresso'),
101
-                    false,
102
-                    ''
103
-                ),
104
-                'TKT_start_date'        => new EE_Datetime_Field(
105
-                    'TKT_start_date',
106
-                    esc_html__('Start time/date of Ticket', 'event_espresso'),
107
-                    false,
108
-                    EE_Datetime_Field::now,
109
-                    $timezone
110
-                ),
111
-                'TKT_end_date'          => new EE_Datetime_Field(
112
-                    'TKT_end_date',
113
-                    esc_html__('End time/date of Ticket', 'event_espresso'),
114
-                    false,
115
-                    EE_Datetime_Field::now,
116
-                    $timezone
117
-                ),
118
-                'TKT_min'               => new EE_Integer_Field(
119
-                    'TKT_min',
120
-                    esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'),
121
-                    false,
122
-                    0
123
-                ),
124
-                'TKT_max'               => new EE_Infinite_Integer_Field(
125
-                    'TKT_max',
126
-                    esc_html__(
127
-                        'Maximum quantity of this ticket that can be purchased in one transaction',
128
-                        'event_espresso'
129
-                    ),
130
-                    false,
131
-                    EE_INF
132
-                ),
133
-                'TKT_price'             => new EE_Money_Field(
134
-                    'TKT_price',
135
-                    esc_html__('Final calculated price for ticket', 'event_espresso'),
136
-                    false,
137
-                    0
138
-                ),
139
-                'TKT_sold'              => new EE_Integer_Field(
140
-                    'TKT_sold',
141
-                    esc_html__('Number of this ticket sold', 'event_espresso'),
142
-                    false,
143
-                    0
144
-                ),
145
-                'TKT_qty'               => new EE_Infinite_Integer_Field(
146
-                    'TKT_qty',
147
-                    esc_html__('Quantity of this ticket that is available', 'event_espresso'),
148
-                    false,
149
-                    EE_INF
150
-                ),
151
-                'TKT_reserved'          => new EE_Integer_Field(
152
-                    'TKT_reserved',
153
-                    esc_html__(
154
-                        'Quantity of this ticket that is reserved, but not yet fully purchased',
155
-                        'event_espresso'
156
-                    ),
157
-                    false,
158
-                    0
159
-                ),
160
-                'TKT_uses'              => new EE_Infinite_Integer_Field(
161
-                    'TKT_uses',
162
-                    esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
163
-                    false,
164
-                    EE_INF
165
-                ),
166
-                'TKT_required'          => new EE_Boolean_Field(
167
-                    'TKT_required',
168
-                    esc_html__(
169
-                        'Flag indicating whether this ticket must be purchased with a transaction',
170
-                        'event_espresso'
171
-                    ),
172
-                    false,
173
-                    false
174
-                ),
175
-                'TKT_taxable'           => new EE_Boolean_Field(
176
-                    'TKT_taxable',
177
-                    esc_html__(
178
-                        'Flag indicating whether there is tax applied on this ticket',
179
-                        'event_espresso'
180
-                    ),
181
-                    false,
182
-                    false
183
-                ),
184
-                'TKT_is_default'        => new EE_Boolean_Field(
185
-                    'TKT_is_default',
186
-                    esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'),
187
-                    false,
188
-                    false
189
-                ),
190
-                'TKT_order'             => new EE_Integer_Field(
191
-                    'TKT_order',
192
-                    esc_html__(
193
-                        'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)',
194
-                        'event_espresso'
195
-                    ),
196
-                    false,
197
-                    0
198
-                ),
199
-                'TKT_row'               => new EE_Integer_Field(
200
-                    'TKT_row',
201
-                    esc_html__('How tickets are displayed in the ui', 'event_espresso'),
202
-                    false,
203
-                    0
204
-                ),
205
-                'TKT_deleted'           => new EE_Trashed_Flag_Field(
206
-                    'TKT_deleted',
207
-                    esc_html__('Flag indicating if this has been archived or not', 'event_espresso'),
208
-                    false,
209
-                    false
210
-                ),
211
-                'TKT_wp_user'           => new EE_WP_User_Field(
212
-                    'TKT_wp_user',
213
-                    esc_html__('Ticket Creator ID', 'event_espresso'),
214
-                    false
215
-                ),
216
-                'TKT_parent'            => new EE_Integer_Field(
217
-                    'TKT_parent',
218
-                    esc_html__(
219
-                        'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)',
220
-                        'event_espresso'
221
-                    ),
222
-                    true,
223
-                    0
224
-                ),
225
-                'TKT_reverse_calculate' => new EE_Boolean_Field(
226
-                    'TKT_reverse_calculate',
227
-                    esc_html__(
228
-                        'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.',
229
-                        'event_espresso'
230
-                    ),
231
-                    false,
232
-                    false
233
-                ),
234
-                'TKT_visibility'        => new EE_Enum_Integer_Field(
235
-                    'TKT_visibility',
236
-                    esc_html__('Defines where the ticket can be viewed throughout the UI.', 'event_espresso'),
237
-                    false,
238
-                    EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE,
239
-                    $this->getTicketVisibilityEnumOptions()
240
-                ),
241
-            ],
242
-        ];
243
-        $this->_model_relations = [
244
-            'Datetime'        => new EE_HABTM_Relation('Datetime_Ticket'),
245
-            'Datetime_Ticket' => new EE_Has_Many_Relation(),
246
-            'Price'           => new EE_HABTM_Relation('Ticket_Price'),
247
-            'Ticket_Template' => new EE_Belongs_To_Relation(),
248
-            'Registration'    => new EE_Has_Many_Relation(),
249
-            'WP_User'         => new EE_Belongs_To_Relation(),
250
-        ];
251
-        // this model is generally available for reading
252
-        $path_to_event                                            = 'Datetime.Event';
253
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
254
-            'TKT_is_default',
255
-            $path_to_event
256
-        );
257
-
258
-        // account for default tickets in the caps
259
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ]
260
-                                                                    = new EE_Restriction_Generator_Default_Protected(
261
-            'TKT_is_default',
262
-            $path_to_event
263
-        );
264
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]   = new EE_Restriction_Generator_Default_Protected(
265
-            'TKT_is_default',
266
-            $path_to_event
267
-        );
268
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
269
-            'TKT_is_default',
270
-            $path_to_event
271
-        );
272
-        $this->model_chain_to_password                              = $path_to_event;
273
-        parent::__construct($timezone);
274
-    }
275
-
276
-
277
-    /**
278
-     * This returns all tickets that are defaults from the db
279
-     *
280
-     * @return EE_Ticket[]
281
-     * @throws EE_Error
282
-     * @throws ReflectionException
283
-     */
284
-    public function get_all_default_tickets(): array
285
-    {
286
-        $tickets = $this->get_all(
287
-            [
288
-                [
289
-                    'TKT_is_default' => 1,
290
-                    'TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE],
291
-                ],
292
-                'order_by' => ['TKT_ID' => 'ASC'],
293
-            ]
294
-        );
295
-        // we need to set the start date and end date to today's date and the start of the default dtt
296
-        return $this->_set_default_dates($tickets);
297
-    }
298
-
299
-
300
-    /**
301
-     * sets up relevant start and end date for EE_Ticket (s)
302
-     *
303
-     * @param EE_Ticket[] $tickets
304
-     * @return EE_Ticket[]
305
-     * @throws EE_Error
306
-     * @throws ReflectionException
307
-     */
308
-    private function _set_default_dates(array $tickets): array
309
-    {
310
-        foreach ($tickets as $ticket) {
311
-            $ticket->set(
312
-                'TKT_start_date',
313
-                (int) $this->current_time_for_query('TKT_start_date', true)
314
-            );
315
-            $ticket->set(
316
-                'TKT_end_date',
317
-                (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
318
-            );
319
-            $ticket->set_end_time(
320
-                $this->convert_datetime_for_query(
321
-                    'TKT_end_date',
322
-                    '11:59 pm',
323
-                    'g:i a',
324
-                    $this->_timezone
325
-                )
326
-            );
327
-        }
328
-        return $tickets;
329
-    }
330
-
331
-
332
-    /**
333
-     * Gets the total number of tickets available at a particular datetime (does
334
-     * NOT take int account the datetime's spaces available)
335
-     *
336
-     * @param int   $DTT_ID
337
-     * @param array $query_params
338
-     * @return int
339
-     * @throws EE_Error
340
-     * @throws ReflectionException
341
-     */
342
-    public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = []): int
343
-    {
344
-        $query_params += [['TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE]]];
345
-        return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params);
346
-    }
347
-
348
-
349
-    /**
350
-     * Updates the TKT_sold quantity on all the tickets matching $query_params
351
-     *
352
-     * @param EE_Ticket[] $tickets
353
-     * @return void
354
-     * @throws EE_Error
355
-     * @throws ReflectionException
356
-     */
357
-    public function update_tickets_sold(array $tickets)
358
-    {
359
-        foreach ($tickets as $ticket) {
360
-            $ticket->update_tickets_sold();
361
-        }
362
-    }
363
-
364
-
365
-    /**
366
-     * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved
367
-     *
368
-     * @return EE_Base_Class[]|EE_Ticket[]|null
369
-     * @throws EE_Error
370
-     * @throws ReflectionException
371
-     */
372
-    public function get_tickets_with_reservations(): ?array
373
-    {
374
-        return $this->get_all(
375
-            [
376
-                [
377
-                    'TKT_reserved'   => ['>', 0],
378
-                    'TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE],
379
-                ],
380
-            ]
381
-        );
382
-    }
383
-
384
-
385
-    /**
386
-     * returns an array of EE_Ticket objects matching the supplied list of IDs
387
-     *
388
-     * @param array $ticket_IDs
389
-     * @return EE_Base_Class[]|EE_Ticket[]|null
390
-     * @throws EE_Error
391
-     * @throws ReflectionException
392
-     */
393
-    public function get_tickets_with_IDs(array $ticket_IDs): ?array
394
-    {
395
-        return $this->get_all(
396
-            [
397
-                [
398
-                    'TKT_ID' => ['IN', $ticket_IDs],
399
-                ],
400
-            ]
401
-        );
402
-    }
403
-
404
-
405
-    /**
406
-     * @return void
407
-     */
408
-    private function parseTicketVisibilityOptions()
409
-    {
410
-        $this->ticket_visibility = (array) apply_filters(
411
-            'FHEE__EEM_Ticket__construct__ticket_visibility',
412
-            [
413
-                EEM_Ticket::TICKET_VISIBILITY_PUBLIC_KEY        => [
414
-                    'desc'  => esc_html__('ticket displayed to everyone everywhere', 'event_espresso'),
415
-                    'label' => esc_html__('Public', 'event_espresso'),
416
-                    'value' => EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE,
417
-                ],
418
-                EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_KEY  => [
419
-                    'desc'  => esc_html__('ticket only displayed to logged-in users', 'event_espresso'),
420
-                    'label' => esc_html__('Members only', 'event_espresso'),
421
-                    'value' => EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE,
422
-                ],
423
-                EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_KEY   => [
424
-                    'desc'  => esc_html__('ticket only displayed to logged-in admins', 'event_espresso'),
425
-                    'label' => esc_html__('Admins only', 'event_espresso'),
426
-                    'value' => EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE,
427
-                ],
428
-                EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_KEY => [
429
-                    'desc'  => esc_html__(
430
-                        'ticket only displayed in the admin UI and not on the frontend',
431
-                        'event_espresso'
432
-                    ),
433
-                    'label' => esc_html__('Admin UI only', 'event_espresso'),
434
-                    'value' => EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE,
435
-                ],
436
-                EEM_Ticket::TICKET_VISIBILITY_NONE_KEY          => [
437
-                    'desc'  => esc_html__('will hide the ticket everywhere', 'event_espresso'),
438
-                    'label' => esc_html__('None', 'event_espresso'),
439
-                    'value' => EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE,
440
-                ],
441
-            ]
442
-        );
443
-    }
444
-
445
-
446
-    /**
447
-     * @return array
448
-     */
449
-    public function getTicketVisibilityEnumOptions(): array
450
-    {
451
-        $ticket_visibility = [];
452
-        foreach ($this->ticket_visibility as $visibility) {
453
-            if (isset($visibility['value'], $visibility['label'])) {
454
-                $ticket_visibility[ $visibility['value'] ] = $visibility['label'];
455
-            }
456
-        }
457
-        return $ticket_visibility;
458
-    }
459
-
460
-
461
-    /**
462
-     * @return array
463
-     */
464
-    public function getTicketVisibilityValues(): array
465
-    {
466
-        // copy ticket_visibility array
467
-        $ticket_visibility_options = $this->ticket_visibility;
468
-        foreach ($ticket_visibility_options as $ticket_visibility_option) {
469
-            // remove labels because we only want the values
470
-            unset($ticket_visibility_option['label']);
471
-        }
472
-        return $ticket_visibility_options;
473
-    }
474
-
475
-
476
-    /**
477
-     * @return array
478
-     */
479
-    public function getTicketVisibilityLabels(): array
480
-    {
481
-        $ticket_visibility_options = [];
482
-        foreach ($this->ticket_visibility as $key => $ticket_visibility_option) {
483
-            if (isset($ticket_visibility_option['label'])) {
484
-                // change because we only want the labels tied to the keys
485
-                $ticket_visibility_options[] = [
486
-                    'value' => $key,
487
-                    'label' => $ticket_visibility_option['label'],
488
-                ];
489
-            }
490
-        }
491
-        return $ticket_visibility_options;
492
-    }
493
-
494
-
495
-    /**
496
-     * @return array
497
-     */
498
-    public function ticketVisibilityOptions(): array
499
-    {
500
-        return $this->ticket_visibility;
501
-    }
16
+	/**
17
+	 * the following constants define where tickets can be viewed throughout the UI
18
+	 *  TICKET_VISIBILITY_NONE          - will not be displayed anywhere
19
+	 *  TICKET_VISIBILITY_PUBLIC        - basically displayed everywhere
20
+	 *  TICKET_VISIBILITY_MEMBERS_ONLY  - displayed to any logged-in user
21
+	 *  TICKET_VISIBILITY_ADMINS_ONLY   - displayed to any logged-in user that is an admin
22
+	 *  TICKET_VISIBILITY_ADMIN_UI_ONLY - only displayed in the admin, never publicly
23
+	 */
24
+	public const TICKET_VISIBILITY_NONE_KEY            = 'NONE';
25
+
26
+	public const TICKET_VISIBILITY_NONE_VALUE          = 0;
27
+
28
+	public const TICKET_VISIBILITY_PUBLIC_KEY          = 'PUBLIC';
29
+
30
+	public const TICKET_VISIBILITY_PUBLIC_VALUE        = 100;
31
+
32
+	public const TICKET_VISIBILITY_MEMBERS_ONLY_KEY    = 'MEMBERS_ONLY';
33
+
34
+	public const TICKET_VISIBILITY_MEMBERS_ONLY_VALUE  = 200;
35
+
36
+	public const TICKET_VISIBILITY_ADMINS_ONLY_KEY     = 'ADMINS_ONLY';
37
+
38
+	public const TICKET_VISIBILITY_ADMINS_ONLY_VALUE   = 300;
39
+
40
+	public const TICKET_VISIBILITY_ADMIN_UI_ONLY_KEY   = 'ADMIN_UI_ONLY';
41
+
42
+	public const TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE = 400;
43
+
44
+
45
+	/**
46
+	 * defines where tickets can be viewed throughout the UI
47
+	 *
48
+	 * @var array
49
+	 */
50
+	private $ticket_visibility;
51
+
52
+	/**
53
+	 * private instance of the EEM_Ticket object
54
+	 *
55
+	 * @var EEM_Ticket $_instance
56
+	 */
57
+	protected static $_instance;
58
+
59
+
60
+	/**
61
+	 * private constructor to prevent direct creation
62
+	 *
63
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
64
+	 *                              (and any incoming timezone data that gets saved).
65
+	 *                              Note this just sends the timezone info to the date time model field objects.
66
+	 *                              Default is NULL
67
+	 *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
68
+	 * @throws EE_Error
69
+	 * @throws ReflectionException
70
+	 */
71
+	protected function __construct(?string $timezone = '')
72
+	{
73
+		$this->singular_item = esc_html__('Ticket', 'event_espresso');
74
+		$this->plural_item   = esc_html__('Tickets', 'event_espresso');
75
+		$this->_tables       = [
76
+			'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'),
77
+		];
78
+		$this->parseTicketVisibilityOptions();
79
+		$this->_fields          = [
80
+			'Ticket' => [
81
+				'TKT_ID'                => new EE_Primary_Key_Int_Field(
82
+					'TKT_ID',
83
+					esc_html__('Ticket ID', 'event_espresso')
84
+				),
85
+				'TTM_ID'                => new EE_Foreign_Key_Int_Field(
86
+					'TTM_ID',
87
+					esc_html__('Ticket Template ID', 'event_espresso'),
88
+					false,
89
+					0,
90
+					'Ticket_Template'
91
+				),
92
+				'TKT_name'              => new EE_Plain_Text_Field(
93
+					'TKT_name',
94
+					esc_html__('Ticket Name', 'event_espresso'),
95
+					false,
96
+					''
97
+				),
98
+				'TKT_description'       => new EE_Post_Content_Field(
99
+					'TKT_description',
100
+					esc_html__('Description of Ticket', 'event_espresso'),
101
+					false,
102
+					''
103
+				),
104
+				'TKT_start_date'        => new EE_Datetime_Field(
105
+					'TKT_start_date',
106
+					esc_html__('Start time/date of Ticket', 'event_espresso'),
107
+					false,
108
+					EE_Datetime_Field::now,
109
+					$timezone
110
+				),
111
+				'TKT_end_date'          => new EE_Datetime_Field(
112
+					'TKT_end_date',
113
+					esc_html__('End time/date of Ticket', 'event_espresso'),
114
+					false,
115
+					EE_Datetime_Field::now,
116
+					$timezone
117
+				),
118
+				'TKT_min'               => new EE_Integer_Field(
119
+					'TKT_min',
120
+					esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'),
121
+					false,
122
+					0
123
+				),
124
+				'TKT_max'               => new EE_Infinite_Integer_Field(
125
+					'TKT_max',
126
+					esc_html__(
127
+						'Maximum quantity of this ticket that can be purchased in one transaction',
128
+						'event_espresso'
129
+					),
130
+					false,
131
+					EE_INF
132
+				),
133
+				'TKT_price'             => new EE_Money_Field(
134
+					'TKT_price',
135
+					esc_html__('Final calculated price for ticket', 'event_espresso'),
136
+					false,
137
+					0
138
+				),
139
+				'TKT_sold'              => new EE_Integer_Field(
140
+					'TKT_sold',
141
+					esc_html__('Number of this ticket sold', 'event_espresso'),
142
+					false,
143
+					0
144
+				),
145
+				'TKT_qty'               => new EE_Infinite_Integer_Field(
146
+					'TKT_qty',
147
+					esc_html__('Quantity of this ticket that is available', 'event_espresso'),
148
+					false,
149
+					EE_INF
150
+				),
151
+				'TKT_reserved'          => new EE_Integer_Field(
152
+					'TKT_reserved',
153
+					esc_html__(
154
+						'Quantity of this ticket that is reserved, but not yet fully purchased',
155
+						'event_espresso'
156
+					),
157
+					false,
158
+					0
159
+				),
160
+				'TKT_uses'              => new EE_Infinite_Integer_Field(
161
+					'TKT_uses',
162
+					esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
163
+					false,
164
+					EE_INF
165
+				),
166
+				'TKT_required'          => new EE_Boolean_Field(
167
+					'TKT_required',
168
+					esc_html__(
169
+						'Flag indicating whether this ticket must be purchased with a transaction',
170
+						'event_espresso'
171
+					),
172
+					false,
173
+					false
174
+				),
175
+				'TKT_taxable'           => new EE_Boolean_Field(
176
+					'TKT_taxable',
177
+					esc_html__(
178
+						'Flag indicating whether there is tax applied on this ticket',
179
+						'event_espresso'
180
+					),
181
+					false,
182
+					false
183
+				),
184
+				'TKT_is_default'        => new EE_Boolean_Field(
185
+					'TKT_is_default',
186
+					esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'),
187
+					false,
188
+					false
189
+				),
190
+				'TKT_order'             => new EE_Integer_Field(
191
+					'TKT_order',
192
+					esc_html__(
193
+						'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)',
194
+						'event_espresso'
195
+					),
196
+					false,
197
+					0
198
+				),
199
+				'TKT_row'               => new EE_Integer_Field(
200
+					'TKT_row',
201
+					esc_html__('How tickets are displayed in the ui', 'event_espresso'),
202
+					false,
203
+					0
204
+				),
205
+				'TKT_deleted'           => new EE_Trashed_Flag_Field(
206
+					'TKT_deleted',
207
+					esc_html__('Flag indicating if this has been archived or not', 'event_espresso'),
208
+					false,
209
+					false
210
+				),
211
+				'TKT_wp_user'           => new EE_WP_User_Field(
212
+					'TKT_wp_user',
213
+					esc_html__('Ticket Creator ID', 'event_espresso'),
214
+					false
215
+				),
216
+				'TKT_parent'            => new EE_Integer_Field(
217
+					'TKT_parent',
218
+					esc_html__(
219
+						'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)',
220
+						'event_espresso'
221
+					),
222
+					true,
223
+					0
224
+				),
225
+				'TKT_reverse_calculate' => new EE_Boolean_Field(
226
+					'TKT_reverse_calculate',
227
+					esc_html__(
228
+						'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.',
229
+						'event_espresso'
230
+					),
231
+					false,
232
+					false
233
+				),
234
+				'TKT_visibility'        => new EE_Enum_Integer_Field(
235
+					'TKT_visibility',
236
+					esc_html__('Defines where the ticket can be viewed throughout the UI.', 'event_espresso'),
237
+					false,
238
+					EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE,
239
+					$this->getTicketVisibilityEnumOptions()
240
+				),
241
+			],
242
+		];
243
+		$this->_model_relations = [
244
+			'Datetime'        => new EE_HABTM_Relation('Datetime_Ticket'),
245
+			'Datetime_Ticket' => new EE_Has_Many_Relation(),
246
+			'Price'           => new EE_HABTM_Relation('Ticket_Price'),
247
+			'Ticket_Template' => new EE_Belongs_To_Relation(),
248
+			'Registration'    => new EE_Has_Many_Relation(),
249
+			'WP_User'         => new EE_Belongs_To_Relation(),
250
+		];
251
+		// this model is generally available for reading
252
+		$path_to_event                                            = 'Datetime.Event';
253
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
254
+			'TKT_is_default',
255
+			$path_to_event
256
+		);
257
+
258
+		// account for default tickets in the caps
259
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ]
260
+																	= new EE_Restriction_Generator_Default_Protected(
261
+			'TKT_is_default',
262
+			$path_to_event
263
+		);
264
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]   = new EE_Restriction_Generator_Default_Protected(
265
+			'TKT_is_default',
266
+			$path_to_event
267
+		);
268
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
269
+			'TKT_is_default',
270
+			$path_to_event
271
+		);
272
+		$this->model_chain_to_password                              = $path_to_event;
273
+		parent::__construct($timezone);
274
+	}
275
+
276
+
277
+	/**
278
+	 * This returns all tickets that are defaults from the db
279
+	 *
280
+	 * @return EE_Ticket[]
281
+	 * @throws EE_Error
282
+	 * @throws ReflectionException
283
+	 */
284
+	public function get_all_default_tickets(): array
285
+	{
286
+		$tickets = $this->get_all(
287
+			[
288
+				[
289
+					'TKT_is_default' => 1,
290
+					'TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE],
291
+				],
292
+				'order_by' => ['TKT_ID' => 'ASC'],
293
+			]
294
+		);
295
+		// we need to set the start date and end date to today's date and the start of the default dtt
296
+		return $this->_set_default_dates($tickets);
297
+	}
298
+
299
+
300
+	/**
301
+	 * sets up relevant start and end date for EE_Ticket (s)
302
+	 *
303
+	 * @param EE_Ticket[] $tickets
304
+	 * @return EE_Ticket[]
305
+	 * @throws EE_Error
306
+	 * @throws ReflectionException
307
+	 */
308
+	private function _set_default_dates(array $tickets): array
309
+	{
310
+		foreach ($tickets as $ticket) {
311
+			$ticket->set(
312
+				'TKT_start_date',
313
+				(int) $this->current_time_for_query('TKT_start_date', true)
314
+			);
315
+			$ticket->set(
316
+				'TKT_end_date',
317
+				(int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
318
+			);
319
+			$ticket->set_end_time(
320
+				$this->convert_datetime_for_query(
321
+					'TKT_end_date',
322
+					'11:59 pm',
323
+					'g:i a',
324
+					$this->_timezone
325
+				)
326
+			);
327
+		}
328
+		return $tickets;
329
+	}
330
+
331
+
332
+	/**
333
+	 * Gets the total number of tickets available at a particular datetime (does
334
+	 * NOT take int account the datetime's spaces available)
335
+	 *
336
+	 * @param int   $DTT_ID
337
+	 * @param array $query_params
338
+	 * @return int
339
+	 * @throws EE_Error
340
+	 * @throws ReflectionException
341
+	 */
342
+	public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = []): int
343
+	{
344
+		$query_params += [['TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE]]];
345
+		return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params);
346
+	}
347
+
348
+
349
+	/**
350
+	 * Updates the TKT_sold quantity on all the tickets matching $query_params
351
+	 *
352
+	 * @param EE_Ticket[] $tickets
353
+	 * @return void
354
+	 * @throws EE_Error
355
+	 * @throws ReflectionException
356
+	 */
357
+	public function update_tickets_sold(array $tickets)
358
+	{
359
+		foreach ($tickets as $ticket) {
360
+			$ticket->update_tickets_sold();
361
+		}
362
+	}
363
+
364
+
365
+	/**
366
+	 * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved
367
+	 *
368
+	 * @return EE_Base_Class[]|EE_Ticket[]|null
369
+	 * @throws EE_Error
370
+	 * @throws ReflectionException
371
+	 */
372
+	public function get_tickets_with_reservations(): ?array
373
+	{
374
+		return $this->get_all(
375
+			[
376
+				[
377
+					'TKT_reserved'   => ['>', 0],
378
+					'TKT_visibility' => ['>', EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE],
379
+				],
380
+			]
381
+		);
382
+	}
383
+
384
+
385
+	/**
386
+	 * returns an array of EE_Ticket objects matching the supplied list of IDs
387
+	 *
388
+	 * @param array $ticket_IDs
389
+	 * @return EE_Base_Class[]|EE_Ticket[]|null
390
+	 * @throws EE_Error
391
+	 * @throws ReflectionException
392
+	 */
393
+	public function get_tickets_with_IDs(array $ticket_IDs): ?array
394
+	{
395
+		return $this->get_all(
396
+			[
397
+				[
398
+					'TKT_ID' => ['IN', $ticket_IDs],
399
+				],
400
+			]
401
+		);
402
+	}
403
+
404
+
405
+	/**
406
+	 * @return void
407
+	 */
408
+	private function parseTicketVisibilityOptions()
409
+	{
410
+		$this->ticket_visibility = (array) apply_filters(
411
+			'FHEE__EEM_Ticket__construct__ticket_visibility',
412
+			[
413
+				EEM_Ticket::TICKET_VISIBILITY_PUBLIC_KEY        => [
414
+					'desc'  => esc_html__('ticket displayed to everyone everywhere', 'event_espresso'),
415
+					'label' => esc_html__('Public', 'event_espresso'),
416
+					'value' => EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE,
417
+				],
418
+				EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_KEY  => [
419
+					'desc'  => esc_html__('ticket only displayed to logged-in users', 'event_espresso'),
420
+					'label' => esc_html__('Members only', 'event_espresso'),
421
+					'value' => EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE,
422
+				],
423
+				EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_KEY   => [
424
+					'desc'  => esc_html__('ticket only displayed to logged-in admins', 'event_espresso'),
425
+					'label' => esc_html__('Admins only', 'event_espresso'),
426
+					'value' => EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE,
427
+				],
428
+				EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_KEY => [
429
+					'desc'  => esc_html__(
430
+						'ticket only displayed in the admin UI and not on the frontend',
431
+						'event_espresso'
432
+					),
433
+					'label' => esc_html__('Admin UI only', 'event_espresso'),
434
+					'value' => EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE,
435
+				],
436
+				EEM_Ticket::TICKET_VISIBILITY_NONE_KEY          => [
437
+					'desc'  => esc_html__('will hide the ticket everywhere', 'event_espresso'),
438
+					'label' => esc_html__('None', 'event_espresso'),
439
+					'value' => EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE,
440
+				],
441
+			]
442
+		);
443
+	}
444
+
445
+
446
+	/**
447
+	 * @return array
448
+	 */
449
+	public function getTicketVisibilityEnumOptions(): array
450
+	{
451
+		$ticket_visibility = [];
452
+		foreach ($this->ticket_visibility as $visibility) {
453
+			if (isset($visibility['value'], $visibility['label'])) {
454
+				$ticket_visibility[ $visibility['value'] ] = $visibility['label'];
455
+			}
456
+		}
457
+		return $ticket_visibility;
458
+	}
459
+
460
+
461
+	/**
462
+	 * @return array
463
+	 */
464
+	public function getTicketVisibilityValues(): array
465
+	{
466
+		// copy ticket_visibility array
467
+		$ticket_visibility_options = $this->ticket_visibility;
468
+		foreach ($ticket_visibility_options as $ticket_visibility_option) {
469
+			// remove labels because we only want the values
470
+			unset($ticket_visibility_option['label']);
471
+		}
472
+		return $ticket_visibility_options;
473
+	}
474
+
475
+
476
+	/**
477
+	 * @return array
478
+	 */
479
+	public function getTicketVisibilityLabels(): array
480
+	{
481
+		$ticket_visibility_options = [];
482
+		foreach ($this->ticket_visibility as $key => $ticket_visibility_option) {
483
+			if (isset($ticket_visibility_option['label'])) {
484
+				// change because we only want the labels tied to the keys
485
+				$ticket_visibility_options[] = [
486
+					'value' => $key,
487
+					'label' => $ticket_visibility_option['label'],
488
+				];
489
+			}
490
+		}
491
+		return $ticket_visibility_options;
492
+	}
493
+
494
+
495
+	/**
496
+	 * @return array
497
+	 */
498
+	public function ticketVisibilityOptions(): array
499
+	{
500
+		return $this->ticket_visibility;
501
+	}
502 502
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'),
77 77
         ];
78 78
         $this->parseTicketVisibilityOptions();
79
-        $this->_fields          = [
79
+        $this->_fields = [
80 80
             'Ticket' => [
81 81
                 'TKT_ID'                => new EE_Primary_Key_Int_Field(
82 82
                     'TKT_ID',
@@ -250,26 +250,26 @@  discard block
 block discarded – undo
250 250
         ];
251 251
         // this model is generally available for reading
252 252
         $path_to_event                                            = 'Datetime.Event';
253
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
253
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public(
254 254
             'TKT_is_default',
255 255
             $path_to_event
256 256
         );
257 257
 
258 258
         // account for default tickets in the caps
259
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ]
259
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin]
260 260
                                                                     = new EE_Restriction_Generator_Default_Protected(
261 261
             'TKT_is_default',
262 262
             $path_to_event
263 263
         );
264
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]   = new EE_Restriction_Generator_Default_Protected(
264
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected(
265 265
             'TKT_is_default',
266 266
             $path_to_event
267 267
         );
268
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
268
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected(
269 269
             'TKT_is_default',
270 270
             $path_to_event
271 271
         );
272
-        $this->model_chain_to_password                              = $path_to_event;
272
+        $this->model_chain_to_password = $path_to_event;
273 273
         parent::__construct($timezone);
274 274
     }
275 275
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
         $ticket_visibility = [];
452 452
         foreach ($this->ticket_visibility as $visibility) {
453 453
             if (isset($visibility['value'], $visibility['label'])) {
454
-                $ticket_visibility[ $visibility['value'] ] = $visibility['label'];
454
+                $ticket_visibility[$visibility['value']] = $visibility['label'];
455 455
             }
456 456
         }
457 457
         return $ticket_visibility;
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket_Template.model.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -10,71 +10,71 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Ticket_Template extends EEM_Base
12 12
 {
13
-    // private instance of the EEM_Ticket_Template object
14
-    protected static $_instance = null;
13
+	// private instance of the EEM_Ticket_Template object
14
+	protected static $_instance = null;
15 15
 
16 16
 
17
-    /**
18
-     * private constructor to prevent direct creation
19
-     *
20
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
21
-     *                              any incoming timezone data that gets saved).  Note this just sends the timezone
22
-     *                              info to the date time model field objects.  Default is NULL (and will be assumed
23
-     *                              using the set timezone in the 'timezone_string' wp option)
24
-     * @throws EE_Error
25
-     */
26
-    protected function __construct(?string $timezone = '')
27
-    {
28
-        $this->singular_item = esc_html__('Ticket Template', 'event_espresso');
29
-        $this->plural_item   = esc_html__('Ticket Templates', 'event_espresso');
17
+	/**
18
+	 * private constructor to prevent direct creation
19
+	 *
20
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
21
+	 *                              any incoming timezone data that gets saved).  Note this just sends the timezone
22
+	 *                              info to the date time model field objects.  Default is NULL (and will be assumed
23
+	 *                              using the set timezone in the 'timezone_string' wp option)
24
+	 * @throws EE_Error
25
+	 */
26
+	protected function __construct(?string $timezone = '')
27
+	{
28
+		$this->singular_item = esc_html__('Ticket Template', 'event_espresso');
29
+		$this->plural_item   = esc_html__('Ticket Templates', 'event_espresso');
30 30
 
31
-        $this->_tables                                            = [
32
-            'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID'),
33
-        ];
34
-        $this->_fields                                            = [
35
-            'Ticket_Template' => [
36
-                'TTM_ID'          => new EE_Primary_Key_Int_Field(
37
-                    'TTM_ID', esc_html__('Ticket Template ID', 'event_espresso')
38
-                ),
39
-                'TTM_name'        => new EE_Plain_Text_Field(
40
-                    'TTM_name',
41
-                    esc_html__('The name of the ticket template', 'event_espresso'),
42
-                    false,
43
-                    ''
44
-                ),
45
-                'TTM_description' => new EE_Plain_Text_Field(
46
-                    'TTM_description',
47
-                    esc_html__(
48
-                        'The description for the ticket template',
49
-                        'event_espresso'
50
-                    ),
51
-                    true,
52
-                    ''
53
-                ),
54
-                'TTM_file'        => new EE_Plain_Text_Field(
55
-                    'TTM_file',
56
-                    esc_html__(
57
-                        'The file name for the actual template file saved on disk',
58
-                        'event_espresso'
59
-                    ),
60
-                    true,
61
-                    ''
62
-                ),
63
-            ],
64
-        ];
65
-        $this->_model_relations                                   = [
66
-            'Ticket' => new EE_Has_Many_Relation(),
67
-        ];
68
-        $this->_model_chain_to_wp_user                            = 'Ticket';
69
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] =
70
-            new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
71
-        // account for default tickets in the caps
72
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
73
-            new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
74
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
75
-            new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
76
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
77
-            new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
78
-        parent::__construct($timezone);
79
-    }
31
+		$this->_tables                                            = [
32
+			'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID'),
33
+		];
34
+		$this->_fields                                            = [
35
+			'Ticket_Template' => [
36
+				'TTM_ID'          => new EE_Primary_Key_Int_Field(
37
+					'TTM_ID', esc_html__('Ticket Template ID', 'event_espresso')
38
+				),
39
+				'TTM_name'        => new EE_Plain_Text_Field(
40
+					'TTM_name',
41
+					esc_html__('The name of the ticket template', 'event_espresso'),
42
+					false,
43
+					''
44
+				),
45
+				'TTM_description' => new EE_Plain_Text_Field(
46
+					'TTM_description',
47
+					esc_html__(
48
+						'The description for the ticket template',
49
+						'event_espresso'
50
+					),
51
+					true,
52
+					''
53
+				),
54
+				'TTM_file'        => new EE_Plain_Text_Field(
55
+					'TTM_file',
56
+					esc_html__(
57
+						'The file name for the actual template file saved on disk',
58
+						'event_espresso'
59
+					),
60
+					true,
61
+					''
62
+				),
63
+			],
64
+		];
65
+		$this->_model_relations                                   = [
66
+			'Ticket' => new EE_Has_Many_Relation(),
67
+		];
68
+		$this->_model_chain_to_wp_user                            = 'Ticket';
69
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] =
70
+			new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
71
+		// account for default tickets in the caps
72
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
73
+			new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
74
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
75
+			new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
76
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
77
+			new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
78
+		parent::__construct($timezone);
79
+	}
80 80
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -66,14 +66,14 @@
 block discarded – undo
66 66
             'Ticket' => new EE_Has_Many_Relation(),
67 67
         ];
68 68
         $this->_model_chain_to_wp_user                            = 'Ticket';
69
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] =
69
+        $this->_cap_restriction_generators[EEM_Base::caps_read] =
70 70
             new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
71 71
         // account for default tickets in the caps
72
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
72
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
73 73
             new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
74
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
74
+        $this->_cap_restriction_generators[EEM_Base::caps_edit]       =
75 75
             new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
76
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
76
+        $this->_cap_restriction_generators[EEM_Base::caps_delete]     =
77 77
             new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
78 78
         parent::__construct($timezone);
79 79
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Soft_Delete_Base.model.php 2 patches
Indentation   +367 added lines, -367 removed lines patch added patch discarded remove patch
@@ -28,371 +28,371 @@
 block discarded – undo
28 28
  */
29 29
 abstract class EEM_Soft_Delete_Base extends EEM_Base
30 30
 {
31
-    /**
32
-     * @param string|null $timezone
33
-     * @throws EE_Error
34
-     */
35
-    protected function __construct(?string $timezone = '')
36
-    {
37
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
38
-            $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
39
-        }
40
-        parent::__construct($timezone);
41
-    }
42
-
43
-
44
-    /**
45
-     * Searches for field on this model of type 'deleted_flag'. if it is found, returns it's name.
46
-     *
47
-     * @return string
48
-     * @throws EE_Error
49
-     */
50
-    public function deleted_field_name()
51
-    {
52
-        $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
53
-        if ($field) {
54
-            return $field->get_name();
55
-        } else {
56
-            throw new EE_Error(
57
-                sprintf(
58
-                    esc_html__(
59
-                        'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
60
-                        'event_espresso'
61
-                    ),
62
-                    get_class($this),
63
-                    get_class($this)
64
-                )
65
-            );
66
-        }
67
-    }
68
-
69
-
70
-    /**
71
-     * Gets one item that's been deleted, according to $query_params
72
-     *
73
-     * @param array $query_params
74
-     * @return EE_Soft_Delete_Base_Class
75
-     * @throws EE_Error
76
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
77
-     */
78
-    public function get_one_deleted($query_params = [])
79
-    {
80
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
81
-        return $this->get_one($query_params);
82
-    }
83
-
84
-
85
-    /**
86
-     * Gets one item from the DB, regardless of whether it's been soft-deleted or not
87
-     *
88
-     * @param array $query_params like EEM_base::get_all's $query_params
89
-     * @return EE_Soft_Delete_Base_Class
90
-     * @throws EE_Error
91
-     */
92
-    public function get_one_deleted_or_undeleted($query_params = [])
93
-    {
94
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
95
-        return $this->get_one($query_params);
96
-    }
97
-
98
-
99
-    /**
100
-     * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
101
-     *
102
-     * @param int|string $id
103
-     * @return EE_Soft_Delete_Base_Class
104
-     * @throws EE_Error
105
-     */
106
-    public function get_one_by_ID_but_ignore_deleted($id)
107
-    {
108
-        return $this->get_one(
109
-            $this->alter_query_params_to_restrict_by_ID(
110
-                $id,
111
-                ['default_where_conditions' => 'default']
112
-            )
113
-        );
114
-    }
115
-
116
-
117
-    /**
118
-     * Counts all the deleted/trashed items
119
-     *
120
-     * @param array  $query_params
121
-     * @param string $field_to_count
122
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger
123
-     *                             that by the setting $distinct to TRUE;
124
-     * @return int
125
-     * @throws EE_Error
126
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
127
-     */
128
-    public function count_deleted($query_params = [], $field_to_count = null, $distinct = false)
129
-    {
130
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
131
-        return $this->count($query_params, $field_to_count, $distinct);
132
-    }
133
-
134
-
135
-    /**
136
-     * Alters the query params so that only trashed/soft-deleted items are considered
137
-     *
138
-     * @param array $query_params
139
-     * @return array
140
-     * @throws EE_Error
141
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
142
-     */
143
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
144
-    {
145
-        $deletedFlagFieldName                     = $this->deleted_field_name();
146
-        $query_params[0][ $deletedFlagFieldName ] = true;
147
-        return $query_params;
148
-    }
149
-
150
-
151
-    /**
152
-     * Alters the query params so that only trashed/soft-deleted items are considered
153
-     *
154
-     * @param array $query_params
155
-     * @return array
156
-     * @throws EE_Error
157
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
158
-     */
159
-    public function alter_query_params_so_only_trashed_items_included($query_params)
160
-    {
161
-        return $this->_alter_query_params_so_only_trashed_items_included($query_params);
162
-    }
163
-
164
-
165
-    /**
166
-     * Alters the query params so each item's deleted status is ignored.
167
-     *
168
-     * @param array $query_params
169
-     * @return array
170
-     */
171
-    public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = [])
172
-    {
173
-        return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
174
-    }
175
-
176
-
177
-    /**
178
-     * Alters the query params so each item's deleted status is ignored.
179
-     *
180
-     * @param array $query_params
181
-     * @return array
182
-     */
183
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
184
-    {
185
-        if (! isset($query_params['default_where_conditions'])) {
186
-            $query_params['default_where_conditions'] = 'minimum';
187
-        }
188
-        return $query_params;
189
-    }
190
-
191
-
192
-    /**
193
-     * Counts all deleted and undeleted items
194
-     *
195
-     * @param array  $query_params
196
-     * @param string $field_to_count
197
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger
198
-     *                             that by the setting $distinct to TRUE;
199
-     * @return int
200
-     * @throws EE_Error
201
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
202
-     */
203
-    public function count_deleted_and_undeleted($query_params = [], $field_to_count = null, $distinct = false)
204
-    {
205
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
206
-        return $this->count($query_params, $field_to_count, $distinct);
207
-    }
208
-
209
-
210
-    /**
211
-     * Sum all the deleted items.
212
-     *
213
-     * @param array  $query_params
214
-     * @param string $field_to_sum
215
-     * @return float
216
-     * @throws EE_Error
217
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
218
-     */
219
-    public function sum_deleted($query_params = [], $field_to_sum = null)
220
-    {
221
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
222
-        return $this->sum($query_params, $field_to_sum);
223
-    }
224
-
225
-
226
-    /**
227
-     * Sums all the deleted and undeleted items.
228
-     *
229
-     * @param array  $query_params
230
-     * @param string $field_to_sum
231
-     * @return float
232
-     * @throws EE_Error
233
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
234
-     */
235
-    public function sum_deleted_and_undeleted($query_params = [], $field_to_sum = null)
236
-    {
237
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
238
-        return $this->sum($query_params, $field_to_sum);
239
-    }
240
-
241
-
242
-    /**
243
-     * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
244
-     * whether they've been soft-deleted or not
245
-     *
246
-     * @param array $query_params
247
-     * @return EE_Soft_Delete_Base_Class[]
248
-     * @throws EE_Error
249
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
250
-     */
251
-    public function get_all_deleted_and_undeleted($query_params = [])
252
-    {
253
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
254
-        return $this->get_all($query_params);
255
-    }
256
-
257
-
258
-    /**
259
-     * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
260
-     *
261
-     * @param array $query_params
262
-     * @return EE_Soft_Delete_Base_Class[]
263
-     * @throws EE_Error
264
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
265
-     */
266
-    public function get_all_deleted($query_params = [])
267
-    {
268
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
269
-        return $this->get_all($query_params);
270
-    }
271
-
272
-
273
-    /**
274
-     * Permanently deletes the selected rows. When selecting rows for deletion, ignores
275
-     * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
276
-     * before you can permanently delete them).
277
-     * Because this will cause a real deletion, related models may block this deletion (ie, add an error
278
-     * and abort the delete)
279
-     *
280
-     * @param array   $query_params
281
-     * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
282
-     *                                that blocks it (ie, there' sno other data that depends on this data);
283
-     *                                if false, deletes regardless of other objects which may depend on it.
284
-     *                                Its generally advisable to always leave this as TRUE,
285
-     *                                otherwise you could easily corrupt your DB
286
-     * @return int                    number of rows deleted
287
-     * @throws EE_Error
288
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
289
-     */
290
-    public function delete_permanently($query_params, $allow_blocking = true)
291
-    {
292
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
293
-        return parent::delete_permanently($query_params, $allow_blocking);
294
-    }
295
-
296
-
297
-    /**
298
-     * Restores a particular item by its ID (primary key). Ignores the fact whether the item
299
-     * has been soft-deleted or not.
300
-     *
301
-     * @param mixed $ID int if primary key is an int, string otherwise
302
-     * @return boolean success
303
-     * @throws EE_Error
304
-     */
305
-    public function restore_by_ID($ID = false)
306
-    {
307
-        return $this->delete_or_restore_by_ID(false, $ID);
308
-    }
309
-
310
-
311
-    /**
312
-     * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
313
-     * this function will ignore whether the items have been soft-deleted or not.
314
-     *
315
-     * @param boolean $delete true for delete, false for restore
316
-     * @param mixed   $ID     int if primary key is an int, string otherwise
317
-     * @return bool
318
-     * @throws EE_Error
319
-     */
320
-    public function delete_or_restore_by_ID($delete = true, $ID = false)
321
-    {
322
-        // returns false if entity doesn't have an ID or if delete/restore action failed
323
-        return $ID && $this->delete_or_restore($delete, $this->alter_query_params_to_restrict_by_ID($ID));
324
-    }
325
-
326
-
327
-    /**
328
-     * Overrides parent's 'delete' method to instead do a soft delete on all rows that
329
-     * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been
330
-     * soft-deleted or not. Note: because this item will be soft-deleted only, doesn't block because of model
331
-     * dependencies
332
-     *
333
-     * @param array $query_params
334
-     * @param bool  $block_deletes
335
-     * @return bool
336
-     * @throws EE_Error
337
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
338
-     */
339
-    public function delete($query_params = [], $block_deletes = false)
340
-    {
341
-        // no matter what, we WON'T block soft deletes.
342
-        return $this->delete_or_restore(true, $query_params);
343
-    }
344
-
345
-
346
-    /**
347
-     * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default,
348
-     * trashed/soft-deleted items are ignored in queries. However, this particular function ignores whether the items
349
-     * have been soft-deleted or not.
350
-     *
351
-     * @param array $query_params
352
-     * @return bool
353
-     * @throws EE_Error
354
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
355
-     */
356
-    public function restore($query_params = [])
357
-    {
358
-        return $this->delete_or_restore(false, $query_params);
359
-    }
360
-
361
-
362
-    /**
363
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
364
-     *
365
-     * @param boolean $delete true to indicate deletion, false to indicate restoration
366
-     * @param array   $query_params
367
-     * @return boolean
368
-     * @throws EE_Error
369
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
370
-     */
371
-    public function delete_or_restore($delete = true, $query_params = [])
372
-    {
373
-        $deletedFlagFieldName = $this->deleted_field_name();
374
-        $query_params         = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
375
-        return (bool) $this->update([$deletedFlagFieldName => $delete], $query_params);
376
-    }
377
-
378
-
379
-    /**
380
-     * Updates all the items of this model which match the $query params, regardless of whether
381
-     * they've been soft-deleted or not
382
-     *
383
-     * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
384
-     * @param array   $query_params            like EEM_base::get_all's $query_params
385
-     * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
386
-     *                                         in this model's entity map according to $fields_n_values that match
387
-     *                                         $query_params. This obviously has some overhead, so you can disable it
388
-     *                                         by setting this to FALSE, but be aware that model objects being used
389
-     *                                         could get out-of-sync with the database
390
-     * @return int number of items updated
391
-     * @throws EE_Error
392
-     */
393
-    public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
394
-    {
395
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
396
-        return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
397
-    }
31
+	/**
32
+	 * @param string|null $timezone
33
+	 * @throws EE_Error
34
+	 */
35
+	protected function __construct(?string $timezone = '')
36
+	{
37
+		if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
38
+			$this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
39
+		}
40
+		parent::__construct($timezone);
41
+	}
42
+
43
+
44
+	/**
45
+	 * Searches for field on this model of type 'deleted_flag'. if it is found, returns it's name.
46
+	 *
47
+	 * @return string
48
+	 * @throws EE_Error
49
+	 */
50
+	public function deleted_field_name()
51
+	{
52
+		$field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
53
+		if ($field) {
54
+			return $field->get_name();
55
+		} else {
56
+			throw new EE_Error(
57
+				sprintf(
58
+					esc_html__(
59
+						'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
60
+						'event_espresso'
61
+					),
62
+					get_class($this),
63
+					get_class($this)
64
+				)
65
+			);
66
+		}
67
+	}
68
+
69
+
70
+	/**
71
+	 * Gets one item that's been deleted, according to $query_params
72
+	 *
73
+	 * @param array $query_params
74
+	 * @return EE_Soft_Delete_Base_Class
75
+	 * @throws EE_Error
76
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
77
+	 */
78
+	public function get_one_deleted($query_params = [])
79
+	{
80
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
81
+		return $this->get_one($query_params);
82
+	}
83
+
84
+
85
+	/**
86
+	 * Gets one item from the DB, regardless of whether it's been soft-deleted or not
87
+	 *
88
+	 * @param array $query_params like EEM_base::get_all's $query_params
89
+	 * @return EE_Soft_Delete_Base_Class
90
+	 * @throws EE_Error
91
+	 */
92
+	public function get_one_deleted_or_undeleted($query_params = [])
93
+	{
94
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
95
+		return $this->get_one($query_params);
96
+	}
97
+
98
+
99
+	/**
100
+	 * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
101
+	 *
102
+	 * @param int|string $id
103
+	 * @return EE_Soft_Delete_Base_Class
104
+	 * @throws EE_Error
105
+	 */
106
+	public function get_one_by_ID_but_ignore_deleted($id)
107
+	{
108
+		return $this->get_one(
109
+			$this->alter_query_params_to_restrict_by_ID(
110
+				$id,
111
+				['default_where_conditions' => 'default']
112
+			)
113
+		);
114
+	}
115
+
116
+
117
+	/**
118
+	 * Counts all the deleted/trashed items
119
+	 *
120
+	 * @param array  $query_params
121
+	 * @param string $field_to_count
122
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger
123
+	 *                             that by the setting $distinct to TRUE;
124
+	 * @return int
125
+	 * @throws EE_Error
126
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
127
+	 */
128
+	public function count_deleted($query_params = [], $field_to_count = null, $distinct = false)
129
+	{
130
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
131
+		return $this->count($query_params, $field_to_count, $distinct);
132
+	}
133
+
134
+
135
+	/**
136
+	 * Alters the query params so that only trashed/soft-deleted items are considered
137
+	 *
138
+	 * @param array $query_params
139
+	 * @return array
140
+	 * @throws EE_Error
141
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
142
+	 */
143
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
144
+	{
145
+		$deletedFlagFieldName                     = $this->deleted_field_name();
146
+		$query_params[0][ $deletedFlagFieldName ] = true;
147
+		return $query_params;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Alters the query params so that only trashed/soft-deleted items are considered
153
+	 *
154
+	 * @param array $query_params
155
+	 * @return array
156
+	 * @throws EE_Error
157
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
158
+	 */
159
+	public function alter_query_params_so_only_trashed_items_included($query_params)
160
+	{
161
+		return $this->_alter_query_params_so_only_trashed_items_included($query_params);
162
+	}
163
+
164
+
165
+	/**
166
+	 * Alters the query params so each item's deleted status is ignored.
167
+	 *
168
+	 * @param array $query_params
169
+	 * @return array
170
+	 */
171
+	public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = [])
172
+	{
173
+		return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
174
+	}
175
+
176
+
177
+	/**
178
+	 * Alters the query params so each item's deleted status is ignored.
179
+	 *
180
+	 * @param array $query_params
181
+	 * @return array
182
+	 */
183
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
184
+	{
185
+		if (! isset($query_params['default_where_conditions'])) {
186
+			$query_params['default_where_conditions'] = 'minimum';
187
+		}
188
+		return $query_params;
189
+	}
190
+
191
+
192
+	/**
193
+	 * Counts all deleted and undeleted items
194
+	 *
195
+	 * @param array  $query_params
196
+	 * @param string $field_to_count
197
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger
198
+	 *                             that by the setting $distinct to TRUE;
199
+	 * @return int
200
+	 * @throws EE_Error
201
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
202
+	 */
203
+	public function count_deleted_and_undeleted($query_params = [], $field_to_count = null, $distinct = false)
204
+	{
205
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
206
+		return $this->count($query_params, $field_to_count, $distinct);
207
+	}
208
+
209
+
210
+	/**
211
+	 * Sum all the deleted items.
212
+	 *
213
+	 * @param array  $query_params
214
+	 * @param string $field_to_sum
215
+	 * @return float
216
+	 * @throws EE_Error
217
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
218
+	 */
219
+	public function sum_deleted($query_params = [], $field_to_sum = null)
220
+	{
221
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
222
+		return $this->sum($query_params, $field_to_sum);
223
+	}
224
+
225
+
226
+	/**
227
+	 * Sums all the deleted and undeleted items.
228
+	 *
229
+	 * @param array  $query_params
230
+	 * @param string $field_to_sum
231
+	 * @return float
232
+	 * @throws EE_Error
233
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
234
+	 */
235
+	public function sum_deleted_and_undeleted($query_params = [], $field_to_sum = null)
236
+	{
237
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
238
+		return $this->sum($query_params, $field_to_sum);
239
+	}
240
+
241
+
242
+	/**
243
+	 * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
244
+	 * whether they've been soft-deleted or not
245
+	 *
246
+	 * @param array $query_params
247
+	 * @return EE_Soft_Delete_Base_Class[]
248
+	 * @throws EE_Error
249
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
250
+	 */
251
+	public function get_all_deleted_and_undeleted($query_params = [])
252
+	{
253
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
254
+		return $this->get_all($query_params);
255
+	}
256
+
257
+
258
+	/**
259
+	 * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
260
+	 *
261
+	 * @param array $query_params
262
+	 * @return EE_Soft_Delete_Base_Class[]
263
+	 * @throws EE_Error
264
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
265
+	 */
266
+	public function get_all_deleted($query_params = [])
267
+	{
268
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
269
+		return $this->get_all($query_params);
270
+	}
271
+
272
+
273
+	/**
274
+	 * Permanently deletes the selected rows. When selecting rows for deletion, ignores
275
+	 * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
276
+	 * before you can permanently delete them).
277
+	 * Because this will cause a real deletion, related models may block this deletion (ie, add an error
278
+	 * and abort the delete)
279
+	 *
280
+	 * @param array   $query_params
281
+	 * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
282
+	 *                                that blocks it (ie, there' sno other data that depends on this data);
283
+	 *                                if false, deletes regardless of other objects which may depend on it.
284
+	 *                                Its generally advisable to always leave this as TRUE,
285
+	 *                                otherwise you could easily corrupt your DB
286
+	 * @return int                    number of rows deleted
287
+	 * @throws EE_Error
288
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
289
+	 */
290
+	public function delete_permanently($query_params, $allow_blocking = true)
291
+	{
292
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
293
+		return parent::delete_permanently($query_params, $allow_blocking);
294
+	}
295
+
296
+
297
+	/**
298
+	 * Restores a particular item by its ID (primary key). Ignores the fact whether the item
299
+	 * has been soft-deleted or not.
300
+	 *
301
+	 * @param mixed $ID int if primary key is an int, string otherwise
302
+	 * @return boolean success
303
+	 * @throws EE_Error
304
+	 */
305
+	public function restore_by_ID($ID = false)
306
+	{
307
+		return $this->delete_or_restore_by_ID(false, $ID);
308
+	}
309
+
310
+
311
+	/**
312
+	 * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
313
+	 * this function will ignore whether the items have been soft-deleted or not.
314
+	 *
315
+	 * @param boolean $delete true for delete, false for restore
316
+	 * @param mixed   $ID     int if primary key is an int, string otherwise
317
+	 * @return bool
318
+	 * @throws EE_Error
319
+	 */
320
+	public function delete_or_restore_by_ID($delete = true, $ID = false)
321
+	{
322
+		// returns false if entity doesn't have an ID or if delete/restore action failed
323
+		return $ID && $this->delete_or_restore($delete, $this->alter_query_params_to_restrict_by_ID($ID));
324
+	}
325
+
326
+
327
+	/**
328
+	 * Overrides parent's 'delete' method to instead do a soft delete on all rows that
329
+	 * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been
330
+	 * soft-deleted or not. Note: because this item will be soft-deleted only, doesn't block because of model
331
+	 * dependencies
332
+	 *
333
+	 * @param array $query_params
334
+	 * @param bool  $block_deletes
335
+	 * @return bool
336
+	 * @throws EE_Error
337
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
338
+	 */
339
+	public function delete($query_params = [], $block_deletes = false)
340
+	{
341
+		// no matter what, we WON'T block soft deletes.
342
+		return $this->delete_or_restore(true, $query_params);
343
+	}
344
+
345
+
346
+	/**
347
+	 * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default,
348
+	 * trashed/soft-deleted items are ignored in queries. However, this particular function ignores whether the items
349
+	 * have been soft-deleted or not.
350
+	 *
351
+	 * @param array $query_params
352
+	 * @return bool
353
+	 * @throws EE_Error
354
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
355
+	 */
356
+	public function restore($query_params = [])
357
+	{
358
+		return $this->delete_or_restore(false, $query_params);
359
+	}
360
+
361
+
362
+	/**
363
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
364
+	 *
365
+	 * @param boolean $delete true to indicate deletion, false to indicate restoration
366
+	 * @param array   $query_params
367
+	 * @return boolean
368
+	 * @throws EE_Error
369
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
370
+	 */
371
+	public function delete_or_restore($delete = true, $query_params = [])
372
+	{
373
+		$deletedFlagFieldName = $this->deleted_field_name();
374
+		$query_params         = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
375
+		return (bool) $this->update([$deletedFlagFieldName => $delete], $query_params);
376
+	}
377
+
378
+
379
+	/**
380
+	 * Updates all the items of this model which match the $query params, regardless of whether
381
+	 * they've been soft-deleted or not
382
+	 *
383
+	 * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
384
+	 * @param array   $query_params            like EEM_base::get_all's $query_params
385
+	 * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
386
+	 *                                         in this model's entity map according to $fields_n_values that match
387
+	 *                                         $query_params. This obviously has some overhead, so you can disable it
388
+	 *                                         by setting this to FALSE, but be aware that model objects being used
389
+	 *                                         could get out-of-sync with the database
390
+	 * @return int number of items updated
391
+	 * @throws EE_Error
392
+	 */
393
+	public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
394
+	{
395
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
396
+		return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
397
+	}
398 398
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      */
35 35
     protected function __construct(?string $timezone = '')
36 36
     {
37
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
37
+        if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
38 38
             $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
39 39
         }
40 40
         parent::__construct($timezone);
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
     protected function _alter_query_params_so_only_trashed_items_included($query_params)
144 144
     {
145 145
         $deletedFlagFieldName                     = $this->deleted_field_name();
146
-        $query_params[0][ $deletedFlagFieldName ] = true;
146
+        $query_params[0][$deletedFlagFieldName] = true;
147 147
         return $query_params;
148 148
     }
149 149
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
184 184
     {
185
-        if (! isset($query_params['default_where_conditions'])) {
185
+        if ( ! isset($query_params['default_where_conditions'])) {
186 186
             $query_params['default_where_conditions'] = 'minimum';
187 187
         }
188 188
         return $query_params;
Please login to merge, or discard this patch.
core/db_models/EEM_Message.model.php 2 patches
Indentation   +664 added lines, -664 removed lines patch added patch discarded remove patch
@@ -12,674 +12,674 @@
 block discarded – undo
12 12
  */
13 13
 class EEM_Message extends EEM_Base implements EEI_Query_Filter
14 14
 {
15
-    // private instance of the Message object
16
-    protected static $_instance = null;
15
+	// private instance of the Message object
16
+	protected static $_instance = null;
17 17
 
18
-
19
-    /**
20
-     * This priority indicates a message should be generated and sent ASAP
21
-     *
22
-     * @type int
23
-     */
24
-    const priority_high = 10;
25
-
26
-
27
-    /**
28
-     * This priority indicates a message should be generated ASAP and queued for sending.
29
-     *
30
-     * @type
31
-     */
32
-    const priority_medium = 20;
33
-
34
-
35
-    /**
36
-     * This priority indicates a message should be queued for generating.
37
-     *
38
-     * @type int
39
-     */
40
-    const priority_low = 30;
41
-
42
-
43
-    /**
44
-     * indicates this message was sent at the time modified
45
-     */
46
-    const status_sent = 'MSN';
47
-
48
-
49
-    /**
50
-     * indicates this message is waiting to be sent
51
-     */
52
-    const status_idle = 'MID';
53
-
54
-
55
-    /**
56
-     * indicates an attempt was a made to send this message
57
-     * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
58
-     * appear to the end user.
59
-     */
60
-    const status_failed = 'MFL';
61
-
62
-
63
-    /**
64
-     * indicates the message has been flagged for resending (at the time modified).
65
-     */
66
-    const status_resend = 'MRS';
67
-
68
-
69
-    /**
70
-     * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
71
-     * this status when added to the queue.
72
-     */
73
-    const status_incomplete = 'MIC';
74
-
75
-
76
-    /**
77
-     * Indicates everything was generated fine for the message, however, the messenger was unable to send.
78
-     * This status means that its possible to retry sending the message.
79
-     */
80
-    const status_retry = 'MRT';
81
-
82
-
83
-    /**
84
-     * This is used for more informational messages that may not indicate anything is broken but still cannot be
85
-     * generated or sent correctly. An example of a message that would get flagged this way would be when a not
86
-     * approved message was queued for generation, but at time of generation, the attached registration(s) are
87
-     * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
88
-     * in the db and be viewable in the message activity list table when the messages system is in debug mode.
89
-     *
90
-     * @see EEM_Message::debug()
91
-     */
92
-    const status_debug_only = 'MDO';
93
-
94
-
95
-    /**
96
-     * This status is given to messages it is processed by the messenger send method.
97
-     * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
98
-     * indicative of a PHP timeout or memory limit issue.
99
-     */
100
-    const status_messenger_executing = 'MEX';
101
-
102
-
103
-    /**
104
-     * Private constructor to prevent direct creation.
105
-     *
106
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
107
-     *                              any incoming timezone data that gets saved).  Note this just sends the timezone
108
-     *                              info to the date time model field objects.  Default is null (and will be assumed
109
-     *                              using the set timezone in the 'timezone_string' wp option)
110
-     * @throws EE_Error
111
-     */
112
-    protected function __construct(?string $timezone = '')
113
-    {
114
-        $this->singular_item = esc_html__('Message', 'event_espresso');
115
-        $this->plural_item   = esc_html__('Messages', 'event_espresso');
116
-
117
-        $this->_tables = [
118
-            'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
119
-        ];
120
-
121
-        $allowed_priority = [
122
-            self::priority_high   => esc_html__('high', 'event_espresso'),
123
-            self::priority_medium => esc_html__('medium', 'event_espresso'),
124
-            self::priority_low    => esc_html__('low', 'event_espresso'),
125
-        ];
126
-
127
-        $this->_fields          = [
128
-            'Message' => [
129
-                'MSG_ID'             => new EE_Primary_Key_Int_Field(
130
-                    'MSG_ID', esc_html__('Message ID', 'event_espresso')
131
-                ),
132
-                'MSG_token'          => new EE_Plain_Text_Field(
133
-                    'MSG_token',
134
-                    esc_html__(
135
-                        'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
136
-                        'event_espresso'
137
-                    ),
138
-                    false,
139
-                    EEH_URL::generate_unique_token()
140
-                ),
141
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field(
142
-                    'GRP_ID',
143
-                    esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
144
-                    true,
145
-                    0,
146
-                    'Message_Template_Group'
147
-                ),
148
-                'TXN_ID'             => new EE_Foreign_Key_Int_Field(
149
-                    'TXN_ID',
150
-                    esc_html__(
151
-                        'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
152
-                        'event_espresso'
153
-                    ),
154
-                    true,
155
-                    0,
156
-                    'Transaction'
157
-                ),
158
-                'MSG_messenger'      => new EE_Plain_Text_Field(
159
-                    'MSG_messenger',
160
-                    esc_html__(
161
-                        'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
162
-                        'event_espresso'
163
-                    ),
164
-                    false,
165
-                    'email'
166
-                ),
167
-                'MSG_message_type'   => new EE_Plain_Text_Field(
168
-                    'MSG_message_type',
169
-                    esc_html__(
170
-                        'Corresponds to the EE_message_type::name used to generate this message.',
171
-                        'event_espresso'
172
-                    ),
173
-                    false,
174
-                    'receipt'
175
-                ),
176
-                'MSG_context'        => new EE_Plain_Text_Field(
177
-                    'MSG_context',
178
-                    esc_html__('Context', 'event_espresso'),
179
-                    false
180
-                ),
181
-                'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
182
-                    'MSG_recipient_ID',
183
-                    esc_html__('Recipient ID', 'event_espresso'),
184
-                    true,
185
-                    null,
186
-                    ['Registration', 'Attendee', 'WP_User']
187
-                ),
188
-                'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
189
-                    'MSG_recipient_type',
190
-                    esc_html__('Recipient Type', 'event_espresso'),
191
-                    true,
192
-                    null,
193
-                    ['Registration', 'Attendee', 'WP_User']
194
-                ),
195
-                'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
196
-                    'MSG_content',
197
-                    esc_html__('Content', 'event_espresso'),
198
-                    true,
199
-                    ''
200
-                ),
201
-                'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
202
-                    'MSG_to',
203
-                    esc_html__('Address To', 'event_espresso'),
204
-                    true
205
-                ),
206
-                'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
207
-                    'MSG_from',
208
-                    esc_html__('Address From', 'event_espresso'),
209
-                    true
210
-                ),
211
-                'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
212
-                    'MSG_subject',
213
-                    esc_html__('Subject', 'event_espresso'),
214
-                    true,
215
-                    ''
216
-                ),
217
-                'MSG_priority'       => new EE_Enum_Integer_Field(
218
-                    'MSG_priority',
219
-                    esc_html__('Priority', 'event_espresso'),
220
-                    false,
221
-                    self::priority_low,
222
-                    $allowed_priority
223
-                ),
224
-                'STS_ID'             => new EE_Foreign_Key_String_Field(
225
-                    'STS_ID',
226
-                    esc_html__('Status', 'event_espresso'),
227
-                    false,
228
-                    self::status_incomplete,
229
-                    'Status'
230
-                ),
231
-                'MSG_created'        => new EE_Datetime_Field(
232
-                    'MSG_created',
233
-                    esc_html__('Created', 'event_espresso'),
234
-                    false,
235
-                    EE_Datetime_Field::now
236
-                ),
237
-                'MSG_modified'       => new EE_Datetime_Field(
238
-                    'MSG_modified',
239
-                    esc_html__('Modified', 'event_espresso'),
240
-                    true,
241
-                    EE_Datetime_Field::now
242
-                ),
243
-            ],
244
-        ];
245
-        $this->_model_relations = [
246
-            'Attendee'               => new EE_Belongs_To_Any_Relation(),
247
-            'Registration'           => new EE_Belongs_To_Any_Relation(),
248
-            'WP_User'                => new EE_Belongs_To_Any_Relation(),
249
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
250
-            'Transaction'            => new EE_Belongs_To_Relation(),
251
-        ];
252
-        parent::__construct($timezone);
253
-    }
254
-
255
-
256
-    /**
257
-     * @return EE_Message
258
-     * @throws EE_Error
259
-     */
260
-    public function create_default_object()
261
-    {
262
-        /** @type EE_Message $message */
263
-        $message = parent::create_default_object();
264
-        if ($message instanceof EE_Message) {
265
-            return EE_Message_Factory::set_messenger_and_message_type($message);
266
-        }
267
-        return null;
268
-    }
269
-
270
-
271
-    /**
272
-     * @param mixed $cols_n_values
273
-     * @return EE_Message
274
-     * @throws EE_Error
275
-     * @throws EE_Error
276
-     */
277
-    public function instantiate_class_from_array_or_object($cols_n_values)
278
-    {
279
-        /** @type EE_Message $message */
280
-        $message = parent::instantiate_class_from_array_or_object($cols_n_values);
281
-        if ($message instanceof EE_Message) {
282
-            return EE_Message_Factory::set_messenger_and_message_type($message);
283
-        }
284
-        return null;
285
-    }
286
-
287
-
288
-    /**
289
-     * Returns whether or not a message of that type was sent for a given attendee.
290
-     *
291
-     * @param EE_Attendee|int $attendee
292
-     * @param string          $message_type the message type slug
293
-     * @return boolean
294
-     * @throws EE_Error
295
-     * @throws EE_Error
296
-     * @throws EE_Error
297
-     */
298
-    public function message_sent_for_attendee($attendee, $message_type)
299
-    {
300
-        $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
301
-        return $this->exists(
302
-            [
303
-                [
304
-                    'Attendee.ATT_ID'  => $attendee_ID,
305
-                    'MSG_message_type' => $message_type,
306
-                    'STS_ID'           => ['IN', $this->stati_indicating_sent()],
307
-                ],
308
-            ]
309
-        );
310
-    }
311
-
312
-
313
-    /**
314
-     * Returns whether or not a message of that type was sent for a given registration
315
-     *
316
-     * @param EE_Registration|int $registration
317
-     * @param string              $message_type the message type slug
318
-     * @return boolean
319
-     * @throws EE_Error
320
-     * @throws EE_Error
321
-     * @throws EE_Error
322
-     */
323
-    public function message_sent_for_registration($registration, $message_type)
324
-    {
325
-        $registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
326
-        return $this->exists(
327
-            [
328
-                [
329
-                    'Registration.REG_ID' => $registrationID,
330
-                    'MSG_message_type'    => $message_type,
331
-                    'STS_ID'              => ['IN', $this->stati_indicating_sent()],
332
-                ],
333
-            ]
334
-        );
335
-    }
336
-
337
-
338
-    /**
339
-     * This retrieves an EE_Message object from the db matching the given token string.
340
-     *
341
-     * @param string $token
342
-     * @return EE_Message
343
-     * @throws EE_Error
344
-     */
345
-    public function get_one_by_token($token)
346
-    {
347
-        return $this->get_one(
348
-            [
349
-                [
350
-                    'MSG_token' => $token,
351
-                ],
352
-            ]
353
-        );
354
-    }
355
-
356
-
357
-    /**
358
-     * Returns stati that indicate the message HAS been sent
359
-     *
360
-     * @return array of strings for possible stati
361
-     */
362
-    public function stati_indicating_sent()
363
-    {
364
-        return apply_filters('FHEE__EEM_Message__stati_indicating_sent', [self::status_sent]);
365
-    }
366
-
367
-
368
-    /**
369
-     * Returns stati that indicate the message is waiting to be sent.
370
-     *
371
-     * @return array of strings for possible stati.
372
-     */
373
-    public function stati_indicating_to_send()
374
-    {
375
-        return apply_filters(
376
-            'FHEE__EEM_Message__stati_indicating_to_send',
377
-            [self::status_idle, self::status_resend]
378
-        );
379
-    }
380
-
381
-
382
-    /**
383
-     * Returns stati that indicate the message has failed sending
384
-     *
385
-     * @return array  array of strings for possible stati.
386
-     */
387
-    public function stati_indicating_failed_sending()
388
-    {
389
-        $failed_stati = [
390
-            self::status_failed,
391
-            self::status_retry,
392
-            self::status_messenger_executing,
393
-        ];
394
-        // if WP_DEBUG is set, then let's include debug_only fails
395
-        if (WP_DEBUG) {
396
-            $failed_stati[] = self::status_debug_only;
397
-        }
398
-        return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
399
-    }
400
-
401
-
402
-    /**
403
-     * Returns filterable array of all EEM_Message statuses.
404
-     *
405
-     * @return array
406
-     */
407
-    public function all_statuses()
408
-    {
409
-        return apply_filters(
410
-            'FHEE__EEM_Message__all_statuses',
411
-            [
412
-                EEM_Message::status_sent,
413
-                EEM_Message::status_incomplete,
414
-                EEM_Message::status_idle,
415
-                EEM_Message::status_resend,
416
-                EEM_Message::status_retry,
417
-                EEM_Message::status_failed,
418
-                EEM_Message::status_messenger_executing,
419
-                EEM_Message::status_debug_only,
420
-            ]
421
-        );
422
-    }
423
-
424
-
425
-    /**
426
-     * Detects any specific query variables in the request and uses those to setup appropriate
427
-     * filter for any queries.
428
-     *
429
-     * @return array
430
-     */
431
-    public function filter_by_query_params()
432
-    {
433
-        /** @var RequestInterface $request */
434
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
435
-        // expected possible query_vars, the key in this array matches an expected key in the request,
436
-        // the value, matches the corresponding EEM_Base child reference.
437
-        $expected_vars   = $this->_expected_vars_for_query_inject();
438
-        $query_params[0] = [];
439
-        foreach ($expected_vars as $request_key => $model_name) {
440
-            $request_value = $request->getRequestParam($request_key);
441
-            if ($request_value) {
442
-                // special case
443
-                switch ($request_key) {
444
-                    case '_REG_ID':
445
-                        $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = [
446
-                            'Transaction.Registration.REG_ID' => $request_value,
447
-                        ];
448
-                        break;
449
-                    case 'EVT_ID':
450
-                        $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = [
451
-                            'Transaction.Registration.EVT_ID' => $request_value,
452
-                        ];
453
-                        break;
454
-                    default:
455
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] =
456
-                            $request_value;
457
-                        break;
458
-                }
459
-            }
460
-        }
461
-        return $query_params;
462
-    }
463
-
464
-
465
-    /**
466
-     * @return string
467
-     * @throws EE_Error
468
-     * @throws ReflectionException
469
-     */
470
-    public function get_pretty_label_for_results()
471
-    {
472
-        /** @var RequestInterface $request */
473
-        $request       = EEM_Base::$loader->getShared(RequestInterface::class);
474
-        $expected_vars = $this->_expected_vars_for_query_inject();
475
-        $pretty_label  = '';
476
-        $label_parts   = [];
477
-        foreach ($expected_vars as $request_key => $model_name) {
478
-            $model_name        = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
479
-            $model             = EEM_Base::$loader->getShared($model_name);
480
-            $model_field_value = $request->getRequestParam($request_key);
481
-            if ($model instanceof EEM_Base && $model_field_value !== '') {
482
-                switch ($request_key) {
483
-                    case '_REG_ID':
484
-                        $label_parts[] = sprintf(
485
-                            esc_html__('Registration with the ID: %s', 'event_espresso'),
486
-                            $model_field_value
487
-                        );
488
-                        break;
489
-                    case 'ATT_ID':
490
-                        /** @var EE_Attendee $attendee */
491
-                        $attendee      = $model->get_one_by_ID($model_field_value);
492
-                        $label_parts[] = $attendee instanceof EE_Attendee
493
-                            ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
494
-                            : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
495
-                        break;
496
-                    case 'ID':
497
-                        /** @var EE_WP_User $wpUser */
498
-                        $wpUser        = $model->get_one_by_ID($model_field_value);
499
-                        $label_parts[] = $wpUser instanceof EE_WP_User
500
-                            ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
501
-                            : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
502
-                        break;
503
-                    case 'TXN_ID':
504
-                        $label_parts[] = sprintf(
505
-                            esc_html__('Transaction with the ID: %s', 'event_espresso'),
506
-                            $model_field_value
507
-                        );
508
-                        break;
509
-                    case 'EVT_ID':
510
-                        /** @var EE_Event $Event */
511
-                        $Event         = $model->get_one_by_ID($model_field_value);
512
-                        $label_parts[] = $Event instanceof EE_Event
513
-                            ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
514
-                            : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
515
-                        break;
516
-                }
517
-            }
518
-        }
519
-
520
-        if ($label_parts) {
521
-            // prepend to the last element of $label_parts an "and".
522
-            if (count($label_parts) > 1) {
523
-                $label_parts_index_to_prepend                 = count($label_parts) - 1;
524
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
525
-            }
526
-
527
-            $pretty_label .= sprintf(
528
-                esc_html_x(
529
-                    'Showing messages for %s',
530
-                    'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
531
-                    'event_espresso'
532
-                ),
533
-                implode(', ', $label_parts)
534
-            );
535
-        }
536
-        return $pretty_label;
537
-    }
538
-
539
-
540
-    /**
541
-     * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
542
-     * The array is in the format:
543
-     * array(
544
-     *  {$field_name} => {$model_name}
545
-     * );
546
-     *
547
-     * @return array
548
-     * @since 4.9.0
549
-     */
550
-    protected function _expected_vars_for_query_inject()
551
-    {
552
-        return [
553
-            '_REG_ID' => 'Registration',
554
-            'ATT_ID'  => 'Attendee',
555
-            'ID'      => 'WP_User',
556
-            'TXN_ID'  => 'Transaction',
557
-            'EVT_ID'  => 'Event',
558
-        ];
559
-    }
560
-
561
-
562
-    /**
563
-     * This returns whether EEM_Message is in debug mode or not.
564
-     * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
565
-     * generating/sending messages. Debug mode can be set by either:
566
-     * 1. Sending in a value for the $set_debug argument
567
-     * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
568
-     * 3. Overriding the above via the provided filter.
569
-     *
570
-     * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
571
-     *                                  provided boolean. When no argument is provided (default null) then the debug
572
-     *                                  mode will be returned.
573
-     * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
574
-     */
575
-    public static function debug($set_debug = null)
576
-    {
577
-        static $is_debugging = null;
578
-
579
-        // initialize (use constant if set).
580
-        if (is_null($set_debug) && is_null($is_debugging)) {
581
-            $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
582
-        }
583
-
584
-        if (! is_null($set_debug)) {
585
-            $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
586
-        }
587
-
588
-        // return filtered value
589
-        return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
590
-    }
591
-
592
-
593
-    /**
594
-     * Deletes old messages meeting certain criteria for removal from the database.
595
-     * By default, this will delete messages that:
596
-     * - are older than the value of the delete_threshold in months.
597
-     * - have a STS_ID other than EEM_Message::status_idle
598
-     *
599
-     * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
600
-     *                              months.
601
-     * @return bool|false|int Either the number of records affected or false if there was an error (you can call
602
-     *                              $wpdb->last_error to find out what the error was.
603
-     * @throws EE_Error
604
-     * @throws EE_Error
605
-     * @throws EE_Error
606
-     */
607
-    public function delete_old_messages($delete_threshold = 6)
608
-    {
609
-        $number_deleted = 0;
610
-        /**
611
-         * Allows code to change the boundary for what messages are kept.
612
-         * Uses the value of the `delete_threshold` variable by default.
613
-         *
614
-         * @param int $seconds seconds that will be subtracted from the timestamp for now.
615
-         * @return int
616
-         */
617
-        $time_to_leave_alone = absint(
618
-            apply_filters(
619
-                'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
620
-                ((int) $delete_threshold) * MONTH_IN_SECONDS
621
-            )
622
-        );
623
-
624
-
625
-        /**
626
-         * Allows code to change what message stati are ignored when deleting.
627
-         * Defaults to only ignore EEM_Message::status_idle messages.
628
-         *
629
-         * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting.
630
-         */
631
-        $message_stati_to_keep = (array) apply_filters(
632
-            'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
633
-            [
634
-                EEM_Message::status_idle,
635
-            ]
636
-        );
637
-
638
-        // first get all the ids of messages being deleted
639
-        $message_ids_to_delete = EEM_Message::instance()->get_col(
640
-            [
641
-                0       => [
642
-                    'STS_ID'       => ['NOT_IN', $message_stati_to_keep],
643
-                    'MSG_modified' => ['<', time() - $time_to_leave_alone],
644
-                ],
645
-                'limit' => apply_filters(
646
-                    'EEM_Message__delete_old_messages__limit',
647
-                    2000,
648
-                    $delete_threshold
649
-                ),
650
-            ]
651
-        );
652
-
653
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
654
-            global $wpdb;
655
-            $number_deleted = $wpdb->query(
656
-                '
18
+
19
+	/**
20
+	 * This priority indicates a message should be generated and sent ASAP
21
+	 *
22
+	 * @type int
23
+	 */
24
+	const priority_high = 10;
25
+
26
+
27
+	/**
28
+	 * This priority indicates a message should be generated ASAP and queued for sending.
29
+	 *
30
+	 * @type
31
+	 */
32
+	const priority_medium = 20;
33
+
34
+
35
+	/**
36
+	 * This priority indicates a message should be queued for generating.
37
+	 *
38
+	 * @type int
39
+	 */
40
+	const priority_low = 30;
41
+
42
+
43
+	/**
44
+	 * indicates this message was sent at the time modified
45
+	 */
46
+	const status_sent = 'MSN';
47
+
48
+
49
+	/**
50
+	 * indicates this message is waiting to be sent
51
+	 */
52
+	const status_idle = 'MID';
53
+
54
+
55
+	/**
56
+	 * indicates an attempt was a made to send this message
57
+	 * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
58
+	 * appear to the end user.
59
+	 */
60
+	const status_failed = 'MFL';
61
+
62
+
63
+	/**
64
+	 * indicates the message has been flagged for resending (at the time modified).
65
+	 */
66
+	const status_resend = 'MRS';
67
+
68
+
69
+	/**
70
+	 * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
71
+	 * this status when added to the queue.
72
+	 */
73
+	const status_incomplete = 'MIC';
74
+
75
+
76
+	/**
77
+	 * Indicates everything was generated fine for the message, however, the messenger was unable to send.
78
+	 * This status means that its possible to retry sending the message.
79
+	 */
80
+	const status_retry = 'MRT';
81
+
82
+
83
+	/**
84
+	 * This is used for more informational messages that may not indicate anything is broken but still cannot be
85
+	 * generated or sent correctly. An example of a message that would get flagged this way would be when a not
86
+	 * approved message was queued for generation, but at time of generation, the attached registration(s) are
87
+	 * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
88
+	 * in the db and be viewable in the message activity list table when the messages system is in debug mode.
89
+	 *
90
+	 * @see EEM_Message::debug()
91
+	 */
92
+	const status_debug_only = 'MDO';
93
+
94
+
95
+	/**
96
+	 * This status is given to messages it is processed by the messenger send method.
97
+	 * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
98
+	 * indicative of a PHP timeout or memory limit issue.
99
+	 */
100
+	const status_messenger_executing = 'MEX';
101
+
102
+
103
+	/**
104
+	 * Private constructor to prevent direct creation.
105
+	 *
106
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
107
+	 *                              any incoming timezone data that gets saved).  Note this just sends the timezone
108
+	 *                              info to the date time model field objects.  Default is null (and will be assumed
109
+	 *                              using the set timezone in the 'timezone_string' wp option)
110
+	 * @throws EE_Error
111
+	 */
112
+	protected function __construct(?string $timezone = '')
113
+	{
114
+		$this->singular_item = esc_html__('Message', 'event_espresso');
115
+		$this->plural_item   = esc_html__('Messages', 'event_espresso');
116
+
117
+		$this->_tables = [
118
+			'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
119
+		];
120
+
121
+		$allowed_priority = [
122
+			self::priority_high   => esc_html__('high', 'event_espresso'),
123
+			self::priority_medium => esc_html__('medium', 'event_espresso'),
124
+			self::priority_low    => esc_html__('low', 'event_espresso'),
125
+		];
126
+
127
+		$this->_fields          = [
128
+			'Message' => [
129
+				'MSG_ID'             => new EE_Primary_Key_Int_Field(
130
+					'MSG_ID', esc_html__('Message ID', 'event_espresso')
131
+				),
132
+				'MSG_token'          => new EE_Plain_Text_Field(
133
+					'MSG_token',
134
+					esc_html__(
135
+						'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
136
+						'event_espresso'
137
+					),
138
+					false,
139
+					EEH_URL::generate_unique_token()
140
+				),
141
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field(
142
+					'GRP_ID',
143
+					esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
144
+					true,
145
+					0,
146
+					'Message_Template_Group'
147
+				),
148
+				'TXN_ID'             => new EE_Foreign_Key_Int_Field(
149
+					'TXN_ID',
150
+					esc_html__(
151
+						'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
152
+						'event_espresso'
153
+					),
154
+					true,
155
+					0,
156
+					'Transaction'
157
+				),
158
+				'MSG_messenger'      => new EE_Plain_Text_Field(
159
+					'MSG_messenger',
160
+					esc_html__(
161
+						'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
162
+						'event_espresso'
163
+					),
164
+					false,
165
+					'email'
166
+				),
167
+				'MSG_message_type'   => new EE_Plain_Text_Field(
168
+					'MSG_message_type',
169
+					esc_html__(
170
+						'Corresponds to the EE_message_type::name used to generate this message.',
171
+						'event_espresso'
172
+					),
173
+					false,
174
+					'receipt'
175
+				),
176
+				'MSG_context'        => new EE_Plain_Text_Field(
177
+					'MSG_context',
178
+					esc_html__('Context', 'event_espresso'),
179
+					false
180
+				),
181
+				'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
182
+					'MSG_recipient_ID',
183
+					esc_html__('Recipient ID', 'event_espresso'),
184
+					true,
185
+					null,
186
+					['Registration', 'Attendee', 'WP_User']
187
+				),
188
+				'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
189
+					'MSG_recipient_type',
190
+					esc_html__('Recipient Type', 'event_espresso'),
191
+					true,
192
+					null,
193
+					['Registration', 'Attendee', 'WP_User']
194
+				),
195
+				'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
196
+					'MSG_content',
197
+					esc_html__('Content', 'event_espresso'),
198
+					true,
199
+					''
200
+				),
201
+				'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
202
+					'MSG_to',
203
+					esc_html__('Address To', 'event_espresso'),
204
+					true
205
+				),
206
+				'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
207
+					'MSG_from',
208
+					esc_html__('Address From', 'event_espresso'),
209
+					true
210
+				),
211
+				'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
212
+					'MSG_subject',
213
+					esc_html__('Subject', 'event_espresso'),
214
+					true,
215
+					''
216
+				),
217
+				'MSG_priority'       => new EE_Enum_Integer_Field(
218
+					'MSG_priority',
219
+					esc_html__('Priority', 'event_espresso'),
220
+					false,
221
+					self::priority_low,
222
+					$allowed_priority
223
+				),
224
+				'STS_ID'             => new EE_Foreign_Key_String_Field(
225
+					'STS_ID',
226
+					esc_html__('Status', 'event_espresso'),
227
+					false,
228
+					self::status_incomplete,
229
+					'Status'
230
+				),
231
+				'MSG_created'        => new EE_Datetime_Field(
232
+					'MSG_created',
233
+					esc_html__('Created', 'event_espresso'),
234
+					false,
235
+					EE_Datetime_Field::now
236
+				),
237
+				'MSG_modified'       => new EE_Datetime_Field(
238
+					'MSG_modified',
239
+					esc_html__('Modified', 'event_espresso'),
240
+					true,
241
+					EE_Datetime_Field::now
242
+				),
243
+			],
244
+		];
245
+		$this->_model_relations = [
246
+			'Attendee'               => new EE_Belongs_To_Any_Relation(),
247
+			'Registration'           => new EE_Belongs_To_Any_Relation(),
248
+			'WP_User'                => new EE_Belongs_To_Any_Relation(),
249
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
250
+			'Transaction'            => new EE_Belongs_To_Relation(),
251
+		];
252
+		parent::__construct($timezone);
253
+	}
254
+
255
+
256
+	/**
257
+	 * @return EE_Message
258
+	 * @throws EE_Error
259
+	 */
260
+	public function create_default_object()
261
+	{
262
+		/** @type EE_Message $message */
263
+		$message = parent::create_default_object();
264
+		if ($message instanceof EE_Message) {
265
+			return EE_Message_Factory::set_messenger_and_message_type($message);
266
+		}
267
+		return null;
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param mixed $cols_n_values
273
+	 * @return EE_Message
274
+	 * @throws EE_Error
275
+	 * @throws EE_Error
276
+	 */
277
+	public function instantiate_class_from_array_or_object($cols_n_values)
278
+	{
279
+		/** @type EE_Message $message */
280
+		$message = parent::instantiate_class_from_array_or_object($cols_n_values);
281
+		if ($message instanceof EE_Message) {
282
+			return EE_Message_Factory::set_messenger_and_message_type($message);
283
+		}
284
+		return null;
285
+	}
286
+
287
+
288
+	/**
289
+	 * Returns whether or not a message of that type was sent for a given attendee.
290
+	 *
291
+	 * @param EE_Attendee|int $attendee
292
+	 * @param string          $message_type the message type slug
293
+	 * @return boolean
294
+	 * @throws EE_Error
295
+	 * @throws EE_Error
296
+	 * @throws EE_Error
297
+	 */
298
+	public function message_sent_for_attendee($attendee, $message_type)
299
+	{
300
+		$attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
301
+		return $this->exists(
302
+			[
303
+				[
304
+					'Attendee.ATT_ID'  => $attendee_ID,
305
+					'MSG_message_type' => $message_type,
306
+					'STS_ID'           => ['IN', $this->stati_indicating_sent()],
307
+				],
308
+			]
309
+		);
310
+	}
311
+
312
+
313
+	/**
314
+	 * Returns whether or not a message of that type was sent for a given registration
315
+	 *
316
+	 * @param EE_Registration|int $registration
317
+	 * @param string              $message_type the message type slug
318
+	 * @return boolean
319
+	 * @throws EE_Error
320
+	 * @throws EE_Error
321
+	 * @throws EE_Error
322
+	 */
323
+	public function message_sent_for_registration($registration, $message_type)
324
+	{
325
+		$registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
326
+		return $this->exists(
327
+			[
328
+				[
329
+					'Registration.REG_ID' => $registrationID,
330
+					'MSG_message_type'    => $message_type,
331
+					'STS_ID'              => ['IN', $this->stati_indicating_sent()],
332
+				],
333
+			]
334
+		);
335
+	}
336
+
337
+
338
+	/**
339
+	 * This retrieves an EE_Message object from the db matching the given token string.
340
+	 *
341
+	 * @param string $token
342
+	 * @return EE_Message
343
+	 * @throws EE_Error
344
+	 */
345
+	public function get_one_by_token($token)
346
+	{
347
+		return $this->get_one(
348
+			[
349
+				[
350
+					'MSG_token' => $token,
351
+				],
352
+			]
353
+		);
354
+	}
355
+
356
+
357
+	/**
358
+	 * Returns stati that indicate the message HAS been sent
359
+	 *
360
+	 * @return array of strings for possible stati
361
+	 */
362
+	public function stati_indicating_sent()
363
+	{
364
+		return apply_filters('FHEE__EEM_Message__stati_indicating_sent', [self::status_sent]);
365
+	}
366
+
367
+
368
+	/**
369
+	 * Returns stati that indicate the message is waiting to be sent.
370
+	 *
371
+	 * @return array of strings for possible stati.
372
+	 */
373
+	public function stati_indicating_to_send()
374
+	{
375
+		return apply_filters(
376
+			'FHEE__EEM_Message__stati_indicating_to_send',
377
+			[self::status_idle, self::status_resend]
378
+		);
379
+	}
380
+
381
+
382
+	/**
383
+	 * Returns stati that indicate the message has failed sending
384
+	 *
385
+	 * @return array  array of strings for possible stati.
386
+	 */
387
+	public function stati_indicating_failed_sending()
388
+	{
389
+		$failed_stati = [
390
+			self::status_failed,
391
+			self::status_retry,
392
+			self::status_messenger_executing,
393
+		];
394
+		// if WP_DEBUG is set, then let's include debug_only fails
395
+		if (WP_DEBUG) {
396
+			$failed_stati[] = self::status_debug_only;
397
+		}
398
+		return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
399
+	}
400
+
401
+
402
+	/**
403
+	 * Returns filterable array of all EEM_Message statuses.
404
+	 *
405
+	 * @return array
406
+	 */
407
+	public function all_statuses()
408
+	{
409
+		return apply_filters(
410
+			'FHEE__EEM_Message__all_statuses',
411
+			[
412
+				EEM_Message::status_sent,
413
+				EEM_Message::status_incomplete,
414
+				EEM_Message::status_idle,
415
+				EEM_Message::status_resend,
416
+				EEM_Message::status_retry,
417
+				EEM_Message::status_failed,
418
+				EEM_Message::status_messenger_executing,
419
+				EEM_Message::status_debug_only,
420
+			]
421
+		);
422
+	}
423
+
424
+
425
+	/**
426
+	 * Detects any specific query variables in the request and uses those to setup appropriate
427
+	 * filter for any queries.
428
+	 *
429
+	 * @return array
430
+	 */
431
+	public function filter_by_query_params()
432
+	{
433
+		/** @var RequestInterface $request */
434
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
435
+		// expected possible query_vars, the key in this array matches an expected key in the request,
436
+		// the value, matches the corresponding EEM_Base child reference.
437
+		$expected_vars   = $this->_expected_vars_for_query_inject();
438
+		$query_params[0] = [];
439
+		foreach ($expected_vars as $request_key => $model_name) {
440
+			$request_value = $request->getRequestParam($request_key);
441
+			if ($request_value) {
442
+				// special case
443
+				switch ($request_key) {
444
+					case '_REG_ID':
445
+						$query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = [
446
+							'Transaction.Registration.REG_ID' => $request_value,
447
+						];
448
+						break;
449
+					case 'EVT_ID':
450
+						$query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = [
451
+							'Transaction.Registration.EVT_ID' => $request_value,
452
+						];
453
+						break;
454
+					default:
455
+						$query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] =
456
+							$request_value;
457
+						break;
458
+				}
459
+			}
460
+		}
461
+		return $query_params;
462
+	}
463
+
464
+
465
+	/**
466
+	 * @return string
467
+	 * @throws EE_Error
468
+	 * @throws ReflectionException
469
+	 */
470
+	public function get_pretty_label_for_results()
471
+	{
472
+		/** @var RequestInterface $request */
473
+		$request       = EEM_Base::$loader->getShared(RequestInterface::class);
474
+		$expected_vars = $this->_expected_vars_for_query_inject();
475
+		$pretty_label  = '';
476
+		$label_parts   = [];
477
+		foreach ($expected_vars as $request_key => $model_name) {
478
+			$model_name        = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
479
+			$model             = EEM_Base::$loader->getShared($model_name);
480
+			$model_field_value = $request->getRequestParam($request_key);
481
+			if ($model instanceof EEM_Base && $model_field_value !== '') {
482
+				switch ($request_key) {
483
+					case '_REG_ID':
484
+						$label_parts[] = sprintf(
485
+							esc_html__('Registration with the ID: %s', 'event_espresso'),
486
+							$model_field_value
487
+						);
488
+						break;
489
+					case 'ATT_ID':
490
+						/** @var EE_Attendee $attendee */
491
+						$attendee      = $model->get_one_by_ID($model_field_value);
492
+						$label_parts[] = $attendee instanceof EE_Attendee
493
+							? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
494
+							: sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
495
+						break;
496
+					case 'ID':
497
+						/** @var EE_WP_User $wpUser */
498
+						$wpUser        = $model->get_one_by_ID($model_field_value);
499
+						$label_parts[] = $wpUser instanceof EE_WP_User
500
+							? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
501
+							: sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
502
+						break;
503
+					case 'TXN_ID':
504
+						$label_parts[] = sprintf(
505
+							esc_html__('Transaction with the ID: %s', 'event_espresso'),
506
+							$model_field_value
507
+						);
508
+						break;
509
+					case 'EVT_ID':
510
+						/** @var EE_Event $Event */
511
+						$Event         = $model->get_one_by_ID($model_field_value);
512
+						$label_parts[] = $Event instanceof EE_Event
513
+							? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
514
+							: sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
515
+						break;
516
+				}
517
+			}
518
+		}
519
+
520
+		if ($label_parts) {
521
+			// prepend to the last element of $label_parts an "and".
522
+			if (count($label_parts) > 1) {
523
+				$label_parts_index_to_prepend                 = count($label_parts) - 1;
524
+				$label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
525
+			}
526
+
527
+			$pretty_label .= sprintf(
528
+				esc_html_x(
529
+					'Showing messages for %s',
530
+					'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
531
+					'event_espresso'
532
+				),
533
+				implode(', ', $label_parts)
534
+			);
535
+		}
536
+		return $pretty_label;
537
+	}
538
+
539
+
540
+	/**
541
+	 * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
542
+	 * The array is in the format:
543
+	 * array(
544
+	 *  {$field_name} => {$model_name}
545
+	 * );
546
+	 *
547
+	 * @return array
548
+	 * @since 4.9.0
549
+	 */
550
+	protected function _expected_vars_for_query_inject()
551
+	{
552
+		return [
553
+			'_REG_ID' => 'Registration',
554
+			'ATT_ID'  => 'Attendee',
555
+			'ID'      => 'WP_User',
556
+			'TXN_ID'  => 'Transaction',
557
+			'EVT_ID'  => 'Event',
558
+		];
559
+	}
560
+
561
+
562
+	/**
563
+	 * This returns whether EEM_Message is in debug mode or not.
564
+	 * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
565
+	 * generating/sending messages. Debug mode can be set by either:
566
+	 * 1. Sending in a value for the $set_debug argument
567
+	 * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
568
+	 * 3. Overriding the above via the provided filter.
569
+	 *
570
+	 * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
571
+	 *                                  provided boolean. When no argument is provided (default null) then the debug
572
+	 *                                  mode will be returned.
573
+	 * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
574
+	 */
575
+	public static function debug($set_debug = null)
576
+	{
577
+		static $is_debugging = null;
578
+
579
+		// initialize (use constant if set).
580
+		if (is_null($set_debug) && is_null($is_debugging)) {
581
+			$is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
582
+		}
583
+
584
+		if (! is_null($set_debug)) {
585
+			$is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
586
+		}
587
+
588
+		// return filtered value
589
+		return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
590
+	}
591
+
592
+
593
+	/**
594
+	 * Deletes old messages meeting certain criteria for removal from the database.
595
+	 * By default, this will delete messages that:
596
+	 * - are older than the value of the delete_threshold in months.
597
+	 * - have a STS_ID other than EEM_Message::status_idle
598
+	 *
599
+	 * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
600
+	 *                              months.
601
+	 * @return bool|false|int Either the number of records affected or false if there was an error (you can call
602
+	 *                              $wpdb->last_error to find out what the error was.
603
+	 * @throws EE_Error
604
+	 * @throws EE_Error
605
+	 * @throws EE_Error
606
+	 */
607
+	public function delete_old_messages($delete_threshold = 6)
608
+	{
609
+		$number_deleted = 0;
610
+		/**
611
+		 * Allows code to change the boundary for what messages are kept.
612
+		 * Uses the value of the `delete_threshold` variable by default.
613
+		 *
614
+		 * @param int $seconds seconds that will be subtracted from the timestamp for now.
615
+		 * @return int
616
+		 */
617
+		$time_to_leave_alone = absint(
618
+			apply_filters(
619
+				'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
620
+				((int) $delete_threshold) * MONTH_IN_SECONDS
621
+			)
622
+		);
623
+
624
+
625
+		/**
626
+		 * Allows code to change what message stati are ignored when deleting.
627
+		 * Defaults to only ignore EEM_Message::status_idle messages.
628
+		 *
629
+		 * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting.
630
+		 */
631
+		$message_stati_to_keep = (array) apply_filters(
632
+			'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
633
+			[
634
+				EEM_Message::status_idle,
635
+			]
636
+		);
637
+
638
+		// first get all the ids of messages being deleted
639
+		$message_ids_to_delete = EEM_Message::instance()->get_col(
640
+			[
641
+				0       => [
642
+					'STS_ID'       => ['NOT_IN', $message_stati_to_keep],
643
+					'MSG_modified' => ['<', time() - $time_to_leave_alone],
644
+				],
645
+				'limit' => apply_filters(
646
+					'EEM_Message__delete_old_messages__limit',
647
+					2000,
648
+					$delete_threshold
649
+				),
650
+			]
651
+		);
652
+
653
+		if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
654
+			global $wpdb;
655
+			$number_deleted = $wpdb->query(
656
+				'
657 657
                 DELETE
658 658
                 FROM ' . $this->table() . '
659 659
                 WHERE
660 660
                     MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
661 661
             '
662
-            );
663
-        }
664
-
665
-        /**
666
-         * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
667
-         * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
668
-         * below.
669
-         */
670
-        if ($number_deleted !== false) {
671
-            do_action(
672
-                'AHEE__EEM_Message__delete_old_messages__after_successful_deletion',
673
-                $message_ids_to_delete,
674
-                $number_deleted
675
-            );
676
-        } else {
677
-            do_action(
678
-                'AHEE__EEM_Message__delete_old_messages__after_deletion_fail',
679
-                $message_ids_to_delete,
680
-                $number_deleted
681
-            );
682
-        }
683
-        return $number_deleted;
684
-    }
662
+			);
663
+		}
664
+
665
+		/**
666
+		 * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
667
+		 * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
668
+		 * below.
669
+		 */
670
+		if ($number_deleted !== false) {
671
+			do_action(
672
+				'AHEE__EEM_Message__delete_old_messages__after_successful_deletion',
673
+				$message_ids_to_delete,
674
+				$number_deleted
675
+			);
676
+		} else {
677
+			do_action(
678
+				'AHEE__EEM_Message__delete_old_messages__after_deletion_fail',
679
+				$message_ids_to_delete,
680
+				$number_deleted
681
+			);
682
+		}
683
+		return $number_deleted;
684
+	}
685 685
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
             self::priority_low    => esc_html__('low', 'event_espresso'),
125 125
         ];
126 126
 
127
-        $this->_fields          = [
127
+        $this->_fields = [
128 128
             'Message' => [
129 129
                 'MSG_ID'             => new EE_Primary_Key_Int_Field(
130 130
                     'MSG_ID', esc_html__('Message ID', 'event_espresso')
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
                         ];
453 453
                         break;
454 454
                     default:
455
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] =
455
+                        $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] =
456 456
                             $request_value;
457 457
                         break;
458 458
                 }
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
             // prepend to the last element of $label_parts an "and".
522 522
             if (count($label_parts) > 1) {
523 523
                 $label_parts_index_to_prepend                 = count($label_parts) - 1;
524
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
524
+                $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend];
525 525
             }
526 526
 
527 527
             $pretty_label .= sprintf(
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
             $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
582 582
         }
583 583
 
584
-        if (! is_null($set_debug)) {
584
+        if ( ! is_null($set_debug)) {
585 585
             $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
586 586
         }
587 587
 
@@ -650,14 +650,14 @@  discard block
 block discarded – undo
650 650
             ]
651 651
         );
652 652
 
653
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
653
+        if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
654 654
             global $wpdb;
655 655
             $number_deleted = $wpdb->query(
656 656
                 '
657 657
                 DELETE
658
-                FROM ' . $this->table() . '
658
+                FROM ' . $this->table().'
659 659
                 WHERE
660
-                    MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
660
+                    MSG_ID IN (' . implode(",", $message_ids_to_delete).')
661 661
             '
662 662
             );
663 663
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Line_Item.model.php 2 patches
Indentation   +625 added lines, -625 removed lines patch added patch discarded remove patch
@@ -27,632 +27,632 @@
 block discarded – undo
27 27
  */
28 28
 class EEM_Line_Item extends EEM_Base
29 29
 {
30
-    /**
31
-     * Tax sub-total is just the total of all the taxes, which should be children
32
-     * of this line item. There should only ever be one tax sub-total, and it should
33
-     * be a direct child of. Its quantity and LIN_unit_price = 1.
34
-     */
35
-    const type_tax_sub_total = 'tax-sub-total';
36
-
37
-    /**
38
-     * Tax line items indicate a tax applied to all the taxable line items.
39
-     * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
40
-     * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
41
-     */
42
-    const type_tax = 'tax';
43
-
44
-    /**
45
-     * Indicating individual items purchased, or discounts or surcharges.
46
-     * The sum of all the regular line items  plus the tax items should equal the grand total.
47
-     * Possible children are sub-line-items and cancellations.
48
-     * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
49
-     * LIN_totals. Its LIN_percent = 0.
50
-     * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
51
-     * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
52
-     */
53
-    const type_line_item = 'line-item';
54
-
55
-    /**
56
-     * Line item indicating all the factors that make a single line item.
57
-     * Sub-line items should have NO children line items.
58
-     * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
59
-     * contribution towards the price of ONE of their parent items, and its LIN_total should be
60
-     *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
61
-     * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
62
-     * = LIN_percent / 100 * sum of lower-priority sibling line items..
63
-     */
64
-    const type_sub_line_item = 'sub-item';
65
-
66
-    /**
67
-     * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item.
68
-     * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
69
-     * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
70
-     */
71
-    const type_sub_tax = 'sub-tax';
72
-
73
-    /**
74
-     * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
75
-     * Direct children should be event subtotals.
76
-     * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
77
-     */
78
-    const type_sub_total = 'sub-total';
79
-
80
-    /**
81
-     * Line item for the grand total of an order.
82
-     * Its direct children should be tax subtotals and (pre-tax) subtotals,
83
-     * and possibly a regular line item indicating a transaction-wide discount/surcharge.
84
-     * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount.
85
-     */
86
-    const type_total = 'total';
87
-
88
-    /**
89
-     * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
-     * should be created, indicating the quantity that were cancelled
91
-     * (because a line item could have a quantity of 1, and its cancellation item
92
-     * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
-     * cancelled, and only one remains).
94
-     * When items are refunded, a cancellation line item should be made, which points
95
-     * to teh payment model object which actually refunded the payment.
96
-     * Cancellations should NOT have any children line items; the should NOT affect
97
-     * any calculations, and are only meant as a record that cancellations have occurred.
98
-     * Their LIN_percent should be 0.
99
-     */
100
-    const type_cancellation = 'cancellation';
101
-
102
-    // various line item object types
103
-    const OBJ_TYPE_EVENT       = 'Event';
104
-
105
-    const OBJ_TYPE_PRICE       = 'Price';
106
-
107
-    const OBJ_TYPE_PROMOTION   = 'Promotion';
108
-
109
-    const OBJ_TYPE_TICKET      = 'Ticket';
110
-
111
-    const OBJ_TYPE_TRANSACTION = 'Transaction';
112
-
113
-    /**
114
-     * @var EEM_Line_Item $_instance
115
-     */
116
-    protected static $_instance;
117
-
118
-
119
-    /**
120
-     * private constructor to prevent direct creation
121
-     *
122
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
123
-     *                              (and any incoming timezone data that gets saved).
124
-     *                              Note this just sends the timezone info to the date time model field objects.
125
-     *                              Default is NULL
126
-     *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
127
-     * @throws EE_Error
128
-     * @throws ReflectionException
129
-     */
130
-    protected function __construct(?string $timezone = '')
131
-    {
132
-        $this->singular_item = esc_html__('Line Item', 'event_espresso');
133
-        $this->plural_item   = esc_html__('Line Items', 'event_espresso');
134
-
135
-        $this->_tables                 = [
136
-            'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'),
137
-        ];
138
-        $line_items_can_be_for         = apply_filters(
139
-            'FHEE__EEM_Line_Item__line_items_can_be_for',
140
-            ['Ticket', 'Price', 'Event']
141
-        );
142
-        $this->_fields                 = [
143
-            'Line_Item' => [
144
-                'LIN_ID'         => new EE_Primary_Key_Int_Field(
145
-                    'LIN_ID',
146
-                    esc_html__('ID', 'event_espresso')
147
-                ),
148
-                'LIN_code'       => new EE_Slug_Field(
149
-                    'LIN_code',
150
-                    esc_html__('Code for index into Cart', 'event_espresso'),
151
-                    true
152
-                ),
153
-                'TXN_ID'         => new EE_Foreign_Key_Int_Field(
154
-                    'TXN_ID',
155
-                    esc_html__('Transaction ID', 'event_espresso'),
156
-                    true,
157
-                    null,
158
-                    'Transaction'
159
-                ),
160
-                'LIN_name'       => new EE_Full_HTML_Field(
161
-                    'LIN_name',
162
-                    esc_html__('Line Item Name', 'event_espresso'),
163
-                    false,
164
-                    ''
165
-                ),
166
-                'LIN_desc'       => new EE_Full_HTML_Field(
167
-                    'LIN_desc',
168
-                    esc_html__('Line Item Description', 'event_espresso'),
169
-                    true
170
-                ),
171
-                'LIN_unit_price' => new EE_Money_Field(
172
-                    'LIN_unit_price',
173
-                    esc_html__('Unit Price', 'event_espresso'),
174
-                    false,
175
-                    0
176
-                ),
177
-                'LIN_percent'    => new EE_Float_Field(
178
-                    'LIN_percent',
179
-                    esc_html__('Percent', 'event_espresso'),
180
-                    false,
181
-                    0
182
-                ),
183
-                'LIN_is_taxable' => new EE_Boolean_Field(
184
-                    'LIN_is_taxable',
185
-                    esc_html__('Taxable', 'event_espresso'),
186
-                    false,
187
-                    false
188
-                ),
189
-                'LIN_order'      => new EE_Integer_Field(
190
-                    'LIN_order',
191
-                    esc_html__('Order of Application towards total of parent', 'event_espresso'),
192
-                    false,
193
-                    1
194
-                ),
195
-                'LIN_total'      => new EE_Money_Field(
196
-                    'LIN_total',
197
-                    esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'),
198
-                    false,
199
-                    0
200
-                ),
201
-                'LIN_pretax'     => new EE_Money_Field(
202
-                    'LIN_pretax',
203
-                    esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'),
204
-                    false,
205
-                    0
206
-                ),
207
-                'LIN_quantity'   => new EE_Integer_Field(
208
-                    'LIN_quantity',
209
-                    esc_html__('Quantity', 'event_espresso'),
210
-                    false,
211
-                    1
212
-                ),
213
-                'LIN_parent'     => new EE_Integer_Field(
214
-                    'LIN_parent',
215
-                    esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'),
216
-                    true,
217
-                    null
218
-                ),
219
-                'LIN_type'       => new EE_Enum_Text_Field(
220
-                    'LIN_type',
221
-                    esc_html__('Type', 'event_espresso'),
222
-                    false,
223
-                    'line-item',
224
-                    [
225
-                        self::type_line_item     => esc_html__('Line Item', 'event_espresso'),
226
-                        self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'),
227
-                        self::type_sub_tax       => esc_html__('Sub-Tax', 'event_espresso'),
228
-                        self::type_sub_total     => esc_html__('Subtotal', 'event_espresso'),
229
-                        self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'),
230
-                        self::type_tax           => esc_html__('Tax', 'event_espresso'),
231
-                        self::type_total         => esc_html__('Total', 'event_espresso'),
232
-                        self::type_cancellation  => esc_html__('Cancellation', 'event_espresso'),
233
-                    ]
234
-                ),
235
-                'OBJ_ID'         => new EE_Foreign_Key_Int_Field(
236
-                    'OBJ_ID',
237
-                    esc_html__('ID of Item purchased.', 'event_espresso'),
238
-                    true,
239
-                    null,
240
-                    $line_items_can_be_for
241
-                ),
242
-                'OBJ_type'       => new EE_Any_Foreign_Model_Name_Field(
243
-                    'OBJ_type',
244
-                    esc_html__('Model Name this Line Item is for', 'event_espresso'),
245
-                    true,
246
-                    null,
247
-                    $line_items_can_be_for
248
-                ),
249
-                'LIN_timestamp'  => new EE_Datetime_Field(
250
-                    'LIN_timestamp',
251
-                    esc_html__('When the line item was created', 'event_espresso'),
252
-                    false,
253
-                    EE_Datetime_Field::now,
254
-                    $timezone
255
-                ),
256
-            ],
257
-        ];
258
-        $this->_model_relations        = [
259
-            'Transaction' => new EE_Belongs_To_Relation(),
260
-            'Ticket'      => new EE_Belongs_To_Any_Relation(),
261
-            'Price'       => new EE_Belongs_To_Any_Relation(),
262
-            'Event'       => new EE_Belongs_To_Any_Relation(),
263
-        ];
264
-        $this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
265
-        $this->_caps_slug              = 'transactions';
266
-        parent::__construct($timezone);
267
-    }
268
-
269
-
270
-    /**
271
-     * Gets all the line items for this transaction of the given type
272
-     *
273
-     * @param string             $line_item_type like one of EEM_Line_Item::type_*
274
-     * @param EE_Transaction|int $transaction
275
-     * @return EE_Base_Class[]|EE_Line_Item[]
276
-     * @throws EE_Error
277
-     * @throws InvalidArgumentException
278
-     * @throws InvalidDataTypeException
279
-     * @throws InvalidInterfaceException
280
-     */
281
-    public function get_all_of_type_for_transaction($line_item_type, $transaction)
282
-    {
283
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
284
-        return $this->get_all(
285
-            [
286
-                [
287
-                    'LIN_type' => $line_item_type,
288
-                    'TXN_ID'   => $transaction,
289
-                ],
290
-            ]
291
-        );
292
-    }
293
-
294
-
295
-    /**
296
-     * Gets all line items unrelated to tickets that are normal line items
297
-     * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
298
-     *
299
-     * @param EE_Transaction|int $transaction
300
-     * @return EE_Base_Class[]|EE_Line_Item[]
301
-     * @throws EE_Error
302
-     * @throws InvalidArgumentException
303
-     * @throws InvalidDataTypeException
304
-     * @throws InvalidInterfaceException
305
-     */
306
-    public function get_all_non_ticket_line_items_for_transaction($transaction)
307
-    {
308
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
309
-        return $this->get_all(
310
-            [
311
-                [
312
-                    'LIN_type' => self::type_line_item,
313
-                    'TXN_ID'   => $transaction,
314
-                    'OR'       => [
315
-                        'OBJ_type*notticket' => ['!=', EEM_Line_Item::OBJ_TYPE_TICKET],
316
-                        'OBJ_type*null'      => ['IS_NULL'],
317
-                    ],
318
-                ],
319
-            ]
320
-        );
321
-    }
322
-
323
-
324
-    /**
325
-     * Deletes line items with no transaction who have passed the transaction cutoff time.
326
-     * This needs to be very efficient
327
-     * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when
328
-     * deleting and joining tables like this.
329
-     *
330
-     * @return int count of how many deleted
331
-     * @throws EE_Error
332
-     * @throws InvalidArgumentException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    public function delete_line_items_with_no_transaction()
337
-    {
338
-        /** @type WPDB $wpdb */
339
-        global $wpdb;
340
-        $time_to_leave_alone = apply_filters(
341
-            'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
342
-            WEEK_IN_SECONDS
343
-        );
344
-        $query               = $wpdb->prepare(
345
-            'DELETE li
30
+	/**
31
+	 * Tax sub-total is just the total of all the taxes, which should be children
32
+	 * of this line item. There should only ever be one tax sub-total, and it should
33
+	 * be a direct child of. Its quantity and LIN_unit_price = 1.
34
+	 */
35
+	const type_tax_sub_total = 'tax-sub-total';
36
+
37
+	/**
38
+	 * Tax line items indicate a tax applied to all the taxable line items.
39
+	 * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
40
+	 * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
41
+	 */
42
+	const type_tax = 'tax';
43
+
44
+	/**
45
+	 * Indicating individual items purchased, or discounts or surcharges.
46
+	 * The sum of all the regular line items  plus the tax items should equal the grand total.
47
+	 * Possible children are sub-line-items and cancellations.
48
+	 * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
49
+	 * LIN_totals. Its LIN_percent = 0.
50
+	 * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
51
+	 * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
52
+	 */
53
+	const type_line_item = 'line-item';
54
+
55
+	/**
56
+	 * Line item indicating all the factors that make a single line item.
57
+	 * Sub-line items should have NO children line items.
58
+	 * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
59
+	 * contribution towards the price of ONE of their parent items, and its LIN_total should be
60
+	 *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
61
+	 * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
62
+	 * = LIN_percent / 100 * sum of lower-priority sibling line items..
63
+	 */
64
+	const type_sub_line_item = 'sub-item';
65
+
66
+	/**
67
+	 * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item.
68
+	 * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
69
+	 * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
70
+	 */
71
+	const type_sub_tax = 'sub-tax';
72
+
73
+	/**
74
+	 * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
75
+	 * Direct children should be event subtotals.
76
+	 * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
77
+	 */
78
+	const type_sub_total = 'sub-total';
79
+
80
+	/**
81
+	 * Line item for the grand total of an order.
82
+	 * Its direct children should be tax subtotals and (pre-tax) subtotals,
83
+	 * and possibly a regular line item indicating a transaction-wide discount/surcharge.
84
+	 * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount.
85
+	 */
86
+	const type_total = 'total';
87
+
88
+	/**
89
+	 * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
+	 * should be created, indicating the quantity that were cancelled
91
+	 * (because a line item could have a quantity of 1, and its cancellation item
92
+	 * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
+	 * cancelled, and only one remains).
94
+	 * When items are refunded, a cancellation line item should be made, which points
95
+	 * to teh payment model object which actually refunded the payment.
96
+	 * Cancellations should NOT have any children line items; the should NOT affect
97
+	 * any calculations, and are only meant as a record that cancellations have occurred.
98
+	 * Their LIN_percent should be 0.
99
+	 */
100
+	const type_cancellation = 'cancellation';
101
+
102
+	// various line item object types
103
+	const OBJ_TYPE_EVENT       = 'Event';
104
+
105
+	const OBJ_TYPE_PRICE       = 'Price';
106
+
107
+	const OBJ_TYPE_PROMOTION   = 'Promotion';
108
+
109
+	const OBJ_TYPE_TICKET      = 'Ticket';
110
+
111
+	const OBJ_TYPE_TRANSACTION = 'Transaction';
112
+
113
+	/**
114
+	 * @var EEM_Line_Item $_instance
115
+	 */
116
+	protected static $_instance;
117
+
118
+
119
+	/**
120
+	 * private constructor to prevent direct creation
121
+	 *
122
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
123
+	 *                              (and any incoming timezone data that gets saved).
124
+	 *                              Note this just sends the timezone info to the date time model field objects.
125
+	 *                              Default is NULL
126
+	 *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
127
+	 * @throws EE_Error
128
+	 * @throws ReflectionException
129
+	 */
130
+	protected function __construct(?string $timezone = '')
131
+	{
132
+		$this->singular_item = esc_html__('Line Item', 'event_espresso');
133
+		$this->plural_item   = esc_html__('Line Items', 'event_espresso');
134
+
135
+		$this->_tables                 = [
136
+			'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'),
137
+		];
138
+		$line_items_can_be_for         = apply_filters(
139
+			'FHEE__EEM_Line_Item__line_items_can_be_for',
140
+			['Ticket', 'Price', 'Event']
141
+		);
142
+		$this->_fields                 = [
143
+			'Line_Item' => [
144
+				'LIN_ID'         => new EE_Primary_Key_Int_Field(
145
+					'LIN_ID',
146
+					esc_html__('ID', 'event_espresso')
147
+				),
148
+				'LIN_code'       => new EE_Slug_Field(
149
+					'LIN_code',
150
+					esc_html__('Code for index into Cart', 'event_espresso'),
151
+					true
152
+				),
153
+				'TXN_ID'         => new EE_Foreign_Key_Int_Field(
154
+					'TXN_ID',
155
+					esc_html__('Transaction ID', 'event_espresso'),
156
+					true,
157
+					null,
158
+					'Transaction'
159
+				),
160
+				'LIN_name'       => new EE_Full_HTML_Field(
161
+					'LIN_name',
162
+					esc_html__('Line Item Name', 'event_espresso'),
163
+					false,
164
+					''
165
+				),
166
+				'LIN_desc'       => new EE_Full_HTML_Field(
167
+					'LIN_desc',
168
+					esc_html__('Line Item Description', 'event_espresso'),
169
+					true
170
+				),
171
+				'LIN_unit_price' => new EE_Money_Field(
172
+					'LIN_unit_price',
173
+					esc_html__('Unit Price', 'event_espresso'),
174
+					false,
175
+					0
176
+				),
177
+				'LIN_percent'    => new EE_Float_Field(
178
+					'LIN_percent',
179
+					esc_html__('Percent', 'event_espresso'),
180
+					false,
181
+					0
182
+				),
183
+				'LIN_is_taxable' => new EE_Boolean_Field(
184
+					'LIN_is_taxable',
185
+					esc_html__('Taxable', 'event_espresso'),
186
+					false,
187
+					false
188
+				),
189
+				'LIN_order'      => new EE_Integer_Field(
190
+					'LIN_order',
191
+					esc_html__('Order of Application towards total of parent', 'event_espresso'),
192
+					false,
193
+					1
194
+				),
195
+				'LIN_total'      => new EE_Money_Field(
196
+					'LIN_total',
197
+					esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'),
198
+					false,
199
+					0
200
+				),
201
+				'LIN_pretax'     => new EE_Money_Field(
202
+					'LIN_pretax',
203
+					esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'),
204
+					false,
205
+					0
206
+				),
207
+				'LIN_quantity'   => new EE_Integer_Field(
208
+					'LIN_quantity',
209
+					esc_html__('Quantity', 'event_espresso'),
210
+					false,
211
+					1
212
+				),
213
+				'LIN_parent'     => new EE_Integer_Field(
214
+					'LIN_parent',
215
+					esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'),
216
+					true,
217
+					null
218
+				),
219
+				'LIN_type'       => new EE_Enum_Text_Field(
220
+					'LIN_type',
221
+					esc_html__('Type', 'event_espresso'),
222
+					false,
223
+					'line-item',
224
+					[
225
+						self::type_line_item     => esc_html__('Line Item', 'event_espresso'),
226
+						self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'),
227
+						self::type_sub_tax       => esc_html__('Sub-Tax', 'event_espresso'),
228
+						self::type_sub_total     => esc_html__('Subtotal', 'event_espresso'),
229
+						self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'),
230
+						self::type_tax           => esc_html__('Tax', 'event_espresso'),
231
+						self::type_total         => esc_html__('Total', 'event_espresso'),
232
+						self::type_cancellation  => esc_html__('Cancellation', 'event_espresso'),
233
+					]
234
+				),
235
+				'OBJ_ID'         => new EE_Foreign_Key_Int_Field(
236
+					'OBJ_ID',
237
+					esc_html__('ID of Item purchased.', 'event_espresso'),
238
+					true,
239
+					null,
240
+					$line_items_can_be_for
241
+				),
242
+				'OBJ_type'       => new EE_Any_Foreign_Model_Name_Field(
243
+					'OBJ_type',
244
+					esc_html__('Model Name this Line Item is for', 'event_espresso'),
245
+					true,
246
+					null,
247
+					$line_items_can_be_for
248
+				),
249
+				'LIN_timestamp'  => new EE_Datetime_Field(
250
+					'LIN_timestamp',
251
+					esc_html__('When the line item was created', 'event_espresso'),
252
+					false,
253
+					EE_Datetime_Field::now,
254
+					$timezone
255
+				),
256
+			],
257
+		];
258
+		$this->_model_relations        = [
259
+			'Transaction' => new EE_Belongs_To_Relation(),
260
+			'Ticket'      => new EE_Belongs_To_Any_Relation(),
261
+			'Price'       => new EE_Belongs_To_Any_Relation(),
262
+			'Event'       => new EE_Belongs_To_Any_Relation(),
263
+		];
264
+		$this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
265
+		$this->_caps_slug              = 'transactions';
266
+		parent::__construct($timezone);
267
+	}
268
+
269
+
270
+	/**
271
+	 * Gets all the line items for this transaction of the given type
272
+	 *
273
+	 * @param string             $line_item_type like one of EEM_Line_Item::type_*
274
+	 * @param EE_Transaction|int $transaction
275
+	 * @return EE_Base_Class[]|EE_Line_Item[]
276
+	 * @throws EE_Error
277
+	 * @throws InvalidArgumentException
278
+	 * @throws InvalidDataTypeException
279
+	 * @throws InvalidInterfaceException
280
+	 */
281
+	public function get_all_of_type_for_transaction($line_item_type, $transaction)
282
+	{
283
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
284
+		return $this->get_all(
285
+			[
286
+				[
287
+					'LIN_type' => $line_item_type,
288
+					'TXN_ID'   => $transaction,
289
+				],
290
+			]
291
+		);
292
+	}
293
+
294
+
295
+	/**
296
+	 * Gets all line items unrelated to tickets that are normal line items
297
+	 * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
298
+	 *
299
+	 * @param EE_Transaction|int $transaction
300
+	 * @return EE_Base_Class[]|EE_Line_Item[]
301
+	 * @throws EE_Error
302
+	 * @throws InvalidArgumentException
303
+	 * @throws InvalidDataTypeException
304
+	 * @throws InvalidInterfaceException
305
+	 */
306
+	public function get_all_non_ticket_line_items_for_transaction($transaction)
307
+	{
308
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
309
+		return $this->get_all(
310
+			[
311
+				[
312
+					'LIN_type' => self::type_line_item,
313
+					'TXN_ID'   => $transaction,
314
+					'OR'       => [
315
+						'OBJ_type*notticket' => ['!=', EEM_Line_Item::OBJ_TYPE_TICKET],
316
+						'OBJ_type*null'      => ['IS_NULL'],
317
+					],
318
+				],
319
+			]
320
+		);
321
+	}
322
+
323
+
324
+	/**
325
+	 * Deletes line items with no transaction who have passed the transaction cutoff time.
326
+	 * This needs to be very efficient
327
+	 * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when
328
+	 * deleting and joining tables like this.
329
+	 *
330
+	 * @return int count of how many deleted
331
+	 * @throws EE_Error
332
+	 * @throws InvalidArgumentException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	public function delete_line_items_with_no_transaction()
337
+	{
338
+		/** @type WPDB $wpdb */
339
+		global $wpdb;
340
+		$time_to_leave_alone = apply_filters(
341
+			'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
342
+			WEEK_IN_SECONDS
343
+		);
344
+		$query               = $wpdb->prepare(
345
+			'DELETE li
346 346
 				FROM ' . $this->table() . ' li
347 347
 				LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID
348 348
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
349
-            // use GMT time because that's what TXN_timestamps are in
350
-            date('Y-m-d H:i:s', time() - $time_to_leave_alone)
351
-        );
352
-        return $wpdb->query($query);
353
-    }
354
-
355
-
356
-    /**
357
-     * get_line_item_for_transaction_object
358
-     * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
359
-     *
360
-     * @param int           $TXN_ID
361
-     * @param EE_Base_Class $object
362
-     * @return EE_Base_Class[]|EE_Line_Item[]
363
-     * @throws EE_Error
364
-     * @throws InvalidArgumentException
365
-     * @throws InvalidDataTypeException
366
-     * @throws InvalidInterfaceException
367
-     * @throws ReflectionException
368
-     */
369
-    public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
370
-    {
371
-        return $this->get_all(
372
-            [
373
-                [
374
-                    'TXN_ID'   => $TXN_ID,
375
-                    'OBJ_type' => str_replace('EE_', '', get_class($object)),
376
-                    'OBJ_ID'   => $object->ID(),
377
-                ],
378
-            ]
379
-        );
380
-    }
381
-
382
-
383
-    /**
384
-     * get_object_line_items_for_transaction
385
-     * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
386
-     *
387
-     * @param int    $TXN_ID
388
-     * @param string $OBJ_type
389
-     * @param array  $OBJ_IDs
390
-     * @return EE_Base_Class[]|EE_Line_Item[]
391
-     * @throws EE_Error
392
-     */
393
-    public function get_object_line_items_for_transaction(
394
-        $TXN_ID,
395
-        $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT,
396
-        $OBJ_IDs = []
397
-    ) {
398
-        $query_params = [
399
-            'OBJ_type' => $OBJ_type,
400
-            // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
401
-            'OBJ_ID'   => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? ['IN', $OBJ_IDs] : $OBJ_IDs,
402
-        ];
403
-        if ($TXN_ID) {
404
-            $query_params['TXN_ID'] = $TXN_ID;
405
-        }
406
-        return $this->get_all([$query_params]);
407
-    }
408
-
409
-
410
-    /**
411
-     * get_all_ticket_line_items_for_transaction
412
-     *
413
-     * @param EE_Transaction $transaction
414
-     * @return EE_Base_Class[]|EE_Line_Item[]
415
-     * @throws EE_Error
416
-     * @throws InvalidArgumentException
417
-     * @throws InvalidDataTypeException
418
-     * @throws InvalidInterfaceException
419
-     * @throws ReflectionException
420
-     */
421
-    public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
422
-    {
423
-        return $this->get_all(
424
-            [
425
-                [
426
-                    'TXN_ID'   => $transaction->ID(),
427
-                    'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
428
-                ],
429
-            ]
430
-        );
431
-    }
432
-
433
-
434
-    /**
435
-     * get_ticket_line_item_for_transaction
436
-     *
437
-     * @param int $TXN_ID
438
-     * @param int $TKT_ID
439
-     * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
440
-     * @throws EE_Error
441
-     * @throws InvalidArgumentException
442
-     * @throws InvalidDataTypeException
443
-     * @throws InvalidInterfaceException
444
-     */
445
-    public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
446
-    {
447
-        return $this->get_one(
448
-            [
449
-                [
450
-                    'TXN_ID'   => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
451
-                    'OBJ_ID'   => $TKT_ID,
452
-                    'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
453
-                ],
454
-            ]
455
-        );
456
-    }
457
-
458
-
459
-    /**
460
-     * get_existing_promotion_line_item
461
-     * searches the cart for existing line items for the specified promotion
462
-     *
463
-     * @param EE_Line_Item $parent_line_item
464
-     * @param EE_Promotion $promotion
465
-     * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
466
-     * @throws EE_Error
467
-     * @throws InvalidArgumentException
468
-     * @throws InvalidDataTypeException
469
-     * @throws InvalidInterfaceException
470
-     * @throws ReflectionException
471
-     * @since 1.0.0
472
-     */
473
-    public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
474
-    {
475
-        return $this->get_one(
476
-            [
477
-                [
478
-                    'TXN_ID'     => $parent_line_item->TXN_ID(),
479
-                    'LIN_parent' => $parent_line_item->ID(),
480
-                    'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
481
-                    'OBJ_ID'     => $promotion->ID(),
482
-                ],
483
-            ]
484
-        );
485
-    }
486
-
487
-
488
-    /**
489
-     * get_all_promotion_line_items
490
-     * searches the cart for any and all existing promotion line items
491
-     *
492
-     * @param EE_Line_Item $parent_line_item
493
-     * @return EE_Base_Class[]|EE_Line_Item[]
494
-     * @throws EE_Error
495
-     * @throws InvalidArgumentException
496
-     * @throws InvalidDataTypeException
497
-     * @throws InvalidInterfaceException
498
-     * @throws ReflectionException
499
-     * @since   1.0.0
500
-     */
501
-    public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
502
-    {
503
-        return $this->get_all(
504
-            [
505
-                [
506
-                    'TXN_ID'     => $parent_line_item->TXN_ID(),
507
-                    'LIN_parent' => $parent_line_item->ID(),
508
-                    'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
509
-                ],
510
-            ]
511
-        );
512
-    }
513
-
514
-
515
-    /**
516
-     * Gets the registration's corresponding line item.
517
-     * Note: basically does NOT support having multiple line items for a single ticket,
518
-     * which would happen if some of the registrations had a price modifier while others didn't.
519
-     * In order to support that, we'd probably need a LIN_ID on registrations or something.
520
-     *
521
-     * @param EE_Registration $registration
522
-     * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL
523
-     * @throws EE_Error
524
-     */
525
-    public function get_line_item_for_registration(EE_Registration $registration)
526
-    {
527
-        return $this->get_one($this->line_item_for_registration_query_params($registration));
528
-    }
529
-
530
-
531
-    /**
532
-     * Gets the query params used to retrieve a specific line item for the given registration
533
-     *
534
-     * @param EE_Registration $registration
535
-     * @param array           $original_query_params any extra query params you'd like to be merged with
536
-     * @return array @see
537
-     *                                               https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
538
-     * @throws EE_Error
539
-     */
540
-    public function line_item_for_registration_query_params(
541
-        EE_Registration $registration,
542
-        $original_query_params = []
543
-    ) {
544
-        return array_replace_recursive(
545
-            $original_query_params,
546
-            [
547
-                [
548
-                    'OBJ_ID'   => $registration->ticket_ID(),
549
-                    'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
550
-                    'TXN_ID'   => $registration->transaction_ID(),
551
-                ],
552
-            ]
553
-        );
554
-    }
555
-
556
-
557
-    /**
558
-     * @return EE_Base_Class[]|EE_Line_Item[]
559
-     * @throws InvalidInterfaceException
560
-     * @throws InvalidDataTypeException
561
-     * @throws EE_Error
562
-     * @throws InvalidArgumentException
563
-     */
564
-    public function get_total_line_items_with_no_transaction()
565
-    {
566
-        return $this->get_total_line_items_for_carts();
567
-    }
568
-
569
-
570
-    /**
571
-     * @return EE_Base_Class[]|EE_Line_Item[]
572
-     * @throws InvalidInterfaceException
573
-     * @throws InvalidDataTypeException
574
-     * @throws EE_Error
575
-     * @throws InvalidArgumentException
576
-     */
577
-    public function get_total_line_items_for_active_carts()
578
-    {
579
-        return $this->get_total_line_items_for_carts(false);
580
-    }
581
-
582
-
583
-    /**
584
-     * @return EE_Base_Class[]|EE_Line_Item[]
585
-     * @throws InvalidInterfaceException
586
-     * @throws InvalidDataTypeException
587
-     * @throws EE_Error
588
-     * @throws InvalidArgumentException
589
-     */
590
-    public function get_total_line_items_for_expired_carts()
591
-    {
592
-        return $this->get_total_line_items_for_carts(true);
593
-    }
594
-
595
-
596
-    /**
597
-     * Returns an array of grand total line items where the TXN_ID is 0.
598
-     * If $expired is set to true, then only line items for expired sessions will be returned.
599
-     * If $expired is set to false, then only line items for active sessions will be returned.
600
-     *
601
-     * @param null $expired
602
-     * @return EE_Base_Class[]|EE_Line_Item[]
603
-     * @throws EE_Error
604
-     * @throws InvalidArgumentException
605
-     * @throws InvalidDataTypeException
606
-     * @throws InvalidInterfaceException
607
-     */
608
-    private function get_total_line_items_for_carts($expired = null)
609
-    {
610
-        $where_params = [
611
-            'TXN_ID'   => 0,
612
-            'LIN_type' => 'total',
613
-        ];
614
-        if ($expired !== null) {
615
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
616
-            $session_lifespan              = LoaderFactory::getLoader()->getShared(
617
-                'EventEspresso\core\domain\values\session\SessionLifespan'
618
-            );
619
-            $where_params['LIN_timestamp'] = [
620
-                $expired ? '<=' : '>',
621
-                $session_lifespan->expiration(),
622
-            ];
623
-        }
624
-        return $this->get_all([$where_params]);
625
-    }
626
-
627
-
628
-    /**
629
-     * Returns an array of ticket total line items where the TXN_ID is 0
630
-     * AND the timestamp is older than the session lifespan.
631
-     *
632
-     * @param int $timestamp
633
-     * @return EE_Base_Class[]|EE_Line_Item[]
634
-     * @throws EE_Error
635
-     * @throws InvalidArgumentException
636
-     * @throws InvalidDataTypeException
637
-     * @throws InvalidInterfaceException
638
-     */
639
-    public function getTicketLineItemsForExpiredCarts($timestamp = 0)
640
-    {
641
-        if (! absint($timestamp)) {
642
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
643
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
644
-                'EventEspresso\core\domain\values\session\SessionLifespan'
645
-            );
646
-            $timestamp        = $session_lifespan->expiration();
647
-        }
648
-        return $this->get_all(
649
-            [
650
-                [
651
-                    'TXN_ID'        => 0,
652
-                    'OBJ_type'      => EEM_Line_Item::OBJ_TYPE_TICKET,
653
-                    'LIN_timestamp' => ['<=', $timestamp],
654
-                ],
655
-            ]
656
-        );
657
-    }
349
+			// use GMT time because that's what TXN_timestamps are in
350
+			date('Y-m-d H:i:s', time() - $time_to_leave_alone)
351
+		);
352
+		return $wpdb->query($query);
353
+	}
354
+
355
+
356
+	/**
357
+	 * get_line_item_for_transaction_object
358
+	 * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
359
+	 *
360
+	 * @param int           $TXN_ID
361
+	 * @param EE_Base_Class $object
362
+	 * @return EE_Base_Class[]|EE_Line_Item[]
363
+	 * @throws EE_Error
364
+	 * @throws InvalidArgumentException
365
+	 * @throws InvalidDataTypeException
366
+	 * @throws InvalidInterfaceException
367
+	 * @throws ReflectionException
368
+	 */
369
+	public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
370
+	{
371
+		return $this->get_all(
372
+			[
373
+				[
374
+					'TXN_ID'   => $TXN_ID,
375
+					'OBJ_type' => str_replace('EE_', '', get_class($object)),
376
+					'OBJ_ID'   => $object->ID(),
377
+				],
378
+			]
379
+		);
380
+	}
381
+
382
+
383
+	/**
384
+	 * get_object_line_items_for_transaction
385
+	 * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
386
+	 *
387
+	 * @param int    $TXN_ID
388
+	 * @param string $OBJ_type
389
+	 * @param array  $OBJ_IDs
390
+	 * @return EE_Base_Class[]|EE_Line_Item[]
391
+	 * @throws EE_Error
392
+	 */
393
+	public function get_object_line_items_for_transaction(
394
+		$TXN_ID,
395
+		$OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT,
396
+		$OBJ_IDs = []
397
+	) {
398
+		$query_params = [
399
+			'OBJ_type' => $OBJ_type,
400
+			// if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
401
+			'OBJ_ID'   => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? ['IN', $OBJ_IDs] : $OBJ_IDs,
402
+		];
403
+		if ($TXN_ID) {
404
+			$query_params['TXN_ID'] = $TXN_ID;
405
+		}
406
+		return $this->get_all([$query_params]);
407
+	}
408
+
409
+
410
+	/**
411
+	 * get_all_ticket_line_items_for_transaction
412
+	 *
413
+	 * @param EE_Transaction $transaction
414
+	 * @return EE_Base_Class[]|EE_Line_Item[]
415
+	 * @throws EE_Error
416
+	 * @throws InvalidArgumentException
417
+	 * @throws InvalidDataTypeException
418
+	 * @throws InvalidInterfaceException
419
+	 * @throws ReflectionException
420
+	 */
421
+	public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
422
+	{
423
+		return $this->get_all(
424
+			[
425
+				[
426
+					'TXN_ID'   => $transaction->ID(),
427
+					'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
428
+				],
429
+			]
430
+		);
431
+	}
432
+
433
+
434
+	/**
435
+	 * get_ticket_line_item_for_transaction
436
+	 *
437
+	 * @param int $TXN_ID
438
+	 * @param int $TKT_ID
439
+	 * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
440
+	 * @throws EE_Error
441
+	 * @throws InvalidArgumentException
442
+	 * @throws InvalidDataTypeException
443
+	 * @throws InvalidInterfaceException
444
+	 */
445
+	public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
446
+	{
447
+		return $this->get_one(
448
+			[
449
+				[
450
+					'TXN_ID'   => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
451
+					'OBJ_ID'   => $TKT_ID,
452
+					'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
453
+				],
454
+			]
455
+		);
456
+	}
457
+
458
+
459
+	/**
460
+	 * get_existing_promotion_line_item
461
+	 * searches the cart for existing line items for the specified promotion
462
+	 *
463
+	 * @param EE_Line_Item $parent_line_item
464
+	 * @param EE_Promotion $promotion
465
+	 * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
466
+	 * @throws EE_Error
467
+	 * @throws InvalidArgumentException
468
+	 * @throws InvalidDataTypeException
469
+	 * @throws InvalidInterfaceException
470
+	 * @throws ReflectionException
471
+	 * @since 1.0.0
472
+	 */
473
+	public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
474
+	{
475
+		return $this->get_one(
476
+			[
477
+				[
478
+					'TXN_ID'     => $parent_line_item->TXN_ID(),
479
+					'LIN_parent' => $parent_line_item->ID(),
480
+					'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
481
+					'OBJ_ID'     => $promotion->ID(),
482
+				],
483
+			]
484
+		);
485
+	}
486
+
487
+
488
+	/**
489
+	 * get_all_promotion_line_items
490
+	 * searches the cart for any and all existing promotion line items
491
+	 *
492
+	 * @param EE_Line_Item $parent_line_item
493
+	 * @return EE_Base_Class[]|EE_Line_Item[]
494
+	 * @throws EE_Error
495
+	 * @throws InvalidArgumentException
496
+	 * @throws InvalidDataTypeException
497
+	 * @throws InvalidInterfaceException
498
+	 * @throws ReflectionException
499
+	 * @since   1.0.0
500
+	 */
501
+	public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
502
+	{
503
+		return $this->get_all(
504
+			[
505
+				[
506
+					'TXN_ID'     => $parent_line_item->TXN_ID(),
507
+					'LIN_parent' => $parent_line_item->ID(),
508
+					'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
509
+				],
510
+			]
511
+		);
512
+	}
513
+
514
+
515
+	/**
516
+	 * Gets the registration's corresponding line item.
517
+	 * Note: basically does NOT support having multiple line items for a single ticket,
518
+	 * which would happen if some of the registrations had a price modifier while others didn't.
519
+	 * In order to support that, we'd probably need a LIN_ID on registrations or something.
520
+	 *
521
+	 * @param EE_Registration $registration
522
+	 * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL
523
+	 * @throws EE_Error
524
+	 */
525
+	public function get_line_item_for_registration(EE_Registration $registration)
526
+	{
527
+		return $this->get_one($this->line_item_for_registration_query_params($registration));
528
+	}
529
+
530
+
531
+	/**
532
+	 * Gets the query params used to retrieve a specific line item for the given registration
533
+	 *
534
+	 * @param EE_Registration $registration
535
+	 * @param array           $original_query_params any extra query params you'd like to be merged with
536
+	 * @return array @see
537
+	 *                                               https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
538
+	 * @throws EE_Error
539
+	 */
540
+	public function line_item_for_registration_query_params(
541
+		EE_Registration $registration,
542
+		$original_query_params = []
543
+	) {
544
+		return array_replace_recursive(
545
+			$original_query_params,
546
+			[
547
+				[
548
+					'OBJ_ID'   => $registration->ticket_ID(),
549
+					'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
550
+					'TXN_ID'   => $registration->transaction_ID(),
551
+				],
552
+			]
553
+		);
554
+	}
555
+
556
+
557
+	/**
558
+	 * @return EE_Base_Class[]|EE_Line_Item[]
559
+	 * @throws InvalidInterfaceException
560
+	 * @throws InvalidDataTypeException
561
+	 * @throws EE_Error
562
+	 * @throws InvalidArgumentException
563
+	 */
564
+	public function get_total_line_items_with_no_transaction()
565
+	{
566
+		return $this->get_total_line_items_for_carts();
567
+	}
568
+
569
+
570
+	/**
571
+	 * @return EE_Base_Class[]|EE_Line_Item[]
572
+	 * @throws InvalidInterfaceException
573
+	 * @throws InvalidDataTypeException
574
+	 * @throws EE_Error
575
+	 * @throws InvalidArgumentException
576
+	 */
577
+	public function get_total_line_items_for_active_carts()
578
+	{
579
+		return $this->get_total_line_items_for_carts(false);
580
+	}
581
+
582
+
583
+	/**
584
+	 * @return EE_Base_Class[]|EE_Line_Item[]
585
+	 * @throws InvalidInterfaceException
586
+	 * @throws InvalidDataTypeException
587
+	 * @throws EE_Error
588
+	 * @throws InvalidArgumentException
589
+	 */
590
+	public function get_total_line_items_for_expired_carts()
591
+	{
592
+		return $this->get_total_line_items_for_carts(true);
593
+	}
594
+
595
+
596
+	/**
597
+	 * Returns an array of grand total line items where the TXN_ID is 0.
598
+	 * If $expired is set to true, then only line items for expired sessions will be returned.
599
+	 * If $expired is set to false, then only line items for active sessions will be returned.
600
+	 *
601
+	 * @param null $expired
602
+	 * @return EE_Base_Class[]|EE_Line_Item[]
603
+	 * @throws EE_Error
604
+	 * @throws InvalidArgumentException
605
+	 * @throws InvalidDataTypeException
606
+	 * @throws InvalidInterfaceException
607
+	 */
608
+	private function get_total_line_items_for_carts($expired = null)
609
+	{
610
+		$where_params = [
611
+			'TXN_ID'   => 0,
612
+			'LIN_type' => 'total',
613
+		];
614
+		if ($expired !== null) {
615
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
616
+			$session_lifespan              = LoaderFactory::getLoader()->getShared(
617
+				'EventEspresso\core\domain\values\session\SessionLifespan'
618
+			);
619
+			$where_params['LIN_timestamp'] = [
620
+				$expired ? '<=' : '>',
621
+				$session_lifespan->expiration(),
622
+			];
623
+		}
624
+		return $this->get_all([$where_params]);
625
+	}
626
+
627
+
628
+	/**
629
+	 * Returns an array of ticket total line items where the TXN_ID is 0
630
+	 * AND the timestamp is older than the session lifespan.
631
+	 *
632
+	 * @param int $timestamp
633
+	 * @return EE_Base_Class[]|EE_Line_Item[]
634
+	 * @throws EE_Error
635
+	 * @throws InvalidArgumentException
636
+	 * @throws InvalidDataTypeException
637
+	 * @throws InvalidInterfaceException
638
+	 */
639
+	public function getTicketLineItemsForExpiredCarts($timestamp = 0)
640
+	{
641
+		if (! absint($timestamp)) {
642
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
643
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
644
+				'EventEspresso\core\domain\values\session\SessionLifespan'
645
+			);
646
+			$timestamp        = $session_lifespan->expiration();
647
+		}
648
+		return $this->get_all(
649
+			[
650
+				[
651
+					'TXN_ID'        => 0,
652
+					'OBJ_type'      => EEM_Line_Item::OBJ_TYPE_TICKET,
653
+					'LIN_timestamp' => ['<=', $timestamp],
654
+				],
655
+			]
656
+		);
657
+	}
658 658
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             'FHEE__EEM_Line_Item__line_items_can_be_for',
140 140
             ['Ticket', 'Price', 'Event']
141 141
         );
142
-        $this->_fields                 = [
142
+        $this->_fields = [
143 143
             'Line_Item' => [
144 144
                 'LIN_ID'         => new EE_Primary_Key_Int_Field(
145 145
                     'LIN_ID',
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
                 ),
256 256
             ],
257 257
         ];
258
-        $this->_model_relations        = [
258
+        $this->_model_relations = [
259 259
             'Transaction' => new EE_Belongs_To_Relation(),
260 260
             'Ticket'      => new EE_Belongs_To_Any_Relation(),
261 261
             'Price'       => new EE_Belongs_To_Any_Relation(),
@@ -341,10 +341,10 @@  discard block
 block discarded – undo
341 341
             'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
342 342
             WEEK_IN_SECONDS
343 343
         );
344
-        $query               = $wpdb->prepare(
344
+        $query = $wpdb->prepare(
345 345
             'DELETE li
346
-				FROM ' . $this->table() . ' li
347
-				LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID
346
+				FROM ' . $this->table().' li
347
+				LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID
348 348
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
349 349
             // use GMT time because that's what TXN_timestamps are in
350 350
             date('Y-m-d H:i:s', time() - $time_to_leave_alone)
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
      */
639 639
     public function getTicketLineItemsForExpiredCarts($timestamp = 0)
640 640
     {
641
-        if (! absint($timestamp)) {
641
+        if ( ! absint($timestamp)) {
642 642
             /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
643 643
             $session_lifespan = LoaderFactory::getLoader()->getShared(
644 644
                 'EventEspresso\core\domain\values\session\SessionLifespan'
Please login to merge, or discard this patch.
core/db_models/EEM_Question_Group_Question.model.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -13,68 +13,68 @@
 block discarded – undo
13 13
  */
14 14
 class EEM_Question_Group_Question extends EEM_Base
15 15
 {
16
-    // private instance of the Attendee object
17
-    protected static $_instance = null;
16
+	// private instance of the Attendee object
17
+	protected static $_instance = null;
18 18
 
19 19
 
20
-    /**
21
-     * @param string|null $timezone
22
-     * @throws EE_Error
23
-     */
24
-    protected function __construct(?string $timezone = '')
25
-    {
26
-        $this->singular_item    = esc_html__('Question Group to Question Link', 'event_espresso');
27
-        $this->plural_item      = esc_html__('Question Group to Question Links', 'event_espresso');
28
-        $this->_tables          = [
29
-            'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID'),
30
-        ];
31
-        $this->_fields          = [
32
-            'Question_Group_Question' => [
33
-                'QGQ_ID'    => new EE_Primary_Key_Int_Field(
34
-                    'QGQ_ID',
35
-                    esc_html__('Question Group to Question Link ID', 'event_espresso')
36
-                ),
37
-                'QSG_ID'    => new EE_Foreign_Key_Int_Field(
38
-                    'QSG_ID',
39
-                    esc_html__('Question Group ID', 'event_espresso'),
40
-                    false,
41
-                    0,
42
-                    'Question_Group'
43
-                ),
44
-                'QST_ID'    => new EE_Foreign_Key_Int_Field(
45
-                    'QST_ID',
46
-                    esc_html__('Question Id', 'event_espresso'),
47
-                    false,
48
-                    0,
49
-                    'Question'
50
-                ),
51
-                'QGQ_order' => new EE_Integer_Field(
52
-                    'QGQ_order',
53
-                    esc_html__('Question Group Question Order', 'event_espresso'),
54
-                    false,
55
-                    0
56
-                ),
57
-            ],
58
-        ];
59
-        $this->_model_relations = [
60
-            'Question_Group' => new EE_Belongs_To_Relation(),
61
-            'Question'       => new EE_Belongs_To_Relation(),
62
-        ];
20
+	/**
21
+	 * @param string|null $timezone
22
+	 * @throws EE_Error
23
+	 */
24
+	protected function __construct(?string $timezone = '')
25
+	{
26
+		$this->singular_item    = esc_html__('Question Group to Question Link', 'event_espresso');
27
+		$this->plural_item      = esc_html__('Question Group to Question Links', 'event_espresso');
28
+		$this->_tables          = [
29
+			'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID'),
30
+		];
31
+		$this->_fields          = [
32
+			'Question_Group_Question' => [
33
+				'QGQ_ID'    => new EE_Primary_Key_Int_Field(
34
+					'QGQ_ID',
35
+					esc_html__('Question Group to Question Link ID', 'event_espresso')
36
+				),
37
+				'QSG_ID'    => new EE_Foreign_Key_Int_Field(
38
+					'QSG_ID',
39
+					esc_html__('Question Group ID', 'event_espresso'),
40
+					false,
41
+					0,
42
+					'Question_Group'
43
+				),
44
+				'QST_ID'    => new EE_Foreign_Key_Int_Field(
45
+					'QST_ID',
46
+					esc_html__('Question Id', 'event_espresso'),
47
+					false,
48
+					0,
49
+					'Question'
50
+				),
51
+				'QGQ_order' => new EE_Integer_Field(
52
+					'QGQ_order',
53
+					esc_html__('Question Group Question Order', 'event_espresso'),
54
+					false,
55
+					0
56
+				),
57
+			],
58
+		];
59
+		$this->_model_relations = [
60
+			'Question_Group' => new EE_Belongs_To_Relation(),
61
+			'Question'       => new EE_Belongs_To_Relation(),
62
+		];
63 63
 
64
-        $this->_model_chain_to_wp_user = 'Question_Group';
64
+		$this->_model_chain_to_wp_user = 'Question_Group';
65 65
 
66
-        // this model is generally available for reading
67
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
68
-            new EE_Restriction_Generator_Public();
69
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
70
-            new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
72
-            new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
73
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
74
-            new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
66
+		// this model is generally available for reading
67
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
68
+			new EE_Restriction_Generator_Public();
69
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
70
+			new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
71
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
72
+			new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
73
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
74
+			new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
75 75
 
76
-        // use the caps for question groups
77
-        $this->_caps_slug = 'question_groups';
78
-        parent::__construct($timezone);
79
-    }
76
+		// use the caps for question groups
77
+		$this->_caps_slug = 'question_groups';
78
+		parent::__construct($timezone);
79
+	}
80 80
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Venue.model.php 2 patches
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -10,202 +10,202 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Venue extends EEM_CPT_Base
12 12
 {
13
-    // private instance of the Attendee object
14
-    protected static $_instance = null;
13
+	// private instance of the Attendee object
14
+	protected static $_instance = null;
15 15
 
16 16
 
17
-    /**
18
-     * @param string|null $timezone
19
-     * @throws EE_Error
20
-     */
21
-    protected function __construct(?string $timezone = '')
22
-    {
23
-        $this->singular_item    = esc_html__('Venue', 'event_espresso');
24
-        $this->plural_item      = esc_html__('Venues', 'event_espresso');
25
-        $this->_tables          = [
26
-            'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
27
-            'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
28
-        ];
29
-        $this->_fields          = [
30
-            'Venue_CPT'  => [
31
-                'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', esc_html__("Venue ID", "event_espresso")),
32
-                'VNU_name'       => new EE_Plain_Text_Field(
33
-                    'post_title',
34
-                    esc_html__("Venue Name", "event_espresso"),
35
-                    false,
36
-                    ''
37
-                ),
38
-                'VNU_desc'       => new EE_Post_Content_Field(
39
-                    'post_content',
40
-                    esc_html__("Venue Description", "event_espresso"),
41
-                    false,
42
-                    ''
43
-                ),
44
-                'VNU_identifier' => new EE_Slug_Field(
45
-                    'post_name',
46
-                    esc_html__("Venue Identifier", "event_espresso"),
47
-                    false,
48
-                    ''
49
-                ),
50
-                'VNU_created'    => new EE_Datetime_Field(
51
-                    'post_date',
52
-                    esc_html__("Date Venue Created", "event_espresso"),
53
-                    false,
54
-                    EE_Datetime_Field::now
55
-                ),
56
-                'VNU_short_desc' => new EE_Plain_Text_Field(
57
-                    'post_excerpt',
58
-                    esc_html__("Short Description of Venue", "event_espresso"),
59
-                    true,
60
-                    ''
61
-                ),
62
-                'VNU_modified'   => new EE_Datetime_Field(
63
-                    'post_modified',
64
-                    esc_html__("Venue Modified Date", "event_espresso"),
65
-                    false,
66
-                    EE_Datetime_Field::now
67
-                ),
68
-                'VNU_wp_user'    => new EE_WP_User_Field(
69
-                    'post_author',
70
-                    esc_html__("Venue Creator ID", "event_espresso"),
71
-                    false
72
-                ),
73
-                'parent'         => new EE_Integer_Field(
74
-                    'post_parent',
75
-                    esc_html__("Venue Parent ID", "event_espresso"),
76
-                    false,
77
-                    0
78
-                ),
79
-                'VNU_order'      => new EE_Integer_Field(
80
-                    'menu_order',
81
-                    esc_html__("Venue order", "event_espresso"),
82
-                    false,
83
-                    1
84
-                ),
85
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
86
-                'password'       => new EE_Password_Field(
87
-                    'post_password',
88
-                    esc_html__('Password', 'event_espresso'),
89
-                    false,
90
-                    '',
91
-                    [
92
-                        'VNU_desc',
93
-                        'VNU_short_desc',
94
-                        'VNU_address',
95
-                        'VNU_address2',
96
-                        'VNU_city',
97
-                        'STA_ID',
98
-                        'CNT_ISO',
99
-                        'VNU_zip',
100
-                        'VNU_phone',
101
-                        'VNU_capacity',
102
-                        'VNU_url',
103
-                        'VNU_virtual_phone',
104
-                        'VNU_virtual_url',
105
-                        'VNU_google_map_link',
106
-                        'VNU_enable_for_gmap',
107
-                    ]
108
-                ),
109
-            ],
110
-            'Venue_Meta' => [
111
-                'VNUM_ID'             => new EE_DB_Only_Int_Field(
112
-                    'VNUM_ID',
113
-                    esc_html__("ID of Venue Meta Row", "event_espresso"),
114
-                    false
115
-                ),
116
-                'VNU_ID_fk'           => new EE_DB_Only_Int_Field(
117
-                    'VNU_ID',
118
-                    esc_html__("Foreign Key to Venue Post ", "event_espresso"),
119
-                    false
120
-                ),
121
-                'VNU_address'         => new EE_Plain_Text_Field(
122
-                    'VNU_address',
123
-                    esc_html__("Venue Address line 1", "event_espresso"),
124
-                    true,
125
-                    ''
126
-                ),
127
-                'VNU_address2'        => new EE_Plain_Text_Field(
128
-                    'VNU_address2',
129
-                    esc_html__("Venue Address line 2", "event_espresso"),
130
-                    true,
131
-                    ''
132
-                ),
133
-                'VNU_city'            => new EE_Plain_Text_Field(
134
-                    'VNU_city',
135
-                    esc_html__("Venue City", "event_espresso"),
136
-                    true,
137
-                    ''
138
-                ),
139
-                'STA_ID'              => new EE_Foreign_Key_Int_Field(
140
-                    'STA_ID',
141
-                    esc_html__("State ID", "event_espresso"),
142
-                    true,
143
-                    null,
144
-                    'State'
145
-                ),
146
-                'CNT_ISO'             => new EE_Foreign_Key_String_Field(
147
-                    'CNT_ISO',
148
-                    esc_html__("Country Code", "event_espresso"),
149
-                    true,
150
-                    null,
151
-                    'Country'
152
-                ),
153
-                'VNU_zip'             => new EE_Plain_Text_Field(
154
-                    'VNU_zip',
155
-                    esc_html__("Venue Zip/Postal Code", "event_espresso"),
156
-                    true
157
-                ),
158
-                'VNU_phone'           => new EE_Plain_Text_Field(
159
-                    'VNU_phone',
160
-                    esc_html__("Venue Phone", "event_espresso"),
161
-                    true
162
-                ),
163
-                'VNU_capacity'        => new EE_Infinite_Integer_Field(
164
-                    'VNU_capacity',
165
-                    esc_html__("Venue Capacity", "event_espresso"),
166
-                    true,
167
-                    EE_INF
168
-                ),
169
-                'VNU_url'             => new EE_Plain_Text_Field(
170
-                    'VNU_url',
171
-                    esc_html__('Venue Website', 'event_espresso'),
172
-                    true
173
-                ),
174
-                'VNU_virtual_phone'   => new EE_Plain_Text_Field(
175
-                    'VNU_virtual_phone',
176
-                    esc_html__('Call in Number', 'event_espresso'),
177
-                    true
178
-                ),
179
-                'VNU_virtual_url'     => new EE_Plain_Text_Field(
180
-                    'VNU_virtual_url',
181
-                    esc_html__('Virtual URL', 'event_espresso'),
182
-                    true
183
-                ),
184
-                'VNU_google_map_link' => new EE_Plain_Text_Field(
185
-                    'VNU_google_map_link',
186
-                    esc_html__('Google Map Link', 'event_espresso'),
187
-                    true
188
-                ),
189
-                'VNU_enable_for_gmap' => new EE_Boolean_Field(
190
-                    'VNU_enable_for_gmap',
191
-                    esc_html__('Show Google Map?', 'event_espresso'),
192
-                    false,
193
-                    false
194
-                ),
195
-            ],
196
-        ];
197
-        $this->_model_relations = [
198
-            'Country'           => new EE_Belongs_To_Relation(),
199
-            'Event'             => new EE_Has_Many_Relation(),
200
-            'Datetime'          => new EE_Has_Many_Relation(),
201
-            'State'             => new EE_Belongs_To_Relation(),
202
-            'Term_Relationship' => new EE_Has_Many_Relation(),
203
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
204
-            'WP_User'           => new EE_Belongs_To_Relation(),
205
-        ];
206
-        // this model is generally available for reading
207
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
208
-        $this->model_chain_to_password                            = '';
209
-        parent::__construct($timezone);
210
-    }
17
+	/**
18
+	 * @param string|null $timezone
19
+	 * @throws EE_Error
20
+	 */
21
+	protected function __construct(?string $timezone = '')
22
+	{
23
+		$this->singular_item    = esc_html__('Venue', 'event_espresso');
24
+		$this->plural_item      = esc_html__('Venues', 'event_espresso');
25
+		$this->_tables          = [
26
+			'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
27
+			'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
28
+		];
29
+		$this->_fields          = [
30
+			'Venue_CPT'  => [
31
+				'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', esc_html__("Venue ID", "event_espresso")),
32
+				'VNU_name'       => new EE_Plain_Text_Field(
33
+					'post_title',
34
+					esc_html__("Venue Name", "event_espresso"),
35
+					false,
36
+					''
37
+				),
38
+				'VNU_desc'       => new EE_Post_Content_Field(
39
+					'post_content',
40
+					esc_html__("Venue Description", "event_espresso"),
41
+					false,
42
+					''
43
+				),
44
+				'VNU_identifier' => new EE_Slug_Field(
45
+					'post_name',
46
+					esc_html__("Venue Identifier", "event_espresso"),
47
+					false,
48
+					''
49
+				),
50
+				'VNU_created'    => new EE_Datetime_Field(
51
+					'post_date',
52
+					esc_html__("Date Venue Created", "event_espresso"),
53
+					false,
54
+					EE_Datetime_Field::now
55
+				),
56
+				'VNU_short_desc' => new EE_Plain_Text_Field(
57
+					'post_excerpt',
58
+					esc_html__("Short Description of Venue", "event_espresso"),
59
+					true,
60
+					''
61
+				),
62
+				'VNU_modified'   => new EE_Datetime_Field(
63
+					'post_modified',
64
+					esc_html__("Venue Modified Date", "event_espresso"),
65
+					false,
66
+					EE_Datetime_Field::now
67
+				),
68
+				'VNU_wp_user'    => new EE_WP_User_Field(
69
+					'post_author',
70
+					esc_html__("Venue Creator ID", "event_espresso"),
71
+					false
72
+				),
73
+				'parent'         => new EE_Integer_Field(
74
+					'post_parent',
75
+					esc_html__("Venue Parent ID", "event_espresso"),
76
+					false,
77
+					0
78
+				),
79
+				'VNU_order'      => new EE_Integer_Field(
80
+					'menu_order',
81
+					esc_html__("Venue order", "event_espresso"),
82
+					false,
83
+					1
84
+				),
85
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
86
+				'password'       => new EE_Password_Field(
87
+					'post_password',
88
+					esc_html__('Password', 'event_espresso'),
89
+					false,
90
+					'',
91
+					[
92
+						'VNU_desc',
93
+						'VNU_short_desc',
94
+						'VNU_address',
95
+						'VNU_address2',
96
+						'VNU_city',
97
+						'STA_ID',
98
+						'CNT_ISO',
99
+						'VNU_zip',
100
+						'VNU_phone',
101
+						'VNU_capacity',
102
+						'VNU_url',
103
+						'VNU_virtual_phone',
104
+						'VNU_virtual_url',
105
+						'VNU_google_map_link',
106
+						'VNU_enable_for_gmap',
107
+					]
108
+				),
109
+			],
110
+			'Venue_Meta' => [
111
+				'VNUM_ID'             => new EE_DB_Only_Int_Field(
112
+					'VNUM_ID',
113
+					esc_html__("ID of Venue Meta Row", "event_espresso"),
114
+					false
115
+				),
116
+				'VNU_ID_fk'           => new EE_DB_Only_Int_Field(
117
+					'VNU_ID',
118
+					esc_html__("Foreign Key to Venue Post ", "event_espresso"),
119
+					false
120
+				),
121
+				'VNU_address'         => new EE_Plain_Text_Field(
122
+					'VNU_address',
123
+					esc_html__("Venue Address line 1", "event_espresso"),
124
+					true,
125
+					''
126
+				),
127
+				'VNU_address2'        => new EE_Plain_Text_Field(
128
+					'VNU_address2',
129
+					esc_html__("Venue Address line 2", "event_espresso"),
130
+					true,
131
+					''
132
+				),
133
+				'VNU_city'            => new EE_Plain_Text_Field(
134
+					'VNU_city',
135
+					esc_html__("Venue City", "event_espresso"),
136
+					true,
137
+					''
138
+				),
139
+				'STA_ID'              => new EE_Foreign_Key_Int_Field(
140
+					'STA_ID',
141
+					esc_html__("State ID", "event_espresso"),
142
+					true,
143
+					null,
144
+					'State'
145
+				),
146
+				'CNT_ISO'             => new EE_Foreign_Key_String_Field(
147
+					'CNT_ISO',
148
+					esc_html__("Country Code", "event_espresso"),
149
+					true,
150
+					null,
151
+					'Country'
152
+				),
153
+				'VNU_zip'             => new EE_Plain_Text_Field(
154
+					'VNU_zip',
155
+					esc_html__("Venue Zip/Postal Code", "event_espresso"),
156
+					true
157
+				),
158
+				'VNU_phone'           => new EE_Plain_Text_Field(
159
+					'VNU_phone',
160
+					esc_html__("Venue Phone", "event_espresso"),
161
+					true
162
+				),
163
+				'VNU_capacity'        => new EE_Infinite_Integer_Field(
164
+					'VNU_capacity',
165
+					esc_html__("Venue Capacity", "event_espresso"),
166
+					true,
167
+					EE_INF
168
+				),
169
+				'VNU_url'             => new EE_Plain_Text_Field(
170
+					'VNU_url',
171
+					esc_html__('Venue Website', 'event_espresso'),
172
+					true
173
+				),
174
+				'VNU_virtual_phone'   => new EE_Plain_Text_Field(
175
+					'VNU_virtual_phone',
176
+					esc_html__('Call in Number', 'event_espresso'),
177
+					true
178
+				),
179
+				'VNU_virtual_url'     => new EE_Plain_Text_Field(
180
+					'VNU_virtual_url',
181
+					esc_html__('Virtual URL', 'event_espresso'),
182
+					true
183
+				),
184
+				'VNU_google_map_link' => new EE_Plain_Text_Field(
185
+					'VNU_google_map_link',
186
+					esc_html__('Google Map Link', 'event_espresso'),
187
+					true
188
+				),
189
+				'VNU_enable_for_gmap' => new EE_Boolean_Field(
190
+					'VNU_enable_for_gmap',
191
+					esc_html__('Show Google Map?', 'event_espresso'),
192
+					false,
193
+					false
194
+				),
195
+			],
196
+		];
197
+		$this->_model_relations = [
198
+			'Country'           => new EE_Belongs_To_Relation(),
199
+			'Event'             => new EE_Has_Many_Relation(),
200
+			'Datetime'          => new EE_Has_Many_Relation(),
201
+			'State'             => new EE_Belongs_To_Relation(),
202
+			'Term_Relationship' => new EE_Has_Many_Relation(),
203
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
204
+			'WP_User'           => new EE_Belongs_To_Relation(),
205
+		];
206
+		// this model is generally available for reading
207
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
208
+		$this->model_chain_to_password                            = '';
209
+		parent::__construct($timezone);
210
+	}
211 211
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
             'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
27 27
             'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
28 28
         ];
29
-        $this->_fields          = [
29
+        $this->_fields = [
30 30
             'Venue_CPT'  => [
31 31
                 'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', esc_html__("Venue ID", "event_espresso")),
32 32
                 'VNU_name'       => new EE_Plain_Text_Field(
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
             'WP_User'           => new EE_Belongs_To_Relation(),
205 205
         ];
206 206
         // this model is generally available for reading
207
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
207
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
208 208
         $this->model_chain_to_password                            = '';
209 209
         parent::__construct($timezone);
210 210
     }
Please login to merge, or discard this patch.