Completed
Branch BUG/fix-ee-rest-debug-headers (1355bc)
by
unknown
03:29 queued 18s
created
core/db_classes/EE_Payment_Method.class.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -445,11 +445,11 @@  discard block
 block discarded – undo
445 445
      */
446 446
     public function type_obj()
447 447
     {
448
-        if (! $this->_type_obj) {
448
+        if ( ! $this->_type_obj) {
449 449
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
450 450
             if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) {
451 451
                 $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type());
452
-                if (! class_exists($class_name)) {
452
+                if ( ! class_exists($class_name)) {
453 453
                     throw new EE_Error(
454 454
                         sprintf(
455 455
                             esc_html__(
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
                             ),
459 459
                             $class_name,
460 460
                             '<br />',
461
-                            '<a href="' . admin_url('plugins.php') . '">',
461
+                            '<a href="'.admin_url('plugins.php').'">',
462 462
                             '</a>'
463 463
                         )
464 464
                     );
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
         foreach ($fields as $key => $value) {
500 500
             if (strpos($key, 'PMD_') === 0) {
501 501
                 $key_sans_model_prefix = str_replace('PMD_', '', $key);
502
-                $combined_settings_array [ $key_sans_model_prefix ] = $value;
502
+                $combined_settings_array [$key_sans_model_prefix] = $value;
503 503
             }
504 504
         }
505 505
         $combined_settings_array = array_merge($extra_meta, $combined_settings_array);
@@ -522,14 +522,14 @@  discard block
 block discarded – undo
522 522
 		 <div id="'
523 523
                . $this->slug()
524 524
                . '-payment-option-dv" class="'
525
-               . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '">
525
+               . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'">
526 526
 			<a id="payment-gateway-button-' . $this->slug()
527 527
                . '" class="reg-page-payment-option-lnk" rel="'
528
-               . $this->slug() . '" href="' . $url . '" >
529
-				<img src="' . $this->button_url() . '" alt="' . sprintf(
528
+               . $this->slug().'" href="'.$url.'" >
529
+				<img src="' . $this->button_url().'" alt="'.sprintf(
530 530
                    esc_attr__('Pay using %s', 'event_espresso'),
531 531
                    $this->get_pretty('PMD_name', 'form_input')
532
-               ) . '" />
532
+               ).'" />
533 533
 			</a>
534 534
 		</div>
535 535
 ';
Please login to merge, or discard this patch.
Indentation   +572 added lines, -572 removed lines patch added patch discarded remove patch
@@ -13,582 +13,582 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Payment_Method extends EE_Base_Class
15 15
 {
16
-    /**
17
-     * Payment Method type object, which has all the info about this type of payment method,
18
-     * including functions for processing payments, to get settings forms, etc.
19
-     *
20
-     * @var EE_PMT_Base
21
-     */
22
-    protected $_type_obj;
23
-
24
-
25
-    /**
26
-     * @param array $props_n_values
27
-     * @return EE_Payment_Method
28
-     * @throws \EE_Error
29
-     */
30
-    public static function new_instance($props_n_values = array())
31
-    {
32
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
33
-        return $has_object ? $has_object : new self($props_n_values, false);
34
-    }
35
-
36
-
37
-    /**
38
-     * @param array $props_n_values
39
-     * @return EE_Payment_Method
40
-     * @throws \EE_Error
41
-     */
42
-    public static function new_instance_from_db($props_n_values = array())
43
-    {
44
-        return new self($props_n_values, true);
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname.
51
-     * Otherwise returns a normal EE_Payment_Method
52
-     *
53
-     * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically
54
-     *                              the classname minus 'EEPM_')
55
-     * @return string
56
-     */
57
-    // private static function _payment_method_type($props_n_values)
58
-    // {
59
-    //     EE_Registry::instance()->load_lib('Payment_Method_Manager');
60
-    //     $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null;
61
-    //     if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) {
62
-    //         return 'EEPM_' . $type_string;
63
-    //     } else {
64
-    //         return __CLASS__;
65
-    //     }
66
-    // }
67
-
68
-
69
-    /**
70
-     * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc)
71
-     *
72
-     * @return boolean
73
-     */
74
-    public function active()
75
-    {
76
-        return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope());
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets this PM as active by making it usable within the CART scope. Offline gateways
82
-     * are also usable from the admin-scope as well. DOES NOT SAVE it
83
-     *
84
-     * @throws \EE_Error
85
-     */
86
-    public function set_active()
87
-    {
88
-        $default_scopes = array(EEM_Payment_Method::scope_cart);
89
-        if (
90
-            $this->type_obj() &&
91
-            $this->type_obj()->payment_occurs() === EE_PMT_Base::offline
92
-        ) {
93
-            $default_scopes[] = EEM_Payment_Method::scope_admin;
94
-        }
95
-        $this->set_scope($default_scopes);
96
-    }
97
-
98
-
99
-    /**
100
-     * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it.
101
-     */
102
-    public function deactivate()
103
-    {
104
-        $this->set_scope(array());
105
-    }
106
-
107
-
108
-    /**
109
-     * Gets button_url
110
-     *
111
-     * @return string
112
-     */
113
-    public function button_url()
114
-    {
115
-        return $this->get('PMD_button_url');
116
-    }
117
-
118
-
119
-    /**
120
-     * Sets button_url
121
-     *
122
-     * @param string $button_url
123
-     */
124
-    public function set_button_url($button_url)
125
-    {
126
-        $this->set('PMD_button_url', $button_url);
127
-    }
128
-
129
-
130
-    /**
131
-     * Gets debug_mode
132
-     *
133
-     * @return boolean
134
-     */
135
-    public function debug_mode()
136
-    {
137
-        return $this->get('PMD_debug_mode');
138
-    }
139
-
140
-
141
-    /**
142
-     * Sets debug_mode
143
-     *
144
-     * @param boolean $debug_mode
145
-     */
146
-    public function set_debug_mode($debug_mode)
147
-    {
148
-        $this->set('PMD_debug_mode', $debug_mode);
149
-    }
150
-
151
-
152
-    /**
153
-     * Gets description
154
-     *
155
-     * @return string
156
-     */
157
-    public function description()
158
-    {
159
-        return $this->get('PMD_desc');
160
-    }
161
-
162
-
163
-    /**
164
-     * Sets description
165
-     *
166
-     * @param string $description
167
-     */
168
-    public function set_description($description)
169
-    {
170
-        $this->set('PMD_desc', $description);
171
-    }
172
-
173
-
174
-    /**
175
-     * Gets name
176
-     *
177
-     * @return string
178
-     */
179
-    public function name()
180
-    {
181
-        return $this->get('PMD_name');
182
-    }
183
-
184
-
185
-    /**
186
-     * Sets name
187
-     *
188
-     * @param string $name
189
-     */
190
-    public function set_name($name)
191
-    {
192
-        $this->set('PMD_name', $name);
193
-    }
194
-
195
-
196
-    /**
197
-     * Gets open_by_default
198
-     *
199
-     * @return boolean
200
-     */
201
-    public function open_by_default()
202
-    {
203
-        return $this->get('PMD_open_by_default');
204
-    }
205
-
206
-
207
-    /**
208
-     * Sets open_by_default
209
-     *
210
-     * @param boolean $open_by_default
211
-     */
212
-    public function set_open_by_default($open_by_default)
213
-    {
214
-        $this->set('PMD_open_by_default', $open_by_default);
215
-    }
216
-
217
-
218
-    /**
219
-     * Gets order
220
-     *
221
-     * @return int
222
-     */
223
-    public function order()
224
-    {
225
-        return $this->get('PMD_order');
226
-    }
227
-
228
-
229
-    /**
230
-     * Sets order
231
-     *
232
-     * @param int $order
233
-     */
234
-    public function set_order($order)
235
-    {
236
-        $this->set('PMD_order', $order);
237
-    }
238
-
239
-
240
-    /**
241
-     * Gets slug
242
-     *
243
-     * @return string
244
-     */
245
-    public function slug()
246
-    {
247
-        return $this->get('PMD_slug');
248
-    }
249
-
250
-
251
-    /**
252
-     * Sets slug
253
-     *
254
-     * @param string $slug
255
-     */
256
-    public function set_slug($slug)
257
-    {
258
-        $this->set('PMD_slug', $slug);
259
-    }
260
-
261
-
262
-    /**
263
-     * Gets type
264
-     *
265
-     * @return string
266
-     */
267
-    public function type()
268
-    {
269
-        return $this->get('PMD_type');
270
-    }
271
-
272
-
273
-    /**
274
-     * Sets type
275
-     *
276
-     * @param string $type
277
-     */
278
-    public function set_type($type)
279
-    {
280
-        $this->set('PMD_type', $type);
281
-    }
282
-
283
-
284
-    /**
285
-     * Gets wp_user
286
-     *
287
-     * @return int
288
-     */
289
-    public function wp_user()
290
-    {
291
-        return $this->get('PMD_wp_user');
292
-    }
293
-
294
-
295
-    /**
296
-     * Sets wp_user
297
-     *
298
-     * @param int $wp_user_id
299
-     */
300
-    public function set_wp_user($wp_user_id)
301
-    {
302
-        $this->set('PMD_wp_user', $wp_user_id);
303
-    }
304
-
305
-    /**
306
-     * Overrides parent so when PMD_type is changed we refresh the _type_obj
307
-     *
308
-     * @param string $field_name
309
-     * @param mixed $field_value
310
-     * @param boolean $use_default
311
-     */
312
-    public function set($field_name, $field_value, $use_default = false)
313
-    {
314
-        if ($field_name === 'PMD_type') {
315
-            // the type has probably changed, so forget about its old type object
316
-            $this->_type_obj = null;
317
-        }
318
-        parent::set($field_name, $field_value, $use_default);
319
-    }
320
-
321
-
322
-    /**
323
-     * Gets admin_name
324
-     *
325
-     * @return string
326
-     */
327
-    public function admin_name()
328
-    {
329
-        return $this->get('PMD_admin_name');
330
-    }
331
-
332
-
333
-    /**
334
-     * Sets admin_name
335
-     *
336
-     * @param string $admin_name
337
-     */
338
-    public function set_admin_name($admin_name)
339
-    {
340
-        $this->set('PMD_admin_name', $admin_name);
341
-    }
342
-
343
-
344
-    /**
345
-     * Gets admin_desc
346
-     *
347
-     * @return string
348
-     */
349
-    public function admin_desc()
350
-    {
351
-        return $this->get('PMD_admin_desc');
352
-    }
353
-
354
-
355
-    /**
356
-     * Sets admin_desc
357
-     *
358
-     * @param string $admin_desc
359
-     */
360
-    public function set_admin_desc($admin_desc)
361
-    {
362
-        $this->set('PMD_admin_desc', $admin_desc);
363
-    }
364
-
365
-
366
-    /**
367
-     * Gets scope
368
-     *
369
-     * @return array
370
-     */
371
-    public function scope()
372
-    {
373
-        return $this->get('PMD_scope');
374
-    }
375
-
376
-
377
-    /**
378
-     * Sets scope
379
-     *
380
-     * @param array $scope
381
-     */
382
-    public function set_scope($scope)
383
-    {
384
-        $this->set('PMD_scope', $scope);
385
-    }
386
-
387
-
388
-    /**
389
-     * Gets the payment method type for this payment method instance
390
-     *
391
-     * @return EE_PMT_Base
392
-     * @throws EE_Error
393
-     */
394
-    public function type_obj()
395
-    {
396
-        if (! $this->_type_obj) {
397
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
398
-            if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) {
399
-                $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type());
400
-                if (! class_exists($class_name)) {
401
-                    throw new EE_Error(
402
-                        sprintf(
403
-                            esc_html__(
404
-                                'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s',
405
-                                'event_espresso'
406
-                            ),
407
-                            $class_name,
408
-                            '<br />',
409
-                            '<a href="' . admin_url('plugins.php') . '">',
410
-                            '</a>'
411
-                        )
412
-                    );
413
-                }
414
-                $r = new ReflectionClass($class_name);
415
-                $this->_type_obj = $r->newInstanceArgs(array($this));
416
-            } else {
417
-                throw new EE_Error(
418
-                    sprintf(
419
-                        esc_html__(
420
-                            'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s',
421
-                            'event_espresso'
422
-                        ),
423
-                        $this->type(),
424
-                        implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names())
425
-                    )
426
-                );
427
-            }
428
-        }
429
-        return $this->_type_obj;
430
-    }
431
-
432
-
433
-    /**
434
-     * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix)
435
-     * and the extra meta. Mostly used for passing off ot gateways.     *
436
-     *
437
-     * @return array
438
-     */
439
-    public function settings_array()
440
-    {
441
-        $fields = $this->model_field_array();
442
-        $extra_meta = $this->all_extra_meta_array();
443
-        // remove the model's prefix from the fields
444
-        $combined_settings_array = array();
445
-        foreach ($fields as $key => $value) {
446
-            if (strpos($key, 'PMD_') === 0) {
447
-                $key_sans_model_prefix = str_replace('PMD_', '', $key);
448
-                $combined_settings_array [ $key_sans_model_prefix ] = $value;
449
-            }
450
-        }
451
-        $combined_settings_array = array_merge($extra_meta, $combined_settings_array);
452
-        return $combined_settings_array;
453
-    }
454
-
455
-
456
-    /**
457
-     * Gets the HTML for displaying the payment method on a page.
458
-     *
459
-     * @param string $url
460
-     * @param string $css_class
461
-     * @return string of HTML for displaying the button
462
-     * @throws \EE_Error
463
-     */
464
-    public function button_html($url = '', $css_class = '')
465
-    {
466
-        $payment_occurs = $this->type_obj()->payment_occurs();
467
-        return '
16
+	/**
17
+	 * Payment Method type object, which has all the info about this type of payment method,
18
+	 * including functions for processing payments, to get settings forms, etc.
19
+	 *
20
+	 * @var EE_PMT_Base
21
+	 */
22
+	protected $_type_obj;
23
+
24
+
25
+	/**
26
+	 * @param array $props_n_values
27
+	 * @return EE_Payment_Method
28
+	 * @throws \EE_Error
29
+	 */
30
+	public static function new_instance($props_n_values = array())
31
+	{
32
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
33
+		return $has_object ? $has_object : new self($props_n_values, false);
34
+	}
35
+
36
+
37
+	/**
38
+	 * @param array $props_n_values
39
+	 * @return EE_Payment_Method
40
+	 * @throws \EE_Error
41
+	 */
42
+	public static function new_instance_from_db($props_n_values = array())
43
+	{
44
+		return new self($props_n_values, true);
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname.
51
+	 * Otherwise returns a normal EE_Payment_Method
52
+	 *
53
+	 * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically
54
+	 *                              the classname minus 'EEPM_')
55
+	 * @return string
56
+	 */
57
+	// private static function _payment_method_type($props_n_values)
58
+	// {
59
+	//     EE_Registry::instance()->load_lib('Payment_Method_Manager');
60
+	//     $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null;
61
+	//     if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) {
62
+	//         return 'EEPM_' . $type_string;
63
+	//     } else {
64
+	//         return __CLASS__;
65
+	//     }
66
+	// }
67
+
68
+
69
+	/**
70
+	 * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc)
71
+	 *
72
+	 * @return boolean
73
+	 */
74
+	public function active()
75
+	{
76
+		return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope());
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets this PM as active by making it usable within the CART scope. Offline gateways
82
+	 * are also usable from the admin-scope as well. DOES NOT SAVE it
83
+	 *
84
+	 * @throws \EE_Error
85
+	 */
86
+	public function set_active()
87
+	{
88
+		$default_scopes = array(EEM_Payment_Method::scope_cart);
89
+		if (
90
+			$this->type_obj() &&
91
+			$this->type_obj()->payment_occurs() === EE_PMT_Base::offline
92
+		) {
93
+			$default_scopes[] = EEM_Payment_Method::scope_admin;
94
+		}
95
+		$this->set_scope($default_scopes);
96
+	}
97
+
98
+
99
+	/**
100
+	 * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it.
101
+	 */
102
+	public function deactivate()
103
+	{
104
+		$this->set_scope(array());
105
+	}
106
+
107
+
108
+	/**
109
+	 * Gets button_url
110
+	 *
111
+	 * @return string
112
+	 */
113
+	public function button_url()
114
+	{
115
+		return $this->get('PMD_button_url');
116
+	}
117
+
118
+
119
+	/**
120
+	 * Sets button_url
121
+	 *
122
+	 * @param string $button_url
123
+	 */
124
+	public function set_button_url($button_url)
125
+	{
126
+		$this->set('PMD_button_url', $button_url);
127
+	}
128
+
129
+
130
+	/**
131
+	 * Gets debug_mode
132
+	 *
133
+	 * @return boolean
134
+	 */
135
+	public function debug_mode()
136
+	{
137
+		return $this->get('PMD_debug_mode');
138
+	}
139
+
140
+
141
+	/**
142
+	 * Sets debug_mode
143
+	 *
144
+	 * @param boolean $debug_mode
145
+	 */
146
+	public function set_debug_mode($debug_mode)
147
+	{
148
+		$this->set('PMD_debug_mode', $debug_mode);
149
+	}
150
+
151
+
152
+	/**
153
+	 * Gets description
154
+	 *
155
+	 * @return string
156
+	 */
157
+	public function description()
158
+	{
159
+		return $this->get('PMD_desc');
160
+	}
161
+
162
+
163
+	/**
164
+	 * Sets description
165
+	 *
166
+	 * @param string $description
167
+	 */
168
+	public function set_description($description)
169
+	{
170
+		$this->set('PMD_desc', $description);
171
+	}
172
+
173
+
174
+	/**
175
+	 * Gets name
176
+	 *
177
+	 * @return string
178
+	 */
179
+	public function name()
180
+	{
181
+		return $this->get('PMD_name');
182
+	}
183
+
184
+
185
+	/**
186
+	 * Sets name
187
+	 *
188
+	 * @param string $name
189
+	 */
190
+	public function set_name($name)
191
+	{
192
+		$this->set('PMD_name', $name);
193
+	}
194
+
195
+
196
+	/**
197
+	 * Gets open_by_default
198
+	 *
199
+	 * @return boolean
200
+	 */
201
+	public function open_by_default()
202
+	{
203
+		return $this->get('PMD_open_by_default');
204
+	}
205
+
206
+
207
+	/**
208
+	 * Sets open_by_default
209
+	 *
210
+	 * @param boolean $open_by_default
211
+	 */
212
+	public function set_open_by_default($open_by_default)
213
+	{
214
+		$this->set('PMD_open_by_default', $open_by_default);
215
+	}
216
+
217
+
218
+	/**
219
+	 * Gets order
220
+	 *
221
+	 * @return int
222
+	 */
223
+	public function order()
224
+	{
225
+		return $this->get('PMD_order');
226
+	}
227
+
228
+
229
+	/**
230
+	 * Sets order
231
+	 *
232
+	 * @param int $order
233
+	 */
234
+	public function set_order($order)
235
+	{
236
+		$this->set('PMD_order', $order);
237
+	}
238
+
239
+
240
+	/**
241
+	 * Gets slug
242
+	 *
243
+	 * @return string
244
+	 */
245
+	public function slug()
246
+	{
247
+		return $this->get('PMD_slug');
248
+	}
249
+
250
+
251
+	/**
252
+	 * Sets slug
253
+	 *
254
+	 * @param string $slug
255
+	 */
256
+	public function set_slug($slug)
257
+	{
258
+		$this->set('PMD_slug', $slug);
259
+	}
260
+
261
+
262
+	/**
263
+	 * Gets type
264
+	 *
265
+	 * @return string
266
+	 */
267
+	public function type()
268
+	{
269
+		return $this->get('PMD_type');
270
+	}
271
+
272
+
273
+	/**
274
+	 * Sets type
275
+	 *
276
+	 * @param string $type
277
+	 */
278
+	public function set_type($type)
279
+	{
280
+		$this->set('PMD_type', $type);
281
+	}
282
+
283
+
284
+	/**
285
+	 * Gets wp_user
286
+	 *
287
+	 * @return int
288
+	 */
289
+	public function wp_user()
290
+	{
291
+		return $this->get('PMD_wp_user');
292
+	}
293
+
294
+
295
+	/**
296
+	 * Sets wp_user
297
+	 *
298
+	 * @param int $wp_user_id
299
+	 */
300
+	public function set_wp_user($wp_user_id)
301
+	{
302
+		$this->set('PMD_wp_user', $wp_user_id);
303
+	}
304
+
305
+	/**
306
+	 * Overrides parent so when PMD_type is changed we refresh the _type_obj
307
+	 *
308
+	 * @param string $field_name
309
+	 * @param mixed $field_value
310
+	 * @param boolean $use_default
311
+	 */
312
+	public function set($field_name, $field_value, $use_default = false)
313
+	{
314
+		if ($field_name === 'PMD_type') {
315
+			// the type has probably changed, so forget about its old type object
316
+			$this->_type_obj = null;
317
+		}
318
+		parent::set($field_name, $field_value, $use_default);
319
+	}
320
+
321
+
322
+	/**
323
+	 * Gets admin_name
324
+	 *
325
+	 * @return string
326
+	 */
327
+	public function admin_name()
328
+	{
329
+		return $this->get('PMD_admin_name');
330
+	}
331
+
332
+
333
+	/**
334
+	 * Sets admin_name
335
+	 *
336
+	 * @param string $admin_name
337
+	 */
338
+	public function set_admin_name($admin_name)
339
+	{
340
+		$this->set('PMD_admin_name', $admin_name);
341
+	}
342
+
343
+
344
+	/**
345
+	 * Gets admin_desc
346
+	 *
347
+	 * @return string
348
+	 */
349
+	public function admin_desc()
350
+	{
351
+		return $this->get('PMD_admin_desc');
352
+	}
353
+
354
+
355
+	/**
356
+	 * Sets admin_desc
357
+	 *
358
+	 * @param string $admin_desc
359
+	 */
360
+	public function set_admin_desc($admin_desc)
361
+	{
362
+		$this->set('PMD_admin_desc', $admin_desc);
363
+	}
364
+
365
+
366
+	/**
367
+	 * Gets scope
368
+	 *
369
+	 * @return array
370
+	 */
371
+	public function scope()
372
+	{
373
+		return $this->get('PMD_scope');
374
+	}
375
+
376
+
377
+	/**
378
+	 * Sets scope
379
+	 *
380
+	 * @param array $scope
381
+	 */
382
+	public function set_scope($scope)
383
+	{
384
+		$this->set('PMD_scope', $scope);
385
+	}
386
+
387
+
388
+	/**
389
+	 * Gets the payment method type for this payment method instance
390
+	 *
391
+	 * @return EE_PMT_Base
392
+	 * @throws EE_Error
393
+	 */
394
+	public function type_obj()
395
+	{
396
+		if (! $this->_type_obj) {
397
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
398
+			if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) {
399
+				$class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type());
400
+				if (! class_exists($class_name)) {
401
+					throw new EE_Error(
402
+						sprintf(
403
+							esc_html__(
404
+								'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s',
405
+								'event_espresso'
406
+							),
407
+							$class_name,
408
+							'<br />',
409
+							'<a href="' . admin_url('plugins.php') . '">',
410
+							'</a>'
411
+						)
412
+					);
413
+				}
414
+				$r = new ReflectionClass($class_name);
415
+				$this->_type_obj = $r->newInstanceArgs(array($this));
416
+			} else {
417
+				throw new EE_Error(
418
+					sprintf(
419
+						esc_html__(
420
+							'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s',
421
+							'event_espresso'
422
+						),
423
+						$this->type(),
424
+						implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names())
425
+					)
426
+				);
427
+			}
428
+		}
429
+		return $this->_type_obj;
430
+	}
431
+
432
+
433
+	/**
434
+	 * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix)
435
+	 * and the extra meta. Mostly used for passing off ot gateways.     *
436
+	 *
437
+	 * @return array
438
+	 */
439
+	public function settings_array()
440
+	{
441
+		$fields = $this->model_field_array();
442
+		$extra_meta = $this->all_extra_meta_array();
443
+		// remove the model's prefix from the fields
444
+		$combined_settings_array = array();
445
+		foreach ($fields as $key => $value) {
446
+			if (strpos($key, 'PMD_') === 0) {
447
+				$key_sans_model_prefix = str_replace('PMD_', '', $key);
448
+				$combined_settings_array [ $key_sans_model_prefix ] = $value;
449
+			}
450
+		}
451
+		$combined_settings_array = array_merge($extra_meta, $combined_settings_array);
452
+		return $combined_settings_array;
453
+	}
454
+
455
+
456
+	/**
457
+	 * Gets the HTML for displaying the payment method on a page.
458
+	 *
459
+	 * @param string $url
460
+	 * @param string $css_class
461
+	 * @return string of HTML for displaying the button
462
+	 * @throws \EE_Error
463
+	 */
464
+	public function button_html($url = '', $css_class = '')
465
+	{
466
+		$payment_occurs = $this->type_obj()->payment_occurs();
467
+		return '
468 468
 		 <div id="'
469
-               . $this->slug()
470
-               . '-payment-option-dv" class="'
471
-               . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '">
469
+			   . $this->slug()
470
+			   . '-payment-option-dv" class="'
471
+			   . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '">
472 472
 			<a id="payment-gateway-button-' . $this->slug()
473
-               . '" class="reg-page-payment-option-lnk" rel="'
474
-               . $this->slug() . '" href="' . $url . '" >
473
+			   . '" class="reg-page-payment-option-lnk" rel="'
474
+			   . $this->slug() . '" href="' . $url . '" >
475 475
 				<img src="' . $this->button_url() . '" alt="' . sprintf(
476
-                   esc_attr__('Pay using %s', 'event_espresso'),
477
-                   $this->get_pretty('PMD_name', 'form_input')
478
-               ) . '" />
476
+				   esc_attr__('Pay using %s', 'event_espresso'),
477
+				   $this->get_pretty('PMD_name', 'form_input')
478
+			   ) . '" />
479 479
 			</a>
480 480
 		</div>
481 481
 ';
482
-    }
483
-
484
-
485
-    /**
486
-     * Gets all the currencies which are an option for this payment method
487
-     * (as defined by the gateway and the currently active currencies)
488
-     *
489
-     * @return EE_Currency[]
490
-     * @throws \EE_Error
491
-     */
492
-    public function get_all_usable_currencies()
493
-    {
494
-        return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj());
495
-    }
496
-
497
-
498
-    /**
499
-     * Reports whether or not this payment method can be used for this payment method
500
-     *
501
-     * @param string $currency_code currency ID (code)
502
-     * @return boolean
503
-     * @throws \EE_Error
504
-     */
505
-    public function usable_for_currency($currency_code)
506
-    {
507
-        foreach ($this->get_all_usable_currencies() as $currency_obj) {
508
-            if ($currency_obj->ID() === $currency_code) {
509
-                return true;
510
-            }
511
-        }
512
-        return false;
513
-    }
514
-
515
-
516
-    /**
517
-     * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway
518
-     *
519
-     * @return bool
520
-     * @throws \EE_Error
521
-     */
522
-    public function is_on_site()
523
-    {
524
-        return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite;
525
-    }
526
-
527
-
528
-    /**
529
-     * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway
530
-     *
531
-     * @return bool
532
-     * @throws \EE_Error
533
-     */
534
-    public function is_off_site()
535
-    {
536
-        return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite;
537
-    }
538
-
539
-
540
-    /**
541
-     * Returns TRUE if this payment method does not utilize a gateway
542
-     *
543
-     * @return bool
544
-     * @throws \EE_Error
545
-     */
546
-    public function is_off_line()
547
-    {
548
-        return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline;
549
-    }
550
-
551
-    /**
552
-     * Overrides default __sleep so the object type is NOT cached.
553
-     * This way we can rely on the normal EE_Payment_Method::type_obj() logic
554
-     * to load the required classes, and don't need them at the time of unserialization
555
-     *
556
-     * @return array
557
-     */
558
-    public function __sleep()
559
-    {
560
-        $properties = get_object_vars($this);
561
-        unset($properties['_type_obj']);
562
-        return array_keys($properties);
563
-    }
564
-
565
-
566
-    /**
567
-     * Overrides parent to add some logging for when payment methods get deactivated
568
-     *
569
-     * @param array $set_cols_n_values
570
-     * @return int @see EE_Base_Class::save()
571
-     * @throws \EE_Error
572
-     */
573
-    public function save($set_cols_n_values = array())
574
-    {
575
-        $results = parent::save($set_cols_n_values);
576
-        if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) {
577
-            /** @var CurrentPage $current_page */
578
-            $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
579
-            EE_Log::instance()->log(
580
-                __FILE__,
581
-                __FUNCTION__,
582
-                sprintf(
583
-                    esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'),
584
-                    $this->name(),
585
-                    serialize($this->get_original('PMD_scope')),
586
-                    serialize($this->get('PMD_scope')),
587
-                    $current_page->getPermalink()
588
-                ),
589
-                'payment_method_change'
590
-            );
591
-        }
592
-        return $results;
593
-    }
482
+	}
483
+
484
+
485
+	/**
486
+	 * Gets all the currencies which are an option for this payment method
487
+	 * (as defined by the gateway and the currently active currencies)
488
+	 *
489
+	 * @return EE_Currency[]
490
+	 * @throws \EE_Error
491
+	 */
492
+	public function get_all_usable_currencies()
493
+	{
494
+		return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj());
495
+	}
496
+
497
+
498
+	/**
499
+	 * Reports whether or not this payment method can be used for this payment method
500
+	 *
501
+	 * @param string $currency_code currency ID (code)
502
+	 * @return boolean
503
+	 * @throws \EE_Error
504
+	 */
505
+	public function usable_for_currency($currency_code)
506
+	{
507
+		foreach ($this->get_all_usable_currencies() as $currency_obj) {
508
+			if ($currency_obj->ID() === $currency_code) {
509
+				return true;
510
+			}
511
+		}
512
+		return false;
513
+	}
514
+
515
+
516
+	/**
517
+	 * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway
518
+	 *
519
+	 * @return bool
520
+	 * @throws \EE_Error
521
+	 */
522
+	public function is_on_site()
523
+	{
524
+		return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite;
525
+	}
526
+
527
+
528
+	/**
529
+	 * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway
530
+	 *
531
+	 * @return bool
532
+	 * @throws \EE_Error
533
+	 */
534
+	public function is_off_site()
535
+	{
536
+		return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite;
537
+	}
538
+
539
+
540
+	/**
541
+	 * Returns TRUE if this payment method does not utilize a gateway
542
+	 *
543
+	 * @return bool
544
+	 * @throws \EE_Error
545
+	 */
546
+	public function is_off_line()
547
+	{
548
+		return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline;
549
+	}
550
+
551
+	/**
552
+	 * Overrides default __sleep so the object type is NOT cached.
553
+	 * This way we can rely on the normal EE_Payment_Method::type_obj() logic
554
+	 * to load the required classes, and don't need them at the time of unserialization
555
+	 *
556
+	 * @return array
557
+	 */
558
+	public function __sleep()
559
+	{
560
+		$properties = get_object_vars($this);
561
+		unset($properties['_type_obj']);
562
+		return array_keys($properties);
563
+	}
564
+
565
+
566
+	/**
567
+	 * Overrides parent to add some logging for when payment methods get deactivated
568
+	 *
569
+	 * @param array $set_cols_n_values
570
+	 * @return int @see EE_Base_Class::save()
571
+	 * @throws \EE_Error
572
+	 */
573
+	public function save($set_cols_n_values = array())
574
+	{
575
+		$results = parent::save($set_cols_n_values);
576
+		if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) {
577
+			/** @var CurrentPage $current_page */
578
+			$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
579
+			EE_Log::instance()->log(
580
+				__FILE__,
581
+				__FUNCTION__,
582
+				sprintf(
583
+					esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'),
584
+					$this->name(),
585
+					serialize($this->get_original('PMD_scope')),
586
+					serialize($this->get('PMD_scope')),
587
+					$current_page->getPermalink()
588
+				),
589
+				'payment_method_change'
590
+			);
591
+		}
592
+		return $results;
593
+	}
594 594
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message.model.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
             self::priority_low    => esc_html__('low', 'event_espresso'),
127 127
         );
128 128
 
129
-        $this->_fields          = array(
129
+        $this->_fields = array(
130 130
             'Message' => array(
131 131
                 'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
132 132
                 'MSG_token'          => new EE_Plain_Text_Field(
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
                         );
437 437
                         break;
438 438
                     default:
439
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
439
+                        $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value;
440 440
                         break;
441 441
                 }
442 442
             }
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
         if ($label_parts) {
500 500
             // prepend to the last element of $label_parts an "and".
501 501
             if (count($label_parts) > 1) {
502
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
503
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
502
+                $label_parts_index_to_prepend = count($label_parts) - 1;
503
+                $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend];
504 504
             }
505 505
 
506 506
             $pretty_label .= sprintf(
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
             $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
561 561
         }
562 562
 
563
-        if (! is_null($set_debug)) {
563
+        if ( ! is_null($set_debug)) {
564 564
             $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
565 565
         }
566 566
 
@@ -627,13 +627,13 @@  discard block
 block discarded – undo
627 627
             )
628 628
         );
629 629
 
630
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
630
+        if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
631 631
             global $wpdb;
632 632
             $number_deleted = $wpdb->query('
633 633
                 DELETE
634
-                FROM ' . $this->table() . '
634
+                FROM ' . $this->table().'
635 635
                 WHERE
636
-                    MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
636
+                    MSG_ID IN (' . implode(",", $message_ids_to_delete).')
637 637
             ');
638 638
         }
639 639
 
Please login to merge, or discard this patch.
Indentation   +640 added lines, -640 removed lines patch added patch discarded remove patch
@@ -12,649 +12,649 @@
 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;
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 $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 info to
108
-     *                         the date time model field objects.  Default is null (and will be assumed using the set
109
-     *                         timezone in the 'timezone_string' wp option)
110
-     * @throws EE_Error
111
-     * @throws EE_Error
112
-     * @throws EE_Error
113
-     */
114
-    protected function __construct($timezone = null)
115
-    {
116
-        $this->singular_item = esc_html__('Message', 'event_espresso');
117
-        $this->plural_item   = esc_html__('Messages', 'event_espresso');
118
-
119
-        $this->_tables = array(
120
-            'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
121
-        );
122
-
123
-        $allowed_priority = array(
124
-            self::priority_high   => esc_html__('high', 'event_espresso'),
125
-            self::priority_medium => esc_html__('medium', 'event_espresso'),
126
-            self::priority_low    => esc_html__('low', 'event_espresso'),
127
-        );
128
-
129
-        $this->_fields          = array(
130
-            'Message' => array(
131
-                'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
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__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
170
-                    false,
171
-                    'receipt'
172
-                ),
173
-                'MSG_context'        => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false),
174
-                'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
175
-                    'MSG_recipient_ID',
176
-                    esc_html__('Recipient ID', 'event_espresso'),
177
-                    true,
178
-                    null,
179
-                    array('Registration', 'Attendee', 'WP_User')
180
-                ),
181
-                'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
182
-                    'MSG_recipient_type',
183
-                    esc_html__('Recipient Type', 'event_espresso'),
184
-                    true,
185
-                    null,
186
-                    array('Registration', 'Attendee', 'WP_User')
187
-                ),
188
-                'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
189
-                    'MSG_content',
190
-                    esc_html__('Content', 'event_espresso'),
191
-                    true,
192
-                    ''
193
-                ),
194
-                'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
195
-                    'MSG_to',
196
-                    esc_html__('Address To', 'event_espresso'),
197
-                    true
198
-                ),
199
-                'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
200
-                    'MSG_from',
201
-                    esc_html__('Address From', 'event_espresso'),
202
-                    true
203
-                ),
204
-                'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
205
-                    'MSG_subject',
206
-                    esc_html__('Subject', 'event_espresso'),
207
-                    true,
208
-                    ''
209
-                ),
210
-                'MSG_priority'       => new EE_Enum_Integer_Field(
211
-                    'MSG_priority',
212
-                    esc_html__('Priority', 'event_espresso'),
213
-                    false,
214
-                    self::priority_low,
215
-                    $allowed_priority
216
-                ),
217
-                'STS_ID'             => new EE_Foreign_Key_String_Field(
218
-                    'STS_ID',
219
-                    esc_html__('Status', 'event_espresso'),
220
-                    false,
221
-                    self::status_incomplete,
222
-                    'Status'
223
-                ),
224
-                'MSG_created'        => new EE_Datetime_Field(
225
-                    'MSG_created',
226
-                    esc_html__('Created', 'event_espresso'),
227
-                    false,
228
-                    EE_Datetime_Field::now
229
-                ),
230
-                'MSG_modified'       => new EE_Datetime_Field(
231
-                    'MSG_modified',
232
-                    esc_html__('Modified', 'event_espresso'),
233
-                    true,
234
-                    EE_Datetime_Field::now
235
-                ),
236
-            ),
237
-        );
238
-        $this->_model_relations = array(
239
-            'Attendee'               => new EE_Belongs_To_Any_Relation(),
240
-            'Registration'           => new EE_Belongs_To_Any_Relation(),
241
-            'WP_User'                => new EE_Belongs_To_Any_Relation(),
242
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
243
-            'Transaction'            => new EE_Belongs_To_Relation(),
244
-        );
245
-        parent::__construct($timezone);
246
-    }
247
-
248
-
249
-    /**
250
-     * @return EE_Message
251
-     * @throws EE_Error
252
-     */
253
-    public function create_default_object()
254
-    {
255
-        /** @type EE_Message $message */
256
-        $message = parent::create_default_object();
257
-        if ($message instanceof EE_Message) {
258
-            return EE_Message_Factory::set_messenger_and_message_type($message);
259
-        }
260
-        return null;
261
-    }
262
-
263
-
264
-    /**
265
-     * @param mixed $cols_n_values
266
-     * @return EE_Message
267
-     * @throws EE_Error
268
-     * @throws EE_Error
269
-     */
270
-    public function instantiate_class_from_array_or_object($cols_n_values)
271
-    {
272
-        /** @type EE_Message $message */
273
-        $message = parent::instantiate_class_from_array_or_object($cols_n_values);
274
-        if ($message instanceof EE_Message) {
275
-            return EE_Message_Factory::set_messenger_and_message_type($message);
276
-        }
277
-        return null;
278
-    }
279
-
280
-
281
-    /**
282
-     * Returns whether or not a message of that type was sent for a given attendee.
283
-     *
284
-     * @param EE_Attendee|int $attendee
285
-     * @param string          $message_type the message type slug
286
-     * @return boolean
287
-     * @throws EE_Error
288
-     * @throws EE_Error
289
-     * @throws EE_Error
290
-     */
291
-    public function message_sent_for_attendee($attendee, $message_type)
292
-    {
293
-        $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
294
-        return $this->exists(array(
295
-            array(
296
-                'Attendee.ATT_ID'  => $attendee_ID,
297
-                'MSG_message_type' => $message_type,
298
-                'STS_ID'           => array('IN', $this->stati_indicating_sent()),
299
-            ),
300
-        ));
301
-    }
302
-
303
-
304
-    /**
305
-     * Returns whether or not a message of that type was sent for a given registration
306
-     *
307
-     * @param EE_Registration|int $registration
308
-     * @param string              $message_type the message type slug
309
-     * @return boolean
310
-     * @throws EE_Error
311
-     * @throws EE_Error
312
-     * @throws EE_Error
313
-     */
314
-    public function message_sent_for_registration($registration, $message_type)
315
-    {
316
-        $registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
317
-        return $this->exists(array(
318
-            array(
319
-                'Registration.REG_ID' => $registrationID,
320
-                'MSG_message_type'    => $message_type,
321
-                'STS_ID'              => array('IN', $this->stati_indicating_sent()),
322
-            ),
323
-        ));
324
-    }
325
-
326
-
327
-    /**
328
-     * This retrieves an EE_Message object from the db matching the given token string.
329
-     *
330
-     * @param string $token
331
-     * @return EE_Message
332
-     * @throws EE_Error
333
-     */
334
-    public function get_one_by_token($token)
335
-    {
336
-        return $this->get_one(array(
337
-            array(
338
-                'MSG_token' => $token,
339
-            ),
340
-        ));
341
-    }
342
-
343
-
344
-    /**
345
-     * Returns stati that indicate the message HAS been sent
346
-     *
347
-     * @return array of strings for possible stati
348
-     */
349
-    public function stati_indicating_sent()
350
-    {
351
-        return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
352
-    }
353
-
354
-
355
-    /**
356
-     * Returns stati that indicate the message is waiting to be sent.
357
-     *
358
-     * @return array of strings for possible stati.
359
-     */
360
-    public function stati_indicating_to_send()
361
-    {
362
-        return apply_filters(
363
-            'FHEE__EEM_Message__stati_indicating_to_send',
364
-            array(self::status_idle, self::status_resend)
365
-        );
366
-    }
367
-
368
-
369
-    /**
370
-     * Returns stati that indicate the message has failed sending
371
-     *
372
-     * @return array  array of strings for possible stati.
373
-     */
374
-    public function stati_indicating_failed_sending()
375
-    {
376
-        $failed_stati = array(
377
-            self::status_failed,
378
-            self::status_retry,
379
-            self::status_messenger_executing,
380
-        );
381
-        // if WP_DEBUG is set, then let's include debug_only fails
382
-        if (WP_DEBUG) {
383
-            $failed_stati[] = self::status_debug_only;
384
-        }
385
-        return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
386
-    }
387
-
388
-
389
-    /**
390
-     * Returns filterable array of all EEM_Message statuses.
391
-     *
392
-     * @return array
393
-     */
394
-    public function all_statuses()
395
-    {
396
-        return apply_filters(
397
-            'FHEE__EEM_Message__all_statuses',
398
-            array(
399
-                EEM_Message::status_sent,
400
-                EEM_Message::status_incomplete,
401
-                EEM_Message::status_idle,
402
-                EEM_Message::status_resend,
403
-                EEM_Message::status_retry,
404
-                EEM_Message::status_failed,
405
-                EEM_Message::status_messenger_executing,
406
-                EEM_Message::status_debug_only,
407
-            )
408
-        );
409
-    }
410
-
411
-    /**
412
-     * Detects any specific query variables in the request and uses those to setup appropriate
413
-     * filter for any queries.
414
-     *
415
-     * @return array
416
-     */
417
-    public function filter_by_query_params()
418
-    {
419
-        /** @var RequestInterface $request */
420
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
421
-        // expected possible query_vars, the key in this array matches an expected key in the request,
422
-        // the value, matches the corresponding EEM_Base child reference.
423
-        $expected_vars   = $this->_expected_vars_for_query_inject();
424
-        $query_params[0] = array();
425
-        foreach ($expected_vars as $request_key => $model_name) {
426
-            $request_value = $request->getRequestParam($request_key);
427
-            if ($request_value) {
428
-                // special case
429
-                switch ($request_key) {
430
-                    case '_REG_ID':
431
-                        $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
432
-                            'Transaction.Registration.REG_ID' => $request_value,
433
-                        );
434
-                        break;
435
-                    case 'EVT_ID':
436
-                        $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
437
-                            'Transaction.Registration.EVT_ID' => $request_value,
438
-                        );
439
-                        break;
440
-                    default:
441
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
442
-                        break;
443
-                }
444
-            }
445
-        }
446
-        return $query_params;
447
-    }
448
-
449
-
450
-    /**
451
-     * @return string
452
-     * @throws EE_Error
453
-     * @throws ReflectionException
454
-     */
455
-    public function get_pretty_label_for_results()
456
-    {
457
-        /** @var RequestInterface $request */
458
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
459
-        $expected_vars = $this->_expected_vars_for_query_inject();
460
-        $pretty_label  = '';
461
-        $label_parts   = array();
462
-        foreach ($expected_vars as $request_key => $model_name) {
463
-            $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
464
-            $model = EEM_Base::$loader->getShared($model_name);
465
-            $model_field_value = $request->getRequestParam($request_key);
466
-            if ($model instanceof EEM_Base && $model_field_value !== '') {
467
-                switch ($request_key) {
468
-                    case '_REG_ID':
469
-                        $label_parts[] = sprintf(
470
-                            esc_html__('Registration with the ID: %s', 'event_espresso'),
471
-                            $model_field_value
472
-                        );
473
-                        break;
474
-                    case 'ATT_ID':
475
-                        /** @var EE_Attendee $attendee */
476
-                        $attendee      = $model->get_one_by_ID($model_field_value);
477
-                        $label_parts[] = $attendee instanceof EE_Attendee
478
-                            ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
479
-                            : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
480
-                        break;
481
-                    case 'ID':
482
-                        /** @var EE_WP_User $wpUser */
483
-                        $wpUser        = $model->get_one_by_ID($model_field_value);
484
-                        $label_parts[] = $wpUser instanceof EE_WP_User
485
-                            ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
486
-                            : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
487
-                        break;
488
-                    case 'TXN_ID':
489
-                        $label_parts[] = sprintf(
490
-                            esc_html__('Transaction with the ID: %s', 'event_espresso'),
491
-                            $model_field_value
492
-                        );
493
-                        break;
494
-                    case 'EVT_ID':
495
-                        /** @var EE_Event $Event */
496
-                        $Event         = $model->get_one_by_ID($model_field_value);
497
-                        $label_parts[] = $Event instanceof EE_Event
498
-                            ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
499
-                            : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
500
-                        break;
501
-                }
502
-            }
503
-        }
504
-
505
-        if ($label_parts) {
506
-            // prepend to the last element of $label_parts an "and".
507
-            if (count($label_parts) > 1) {
508
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
509
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
510
-            }
511
-
512
-            $pretty_label .= sprintf(
513
-                esc_html_x(
514
-                    'Showing messages for %s',
515
-                    '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.',
516
-                    'event_espresso'
517
-                ),
518
-                implode(', ', $label_parts)
519
-            );
520
-        }
521
-        return $pretty_label;
522
-    }
523
-
524
-
525
-    /**
526
-     * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
527
-     * The array is in the format:
528
-     * array(
529
-     *  {$field_name} => {$model_name}
530
-     * );
531
-     *
532
-     * @since 4.9.0
533
-     * @return array
534
-     */
535
-    protected function _expected_vars_for_query_inject()
536
-    {
537
-        return array(
538
-            '_REG_ID' => 'Registration',
539
-            'ATT_ID'  => 'Attendee',
540
-            'ID'      => 'WP_User',
541
-            'TXN_ID'  => 'Transaction',
542
-            'EVT_ID'  => 'Event',
543
-        );
544
-    }
545
-
546
-
547
-    /**
548
-     * This returns whether EEM_Message is in debug mode or not.
549
-     * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
550
-     * generating/sending messages. Debug mode can be set by either:
551
-     * 1. Sending in a value for the $set_debug argument
552
-     * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
553
-     * 3. Overriding the above via the provided filter.
554
-     *
555
-     * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
556
-     *                                  provided boolean. When no argument is provided (default null) then the debug
557
-     *                                  mode will be returned.
558
-     * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
559
-     */
560
-    public static function debug($set_debug = null)
561
-    {
562
-        static $is_debugging = null;
563
-
564
-        // initialize (use constant if set).
565
-        if (is_null($set_debug) && is_null($is_debugging)) {
566
-            $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
567
-        }
568
-
569
-        if (! is_null($set_debug)) {
570
-            $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
571
-        }
572
-
573
-        // return filtered value
574
-        return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
575
-    }
576
-
577
-
578
-    /**
579
-     * Deletes old messages meeting certain criteria for removal from the database.
580
-     * By default, this will delete messages that:
581
-     * - are older than the value of the delete_threshold in months.
582
-     * - have a STS_ID other than EEM_Message::status_idle
583
-     *
584
-     * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
585
-     *                              months.
586
-     * @return bool|false|int Either the number of records affected or false if there was an error (you can call
587
-     *                              $wpdb->last_error to find out what the error was.
588
-     * @throws EE_Error
589
-     * @throws EE_Error
590
-     * @throws EE_Error
591
-     */
592
-    public function delete_old_messages($delete_threshold = 6)
593
-    {
594
-        $number_deleted = 0;
595
-        /**
596
-         * Allows code to change the boundary for what messages are kept.
597
-         * Uses the value of the `delete_threshold` variable by default.
598
-         *
599
-         * @param int $seconds seconds that will be subtracted from the timestamp for now.
600
-         * @return int
601
-         */
602
-        $time_to_leave_alone = absint(
603
-            apply_filters(
604
-                'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
605
-                ((int) $delete_threshold) * MONTH_IN_SECONDS
606
-            )
607
-        );
608
-
609
-
610
-        /**
611
-         * Allows code to change what message stati are ignored when deleting.
612
-         * Defaults to only ignore EEM_Message::status_idle messages.
613
-         *
614
-         * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
615
-         */
616
-        $message_stati_to_keep = (array) apply_filters(
617
-            'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
618
-            array(
619
-                EEM_Message::status_idle
620
-            )
621
-        );
622
-
623
-        // first get all the ids of messages being deleted
624
-        $message_ids_to_delete = EEM_Message::instance()->get_col(
625
-            array(
626
-                0 => array(
627
-                    'STS_ID' => array('NOT_IN', $message_stati_to_keep),
628
-                    'MSG_modified' => array('<', time() - $time_to_leave_alone)
629
-                ),
630
-                'limit' => apply_filters(
631
-                    'EEM_Message__delete_old_messages__limit',
632
-                    2000,
633
-                    $delete_threshold
634
-                )
635
-            )
636
-        );
637
-
638
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
639
-            global $wpdb;
640
-            $number_deleted = $wpdb->query('
15
+	// private instance of the Message object
16
+	protected static $_instance = null;
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 $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 info to
108
+	 *                         the date time model field objects.  Default is null (and will be assumed using the set
109
+	 *                         timezone in the 'timezone_string' wp option)
110
+	 * @throws EE_Error
111
+	 * @throws EE_Error
112
+	 * @throws EE_Error
113
+	 */
114
+	protected function __construct($timezone = null)
115
+	{
116
+		$this->singular_item = esc_html__('Message', 'event_espresso');
117
+		$this->plural_item   = esc_html__('Messages', 'event_espresso');
118
+
119
+		$this->_tables = array(
120
+			'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
121
+		);
122
+
123
+		$allowed_priority = array(
124
+			self::priority_high   => esc_html__('high', 'event_espresso'),
125
+			self::priority_medium => esc_html__('medium', 'event_espresso'),
126
+			self::priority_low    => esc_html__('low', 'event_espresso'),
127
+		);
128
+
129
+		$this->_fields          = array(
130
+			'Message' => array(
131
+				'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
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__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
170
+					false,
171
+					'receipt'
172
+				),
173
+				'MSG_context'        => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false),
174
+				'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
175
+					'MSG_recipient_ID',
176
+					esc_html__('Recipient ID', 'event_espresso'),
177
+					true,
178
+					null,
179
+					array('Registration', 'Attendee', 'WP_User')
180
+				),
181
+				'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
182
+					'MSG_recipient_type',
183
+					esc_html__('Recipient Type', 'event_espresso'),
184
+					true,
185
+					null,
186
+					array('Registration', 'Attendee', 'WP_User')
187
+				),
188
+				'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
189
+					'MSG_content',
190
+					esc_html__('Content', 'event_espresso'),
191
+					true,
192
+					''
193
+				),
194
+				'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
195
+					'MSG_to',
196
+					esc_html__('Address To', 'event_espresso'),
197
+					true
198
+				),
199
+				'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
200
+					'MSG_from',
201
+					esc_html__('Address From', 'event_espresso'),
202
+					true
203
+				),
204
+				'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
205
+					'MSG_subject',
206
+					esc_html__('Subject', 'event_espresso'),
207
+					true,
208
+					''
209
+				),
210
+				'MSG_priority'       => new EE_Enum_Integer_Field(
211
+					'MSG_priority',
212
+					esc_html__('Priority', 'event_espresso'),
213
+					false,
214
+					self::priority_low,
215
+					$allowed_priority
216
+				),
217
+				'STS_ID'             => new EE_Foreign_Key_String_Field(
218
+					'STS_ID',
219
+					esc_html__('Status', 'event_espresso'),
220
+					false,
221
+					self::status_incomplete,
222
+					'Status'
223
+				),
224
+				'MSG_created'        => new EE_Datetime_Field(
225
+					'MSG_created',
226
+					esc_html__('Created', 'event_espresso'),
227
+					false,
228
+					EE_Datetime_Field::now
229
+				),
230
+				'MSG_modified'       => new EE_Datetime_Field(
231
+					'MSG_modified',
232
+					esc_html__('Modified', 'event_espresso'),
233
+					true,
234
+					EE_Datetime_Field::now
235
+				),
236
+			),
237
+		);
238
+		$this->_model_relations = array(
239
+			'Attendee'               => new EE_Belongs_To_Any_Relation(),
240
+			'Registration'           => new EE_Belongs_To_Any_Relation(),
241
+			'WP_User'                => new EE_Belongs_To_Any_Relation(),
242
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
243
+			'Transaction'            => new EE_Belongs_To_Relation(),
244
+		);
245
+		parent::__construct($timezone);
246
+	}
247
+
248
+
249
+	/**
250
+	 * @return EE_Message
251
+	 * @throws EE_Error
252
+	 */
253
+	public function create_default_object()
254
+	{
255
+		/** @type EE_Message $message */
256
+		$message = parent::create_default_object();
257
+		if ($message instanceof EE_Message) {
258
+			return EE_Message_Factory::set_messenger_and_message_type($message);
259
+		}
260
+		return null;
261
+	}
262
+
263
+
264
+	/**
265
+	 * @param mixed $cols_n_values
266
+	 * @return EE_Message
267
+	 * @throws EE_Error
268
+	 * @throws EE_Error
269
+	 */
270
+	public function instantiate_class_from_array_or_object($cols_n_values)
271
+	{
272
+		/** @type EE_Message $message */
273
+		$message = parent::instantiate_class_from_array_or_object($cols_n_values);
274
+		if ($message instanceof EE_Message) {
275
+			return EE_Message_Factory::set_messenger_and_message_type($message);
276
+		}
277
+		return null;
278
+	}
279
+
280
+
281
+	/**
282
+	 * Returns whether or not a message of that type was sent for a given attendee.
283
+	 *
284
+	 * @param EE_Attendee|int $attendee
285
+	 * @param string          $message_type the message type slug
286
+	 * @return boolean
287
+	 * @throws EE_Error
288
+	 * @throws EE_Error
289
+	 * @throws EE_Error
290
+	 */
291
+	public function message_sent_for_attendee($attendee, $message_type)
292
+	{
293
+		$attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
294
+		return $this->exists(array(
295
+			array(
296
+				'Attendee.ATT_ID'  => $attendee_ID,
297
+				'MSG_message_type' => $message_type,
298
+				'STS_ID'           => array('IN', $this->stati_indicating_sent()),
299
+			),
300
+		));
301
+	}
302
+
303
+
304
+	/**
305
+	 * Returns whether or not a message of that type was sent for a given registration
306
+	 *
307
+	 * @param EE_Registration|int $registration
308
+	 * @param string              $message_type the message type slug
309
+	 * @return boolean
310
+	 * @throws EE_Error
311
+	 * @throws EE_Error
312
+	 * @throws EE_Error
313
+	 */
314
+	public function message_sent_for_registration($registration, $message_type)
315
+	{
316
+		$registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
317
+		return $this->exists(array(
318
+			array(
319
+				'Registration.REG_ID' => $registrationID,
320
+				'MSG_message_type'    => $message_type,
321
+				'STS_ID'              => array('IN', $this->stati_indicating_sent()),
322
+			),
323
+		));
324
+	}
325
+
326
+
327
+	/**
328
+	 * This retrieves an EE_Message object from the db matching the given token string.
329
+	 *
330
+	 * @param string $token
331
+	 * @return EE_Message
332
+	 * @throws EE_Error
333
+	 */
334
+	public function get_one_by_token($token)
335
+	{
336
+		return $this->get_one(array(
337
+			array(
338
+				'MSG_token' => $token,
339
+			),
340
+		));
341
+	}
342
+
343
+
344
+	/**
345
+	 * Returns stati that indicate the message HAS been sent
346
+	 *
347
+	 * @return array of strings for possible stati
348
+	 */
349
+	public function stati_indicating_sent()
350
+	{
351
+		return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
352
+	}
353
+
354
+
355
+	/**
356
+	 * Returns stati that indicate the message is waiting to be sent.
357
+	 *
358
+	 * @return array of strings for possible stati.
359
+	 */
360
+	public function stati_indicating_to_send()
361
+	{
362
+		return apply_filters(
363
+			'FHEE__EEM_Message__stati_indicating_to_send',
364
+			array(self::status_idle, self::status_resend)
365
+		);
366
+	}
367
+
368
+
369
+	/**
370
+	 * Returns stati that indicate the message has failed sending
371
+	 *
372
+	 * @return array  array of strings for possible stati.
373
+	 */
374
+	public function stati_indicating_failed_sending()
375
+	{
376
+		$failed_stati = array(
377
+			self::status_failed,
378
+			self::status_retry,
379
+			self::status_messenger_executing,
380
+		);
381
+		// if WP_DEBUG is set, then let's include debug_only fails
382
+		if (WP_DEBUG) {
383
+			$failed_stati[] = self::status_debug_only;
384
+		}
385
+		return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Returns filterable array of all EEM_Message statuses.
391
+	 *
392
+	 * @return array
393
+	 */
394
+	public function all_statuses()
395
+	{
396
+		return apply_filters(
397
+			'FHEE__EEM_Message__all_statuses',
398
+			array(
399
+				EEM_Message::status_sent,
400
+				EEM_Message::status_incomplete,
401
+				EEM_Message::status_idle,
402
+				EEM_Message::status_resend,
403
+				EEM_Message::status_retry,
404
+				EEM_Message::status_failed,
405
+				EEM_Message::status_messenger_executing,
406
+				EEM_Message::status_debug_only,
407
+			)
408
+		);
409
+	}
410
+
411
+	/**
412
+	 * Detects any specific query variables in the request and uses those to setup appropriate
413
+	 * filter for any queries.
414
+	 *
415
+	 * @return array
416
+	 */
417
+	public function filter_by_query_params()
418
+	{
419
+		/** @var RequestInterface $request */
420
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
421
+		// expected possible query_vars, the key in this array matches an expected key in the request,
422
+		// the value, matches the corresponding EEM_Base child reference.
423
+		$expected_vars   = $this->_expected_vars_for_query_inject();
424
+		$query_params[0] = array();
425
+		foreach ($expected_vars as $request_key => $model_name) {
426
+			$request_value = $request->getRequestParam($request_key);
427
+			if ($request_value) {
428
+				// special case
429
+				switch ($request_key) {
430
+					case '_REG_ID':
431
+						$query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
432
+							'Transaction.Registration.REG_ID' => $request_value,
433
+						);
434
+						break;
435
+					case 'EVT_ID':
436
+						$query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
437
+							'Transaction.Registration.EVT_ID' => $request_value,
438
+						);
439
+						break;
440
+					default:
441
+						$query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
442
+						break;
443
+				}
444
+			}
445
+		}
446
+		return $query_params;
447
+	}
448
+
449
+
450
+	/**
451
+	 * @return string
452
+	 * @throws EE_Error
453
+	 * @throws ReflectionException
454
+	 */
455
+	public function get_pretty_label_for_results()
456
+	{
457
+		/** @var RequestInterface $request */
458
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
459
+		$expected_vars = $this->_expected_vars_for_query_inject();
460
+		$pretty_label  = '';
461
+		$label_parts   = array();
462
+		foreach ($expected_vars as $request_key => $model_name) {
463
+			$model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
464
+			$model = EEM_Base::$loader->getShared($model_name);
465
+			$model_field_value = $request->getRequestParam($request_key);
466
+			if ($model instanceof EEM_Base && $model_field_value !== '') {
467
+				switch ($request_key) {
468
+					case '_REG_ID':
469
+						$label_parts[] = sprintf(
470
+							esc_html__('Registration with the ID: %s', 'event_espresso'),
471
+							$model_field_value
472
+						);
473
+						break;
474
+					case 'ATT_ID':
475
+						/** @var EE_Attendee $attendee */
476
+						$attendee      = $model->get_one_by_ID($model_field_value);
477
+						$label_parts[] = $attendee instanceof EE_Attendee
478
+							? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
479
+							: sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
480
+						break;
481
+					case 'ID':
482
+						/** @var EE_WP_User $wpUser */
483
+						$wpUser        = $model->get_one_by_ID($model_field_value);
484
+						$label_parts[] = $wpUser instanceof EE_WP_User
485
+							? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
486
+							: sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
487
+						break;
488
+					case 'TXN_ID':
489
+						$label_parts[] = sprintf(
490
+							esc_html__('Transaction with the ID: %s', 'event_espresso'),
491
+							$model_field_value
492
+						);
493
+						break;
494
+					case 'EVT_ID':
495
+						/** @var EE_Event $Event */
496
+						$Event         = $model->get_one_by_ID($model_field_value);
497
+						$label_parts[] = $Event instanceof EE_Event
498
+							? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
499
+							: sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
500
+						break;
501
+				}
502
+			}
503
+		}
504
+
505
+		if ($label_parts) {
506
+			// prepend to the last element of $label_parts an "and".
507
+			if (count($label_parts) > 1) {
508
+				$label_parts_index_to_prepend               = count($label_parts) - 1;
509
+				$label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
510
+			}
511
+
512
+			$pretty_label .= sprintf(
513
+				esc_html_x(
514
+					'Showing messages for %s',
515
+					'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.',
516
+					'event_espresso'
517
+				),
518
+				implode(', ', $label_parts)
519
+			);
520
+		}
521
+		return $pretty_label;
522
+	}
523
+
524
+
525
+	/**
526
+	 * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
527
+	 * The array is in the format:
528
+	 * array(
529
+	 *  {$field_name} => {$model_name}
530
+	 * );
531
+	 *
532
+	 * @since 4.9.0
533
+	 * @return array
534
+	 */
535
+	protected function _expected_vars_for_query_inject()
536
+	{
537
+		return array(
538
+			'_REG_ID' => 'Registration',
539
+			'ATT_ID'  => 'Attendee',
540
+			'ID'      => 'WP_User',
541
+			'TXN_ID'  => 'Transaction',
542
+			'EVT_ID'  => 'Event',
543
+		);
544
+	}
545
+
546
+
547
+	/**
548
+	 * This returns whether EEM_Message is in debug mode or not.
549
+	 * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
550
+	 * generating/sending messages. Debug mode can be set by either:
551
+	 * 1. Sending in a value for the $set_debug argument
552
+	 * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
553
+	 * 3. Overriding the above via the provided filter.
554
+	 *
555
+	 * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
556
+	 *                                  provided boolean. When no argument is provided (default null) then the debug
557
+	 *                                  mode will be returned.
558
+	 * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
559
+	 */
560
+	public static function debug($set_debug = null)
561
+	{
562
+		static $is_debugging = null;
563
+
564
+		// initialize (use constant if set).
565
+		if (is_null($set_debug) && is_null($is_debugging)) {
566
+			$is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
567
+		}
568
+
569
+		if (! is_null($set_debug)) {
570
+			$is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
571
+		}
572
+
573
+		// return filtered value
574
+		return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
575
+	}
576
+
577
+
578
+	/**
579
+	 * Deletes old messages meeting certain criteria for removal from the database.
580
+	 * By default, this will delete messages that:
581
+	 * - are older than the value of the delete_threshold in months.
582
+	 * - have a STS_ID other than EEM_Message::status_idle
583
+	 *
584
+	 * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
585
+	 *                              months.
586
+	 * @return bool|false|int Either the number of records affected or false if there was an error (you can call
587
+	 *                              $wpdb->last_error to find out what the error was.
588
+	 * @throws EE_Error
589
+	 * @throws EE_Error
590
+	 * @throws EE_Error
591
+	 */
592
+	public function delete_old_messages($delete_threshold = 6)
593
+	{
594
+		$number_deleted = 0;
595
+		/**
596
+		 * Allows code to change the boundary for what messages are kept.
597
+		 * Uses the value of the `delete_threshold` variable by default.
598
+		 *
599
+		 * @param int $seconds seconds that will be subtracted from the timestamp for now.
600
+		 * @return int
601
+		 */
602
+		$time_to_leave_alone = absint(
603
+			apply_filters(
604
+				'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
605
+				((int) $delete_threshold) * MONTH_IN_SECONDS
606
+			)
607
+		);
608
+
609
+
610
+		/**
611
+		 * Allows code to change what message stati are ignored when deleting.
612
+		 * Defaults to only ignore EEM_Message::status_idle messages.
613
+		 *
614
+		 * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
615
+		 */
616
+		$message_stati_to_keep = (array) apply_filters(
617
+			'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
618
+			array(
619
+				EEM_Message::status_idle
620
+			)
621
+		);
622
+
623
+		// first get all the ids of messages being deleted
624
+		$message_ids_to_delete = EEM_Message::instance()->get_col(
625
+			array(
626
+				0 => array(
627
+					'STS_ID' => array('NOT_IN', $message_stati_to_keep),
628
+					'MSG_modified' => array('<', time() - $time_to_leave_alone)
629
+				),
630
+				'limit' => apply_filters(
631
+					'EEM_Message__delete_old_messages__limit',
632
+					2000,
633
+					$delete_threshold
634
+				)
635
+			)
636
+		);
637
+
638
+		if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
639
+			global $wpdb;
640
+			$number_deleted = $wpdb->query('
641 641
                 DELETE
642 642
                 FROM ' . $this->table() . '
643 643
                 WHERE
644 644
                     MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
645 645
             ');
646
-        }
647
-
648
-        /**
649
-         * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
650
-         * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
651
-         * below.
652
-         */
653
-        if ($number_deleted !== false) {
654
-            do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
655
-        } else {
656
-            do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
657
-        }
658
-        return $number_deleted;
659
-    }
646
+		}
647
+
648
+		/**
649
+		 * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
650
+		 * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
651
+		 * below.
652
+		 */
653
+		if ($number_deleted !== false) {
654
+			do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
655
+		} else {
656
+			do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
657
+		}
658
+		return $number_deleted;
659
+	}
660 660
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Type_Field.php.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@
 block discarded – undo
5 5
  */
6 6
 class EE_WP_Post_Type_Field extends EE_DB_Only_Text_Field
7 7
 {
8
-    /**
9
-     * @param string $post_type the exact string to be used for the post type
10
-     *                          of all these post type model objects/rows
11
-     */
12
-    public function __construct($post_type)
13
-    {
14
-        parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type);
15
-    }
8
+	/**
9
+	 * @param string $post_type the exact string to be used for the post type
10
+	 *                          of all these post type model objects/rows
11
+	 */
12
+	public function __construct($post_type)
13
+	{
14
+		parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type);
15
+	}
16 16
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             'WP_User'                => new EE_Belongs_To_Relation(),
279 279
         );
280 280
         // this model is generally available for reading
281
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
281
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
282 282
         $this->model_chain_to_password = '';
283 283
         parent::__construct($timezone);
284 284
     }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
      */
372 372
     public function get_all_event_question_groups($EVT_ID = 0)
373 373
     {
374
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
374
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
375 375
             EE_Error::add_error(
376 376
                 esc_html__(
377 377
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
      */
406 406
     public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
407 407
     {
408
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
408
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
409 409
             EE_Error::add_error(
410 410
                 esc_html__(
411 411
                     // @codingStandardsIgnoreStart
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
      */
449 449
     public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
450 450
     {
451
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
451
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
452 452
             EE_Error::add_error(
453 453
                 esc_html__(
454 454
                     'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
@@ -867,11 +867,11 @@  discard block
 block discarded – undo
867 867
         $questions = array();
868 868
         // get all question groups for event
869 869
         $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
870
-        if (! empty($qgs)) {
870
+        if ( ! empty($qgs)) {
871 871
             foreach ($qgs as $qg) {
872 872
                 $qsts = $qg->questions();
873
-                $questions[ $qg->ID() ] = $qg->model_field_array();
874
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
873
+                $questions[$qg->ID()] = $qg->model_field_array();
874
+                $questions[$qg->ID()]['QSG_questions'] = array();
875 875
                 foreach ($qsts as $qst) {
876 876
                     if ($qst->is_system_question()) {
877 877
                         continue;
@@ -885,26 +885,26 @@  discard block
 block discarded – undo
885 885
                     $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
886 886
                     $qst_name = $qstn_id = $qst->ID();
887 887
                     $ans_id = $answer->ID();
888
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
888
+                    $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']';
889 889
                     $input_name = '';
890 890
                     $input_id = sanitize_key($qst->display_text());
891 891
                     $input_class = '';
892
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
893
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
892
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
893
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
894 894
                                                                                            . $input_name
895 895
                                                                                            . $qst_name;
896
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
897
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
898
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
899
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
900
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
896
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id;
897
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
898
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
899
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
900
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
901 901
                     // leave responses as-is, don't convert stuff into html entities please!
902
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
902
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
903 903
                     if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
904 904
                         $QSOs = $qst->options(true, $answer->value());
905 905
                         if (is_array($QSOs)) {
906 906
                             foreach ($QSOs as $QSO_ID => $QSO) {
907
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
907
+                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
908 908
                             }
909 909
                         }
910 910
                     }
Please login to merge, or discard this patch.
Indentation   +915 added lines, -915 removed lines patch added patch discarded remove patch
@@ -14,919 +14,919 @@
 block discarded – undo
14 14
  */
15 15
 class EEM_Event extends EEM_CPT_Base
16 16
 {
17
-    /**
18
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
19
-     * event
20
-     */
21
-    const sold_out = 'sold_out';
22
-
23
-    /**
24
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
25
-     * date)
26
-     */
27
-    const postponed = 'postponed';
28
-
29
-    /**
30
-     * constant used by status(), indicating that the event will no longer occur
31
-     */
32
-    const cancelled = 'cancelled';
33
-
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    protected static $_default_reg_status;
39
-
40
-
41
-    /**
42
-     * This is the default for the additional limit field.
43
-     * @var int
44
-     */
45
-    protected static $_default_additional_limit = 10;
46
-
47
-
48
-    /**
49
-     * private instance of the Event object
50
-     *
51
-     * @var EEM_Event
52
-     */
53
-    protected static $_instance;
54
-
55
-
56
-
57
-
58
-    /**
59
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
60
-     *
61
-     * @param string $timezone
62
-     * @throws \EE_Error
63
-     */
64
-    protected function __construct($timezone = null)
65
-    {
66
-        EE_Registry::instance()->load_model('Registration');
67
-        $this->singular_item = esc_html__('Event', 'event_espresso');
68
-        $this->plural_item = esc_html__('Events', 'event_espresso');
69
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
70
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
71
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
72
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
73
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
74
-        //  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
75
-        $this->_custom_stati = apply_filters(
76
-            'AFEE__EEM_Event__construct___custom_stati',
77
-            array(
78
-                EEM_Event::cancelled => array(
79
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
80
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
81
-                ),
82
-                EEM_Event::postponed => array(
83
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
84
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
85
-                ),
86
-                EEM_Event::sold_out  => array(
87
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
88
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
89
-                ),
90
-            )
91
-        );
92
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
93
-            : self::$_default_reg_status;
94
-        $this->_tables = array(
95
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
96
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
97
-        );
98
-        $this->_fields = array(
99
-            'Event_CPT'  => array(
100
-                'EVT_ID'         => new EE_Primary_Key_Int_Field(
101
-                    'ID',
102
-                    esc_html__('Post ID for Event', 'event_espresso')
103
-                ),
104
-                'EVT_name'       => new EE_Plain_Text_Field(
105
-                    'post_title',
106
-                    esc_html__('Event Name', 'event_espresso'),
107
-                    false,
108
-                    ''
109
-                ),
110
-                'EVT_desc'       => new EE_Post_Content_Field(
111
-                    'post_content',
112
-                    esc_html__('Event Description', 'event_espresso'),
113
-                    false,
114
-                    ''
115
-                ),
116
-                'EVT_slug'       => new EE_Slug_Field(
117
-                    'post_name',
118
-                    esc_html__('Event Slug', 'event_espresso'),
119
-                    false,
120
-                    ''
121
-                ),
122
-                'EVT_created'    => new EE_Datetime_Field(
123
-                    'post_date',
124
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
125
-                    false,
126
-                    EE_Datetime_Field::now
127
-                ),
128
-                'EVT_short_desc' => new EE_Simple_HTML_Field(
129
-                    'post_excerpt',
130
-                    esc_html__('Event Short Description', 'event_espresso'),
131
-                    false,
132
-                    ''
133
-                ),
134
-                'EVT_modified'   => new EE_Datetime_Field(
135
-                    'post_modified',
136
-                    esc_html__('Date/Time Event Modified', 'event_espresso'),
137
-                    false,
138
-                    EE_Datetime_Field::now
139
-                ),
140
-                'EVT_wp_user'    => new EE_WP_User_Field(
141
-                    'post_author',
142
-                    esc_html__('Event Creator ID', 'event_espresso'),
143
-                    false
144
-                ),
145
-                'parent'         => new EE_Integer_Field(
146
-                    'post_parent',
147
-                    esc_html__('Event Parent ID', 'event_espresso'),
148
-                    false,
149
-                    0
150
-                ),
151
-                'EVT_order'      => new EE_Integer_Field(
152
-                    'menu_order',
153
-                    esc_html__('Event Menu Order', 'event_espresso'),
154
-                    false,
155
-                    1
156
-                ),
157
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
158
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
159
-                'status'         => new EE_WP_Post_Status_Field(
160
-                    'post_status',
161
-                    esc_html__('Event Status', 'event_espresso'),
162
-                    false,
163
-                    'draft',
164
-                    $this->_custom_stati
165
-                ),
166
-                'password' => new EE_Password_Field(
167
-                    'post_password',
168
-                    esc_html__('Password', 'event_espresso'),
169
-                    false,
170
-                    '',
171
-                    array(
172
-                        'EVT_desc',
173
-                        'EVT_short_desc',
174
-                        'EVT_display_desc',
175
-                        'EVT_display_ticket_selector',
176
-                        'EVT_visible_on',
177
-                        'EVT_additional_limit',
178
-                        'EVT_default_registration_status',
179
-                        'EVT_member_only',
180
-                        'EVT_phone',
181
-                        'EVT_allow_overflow',
182
-                        'EVT_timezone_string',
183
-                        'EVT_external_URL',
184
-                        'EVT_donations'
185
-                    )
186
-                )
187
-            ),
188
-            'Event_Meta' => array(
189
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field(
190
-                    'EVTM_ID',
191
-                    esc_html__('Event Meta Row ID', 'event_espresso'),
192
-                    false
193
-                ),
194
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
195
-                    'EVT_ID',
196
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
197
-                    false
198
-                ),
199
-                'EVT_display_desc'                => new EE_Boolean_Field(
200
-                    'EVT_display_desc',
201
-                    esc_html__('Display Description Flag', 'event_espresso'),
202
-                    false,
203
-                    true
204
-                ),
205
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field(
206
-                    'EVT_display_ticket_selector',
207
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'),
208
-                    false,
209
-                    true
210
-                ),
211
-                'EVT_visible_on'                  => new EE_Datetime_Field(
212
-                    'EVT_visible_on',
213
-                    esc_html__('Event Visible Date', 'event_espresso'),
214
-                    true,
215
-                    EE_Datetime_Field::now
216
-                ),
217
-                'EVT_additional_limit'            => new EE_Integer_Field(
218
-                    'EVT_additional_limit',
219
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
220
-                    true,
221
-                    self::$_default_additional_limit
222
-                ),
223
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
224
-                    'EVT_default_registration_status',
225
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'),
226
-                    false,
227
-                    EEM_Event::$_default_reg_status,
228
-                    EEM_Registration::reg_status_array()
229
-                ),
230
-                'EVT_member_only'                 => new EE_Boolean_Field(
231
-                    'EVT_member_only',
232
-                    esc_html__('Member-Only Event Flag', 'event_espresso'),
233
-                    false,
234
-                    false
235
-                ),
236
-                'EVT_phone'                       => new EE_Plain_Text_Field(
237
-                    'EVT_phone',
238
-                    esc_html__('Event Phone Number', 'event_espresso'),
239
-                    false,
240
-                    ''
241
-                ),
242
-                'EVT_allow_overflow'              => new EE_Boolean_Field(
243
-                    'EVT_allow_overflow',
244
-                    esc_html__('Allow Overflow on Event', 'event_espresso'),
245
-                    false,
246
-                    false
247
-                ),
248
-                'EVT_timezone_string'             => new EE_Plain_Text_Field(
249
-                    'EVT_timezone_string',
250
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'),
251
-                    false,
252
-                    ''
253
-                ),
254
-                'EVT_external_URL'                => new EE_Plain_Text_Field(
255
-                    'EVT_external_URL',
256
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
257
-                    true
258
-                ),
259
-                'EVT_donations'                   => new EE_Boolean_Field(
260
-                    'EVT_donations',
261
-                    esc_html__('Accept Donations?', 'event_espresso'),
262
-                    false,
263
-                    false
264
-                ),
265
-            ),
266
-        );
267
-        $this->_model_relations = array(
268
-            'Registration'           => new EE_Has_Many_Relation(),
269
-            'Datetime'               => new EE_Has_Many_Relation(),
270
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
271
-            'Event_Question_Group'   => new EE_Has_Many_Relation(),
272
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
273
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
274
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
275
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
276
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
277
-            'WP_User'                => new EE_Belongs_To_Relation(),
278
-        );
279
-        // this model is generally available for reading
280
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
281
-        $this->model_chain_to_password = '';
282
-        parent::__construct($timezone);
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * @param string $default_reg_status
289
-     */
290
-    public static function set_default_reg_status($default_reg_status)
291
-    {
292
-        self::$_default_reg_status = $default_reg_status;
293
-        // if EEM_Event has already been instantiated,
294
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
295
-        if (self::$_instance instanceof EEM_Event) {
296
-            $default_reg_status = new EE_Enum_Text_Field(
297
-                'EVT_default_registration_status',
298
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
299
-                false,
300
-                $default_reg_status,
301
-                EEM_Registration::reg_status_array()
302
-            );
303
-            $default_reg_status->_construct_finalize(
304
-                'Event_Meta',
305
-                'EVT_default_registration_status',
306
-                'EEM_Event'
307
-            );
308
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
309
-        }
310
-    }
311
-
312
-
313
-    /**
314
-     * Used to override the default for the additional limit field.
315
-     * @param $additional_limit
316
-     */
317
-    public static function set_default_additional_limit($additional_limit)
318
-    {
319
-        self::$_default_additional_limit = (int) $additional_limit;
320
-        if (self::$_instance instanceof EEM_Event) {
321
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
322
-                'EVT_additional_limit',
323
-                esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
324
-                true,
325
-                self::$_default_additional_limit
326
-            );
327
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
328
-                'Event_Meta',
329
-                'EVT_additional_limit',
330
-                'EEM_Event'
331
-            );
332
-        }
333
-    }
334
-
335
-
336
-    /**
337
-     * Return what is currently set as the default additional limit for the event.
338
-     * @return int
339
-     */
340
-    public static function get_default_additional_limit()
341
-    {
342
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
343
-    }
344
-
345
-
346
-    /**
347
-     * get_question_groups
348
-     *
349
-     * @return array
350
-     * @throws \EE_Error
351
-     */
352
-    public function get_all_question_groups()
353
-    {
354
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
355
-            array(
356
-                array('QSG_deleted' => false),
357
-                'order_by' => array('QSG_order' => 'ASC'),
358
-            )
359
-        );
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * get_question_groups
366
-     *
367
-     * @param int $EVT_ID
368
-     * @return array|bool
369
-     * @throws \EE_Error
370
-     */
371
-    public function get_all_event_question_groups($EVT_ID = 0)
372
-    {
373
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
374
-            EE_Error::add_error(
375
-                esc_html__(
376
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
377
-                    'event_espresso'
378
-                ),
379
-                __FILE__,
380
-                __FUNCTION__,
381
-                __LINE__
382
-            );
383
-            return false;
384
-        }
385
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
386
-            array(
387
-                array('EVT_ID' => $EVT_ID),
388
-            )
389
-        );
390
-    }
391
-
392
-
393
-    /**
394
-     * get_question_groups
395
-     *
396
-     * @param int $EVT_ID
397
-     * @param boolean $for_primary_attendee
398
-     * @return array|bool
399
-     * @throws EE_Error
400
-     * @throws InvalidArgumentException
401
-     * @throws ReflectionException
402
-     * @throws InvalidDataTypeException
403
-     * @throws InvalidInterfaceException
404
-     */
405
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
406
-    {
407
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
408
-            EE_Error::add_error(
409
-                esc_html__(
410
-                    // @codingStandardsIgnoreStart
411
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
412
-                    // @codingStandardsIgnoreEnd
413
-                    'event_espresso'
414
-                ),
415
-                __FILE__,
416
-                __FUNCTION__,
417
-                __LINE__
418
-            );
419
-            return false;
420
-        }
421
-        $query_params = [
422
-            [
423
-                'EVT_ID' => $EVT_ID,
424
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true
425
-            ]
426
-        ];
427
-        if ($for_primary_attendee) {
428
-            $query_params[0]['EQG_primary'] = true;
429
-        } else {
430
-            $query_params[0]['EQG_additional'] = true;
431
-        }
432
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
433
-    }
434
-
435
-
436
-    /**
437
-     * get_question_groups
438
-     *
439
-     * @param int $EVT_ID
440
-     * @param EE_Registration $registration
441
-     * @return array|bool
442
-     * @throws EE_Error
443
-     * @throws InvalidArgumentException
444
-     * @throws InvalidDataTypeException
445
-     * @throws InvalidInterfaceException
446
-     * @throws ReflectionException
447
-     */
448
-    public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
449
-    {
450
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
451
-            EE_Error::add_error(
452
-                esc_html__(
453
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
454
-                    'event_espresso'
455
-                ),
456
-                __FILE__,
457
-                __FUNCTION__,
458
-                __LINE__
459
-            );
460
-            return false;
461
-        }
462
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
463
-            [
464
-                [
465
-                    'Event_Question_Group.EVT_ID'      => $EVT_ID,
466
-                    'Event_Question_Group.'
467
-                        . EEM_Event_Question_Group::instance()->fieldNameForContext(
468
-                            $registration->is_primary_registrant()
469
-                        ) => true
470
-                ],
471
-                'order_by' => ['QSG_order' => 'ASC'],
472
-            ]
473
-        );
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * get_question_target_db_column
480
-     *
481
-     * @param string $QSG_IDs csv list of $QSG IDs
482
-     * @return array|bool
483
-     * @throws \EE_Error
484
-     */
485
-    public function get_questions_in_groups($QSG_IDs = '')
486
-    {
487
-        if (empty($QSG_IDs)) {
488
-            EE_Error::add_error(
489
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
490
-                __FILE__,
491
-                __FUNCTION__,
492
-                __LINE__
493
-            );
494
-            return false;
495
-        }
496
-        return EE_Registry::instance()->load_model('Question')->get_all(
497
-            array(
498
-                array(
499
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
500
-                    'QST_deleted'           => false,
501
-                    'QST_admin_only'        => is_admin(),
502
-                ),
503
-                'order_by' => 'QST_order',
504
-            )
505
-        );
506
-    }
507
-
508
-
509
-
510
-    /**
511
-     * get_options_for_question
512
-     *
513
-     * @param string $QST_IDs csv list of $QST IDs
514
-     * @return array|bool
515
-     * @throws \EE_Error
516
-     */
517
-    public function get_options_for_question($QST_IDs)
518
-    {
519
-        if (empty($QST_IDs)) {
520
-            EE_Error::add_error(
521
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
522
-                __FILE__,
523
-                __FUNCTION__,
524
-                __LINE__
525
-            );
526
-            return false;
527
-        }
528
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
529
-            array(
530
-                array(
531
-                    'Question.QST_ID' => array('IN', $QST_IDs),
532
-                    'QSO_deleted'     => false,
533
-                ),
534
-                'order_by' => 'QSO_ID',
535
-            )
536
-        );
537
-    }
538
-
539
-
540
-
541
-
542
-
543
-
544
-
545
-    /**
546
-     * Gets all events that are published
547
-     * and have event start time earlier than now and an event end time later than now
548
-     *
549
-     * @param  array $query_params An array of query params to further filter on
550
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
551
-     * @param bool   $count        whether to return the count or not (default FALSE)
552
-     * @return EE_Event[]|int
553
-     * @throws \EE_Error
554
-     */
555
-    public function get_active_events($query_params, $count = false)
556
-    {
557
-        if (array_key_exists(0, $query_params)) {
558
-            $where_params = $query_params[0];
559
-            unset($query_params[0]);
560
-        } else {
561
-            $where_params = array();
562
-        }
563
-        // if we have count make sure we don't include group by
564
-        if ($count && isset($query_params['group_by'])) {
565
-            unset($query_params['group_by']);
566
-        }
567
-        // let's add specific query_params for active_events
568
-        // keep in mind this will override any sent status in the query AND any date queries.
569
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
570
-        // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
571
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
572
-            $where_params['Datetime.DTT_EVT_start******'] = array(
573
-                '<',
574
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
575
-            );
576
-        } else {
577
-            $where_params['Datetime.DTT_EVT_start'] = array(
578
-                '<',
579
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
580
-            );
581
-        }
582
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
583
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
584
-                '>',
585
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
586
-            );
587
-        } else {
588
-            $where_params['Datetime.DTT_EVT_end'] = array(
589
-                '>',
590
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
591
-            );
592
-        }
593
-        $query_params[0] = $where_params;
594
-        // don't use $query_params with count()
595
-        // because we don't want to include additional query clauses like "GROUP BY"
596
-        return $count
597
-            ? $this->count(array($where_params), 'EVT_ID', true)
598
-            : $this->get_all($query_params);
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * get all events that are published and have an event start time later than now
605
-     *
606
-     * @param  array $query_params An array of query params to further filter on
607
-     *                             (Note that status and DTT_EVT_start will be overridden)
608
-     * @param bool   $count        whether to return the count or not (default FALSE)
609
-     * @return EE_Event[]|int
610
-     * @throws \EE_Error
611
-     */
612
-    public function get_upcoming_events($query_params, $count = false)
613
-    {
614
-        if (array_key_exists(0, $query_params)) {
615
-            $where_params = $query_params[0];
616
-            unset($query_params[0]);
617
-        } else {
618
-            $where_params = array();
619
-        }
620
-        // if we have count make sure we don't include group by
621
-        if ($count && isset($query_params['group_by'])) {
622
-            unset($query_params['group_by']);
623
-        }
624
-        // let's add specific query_params for active_events
625
-        // keep in mind this will override any sent status in the query AND any date queries.
626
-        // we need to pull events with a status of publish and sold_out
627
-        $event_status = array('publish', EEM_Event::sold_out);
628
-        // check if the user can read private events and if so add the 'private status to the were params'
629
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
630
-            $event_status[] = 'private';
631
-        }
632
-        $where_params['status'] = array('IN', $event_status);
633
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
634
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
635
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
636
-                '>',
637
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
638
-            );
639
-        } else {
640
-            $where_params['Datetime.DTT_EVT_start'] = array(
641
-                '>',
642
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
643
-            );
644
-        }
645
-        $query_params[0] = $where_params;
646
-        // don't use $query_params with count()
647
-        // because we don't want to include additional query clauses like "GROUP BY"
648
-        return $count
649
-            ? $this->count(array($where_params), 'EVT_ID', true)
650
-            : $this->get_all($query_params);
651
-    }
652
-
653
-
654
-
655
-    /**
656
-     * Gets all events that are published
657
-     * and have an event end time later than now
658
-     *
659
-     * @param  array $query_params An array of query params to further filter on
660
-     *                             (note that status and DTT_EVT_end will be overridden)
661
-     * @param bool   $count        whether to return the count or not (default FALSE)
662
-     * @return EE_Event[]|int
663
-     * @throws \EE_Error
664
-     */
665
-    public function get_active_and_upcoming_events($query_params, $count = false)
666
-    {
667
-        if (array_key_exists(0, $query_params)) {
668
-            $where_params = $query_params[0];
669
-            unset($query_params[0]);
670
-        } else {
671
-            $where_params = array();
672
-        }
673
-        // if we have count make sure we don't include group by
674
-        if ($count && isset($query_params['group_by'])) {
675
-            unset($query_params['group_by']);
676
-        }
677
-        // let's add specific query_params for active_events
678
-        // keep in mind this will override any sent status in the query AND any date queries.
679
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
680
-        // add where params for DTT_EVT_end
681
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
682
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
683
-                '>',
684
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
685
-            );
686
-        } else {
687
-            $where_params['Datetime.DTT_EVT_end'] = array(
688
-                '>',
689
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
690
-            );
691
-        }
692
-        $query_params[0] = $where_params;
693
-        // don't use $query_params with count()
694
-        // because we don't want to include additional query clauses like "GROUP BY"
695
-        return $count
696
-            ? $this->count(array($where_params), 'EVT_ID', true)
697
-            : $this->get_all($query_params);
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * This only returns events that are expired.
704
-     * They may still be published but all their datetimes have expired.
705
-     *
706
-     * @param  array $query_params An array of query params to further filter on
707
-     *                             (note that status and DTT_EVT_end will be overridden)
708
-     * @param bool   $count        whether to return the count or not (default FALSE)
709
-     * @return EE_Event[]|int
710
-     * @throws \EE_Error
711
-     */
712
-    public function get_expired_events($query_params, $count = false)
713
-    {
714
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
715
-        // if we have count make sure we don't include group by
716
-        if ($count && isset($query_params['group_by'])) {
717
-            unset($query_params['group_by']);
718
-        }
719
-        // let's add specific query_params for active_events
720
-        // keep in mind this will override any sent status in the query AND any date queries.
721
-        if (isset($where_params['status'])) {
722
-            unset($where_params['status']);
723
-        }
724
-        $exclude_query = $query_params;
725
-        if (isset($exclude_query[0])) {
726
-            unset($exclude_query[0]);
727
-        }
728
-        $exclude_query[0] = array(
729
-            'Datetime.DTT_EVT_end' => array(
730
-                '>',
731
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
732
-            ),
733
-        );
734
-        // first get all events that have datetimes where its not expired.
735
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
736
-        $event_ids = array_keys($event_ids);
737
-        // if we have any additional query_params, let's add them to the 'AND' condition
738
-        $and_condition = array(
739
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
740
-            'EVT_ID'               => array('NOT IN', $event_ids),
741
-        );
742
-        if (isset($where_params['OR'])) {
743
-            $and_condition['OR'] = $where_params['OR'];
744
-            unset($where_params['OR']);
745
-        }
746
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
747
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
748
-            unset($where_params['Datetime.DTT_EVT_end']);
749
-        }
750
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
751
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
752
-            unset($where_params['Datetime.DTT_EVT_start']);
753
-        }
754
-        // merge remaining $where params with the and conditions.
755
-        $where_params['AND'] = array_merge($and_condition, $where_params);
756
-        $query_params[0] = $where_params;
757
-        // don't use $query_params with count()
758
-        // because we don't want to include additional query clauses like "GROUP BY"
759
-        return $count
760
-            ? $this->count(array($where_params), 'EVT_ID', true)
761
-            : $this->get_all($query_params);
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * This basically just returns the events that do not have the publish status.
768
-     *
769
-     * @param  array   $query_params An array of query params to further filter on
770
-     *                               (note that status will be overwritten)
771
-     * @param  boolean $count        whether to return the count or not (default FALSE)
772
-     * @return EE_Event[]|int
773
-     * @throws \EE_Error
774
-     */
775
-    public function get_inactive_events($query_params, $count = false)
776
-    {
777
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
778
-        // let's add in specific query_params for inactive events.
779
-        if (isset($where_params['status'])) {
780
-            unset($where_params['status']);
781
-        }
782
-        // if we have count make sure we don't include group by
783
-        if ($count && isset($query_params['group_by'])) {
784
-            unset($query_params['group_by']);
785
-        }
786
-        // if we have any additional query_params, let's add them to the 'AND' condition
787
-        $where_params['AND']['status'] = array('!=', 'publish');
788
-        if (isset($where_params['OR'])) {
789
-            $where_params['AND']['OR'] = $where_params['OR'];
790
-            unset($where_params['OR']);
791
-        }
792
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
793
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
794
-            unset($where_params['Datetime.DTT_EVT_end']);
795
-        }
796
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
797
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
798
-            unset($where_params['Datetime.DTT_EVT_start']);
799
-        }
800
-        $query_params[0] = $where_params;
801
-        // don't use $query_params with count()
802
-        // because we don't want to include additional query clauses like "GROUP BY"
803
-        return $count
804
-            ? $this->count(array($where_params), 'EVT_ID', true)
805
-            : $this->get_all($query_params);
806
-    }
807
-
808
-
809
-
810
-    /**
811
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
812
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
813
-     * attached to the event. See parent for param descriptions
814
-     *
815
-     * @param        $id_or_obj
816
-     * @param        $other_model_id_or_obj
817
-     * @param string $relationName
818
-     * @param array  $where_query
819
-     * @return EE_Base_Class
820
-     * @throws EE_Error
821
-     */
822
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
823
-    {
824
-        if ($relationName === 'Price') {
825
-            // let's get the PRC object for the given ID to make sure that we aren't dealing with a default
826
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
827
-            // if EVT_ID = 0, then this is a default
828
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
829
-                // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
830
-                $prc_chk->set('PRC_ID', 0);
831
-            }
832
-            // run parent
833
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
834
-        }
835
-        // otherwise carry on as normal
836
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
837
-    }
838
-
839
-
840
-
841
-    /******************** DEPRECATED METHODS ********************/
842
-
843
-
844
-
845
-    /**
846
-     * _get_question_target_db_column
847
-     *
848
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
849
-     *             EE_Registration_Custom_Questions_Form located in
850
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
851
-     * @access     public
852
-     * @param    EE_Registration $registration (so existing answers for registration are included)
853
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
854
-     *                                         registration).
855
-     * @throws EE_Error
856
-     * @return    array
857
-     */
858
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
859
-    {
860
-        if (empty($EVT_ID)) {
861
-            throw new EE_Error(esc_html__(
862
-                'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
863
-                'event_espresso'
864
-            ));
865
-        }
866
-        $questions = array();
867
-        // get all question groups for event
868
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
869
-        if (! empty($qgs)) {
870
-            foreach ($qgs as $qg) {
871
-                $qsts = $qg->questions();
872
-                $questions[ $qg->ID() ] = $qg->model_field_array();
873
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
874
-                foreach ($qsts as $qst) {
875
-                    if ($qst->is_system_question()) {
876
-                        continue;
877
-                    }
878
-                    $answer = EEM_Answer::instance()->get_one(array(
879
-                        array(
880
-                            'QST_ID' => $qst->ID(),
881
-                            'REG_ID' => $registration->ID(),
882
-                        ),
883
-                    ));
884
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
885
-                    $qst_name = $qstn_id = $qst->ID();
886
-                    $ans_id = $answer->ID();
887
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
888
-                    $input_name = '';
889
-                    $input_id = sanitize_key($qst->display_text());
890
-                    $input_class = '';
891
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
892
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
893
-                                                                                           . $input_name
894
-                                                                                           . $qst_name;
895
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
896
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
897
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
898
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
899
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
900
-                    // leave responses as-is, don't convert stuff into html entities please!
901
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
902
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
903
-                        $QSOs = $qst->options(true, $answer->value());
904
-                        if (is_array($QSOs)) {
905
-                            foreach ($QSOs as $QSO_ID => $QSO) {
906
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
907
-                            }
908
-                        }
909
-                    }
910
-                }
911
-            }
912
-        }
913
-        return $questions;
914
-    }
915
-
916
-
917
-    /**
918
-     * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
919
-     *                             or an stdClass where each property is the name of a column,
920
-     * @return EE_Base_Class
921
-     * @throws \EE_Error
922
-     */
923
-    public function instantiate_class_from_array_or_object($cols_n_values)
924
-    {
925
-        $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
926
-        if ($classInstance instanceof EE_Event) {
927
-            // events have their timezone defined in the DB, so use it immediately
928
-            $this->set_timezone($classInstance->get_timezone());
929
-        }
930
-        return $classInstance;
931
-    }
17
+	/**
18
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
19
+	 * event
20
+	 */
21
+	const sold_out = 'sold_out';
22
+
23
+	/**
24
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
25
+	 * date)
26
+	 */
27
+	const postponed = 'postponed';
28
+
29
+	/**
30
+	 * constant used by status(), indicating that the event will no longer occur
31
+	 */
32
+	const cancelled = 'cancelled';
33
+
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	protected static $_default_reg_status;
39
+
40
+
41
+	/**
42
+	 * This is the default for the additional limit field.
43
+	 * @var int
44
+	 */
45
+	protected static $_default_additional_limit = 10;
46
+
47
+
48
+	/**
49
+	 * private instance of the Event object
50
+	 *
51
+	 * @var EEM_Event
52
+	 */
53
+	protected static $_instance;
54
+
55
+
56
+
57
+
58
+	/**
59
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
60
+	 *
61
+	 * @param string $timezone
62
+	 * @throws \EE_Error
63
+	 */
64
+	protected function __construct($timezone = null)
65
+	{
66
+		EE_Registry::instance()->load_model('Registration');
67
+		$this->singular_item = esc_html__('Event', 'event_espresso');
68
+		$this->plural_item = esc_html__('Events', 'event_espresso');
69
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
70
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
71
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
72
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
73
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
74
+		//  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
75
+		$this->_custom_stati = apply_filters(
76
+			'AFEE__EEM_Event__construct___custom_stati',
77
+			array(
78
+				EEM_Event::cancelled => array(
79
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
80
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
81
+				),
82
+				EEM_Event::postponed => array(
83
+					'label'  => esc_html__('Postponed', 'event_espresso'),
84
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
85
+				),
86
+				EEM_Event::sold_out  => array(
87
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
88
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
89
+				),
90
+			)
91
+		);
92
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
93
+			: self::$_default_reg_status;
94
+		$this->_tables = array(
95
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
96
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
97
+		);
98
+		$this->_fields = array(
99
+			'Event_CPT'  => array(
100
+				'EVT_ID'         => new EE_Primary_Key_Int_Field(
101
+					'ID',
102
+					esc_html__('Post ID for Event', 'event_espresso')
103
+				),
104
+				'EVT_name'       => new EE_Plain_Text_Field(
105
+					'post_title',
106
+					esc_html__('Event Name', 'event_espresso'),
107
+					false,
108
+					''
109
+				),
110
+				'EVT_desc'       => new EE_Post_Content_Field(
111
+					'post_content',
112
+					esc_html__('Event Description', 'event_espresso'),
113
+					false,
114
+					''
115
+				),
116
+				'EVT_slug'       => new EE_Slug_Field(
117
+					'post_name',
118
+					esc_html__('Event Slug', 'event_espresso'),
119
+					false,
120
+					''
121
+				),
122
+				'EVT_created'    => new EE_Datetime_Field(
123
+					'post_date',
124
+					esc_html__('Date/Time Event Created', 'event_espresso'),
125
+					false,
126
+					EE_Datetime_Field::now
127
+				),
128
+				'EVT_short_desc' => new EE_Simple_HTML_Field(
129
+					'post_excerpt',
130
+					esc_html__('Event Short Description', 'event_espresso'),
131
+					false,
132
+					''
133
+				),
134
+				'EVT_modified'   => new EE_Datetime_Field(
135
+					'post_modified',
136
+					esc_html__('Date/Time Event Modified', 'event_espresso'),
137
+					false,
138
+					EE_Datetime_Field::now
139
+				),
140
+				'EVT_wp_user'    => new EE_WP_User_Field(
141
+					'post_author',
142
+					esc_html__('Event Creator ID', 'event_espresso'),
143
+					false
144
+				),
145
+				'parent'         => new EE_Integer_Field(
146
+					'post_parent',
147
+					esc_html__('Event Parent ID', 'event_espresso'),
148
+					false,
149
+					0
150
+				),
151
+				'EVT_order'      => new EE_Integer_Field(
152
+					'menu_order',
153
+					esc_html__('Event Menu Order', 'event_espresso'),
154
+					false,
155
+					1
156
+				),
157
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
158
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
159
+				'status'         => new EE_WP_Post_Status_Field(
160
+					'post_status',
161
+					esc_html__('Event Status', 'event_espresso'),
162
+					false,
163
+					'draft',
164
+					$this->_custom_stati
165
+				),
166
+				'password' => new EE_Password_Field(
167
+					'post_password',
168
+					esc_html__('Password', 'event_espresso'),
169
+					false,
170
+					'',
171
+					array(
172
+						'EVT_desc',
173
+						'EVT_short_desc',
174
+						'EVT_display_desc',
175
+						'EVT_display_ticket_selector',
176
+						'EVT_visible_on',
177
+						'EVT_additional_limit',
178
+						'EVT_default_registration_status',
179
+						'EVT_member_only',
180
+						'EVT_phone',
181
+						'EVT_allow_overflow',
182
+						'EVT_timezone_string',
183
+						'EVT_external_URL',
184
+						'EVT_donations'
185
+					)
186
+				)
187
+			),
188
+			'Event_Meta' => array(
189
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field(
190
+					'EVTM_ID',
191
+					esc_html__('Event Meta Row ID', 'event_espresso'),
192
+					false
193
+				),
194
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
195
+					'EVT_ID',
196
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
197
+					false
198
+				),
199
+				'EVT_display_desc'                => new EE_Boolean_Field(
200
+					'EVT_display_desc',
201
+					esc_html__('Display Description Flag', 'event_espresso'),
202
+					false,
203
+					true
204
+				),
205
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field(
206
+					'EVT_display_ticket_selector',
207
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'),
208
+					false,
209
+					true
210
+				),
211
+				'EVT_visible_on'                  => new EE_Datetime_Field(
212
+					'EVT_visible_on',
213
+					esc_html__('Event Visible Date', 'event_espresso'),
214
+					true,
215
+					EE_Datetime_Field::now
216
+				),
217
+				'EVT_additional_limit'            => new EE_Integer_Field(
218
+					'EVT_additional_limit',
219
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
220
+					true,
221
+					self::$_default_additional_limit
222
+				),
223
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
224
+					'EVT_default_registration_status',
225
+					esc_html__('Default Registration Status on this Event', 'event_espresso'),
226
+					false,
227
+					EEM_Event::$_default_reg_status,
228
+					EEM_Registration::reg_status_array()
229
+				),
230
+				'EVT_member_only'                 => new EE_Boolean_Field(
231
+					'EVT_member_only',
232
+					esc_html__('Member-Only Event Flag', 'event_espresso'),
233
+					false,
234
+					false
235
+				),
236
+				'EVT_phone'                       => new EE_Plain_Text_Field(
237
+					'EVT_phone',
238
+					esc_html__('Event Phone Number', 'event_espresso'),
239
+					false,
240
+					''
241
+				),
242
+				'EVT_allow_overflow'              => new EE_Boolean_Field(
243
+					'EVT_allow_overflow',
244
+					esc_html__('Allow Overflow on Event', 'event_espresso'),
245
+					false,
246
+					false
247
+				),
248
+				'EVT_timezone_string'             => new EE_Plain_Text_Field(
249
+					'EVT_timezone_string',
250
+					esc_html__('Timezone (name) for Event times', 'event_espresso'),
251
+					false,
252
+					''
253
+				),
254
+				'EVT_external_URL'                => new EE_Plain_Text_Field(
255
+					'EVT_external_URL',
256
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
257
+					true
258
+				),
259
+				'EVT_donations'                   => new EE_Boolean_Field(
260
+					'EVT_donations',
261
+					esc_html__('Accept Donations?', 'event_espresso'),
262
+					false,
263
+					false
264
+				),
265
+			),
266
+		);
267
+		$this->_model_relations = array(
268
+			'Registration'           => new EE_Has_Many_Relation(),
269
+			'Datetime'               => new EE_Has_Many_Relation(),
270
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
271
+			'Event_Question_Group'   => new EE_Has_Many_Relation(),
272
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
273
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
274
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
275
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
276
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
277
+			'WP_User'                => new EE_Belongs_To_Relation(),
278
+		);
279
+		// this model is generally available for reading
280
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
281
+		$this->model_chain_to_password = '';
282
+		parent::__construct($timezone);
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * @param string $default_reg_status
289
+	 */
290
+	public static function set_default_reg_status($default_reg_status)
291
+	{
292
+		self::$_default_reg_status = $default_reg_status;
293
+		// if EEM_Event has already been instantiated,
294
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
295
+		if (self::$_instance instanceof EEM_Event) {
296
+			$default_reg_status = new EE_Enum_Text_Field(
297
+				'EVT_default_registration_status',
298
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
299
+				false,
300
+				$default_reg_status,
301
+				EEM_Registration::reg_status_array()
302
+			);
303
+			$default_reg_status->_construct_finalize(
304
+				'Event_Meta',
305
+				'EVT_default_registration_status',
306
+				'EEM_Event'
307
+			);
308
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
309
+		}
310
+	}
311
+
312
+
313
+	/**
314
+	 * Used to override the default for the additional limit field.
315
+	 * @param $additional_limit
316
+	 */
317
+	public static function set_default_additional_limit($additional_limit)
318
+	{
319
+		self::$_default_additional_limit = (int) $additional_limit;
320
+		if (self::$_instance instanceof EEM_Event) {
321
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
322
+				'EVT_additional_limit',
323
+				esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
324
+				true,
325
+				self::$_default_additional_limit
326
+			);
327
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
328
+				'Event_Meta',
329
+				'EVT_additional_limit',
330
+				'EEM_Event'
331
+			);
332
+		}
333
+	}
334
+
335
+
336
+	/**
337
+	 * Return what is currently set as the default additional limit for the event.
338
+	 * @return int
339
+	 */
340
+	public static function get_default_additional_limit()
341
+	{
342
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
343
+	}
344
+
345
+
346
+	/**
347
+	 * get_question_groups
348
+	 *
349
+	 * @return array
350
+	 * @throws \EE_Error
351
+	 */
352
+	public function get_all_question_groups()
353
+	{
354
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
355
+			array(
356
+				array('QSG_deleted' => false),
357
+				'order_by' => array('QSG_order' => 'ASC'),
358
+			)
359
+		);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * get_question_groups
366
+	 *
367
+	 * @param int $EVT_ID
368
+	 * @return array|bool
369
+	 * @throws \EE_Error
370
+	 */
371
+	public function get_all_event_question_groups($EVT_ID = 0)
372
+	{
373
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
374
+			EE_Error::add_error(
375
+				esc_html__(
376
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
377
+					'event_espresso'
378
+				),
379
+				__FILE__,
380
+				__FUNCTION__,
381
+				__LINE__
382
+			);
383
+			return false;
384
+		}
385
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
386
+			array(
387
+				array('EVT_ID' => $EVT_ID),
388
+			)
389
+		);
390
+	}
391
+
392
+
393
+	/**
394
+	 * get_question_groups
395
+	 *
396
+	 * @param int $EVT_ID
397
+	 * @param boolean $for_primary_attendee
398
+	 * @return array|bool
399
+	 * @throws EE_Error
400
+	 * @throws InvalidArgumentException
401
+	 * @throws ReflectionException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws InvalidInterfaceException
404
+	 */
405
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
406
+	{
407
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
408
+			EE_Error::add_error(
409
+				esc_html__(
410
+					// @codingStandardsIgnoreStart
411
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
412
+					// @codingStandardsIgnoreEnd
413
+					'event_espresso'
414
+				),
415
+				__FILE__,
416
+				__FUNCTION__,
417
+				__LINE__
418
+			);
419
+			return false;
420
+		}
421
+		$query_params = [
422
+			[
423
+				'EVT_ID' => $EVT_ID,
424
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true
425
+			]
426
+		];
427
+		if ($for_primary_attendee) {
428
+			$query_params[0]['EQG_primary'] = true;
429
+		} else {
430
+			$query_params[0]['EQG_additional'] = true;
431
+		}
432
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
433
+	}
434
+
435
+
436
+	/**
437
+	 * get_question_groups
438
+	 *
439
+	 * @param int $EVT_ID
440
+	 * @param EE_Registration $registration
441
+	 * @return array|bool
442
+	 * @throws EE_Error
443
+	 * @throws InvalidArgumentException
444
+	 * @throws InvalidDataTypeException
445
+	 * @throws InvalidInterfaceException
446
+	 * @throws ReflectionException
447
+	 */
448
+	public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
449
+	{
450
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
451
+			EE_Error::add_error(
452
+				esc_html__(
453
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
454
+					'event_espresso'
455
+				),
456
+				__FILE__,
457
+				__FUNCTION__,
458
+				__LINE__
459
+			);
460
+			return false;
461
+		}
462
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
463
+			[
464
+				[
465
+					'Event_Question_Group.EVT_ID'      => $EVT_ID,
466
+					'Event_Question_Group.'
467
+						. EEM_Event_Question_Group::instance()->fieldNameForContext(
468
+							$registration->is_primary_registrant()
469
+						) => true
470
+				],
471
+				'order_by' => ['QSG_order' => 'ASC'],
472
+			]
473
+		);
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * get_question_target_db_column
480
+	 *
481
+	 * @param string $QSG_IDs csv list of $QSG IDs
482
+	 * @return array|bool
483
+	 * @throws \EE_Error
484
+	 */
485
+	public function get_questions_in_groups($QSG_IDs = '')
486
+	{
487
+		if (empty($QSG_IDs)) {
488
+			EE_Error::add_error(
489
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
490
+				__FILE__,
491
+				__FUNCTION__,
492
+				__LINE__
493
+			);
494
+			return false;
495
+		}
496
+		return EE_Registry::instance()->load_model('Question')->get_all(
497
+			array(
498
+				array(
499
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
500
+					'QST_deleted'           => false,
501
+					'QST_admin_only'        => is_admin(),
502
+				),
503
+				'order_by' => 'QST_order',
504
+			)
505
+		);
506
+	}
507
+
508
+
509
+
510
+	/**
511
+	 * get_options_for_question
512
+	 *
513
+	 * @param string $QST_IDs csv list of $QST IDs
514
+	 * @return array|bool
515
+	 * @throws \EE_Error
516
+	 */
517
+	public function get_options_for_question($QST_IDs)
518
+	{
519
+		if (empty($QST_IDs)) {
520
+			EE_Error::add_error(
521
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
522
+				__FILE__,
523
+				__FUNCTION__,
524
+				__LINE__
525
+			);
526
+			return false;
527
+		}
528
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
529
+			array(
530
+				array(
531
+					'Question.QST_ID' => array('IN', $QST_IDs),
532
+					'QSO_deleted'     => false,
533
+				),
534
+				'order_by' => 'QSO_ID',
535
+			)
536
+		);
537
+	}
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+	/**
546
+	 * Gets all events that are published
547
+	 * and have event start time earlier than now and an event end time later than now
548
+	 *
549
+	 * @param  array $query_params An array of query params to further filter on
550
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
551
+	 * @param bool   $count        whether to return the count or not (default FALSE)
552
+	 * @return EE_Event[]|int
553
+	 * @throws \EE_Error
554
+	 */
555
+	public function get_active_events($query_params, $count = false)
556
+	{
557
+		if (array_key_exists(0, $query_params)) {
558
+			$where_params = $query_params[0];
559
+			unset($query_params[0]);
560
+		} else {
561
+			$where_params = array();
562
+		}
563
+		// if we have count make sure we don't include group by
564
+		if ($count && isset($query_params['group_by'])) {
565
+			unset($query_params['group_by']);
566
+		}
567
+		// let's add specific query_params for active_events
568
+		// keep in mind this will override any sent status in the query AND any date queries.
569
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
570
+		// if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
571
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
572
+			$where_params['Datetime.DTT_EVT_start******'] = array(
573
+				'<',
574
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
575
+			);
576
+		} else {
577
+			$where_params['Datetime.DTT_EVT_start'] = array(
578
+				'<',
579
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
580
+			);
581
+		}
582
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
583
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
584
+				'>',
585
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
586
+			);
587
+		} else {
588
+			$where_params['Datetime.DTT_EVT_end'] = array(
589
+				'>',
590
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
591
+			);
592
+		}
593
+		$query_params[0] = $where_params;
594
+		// don't use $query_params with count()
595
+		// because we don't want to include additional query clauses like "GROUP BY"
596
+		return $count
597
+			? $this->count(array($where_params), 'EVT_ID', true)
598
+			: $this->get_all($query_params);
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * get all events that are published and have an event start time later than now
605
+	 *
606
+	 * @param  array $query_params An array of query params to further filter on
607
+	 *                             (Note that status and DTT_EVT_start will be overridden)
608
+	 * @param bool   $count        whether to return the count or not (default FALSE)
609
+	 * @return EE_Event[]|int
610
+	 * @throws \EE_Error
611
+	 */
612
+	public function get_upcoming_events($query_params, $count = false)
613
+	{
614
+		if (array_key_exists(0, $query_params)) {
615
+			$where_params = $query_params[0];
616
+			unset($query_params[0]);
617
+		} else {
618
+			$where_params = array();
619
+		}
620
+		// if we have count make sure we don't include group by
621
+		if ($count && isset($query_params['group_by'])) {
622
+			unset($query_params['group_by']);
623
+		}
624
+		// let's add specific query_params for active_events
625
+		// keep in mind this will override any sent status in the query AND any date queries.
626
+		// we need to pull events with a status of publish and sold_out
627
+		$event_status = array('publish', EEM_Event::sold_out);
628
+		// check if the user can read private events and if so add the 'private status to the were params'
629
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
630
+			$event_status[] = 'private';
631
+		}
632
+		$where_params['status'] = array('IN', $event_status);
633
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
634
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
635
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
636
+				'>',
637
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
638
+			);
639
+		} else {
640
+			$where_params['Datetime.DTT_EVT_start'] = array(
641
+				'>',
642
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
643
+			);
644
+		}
645
+		$query_params[0] = $where_params;
646
+		// don't use $query_params with count()
647
+		// because we don't want to include additional query clauses like "GROUP BY"
648
+		return $count
649
+			? $this->count(array($where_params), 'EVT_ID', true)
650
+			: $this->get_all($query_params);
651
+	}
652
+
653
+
654
+
655
+	/**
656
+	 * Gets all events that are published
657
+	 * and have an event end time later than now
658
+	 *
659
+	 * @param  array $query_params An array of query params to further filter on
660
+	 *                             (note that status and DTT_EVT_end will be overridden)
661
+	 * @param bool   $count        whether to return the count or not (default FALSE)
662
+	 * @return EE_Event[]|int
663
+	 * @throws \EE_Error
664
+	 */
665
+	public function get_active_and_upcoming_events($query_params, $count = false)
666
+	{
667
+		if (array_key_exists(0, $query_params)) {
668
+			$where_params = $query_params[0];
669
+			unset($query_params[0]);
670
+		} else {
671
+			$where_params = array();
672
+		}
673
+		// if we have count make sure we don't include group by
674
+		if ($count && isset($query_params['group_by'])) {
675
+			unset($query_params['group_by']);
676
+		}
677
+		// let's add specific query_params for active_events
678
+		// keep in mind this will override any sent status in the query AND any date queries.
679
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
680
+		// add where params for DTT_EVT_end
681
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
682
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
683
+				'>',
684
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
685
+			);
686
+		} else {
687
+			$where_params['Datetime.DTT_EVT_end'] = array(
688
+				'>',
689
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
690
+			);
691
+		}
692
+		$query_params[0] = $where_params;
693
+		// don't use $query_params with count()
694
+		// because we don't want to include additional query clauses like "GROUP BY"
695
+		return $count
696
+			? $this->count(array($where_params), 'EVT_ID', true)
697
+			: $this->get_all($query_params);
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * This only returns events that are expired.
704
+	 * They may still be published but all their datetimes have expired.
705
+	 *
706
+	 * @param  array $query_params An array of query params to further filter on
707
+	 *                             (note that status and DTT_EVT_end will be overridden)
708
+	 * @param bool   $count        whether to return the count or not (default FALSE)
709
+	 * @return EE_Event[]|int
710
+	 * @throws \EE_Error
711
+	 */
712
+	public function get_expired_events($query_params, $count = false)
713
+	{
714
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
715
+		// if we have count make sure we don't include group by
716
+		if ($count && isset($query_params['group_by'])) {
717
+			unset($query_params['group_by']);
718
+		}
719
+		// let's add specific query_params for active_events
720
+		// keep in mind this will override any sent status in the query AND any date queries.
721
+		if (isset($where_params['status'])) {
722
+			unset($where_params['status']);
723
+		}
724
+		$exclude_query = $query_params;
725
+		if (isset($exclude_query[0])) {
726
+			unset($exclude_query[0]);
727
+		}
728
+		$exclude_query[0] = array(
729
+			'Datetime.DTT_EVT_end' => array(
730
+				'>',
731
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
732
+			),
733
+		);
734
+		// first get all events that have datetimes where its not expired.
735
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
736
+		$event_ids = array_keys($event_ids);
737
+		// if we have any additional query_params, let's add them to the 'AND' condition
738
+		$and_condition = array(
739
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
740
+			'EVT_ID'               => array('NOT IN', $event_ids),
741
+		);
742
+		if (isset($where_params['OR'])) {
743
+			$and_condition['OR'] = $where_params['OR'];
744
+			unset($where_params['OR']);
745
+		}
746
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
747
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
748
+			unset($where_params['Datetime.DTT_EVT_end']);
749
+		}
750
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
751
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
752
+			unset($where_params['Datetime.DTT_EVT_start']);
753
+		}
754
+		// merge remaining $where params with the and conditions.
755
+		$where_params['AND'] = array_merge($and_condition, $where_params);
756
+		$query_params[0] = $where_params;
757
+		// don't use $query_params with count()
758
+		// because we don't want to include additional query clauses like "GROUP BY"
759
+		return $count
760
+			? $this->count(array($where_params), 'EVT_ID', true)
761
+			: $this->get_all($query_params);
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * This basically just returns the events that do not have the publish status.
768
+	 *
769
+	 * @param  array   $query_params An array of query params to further filter on
770
+	 *                               (note that status will be overwritten)
771
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
772
+	 * @return EE_Event[]|int
773
+	 * @throws \EE_Error
774
+	 */
775
+	public function get_inactive_events($query_params, $count = false)
776
+	{
777
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
778
+		// let's add in specific query_params for inactive events.
779
+		if (isset($where_params['status'])) {
780
+			unset($where_params['status']);
781
+		}
782
+		// if we have count make sure we don't include group by
783
+		if ($count && isset($query_params['group_by'])) {
784
+			unset($query_params['group_by']);
785
+		}
786
+		// if we have any additional query_params, let's add them to the 'AND' condition
787
+		$where_params['AND']['status'] = array('!=', 'publish');
788
+		if (isset($where_params['OR'])) {
789
+			$where_params['AND']['OR'] = $where_params['OR'];
790
+			unset($where_params['OR']);
791
+		}
792
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
793
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
794
+			unset($where_params['Datetime.DTT_EVT_end']);
795
+		}
796
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
797
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
798
+			unset($where_params['Datetime.DTT_EVT_start']);
799
+		}
800
+		$query_params[0] = $where_params;
801
+		// don't use $query_params with count()
802
+		// because we don't want to include additional query clauses like "GROUP BY"
803
+		return $count
804
+			? $this->count(array($where_params), 'EVT_ID', true)
805
+			: $this->get_all($query_params);
806
+	}
807
+
808
+
809
+
810
+	/**
811
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
812
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
813
+	 * attached to the event. See parent for param descriptions
814
+	 *
815
+	 * @param        $id_or_obj
816
+	 * @param        $other_model_id_or_obj
817
+	 * @param string $relationName
818
+	 * @param array  $where_query
819
+	 * @return EE_Base_Class
820
+	 * @throws EE_Error
821
+	 */
822
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
823
+	{
824
+		if ($relationName === 'Price') {
825
+			// let's get the PRC object for the given ID to make sure that we aren't dealing with a default
826
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
827
+			// if EVT_ID = 0, then this is a default
828
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
829
+				// let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
830
+				$prc_chk->set('PRC_ID', 0);
831
+			}
832
+			// run parent
833
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
834
+		}
835
+		// otherwise carry on as normal
836
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
837
+	}
838
+
839
+
840
+
841
+	/******************** DEPRECATED METHODS ********************/
842
+
843
+
844
+
845
+	/**
846
+	 * _get_question_target_db_column
847
+	 *
848
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
849
+	 *             EE_Registration_Custom_Questions_Form located in
850
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
851
+	 * @access     public
852
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
853
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
854
+	 *                                         registration).
855
+	 * @throws EE_Error
856
+	 * @return    array
857
+	 */
858
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
859
+	{
860
+		if (empty($EVT_ID)) {
861
+			throw new EE_Error(esc_html__(
862
+				'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
863
+				'event_espresso'
864
+			));
865
+		}
866
+		$questions = array();
867
+		// get all question groups for event
868
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
869
+		if (! empty($qgs)) {
870
+			foreach ($qgs as $qg) {
871
+				$qsts = $qg->questions();
872
+				$questions[ $qg->ID() ] = $qg->model_field_array();
873
+				$questions[ $qg->ID() ]['QSG_questions'] = array();
874
+				foreach ($qsts as $qst) {
875
+					if ($qst->is_system_question()) {
876
+						continue;
877
+					}
878
+					$answer = EEM_Answer::instance()->get_one(array(
879
+						array(
880
+							'QST_ID' => $qst->ID(),
881
+							'REG_ID' => $registration->ID(),
882
+						),
883
+					));
884
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
885
+					$qst_name = $qstn_id = $qst->ID();
886
+					$ans_id = $answer->ID();
887
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
888
+					$input_name = '';
889
+					$input_id = sanitize_key($qst->display_text());
890
+					$input_class = '';
891
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
892
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
893
+																						   . $input_name
894
+																						   . $qst_name;
895
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
896
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
897
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
898
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
899
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
900
+					// leave responses as-is, don't convert stuff into html entities please!
901
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
902
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
903
+						$QSOs = $qst->options(true, $answer->value());
904
+						if (is_array($QSOs)) {
905
+							foreach ($QSOs as $QSO_ID => $QSO) {
906
+								$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
907
+							}
908
+						}
909
+					}
910
+				}
911
+			}
912
+		}
913
+		return $questions;
914
+	}
915
+
916
+
917
+	/**
918
+	 * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
919
+	 *                             or an stdClass where each property is the name of a column,
920
+	 * @return EE_Base_Class
921
+	 * @throws \EE_Error
922
+	 */
923
+	public function instantiate_class_from_array_or_object($cols_n_values)
924
+	{
925
+		$classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
926
+		if ($classInstance instanceof EE_Event) {
927
+			// events have their timezone defined in the DB, so use it immediately
928
+			$this->set_timezone($classInstance->get_timezone());
929
+		}
930
+		return $classInstance;
931
+	}
932 932
 }
Please login to merge, or discard this patch.
core/domain/services/admin/events/data/ConfirmDeletion.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -30,86 +30,86 @@
 block discarded – undo
30 30
  */
31 31
 class ConfirmDeletion
32 32
 {
33
-    /**
34
-     * @var NodeGroupDao
35
-     */
36
-    private $dao;
33
+	/**
34
+	 * @var NodeGroupDao
35
+	 */
36
+	private $dao;
37 37
 
38
-    /**
39
-     * ConfirmDeletion constructor.
40
-     * @param NodeGroupDao $dao
41
-     */
42
-    public function __construct(
43
-        NodeGroupDao $dao
44
-    ) {
38
+	/**
39
+	 * ConfirmDeletion constructor.
40
+	 * @param NodeGroupDao $dao
41
+	 */
42
+	public function __construct(
43
+		NodeGroupDao $dao
44
+	) {
45 45
 
46
-        $this->dao = $dao;
47
-    }
46
+		$this->dao = $dao;
47
+	}
48 48
 
49
-    /**
50
-     * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
-     * preview page.
52
-     * @since 4.10.12.p
53
-     * @param $request_data
54
-     * @param $admin_base_url
55
-     * @throws EE_Error
56
-     * @throws InvalidArgumentException
57
-     * @throws InvalidDataTypeException
58
-     * @throws InvalidInterfaceException
59
-     * @throws ReflectionException
60
-     * @throws UnexpectedEntityException
61
-     */
62
-    public function handle($request_data, $admin_base_url)
63
-    {
64
-        $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
-        $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
-        $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
-        // Initialize the form from the request, and check if its valid.
68
-        $form->receive_form_submission($request_data);
69
-        if ($form->is_valid()) {
70
-            // Redirect the user to the deletion batch job.
71
-            EEH_URL::safeRedirectAndExit(
72
-                EE_Admin_Page::add_query_args_and_nonce(
73
-                    array(
74
-                        'page' => 'espresso_batch',
75
-                        'batch' => EED_Batch::batch_job,
76
-                        'deletion_job_code' => $deletion_job_code,
77
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
-                        'return_url' => urlencode(
79
-                            add_query_arg(
80
-                                [
81
-                                    'status' => 'trash'
82
-                                ],
83
-                                EVENTS_ADMIN_URL
84
-                            )
85
-                        )
86
-                    ),
87
-                    admin_url()
88
-                )
89
-            );
90
-        }
91
-        // Dont' use $form->submission_error_message() because it adds the form input's label in front
92
-        // of each validation error which ends up looking quite confusing.
93
-        $validation_errors = $form->get_validation_errors_accumulated();
94
-        foreach ($validation_errors as $validation_error) {
95
-            EE_Error::add_error(
96
-                $validation_error->getMessage(),
97
-                __FILE__,
98
-                __FUNCTION__,
99
-                __LINE__
100
-            );
101
-        }
49
+	/**
50
+	 * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
+	 * preview page.
52
+	 * @since 4.10.12.p
53
+	 * @param $request_data
54
+	 * @param $admin_base_url
55
+	 * @throws EE_Error
56
+	 * @throws InvalidArgumentException
57
+	 * @throws InvalidDataTypeException
58
+	 * @throws InvalidInterfaceException
59
+	 * @throws ReflectionException
60
+	 * @throws UnexpectedEntityException
61
+	 */
62
+	public function handle($request_data, $admin_base_url)
63
+	{
64
+		$deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
+		$models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
+		$form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
+		// Initialize the form from the request, and check if its valid.
68
+		$form->receive_form_submission($request_data);
69
+		if ($form->is_valid()) {
70
+			// Redirect the user to the deletion batch job.
71
+			EEH_URL::safeRedirectAndExit(
72
+				EE_Admin_Page::add_query_args_and_nonce(
73
+					array(
74
+						'page' => 'espresso_batch',
75
+						'batch' => EED_Batch::batch_job,
76
+						'deletion_job_code' => $deletion_job_code,
77
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
+						'return_url' => urlencode(
79
+							add_query_arg(
80
+								[
81
+									'status' => 'trash'
82
+								],
83
+								EVENTS_ADMIN_URL
84
+							)
85
+						)
86
+					),
87
+					admin_url()
88
+				)
89
+			);
90
+		}
91
+		// Dont' use $form->submission_error_message() because it adds the form input's label in front
92
+		// of each validation error which ends up looking quite confusing.
93
+		$validation_errors = $form->get_validation_errors_accumulated();
94
+		foreach ($validation_errors as $validation_error) {
95
+			EE_Error::add_error(
96
+				$validation_error->getMessage(),
97
+				__FILE__,
98
+				__FUNCTION__,
99
+				__LINE__
100
+			);
101
+		}
102 102
 
103
-        EEH_URL::safeRedirectAndExit(
104
-            EE_Admin_Page::add_query_args_and_nonce(
105
-                [
106
-                    'action' => 'preview_deletion',
107
-                    'deletion_job_code' => $deletion_job_code
108
-                ],
109
-                $admin_base_url
110
-            )
111
-        );
112
-    }
103
+		EEH_URL::safeRedirectAndExit(
104
+			EE_Admin_Page::add_query_args_and_nonce(
105
+				[
106
+					'action' => 'preview_deletion',
107
+					'deletion_job_code' => $deletion_job_code
108
+				],
109
+				$admin_base_url
110
+			)
111
+		);
112
+	}
113 113
 }
114 114
 // End of file ConfirmDeletion.php
115 115
 // Location: EventEspresso\core\domain\services\admin\events\data/ConfirmDeletion.php
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public function get_table_name()
95 95
     {
96
-        return $this->get_table_prefix() . $this->_table_name;
96
+        return $this->get_table_prefix().$this->_table_name;
97 97
     }
98 98
 
99 99
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public function get_table_alias()
107 107
     {
108
-        if (! $this->_table_alias) {
108
+        if ( ! $this->_table_alias) {
109 109
             throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
110 110
         }
111 111
         return $this->_table_alias;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function get_fully_qualified_pk_column()
130 130
     {
131
-        return $this->get_table_alias() . "." . $this->get_pk_column();
131
+        return $this->get_table_alias().".".$this->get_pk_column();
132 132
     }
133 133
 
134 134
 
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function get_select_join_limit($limit)
141 141
     {
142
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
143
-        return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
142
+        $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit;
143
+        return SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias;
144 144
     }
145 145
 
146 146
 
Please login to merge, or discard this patch.
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -6,151 +6,151 @@
 block discarded – undo
6 6
  */
7 7
 abstract class EE_Table_Base
8 8
 {
9
-    /**
10
-     * This holds the table_name without the table prefix.
11
-     *
12
-     * @var string
13
-     */
14
-    public $_table_name;
15
-
16
-
17
-    /**
18
-     * This holds what is used as the alias for the table in queries.
19
-     *
20
-     * @var string
21
-     */
22
-    public $_table_alias;
23
-
24
-
25
-    /**
26
-     * Table's private key column
27
-     *
28
-     * @var string
29
-     */
30
-    protected $_pk_column;
31
-
32
-
33
-    /**
34
-     * Whether this table is a global table (in multisite) or specific to site.
35
-     *
36
-     * @var bool
37
-     */
38
-    protected $_global;
39
-
40
-
41
-    /**
42
-     * @param string  $table_name with or without wpdb prefix
43
-     * @param string  $pk_column
44
-     * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
45
-     *                            install, or whether each site on a multisite install has a copy of this table
46
-     * @global wpdb   $wpdb
47
-     */
48
-    public function __construct($table_name, $pk_column, $global = false)
49
-    {
50
-        $this->_global = $global;
51
-        $prefix        = $this->get_table_prefix();
52
-        // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
53
-        if (strpos($table_name, $prefix) === 0) {
54
-            $table_name = substr_replace($table_name, '', 0, strlen($prefix));
55
-        }
56
-        $this->_table_name = $table_name;
57
-        $this->_pk_column  = $pk_column;
58
-    }
59
-
60
-
61
-    /**
62
-     * This returns the table prefix for the current model state.
63
-     *
64
-     * @return string
65
-     * @global wpdb $wpdb
66
-     */
67
-    public function get_table_prefix()
68
-    {
69
-        global $wpdb;
70
-        if ($this->_global) {
71
-            return $wpdb->base_prefix;
72
-        }
73
-        return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
74
-    }
75
-
76
-
77
-    /**
78
-     * Used to set the table_alias property
79
-     *
80
-     * @param string $table_alias
81
-     */
82
-    public function _construct_finalize_with_alias($table_alias)
83
-    {
84
-        $this->_table_alias = $table_alias;
85
-    }
86
-
87
-
88
-    /**
89
-     * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
90
-     *
91
-     * @return string
92
-     */
93
-    public function get_table_name()
94
-    {
95
-        return $this->get_table_prefix() . $this->_table_name;
96
-    }
97
-
98
-
99
-    /**
100
-     * Provides what is currently set as the alias for the table to be used in queries.
101
-     *
102
-     * @return string
103
-     * @throws EE_Error
104
-     */
105
-    public function get_table_alias()
106
-    {
107
-        if (! $this->_table_alias) {
108
-            throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
109
-        }
110
-        return $this->_table_alias;
111
-    }
112
-
113
-
114
-    /**
115
-     * @return string name of column of PK
116
-     */
117
-    public function get_pk_column()
118
-    {
119
-        return $this->_pk_column;
120
-    }
121
-
122
-
123
-    /**
124
-     * returns a string with the table alias, a period, and the private key's column.
125
-     *
126
-     * @return string
127
-     */
128
-    public function get_fully_qualified_pk_column()
129
-    {
130
-        return $this->get_table_alias() . "." . $this->get_pk_column();
131
-    }
132
-
133
-
134
-    /**
135
-     * returns the special sql for a inner select with a limit.
136
-     *
137
-     * @return string    SQL select
138
-     */
139
-    public function get_select_join_limit($limit)
140
-    {
141
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
142
-        return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
143
-    }
144
-
145
-
146
-    /**
147
-     * Returns whether or not htis is a global table (ie, on multisite there's
148
-     * only one of these tables, on the main blog)
149
-     *
150
-     * @return boolean
151
-     */
152
-    public function is_global()
153
-    {
154
-        return $this->_global;
155
-    }
9
+	/**
10
+	 * This holds the table_name without the table prefix.
11
+	 *
12
+	 * @var string
13
+	 */
14
+	public $_table_name;
15
+
16
+
17
+	/**
18
+	 * This holds what is used as the alias for the table in queries.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	public $_table_alias;
23
+
24
+
25
+	/**
26
+	 * Table's private key column
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected $_pk_column;
31
+
32
+
33
+	/**
34
+	 * Whether this table is a global table (in multisite) or specific to site.
35
+	 *
36
+	 * @var bool
37
+	 */
38
+	protected $_global;
39
+
40
+
41
+	/**
42
+	 * @param string  $table_name with or without wpdb prefix
43
+	 * @param string  $pk_column
44
+	 * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
45
+	 *                            install, or whether each site on a multisite install has a copy of this table
46
+	 * @global wpdb   $wpdb
47
+	 */
48
+	public function __construct($table_name, $pk_column, $global = false)
49
+	{
50
+		$this->_global = $global;
51
+		$prefix        = $this->get_table_prefix();
52
+		// if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
53
+		if (strpos($table_name, $prefix) === 0) {
54
+			$table_name = substr_replace($table_name, '', 0, strlen($prefix));
55
+		}
56
+		$this->_table_name = $table_name;
57
+		$this->_pk_column  = $pk_column;
58
+	}
59
+
60
+
61
+	/**
62
+	 * This returns the table prefix for the current model state.
63
+	 *
64
+	 * @return string
65
+	 * @global wpdb $wpdb
66
+	 */
67
+	public function get_table_prefix()
68
+	{
69
+		global $wpdb;
70
+		if ($this->_global) {
71
+			return $wpdb->base_prefix;
72
+		}
73
+		return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
74
+	}
75
+
76
+
77
+	/**
78
+	 * Used to set the table_alias property
79
+	 *
80
+	 * @param string $table_alias
81
+	 */
82
+	public function _construct_finalize_with_alias($table_alias)
83
+	{
84
+		$this->_table_alias = $table_alias;
85
+	}
86
+
87
+
88
+	/**
89
+	 * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
90
+	 *
91
+	 * @return string
92
+	 */
93
+	public function get_table_name()
94
+	{
95
+		return $this->get_table_prefix() . $this->_table_name;
96
+	}
97
+
98
+
99
+	/**
100
+	 * Provides what is currently set as the alias for the table to be used in queries.
101
+	 *
102
+	 * @return string
103
+	 * @throws EE_Error
104
+	 */
105
+	public function get_table_alias()
106
+	{
107
+		if (! $this->_table_alias) {
108
+			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
109
+		}
110
+		return $this->_table_alias;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @return string name of column of PK
116
+	 */
117
+	public function get_pk_column()
118
+	{
119
+		return $this->_pk_column;
120
+	}
121
+
122
+
123
+	/**
124
+	 * returns a string with the table alias, a period, and the private key's column.
125
+	 *
126
+	 * @return string
127
+	 */
128
+	public function get_fully_qualified_pk_column()
129
+	{
130
+		return $this->get_table_alias() . "." . $this->get_pk_column();
131
+	}
132
+
133
+
134
+	/**
135
+	 * returns the special sql for a inner select with a limit.
136
+	 *
137
+	 * @return string    SQL select
138
+	 */
139
+	public function get_select_join_limit($limit)
140
+	{
141
+		$limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
142
+		return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
143
+	}
144
+
145
+
146
+	/**
147
+	 * Returns whether or not htis is a global table (ie, on multisite there's
148
+	 * only one of these tables, on the main blog)
149
+	 *
150
+	 * @return boolean
151
+	 */
152
+	public function is_global()
153
+	{
154
+		return $this->_global;
155
+	}
156 156
 }
Please login to merge, or discard this patch.
core/domain/DomainFactory.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments)
41 41
     {
42
-        if (! isset($arguments[0], $arguments[1])) {
42
+        if ( ! isset($arguments[0], $arguments[1])) {
43 43
             throw new InvalidArgumentException(
44 44
                 esc_html__(
45 45
                     'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class',
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
         }
50 50
         /** @var DomainInterface $domain */
51 51
         $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments);
52
-        if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
52
+        if ( ! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
53 53
             throw new DomainException(
54 54
                 sprintf(
55 55
                     esc_html__(
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -22,62 +22,62 @@
 block discarded – undo
22 22
  */
23 23
 class DomainFactory
24 24
 {
25
-    /**
26
-     * @param FullyQualifiedName $domain_fqcn   [required] Fully Qualified Class Name for the Domain class
27
-     * @param array $arguments                  [required] array of arguments to be passed to the Domain class
28
-     *                                          constructor. Must at least include the following two value objects:
29
-     *                                          array(
30
-     *                                              EventEspresso\core\domain\values\FilePath $plugin_file
31
-     *                                              EventEspresso\core\domain\values\Version $version
32
-     *                                          )
33
-     * @return DomainInterface
34
-     * @throws DomainException
35
-     * @throws InvalidArgumentException
36
-     * @throws InvalidDataTypeException
37
-     * @throws InvalidInterfaceException
38
-     */
39
-    public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments)
40
-    {
41
-        if (! isset($arguments[0], $arguments[1])) {
42
-            throw new InvalidArgumentException(
43
-                esc_html__(
44
-                    'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class',
45
-                    'event_espresso'
46
-                )
47
-            );
48
-        }
49
-        /** @var DomainInterface $domain */
50
-        $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments);
51
-        if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
52
-            throw new DomainException(
53
-                sprintf(
54
-                    esc_html__(
55
-                        'The requested Domain class "%1$s" could not be loaded.',
56
-                        'event_espresso'
57
-                    ),
58
-                    $domain_fqcn
59
-                )
60
-            );
61
-        }
62
-        return $domain;
63
-    }
25
+	/**
26
+	 * @param FullyQualifiedName $domain_fqcn   [required] Fully Qualified Class Name for the Domain class
27
+	 * @param array $arguments                  [required] array of arguments to be passed to the Domain class
28
+	 *                                          constructor. Must at least include the following two value objects:
29
+	 *                                          array(
30
+	 *                                              EventEspresso\core\domain\values\FilePath $plugin_file
31
+	 *                                              EventEspresso\core\domain\values\Version $version
32
+	 *                                          )
33
+	 * @return DomainInterface
34
+	 * @throws DomainException
35
+	 * @throws InvalidArgumentException
36
+	 * @throws InvalidDataTypeException
37
+	 * @throws InvalidInterfaceException
38
+	 */
39
+	public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments)
40
+	{
41
+		if (! isset($arguments[0], $arguments[1])) {
42
+			throw new InvalidArgumentException(
43
+				esc_html__(
44
+					'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class',
45
+					'event_espresso'
46
+				)
47
+			);
48
+		}
49
+		/** @var DomainInterface $domain */
50
+		$domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments);
51
+		if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) {
52
+			throw new DomainException(
53
+				sprintf(
54
+					esc_html__(
55
+						'The requested Domain class "%1$s" could not be loaded.',
56
+						'event_espresso'
57
+					),
58
+					$domain_fqcn
59
+				)
60
+			);
61
+		}
62
+		return $domain;
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * @return Domain
68
-     * @throws DomainException
69
-     * @throws InvalidArgumentException
70
-     * @throws InvalidDataTypeException
71
-     * @throws InvalidFilePathException
72
-     * @throws InvalidInterfaceException
73
-     */
74
-    public static function getEventEspressoCoreDomain()
75
-    {
76
-        $domain = new Domain(
77
-            new FilePath(EVENT_ESPRESSO_MAIN_FILE),
78
-            Version::fromString(espresso_version())
79
-        );
80
-        LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain);
81
-        return $domain;
82
-    }
66
+	/**
67
+	 * @return Domain
68
+	 * @throws DomainException
69
+	 * @throws InvalidArgumentException
70
+	 * @throws InvalidDataTypeException
71
+	 * @throws InvalidFilePathException
72
+	 * @throws InvalidInterfaceException
73
+	 */
74
+	public static function getEventEspressoCoreDomain()
75
+	{
76
+		$domain = new Domain(
77
+			new FilePath(EVENT_ESPRESSO_MAIN_FILE),
78
+			Version::fromString(espresso_version())
79
+		);
80
+		LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain);
81
+		return $domain;
82
+	}
83 83
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Personal_Data_Exporter.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public static function register($identifier = '', array $setup_args = [])
30 30
     {
31
-        self::$exporters[ $identifier ] = $setup_args;
31
+        self::$exporters[$identifier] = $setup_args;
32 32
         // add to list of modules to be registered
33 33
         add_filter(
34 34
             'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public static function deregister($identifier = '')
44 44
     {
45
-        unset(self::$exporters[ $identifier ]);
45
+        unset(self::$exporters[$identifier]);
46 46
     }
47 47
 
48 48
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Register_Personal_Data_Exporter implements EEI_Plugin_API
14 14
 {
15
-    /**
16
-     * FQCN for all privacy policy generators
17
-     *
18
-     * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
-     */
20
-    protected static $exporters = [];
15
+	/**
16
+	 * FQCN for all privacy policy generators
17
+	 *
18
+	 * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
+	 */
20
+	protected static $exporters = [];
21 21
 
22 22
 
23
-    /**
24
-     * @param string $identifier
25
-     * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
-     *                           OR fully qualified class names of privacy policies
27
-     */
28
-    public static function register($identifier = '', array $setup_args = [])
29
-    {
30
-        self::$exporters[ $identifier ] = $setup_args;
31
-        // add to list of modules to be registered
32
-        add_filter(
33
-            'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
34
-            ['EE_Register_Personal_Data_Exporter', 'addExporters']
35
-        );
36
-    }
23
+	/**
24
+	 * @param string $identifier
25
+	 * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
+	 *                           OR fully qualified class names of privacy policies
27
+	 */
28
+	public static function register($identifier = '', array $setup_args = [])
29
+	{
30
+		self::$exporters[ $identifier ] = $setup_args;
31
+		// add to list of modules to be registered
32
+		add_filter(
33
+			'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
34
+			['EE_Register_Personal_Data_Exporter', 'addExporters']
35
+		);
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param string $identifier
41
-     */
42
-    public static function deregister($identifier = '')
43
-    {
44
-        unset(self::$exporters[ $identifier ]);
45
-    }
39
+	/**
40
+	 * @param string $identifier
41
+	 */
42
+	public static function deregister($identifier = '')
43
+	{
44
+		unset(self::$exporters[ $identifier ]);
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Adds our personal data exporters registered by add-ons
50
-     *
51
-     * @param string[] $exporters
52
-     * @return string[]
53
-     */
54
-    public static function addExporters(array $exporters)
55
-    {
56
-        foreach (self::$exporters as $exporters_per_addon) {
57
-            $exporters = array_merge(
58
-                $exporters,
59
-                $exporters_per_addon
60
-            );
61
-        }
62
-        return $exporters;
63
-    }
48
+	/**
49
+	 * Adds our personal data exporters registered by add-ons
50
+	 *
51
+	 * @param string[] $exporters
52
+	 * @return string[]
53
+	 */
54
+	public static function addExporters(array $exporters)
55
+	{
56
+		foreach (self::$exporters as $exporters_per_addon) {
57
+			$exporters = array_merge(
58
+				$exporters,
59
+				$exporters_per_addon
60
+			);
61
+		}
62
+		return $exporters;
63
+	}
64 64
 }
65 65
 // End of file EE_Register_Personal_Data_Exporter.lib.php
66 66
 // Location: ${NAMESPACE}/EE_Register_Personal_Data_Exporter.lib.php
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Personal_Data_Eraser.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public static function register($identifier = '', array $setup_args = [])
30 30
     {
31
-        self::$erasers[ $identifier ] = $setup_args;
31
+        self::$erasers[$identifier] = $setup_args;
32 32
         // add to list of modules to be registered
33 33
         add_filter(
34 34
             'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public static function deregister($identifier = '')
44 44
     {
45
-        unset(self::$erasers[ $identifier ]);
45
+        unset(self::$erasers[$identifier]);
46 46
     }
47 47
 
48 48
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Register_Personal_Data_Eraser implements EEI_Plugin_API
14 14
 {
15
-    /**
16
-     * FQCN for all privacy policy generators
17
-     *
18
-     * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
-     */
20
-    protected static $erasers = [];
15
+	/**
16
+	 * FQCN for all privacy policy generators
17
+	 *
18
+	 * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs
19
+	 */
20
+	protected static $erasers = [];
21 21
 
22 22
 
23
-    /**
24
-     * @param string $identifier
25
-     * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
-     *                           OR fully qualified class names of privacy policies
27
-     */
28
-    public static function register($identifier = '', array $setup_args = [])
29
-    {
30
-        self::$erasers[ $identifier ] = $setup_args;
31
-        // add to list of modules to be registered
32
-        add_filter(
33
-            'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
34
-            ['EE_Register_Personal_Data_Eraser', 'addErasers']
35
-        );
36
-    }
23
+	/**
24
+	 * @param string $identifier
25
+	 * @param array  $setup_args can be the fully qualified namespaces each containing only privacy policies,
26
+	 *                           OR fully qualified class names of privacy policies
27
+	 */
28
+	public static function register($identifier = '', array $setup_args = [])
29
+	{
30
+		self::$erasers[ $identifier ] = $setup_args;
31
+		// add to list of modules to be registered
32
+		add_filter(
33
+			'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
34
+			['EE_Register_Personal_Data_Eraser', 'addErasers']
35
+		);
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param string $identifier
41
-     */
42
-    public static function deregister($identifier = '')
43
-    {
44
-        unset(self::$erasers[ $identifier ]);
45
-    }
39
+	/**
40
+	 * @param string $identifier
41
+	 */
42
+	public static function deregister($identifier = '')
43
+	{
44
+		unset(self::$erasers[ $identifier ]);
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Adds our personal data erasers registered by add-ons
50
-     *
51
-     * @param string[] $erasers
52
-     * @return string[]
53
-     */
54
-    public static function addErasers(array $erasers)
55
-    {
56
-        foreach (self::$erasers as $erasers_per_addon) {
57
-            $erasers = array_merge(
58
-                $erasers,
59
-                $erasers_per_addon
60
-            );
61
-        }
62
-        return $erasers;
63
-    }
48
+	/**
49
+	 * Adds our personal data erasers registered by add-ons
50
+	 *
51
+	 * @param string[] $erasers
52
+	 * @return string[]
53
+	 */
54
+	public static function addErasers(array $erasers)
55
+	{
56
+		foreach (self::$erasers as $erasers_per_addon) {
57
+			$erasers = array_merge(
58
+				$erasers,
59
+				$erasers_per_addon
60
+			);
61
+		}
62
+		return $erasers;
63
+	}
64 64
 }
65 65
 // End of file EE_Register_Personal_Data_Eraser.lib.php
66 66
 // Location: ${NAMESPACE}/EE_Register_Personal_Data_Eraser.lib.php
Please login to merge, or discard this patch.