Completed
Branch BUG/fix-datetime-reg-links (1a6d9f)
by
unknown
02:51 queued 28s
created
modules/single_page_checkout/inc/EE_SPCO_JSON_Response.php 1 patch
Indentation   +397 added lines, -397 removed lines patch added patch discarded remove patch
@@ -14,401 +14,401 @@
 block discarded – undo
14 14
  */
15 15
 class EE_SPCO_JSON_Response
16 16
 {
17
-    /**
18
-     * @var string
19
-     */
20
-    protected $_errors = '';
21
-
22
-    /**
23
-     * @var string
24
-     */
25
-    protected $_unexpected_errors = '';
26
-
27
-    /**
28
-     * @var string
29
-     */
30
-    protected $_attention = '';
31
-
32
-    /**
33
-     * @var string
34
-     */
35
-    protected $_success = '';
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    protected $_plz_select_method_of_payment = '';
41
-
42
-    /**
43
-     * @var string
44
-     */
45
-    protected $_redirect_url = '';
46
-
47
-    /**
48
-     * @var string
49
-     */
50
-    protected $_registration_time_limit = '';
51
-
52
-    /**
53
-     * @var string
54
-     */
55
-    protected $_redirect_form = '';
56
-
57
-    /**
58
-     * @var string
59
-     */
60
-    protected $_reg_step_html = '';
61
-
62
-    /**
63
-     * @var string
64
-     */
65
-    protected $_method_of_payment = '';
66
-
67
-    /**
68
-     * @var float
69
-     */
70
-    protected $_payment_amount;
71
-
72
-    /**
73
-     * @var array
74
-     */
75
-    protected $_return_data = array();
76
-
77
-
78
-    /**
79
-     * @var array
80
-     */
81
-    protected $_validation_rules = array();
82
-
83
-
84
-    /**
85
-     *    class constructor
86
-     */
87
-    public function __construct()
88
-    {
89
-    }
90
-
91
-
92
-    /**
93
-     *    __toString
94
-     *
95
-     *        allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a  JSON encoded string
96
-     *
97
-     * @access    public
98
-     * @return    string
99
-     */
100
-    public function __toString()
101
-    {
102
-        $JSON_response = array();
103
-        // grab notices
104
-        $notices = EE_Error::get_notices(false);
105
-        $this->set_attention(isset($notices['attention']) ? $notices['attention'] : '');
106
-        $this->set_errors(isset($notices['errors']) ? $notices['errors'] : '');
107
-        $this->set_success(isset($notices['success']) ? $notices['success'] : '');
108
-        // add notices to JSON response, but only if they exist
109
-        if ($this->attention()) {
110
-            $JSON_response['attention'] = $this->attention();
111
-        }
112
-        if ($this->errors()) {
113
-            $JSON_response['errors'] = $this->errors();
114
-        }
115
-        if ($this->unexpected_errors()) {
116
-            $JSON_response['unexpected_errors'] = $this->unexpected_errors();
117
-        }
118
-        if ($this->success()) {
119
-            $JSON_response['success'] = $this->success();
120
-        }
121
-        // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked
122
-        if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) {
123
-            $JSON_response['success'] = null;
124
-        }
125
-        // set redirect_url, IF it exists
126
-        if ($this->redirect_url()) {
127
-            $JSON_response['redirect_url'] = $this->redirect_url();
128
-        }
129
-        // set registration_time_limit, IF it exists
130
-        if ($this->registration_time_limit()) {
131
-            $JSON_response['registration_time_limit'] = $this->registration_time_limit();
132
-        }
133
-        // set payment_amount, IF it exists
134
-        if ($this->payment_amount() !== null) {
135
-            $JSON_response['payment_amount'] = $this->payment_amount();
136
-        }
137
-        // grab generic return data
138
-        $return_data = $this->return_data();
139
-        // add billing form validation rules
140
-        if ($this->validation_rules()) {
141
-            $return_data['validation_rules'] = $this->validation_rules();
142
-        }
143
-        // set reg_step_html, IF it exists
144
-        if ($this->reg_step_html()) {
145
-            $return_data['reg_step_html'] = $this->reg_step_html();
146
-        }
147
-        // set method of payment, IF it exists
148
-        if ($this->method_of_payment()) {
149
-            $return_data['method_of_payment'] = $this->method_of_payment();
150
-        }
151
-        // set "plz_select_method_of_payment" message, IF it exists
152
-        if ($this->plz_select_method_of_payment()) {
153
-            $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment();
154
-        }
155
-        // set redirect_form, IF it exists
156
-        if ($this->redirect_form()) {
157
-            $return_data['redirect_form'] = $this->redirect_form();
158
-        }
159
-        // and finally, add return_data array to main JSON response array, IF it contains anything
160
-        // why did we add some of the above properties to the return data array?
161
-        // because it is easier and cleaner in the Javascript to deal with this way
162
-        if (! empty($return_data)) {
163
-            $JSON_response['return_data'] = $return_data;
164
-        }
165
-        // filter final array
166
-        $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response);
167
-        // return encoded array
168
-        return (string) wp_json_encode($JSON_response);
169
-    }
170
-
171
-
172
-    /**
173
-     * @param string $attention
174
-     */
175
-    public function set_attention($attention)
176
-    {
177
-        $this->_attention = $attention;
178
-    }
179
-
180
-
181
-    /**
182
-     * @return string
183
-     */
184
-    public function attention()
185
-    {
186
-        return $this->_attention;
187
-    }
188
-
189
-
190
-    /**
191
-     * @param string $errors
192
-     */
193
-    public function set_errors($errors)
194
-    {
195
-        $this->_errors = $errors;
196
-    }
197
-
198
-
199
-    /**
200
-     * @return string
201
-     */
202
-    public function errors()
203
-    {
204
-        return $this->_errors;
205
-    }
206
-
207
-
208
-    /**
209
-     * @return string
210
-     */
211
-    public function unexpected_errors()
212
-    {
213
-        return $this->_unexpected_errors;
214
-    }
215
-
216
-
217
-    /**
218
-     * @param string $unexpected_errors
219
-     */
220
-    public function set_unexpected_errors($unexpected_errors)
221
-    {
222
-        $this->_unexpected_errors = $unexpected_errors;
223
-    }
224
-
225
-
226
-    /**
227
-     * @param string $success
228
-     */
229
-    public function set_success($success)
230
-    {
231
-        $this->_success = $success;
232
-    }
233
-
234
-
235
-    /**
236
-     * @return string
237
-     */
238
-    public function success()
239
-    {
240
-        return $this->_success;
241
-    }
242
-
243
-
244
-    /**
245
-     * @param string $method_of_payment
246
-     */
247
-    public function set_method_of_payment($method_of_payment)
248
-    {
249
-        $this->_method_of_payment = $method_of_payment;
250
-    }
251
-
252
-
253
-    /**
254
-     * @return string
255
-     */
256
-    public function method_of_payment()
257
-    {
258
-        return $this->_method_of_payment;
259
-    }
260
-
261
-
262
-    /**
263
-     * @return float
264
-     */
265
-    public function payment_amount()
266
-    {
267
-        return $this->_payment_amount;
268
-    }
269
-
270
-
271
-    /**
272
-     * @param float $payment_amount
273
-     * @throws EE_Error
274
-     */
275
-    public function set_payment_amount($payment_amount)
276
-    {
277
-        $this->_payment_amount = (float) $payment_amount;
278
-    }
279
-
280
-
281
-    /**
282
-     * @param string $next_step_html
283
-     */
284
-    public function set_reg_step_html($next_step_html)
285
-    {
286
-        $this->_reg_step_html = $next_step_html;
287
-    }
288
-
289
-
290
-    /**
291
-     * @return string
292
-     */
293
-    public function reg_step_html()
294
-    {
295
-        return $this->_reg_step_html;
296
-    }
297
-
298
-
299
-    /**
300
-     * @param string $redirect_form
301
-     */
302
-    public function set_redirect_form($redirect_form)
303
-    {
304
-        $this->_redirect_form = $redirect_form;
305
-    }
306
-
307
-
308
-    /**
309
-     * @return string
310
-     */
311
-    public function redirect_form()
312
-    {
313
-        return ! empty($this->_redirect_form) ? $this->_redirect_form : false;
314
-    }
315
-
316
-
317
-    /**
318
-     * @param string $plz_select_method_of_payment
319
-     */
320
-    public function set_plz_select_method_of_payment($plz_select_method_of_payment)
321
-    {
322
-        $this->_plz_select_method_of_payment = $plz_select_method_of_payment;
323
-    }
324
-
325
-
326
-    /**
327
-     * @return string
328
-     */
329
-    public function plz_select_method_of_payment()
330
-    {
331
-        return $this->_plz_select_method_of_payment;
332
-    }
333
-
334
-
335
-    /**
336
-     * @param string $redirect_url
337
-     */
338
-    public function set_redirect_url($redirect_url)
339
-    {
340
-        $this->_redirect_url = $redirect_url;
341
-    }
342
-
343
-
344
-    /**
345
-     * @return string
346
-     */
347
-    public function redirect_url()
348
-    {
349
-        return $this->_redirect_url;
350
-    }
351
-
352
-
353
-    /**
354
-     * @return string
355
-     */
356
-    public function registration_time_limit()
357
-    {
358
-        return $this->_registration_time_limit;
359
-    }
360
-
361
-
362
-    /**
363
-     * @param string $registration_time_limit
364
-     */
365
-    public function set_registration_time_limit($registration_time_limit)
366
-    {
367
-        $this->_registration_time_limit = $registration_time_limit;
368
-    }
369
-
370
-
371
-    /**
372
-     * @param array $return_data
373
-     */
374
-    public function set_return_data($return_data)
375
-    {
376
-        $this->_return_data = array_merge($this->_return_data, $return_data);
377
-    }
378
-
379
-
380
-    /**
381
-     * @return array
382
-     */
383
-    public function return_data()
384
-    {
385
-        return $this->_return_data;
386
-    }
387
-
388
-
389
-    /**
390
-     * @param array $validation_rules
391
-     */
392
-    public function add_validation_rules(array $validation_rules = array())
393
-    {
394
-        if (is_array($validation_rules) && ! empty($validation_rules)) {
395
-            $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules);
396
-        }
397
-    }
398
-
399
-
400
-    /**
401
-     * @return array | bool
402
-     */
403
-    public function validation_rules()
404
-    {
405
-        return ! empty($this->_validation_rules) ? $this->_validation_rules : false;
406
-    }
407
-
408
-
409
-    public function echoAndExit()
410
-    {
411
-        echo ($this);
412
-        exit();
413
-    }
17
+	/**
18
+	 * @var string
19
+	 */
20
+	protected $_errors = '';
21
+
22
+	/**
23
+	 * @var string
24
+	 */
25
+	protected $_unexpected_errors = '';
26
+
27
+	/**
28
+	 * @var string
29
+	 */
30
+	protected $_attention = '';
31
+
32
+	/**
33
+	 * @var string
34
+	 */
35
+	protected $_success = '';
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	protected $_plz_select_method_of_payment = '';
41
+
42
+	/**
43
+	 * @var string
44
+	 */
45
+	protected $_redirect_url = '';
46
+
47
+	/**
48
+	 * @var string
49
+	 */
50
+	protected $_registration_time_limit = '';
51
+
52
+	/**
53
+	 * @var string
54
+	 */
55
+	protected $_redirect_form = '';
56
+
57
+	/**
58
+	 * @var string
59
+	 */
60
+	protected $_reg_step_html = '';
61
+
62
+	/**
63
+	 * @var string
64
+	 */
65
+	protected $_method_of_payment = '';
66
+
67
+	/**
68
+	 * @var float
69
+	 */
70
+	protected $_payment_amount;
71
+
72
+	/**
73
+	 * @var array
74
+	 */
75
+	protected $_return_data = array();
76
+
77
+
78
+	/**
79
+	 * @var array
80
+	 */
81
+	protected $_validation_rules = array();
82
+
83
+
84
+	/**
85
+	 *    class constructor
86
+	 */
87
+	public function __construct()
88
+	{
89
+	}
90
+
91
+
92
+	/**
93
+	 *    __toString
94
+	 *
95
+	 *        allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a  JSON encoded string
96
+	 *
97
+	 * @access    public
98
+	 * @return    string
99
+	 */
100
+	public function __toString()
101
+	{
102
+		$JSON_response = array();
103
+		// grab notices
104
+		$notices = EE_Error::get_notices(false);
105
+		$this->set_attention(isset($notices['attention']) ? $notices['attention'] : '');
106
+		$this->set_errors(isset($notices['errors']) ? $notices['errors'] : '');
107
+		$this->set_success(isset($notices['success']) ? $notices['success'] : '');
108
+		// add notices to JSON response, but only if they exist
109
+		if ($this->attention()) {
110
+			$JSON_response['attention'] = $this->attention();
111
+		}
112
+		if ($this->errors()) {
113
+			$JSON_response['errors'] = $this->errors();
114
+		}
115
+		if ($this->unexpected_errors()) {
116
+			$JSON_response['unexpected_errors'] = $this->unexpected_errors();
117
+		}
118
+		if ($this->success()) {
119
+			$JSON_response['success'] = $this->success();
120
+		}
121
+		// but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked
122
+		if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) {
123
+			$JSON_response['success'] = null;
124
+		}
125
+		// set redirect_url, IF it exists
126
+		if ($this->redirect_url()) {
127
+			$JSON_response['redirect_url'] = $this->redirect_url();
128
+		}
129
+		// set registration_time_limit, IF it exists
130
+		if ($this->registration_time_limit()) {
131
+			$JSON_response['registration_time_limit'] = $this->registration_time_limit();
132
+		}
133
+		// set payment_amount, IF it exists
134
+		if ($this->payment_amount() !== null) {
135
+			$JSON_response['payment_amount'] = $this->payment_amount();
136
+		}
137
+		// grab generic return data
138
+		$return_data = $this->return_data();
139
+		// add billing form validation rules
140
+		if ($this->validation_rules()) {
141
+			$return_data['validation_rules'] = $this->validation_rules();
142
+		}
143
+		// set reg_step_html, IF it exists
144
+		if ($this->reg_step_html()) {
145
+			$return_data['reg_step_html'] = $this->reg_step_html();
146
+		}
147
+		// set method of payment, IF it exists
148
+		if ($this->method_of_payment()) {
149
+			$return_data['method_of_payment'] = $this->method_of_payment();
150
+		}
151
+		// set "plz_select_method_of_payment" message, IF it exists
152
+		if ($this->plz_select_method_of_payment()) {
153
+			$return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment();
154
+		}
155
+		// set redirect_form, IF it exists
156
+		if ($this->redirect_form()) {
157
+			$return_data['redirect_form'] = $this->redirect_form();
158
+		}
159
+		// and finally, add return_data array to main JSON response array, IF it contains anything
160
+		// why did we add some of the above properties to the return data array?
161
+		// because it is easier and cleaner in the Javascript to deal with this way
162
+		if (! empty($return_data)) {
163
+			$JSON_response['return_data'] = $return_data;
164
+		}
165
+		// filter final array
166
+		$JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response);
167
+		// return encoded array
168
+		return (string) wp_json_encode($JSON_response);
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param string $attention
174
+	 */
175
+	public function set_attention($attention)
176
+	{
177
+		$this->_attention = $attention;
178
+	}
179
+
180
+
181
+	/**
182
+	 * @return string
183
+	 */
184
+	public function attention()
185
+	{
186
+		return $this->_attention;
187
+	}
188
+
189
+
190
+	/**
191
+	 * @param string $errors
192
+	 */
193
+	public function set_errors($errors)
194
+	{
195
+		$this->_errors = $errors;
196
+	}
197
+
198
+
199
+	/**
200
+	 * @return string
201
+	 */
202
+	public function errors()
203
+	{
204
+		return $this->_errors;
205
+	}
206
+
207
+
208
+	/**
209
+	 * @return string
210
+	 */
211
+	public function unexpected_errors()
212
+	{
213
+		return $this->_unexpected_errors;
214
+	}
215
+
216
+
217
+	/**
218
+	 * @param string $unexpected_errors
219
+	 */
220
+	public function set_unexpected_errors($unexpected_errors)
221
+	{
222
+		$this->_unexpected_errors = $unexpected_errors;
223
+	}
224
+
225
+
226
+	/**
227
+	 * @param string $success
228
+	 */
229
+	public function set_success($success)
230
+	{
231
+		$this->_success = $success;
232
+	}
233
+
234
+
235
+	/**
236
+	 * @return string
237
+	 */
238
+	public function success()
239
+	{
240
+		return $this->_success;
241
+	}
242
+
243
+
244
+	/**
245
+	 * @param string $method_of_payment
246
+	 */
247
+	public function set_method_of_payment($method_of_payment)
248
+	{
249
+		$this->_method_of_payment = $method_of_payment;
250
+	}
251
+
252
+
253
+	/**
254
+	 * @return string
255
+	 */
256
+	public function method_of_payment()
257
+	{
258
+		return $this->_method_of_payment;
259
+	}
260
+
261
+
262
+	/**
263
+	 * @return float
264
+	 */
265
+	public function payment_amount()
266
+	{
267
+		return $this->_payment_amount;
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param float $payment_amount
273
+	 * @throws EE_Error
274
+	 */
275
+	public function set_payment_amount($payment_amount)
276
+	{
277
+		$this->_payment_amount = (float) $payment_amount;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @param string $next_step_html
283
+	 */
284
+	public function set_reg_step_html($next_step_html)
285
+	{
286
+		$this->_reg_step_html = $next_step_html;
287
+	}
288
+
289
+
290
+	/**
291
+	 * @return string
292
+	 */
293
+	public function reg_step_html()
294
+	{
295
+		return $this->_reg_step_html;
296
+	}
297
+
298
+
299
+	/**
300
+	 * @param string $redirect_form
301
+	 */
302
+	public function set_redirect_form($redirect_form)
303
+	{
304
+		$this->_redirect_form = $redirect_form;
305
+	}
306
+
307
+
308
+	/**
309
+	 * @return string
310
+	 */
311
+	public function redirect_form()
312
+	{
313
+		return ! empty($this->_redirect_form) ? $this->_redirect_form : false;
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param string $plz_select_method_of_payment
319
+	 */
320
+	public function set_plz_select_method_of_payment($plz_select_method_of_payment)
321
+	{
322
+		$this->_plz_select_method_of_payment = $plz_select_method_of_payment;
323
+	}
324
+
325
+
326
+	/**
327
+	 * @return string
328
+	 */
329
+	public function plz_select_method_of_payment()
330
+	{
331
+		return $this->_plz_select_method_of_payment;
332
+	}
333
+
334
+
335
+	/**
336
+	 * @param string $redirect_url
337
+	 */
338
+	public function set_redirect_url($redirect_url)
339
+	{
340
+		$this->_redirect_url = $redirect_url;
341
+	}
342
+
343
+
344
+	/**
345
+	 * @return string
346
+	 */
347
+	public function redirect_url()
348
+	{
349
+		return $this->_redirect_url;
350
+	}
351
+
352
+
353
+	/**
354
+	 * @return string
355
+	 */
356
+	public function registration_time_limit()
357
+	{
358
+		return $this->_registration_time_limit;
359
+	}
360
+
361
+
362
+	/**
363
+	 * @param string $registration_time_limit
364
+	 */
365
+	public function set_registration_time_limit($registration_time_limit)
366
+	{
367
+		$this->_registration_time_limit = $registration_time_limit;
368
+	}
369
+
370
+
371
+	/**
372
+	 * @param array $return_data
373
+	 */
374
+	public function set_return_data($return_data)
375
+	{
376
+		$this->_return_data = array_merge($this->_return_data, $return_data);
377
+	}
378
+
379
+
380
+	/**
381
+	 * @return array
382
+	 */
383
+	public function return_data()
384
+	{
385
+		return $this->_return_data;
386
+	}
387
+
388
+
389
+	/**
390
+	 * @param array $validation_rules
391
+	 */
392
+	public function add_validation_rules(array $validation_rules = array())
393
+	{
394
+		if (is_array($validation_rules) && ! empty($validation_rules)) {
395
+			$this->_validation_rules = array_merge($this->_validation_rules, $validation_rules);
396
+		}
397
+	}
398
+
399
+
400
+	/**
401
+	 * @return array | bool
402
+	 */
403
+	public function validation_rules()
404
+	{
405
+		return ! empty($this->_validation_rules) ? $this->_validation_rules : false;
406
+	}
407
+
408
+
409
+	public function echoAndExit()
410
+	{
411
+		echo ($this);
412
+		exit();
413
+	}
414 414
 }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Html_messenger.class.php 1 patch
Indentation   +545 added lines, -545 removed lines patch added patch discarded remove patch
@@ -12,549 +12,549 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Html_messenger extends EE_messenger
14 14
 {
15
-    /**
16
-     * The following are the properties that this messenger requires for displaying the html
17
-     */
18
-    /**
19
-     * This is the html body generated by the template via the message type.
20
-     *
21
-     * @var string
22
-     */
23
-    protected $_content = '';
24
-
25
-    /**
26
-     * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
27
-     * equivalent to the "subject" of the page.
28
-     *
29
-     * @var string
30
-     */
31
-    protected $_subject = '';
32
-
33
-
34
-    /**
35
-     * EE_Html_messenger constructor.
36
-     */
37
-    public function __construct()
38
-    {
39
-        // set properties
40
-        $this->name                = 'html';
41
-        $this->description         = esc_html__(
42
-            'This messenger outputs a message to a browser for display.',
43
-            'event_espresso'
44
-        );
45
-        $this->label               = [
46
-            'singular' => esc_html__('html', 'event_espresso'),
47
-            'plural'   => esc_html__('html', 'event_espresso'),
48
-        ];
49
-        $this->activate_on_install = true;
50
-        // add the "powered by EE" credit link to the HTML receipt and invoice
51
-        add_filter(
52
-            'FHEE__EE_Html_messenger___send_message__main_body',
53
-            [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'],
54
-            10,
55
-            3
56
-        );
57
-        parent::__construct();
58
-    }
59
-
60
-
61
-    /**
62
-     * HTML Messenger desires execution immediately.
63
-     *
64
-     * @return bool
65
-     * @since  4.9.0
66
-     * @see    parent::send_now() for documentation.
67
-     */
68
-    public function send_now(): bool
69
-    {
70
-        return true;
71
-    }
72
-
73
-
74
-    /**
75
-     * HTML Messenger allows an empty to field.
76
-     *
77
-     * @return bool
78
-     * @since  4.9.0
79
-     * @see    parent::allow_empty_to_field() for documentation
80
-     */
81
-    public function allow_empty_to_field(): bool
82
-    {
83
-        return true;
84
-    }
85
-
86
-
87
-    /**
88
-     * @see abstract declaration in EE_messenger for details.
89
-     */
90
-    protected function _set_admin_pages()
91
-    {
92
-        $this->admin_registered_pages = ['events_edit' => true];
93
-    }
94
-
95
-
96
-    /**
97
-     * @see abstract declaration in EE_messenger for details.
98
-     */
99
-    protected function _set_valid_shortcodes()
100
-    {
101
-        $this->_valid_shortcodes = [];
102
-    }
103
-
104
-
105
-    /**
106
-     * @see abstract declaration in EE_messenger for details.
107
-     */
108
-    protected function _set_validator_config()
109
-    {
110
-        $this->_validator_config = [
111
-            'subject'                       => [
112
-                'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'],
113
-            ],
114
-            'content'                       => [
115
-                'shortcodes' => [
116
-                    'organization',
117
-                    'primary_registration_list',
118
-                    'primary_registration_details',
119
-                    'email',
120
-                    'transaction',
121
-                    'event_list',
122
-                    'payment_list',
123
-                    'venue',
124
-                    'line_item_list',
125
-                    'messenger',
126
-                    'ticket_list',
127
-                ],
128
-            ],
129
-            'event_list'                    => [
130
-                'shortcodes' => [
131
-                    'event',
132
-                    'ticket_list',
133
-                    'venue',
134
-                    'primary_registration_details',
135
-                    'primary_registration_list',
136
-                    'event_author',
137
-                ],
138
-                'required'   => ['[EVENT_LIST]'],
139
-            ],
140
-            'ticket_list'                   => [
141
-                'shortcodes' => [
142
-                    'attendee_list',
143
-                    'ticket',
144
-                    'datetime_list',
145
-                    'primary_registration_details',
146
-                    'line_item_list',
147
-                    'venue',
148
-                ],
149
-                'required'   => ['[TICKET_LIST]'],
150
-            ],
151
-            'ticket_line_item_no_pms'       => [
152
-                'shortcodes' => ['line_item', 'ticket'],
153
-                'required'   => ['[TICKET_LINE_ITEM_LIST]'],
154
-            ],
155
-            'ticket_line_item_pms'          => [
156
-                'shortcodes' => ['line_item', 'ticket', 'line_item_list'],
157
-                'required'   => ['[TICKET_LINE_ITEM_LIST]'],
158
-            ],
159
-            'price_modifier_line_item_list' => [
160
-                'shortcodes' => ['line_item'],
161
-                'required'   => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],
162
-            ],
163
-            'datetime_list'                 => [
164
-                'shortcodes' => ['datetime'],
165
-                'required'   => ['[DATETIME_LIST]'],
166
-            ],
167
-            'attendee_list'                 => [
168
-                'shortcodes' => ['attendee'],
169
-                'required'   => ['[ATTENDEE_LIST]'],
170
-            ],
171
-            'tax_line_item_list'            => [
172
-                'shortcodes' => ['line_item'],
173
-                'required'   => ['[TAX_LINE_ITEM_LIST]'],
174
-            ],
175
-            'additional_line_item_list'     => [
176
-                'shortcodes' => ['line_item'],
177
-                'required'   => ['[ADDITIONAL_LINE_ITEM_LIST]'],
178
-            ],
179
-            'payment_list'                  => [
180
-                'shortcodes' => ['payment'],
181
-                'required'   => ['[PAYMENT_LIST_*]'],
182
-            ],
183
-        ];
184
-    }
185
-
186
-
187
-    /**
188
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
189
-     * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
190
-     * (i.e. swap out css files or something else).
191
-     *
192
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
193
-     * @return void
194
-     * @since 4.5.0
195
-     */
196
-    public function do_secondary_messenger_hooks($sending_messenger_name)
197
-    {
198
-        if ($sending_messenger_name === 'pdf') {
199
-            add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8);
200
-        }
201
-    }
202
-
203
-
204
-    /**
205
-     * @param                            $variation_path
206
-     * @param EE_Messages_Template_Pack  $template_pack
207
-     * @param                            $messenger_name
208
-     * @param                            $message_type_name
209
-     * @param                            $url
210
-     * @param                            $type
211
-     * @param                            $variation
212
-     * @param                            $skip_filters
213
-     * @return string
214
-     */
215
-    public function add_html_css(
216
-        $variation_path,
217
-        EE_Messages_Template_Pack $template_pack,
218
-        $messenger_name,
219
-        $message_type_name,
220
-        $url,
221
-        $type,
222
-        $variation,
223
-        $skip_filters
224
-    ): string {
225
-        return $template_pack->get_variation(
226
-            $this->name,
227
-            $message_type_name,
228
-            $type,
229
-            $variation,
230
-            $url,
231
-            '.css',
232
-            $skip_filters
233
-        );
234
-    }
235
-
236
-
237
-    /**
238
-     * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
239
-     * messenger can add their own js.
240
-     *
241
-     * @return void.
242
-     */
243
-    public function enqueue_scripts_styles()
244
-    {
245
-        parent::enqueue_scripts_styles();
246
-        do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
247
-    }
248
-
249
-
250
-    /**
251
-     * _set_template_fields
252
-     * This sets up the fields that a messenger requires for the message to go out.
253
-     *
254
-     * @access  protected
255
-     * @return void
256
-     */
257
-    protected function _set_template_fields()
258
-    {
259
-        // any extra template fields that are NOT used by the messenger
260
-        // but will get used by a messenger field for shortcode replacement
261
-        // get added to the 'extra' key in an associated array
262
-        // indexed by the messenger field they relate to.
263
-        // This is important for the Messages_admin to know what fields to display to the user.
264
-        // Also, notice that the "values" are equal to the field type
265
-        // that messages admin will use to know what kind of field to display.
266
-        // The values ALSO have one index labeled "shortcode".
267
-        // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
268
-        // is required in order for this extra field to be displayed.
269
-        //  If the required shortcode isn't part of the shortcodes array
270
-        // then the field is not needed and will not be displayed/parsed.
271
-        $this->_template_fields = [
272
-            'subject' => [
273
-                'input'      => 'text',
274
-                'label'      => esc_html__('Page Title', 'event_espresso'),
275
-                'type'       => 'string',
276
-                'required'   => true,
277
-                'validation' => true,
278
-                'css_class'  => 'large-text',
279
-                'format'     => '%s',
280
-            ],
281
-            'content' => '',
282
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
283
-            'extra'   => [
284
-                'content' => [
285
-                    'main'                          => [
286
-                        'input'      => 'wp_editor',
287
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
288
-                        'type'       => 'string',
289
-                        'required'   => true,
290
-                        'validation' => true,
291
-                        'format'     => '%s',
292
-                        'rows'       => '15',
293
-                    ],
294
-                    'event_list'                    => [
295
-                        'input'               => 'wp_editor',
296
-                        'label'               => '[EVENT_LIST]',
297
-                        'type'                => 'string',
298
-                        'required'            => true,
299
-                        'validation'          => true,
300
-                        'format'              => '%s',
301
-                        'rows'                => '15',
302
-                        'shortcodes_required' => ['[EVENT_LIST]'],
303
-                    ],
304
-                    'ticket_list'                   => [
305
-                        'input'               => 'textarea',
306
-                        'label'               => '[TICKET_LIST]',
307
-                        'type'                => 'string',
308
-                        'required'            => true,
309
-                        'validation'          => true,
310
-                        'format'              => '%s',
311
-                        'css_class'           => 'large-text',
312
-                        'rows'                => '10',
313
-                        'shortcodes_required' => ['[TICKET_LIST]'],
314
-                    ],
315
-                    'ticket_line_item_no_pms'       => [
316
-                        'input'               => 'textarea',
317
-                        'label'               => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(
318
-                            'Ticket Line Item List with no Price Modifiers',
319
-                            'event_espresso'
320
-                        ),
321
-                        'type'                => 'string',
322
-                        'required'            => false,
323
-                        'validation'          => true,
324
-                        'format'              => '%s',
325
-                        'css_class'           => 'large-text',
326
-                        'rows'                => '5',
327
-                        'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],
328
-                    ],
329
-                    'ticket_line_item_pms'          => [
330
-                        'input'               => 'textarea',
331
-                        'label'               => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(
332
-                            'Ticket Line Item List with Price Modifiers',
333
-                            'event_espresso'
334
-                        ),
335
-                        'type'                => 'string',
336
-                        'required'            => false,
337
-                        'validation'          => true,
338
-                        'format'              => '%s',
339
-                        'css_class'           => 'large-text',
340
-                        'rows'                => '5',
341
-                        'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],
342
-                    ],
343
-                    'price_modifier_line_item_list' => [
344
-                        'input'               => 'textarea',
345
-                        'label'               => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
346
-                        'type'                => 'string',
347
-                        'required'            => false,
348
-                        'validation'          => true,
349
-                        'format'              => '%s',
350
-                        'css_class'           => 'large-text',
351
-                        'rows'                => '5',
352
-                        'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],
353
-                    ],
354
-                    'datetime_list'                 => [
355
-                        'input'               => 'textarea',
356
-                        'label'               => '[DATETIME_LIST]',
357
-                        'type'                => 'string',
358
-                        'required'            => true,
359
-                        'validation'          => true,
360
-                        'format'              => '%s',
361
-                        'css_class'           => 'large-text',
362
-                        'rows'                => '5',
363
-                        'shortcodes_required' => ['[DATETIME_LIST]'],
364
-                    ],
365
-                    'attendee_list'                 => [
366
-                        'input'               => 'textarea',
367
-                        'label'               => '[ATTENDEE_LIST]',
368
-                        'type'                => 'string',
369
-                        'required'            => true,
370
-                        'validation'          => true,
371
-                        'format'              => '%s',
372
-                        'css_class'           => 'large-text',
373
-                        'rows'                => '5',
374
-                        'shortcodes_required' => ['[ATTENDEE_LIST]'],
375
-                    ],
376
-                    'tax_line_item_list'            => [
377
-                        'input'               => 'textarea',
378
-                        'label'               => '[TAX_LINE_ITEM_LIST]',
379
-                        'type'                => 'string',
380
-                        'required'            => false,
381
-                        'validation'          => true,
382
-                        'format'              => '%s',
383
-                        'css_class'           => 'large-text',
384
-                        'rows'                => '5',
385
-                        'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'],
386
-                    ],
387
-                    'additional_line_item_list'     => [
388
-                        'input'               => 'textarea',
389
-                        'label'               => '[ADDITIONAL_LINE_ITEM_LIST]',
390
-                        'type'                => 'string',
391
-                        'required'            => false,
392
-                        'validation'          => true,
393
-                        'format'              => '%s',
394
-                        'css_class'           => 'large-text',
395
-                        'rows'                => '5',
396
-                        'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'],
397
-                    ],
398
-                    'payment_list'                  => [
399
-                        'input'               => 'textarea',
400
-                        'label'               => '[PAYMENT_LIST]',
401
-                        'type'                => 'string',
402
-                        'required'            => true,
403
-                        'validation'          => true,
404
-                        'format'              => '%s',
405
-                        'css_class'           => 'large-text',
406
-                        'rows'                => '5',
407
-                        'shortcodes_required' => ['[PAYMENT_LIST_*]'],
408
-                    ],
409
-                ],
410
-            ],
411
-        ];
412
-    }
413
-
414
-
415
-    /**
416
-     * @see   definition of this method in parent
417
-     * @since 4.5.0
418
-     */
419
-    protected function _set_default_message_types()
420
-    {
421
-        $this->_default_message_types = ['receipt', 'invoice'];
422
-    }
423
-
424
-
425
-    /**
426
-     * @see   definition of this method in parent
427
-     * @since 4.5.0
428
-     */
429
-    protected function _set_valid_message_types()
430
-    {
431
-        $this->_valid_message_types = ['receipt', 'invoice'];
432
-    }
433
-
434
-
435
-    /**
436
-     * Displays the message in the browser.
437
-     *
438
-     * @return void.
439
-     * @since 4.5.0
440
-     */
441
-    protected function _send_message()
442
-    {
443
-        $this->_template_args = [
444
-            'page_title' => $this->_subject,
445
-            'base_css'   => $this->get_variation(
446
-                $this->_tmp_pack,
447
-                $this->_incoming_message_type->name,
448
-                true,
449
-                'base',
450
-                $this->_variation
451
-            ),
452
-            'print_css'  => $this->get_variation(
453
-                $this->_tmp_pack,
454
-                $this->_incoming_message_type->name,
455
-                true,
456
-                'print',
457
-                $this->_variation
458
-            ),
459
-            'main_css'   => $this->get_variation(
460
-                $this->_tmp_pack,
461
-                $this->_incoming_message_type->name,
462
-                true,
463
-                'main',
464
-                $this->_variation
465
-            ),
466
-            'main_body'  => wpautop(
467
-                apply_filters(
468
-                    'FHEE__EE_Html_messenger___send_message__main_body',
469
-                    $this->_content,
470
-                    $this->_content,
471
-                    $this->_incoming_message_type
472
-                )
473
-            ),
474
-        ];
475
-        $this->_deregister_wp_hooks();
476
-        add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']);
477
-        echo ($this->_get_main_template());
478
-        exit();
479
-    }
480
-
481
-
482
-    /**
483
-     * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
484
-     * interfere with our templates.  If users want to add any custom styles or scripts they must use the
485
-     * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
486
-     *
487
-     * @return void
488
-     * @since 4.5.0
489
-     */
490
-    protected function _deregister_wp_hooks()
491
-    {
492
-        remove_all_actions('wp_head');
493
-        remove_all_actions('wp_footer');
494
-        remove_all_actions('wp_print_footer_scripts');
495
-        remove_all_actions('wp_enqueue_scripts');
496
-        global $wp_scripts, $wp_styles;
497
-        $wp_scripts = $wp_styles = [];
498
-        // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
499
-        add_action('wp_footer', 'wp_print_footer_scripts');
500
-        add_action('wp_print_footer_scripts', '_wp_footer_scripts');
501
-        add_action('wp_head', 'wp_enqueue_scripts');
502
-    }
503
-
504
-
505
-    /**
506
-     * Overwrite parent _get_main_template for display_html purposes.
507
-     *
508
-     * @param bool $preview
509
-     * @return string
510
-     * @since  4.5.0
511
-     */
512
-    protected function _get_main_template($preview = false): string
513
-    {
514
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name);
515
-        // include message type as a template arg
516
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
517
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
518
-    }
519
-
520
-
521
-    /**
522
-     * @return void
523
-     */
524
-    protected function _preview()
525
-    {
526
-        $this->_send_message();
527
-    }
528
-
529
-
530
-    protected function _set_admin_settings_fields()
531
-    {
532
-    }
533
-
534
-
535
-    /**
536
-     * add the "powered by EE" credit link to the HTML receipt and invoice
537
-     *
538
-     * @param string          $content
539
-     * @param string          $content_again
540
-     * @param EE_message_type $incoming_message_type
541
-     * @return string
542
-     */
543
-    public function add_powered_by_credit_link_to_receipt_and_invoice(
544
-        string $content,
545
-        string $content_again,
546
-        EE_message_type $incoming_message_type
547
-    ): string {
548
-        if (
549
-            ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
550
-            && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
551
-        ) {
552
-            $content .= EEH_Template::powered_by_event_espresso(
553
-                'aln-cntr',
554
-                '',
555
-                ['utm_content' => 'messages_system']
556
-            ) . EEH_HTML::div(EEH_HTML::p('&nbsp;'));
557
-        }
558
-        return $content;
559
-    }
15
+	/**
16
+	 * The following are the properties that this messenger requires for displaying the html
17
+	 */
18
+	/**
19
+	 * This is the html body generated by the template via the message type.
20
+	 *
21
+	 * @var string
22
+	 */
23
+	protected $_content = '';
24
+
25
+	/**
26
+	 * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
27
+	 * equivalent to the "subject" of the page.
28
+	 *
29
+	 * @var string
30
+	 */
31
+	protected $_subject = '';
32
+
33
+
34
+	/**
35
+	 * EE_Html_messenger constructor.
36
+	 */
37
+	public function __construct()
38
+	{
39
+		// set properties
40
+		$this->name                = 'html';
41
+		$this->description         = esc_html__(
42
+			'This messenger outputs a message to a browser for display.',
43
+			'event_espresso'
44
+		);
45
+		$this->label               = [
46
+			'singular' => esc_html__('html', 'event_espresso'),
47
+			'plural'   => esc_html__('html', 'event_espresso'),
48
+		];
49
+		$this->activate_on_install = true;
50
+		// add the "powered by EE" credit link to the HTML receipt and invoice
51
+		add_filter(
52
+			'FHEE__EE_Html_messenger___send_message__main_body',
53
+			[$this, 'add_powered_by_credit_link_to_receipt_and_invoice'],
54
+			10,
55
+			3
56
+		);
57
+		parent::__construct();
58
+	}
59
+
60
+
61
+	/**
62
+	 * HTML Messenger desires execution immediately.
63
+	 *
64
+	 * @return bool
65
+	 * @since  4.9.0
66
+	 * @see    parent::send_now() for documentation.
67
+	 */
68
+	public function send_now(): bool
69
+	{
70
+		return true;
71
+	}
72
+
73
+
74
+	/**
75
+	 * HTML Messenger allows an empty to field.
76
+	 *
77
+	 * @return bool
78
+	 * @since  4.9.0
79
+	 * @see    parent::allow_empty_to_field() for documentation
80
+	 */
81
+	public function allow_empty_to_field(): bool
82
+	{
83
+		return true;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @see abstract declaration in EE_messenger for details.
89
+	 */
90
+	protected function _set_admin_pages()
91
+	{
92
+		$this->admin_registered_pages = ['events_edit' => true];
93
+	}
94
+
95
+
96
+	/**
97
+	 * @see abstract declaration in EE_messenger for details.
98
+	 */
99
+	protected function _set_valid_shortcodes()
100
+	{
101
+		$this->_valid_shortcodes = [];
102
+	}
103
+
104
+
105
+	/**
106
+	 * @see abstract declaration in EE_messenger for details.
107
+	 */
108
+	protected function _set_validator_config()
109
+	{
110
+		$this->_validator_config = [
111
+			'subject'                       => [
112
+				'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'],
113
+			],
114
+			'content'                       => [
115
+				'shortcodes' => [
116
+					'organization',
117
+					'primary_registration_list',
118
+					'primary_registration_details',
119
+					'email',
120
+					'transaction',
121
+					'event_list',
122
+					'payment_list',
123
+					'venue',
124
+					'line_item_list',
125
+					'messenger',
126
+					'ticket_list',
127
+				],
128
+			],
129
+			'event_list'                    => [
130
+				'shortcodes' => [
131
+					'event',
132
+					'ticket_list',
133
+					'venue',
134
+					'primary_registration_details',
135
+					'primary_registration_list',
136
+					'event_author',
137
+				],
138
+				'required'   => ['[EVENT_LIST]'],
139
+			],
140
+			'ticket_list'                   => [
141
+				'shortcodes' => [
142
+					'attendee_list',
143
+					'ticket',
144
+					'datetime_list',
145
+					'primary_registration_details',
146
+					'line_item_list',
147
+					'venue',
148
+				],
149
+				'required'   => ['[TICKET_LIST]'],
150
+			],
151
+			'ticket_line_item_no_pms'       => [
152
+				'shortcodes' => ['line_item', 'ticket'],
153
+				'required'   => ['[TICKET_LINE_ITEM_LIST]'],
154
+			],
155
+			'ticket_line_item_pms'          => [
156
+				'shortcodes' => ['line_item', 'ticket', 'line_item_list'],
157
+				'required'   => ['[TICKET_LINE_ITEM_LIST]'],
158
+			],
159
+			'price_modifier_line_item_list' => [
160
+				'shortcodes' => ['line_item'],
161
+				'required'   => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],
162
+			],
163
+			'datetime_list'                 => [
164
+				'shortcodes' => ['datetime'],
165
+				'required'   => ['[DATETIME_LIST]'],
166
+			],
167
+			'attendee_list'                 => [
168
+				'shortcodes' => ['attendee'],
169
+				'required'   => ['[ATTENDEE_LIST]'],
170
+			],
171
+			'tax_line_item_list'            => [
172
+				'shortcodes' => ['line_item'],
173
+				'required'   => ['[TAX_LINE_ITEM_LIST]'],
174
+			],
175
+			'additional_line_item_list'     => [
176
+				'shortcodes' => ['line_item'],
177
+				'required'   => ['[ADDITIONAL_LINE_ITEM_LIST]'],
178
+			],
179
+			'payment_list'                  => [
180
+				'shortcodes' => ['payment'],
181
+				'required'   => ['[PAYMENT_LIST_*]'],
182
+			],
183
+		];
184
+	}
185
+
186
+
187
+	/**
188
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
189
+	 * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
190
+	 * (i.e. swap out css files or something else).
191
+	 *
192
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
193
+	 * @return void
194
+	 * @since 4.5.0
195
+	 */
196
+	public function do_secondary_messenger_hooks($sending_messenger_name)
197
+	{
198
+		if ($sending_messenger_name === 'pdf') {
199
+			add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8);
200
+		}
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param                            $variation_path
206
+	 * @param EE_Messages_Template_Pack  $template_pack
207
+	 * @param                            $messenger_name
208
+	 * @param                            $message_type_name
209
+	 * @param                            $url
210
+	 * @param                            $type
211
+	 * @param                            $variation
212
+	 * @param                            $skip_filters
213
+	 * @return string
214
+	 */
215
+	public function add_html_css(
216
+		$variation_path,
217
+		EE_Messages_Template_Pack $template_pack,
218
+		$messenger_name,
219
+		$message_type_name,
220
+		$url,
221
+		$type,
222
+		$variation,
223
+		$skip_filters
224
+	): string {
225
+		return $template_pack->get_variation(
226
+			$this->name,
227
+			$message_type_name,
228
+			$type,
229
+			$variation,
230
+			$url,
231
+			'.css',
232
+			$skip_filters
233
+		);
234
+	}
235
+
236
+
237
+	/**
238
+	 * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
239
+	 * messenger can add their own js.
240
+	 *
241
+	 * @return void.
242
+	 */
243
+	public function enqueue_scripts_styles()
244
+	{
245
+		parent::enqueue_scripts_styles();
246
+		do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
247
+	}
248
+
249
+
250
+	/**
251
+	 * _set_template_fields
252
+	 * This sets up the fields that a messenger requires for the message to go out.
253
+	 *
254
+	 * @access  protected
255
+	 * @return void
256
+	 */
257
+	protected function _set_template_fields()
258
+	{
259
+		// any extra template fields that are NOT used by the messenger
260
+		// but will get used by a messenger field for shortcode replacement
261
+		// get added to the 'extra' key in an associated array
262
+		// indexed by the messenger field they relate to.
263
+		// This is important for the Messages_admin to know what fields to display to the user.
264
+		// Also, notice that the "values" are equal to the field type
265
+		// that messages admin will use to know what kind of field to display.
266
+		// The values ALSO have one index labeled "shortcode".
267
+		// The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
268
+		// is required in order for this extra field to be displayed.
269
+		//  If the required shortcode isn't part of the shortcodes array
270
+		// then the field is not needed and will not be displayed/parsed.
271
+		$this->_template_fields = [
272
+			'subject' => [
273
+				'input'      => 'text',
274
+				'label'      => esc_html__('Page Title', 'event_espresso'),
275
+				'type'       => 'string',
276
+				'required'   => true,
277
+				'validation' => true,
278
+				'css_class'  => 'large-text',
279
+				'format'     => '%s',
280
+			],
281
+			'content' => '',
282
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
283
+			'extra'   => [
284
+				'content' => [
285
+					'main'                          => [
286
+						'input'      => 'wp_editor',
287
+						'label'      => esc_html__('Main Content', 'event_espresso'),
288
+						'type'       => 'string',
289
+						'required'   => true,
290
+						'validation' => true,
291
+						'format'     => '%s',
292
+						'rows'       => '15',
293
+					],
294
+					'event_list'                    => [
295
+						'input'               => 'wp_editor',
296
+						'label'               => '[EVENT_LIST]',
297
+						'type'                => 'string',
298
+						'required'            => true,
299
+						'validation'          => true,
300
+						'format'              => '%s',
301
+						'rows'                => '15',
302
+						'shortcodes_required' => ['[EVENT_LIST]'],
303
+					],
304
+					'ticket_list'                   => [
305
+						'input'               => 'textarea',
306
+						'label'               => '[TICKET_LIST]',
307
+						'type'                => 'string',
308
+						'required'            => true,
309
+						'validation'          => true,
310
+						'format'              => '%s',
311
+						'css_class'           => 'large-text',
312
+						'rows'                => '10',
313
+						'shortcodes_required' => ['[TICKET_LIST]'],
314
+					],
315
+					'ticket_line_item_no_pms'       => [
316
+						'input'               => 'textarea',
317
+						'label'               => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(
318
+							'Ticket Line Item List with no Price Modifiers',
319
+							'event_espresso'
320
+						),
321
+						'type'                => 'string',
322
+						'required'            => false,
323
+						'validation'          => true,
324
+						'format'              => '%s',
325
+						'css_class'           => 'large-text',
326
+						'rows'                => '5',
327
+						'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],
328
+					],
329
+					'ticket_line_item_pms'          => [
330
+						'input'               => 'textarea',
331
+						'label'               => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(
332
+							'Ticket Line Item List with Price Modifiers',
333
+							'event_espresso'
334
+						),
335
+						'type'                => 'string',
336
+						'required'            => false,
337
+						'validation'          => true,
338
+						'format'              => '%s',
339
+						'css_class'           => 'large-text',
340
+						'rows'                => '5',
341
+						'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],
342
+					],
343
+					'price_modifier_line_item_list' => [
344
+						'input'               => 'textarea',
345
+						'label'               => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
346
+						'type'                => 'string',
347
+						'required'            => false,
348
+						'validation'          => true,
349
+						'format'              => '%s',
350
+						'css_class'           => 'large-text',
351
+						'rows'                => '5',
352
+						'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],
353
+					],
354
+					'datetime_list'                 => [
355
+						'input'               => 'textarea',
356
+						'label'               => '[DATETIME_LIST]',
357
+						'type'                => 'string',
358
+						'required'            => true,
359
+						'validation'          => true,
360
+						'format'              => '%s',
361
+						'css_class'           => 'large-text',
362
+						'rows'                => '5',
363
+						'shortcodes_required' => ['[DATETIME_LIST]'],
364
+					],
365
+					'attendee_list'                 => [
366
+						'input'               => 'textarea',
367
+						'label'               => '[ATTENDEE_LIST]',
368
+						'type'                => 'string',
369
+						'required'            => true,
370
+						'validation'          => true,
371
+						'format'              => '%s',
372
+						'css_class'           => 'large-text',
373
+						'rows'                => '5',
374
+						'shortcodes_required' => ['[ATTENDEE_LIST]'],
375
+					],
376
+					'tax_line_item_list'            => [
377
+						'input'               => 'textarea',
378
+						'label'               => '[TAX_LINE_ITEM_LIST]',
379
+						'type'                => 'string',
380
+						'required'            => false,
381
+						'validation'          => true,
382
+						'format'              => '%s',
383
+						'css_class'           => 'large-text',
384
+						'rows'                => '5',
385
+						'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'],
386
+					],
387
+					'additional_line_item_list'     => [
388
+						'input'               => 'textarea',
389
+						'label'               => '[ADDITIONAL_LINE_ITEM_LIST]',
390
+						'type'                => 'string',
391
+						'required'            => false,
392
+						'validation'          => true,
393
+						'format'              => '%s',
394
+						'css_class'           => 'large-text',
395
+						'rows'                => '5',
396
+						'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'],
397
+					],
398
+					'payment_list'                  => [
399
+						'input'               => 'textarea',
400
+						'label'               => '[PAYMENT_LIST]',
401
+						'type'                => 'string',
402
+						'required'            => true,
403
+						'validation'          => true,
404
+						'format'              => '%s',
405
+						'css_class'           => 'large-text',
406
+						'rows'                => '5',
407
+						'shortcodes_required' => ['[PAYMENT_LIST_*]'],
408
+					],
409
+				],
410
+			],
411
+		];
412
+	}
413
+
414
+
415
+	/**
416
+	 * @see   definition of this method in parent
417
+	 * @since 4.5.0
418
+	 */
419
+	protected function _set_default_message_types()
420
+	{
421
+		$this->_default_message_types = ['receipt', 'invoice'];
422
+	}
423
+
424
+
425
+	/**
426
+	 * @see   definition of this method in parent
427
+	 * @since 4.5.0
428
+	 */
429
+	protected function _set_valid_message_types()
430
+	{
431
+		$this->_valid_message_types = ['receipt', 'invoice'];
432
+	}
433
+
434
+
435
+	/**
436
+	 * Displays the message in the browser.
437
+	 *
438
+	 * @return void.
439
+	 * @since 4.5.0
440
+	 */
441
+	protected function _send_message()
442
+	{
443
+		$this->_template_args = [
444
+			'page_title' => $this->_subject,
445
+			'base_css'   => $this->get_variation(
446
+				$this->_tmp_pack,
447
+				$this->_incoming_message_type->name,
448
+				true,
449
+				'base',
450
+				$this->_variation
451
+			),
452
+			'print_css'  => $this->get_variation(
453
+				$this->_tmp_pack,
454
+				$this->_incoming_message_type->name,
455
+				true,
456
+				'print',
457
+				$this->_variation
458
+			),
459
+			'main_css'   => $this->get_variation(
460
+				$this->_tmp_pack,
461
+				$this->_incoming_message_type->name,
462
+				true,
463
+				'main',
464
+				$this->_variation
465
+			),
466
+			'main_body'  => wpautop(
467
+				apply_filters(
468
+					'FHEE__EE_Html_messenger___send_message__main_body',
469
+					$this->_content,
470
+					$this->_content,
471
+					$this->_incoming_message_type
472
+				)
473
+			),
474
+		];
475
+		$this->_deregister_wp_hooks();
476
+		add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']);
477
+		echo ($this->_get_main_template());
478
+		exit();
479
+	}
480
+
481
+
482
+	/**
483
+	 * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
484
+	 * interfere with our templates.  If users want to add any custom styles or scripts they must use the
485
+	 * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
486
+	 *
487
+	 * @return void
488
+	 * @since 4.5.0
489
+	 */
490
+	protected function _deregister_wp_hooks()
491
+	{
492
+		remove_all_actions('wp_head');
493
+		remove_all_actions('wp_footer');
494
+		remove_all_actions('wp_print_footer_scripts');
495
+		remove_all_actions('wp_enqueue_scripts');
496
+		global $wp_scripts, $wp_styles;
497
+		$wp_scripts = $wp_styles = [];
498
+		// just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
499
+		add_action('wp_footer', 'wp_print_footer_scripts');
500
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
501
+		add_action('wp_head', 'wp_enqueue_scripts');
502
+	}
503
+
504
+
505
+	/**
506
+	 * Overwrite parent _get_main_template for display_html purposes.
507
+	 *
508
+	 * @param bool $preview
509
+	 * @return string
510
+	 * @since  4.5.0
511
+	 */
512
+	protected function _get_main_template($preview = false): string
513
+	{
514
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name);
515
+		// include message type as a template arg
516
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
517
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
518
+	}
519
+
520
+
521
+	/**
522
+	 * @return void
523
+	 */
524
+	protected function _preview()
525
+	{
526
+		$this->_send_message();
527
+	}
528
+
529
+
530
+	protected function _set_admin_settings_fields()
531
+	{
532
+	}
533
+
534
+
535
+	/**
536
+	 * add the "powered by EE" credit link to the HTML receipt and invoice
537
+	 *
538
+	 * @param string          $content
539
+	 * @param string          $content_again
540
+	 * @param EE_message_type $incoming_message_type
541
+	 * @return string
542
+	 */
543
+	public function add_powered_by_credit_link_to_receipt_and_invoice(
544
+		string $content,
545
+		string $content_again,
546
+		EE_message_type $incoming_message_type
547
+	): string {
548
+		if (
549
+			($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
550
+			&& apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
551
+		) {
552
+			$content .= EEH_Template::powered_by_event_espresso(
553
+				'aln-cntr',
554
+				'',
555
+				['utm_content' => 'messages_system']
556
+			) . EEH_HTML::div(EEH_HTML::p('&nbsp;'));
557
+		}
558
+		return $content;
559
+	}
560 560
 }
Please login to merge, or discard this patch.
core/libraries/iframe_display/Iframe.php 1 patch
Indentation   +334 added lines, -334 removed lines patch added patch discarded remove patch
@@ -18,373 +18,373 @@
 block discarded – undo
18 18
  */
19 19
 class Iframe
20 20
 {
21
-    /*
21
+	/*
22 22
     * HTML for notices and ajax gif
23 23
     * @var string $title
24 24
     */
25
-    protected $title = '';
25
+	protected $title = '';
26 26
 
27
-    /*
27
+	/*
28 28
     * HTML for the content being displayed
29 29
     * @var string $content
30 30
     */
31
-    protected $content = '';
31
+	protected $content = '';
32 32
 
33
-    /*
33
+	/*
34 34
     * whether or not to call wp_head() and wp_footer()
35 35
     * @var boolean $enqueue_wp_assets
36 36
     */
37
-    protected $enqueue_wp_assets = false;
37
+	protected $enqueue_wp_assets = false;
38 38
 
39
-    /*
39
+	/*
40 40
     * an array of CSS URLs
41 41
     * @var array $css
42 42
     */
43
-    protected $css = array();
43
+	protected $css = array();
44 44
 
45
-    /*
45
+	/*
46 46
     * an array of JS URLs to be set in the HTML header.
47 47
     * @var array $header_js
48 48
     */
49
-    protected $header_js = array();
49
+	protected $header_js = array();
50 50
 
51
-    /*
51
+	/*
52 52
     * an array of additional attributes to be added to <script> tags for header JS
53 53
     * @var array $footer_js
54 54
     */
55
-    protected $header_js_attributes = array();
55
+	protected $header_js_attributes = array();
56 56
 
57
-    /*
57
+	/*
58 58
     * an array of JS URLs to be displayed before the HTML </body> tag
59 59
     * @var array $footer_js
60 60
     */
61
-    protected $footer_js = array();
61
+	protected $footer_js = array();
62 62
 
63
-    /*
63
+	/*
64 64
     * an array of additional attributes to be added to <script> tags for footer JS
65 65
     * @var array $footer_js_attributes
66 66
     */
67
-    protected $footer_js_attributes = array();
67
+	protected $footer_js_attributes = array();
68 68
 
69
-    /*
69
+	/*
70 70
     * an array of JSON vars to be set in the HTML header.
71 71
     * @var array $localized_vars
72 72
     */
73
-    protected $localized_vars = array();
74
-
75
-
76
-    /**
77
-     * Iframe constructor
78
-     *
79
-     * @param string $title
80
-     * @param string $content
81
-     * @throws DomainException
82
-     */
83
-    public function __construct($title, $content)
84
-    {
85
-        global $wp_version;
86
-        if (! defined('EE_IFRAME_DIR_URL')) {
87
-            define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__));
88
-        }
89
-        $this->setContent($content);
90
-        $this->setTitle($title);
91
-        $this->addStylesheets(
92
-            apply_filters(
93
-                'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css',
94
-                array(
95
-                    'site_theme'       => get_stylesheet_directory_uri()
96
-                                          . '/style.css?ver=' . EVENT_ESPRESSO_VERSION,
97
-                    'dashicons'        => includes_url('css/dashicons.min.css?ver=' . $wp_version),
98
-                    'espresso_default' => EE_GLOBAL_ASSETS_URL
99
-                                          . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
100
-                ),
101
-                $this
102
-            )
103
-        );
104
-        $this->addScripts(
105
-            apply_filters(
106
-                'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js',
107
-                array(
108
-                    'jquery'        => includes_url('js/jquery/jquery.js?ver=' . $wp_version),
109
-                    'espresso_core' => EE_GLOBAL_ASSETS_URL
110
-                                       . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
111
-                ),
112
-                $this
113
-            )
114
-        );
115
-        if (
116
-            apply_filters(
117
-                'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet',
118
-                false
119
-            )
120
-        ) {
121
-            $this->addStylesheets(
122
-                apply_filters(
123
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet',
124
-                    array('default_theme_stylesheet' => get_stylesheet_uri()),
125
-                    $this
126
-                )
127
-            );
128
-        }
129
-    }
130
-
131
-
132
-    /**
133
-     * @param string $title
134
-     * @throws DomainException
135
-     */
136
-    public function setTitle($title)
137
-    {
138
-        if (empty($title)) {
139
-            throw new DomainException(
140
-                esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso')
141
-            );
142
-        }
143
-        $this->title = $title;
144
-    }
145
-
146
-
147
-    /**
148
-     * @param string $content
149
-     * @throws DomainException
150
-     */
151
-    public function setContent($content)
152
-    {
153
-        if (empty($content)) {
154
-            throw new DomainException(
155
-                esc_html__('You must provide content in order to create an iframe.', 'event_espresso')
156
-            );
157
-        }
158
-        $this->content = $content;
159
-    }
160
-
161
-
162
-    /**
163
-     * @param boolean $enqueue_wp_assets
164
-     */
165
-    public function setEnqueueWpAssets($enqueue_wp_assets)
166
-    {
167
-        $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN);
168
-    }
169
-
170
-
171
-    /**
172
-     * @param array $stylesheets
173
-     * @throws DomainException
174
-     */
175
-    public function addStylesheets(array $stylesheets)
176
-    {
177
-        if (empty($stylesheets)) {
178
-            throw new DomainException(
179
-                esc_html__(
180
-                    'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.',
181
-                    'event_espresso'
182
-                )
183
-            );
184
-        }
185
-        foreach ($stylesheets as $handle => $stylesheet) {
186
-            $this->css[ $handle ] = $stylesheet;
187
-        }
188
-    }
189
-
190
-
191
-    /**
192
-     * @param array $scripts
193
-     * @param bool  $add_to_header
194
-     * @throws DomainException
195
-     */
196
-    public function addScripts(array $scripts, $add_to_header = false)
197
-    {
198
-        if (empty($scripts)) {
199
-            throw new DomainException(
200
-                esc_html__(
201
-                    'A non-empty array of URLs, is required to add Javascript to an iframe.',
202
-                    'event_espresso'
203
-                )
204
-            );
205
-        }
206
-        foreach ($scripts as $handle => $script) {
207
-            if ($add_to_header) {
208
-                $this->header_js[ $handle ] = $script;
209
-            } else {
210
-                $this->footer_js[ $handle ] = $script;
211
-            }
212
-        }
213
-    }
214
-
215
-
216
-    /**
217
-     * @param array $script_attributes
218
-     * @param bool  $add_to_header
219
-     * @throws DomainException
220
-     */
221
-    public function addScriptAttributes(array $script_attributes, $add_to_header = false)
222
-    {
223
-        if (empty($script_attributes)) {
224
-            throw new DomainException(
225
-                esc_html__(
226
-                    'A non-empty array of strings, is required to add attributes to iframe Javascript.',
227
-                    'event_espresso'
228
-                )
229
-            );
230
-        }
231
-        foreach ($script_attributes as $handle => $script_attribute) {
232
-            if ($add_to_header) {
233
-                $this->header_js_attributes[ $handle ] = $script_attribute;
234
-            } else {
235
-                $this->footer_js_attributes[ $handle ] = $script_attribute;
236
-            }
237
-        }
238
-    }
239
-
240
-
241
-    /**
242
-     * @param array  $vars
243
-     * @param string $var_name
244
-     * @throws DomainException
245
-     */
246
-    public function addLocalizedVars(array $vars, $var_name = 'eei18n')
247
-    {
248
-        if (empty($vars)) {
249
-            throw new DomainException(
250
-                esc_html__(
251
-                    'A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
252
-                    'event_espresso'
253
-                )
254
-            );
255
-        }
256
-        foreach ($vars as $handle => $var) {
257
-            if ($var_name === 'eei18n') {
258
-                EE_Registry::$i18n_js_strings[ $handle ] = $var;
259
-            } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
260
-                $this->localized_vars[ $var_name ] = $var;
261
-            } else {
262
-                if (! isset($this->localized_vars[ $var_name ])) {
263
-                    $this->localized_vars[ $var_name ] = array();
264
-                }
265
-                $this->localized_vars[ $var_name ][ $handle ] = $var;
266
-            }
267
-        }
268
-    }
269
-
270
-
271
-    /**
272
-     * @param string $utm_content
273
-     * @throws DomainException
274
-     */
275
-    public function display($utm_content = '')
276
-    {
277
-        $this->content .= EEH_Template::powered_by_event_espresso(
278
-            '',
279
-            '',
280
-            ! empty($utm_content) ? array('utm_content' => $utm_content) : array()
281
-        );
282
-        EE_System::do_not_cache();
283
-        echo ($this->getTemplate());
284
-        exit;
285
-    }
286
-
287
-
288
-    /**
289
-     * @return string
290
-     * @throws DomainException
291
-     */
292
-    public function getTemplate()
293
-    {
294
-        return EEH_Template::display_template(
295
-            __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php',
296
-            array(
297
-                'title'                => apply_filters(
298
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title',
299
-                    $this->title,
300
-                    $this
301
-                ),
302
-                'content'              => apply_filters(
303
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content',
304
-                    $this->content,
305
-                    $this
306
-                ),
307
-                'enqueue_wp_assets'    => apply_filters(
308
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets',
309
-                    $this->enqueue_wp_assets,
310
-                    $this
311
-                ),
312
-                'css'                  => (array) apply_filters(
313
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
314
-                    $this->css,
315
-                    $this
316
-                ),
317
-                'header_js'            => (array) apply_filters(
318
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
319
-                    $this->header_js,
320
-                    $this
321
-                ),
322
-                'header_js_attributes' => (array) apply_filters(
323
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes',
324
-                    $this->header_js_attributes,
325
-                    $this
326
-                ),
327
-                'footer_js'            => (array) apply_filters(
328
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
329
-                    $this->footer_js,
330
-                    $this
331
-                ),
332
-                'footer_js_attributes' => (array) apply_filters(
333
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
334
-                    $this->footer_js_attributes,
335
-                    $this
336
-                ),
337
-                'eei18n'               => apply_filters(
338
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings',
339
-                    EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(),
340
-                    $this
341
-                ),
342
-                'notices'              => EEH_Template::display_template(
343
-                    EE_TEMPLATES . 'espresso-ajax-notices.template.php',
344
-                    array(),
345
-                    true
346
-                ),
347
-            ),
348
-            true,
349
-            true
350
-        );
351
-    }
352
-
353
-
354
-    /**
355
-     * localizeJsonVars
356
-     *
357
-     * @return string
358
-     */
359
-    public function localizeJsonVars()
360
-    {
361
-        $JSON = '';
362
-        foreach ($this->localized_vars as $var_name => $vars) {
363
-            $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars);
364
-            $JSON .= "/* <![CDATA[ */ var {$var_name} = ";
365
-            $JSON .= wp_json_encode($this->localized_vars[ $var_name ]);
366
-            $JSON .= '; /* ]]> */';
367
-        }
368
-        return $JSON;
369
-    }
370
-
371
-
372
-    /**
373
-     * @param bool|int|float|string|array $var
374
-     * @return array|string|null
375
-     */
376
-    public function encodeJsonVars($var)
377
-    {
378
-        if (is_array($var)) {
379
-            $localized_vars = array();
380
-            foreach ((array) $var as $key => $value) {
381
-                $localized_vars[ $key ] = $this->encodeJsonVars($value);
382
-            }
383
-            return $localized_vars;
384
-        }
385
-        if (is_scalar($var)) {
386
-            return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8');
387
-        }
388
-        return null;
389
-    }
73
+	protected $localized_vars = array();
74
+
75
+
76
+	/**
77
+	 * Iframe constructor
78
+	 *
79
+	 * @param string $title
80
+	 * @param string $content
81
+	 * @throws DomainException
82
+	 */
83
+	public function __construct($title, $content)
84
+	{
85
+		global $wp_version;
86
+		if (! defined('EE_IFRAME_DIR_URL')) {
87
+			define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__));
88
+		}
89
+		$this->setContent($content);
90
+		$this->setTitle($title);
91
+		$this->addStylesheets(
92
+			apply_filters(
93
+				'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css',
94
+				array(
95
+					'site_theme'       => get_stylesheet_directory_uri()
96
+										  . '/style.css?ver=' . EVENT_ESPRESSO_VERSION,
97
+					'dashicons'        => includes_url('css/dashicons.min.css?ver=' . $wp_version),
98
+					'espresso_default' => EE_GLOBAL_ASSETS_URL
99
+										  . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
100
+				),
101
+				$this
102
+			)
103
+		);
104
+		$this->addScripts(
105
+			apply_filters(
106
+				'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js',
107
+				array(
108
+					'jquery'        => includes_url('js/jquery/jquery.js?ver=' . $wp_version),
109
+					'espresso_core' => EE_GLOBAL_ASSETS_URL
110
+									   . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
111
+				),
112
+				$this
113
+			)
114
+		);
115
+		if (
116
+			apply_filters(
117
+				'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet',
118
+				false
119
+			)
120
+		) {
121
+			$this->addStylesheets(
122
+				apply_filters(
123
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet',
124
+					array('default_theme_stylesheet' => get_stylesheet_uri()),
125
+					$this
126
+				)
127
+			);
128
+		}
129
+	}
130
+
131
+
132
+	/**
133
+	 * @param string $title
134
+	 * @throws DomainException
135
+	 */
136
+	public function setTitle($title)
137
+	{
138
+		if (empty($title)) {
139
+			throw new DomainException(
140
+				esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso')
141
+			);
142
+		}
143
+		$this->title = $title;
144
+	}
145
+
146
+
147
+	/**
148
+	 * @param string $content
149
+	 * @throws DomainException
150
+	 */
151
+	public function setContent($content)
152
+	{
153
+		if (empty($content)) {
154
+			throw new DomainException(
155
+				esc_html__('You must provide content in order to create an iframe.', 'event_espresso')
156
+			);
157
+		}
158
+		$this->content = $content;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @param boolean $enqueue_wp_assets
164
+	 */
165
+	public function setEnqueueWpAssets($enqueue_wp_assets)
166
+	{
167
+		$this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN);
168
+	}
169
+
170
+
171
+	/**
172
+	 * @param array $stylesheets
173
+	 * @throws DomainException
174
+	 */
175
+	public function addStylesheets(array $stylesheets)
176
+	{
177
+		if (empty($stylesheets)) {
178
+			throw new DomainException(
179
+				esc_html__(
180
+					'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.',
181
+					'event_espresso'
182
+				)
183
+			);
184
+		}
185
+		foreach ($stylesheets as $handle => $stylesheet) {
186
+			$this->css[ $handle ] = $stylesheet;
187
+		}
188
+	}
189
+
190
+
191
+	/**
192
+	 * @param array $scripts
193
+	 * @param bool  $add_to_header
194
+	 * @throws DomainException
195
+	 */
196
+	public function addScripts(array $scripts, $add_to_header = false)
197
+	{
198
+		if (empty($scripts)) {
199
+			throw new DomainException(
200
+				esc_html__(
201
+					'A non-empty array of URLs, is required to add Javascript to an iframe.',
202
+					'event_espresso'
203
+				)
204
+			);
205
+		}
206
+		foreach ($scripts as $handle => $script) {
207
+			if ($add_to_header) {
208
+				$this->header_js[ $handle ] = $script;
209
+			} else {
210
+				$this->footer_js[ $handle ] = $script;
211
+			}
212
+		}
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param array $script_attributes
218
+	 * @param bool  $add_to_header
219
+	 * @throws DomainException
220
+	 */
221
+	public function addScriptAttributes(array $script_attributes, $add_to_header = false)
222
+	{
223
+		if (empty($script_attributes)) {
224
+			throw new DomainException(
225
+				esc_html__(
226
+					'A non-empty array of strings, is required to add attributes to iframe Javascript.',
227
+					'event_espresso'
228
+				)
229
+			);
230
+		}
231
+		foreach ($script_attributes as $handle => $script_attribute) {
232
+			if ($add_to_header) {
233
+				$this->header_js_attributes[ $handle ] = $script_attribute;
234
+			} else {
235
+				$this->footer_js_attributes[ $handle ] = $script_attribute;
236
+			}
237
+		}
238
+	}
239
+
240
+
241
+	/**
242
+	 * @param array  $vars
243
+	 * @param string $var_name
244
+	 * @throws DomainException
245
+	 */
246
+	public function addLocalizedVars(array $vars, $var_name = 'eei18n')
247
+	{
248
+		if (empty($vars)) {
249
+			throw new DomainException(
250
+				esc_html__(
251
+					'A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
252
+					'event_espresso'
253
+				)
254
+			);
255
+		}
256
+		foreach ($vars as $handle => $var) {
257
+			if ($var_name === 'eei18n') {
258
+				EE_Registry::$i18n_js_strings[ $handle ] = $var;
259
+			} elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
260
+				$this->localized_vars[ $var_name ] = $var;
261
+			} else {
262
+				if (! isset($this->localized_vars[ $var_name ])) {
263
+					$this->localized_vars[ $var_name ] = array();
264
+				}
265
+				$this->localized_vars[ $var_name ][ $handle ] = $var;
266
+			}
267
+		}
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param string $utm_content
273
+	 * @throws DomainException
274
+	 */
275
+	public function display($utm_content = '')
276
+	{
277
+		$this->content .= EEH_Template::powered_by_event_espresso(
278
+			'',
279
+			'',
280
+			! empty($utm_content) ? array('utm_content' => $utm_content) : array()
281
+		);
282
+		EE_System::do_not_cache();
283
+		echo ($this->getTemplate());
284
+		exit;
285
+	}
286
+
287
+
288
+	/**
289
+	 * @return string
290
+	 * @throws DomainException
291
+	 */
292
+	public function getTemplate()
293
+	{
294
+		return EEH_Template::display_template(
295
+			__DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php',
296
+			array(
297
+				'title'                => apply_filters(
298
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title',
299
+					$this->title,
300
+					$this
301
+				),
302
+				'content'              => apply_filters(
303
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content',
304
+					$this->content,
305
+					$this
306
+				),
307
+				'enqueue_wp_assets'    => apply_filters(
308
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets',
309
+					$this->enqueue_wp_assets,
310
+					$this
311
+				),
312
+				'css'                  => (array) apply_filters(
313
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
314
+					$this->css,
315
+					$this
316
+				),
317
+				'header_js'            => (array) apply_filters(
318
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
319
+					$this->header_js,
320
+					$this
321
+				),
322
+				'header_js_attributes' => (array) apply_filters(
323
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes',
324
+					$this->header_js_attributes,
325
+					$this
326
+				),
327
+				'footer_js'            => (array) apply_filters(
328
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
329
+					$this->footer_js,
330
+					$this
331
+				),
332
+				'footer_js_attributes' => (array) apply_filters(
333
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
334
+					$this->footer_js_attributes,
335
+					$this
336
+				),
337
+				'eei18n'               => apply_filters(
338
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings',
339
+					EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(),
340
+					$this
341
+				),
342
+				'notices'              => EEH_Template::display_template(
343
+					EE_TEMPLATES . 'espresso-ajax-notices.template.php',
344
+					array(),
345
+					true
346
+				),
347
+			),
348
+			true,
349
+			true
350
+		);
351
+	}
352
+
353
+
354
+	/**
355
+	 * localizeJsonVars
356
+	 *
357
+	 * @return string
358
+	 */
359
+	public function localizeJsonVars()
360
+	{
361
+		$JSON = '';
362
+		foreach ($this->localized_vars as $var_name => $vars) {
363
+			$this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars);
364
+			$JSON .= "/* <![CDATA[ */ var {$var_name} = ";
365
+			$JSON .= wp_json_encode($this->localized_vars[ $var_name ]);
366
+			$JSON .= '; /* ]]> */';
367
+		}
368
+		return $JSON;
369
+	}
370
+
371
+
372
+	/**
373
+	 * @param bool|int|float|string|array $var
374
+	 * @return array|string|null
375
+	 */
376
+	public function encodeJsonVars($var)
377
+	{
378
+		if (is_array($var)) {
379
+			$localized_vars = array();
380
+			foreach ((array) $var as $key => $value) {
381
+				$localized_vars[ $key ] = $this->encodeJsonVars($value);
382
+			}
383
+			return $localized_vars;
384
+		}
385
+		if (is_scalar($var)) {
386
+			return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8');
387
+		}
388
+		return null;
389
+	}
390 390
 }
Please login to merge, or discard this patch.
core/libraries/iframe_display/iframe_wrapper.template.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
                 <?php echo ($eei18n); ?>
37 37
             </script>
38 38
         <?php foreach ($header_js as $key => $url) :?>
39
-            <?php $header_attributes = isset($header_js_attributes[ $key ]) ? $header_js_attributes[ $key ] : ''; ?>
39
+            <?php $header_attributes = isset($header_js_attributes[$key]) ? $header_js_attributes[$key] : ''; ?>
40 40
         <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($header_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script>
41 41
         <?php endforeach; ?>
42 42
     <?php endif; ?>
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     <?php echo wp_kses($content, AllowedTags::getWithFullTags()); ?>
48 48
 </div>
49 49
 <?php foreach ($footer_js as $key => $url) : ?>
50
-    <?php $footer_attributes = isset($footer_js_attributes[ $key ]) ? $footer_js_attributes[ $key ] : ''; ?>
50
+    <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[$key] : ''; ?>
51 51
     <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($footer_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script>
52 52
 <?php endforeach; ?>
53 53
 <?php if ($enqueue_wp_assets) : ?>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,9 +28,12 @@
 block discarded – undo
28 28
     <title><?php echo wp_strip_all_tags($title); ?></title>
29 29
     <?php if ($enqueue_wp_assets) : ?>
30 30
         <?php wp_head(); ?>
31
-    <?php else : ?>
31
+    <?php else {
32
+	: ?>
32 33
         <?php foreach ($css as $url) :?>
33
-    <link rel="stylesheet" type="text/css" href="<?php echo esc_url_raw($url); ?>">
34
+    <link rel="stylesheet" type="text/css" href="<?php echo esc_url_raw($url);
35
+}
36
+?>">
34 37
         <?php endforeach; ?>
35 38
             <script type="text/javascript">
36 39
                 <?php echo ($eei18n); ?>
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2799 added lines, -2799 removed lines patch added patch discarded remove patch
@@ -15,2806 +15,2806 @@
 block discarded – undo
15 15
  */
16 16
 class Events_Admin_Page extends EE_Admin_Page_CPT
17 17
 {
18
-    /**
19
-     * This will hold the event object for event_details screen.
18
+	/**
19
+	 * This will hold the event object for event_details screen.
20
+	 *
21
+	 * @var EE_Event $_event
22
+	 */
23
+	protected $_event;
24
+
25
+
26
+	/**
27
+	 * This will hold the category object for category_details screen.
28
+	 *
29
+	 * @var stdClass $_category
30
+	 */
31
+	protected $_category;
32
+
33
+
34
+	/**
35
+	 * This will hold the event model instance
36
+	 *
37
+	 * @var EEM_Event $_event_model
38
+	 */
39
+	protected $_event_model;
40
+
41
+
42
+	/**
43
+	 * @var EE_Event
44
+	 */
45
+	protected $_cpt_model_obj = false;
46
+
47
+
48
+	/**
49
+	 * @var NodeGroupDao
50
+	 */
51
+	protected $model_obj_node_group_persister;
52
+
53
+
54
+	/**
55
+	 * Initialize page props for this admin page group.
56
+	 */
57
+	protected function _init_page_props()
58
+	{
59
+		$this->page_slug        = EVENTS_PG_SLUG;
60
+		$this->page_label       = EVENTS_LABEL;
61
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
62
+		$this->_admin_base_path = EVENTS_ADMIN;
63
+		$this->_cpt_model_names = [
64
+			'create_new' => 'EEM_Event',
65
+			'edit'       => 'EEM_Event',
66
+		];
67
+		$this->_cpt_edit_routes = [
68
+			'espresso_events' => 'edit',
69
+		];
70
+		add_action(
71
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
72
+			[$this, 'verify_event_edit'],
73
+			10,
74
+			2
75
+		);
76
+	}
77
+
78
+
79
+	/**
80
+	 * Sets the ajax hooks used for this admin page group.
81
+	 */
82
+	protected function _ajax_hooks()
83
+	{
84
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
85
+	}
86
+
87
+
88
+	/**
89
+	 * Sets the page properties for this admin page group.
90
+	 */
91
+	protected function _define_page_props()
92
+	{
93
+		$this->_admin_page_title = EVENTS_LABEL;
94
+		$this->_labels           = [
95
+			'buttons'      => [
96
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
97
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
98
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
99
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
100
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
101
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
102
+			],
103
+			'editor_title' => [
104
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
105
+			],
106
+			'publishbox'   => [
107
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
108
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
109
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
110
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
111
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
112
+			],
113
+		];
114
+	}
115
+
116
+
117
+	/**
118
+	 * Sets the page routes property for this admin page group.
119
+	 */
120
+	protected function _set_page_routes()
121
+	{
122
+		// load formatter helper
123
+		// load field generator helper
124
+		// is there a evt_id in the request?
125
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
126
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
127
+
128
+		$this->_page_routes = [
129
+			'default'                       => [
130
+				'func'       => '_events_overview_list_table',
131
+				'capability' => 'ee_read_events',
132
+			],
133
+			'create_new'                    => [
134
+				'func'       => '_create_new_cpt_item',
135
+				'capability' => 'ee_edit_events',
136
+			],
137
+			'edit'                          => [
138
+				'func'       => '_edit_cpt_item',
139
+				'capability' => 'ee_edit_event',
140
+				'obj_id'     => $EVT_ID,
141
+			],
142
+			'copy_event'                    => [
143
+				'func'       => '_copy_events',
144
+				'capability' => 'ee_edit_event',
145
+				'obj_id'     => $EVT_ID,
146
+				'noheader'   => true,
147
+			],
148
+			'trash_event'                   => [
149
+				'func'       => '_trash_or_restore_event',
150
+				'args'       => ['event_status' => 'trash'],
151
+				'capability' => 'ee_delete_event',
152
+				'obj_id'     => $EVT_ID,
153
+				'noheader'   => true,
154
+			],
155
+			'trash_events'                  => [
156
+				'func'       => '_trash_or_restore_events',
157
+				'args'       => ['event_status' => 'trash'],
158
+				'capability' => 'ee_delete_events',
159
+				'noheader'   => true,
160
+			],
161
+			'restore_event'                 => [
162
+				'func'       => '_trash_or_restore_event',
163
+				'args'       => ['event_status' => 'draft'],
164
+				'capability' => 'ee_delete_event',
165
+				'obj_id'     => $EVT_ID,
166
+				'noheader'   => true,
167
+			],
168
+			'restore_events'                => [
169
+				'func'       => '_trash_or_restore_events',
170
+				'args'       => ['event_status' => 'draft'],
171
+				'capability' => 'ee_delete_events',
172
+				'noheader'   => true,
173
+			],
174
+			'delete_event'                  => [
175
+				'func'       => '_delete_event',
176
+				'capability' => 'ee_delete_event',
177
+				'obj_id'     => $EVT_ID,
178
+				'noheader'   => true,
179
+			],
180
+			'delete_events'                 => [
181
+				'func'       => '_delete_events',
182
+				'capability' => 'ee_delete_events',
183
+				'noheader'   => true,
184
+			],
185
+			'view_report'                   => [
186
+				'func'       => '_view_report',
187
+				'capability' => 'ee_edit_events',
188
+			],
189
+			'default_event_settings'        => [
190
+				'func'       => '_default_event_settings',
191
+				'capability' => 'manage_options',
192
+			],
193
+			'update_default_event_settings' => [
194
+				'func'       => '_update_default_event_settings',
195
+				'capability' => 'manage_options',
196
+				'noheader'   => true,
197
+			],
198
+			'template_settings'             => [
199
+				'func'       => '_template_settings',
200
+				'capability' => 'manage_options',
201
+			],
202
+			// event category tab related
203
+			'add_category'                  => [
204
+				'func'       => '_category_details',
205
+				'capability' => 'ee_edit_event_category',
206
+				'args'       => ['add'],
207
+			],
208
+			'edit_category'                 => [
209
+				'func'       => '_category_details',
210
+				'capability' => 'ee_edit_event_category',
211
+				'args'       => ['edit'],
212
+			],
213
+			'delete_categories'             => [
214
+				'func'       => '_delete_categories',
215
+				'capability' => 'ee_delete_event_category',
216
+				'noheader'   => true,
217
+			],
218
+			'delete_category'               => [
219
+				'func'       => '_delete_categories',
220
+				'capability' => 'ee_delete_event_category',
221
+				'noheader'   => true,
222
+			],
223
+			'insert_category'               => [
224
+				'func'       => '_insert_or_update_category',
225
+				'args'       => ['new_category' => true],
226
+				'capability' => 'ee_edit_event_category',
227
+				'noheader'   => true,
228
+			],
229
+			'update_category'               => [
230
+				'func'       => '_insert_or_update_category',
231
+				'args'       => ['new_category' => false],
232
+				'capability' => 'ee_edit_event_category',
233
+				'noheader'   => true,
234
+			],
235
+			'category_list'                 => [
236
+				'func'       => '_category_list_table',
237
+				'capability' => 'ee_manage_event_categories',
238
+			],
239
+			'preview_deletion'              => [
240
+				'func'       => 'previewDeletion',
241
+				'capability' => 'ee_delete_events',
242
+			],
243
+			'confirm_deletion'              => [
244
+				'func'       => 'confirmDeletion',
245
+				'capability' => 'ee_delete_events',
246
+				'noheader'   => true,
247
+			],
248
+		];
249
+	}
250
+
251
+
252
+	/**
253
+	 * Set the _page_config property for this admin page group.
254
+	 */
255
+	protected function _set_page_config()
256
+	{
257
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
258
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
259
+		$this->_page_config = [
260
+			'default'                => [
261
+				'nav'           => [
262
+					'label' => esc_html__('Overview', 'event_espresso'),
263
+					'order' => 10,
264
+				],
265
+				'list_table'    => 'Events_Admin_List_Table',
266
+				'help_tabs'     => [
267
+					'events_overview_help_tab'                       => [
268
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
269
+						'filename' => 'events_overview',
270
+					],
271
+					'events_overview_table_column_headings_help_tab' => [
272
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
273
+						'filename' => 'events_overview_table_column_headings',
274
+					],
275
+					'events_overview_filters_help_tab'               => [
276
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
277
+						'filename' => 'events_overview_filters',
278
+					],
279
+					'events_overview_view_help_tab'                  => [
280
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
281
+						'filename' => 'events_overview_views',
282
+					],
283
+					'events_overview_other_help_tab'                 => [
284
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
285
+						'filename' => 'events_overview_other',
286
+					],
287
+				],
288
+				'qtips'         => [
289
+					'EE_Event_List_Table_Tips',
290
+				],
291
+				'require_nonce' => false,
292
+			],
293
+			'create_new'             => [
294
+				'nav'           => [
295
+					'label'      => esc_html__('Add Event', 'event_espresso'),
296
+					'order'      => 5,
297
+					'persistent' => false,
298
+				],
299
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
300
+				'help_tabs'     => [
301
+					'event_editor_help_tab'                            => [
302
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
303
+						'filename' => 'event_editor',
304
+					],
305
+					'event_editor_title_richtexteditor_help_tab'       => [
306
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
307
+						'filename' => 'event_editor_title_richtexteditor',
308
+					],
309
+					'event_editor_venue_details_help_tab'              => [
310
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
311
+						'filename' => 'event_editor_venue_details',
312
+					],
313
+					'event_editor_event_datetimes_help_tab'            => [
314
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
315
+						'filename' => 'event_editor_event_datetimes',
316
+					],
317
+					'event_editor_event_tickets_help_tab'              => [
318
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
319
+						'filename' => 'event_editor_event_tickets',
320
+					],
321
+					'event_editor_event_registration_options_help_tab' => [
322
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
323
+						'filename' => 'event_editor_event_registration_options',
324
+					],
325
+					'event_editor_tags_categories_help_tab'            => [
326
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
327
+						'filename' => 'event_editor_tags_categories',
328
+					],
329
+					'event_editor_questions_registrants_help_tab'      => [
330
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
331
+						'filename' => 'event_editor_questions_registrants',
332
+					],
333
+					'event_editor_save_new_event_help_tab'             => [
334
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
335
+						'filename' => 'event_editor_save_new_event',
336
+					],
337
+					'event_editor_other_help_tab'                      => [
338
+						'title'    => esc_html__('Event Other', 'event_espresso'),
339
+						'filename' => 'event_editor_other',
340
+					],
341
+				],
342
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
343
+				'require_nonce' => false,
344
+			],
345
+			'edit'                   => [
346
+				'nav'           => [
347
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
348
+					'order'      => 5,
349
+					'persistent' => false,
350
+					'url'        => $post_id
351
+						? EE_Admin_Page::add_query_args_and_nonce(
352
+							['post' => $post_id, 'action' => 'edit'],
353
+							$this->_current_page_view_url
354
+						)
355
+						: $this->_admin_base_url,
356
+				],
357
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
358
+				'help_tabs'     => [
359
+					'event_editor_help_tab'                            => [
360
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
361
+						'filename' => 'event_editor',
362
+					],
363
+					'event_editor_title_richtexteditor_help_tab'       => [
364
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
365
+						'filename' => 'event_editor_title_richtexteditor',
366
+					],
367
+					'event_editor_venue_details_help_tab'              => [
368
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
369
+						'filename' => 'event_editor_venue_details',
370
+					],
371
+					'event_editor_event_datetimes_help_tab'            => [
372
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
373
+						'filename' => 'event_editor_event_datetimes',
374
+					],
375
+					'event_editor_event_tickets_help_tab'              => [
376
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
377
+						'filename' => 'event_editor_event_tickets',
378
+					],
379
+					'event_editor_event_registration_options_help_tab' => [
380
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
381
+						'filename' => 'event_editor_event_registration_options',
382
+					],
383
+					'event_editor_tags_categories_help_tab'            => [
384
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
385
+						'filename' => 'event_editor_tags_categories',
386
+					],
387
+					'event_editor_questions_registrants_help_tab'      => [
388
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
389
+						'filename' => 'event_editor_questions_registrants',
390
+					],
391
+					'event_editor_save_new_event_help_tab'             => [
392
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
393
+						'filename' => 'event_editor_save_new_event',
394
+					],
395
+					'event_editor_other_help_tab'                      => [
396
+						'title'    => esc_html__('Event Other', 'event_espresso'),
397
+						'filename' => 'event_editor_other',
398
+					],
399
+				],
400
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
401
+				'require_nonce' => false,
402
+			],
403
+			'default_event_settings' => [
404
+				'nav'           => [
405
+					'label' => esc_html__('Default Settings', 'event_espresso'),
406
+					'order' => 40,
407
+				],
408
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
409
+				'labels'        => [
410
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
411
+				],
412
+				'help_tabs'     => [
413
+					'default_settings_help_tab'        => [
414
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
415
+						'filename' => 'events_default_settings',
416
+					],
417
+					'default_settings_status_help_tab' => [
418
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
419
+						'filename' => 'events_default_settings_status',
420
+					],
421
+					'default_maximum_tickets_help_tab' => [
422
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
423
+						'filename' => 'events_default_settings_max_tickets',
424
+					],
425
+				],
426
+				'require_nonce' => false,
427
+			],
428
+			// template settings
429
+			'template_settings'      => [
430
+				'nav'           => [
431
+					'label' => esc_html__('Templates', 'event_espresso'),
432
+					'order' => 30,
433
+				],
434
+				'metaboxes'     => $this->_default_espresso_metaboxes,
435
+				'help_tabs'     => [
436
+					'general_settings_templates_help_tab' => [
437
+						'title'    => esc_html__('Templates', 'event_espresso'),
438
+						'filename' => 'general_settings_templates',
439
+					],
440
+				],
441
+				'require_nonce' => false,
442
+			],
443
+			// event category stuff
444
+			'add_category'           => [
445
+				'nav'           => [
446
+					'label'      => esc_html__('Add Category', 'event_espresso'),
447
+					'order'      => 15,
448
+					'persistent' => false,
449
+				],
450
+				'help_tabs'     => [
451
+					'add_category_help_tab' => [
452
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
453
+						'filename' => 'events_add_category',
454
+					],
455
+				],
456
+				'metaboxes'     => ['_publish_post_box'],
457
+				'require_nonce' => false,
458
+			],
459
+			'edit_category'          => [
460
+				'nav'           => [
461
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
462
+					'order'      => 15,
463
+					'persistent' => false,
464
+					'url'        => $EVT_CAT_ID
465
+						? add_query_arg(
466
+							['EVT_CAT_ID' => $EVT_CAT_ID],
467
+							$this->_current_page_view_url
468
+						)
469
+						: $this->_admin_base_url,
470
+				],
471
+				'help_tabs'     => [
472
+					'edit_category_help_tab' => [
473
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
474
+						'filename' => 'events_edit_category',
475
+					],
476
+				],
477
+				'metaboxes'     => ['_publish_post_box'],
478
+				'require_nonce' => false,
479
+			],
480
+			'category_list'          => [
481
+				'nav'           => [
482
+					'label' => esc_html__('Categories', 'event_espresso'),
483
+					'order' => 20,
484
+				],
485
+				'list_table'    => 'Event_Categories_Admin_List_Table',
486
+				'help_tabs'     => [
487
+					'events_categories_help_tab'                       => [
488
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
489
+						'filename' => 'events_categories',
490
+					],
491
+					'events_categories_table_column_headings_help_tab' => [
492
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
493
+						'filename' => 'events_categories_table_column_headings',
494
+					],
495
+					'events_categories_view_help_tab'                  => [
496
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
497
+						'filename' => 'events_categories_views',
498
+					],
499
+					'events_categories_other_help_tab'                 => [
500
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
501
+						'filename' => 'events_categories_other',
502
+					],
503
+				],
504
+				'metaboxes'     => $this->_default_espresso_metaboxes,
505
+				'require_nonce' => false,
506
+			],
507
+			'preview_deletion'       => [
508
+				'nav'           => [
509
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
510
+					'order'      => 15,
511
+					'persistent' => false,
512
+					'url'        => '',
513
+				],
514
+				'require_nonce' => false,
515
+			],
516
+		];
517
+	}
518
+
519
+
520
+	/**
521
+	 * Used to register any global screen options if necessary for every route in this admin page group.
522
+	 */
523
+	protected function _add_screen_options()
524
+	{
525
+	}
526
+
527
+
528
+	/**
529
+	 * Implementing the screen options for the 'default' route.
530
+	 */
531
+	protected function _add_screen_options_default()
532
+	{
533
+		$this->_per_page_screen_option();
534
+	}
535
+
536
+
537
+	/**
538
+	 * Implementing screen options for the category list route.
539
+	 */
540
+	protected function _add_screen_options_category_list()
541
+	{
542
+		$page_title              = $this->_admin_page_title;
543
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
544
+		$this->_per_page_screen_option();
545
+		$this->_admin_page_title = $page_title;
546
+	}
547
+
548
+
549
+	/**
550
+	 * Used to register any global feature pointers for the admin page group.
551
+	 */
552
+	protected function _add_feature_pointers()
553
+	{
554
+	}
555
+
556
+
557
+	/**
558
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
559
+	 */
560
+	public function load_scripts_styles()
561
+	{
562
+		wp_register_style(
563
+			'events-admin-css',
564
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
565
+			[],
566
+			EVENT_ESPRESSO_VERSION
567
+		);
568
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
569
+		wp_enqueue_style('events-admin-css');
570
+		wp_enqueue_style('ee-cat-admin');
571
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
572
+		// registers for all views
573
+		// scripts
574
+		wp_register_script(
575
+			'event_editor_js',
576
+			EVENTS_ASSETS_URL . 'event_editor.js',
577
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
578
+			EVENT_ESPRESSO_VERSION,
579
+			true
580
+		);
581
+	}
582
+
583
+
584
+	/**
585
+	 * Enqueuing scripts and styles specific to this view
586
+	 */
587
+	public function load_scripts_styles_create_new()
588
+	{
589
+		$this->load_scripts_styles_edit();
590
+	}
591
+
592
+
593
+	/**
594
+	 * Enqueuing scripts and styles specific to this view
595
+	 */
596
+	public function load_scripts_styles_edit()
597
+	{
598
+		// styles
599
+		wp_enqueue_style('espresso-ui-theme');
600
+		wp_register_style(
601
+			'event-editor-css',
602
+			EVENTS_ASSETS_URL . 'event-editor.css',
603
+			['ee-admin-css'],
604
+			EVENT_ESPRESSO_VERSION
605
+		);
606
+		wp_enqueue_style('event-editor-css');
607
+		// scripts
608
+		wp_register_script(
609
+			'event-datetime-metabox',
610
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
611
+			['event_editor_js', 'ee-datepicker'],
612
+			EVENT_ESPRESSO_VERSION
613
+		);
614
+		wp_enqueue_script('event-datetime-metabox');
615
+	}
616
+
617
+
618
+	/**
619
+	 * Populating the _views property for the category list table view.
620
+	 */
621
+	protected function _set_list_table_views_category_list()
622
+	{
623
+		$this->_views = [
624
+			'all' => [
625
+				'slug'        => 'all',
626
+				'label'       => esc_html__('All', 'event_espresso'),
627
+				'count'       => 0,
628
+				'bulk_action' => [
629
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
630
+				],
631
+			],
632
+		];
633
+	}
634
+
635
+
636
+	/**
637
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
638
+	 */
639
+	public function admin_init()
640
+	{
641
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
642
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
643
+			'event_espresso'
644
+		);
645
+	}
646
+
647
+
648
+	/**
649
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
650
+	 * group.
651
+	 */
652
+	public function admin_notices()
653
+	{
654
+	}
655
+
656
+
657
+	/**
658
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
659
+	 * this admin page group.
660
+	 */
661
+	public function admin_footer_scripts()
662
+	{
663
+	}
664
+
665
+
666
+	/**
667
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
668
+	 * warning (via EE_Error::add_error());
669
+	 *
670
+	 * @param EE_Event $event Event object
671
+	 * @param string   $req_type
672
+	 * @return void
673
+	 * @throws EE_Error
674
+	 * @throws ReflectionException
675
+	 */
676
+	public function verify_event_edit($event = null, $req_type = '')
677
+	{
678
+		// don't need to do this when processing
679
+		if (! empty($req_type)) {
680
+			return;
681
+		}
682
+		// no event?
683
+		if (empty($event)) {
684
+			// set event
685
+			$event = $this->_cpt_model_obj;
686
+		}
687
+		// STILL no event?
688
+		if (! $event instanceof EE_Event) {
689
+			return;
690
+		}
691
+		$orig_status = $event->status();
692
+		// first check if event is active.
693
+		if (
694
+			$orig_status === EEM_Event::cancelled
695
+			|| $orig_status === EEM_Event::postponed
696
+			|| $event->is_expired()
697
+			|| $event->is_inactive()
698
+		) {
699
+			return;
700
+		}
701
+		// made it here so it IS active... next check that any of the tickets are sold.
702
+		if ($event->is_sold_out(true)) {
703
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
704
+				EE_Error::add_attention(
705
+					sprintf(
706
+						esc_html__(
707
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
708
+							'event_espresso'
709
+						),
710
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
711
+					)
712
+				);
713
+			}
714
+			return;
715
+		} elseif ($orig_status === EEM_Event::sold_out) {
716
+			EE_Error::add_attention(
717
+				sprintf(
718
+					esc_html__(
719
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
720
+						'event_espresso'
721
+					),
722
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
723
+				)
724
+			);
725
+		}
726
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
727
+		if (! $event->tickets_on_sale()) {
728
+			return;
729
+		}
730
+		// made it here so show warning
731
+		$this->_edit_event_warning();
732
+	}
733
+
734
+
735
+	/**
736
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
737
+	 * When needed, hook this into a EE_Error::add_error() notice.
738
+	 *
739
+	 * @access protected
740
+	 * @return void
741
+	 */
742
+	protected function _edit_event_warning()
743
+	{
744
+		// we don't want to add warnings during these requests
745
+		if ($this->request->getRequestParam('action') === 'editpost') {
746
+			return;
747
+		}
748
+		EE_Error::add_attention(
749
+			sprintf(
750
+				esc_html__(
751
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
752
+					'event_espresso'
753
+				),
754
+				'<a class="espresso-help-tab-lnk">',
755
+				'</a>'
756
+			)
757
+		);
758
+	}
759
+
760
+
761
+	/**
762
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
763
+	 * Otherwise, do the normal logic
764
+	 *
765
+	 * @return void
766
+	 * @throws EE_Error
767
+	 */
768
+	protected function _create_new_cpt_item()
769
+	{
770
+		$has_timezone_string = get_option('timezone_string');
771
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
772
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
773
+			EE_Error::add_attention(
774
+				sprintf(
775
+					esc_html__(
776
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
777
+						'event_espresso'
778
+					),
779
+					'<br>',
780
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
781
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
782
+					. '</select>',
783
+					'<button class="button button-secondary timezone-submit">',
784
+					'</button><span class="spinner"></span>'
785
+				),
786
+				__FILE__,
787
+				__FUNCTION__,
788
+				__LINE__
789
+			);
790
+		}
791
+		parent::_create_new_cpt_item();
792
+	}
793
+
794
+
795
+	/**
796
+	 * Sets the _views property for the default route in this admin page group.
797
+	 */
798
+	protected function _set_list_table_views_default()
799
+	{
800
+		$this->_views = [
801
+			'all'   => [
802
+				'slug'        => 'all',
803
+				'label'       => esc_html__('View All Events', 'event_espresso'),
804
+				'count'       => 0,
805
+				'bulk_action' => [
806
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
807
+				],
808
+			],
809
+			'draft' => [
810
+				'slug'        => 'draft',
811
+				'label'       => esc_html__('Draft', 'event_espresso'),
812
+				'count'       => 0,
813
+				'bulk_action' => [
814
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
815
+				],
816
+			],
817
+		];
818
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
819
+			$this->_views['trash'] = [
820
+				'slug'        => 'trash',
821
+				'label'       => esc_html__('Trash', 'event_espresso'),
822
+				'count'       => 0,
823
+				'bulk_action' => [
824
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
825
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
826
+				],
827
+			];
828
+		}
829
+	}
830
+
831
+
832
+	/**
833
+	 * Provides the legend item array for the default list table view.
834
+	 *
835
+	 * @return array
836
+	 * @throws EE_Error
837
+	 * @throws EE_Error
838
+	 */
839
+	protected function _event_legend_items()
840
+	{
841
+		$items    = [
842
+			'view_details'   => [
843
+				'class' => 'dashicons dashicons-search',
844
+				'desc'  => esc_html__('View Event', 'event_espresso'),
845
+			],
846
+			'edit_event'     => [
847
+				'class' => 'ee-icon ee-icon-calendar-edit',
848
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
849
+			],
850
+			'view_attendees' => [
851
+				'class' => 'dashicons dashicons-groups',
852
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
853
+			],
854
+		];
855
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
856
+		$statuses = [
857
+			'sold_out_status'  => [
858
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
859
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
860
+			],
861
+			'active_status'    => [
862
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
863
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
864
+			],
865
+			'upcoming_status'  => [
866
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
867
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
868
+			],
869
+			'postponed_status' => [
870
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
871
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
872
+			],
873
+			'cancelled_status' => [
874
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
875
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
876
+			],
877
+			'expired_status'   => [
878
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
879
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
880
+			],
881
+			'inactive_status'  => [
882
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
883
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
884
+			],
885
+		];
886
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
887
+		return array_merge($items, $statuses);
888
+	}
889
+
890
+
891
+	/**
892
+	 * @return EEM_Event
893
+	 * @throws EE_Error
894
+	 * @throws ReflectionException
895
+	 */
896
+	private function _event_model()
897
+	{
898
+		if (! $this->_event_model instanceof EEM_Event) {
899
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
900
+		}
901
+		return $this->_event_model;
902
+	}
903
+
904
+
905
+	/**
906
+	 * Adds extra buttons to the WP CPT permalink field row.
907
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
908
+	 *
909
+	 * @param string $return    the current html
910
+	 * @param int    $id        the post id for the page
911
+	 * @param string $new_title What the title is
912
+	 * @param string $new_slug  what the slug is
913
+	 * @return string            The new html string for the permalink area
914
+	 */
915
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
916
+	{
917
+		// make sure this is only when editing
918
+		if (! empty($id)) {
919
+			$post   = get_post($id);
920
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
921
+					   . esc_html__('Shortcode', 'event_espresso')
922
+					   . '</a> ';
923
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
924
+					   . $post->ID
925
+					   . ']">';
926
+		}
927
+		return $return;
928
+	}
929
+
930
+
931
+	/**
932
+	 * _events_overview_list_table
933
+	 * This contains the logic for showing the events_overview list
934
+	 *
935
+	 * @access protected
936
+	 * @return void
937
+	 * @throws EE_Error
938
+	 */
939
+	protected function _events_overview_list_table()
940
+	{
941
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
942
+		$this->_template_args['after_list_table']                           =
943
+			! empty($this->_template_args['after_list_table'])
944
+				? (array) $this->_template_args['after_list_table']
945
+				: [];
946
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
947
+			. EEH_Template::get_button_or_link(
948
+				get_post_type_archive_link('espresso_events'),
949
+				esc_html__("View Event Archive Page", "event_espresso"),
950
+				'button'
951
+			);
952
+		$this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
953
+			$this->_event_legend_items()
954
+		);
955
+		$this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
956
+			'create_new',
957
+			'add',
958
+			[],
959
+			'add-new-h2'
960
+		);
961
+		$this->display_admin_list_table_page_with_no_sidebar();
962
+	}
963
+
964
+
965
+	/**
966
+	 * this allows for extra misc actions in the default WP publish box
967
+	 *
968
+	 * @return void
969
+	 * @throws EE_Error
970
+	 * @throws ReflectionException
971
+	 */
972
+	public function extra_misc_actions_publish_box()
973
+	{
974
+		$this->_generate_publish_box_extra_content();
975
+	}
976
+
977
+
978
+	/**
979
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
980
+	 * saved.
981
+	 * Typically you would use this to save any additional data.
982
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
983
+	 * ALSO very important.  When a post transitions from scheduled to published,
984
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
985
+	 * other meta saves. So MAKE sure that you handle this accordingly.
986
+	 *
987
+	 * @access protected
988
+	 * @abstract
989
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
990
+	 * @param WP_Post $post    The post object of the cpt that was saved.
991
+	 * @return void
992
+	 * @throws EE_Error
993
+	 * @throws ReflectionException
994
+	 */
995
+	protected function _insert_update_cpt_item($post_id, $post)
996
+	{
997
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
998
+			// get out we're not processing an event save.
999
+			return;
1000
+		}
1001
+
1002
+		$event_values = [
1003
+			'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1004
+			'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1005
+				'display_ticket_selector',
1006
+				false,
1007
+				'bool'
1008
+			),
1009
+			'EVT_additional_limit'            => min(
1010
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1011
+				$this->request->getRequestParam('additional_limit', null, 'int')
1012
+			),
1013
+			'EVT_default_registration_status' => $this->request->getRequestParam(
1014
+				'EVT_default_registration_status',
1015
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1016
+			),
1017
+
1018
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1019
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1020
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1021
+			'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1022
+			'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1023
+		];
1024
+		// update event
1025
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1026
+		// get event_object for other metaboxes...
1027
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1028
+		// i have to setup where conditions to override the filters in the model
1029
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1030
+		$event = $this->_event_model()->get_one(
1031
+			[
1032
+				[
1033
+					$this->_event_model()->primary_key_name() => $post_id,
1034
+					'OR'                                      => [
1035
+						'status'   => $post->post_status,
1036
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1037
+						// but the returned object here has a status of "publish", so use the original post status as well
1038
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1039
+					],
1040
+				],
1041
+			]
1042
+		);
1043
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1044
+		$event_update_callbacks = apply_filters(
1045
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1046
+			[
1047
+				[$this, '_default_venue_update'],
1048
+				[$this, '_default_tickets_update'],
1049
+			]
1050
+		);
1051
+		$att_success            = true;
1052
+		foreach ($event_update_callbacks as $e_callback) {
1053
+			$_success = is_callable($e_callback)
1054
+				? call_user_func($e_callback, $event, $this->request->requestParams())
1055
+				: false;
1056
+			// if ANY of these updates fail then we want the appropriate global error message
1057
+			$att_success = ! $att_success ? $att_success : $_success;
1058
+		}
1059
+		// any errors?
1060
+		if ($success && false === $att_success) {
1061
+			EE_Error::add_error(
1062
+				esc_html__(
1063
+					'Event Details saved successfully but something went wrong with saving attachments.',
1064
+					'event_espresso'
1065
+				),
1066
+				__FILE__,
1067
+				__FUNCTION__,
1068
+				__LINE__
1069
+			);
1070
+		} elseif ($success === false) {
1071
+			EE_Error::add_error(
1072
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1073
+				__FILE__,
1074
+				__FUNCTION__,
1075
+				__LINE__
1076
+			);
1077
+		}
1078
+	}
1079
+
1080
+
1081
+	/**
1082
+	 * @param int $post_id
1083
+	 * @param int $revision_id
1084
+	 * @throws EE_Error
1085
+	 * @throws EE_Error
1086
+	 * @throws ReflectionException
1087
+	 * @see parent::restore_item()
1088
+	 */
1089
+	protected function _restore_cpt_item($post_id, $revision_id)
1090
+	{
1091
+		// copy existing event meta to new post
1092
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1093
+		if ($post_evt instanceof EE_Event) {
1094
+			// meta revision restore
1095
+			$post_evt->restore_revision($revision_id);
1096
+			// related objs restore
1097
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1098
+		}
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * Attach the venue to the Event
1104
+	 *
1105
+	 * @param EE_Event $event Event Object to add the venue to
1106
+	 * @param array    $data  The request data from the form
1107
+	 * @return bool           Success or fail.
1108
+	 * @throws EE_Error
1109
+	 * @throws ReflectionException
1110
+	 */
1111
+	protected function _default_venue_update(EE_Event $event, $data)
1112
+	{
1113
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1114
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1115
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1116
+		// very important.  If we don't have a venue name...
1117
+		// then we'll get out because not necessary to create empty venue
1118
+		if (empty($data['venue_title'])) {
1119
+			return false;
1120
+		}
1121
+		$venue_array = [
1122
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1123
+			'VNU_name'            => $data['venue_title'],
1124
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1125
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1126
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1127
+				? $data['venue_short_description']
1128
+				: null,
1129
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1130
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1131
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1132
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1133
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1134
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1135
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1136
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1137
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1138
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1139
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1140
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1141
+			'status'              => 'publish',
1142
+		];
1143
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1144
+		if (! empty($venue_id)) {
1145
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1146
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1147
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1148
+			$event->_add_relation_to($venue_id, 'Venue');
1149
+			return $rows_affected > 0;
1150
+		}
1151
+		// we insert the venue
1152
+		$venue_id = $venue_model->insert($venue_array);
1153
+		$event->_add_relation_to($venue_id, 'Venue');
1154
+		return ! empty($venue_id);
1155
+		// when we have the ancestor come in it's already been handled by the revision save.
1156
+	}
1157
+
1158
+
1159
+	/**
1160
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1161
+	 *
1162
+	 * @param EE_Event $event The Event object we're attaching data to
1163
+	 * @param array    $data  The request data from the form
1164
+	 * @return array
1165
+	 * @throws EE_Error
1166
+	 * @throws ReflectionException
1167
+	 * @throws Exception
1168
+	 */
1169
+	protected function _default_tickets_update(EE_Event $event, $data)
1170
+	{
1171
+		$datetime       = null;
1172
+		$saved_tickets  = [];
1173
+		$event_timezone = $event->get_timezone();
1174
+		$date_formats   = ['Y-m-d', 'h:i a'];
1175
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1176
+			// trim all values to ensure any excess whitespace is removed.
1177
+			$datetime_data                = array_map('trim', $datetime_data);
1178
+			$datetime_data['DTT_EVT_end'] =
1179
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1180
+					? $datetime_data['DTT_EVT_end']
1181
+					: $datetime_data['DTT_EVT_start'];
1182
+			$datetime_values              = [
1183
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1184
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1185
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1186
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1187
+				'DTT_order'     => $row,
1188
+			];
1189
+			// if we have an id then let's get existing object first and then set the new values.
1190
+			//  Otherwise we instantiate a new object for save.
1191
+			if (! empty($datetime_data['DTT_ID'])) {
1192
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1193
+				if (! $datetime instanceof EE_Datetime) {
1194
+					throw new RuntimeException(
1195
+						sprintf(
1196
+							esc_html__(
1197
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1198
+								'event_espresso'
1199
+							),
1200
+							$datetime_data['DTT_ID']
1201
+						)
1202
+					);
1203
+				}
1204
+				$datetime->set_date_format($date_formats[0]);
1205
+				$datetime->set_time_format($date_formats[1]);
1206
+				foreach ($datetime_values as $field => $value) {
1207
+					$datetime->set($field, $value);
1208
+				}
1209
+			} else {
1210
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1211
+			}
1212
+			if (! $datetime instanceof EE_Datetime) {
1213
+				throw new RuntimeException(
1214
+					sprintf(
1215
+						esc_html__(
1216
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1217
+							'event_espresso'
1218
+						),
1219
+						print_r($datetime_values, true)
1220
+					)
1221
+				);
1222
+			}
1223
+			// before going any further make sure our dates are setup correctly
1224
+			// so that the end date is always equal or greater than the start date.
1225
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1226
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1227
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1228
+			}
1229
+			$datetime->save();
1230
+			$event->_add_relation_to($datetime, 'Datetime');
1231
+		}
1232
+		// no datetimes get deleted so we don't do any of that logic here.
1233
+		// update tickets next
1234
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1235
+
1236
+		// set up some default start and end dates in case those are not present in the incoming data
1237
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1238
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1239
+		// use the start date of the first datetime for the end date
1240
+		$first_datetime   = $event->first_datetime();
1241
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1242
+
1243
+		// now process the incoming data
1244
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1245
+			$update_prices = false;
1246
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1247
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1248
+				: 0;
1249
+			// trim inputs to ensure any excess whitespace is removed.
1250
+			$ticket_data   = array_map('trim', $ticket_data);
1251
+			$ticket_values = [
1252
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1253
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1254
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1255
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1256
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1257
+					? $ticket_data['TKT_start_date']
1258
+					: $default_start_date,
1259
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1260
+					? $ticket_data['TKT_end_date']
1261
+					: $default_end_date,
1262
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1263
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1264
+					? $ticket_data['TKT_qty']
1265
+					: EE_INF,
1266
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1267
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1268
+					? $ticket_data['TKT_uses']
1269
+					: EE_INF,
1270
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1271
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1272
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1273
+				'TKT_price'       => $ticket_price,
1274
+				'TKT_row'         => $row,
1275
+			];
1276
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1277
+			// which means in turn that the prices will become new prices as well.
1278
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1279
+				$ticket_values['TKT_ID']         = 0;
1280
+				$ticket_values['TKT_is_default'] = 0;
1281
+				$update_prices                   = true;
1282
+			}
1283
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1284
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1285
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1286
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1287
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1288
+			if (! empty($ticket_data['TKT_ID'])) {
1289
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1290
+				if (! $existing_ticket instanceof EE_Ticket) {
1291
+					throw new RuntimeException(
1292
+						sprintf(
1293
+							esc_html__(
1294
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1295
+								'event_espresso'
1296
+							),
1297
+							$ticket_data['TKT_ID']
1298
+						)
1299
+					);
1300
+				}
1301
+				$ticket_sold = $existing_ticket->count_related(
1302
+					'Registration',
1303
+					[
1304
+						[
1305
+							'STS_ID' => [
1306
+								'NOT IN',
1307
+								[EEM_Registration::status_id_incomplete],
1308
+							],
1309
+						],
1310
+					]
1311
+				) > 0;
1312
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1313
+				// if they are different then we create a new ticket (if $ticket_sold)
1314
+				// if they aren't different then we go ahead and modify existing ticket.
1315
+				$create_new_ticket = $ticket_sold
1316
+									 && $ticket_price !== $existing_ticket->price()
1317
+									 && ! $existing_ticket->deleted();
1318
+				$existing_ticket->set_date_format($date_formats[0]);
1319
+				$existing_ticket->set_time_format($date_formats[1]);
1320
+				// set new values
1321
+				foreach ($ticket_values as $field => $value) {
1322
+					if ($field == 'TKT_qty') {
1323
+						$existing_ticket->set_qty($value);
1324
+					} elseif ($field == 'TKT_price') {
1325
+						$existing_ticket->set('TKT_price', $ticket_price);
1326
+					} else {
1327
+						$existing_ticket->set($field, $value);
1328
+					}
1329
+				}
1330
+				$ticket = $existing_ticket;
1331
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1332
+				//  Otherwise we have to create a new ticket.
1333
+				if ($create_new_ticket) {
1334
+					// archive the old ticket first
1335
+					$existing_ticket->set('TKT_deleted', 1);
1336
+					$existing_ticket->save();
1337
+					// make sure this ticket is still recorded in our $saved_tickets
1338
+					// so we don't run it through the regular trash routine.
1339
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1340
+					// create new ticket that's a copy of the existing except,
1341
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1342
+					$new_ticket = clone $existing_ticket;
1343
+					$new_ticket->set('TKT_ID', 0);
1344
+					$new_ticket->set('TKT_deleted', 0);
1345
+					$new_ticket->set('TKT_sold', 0);
1346
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1347
+					$update_prices = true;
1348
+					$ticket        = $new_ticket;
1349
+				}
1350
+			} else {
1351
+				// no TKT_id so a new ticket
1352
+				$ticket_values['TKT_price'] = $ticket_price;
1353
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1354
+				$update_prices              = true;
1355
+			}
1356
+			if (! $ticket instanceof EE_Ticket) {
1357
+				throw new RuntimeException(
1358
+					sprintf(
1359
+						esc_html__(
1360
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1361
+							'event_espresso'
1362
+						),
1363
+						print_r($ticket_values, true)
1364
+					)
1365
+				);
1366
+			}
1367
+			// cap ticket qty by datetime reg limits
1368
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1369
+			// update ticket.
1370
+			$ticket->save();
1371
+			// before going any further make sure our dates are setup correctly
1372
+			// so that the end date is always equal or greater than the start date.
1373
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1374
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1375
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1376
+				$ticket->save();
1377
+			}
1378
+			// initially let's add the ticket to the datetime
1379
+			$datetime->_add_relation_to($ticket, 'Ticket');
1380
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1381
+			// add prices to ticket
1382
+			$prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1383
+				? $data['edit_prices'][ $row ]
1384
+				: [];
1385
+			$this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1386
+		}
1387
+		// however now we need to handle permanently deleting tickets via the ui.
1388
+		// Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1389
+		// However, it does allow for deleting tickets that have no tickets sold,
1390
+		// in which case we want to get rid of permanently because there is no need to save in db.
1391
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1392
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1393
+		foreach ($tickets_removed as $id) {
1394
+			$id = absint($id);
1395
+			// get the ticket for this id
1396
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1397
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1398
+				continue;
1399
+			}
1400
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1401
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1402
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1403
+			foreach ($related_datetimes as $related_datetime) {
1404
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1405
+			}
1406
+			// need to do the same for prices (except these prices can also be deleted because again,
1407
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1408
+			$ticket_to_remove->delete_related_permanently('Price');
1409
+			// finally let's delete this ticket
1410
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1411
+			$ticket_to_remove->delete_permanently();
1412
+		}
1413
+		return [$datetime, $saved_tickets];
1414
+	}
1415
+
1416
+
1417
+	/**
1418
+	 * This attaches a list of given prices to a ticket.
1419
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1420
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1421
+	 * price info and prices are automatically "archived" via the ticket.
1422
+	 *
1423
+	 * @access  private
1424
+	 * @param array     $prices_data Array of prices from the form.
1425
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1426
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1427
+	 * @return  void
1428
+	 * @throws EE_Error
1429
+	 * @throws ReflectionException
1430
+	 */
1431
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1432
+	{
1433
+		$timezone = $ticket->get_timezone();
1434
+		foreach ($prices_data as $row => $price_data) {
1435
+			$price_values = [
1436
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1437
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1438
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1439
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1440
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1441
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1442
+				'PRC_order'      => $row,
1443
+			];
1444
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1445
+				$price_values['PRC_ID'] = 0;
1446
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1447
+			} else {
1448
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1449
+				// update this price with new values
1450
+				foreach ($price_values as $field => $new_price) {
1451
+					$price->set($field, $new_price);
1452
+				}
1453
+			}
1454
+			if (! $price instanceof EE_Price) {
1455
+				throw new RuntimeException(
1456
+					sprintf(
1457
+						esc_html__(
1458
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1459
+							'event_espresso'
1460
+						),
1461
+						print_r($price_values, true)
1462
+					)
1463
+				);
1464
+			}
1465
+			$price->save();
1466
+			$ticket->_add_relation_to($price, 'Price');
1467
+		}
1468
+	}
1469
+
1470
+
1471
+	/**
1472
+	 * Add in our autosave ajax handlers
1473
+	 *
1474
+	 */
1475
+	protected function _ee_autosave_create_new()
1476
+	{
1477
+	}
1478
+
1479
+
1480
+	/**
1481
+	 * More autosave handlers.
1482
+	 */
1483
+	protected function _ee_autosave_edit()
1484
+	{
1485
+		// TEMPORARILY EXITING CAUSE THIS IS A TODO
1486
+	}
1487
+
1488
+
1489
+	/**
1490
+	 * @throws EE_Error
1491
+	 * @throws ReflectionException
1492
+	 */
1493
+	private function _generate_publish_box_extra_content()
1494
+	{
1495
+		// load formatter helper
1496
+		// args for getting related registrations
1497
+		$approved_query_args        = [
1498
+			[
1499
+				'REG_deleted' => 0,
1500
+				'STS_ID'      => EEM_Registration::status_id_approved,
1501
+			],
1502
+		];
1503
+		$not_approved_query_args    = [
1504
+			[
1505
+				'REG_deleted' => 0,
1506
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1507
+			],
1508
+		];
1509
+		$pending_payment_query_args = [
1510
+			[
1511
+				'REG_deleted' => 0,
1512
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1513
+			],
1514
+		];
1515
+		// publish box
1516
+		$publish_box_extra_args = [
1517
+			'view_approved_reg_url'        => add_query_arg(
1518
+				[
1519
+					'action'      => 'default',
1520
+					'event_id'    => $this->_cpt_model_obj->ID(),
1521
+					'_reg_status' => EEM_Registration::status_id_approved,
1522
+					'use_filters' => true,
1523
+				],
1524
+				REG_ADMIN_URL
1525
+			),
1526
+			'view_not_approved_reg_url'    => add_query_arg(
1527
+				[
1528
+					'action'      => 'default',
1529
+					'event_id'    => $this->_cpt_model_obj->ID(),
1530
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1531
+					'use_filters' => true,
1532
+				],
1533
+				REG_ADMIN_URL
1534
+			),
1535
+			'view_pending_payment_reg_url' => add_query_arg(
1536
+				[
1537
+					'action'      => 'default',
1538
+					'event_id'    => $this->_cpt_model_obj->ID(),
1539
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1540
+					'use_filters' => true,
1541
+				],
1542
+				REG_ADMIN_URL
1543
+			),
1544
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1545
+				'Registration',
1546
+				$approved_query_args
1547
+			),
1548
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1549
+				'Registration',
1550
+				$not_approved_query_args
1551
+			),
1552
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1553
+				'Registration',
1554
+				$pending_payment_query_args
1555
+			),
1556
+			'misc_pub_section_class'       => apply_filters(
1557
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1558
+				'misc-pub-section'
1559
+			),
1560
+		];
1561
+		ob_start();
1562
+		do_action(
1563
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1564
+			$this->_cpt_model_obj
1565
+		);
1566
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1567
+		// load template
1568
+		EEH_Template::display_template(
1569
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1570
+			$publish_box_extra_args
1571
+		);
1572
+	}
1573
+
1574
+
1575
+	/**
1576
+	 * @return EE_Event
1577
+	 */
1578
+	public function get_event_object()
1579
+	{
1580
+		return $this->_cpt_model_obj;
1581
+	}
1582
+
1583
+
1584
+
1585
+
1586
+	/** METABOXES * */
1587
+	/**
1588
+	 * _register_event_editor_meta_boxes
1589
+	 * add all metaboxes related to the event_editor
1590
+	 *
1591
+	 * @return void
1592
+	 * @throws EE_Error
1593
+	 * @throws ReflectionException
1594
+	 */
1595
+	protected function _register_event_editor_meta_boxes()
1596
+	{
1597
+		$this->verify_cpt_object();
1598
+		add_meta_box(
1599
+			'espresso_event_editor_tickets',
1600
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1601
+			[$this, 'ticket_metabox'],
1602
+			$this->page_slug,
1603
+			'normal',
1604
+			'high'
1605
+		);
1606
+		add_meta_box(
1607
+			'espresso_event_editor_event_options',
1608
+			esc_html__('Event Registration Options', 'event_espresso'),
1609
+			[$this, 'registration_options_meta_box'],
1610
+			$this->page_slug,
1611
+			'side'
1612
+		);
1613
+		// NOTE: if you're looking for other metaboxes in here,
1614
+		// where a metabox has a related management page in the admin
1615
+		// you will find it setup in the related management page's "_Hooks" file.
1616
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1617
+	}
1618
+
1619
+
1620
+	/**
1621
+	 * @throws DomainException
1622
+	 * @throws EE_Error
1623
+	 * @throws ReflectionException
1624
+	 */
1625
+	public function ticket_metabox()
1626
+	{
1627
+		$existing_datetime_ids = $existing_ticket_ids = [];
1628
+		// defaults for template args
1629
+		$template_args = [
1630
+			'existing_datetime_ids'    => '',
1631
+			'event_datetime_help_link' => '',
1632
+			'ticket_options_help_link' => '',
1633
+			'time'                     => null,
1634
+			'ticket_rows'              => '',
1635
+			'existing_ticket_ids'      => '',
1636
+			'total_ticket_rows'        => 1,
1637
+			'ticket_js_structure'      => '',
1638
+			'trash_icon'               => 'ee-lock-icon',
1639
+			'disabled'                 => '',
1640
+		];
1641
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1642
+		/**
1643
+		 * 1. Start with retrieving Datetimes
1644
+		 * 2. Fore each datetime get related tickets
1645
+		 * 3. For each ticket get related prices
1646
+		 */
1647
+		$times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1648
+		$first_datetime = reset($times);
1649
+		// do we get related tickets?
1650
+		if (
1651
+			$first_datetime instanceof EE_Datetime
1652
+			&& $first_datetime->ID() !== 0
1653
+		) {
1654
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1655
+			$template_args['time']   = $first_datetime;
1656
+			$related_tickets         = $first_datetime->tickets(
1657
+				[
1658
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1659
+					'default_where_conditions' => 'none',
1660
+				]
1661
+			);
1662
+			if (! empty($related_tickets)) {
1663
+				$template_args['total_ticket_rows'] = count($related_tickets);
1664
+				$row                                = 0;
1665
+				foreach ($related_tickets as $ticket) {
1666
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1667
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1668
+					$row++;
1669
+				}
1670
+			} else {
1671
+				$template_args['total_ticket_rows'] = 1;
1672
+				/** @type EE_Ticket $ticket */
1673
+				$ticket                       = EEM_Ticket::instance()->create_default_object();
1674
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1675
+			}
1676
+		} else {
1677
+			$template_args['time']        = $times[0];
1678
+			$tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1679
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1680
+			// NOTE: we're just sending the first default row
1681
+			// (decaf can't manage default tickets so this should be sufficient);
1682
+		}
1683
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1684
+			'event_editor_event_datetimes_help_tab'
1685
+		);
1686
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1687
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1688
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1689
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1690
+			EEM_Ticket::instance()->create_default_object(),
1691
+			true
1692
+		);
1693
+		$template                                  = apply_filters(
1694
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1695
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1696
+		);
1697
+		EEH_Template::display_template($template, $template_args);
1698
+	}
1699
+
1700
+
1701
+	/**
1702
+	 * Setup an individual ticket form for the decaf event editor page
1703
+	 *
1704
+	 * @access private
1705
+	 * @param EE_Ticket $ticket   the ticket object
1706
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1707
+	 * @param int       $row
1708
+	 * @return string generated html for the ticket row.
1709
+	 * @throws EE_Error
1710
+	 * @throws ReflectionException
1711
+	 */
1712
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1713
+	{
1714
+		$template_args = [
1715
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1716
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1717
+				: '',
1718
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1719
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1720
+			'TKT_name'            => $ticket->get('TKT_name'),
1721
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1722
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1723
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1724
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1725
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1726
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1727
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1728
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1729
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1730
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1731
+				: ' disabled=disabled',
1732
+		];
1733
+		$price         = $ticket->ID() !== 0
1734
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1735
+			: null;
1736
+		$price         = $price instanceof EE_Price
1737
+			? $price
1738
+			: EEM_Price::instance()->create_default_object();
1739
+		$price_args    = [
1740
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1741
+			'PRC_amount'            => $price->get('PRC_amount'),
1742
+			'PRT_ID'                => $price->get('PRT_ID'),
1743
+			'PRC_ID'                => $price->get('PRC_ID'),
1744
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1745
+		];
1746
+		// make sure we have default start and end dates if skeleton
1747
+		// handle rows that should NOT be empty
1748
+		if (empty($template_args['TKT_start_date'])) {
1749
+			// if empty then the start date will be now.
1750
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1751
+		}
1752
+		if (empty($template_args['TKT_end_date'])) {
1753
+			// get the earliest datetime (if present);
1754
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1755
+				? $this->_cpt_model_obj->get_first_related(
1756
+					'Datetime',
1757
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1758
+				)
1759
+				: null;
1760
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1761
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1762
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1763
+		}
1764
+		$template_args = array_merge($template_args, $price_args);
1765
+		$template      = apply_filters(
1766
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1767
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1768
+			$ticket
1769
+		);
1770
+		return EEH_Template::display_template($template, $template_args, true);
1771
+	}
1772
+
1773
+
1774
+	/**
1775
+	 * @throws EE_Error
1776
+	 * @throws ReflectionException
1777
+	 */
1778
+	public function registration_options_meta_box()
1779
+	{
1780
+		$yes_no_values             = [
1781
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1782
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1783
+		];
1784
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1785
+			[
1786
+				EEM_Registration::status_id_cancelled,
1787
+				EEM_Registration::status_id_declined,
1788
+				EEM_Registration::status_id_incomplete,
1789
+			],
1790
+			true
1791
+		);
1792
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1793
+		$template_args['_event']                          = $this->_cpt_model_obj;
1794
+		$template_args['event']                           = $this->_cpt_model_obj;
1795
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1796
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1797
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1798
+			'default_reg_status',
1799
+			$default_reg_status_values,
1800
+			$this->_cpt_model_obj->default_registration_status()
1801
+		);
1802
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1803
+			'display_desc',
1804
+			$yes_no_values,
1805
+			$this->_cpt_model_obj->display_description()
1806
+		);
1807
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1808
+			'display_ticket_selector',
1809
+			$yes_no_values,
1810
+			$this->_cpt_model_obj->display_ticket_selector(),
1811
+			'',
1812
+			'',
1813
+			false
1814
+		);
1815
+		$template_args['additional_registration_options'] = apply_filters(
1816
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1817
+			'',
1818
+			$template_args,
1819
+			$yes_no_values,
1820
+			$default_reg_status_values
1821
+		);
1822
+		EEH_Template::display_template(
1823
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1824
+			$template_args
1825
+		);
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * _get_events()
1831
+	 * This method simply returns all the events (for the given _view and paging)
1832
+	 *
1833
+	 * @access public
1834
+	 * @param int  $per_page     count of items per page (20 default);
1835
+	 * @param int  $current_page what is the current page being viewed.
1836
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1837
+	 *                           If FALSE then we return an array of event objects
1838
+	 *                           that match the given _view and paging parameters.
1839
+	 * @return array|int         an array of event objects or a count of them.
1840
+	 * @throws Exception
1841
+	 */
1842
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1843
+	{
1844
+		$EEM_Event   = $this->_event_model();
1845
+		$offset      = ($current_page - 1) * $per_page;
1846
+		$limit       = $count ? null : $offset . ',' . $per_page;
1847
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1848
+		$order       = $this->request->getRequestParam('order', 'DESC');
1849
+		$month_range = $this->request->getRequestParam('month_range');
1850
+		if ($month_range) {
1851
+			$pieces = explode(' ', $month_range, 3);
1852
+			// simulate the FIRST day of the month, that fixes issues for months like February
1853
+			// where PHP doesn't know what to assume for date.
1854
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1855
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1856
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1857
+		}
1858
+		$where  = [];
1859
+		$status = $this->request->getRequestParam('status');
1860
+		// determine what post_status our condition will have for the query.
1861
+		switch ($status) {
1862
+			case 'month':
1863
+			case 'today':
1864
+			case null:
1865
+			case 'all':
1866
+				break;
1867
+			case 'draft':
1868
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1869
+				break;
1870
+			default:
1871
+				$where['status'] = $status;
1872
+		}
1873
+		// categories? The default for all categories is -1
1874
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1875
+		if ($category !== -1) {
1876
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1877
+			$where['Term_Taxonomy.term_id']  = $category;
1878
+		}
1879
+		// date where conditions
1880
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1881
+		if ($month_range) {
1882
+			$DateTime = new DateTime(
1883
+				$year_r . '-' . $month_r . '-01 00:00:00',
1884
+				new DateTimeZone('UTC')
1885
+			);
1886
+			$start    = $DateTime->getTimestamp();
1887
+			// set the datetime to be the end of the month
1888
+			$DateTime->setDate(
1889
+				$year_r,
1890
+				$month_r,
1891
+				$DateTime->format('t')
1892
+			)->setTime(23, 59, 59);
1893
+			$end                             = $DateTime->getTimestamp();
1894
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1895
+		} elseif ($status === 'today') {
1896
+			$DateTime                        =
1897
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1898
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1899
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1900
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1901
+		} elseif ($status === 'month') {
1902
+			$now                             = date('Y-m-01');
1903
+			$DateTime                        =
1904
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1905
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1906
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1907
+														->setTime(23, 59, 59)
1908
+														->format(implode(' ', $start_formats));
1909
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1910
+		}
1911
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1912
+			$where['EVT_wp_user'] = get_current_user_id();
1913
+		} else {
1914
+			if (! isset($where['status'])) {
1915
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1916
+					$where['OR'] = [
1917
+						'status*restrict_private' => ['!=', 'private'],
1918
+						'AND'                     => [
1919
+							'status*inclusive' => ['=', 'private'],
1920
+							'EVT_wp_user'      => get_current_user_id(),
1921
+						],
1922
+					];
1923
+				}
1924
+			}
1925
+		}
1926
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1927
+		if (
1928
+			$wp_user
1929
+			&& $wp_user !== get_current_user_id()
1930
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1931
+		) {
1932
+			$where['EVT_wp_user'] = $wp_user;
1933
+		}
1934
+		// search query handling
1935
+		$search_term = $this->request->getRequestParam('s');
1936
+		if ($search_term) {
1937
+			$search_term = '%' . $search_term . '%';
1938
+			$where['OR'] = [
1939
+				'EVT_name'       => ['LIKE', $search_term],
1940
+				'EVT_desc'       => ['LIKE', $search_term],
1941
+				'EVT_short_desc' => ['LIKE', $search_term],
1942
+			];
1943
+		}
1944
+		// filter events by venue.
1945
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
1946
+		if ($venue) {
1947
+			$where['Venue.VNU_ID'] = $venue;
1948
+		}
1949
+		$request_params = $this->request->requestParams();
1950
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1951
+		$query_params   = apply_filters(
1952
+			'FHEE__Events_Admin_Page__get_events__query_params',
1953
+			[
1954
+				$where,
1955
+				'limit'    => $limit,
1956
+				'order_by' => $orderby,
1957
+				'order'    => $order,
1958
+				'group_by' => 'EVT_ID',
1959
+			],
1960
+			$request_params
1961
+		);
1962
+
1963
+		// let's first check if we have special requests coming in.
1964
+		$active_status = $this->request->getRequestParam('active_status');
1965
+		if ($active_status) {
1966
+			switch ($active_status) {
1967
+				case 'upcoming':
1968
+					return $EEM_Event->get_upcoming_events($query_params, $count);
1969
+				case 'expired':
1970
+					return $EEM_Event->get_expired_events($query_params, $count);
1971
+				case 'active':
1972
+					return $EEM_Event->get_active_events($query_params, $count);
1973
+				case 'inactive':
1974
+					return $EEM_Event->get_inactive_events($query_params, $count);
1975
+			}
1976
+		}
1977
+
1978
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1979
+	}
1980
+
1981
+
1982
+	/**
1983
+	 * handling for WordPress CPT actions (trash, restore, delete)
1984
+	 *
1985
+	 * @param string $post_id
1986
+	 * @throws EE_Error
1987
+	 * @throws ReflectionException
1988
+	 */
1989
+	public function trash_cpt_item($post_id)
1990
+	{
1991
+		$this->request->setRequestParam('EVT_ID', $post_id);
1992
+		$this->_trash_or_restore_event('trash', false);
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * @param string $post_id
1998
+	 * @throws EE_Error
1999
+	 * @throws ReflectionException
2000
+	 */
2001
+	public function restore_cpt_item($post_id)
2002
+	{
2003
+		$this->request->setRequestParam('EVT_ID', $post_id);
2004
+		$this->_trash_or_restore_event('draft', false);
2005
+	}
2006
+
2007
+
2008
+	/**
2009
+	 * @param string $post_id
2010
+	 * @throws EE_Error
2011
+	 * @throws EE_Error
2012
+	 */
2013
+	public function delete_cpt_item($post_id)
2014
+	{
2015
+		throw new EE_Error(
2016
+			esc_html__(
2017
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2018
+				'event_espresso'
2019
+			)
2020
+		);
2021
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2022
+		// $this->_delete_event();
2023
+	}
2024
+
2025
+
2026
+	/**
2027
+	 * _trash_or_restore_event
2028
+	 *
2029
+	 * @access protected
2030
+	 * @param string $event_status
2031
+	 * @param bool   $redirect_after
2032
+	 * @throws EE_Error
2033
+	 * @throws EE_Error
2034
+	 * @throws ReflectionException
2035
+	 */
2036
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2037
+	{
2038
+		// determine the event id and set to array.
2039
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2040
+		// loop thru events
2041
+		if ($EVT_ID) {
2042
+			// clean status
2043
+			$event_status = sanitize_key($event_status);
2044
+			// grab status
2045
+			if (! empty($event_status)) {
2046
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2047
+			} else {
2048
+				$success = false;
2049
+				$msg     = esc_html__(
2050
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2051
+					'event_espresso'
2052
+				);
2053
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2054
+			}
2055
+		} else {
2056
+			$success = false;
2057
+			$msg     = esc_html__(
2058
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2059
+				'event_espresso'
2060
+			);
2061
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2062
+		}
2063
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2064
+		if ($redirect_after) {
2065
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2066
+		}
2067
+	}
2068
+
2069
+
2070
+	/**
2071
+	 * _trash_or_restore_events
2072
+	 *
2073
+	 * @access protected
2074
+	 * @param string $event_status
2075
+	 * @return void
2076
+	 * @throws EE_Error
2077
+	 * @throws EE_Error
2078
+	 * @throws ReflectionException
2079
+	 */
2080
+	protected function _trash_or_restore_events($event_status = 'trash')
2081
+	{
2082
+		// clean status
2083
+		$event_status = sanitize_key($event_status);
2084
+		// grab status
2085
+		if (! empty($event_status)) {
2086
+			$success = true;
2087
+			// determine the event id and set to array.
2088
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2089
+			// loop thru events
2090
+			foreach ($EVT_IDs as $EVT_ID) {
2091
+				if ($EVT_ID = absint($EVT_ID)) {
2092
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2093
+					$success = $results !== false ? $success : false;
2094
+				} else {
2095
+					$msg = sprintf(
2096
+						esc_html__(
2097
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2098
+							'event_espresso'
2099
+						),
2100
+						$EVT_ID
2101
+					);
2102
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2103
+					$success = false;
2104
+				}
2105
+			}
2106
+		} else {
2107
+			$success = false;
2108
+			$msg     = esc_html__(
2109
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2110
+				'event_espresso'
2111
+			);
2112
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2113
+		}
2114
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2115
+		$success = $success ? 2 : false;
2116
+		$action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2117
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2118
+	}
2119
+
2120
+
2121
+	/**
2122
+	 * @param int    $EVT_ID
2123
+	 * @param string $event_status
2124
+	 * @return bool
2125
+	 * @throws EE_Error
2126
+	 * @throws ReflectionException
2127
+	 */
2128
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2129
+	{
2130
+		// grab event id
2131
+		if (! $EVT_ID) {
2132
+			$msg = esc_html__(
2133
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2134
+				'event_espresso'
2135
+			);
2136
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2137
+			return false;
2138
+		}
2139
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2140
+		// clean status
2141
+		$event_status = sanitize_key($event_status);
2142
+		// grab status
2143
+		if (empty($event_status)) {
2144
+			$msg = esc_html__(
2145
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2146
+				'event_espresso'
2147
+			);
2148
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2149
+			return false;
2150
+		}
2151
+		// was event trashed or restored ?
2152
+		switch ($event_status) {
2153
+			case 'draft':
2154
+				$action = 'restored from the trash';
2155
+				$hook   = 'AHEE_event_restored_from_trash';
2156
+				break;
2157
+			case 'trash':
2158
+				$action = 'moved to the trash';
2159
+				$hook   = 'AHEE_event_moved_to_trash';
2160
+				break;
2161
+			default:
2162
+				$action = 'updated';
2163
+				$hook   = false;
2164
+		}
2165
+		// use class to change status
2166
+		$this->_cpt_model_obj->set_status($event_status);
2167
+		$success = $this->_cpt_model_obj->save();
2168
+		if (! $success) {
2169
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2170
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
+			return false;
2172
+		}
2173
+		if ($hook) {
2174
+			do_action($hook);
2175
+		}
2176
+		return true;
2177
+	}
2178
+
2179
+
2180
+	/**
2181
+	 * @param array $event_ids
2182
+	 * @return array
2183
+	 * @since   4.10.23.p
2184
+	 */
2185
+	private function cleanEventIds(array $event_ids)
2186
+	{
2187
+		return array_map('absint', $event_ids);
2188
+	}
2189
+
2190
+
2191
+	/**
2192
+	 * @return array
2193
+	 * @since   4.10.23.p
2194
+	 */
2195
+	private function getEventIdsFromRequest()
2196
+	{
2197
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2198
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2199
+		} else {
2200
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2201
+		}
2202
+	}
2203
+
2204
+
2205
+	/**
2206
+	 * @param bool $preview_delete
2207
+	 * @throws EE_Error
2208
+	 */
2209
+	protected function _delete_event($preview_delete = true)
2210
+	{
2211
+		$this->_delete_events($preview_delete);
2212
+	}
2213
+
2214
+
2215
+	/**
2216
+	 * Gets the tree traversal batch persister.
2217
+	 *
2218
+	 * @return NodeGroupDao
2219
+	 * @throws InvalidArgumentException
2220
+	 * @throws InvalidDataTypeException
2221
+	 * @throws InvalidInterfaceException
2222
+	 * @since 4.10.12.p
2223
+	 */
2224
+	protected function getModelObjNodeGroupPersister()
2225
+	{
2226
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2227
+			$this->model_obj_node_group_persister =
2228
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2229
+		}
2230
+		return $this->model_obj_node_group_persister;
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 * @param bool $preview_delete
2236
+	 * @return void
2237
+	 * @throws EE_Error
2238
+	 */
2239
+	protected function _delete_events($preview_delete = true)
2240
+	{
2241
+		$event_ids = $this->getEventIdsFromRequest();
2242
+		if ($preview_delete) {
2243
+			$this->generateDeletionPreview($event_ids);
2244
+		} else {
2245
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2246
+		}
2247
+	}
2248
+
2249
+
2250
+	/**
2251
+	 * @param array $event_ids
2252
+	 */
2253
+	protected function generateDeletionPreview(array $event_ids)
2254
+	{
2255
+		$event_ids = $this->cleanEventIds($event_ids);
2256
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2257
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2258
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2259
+			[
2260
+				'action'            => 'preview_deletion',
2261
+				'deletion_job_code' => $deletion_job_code,
2262
+			],
2263
+			$this->_admin_base_url
2264
+		);
2265
+		EEH_URL::safeRedirectAndExit(
2266
+			EE_Admin_Page::add_query_args_and_nonce(
2267
+				[
2268
+					'page'              => 'espresso_batch',
2269
+					'batch'             => EED_Batch::batch_job,
2270
+					'EVT_IDs'           => $event_ids,
2271
+					'deletion_job_code' => $deletion_job_code,
2272
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2273
+					'return_url'        => urlencode($return_url),
2274
+				],
2275
+				admin_url()
2276
+			)
2277
+		);
2278
+	}
2279
+
2280
+
2281
+	/**
2282
+	 * Checks for a POST submission
2283
+	 *
2284
+	 * @since 4.10.12.p
2285
+	 */
2286
+	protected function confirmDeletion()
2287
+	{
2288
+		$deletion_redirect_logic =
2289
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2290
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2291
+	}
2292
+
2293
+
2294
+	/**
2295
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2296
+	 *
2297
+	 * @throws EE_Error
2298
+	 * @since 4.10.12.p
2299
+	 */
2300
+	protected function previewDeletion()
2301
+	{
2302
+		$preview_deletion_logic =
2303
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2304
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2305
+		$this->display_admin_page_with_no_sidebar();
2306
+	}
2307
+
2308
+
2309
+	/**
2310
+	 * get total number of events
2311
+	 *
2312
+	 * @access public
2313
+	 * @return int
2314
+	 * @throws EE_Error
2315
+	 * @throws EE_Error
2316
+	 */
2317
+	public function total_events()
2318
+	{
2319
+		return EEM_Event::instance()->count(
2320
+			['caps' => 'read_admin'],
2321
+			'EVT_ID',
2322
+			true
2323
+		);
2324
+	}
2325
+
2326
+
2327
+	/**
2328
+	 * get total number of draft events
2329
+	 *
2330
+	 * @access public
2331
+	 * @return int
2332
+	 * @throws EE_Error
2333
+	 * @throws EE_Error
2334
+	 */
2335
+	public function total_events_draft()
2336
+	{
2337
+		return EEM_Event::instance()->count(
2338
+			[
2339
+				['status' => ['IN', ['draft', 'auto-draft']]],
2340
+				'caps' => 'read_admin',
2341
+			],
2342
+			'EVT_ID',
2343
+			true
2344
+		);
2345
+	}
2346
+
2347
+
2348
+	/**
2349
+	 * get total number of trashed events
2350
+	 *
2351
+	 * @access public
2352
+	 * @return int
2353
+	 * @throws EE_Error
2354
+	 * @throws EE_Error
2355
+	 */
2356
+	public function total_trashed_events()
2357
+	{
2358
+		return EEM_Event::instance()->count(
2359
+			[
2360
+				['status' => 'trash'],
2361
+				'caps' => 'read_admin',
2362
+			],
2363
+			'EVT_ID',
2364
+			true
2365
+		);
2366
+	}
2367
+
2368
+
2369
+	/**
2370
+	 *    _default_event_settings
2371
+	 *    This generates the Default Settings Tab
2372
+	 *
2373
+	 * @return void
2374
+	 * @throws EE_Error
2375
+	 */
2376
+	protected function _default_event_settings()
2377
+	{
2378
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2379
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2380
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2381
+		$this->display_admin_page_with_sidebar();
2382
+	}
2383
+
2384
+
2385
+	/**
2386
+	 * Return the form for event settings.
2387
+	 *
2388
+	 * @return EE_Form_Section_Proper
2389
+	 * @throws EE_Error
2390
+	 */
2391
+	protected function _default_event_settings_form()
2392
+	{
2393
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2394
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2395
+		// exclude
2396
+			[
2397
+				EEM_Registration::status_id_cancelled,
2398
+				EEM_Registration::status_id_declined,
2399
+				EEM_Registration::status_id_incomplete,
2400
+				EEM_Registration::status_id_wait_list,
2401
+			],
2402
+			true
2403
+		);
2404
+		return new EE_Form_Section_Proper(
2405
+			[
2406
+				'name'            => 'update_default_event_settings',
2407
+				'html_id'         => 'update_default_event_settings',
2408
+				'html_class'      => 'form-table',
2409
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2410
+				'subsections'     => apply_filters(
2411
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2412
+					[
2413
+						'default_reg_status'  => new EE_Select_Input(
2414
+							$registration_stati_for_selection,
2415
+							[
2416
+								'default'         => isset($registration_config->default_STS_ID)
2417
+													 && array_key_exists(
2418
+														 $registration_config->default_STS_ID,
2419
+														 $registration_stati_for_selection
2420
+													 )
2421
+									? sanitize_text_field($registration_config->default_STS_ID)
2422
+									: EEM_Registration::status_id_pending_payment,
2423
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2424
+													 . EEH_Template::get_help_tab_link(
2425
+														 'default_settings_status_help_tab'
2426
+													 ),
2427
+								'html_help_text'  => esc_html__(
2428
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2429
+									'event_espresso'
2430
+								),
2431
+							]
2432
+						),
2433
+						'default_max_tickets' => new EE_Integer_Input(
2434
+							[
2435
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2436
+									? $registration_config->default_maximum_number_of_tickets
2437
+									: EEM_Event::get_default_additional_limit(),
2438
+								'html_label_text' => esc_html__(
2439
+									'Default Maximum Tickets Allowed Per Order:',
2440
+									'event_espresso'
2441
+								)
2442
+								. EEH_Template::get_help_tab_link(
2443
+									'default_maximum_tickets_help_tab"'
2444
+								),
2445
+								'html_help_text'  => esc_html__(
2446
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2447
+									'event_espresso'
2448
+								),
2449
+							]
2450
+						),
2451
+					]
2452
+				),
2453
+			]
2454
+		);
2455
+	}
2456
+
2457
+
2458
+	/**
2459
+	 * _update_default_event_settings
2460
+	 *
2461
+	 * @access protected
2462
+	 * @return void
2463
+	 * @throws EE_Error
2464
+	 */
2465
+	protected function _update_default_event_settings()
2466
+	{
2467
+		$registration_config = EE_Registry::instance()->CFG->registration;
2468
+		$form                = $this->_default_event_settings_form();
2469
+		if ($form->was_submitted()) {
2470
+			$form->receive_form_submission();
2471
+			if ($form->is_valid()) {
2472
+				$valid_data = $form->valid_data();
2473
+				if (isset($valid_data['default_reg_status'])) {
2474
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2475
+				}
2476
+				if (isset($valid_data['default_max_tickets'])) {
2477
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2478
+				}
2479
+				// update because data was valid!
2480
+				EE_Registry::instance()->CFG->update_espresso_config();
2481
+				EE_Error::overwrite_success();
2482
+				EE_Error::add_success(
2483
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2484
+				);
2485
+			}
2486
+		}
2487
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2488
+	}
2489
+
2490
+
2491
+	/*************        Templates        *************
20 2492
      *
21
-     * @var EE_Event $_event
22
-     */
23
-    protected $_event;
24
-
25
-
26
-    /**
27
-     * This will hold the category object for category_details screen.
28
-     *
29
-     * @var stdClass $_category
30
-     */
31
-    protected $_category;
32
-
33
-
34
-    /**
35
-     * This will hold the event model instance
36
-     *
37
-     * @var EEM_Event $_event_model
38
-     */
39
-    protected $_event_model;
40
-
41
-
42
-    /**
43
-     * @var EE_Event
44
-     */
45
-    protected $_cpt_model_obj = false;
46
-
47
-
48
-    /**
49
-     * @var NodeGroupDao
50
-     */
51
-    protected $model_obj_node_group_persister;
52
-
53
-
54
-    /**
55
-     * Initialize page props for this admin page group.
56
-     */
57
-    protected function _init_page_props()
58
-    {
59
-        $this->page_slug        = EVENTS_PG_SLUG;
60
-        $this->page_label       = EVENTS_LABEL;
61
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
62
-        $this->_admin_base_path = EVENTS_ADMIN;
63
-        $this->_cpt_model_names = [
64
-            'create_new' => 'EEM_Event',
65
-            'edit'       => 'EEM_Event',
66
-        ];
67
-        $this->_cpt_edit_routes = [
68
-            'espresso_events' => 'edit',
69
-        ];
70
-        add_action(
71
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
72
-            [$this, 'verify_event_edit'],
73
-            10,
74
-            2
75
-        );
76
-    }
77
-
78
-
79
-    /**
80
-     * Sets the ajax hooks used for this admin page group.
81
-     */
82
-    protected function _ajax_hooks()
83
-    {
84
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
85
-    }
86
-
87
-
88
-    /**
89
-     * Sets the page properties for this admin page group.
90
-     */
91
-    protected function _define_page_props()
92
-    {
93
-        $this->_admin_page_title = EVENTS_LABEL;
94
-        $this->_labels           = [
95
-            'buttons'      => [
96
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
97
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
98
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
99
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
100
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
101
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
102
-            ],
103
-            'editor_title' => [
104
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
105
-            ],
106
-            'publishbox'   => [
107
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
108
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
109
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
110
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
111
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
112
-            ],
113
-        ];
114
-    }
115
-
116
-
117
-    /**
118
-     * Sets the page routes property for this admin page group.
119
-     */
120
-    protected function _set_page_routes()
121
-    {
122
-        // load formatter helper
123
-        // load field generator helper
124
-        // is there a evt_id in the request?
125
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
126
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
127
-
128
-        $this->_page_routes = [
129
-            'default'                       => [
130
-                'func'       => '_events_overview_list_table',
131
-                'capability' => 'ee_read_events',
132
-            ],
133
-            'create_new'                    => [
134
-                'func'       => '_create_new_cpt_item',
135
-                'capability' => 'ee_edit_events',
136
-            ],
137
-            'edit'                          => [
138
-                'func'       => '_edit_cpt_item',
139
-                'capability' => 'ee_edit_event',
140
-                'obj_id'     => $EVT_ID,
141
-            ],
142
-            'copy_event'                    => [
143
-                'func'       => '_copy_events',
144
-                'capability' => 'ee_edit_event',
145
-                'obj_id'     => $EVT_ID,
146
-                'noheader'   => true,
147
-            ],
148
-            'trash_event'                   => [
149
-                'func'       => '_trash_or_restore_event',
150
-                'args'       => ['event_status' => 'trash'],
151
-                'capability' => 'ee_delete_event',
152
-                'obj_id'     => $EVT_ID,
153
-                'noheader'   => true,
154
-            ],
155
-            'trash_events'                  => [
156
-                'func'       => '_trash_or_restore_events',
157
-                'args'       => ['event_status' => 'trash'],
158
-                'capability' => 'ee_delete_events',
159
-                'noheader'   => true,
160
-            ],
161
-            'restore_event'                 => [
162
-                'func'       => '_trash_or_restore_event',
163
-                'args'       => ['event_status' => 'draft'],
164
-                'capability' => 'ee_delete_event',
165
-                'obj_id'     => $EVT_ID,
166
-                'noheader'   => true,
167
-            ],
168
-            'restore_events'                => [
169
-                'func'       => '_trash_or_restore_events',
170
-                'args'       => ['event_status' => 'draft'],
171
-                'capability' => 'ee_delete_events',
172
-                'noheader'   => true,
173
-            ],
174
-            'delete_event'                  => [
175
-                'func'       => '_delete_event',
176
-                'capability' => 'ee_delete_event',
177
-                'obj_id'     => $EVT_ID,
178
-                'noheader'   => true,
179
-            ],
180
-            'delete_events'                 => [
181
-                'func'       => '_delete_events',
182
-                'capability' => 'ee_delete_events',
183
-                'noheader'   => true,
184
-            ],
185
-            'view_report'                   => [
186
-                'func'       => '_view_report',
187
-                'capability' => 'ee_edit_events',
188
-            ],
189
-            'default_event_settings'        => [
190
-                'func'       => '_default_event_settings',
191
-                'capability' => 'manage_options',
192
-            ],
193
-            'update_default_event_settings' => [
194
-                'func'       => '_update_default_event_settings',
195
-                'capability' => 'manage_options',
196
-                'noheader'   => true,
197
-            ],
198
-            'template_settings'             => [
199
-                'func'       => '_template_settings',
200
-                'capability' => 'manage_options',
201
-            ],
202
-            // event category tab related
203
-            'add_category'                  => [
204
-                'func'       => '_category_details',
205
-                'capability' => 'ee_edit_event_category',
206
-                'args'       => ['add'],
207
-            ],
208
-            'edit_category'                 => [
209
-                'func'       => '_category_details',
210
-                'capability' => 'ee_edit_event_category',
211
-                'args'       => ['edit'],
212
-            ],
213
-            'delete_categories'             => [
214
-                'func'       => '_delete_categories',
215
-                'capability' => 'ee_delete_event_category',
216
-                'noheader'   => true,
217
-            ],
218
-            'delete_category'               => [
219
-                'func'       => '_delete_categories',
220
-                'capability' => 'ee_delete_event_category',
221
-                'noheader'   => true,
222
-            ],
223
-            'insert_category'               => [
224
-                'func'       => '_insert_or_update_category',
225
-                'args'       => ['new_category' => true],
226
-                'capability' => 'ee_edit_event_category',
227
-                'noheader'   => true,
228
-            ],
229
-            'update_category'               => [
230
-                'func'       => '_insert_or_update_category',
231
-                'args'       => ['new_category' => false],
232
-                'capability' => 'ee_edit_event_category',
233
-                'noheader'   => true,
234
-            ],
235
-            'category_list'                 => [
236
-                'func'       => '_category_list_table',
237
-                'capability' => 'ee_manage_event_categories',
238
-            ],
239
-            'preview_deletion'              => [
240
-                'func'       => 'previewDeletion',
241
-                'capability' => 'ee_delete_events',
242
-            ],
243
-            'confirm_deletion'              => [
244
-                'func'       => 'confirmDeletion',
245
-                'capability' => 'ee_delete_events',
246
-                'noheader'   => true,
247
-            ],
248
-        ];
249
-    }
250
-
251
-
252
-    /**
253
-     * Set the _page_config property for this admin page group.
254
-     */
255
-    protected function _set_page_config()
256
-    {
257
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
258
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
259
-        $this->_page_config = [
260
-            'default'                => [
261
-                'nav'           => [
262
-                    'label' => esc_html__('Overview', 'event_espresso'),
263
-                    'order' => 10,
264
-                ],
265
-                'list_table'    => 'Events_Admin_List_Table',
266
-                'help_tabs'     => [
267
-                    'events_overview_help_tab'                       => [
268
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
269
-                        'filename' => 'events_overview',
270
-                    ],
271
-                    'events_overview_table_column_headings_help_tab' => [
272
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
273
-                        'filename' => 'events_overview_table_column_headings',
274
-                    ],
275
-                    'events_overview_filters_help_tab'               => [
276
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
277
-                        'filename' => 'events_overview_filters',
278
-                    ],
279
-                    'events_overview_view_help_tab'                  => [
280
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
281
-                        'filename' => 'events_overview_views',
282
-                    ],
283
-                    'events_overview_other_help_tab'                 => [
284
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
285
-                        'filename' => 'events_overview_other',
286
-                    ],
287
-                ],
288
-                'qtips'         => [
289
-                    'EE_Event_List_Table_Tips',
290
-                ],
291
-                'require_nonce' => false,
292
-            ],
293
-            'create_new'             => [
294
-                'nav'           => [
295
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
296
-                    'order'      => 5,
297
-                    'persistent' => false,
298
-                ],
299
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
300
-                'help_tabs'     => [
301
-                    'event_editor_help_tab'                            => [
302
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
303
-                        'filename' => 'event_editor',
304
-                    ],
305
-                    'event_editor_title_richtexteditor_help_tab'       => [
306
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
307
-                        'filename' => 'event_editor_title_richtexteditor',
308
-                    ],
309
-                    'event_editor_venue_details_help_tab'              => [
310
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
311
-                        'filename' => 'event_editor_venue_details',
312
-                    ],
313
-                    'event_editor_event_datetimes_help_tab'            => [
314
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
315
-                        'filename' => 'event_editor_event_datetimes',
316
-                    ],
317
-                    'event_editor_event_tickets_help_tab'              => [
318
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
319
-                        'filename' => 'event_editor_event_tickets',
320
-                    ],
321
-                    'event_editor_event_registration_options_help_tab' => [
322
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
323
-                        'filename' => 'event_editor_event_registration_options',
324
-                    ],
325
-                    'event_editor_tags_categories_help_tab'            => [
326
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
327
-                        'filename' => 'event_editor_tags_categories',
328
-                    ],
329
-                    'event_editor_questions_registrants_help_tab'      => [
330
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
331
-                        'filename' => 'event_editor_questions_registrants',
332
-                    ],
333
-                    'event_editor_save_new_event_help_tab'             => [
334
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
335
-                        'filename' => 'event_editor_save_new_event',
336
-                    ],
337
-                    'event_editor_other_help_tab'                      => [
338
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
339
-                        'filename' => 'event_editor_other',
340
-                    ],
341
-                ],
342
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
343
-                'require_nonce' => false,
344
-            ],
345
-            'edit'                   => [
346
-                'nav'           => [
347
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
348
-                    'order'      => 5,
349
-                    'persistent' => false,
350
-                    'url'        => $post_id
351
-                        ? EE_Admin_Page::add_query_args_and_nonce(
352
-                            ['post' => $post_id, 'action' => 'edit'],
353
-                            $this->_current_page_view_url
354
-                        )
355
-                        : $this->_admin_base_url,
356
-                ],
357
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
358
-                'help_tabs'     => [
359
-                    'event_editor_help_tab'                            => [
360
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
361
-                        'filename' => 'event_editor',
362
-                    ],
363
-                    'event_editor_title_richtexteditor_help_tab'       => [
364
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
365
-                        'filename' => 'event_editor_title_richtexteditor',
366
-                    ],
367
-                    'event_editor_venue_details_help_tab'              => [
368
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
369
-                        'filename' => 'event_editor_venue_details',
370
-                    ],
371
-                    'event_editor_event_datetimes_help_tab'            => [
372
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
373
-                        'filename' => 'event_editor_event_datetimes',
374
-                    ],
375
-                    'event_editor_event_tickets_help_tab'              => [
376
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
377
-                        'filename' => 'event_editor_event_tickets',
378
-                    ],
379
-                    'event_editor_event_registration_options_help_tab' => [
380
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
381
-                        'filename' => 'event_editor_event_registration_options',
382
-                    ],
383
-                    'event_editor_tags_categories_help_tab'            => [
384
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
385
-                        'filename' => 'event_editor_tags_categories',
386
-                    ],
387
-                    'event_editor_questions_registrants_help_tab'      => [
388
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
389
-                        'filename' => 'event_editor_questions_registrants',
390
-                    ],
391
-                    'event_editor_save_new_event_help_tab'             => [
392
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
393
-                        'filename' => 'event_editor_save_new_event',
394
-                    ],
395
-                    'event_editor_other_help_tab'                      => [
396
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
397
-                        'filename' => 'event_editor_other',
398
-                    ],
399
-                ],
400
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
401
-                'require_nonce' => false,
402
-            ],
403
-            'default_event_settings' => [
404
-                'nav'           => [
405
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
406
-                    'order' => 40,
407
-                ],
408
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
409
-                'labels'        => [
410
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
411
-                ],
412
-                'help_tabs'     => [
413
-                    'default_settings_help_tab'        => [
414
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
415
-                        'filename' => 'events_default_settings',
416
-                    ],
417
-                    'default_settings_status_help_tab' => [
418
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
419
-                        'filename' => 'events_default_settings_status',
420
-                    ],
421
-                    'default_maximum_tickets_help_tab' => [
422
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
423
-                        'filename' => 'events_default_settings_max_tickets',
424
-                    ],
425
-                ],
426
-                'require_nonce' => false,
427
-            ],
428
-            // template settings
429
-            'template_settings'      => [
430
-                'nav'           => [
431
-                    'label' => esc_html__('Templates', 'event_espresso'),
432
-                    'order' => 30,
433
-                ],
434
-                'metaboxes'     => $this->_default_espresso_metaboxes,
435
-                'help_tabs'     => [
436
-                    'general_settings_templates_help_tab' => [
437
-                        'title'    => esc_html__('Templates', 'event_espresso'),
438
-                        'filename' => 'general_settings_templates',
439
-                    ],
440
-                ],
441
-                'require_nonce' => false,
442
-            ],
443
-            // event category stuff
444
-            'add_category'           => [
445
-                'nav'           => [
446
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
447
-                    'order'      => 15,
448
-                    'persistent' => false,
449
-                ],
450
-                'help_tabs'     => [
451
-                    'add_category_help_tab' => [
452
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
453
-                        'filename' => 'events_add_category',
454
-                    ],
455
-                ],
456
-                'metaboxes'     => ['_publish_post_box'],
457
-                'require_nonce' => false,
458
-            ],
459
-            'edit_category'          => [
460
-                'nav'           => [
461
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
462
-                    'order'      => 15,
463
-                    'persistent' => false,
464
-                    'url'        => $EVT_CAT_ID
465
-                        ? add_query_arg(
466
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
467
-                            $this->_current_page_view_url
468
-                        )
469
-                        : $this->_admin_base_url,
470
-                ],
471
-                'help_tabs'     => [
472
-                    'edit_category_help_tab' => [
473
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
474
-                        'filename' => 'events_edit_category',
475
-                    ],
476
-                ],
477
-                'metaboxes'     => ['_publish_post_box'],
478
-                'require_nonce' => false,
479
-            ],
480
-            'category_list'          => [
481
-                'nav'           => [
482
-                    'label' => esc_html__('Categories', 'event_espresso'),
483
-                    'order' => 20,
484
-                ],
485
-                'list_table'    => 'Event_Categories_Admin_List_Table',
486
-                'help_tabs'     => [
487
-                    'events_categories_help_tab'                       => [
488
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
489
-                        'filename' => 'events_categories',
490
-                    ],
491
-                    'events_categories_table_column_headings_help_tab' => [
492
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
493
-                        'filename' => 'events_categories_table_column_headings',
494
-                    ],
495
-                    'events_categories_view_help_tab'                  => [
496
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
497
-                        'filename' => 'events_categories_views',
498
-                    ],
499
-                    'events_categories_other_help_tab'                 => [
500
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
501
-                        'filename' => 'events_categories_other',
502
-                    ],
503
-                ],
504
-                'metaboxes'     => $this->_default_espresso_metaboxes,
505
-                'require_nonce' => false,
506
-            ],
507
-            'preview_deletion'       => [
508
-                'nav'           => [
509
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
510
-                    'order'      => 15,
511
-                    'persistent' => false,
512
-                    'url'        => '',
513
-                ],
514
-                'require_nonce' => false,
515
-            ],
516
-        ];
517
-    }
518
-
519
-
520
-    /**
521
-     * Used to register any global screen options if necessary for every route in this admin page group.
522
-     */
523
-    protected function _add_screen_options()
524
-    {
525
-    }
526
-
527
-
528
-    /**
529
-     * Implementing the screen options for the 'default' route.
530
-     */
531
-    protected function _add_screen_options_default()
532
-    {
533
-        $this->_per_page_screen_option();
534
-    }
535
-
536
-
537
-    /**
538
-     * Implementing screen options for the category list route.
539
-     */
540
-    protected function _add_screen_options_category_list()
541
-    {
542
-        $page_title              = $this->_admin_page_title;
543
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
544
-        $this->_per_page_screen_option();
545
-        $this->_admin_page_title = $page_title;
546
-    }
547
-
548
-
549
-    /**
550
-     * Used to register any global feature pointers for the admin page group.
551
-     */
552
-    protected function _add_feature_pointers()
553
-    {
554
-    }
555
-
556
-
557
-    /**
558
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
559
-     */
560
-    public function load_scripts_styles()
561
-    {
562
-        wp_register_style(
563
-            'events-admin-css',
564
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
565
-            [],
566
-            EVENT_ESPRESSO_VERSION
567
-        );
568
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
569
-        wp_enqueue_style('events-admin-css');
570
-        wp_enqueue_style('ee-cat-admin');
571
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
572
-        // registers for all views
573
-        // scripts
574
-        wp_register_script(
575
-            'event_editor_js',
576
-            EVENTS_ASSETS_URL . 'event_editor.js',
577
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
578
-            EVENT_ESPRESSO_VERSION,
579
-            true
580
-        );
581
-    }
582
-
583
-
584
-    /**
585
-     * Enqueuing scripts and styles specific to this view
586
-     */
587
-    public function load_scripts_styles_create_new()
588
-    {
589
-        $this->load_scripts_styles_edit();
590
-    }
591
-
592
-
593
-    /**
594
-     * Enqueuing scripts and styles specific to this view
595
-     */
596
-    public function load_scripts_styles_edit()
597
-    {
598
-        // styles
599
-        wp_enqueue_style('espresso-ui-theme');
600
-        wp_register_style(
601
-            'event-editor-css',
602
-            EVENTS_ASSETS_URL . 'event-editor.css',
603
-            ['ee-admin-css'],
604
-            EVENT_ESPRESSO_VERSION
605
-        );
606
-        wp_enqueue_style('event-editor-css');
607
-        // scripts
608
-        wp_register_script(
609
-            'event-datetime-metabox',
610
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
611
-            ['event_editor_js', 'ee-datepicker'],
612
-            EVENT_ESPRESSO_VERSION
613
-        );
614
-        wp_enqueue_script('event-datetime-metabox');
615
-    }
616
-
617
-
618
-    /**
619
-     * Populating the _views property for the category list table view.
620
-     */
621
-    protected function _set_list_table_views_category_list()
622
-    {
623
-        $this->_views = [
624
-            'all' => [
625
-                'slug'        => 'all',
626
-                'label'       => esc_html__('All', 'event_espresso'),
627
-                'count'       => 0,
628
-                'bulk_action' => [
629
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
630
-                ],
631
-            ],
632
-        ];
633
-    }
634
-
635
-
636
-    /**
637
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
638
-     */
639
-    public function admin_init()
640
-    {
641
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
642
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
643
-            'event_espresso'
644
-        );
645
-    }
646
-
647
-
648
-    /**
649
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
650
-     * group.
651
-     */
652
-    public function admin_notices()
653
-    {
654
-    }
655
-
656
-
657
-    /**
658
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
659
-     * this admin page group.
660
-     */
661
-    public function admin_footer_scripts()
662
-    {
663
-    }
664
-
665
-
666
-    /**
667
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
668
-     * warning (via EE_Error::add_error());
669
-     *
670
-     * @param EE_Event $event Event object
671
-     * @param string   $req_type
672
-     * @return void
673
-     * @throws EE_Error
674
-     * @throws ReflectionException
675
-     */
676
-    public function verify_event_edit($event = null, $req_type = '')
677
-    {
678
-        // don't need to do this when processing
679
-        if (! empty($req_type)) {
680
-            return;
681
-        }
682
-        // no event?
683
-        if (empty($event)) {
684
-            // set event
685
-            $event = $this->_cpt_model_obj;
686
-        }
687
-        // STILL no event?
688
-        if (! $event instanceof EE_Event) {
689
-            return;
690
-        }
691
-        $orig_status = $event->status();
692
-        // first check if event is active.
693
-        if (
694
-            $orig_status === EEM_Event::cancelled
695
-            || $orig_status === EEM_Event::postponed
696
-            || $event->is_expired()
697
-            || $event->is_inactive()
698
-        ) {
699
-            return;
700
-        }
701
-        // made it here so it IS active... next check that any of the tickets are sold.
702
-        if ($event->is_sold_out(true)) {
703
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
704
-                EE_Error::add_attention(
705
-                    sprintf(
706
-                        esc_html__(
707
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
708
-                            'event_espresso'
709
-                        ),
710
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
711
-                    )
712
-                );
713
-            }
714
-            return;
715
-        } elseif ($orig_status === EEM_Event::sold_out) {
716
-            EE_Error::add_attention(
717
-                sprintf(
718
-                    esc_html__(
719
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
720
-                        'event_espresso'
721
-                    ),
722
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
723
-                )
724
-            );
725
-        }
726
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
727
-        if (! $event->tickets_on_sale()) {
728
-            return;
729
-        }
730
-        // made it here so show warning
731
-        $this->_edit_event_warning();
732
-    }
733
-
734
-
735
-    /**
736
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
737
-     * When needed, hook this into a EE_Error::add_error() notice.
738
-     *
739
-     * @access protected
740
-     * @return void
741
-     */
742
-    protected function _edit_event_warning()
743
-    {
744
-        // we don't want to add warnings during these requests
745
-        if ($this->request->getRequestParam('action') === 'editpost') {
746
-            return;
747
-        }
748
-        EE_Error::add_attention(
749
-            sprintf(
750
-                esc_html__(
751
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
752
-                    'event_espresso'
753
-                ),
754
-                '<a class="espresso-help-tab-lnk">',
755
-                '</a>'
756
-            )
757
-        );
758
-    }
759
-
760
-
761
-    /**
762
-     * When a user is creating a new event, notify them if they haven't set their timezone.
763
-     * Otherwise, do the normal logic
764
-     *
765
-     * @return void
766
-     * @throws EE_Error
767
-     */
768
-    protected function _create_new_cpt_item()
769
-    {
770
-        $has_timezone_string = get_option('timezone_string');
771
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
772
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
773
-            EE_Error::add_attention(
774
-                sprintf(
775
-                    esc_html__(
776
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
777
-                        'event_espresso'
778
-                    ),
779
-                    '<br>',
780
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
781
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
782
-                    . '</select>',
783
-                    '<button class="button button-secondary timezone-submit">',
784
-                    '</button><span class="spinner"></span>'
785
-                ),
786
-                __FILE__,
787
-                __FUNCTION__,
788
-                __LINE__
789
-            );
790
-        }
791
-        parent::_create_new_cpt_item();
792
-    }
793
-
794
-
795
-    /**
796
-     * Sets the _views property for the default route in this admin page group.
797
-     */
798
-    protected function _set_list_table_views_default()
799
-    {
800
-        $this->_views = [
801
-            'all'   => [
802
-                'slug'        => 'all',
803
-                'label'       => esc_html__('View All Events', 'event_espresso'),
804
-                'count'       => 0,
805
-                'bulk_action' => [
806
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
807
-                ],
808
-            ],
809
-            'draft' => [
810
-                'slug'        => 'draft',
811
-                'label'       => esc_html__('Draft', 'event_espresso'),
812
-                'count'       => 0,
813
-                'bulk_action' => [
814
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
815
-                ],
816
-            ],
817
-        ];
818
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
819
-            $this->_views['trash'] = [
820
-                'slug'        => 'trash',
821
-                'label'       => esc_html__('Trash', 'event_espresso'),
822
-                'count'       => 0,
823
-                'bulk_action' => [
824
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
825
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
826
-                ],
827
-            ];
828
-        }
829
-    }
830
-
831
-
832
-    /**
833
-     * Provides the legend item array for the default list table view.
834
-     *
835
-     * @return array
836
-     * @throws EE_Error
837
-     * @throws EE_Error
838
-     */
839
-    protected function _event_legend_items()
840
-    {
841
-        $items    = [
842
-            'view_details'   => [
843
-                'class' => 'dashicons dashicons-search',
844
-                'desc'  => esc_html__('View Event', 'event_espresso'),
845
-            ],
846
-            'edit_event'     => [
847
-                'class' => 'ee-icon ee-icon-calendar-edit',
848
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
849
-            ],
850
-            'view_attendees' => [
851
-                'class' => 'dashicons dashicons-groups',
852
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
853
-            ],
854
-        ];
855
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
856
-        $statuses = [
857
-            'sold_out_status'  => [
858
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
859
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
860
-            ],
861
-            'active_status'    => [
862
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
863
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
864
-            ],
865
-            'upcoming_status'  => [
866
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
867
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
868
-            ],
869
-            'postponed_status' => [
870
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
871
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
872
-            ],
873
-            'cancelled_status' => [
874
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
875
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
876
-            ],
877
-            'expired_status'   => [
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
879
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
880
-            ],
881
-            'inactive_status'  => [
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
883
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
884
-            ],
885
-        ];
886
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
887
-        return array_merge($items, $statuses);
888
-    }
889
-
890
-
891
-    /**
892
-     * @return EEM_Event
893
-     * @throws EE_Error
894
-     * @throws ReflectionException
895
-     */
896
-    private function _event_model()
897
-    {
898
-        if (! $this->_event_model instanceof EEM_Event) {
899
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
900
-        }
901
-        return $this->_event_model;
902
-    }
903
-
904
-
905
-    /**
906
-     * Adds extra buttons to the WP CPT permalink field row.
907
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
908
-     *
909
-     * @param string $return    the current html
910
-     * @param int    $id        the post id for the page
911
-     * @param string $new_title What the title is
912
-     * @param string $new_slug  what the slug is
913
-     * @return string            The new html string for the permalink area
914
-     */
915
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
916
-    {
917
-        // make sure this is only when editing
918
-        if (! empty($id)) {
919
-            $post   = get_post($id);
920
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
921
-                       . esc_html__('Shortcode', 'event_espresso')
922
-                       . '</a> ';
923
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
924
-                       . $post->ID
925
-                       . ']">';
926
-        }
927
-        return $return;
928
-    }
929
-
930
-
931
-    /**
932
-     * _events_overview_list_table
933
-     * This contains the logic for showing the events_overview list
934
-     *
935
-     * @access protected
936
-     * @return void
937
-     * @throws EE_Error
938
-     */
939
-    protected function _events_overview_list_table()
940
-    {
941
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
942
-        $this->_template_args['after_list_table']                           =
943
-            ! empty($this->_template_args['after_list_table'])
944
-                ? (array) $this->_template_args['after_list_table']
945
-                : [];
946
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
947
-            . EEH_Template::get_button_or_link(
948
-                get_post_type_archive_link('espresso_events'),
949
-                esc_html__("View Event Archive Page", "event_espresso"),
950
-                'button'
951
-            );
952
-        $this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
953
-            $this->_event_legend_items()
954
-        );
955
-        $this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
956
-            'create_new',
957
-            'add',
958
-            [],
959
-            'add-new-h2'
960
-        );
961
-        $this->display_admin_list_table_page_with_no_sidebar();
962
-    }
963
-
964
-
965
-    /**
966
-     * this allows for extra misc actions in the default WP publish box
967
-     *
968
-     * @return void
969
-     * @throws EE_Error
970
-     * @throws ReflectionException
971
-     */
972
-    public function extra_misc_actions_publish_box()
973
-    {
974
-        $this->_generate_publish_box_extra_content();
975
-    }
976
-
977
-
978
-    /**
979
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
980
-     * saved.
981
-     * Typically you would use this to save any additional data.
982
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
983
-     * ALSO very important.  When a post transitions from scheduled to published,
984
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
985
-     * other meta saves. So MAKE sure that you handle this accordingly.
986
-     *
987
-     * @access protected
988
-     * @abstract
989
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
990
-     * @param WP_Post $post    The post object of the cpt that was saved.
991
-     * @return void
992
-     * @throws EE_Error
993
-     * @throws ReflectionException
994
-     */
995
-    protected function _insert_update_cpt_item($post_id, $post)
996
-    {
997
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
998
-            // get out we're not processing an event save.
999
-            return;
1000
-        }
1001
-
1002
-        $event_values = [
1003
-            'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1004
-            'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1005
-                'display_ticket_selector',
1006
-                false,
1007
-                'bool'
1008
-            ),
1009
-            'EVT_additional_limit'            => min(
1010
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1011
-                $this->request->getRequestParam('additional_limit', null, 'int')
1012
-            ),
1013
-            'EVT_default_registration_status' => $this->request->getRequestParam(
1014
-                'EVT_default_registration_status',
1015
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1016
-            ),
1017
-
1018
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1019
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1020
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1021
-            'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1022
-            'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1023
-        ];
1024
-        // update event
1025
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1026
-        // get event_object for other metaboxes...
1027
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1028
-        // i have to setup where conditions to override the filters in the model
1029
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1030
-        $event = $this->_event_model()->get_one(
1031
-            [
1032
-                [
1033
-                    $this->_event_model()->primary_key_name() => $post_id,
1034
-                    'OR'                                      => [
1035
-                        'status'   => $post->post_status,
1036
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1037
-                        // but the returned object here has a status of "publish", so use the original post status as well
1038
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1039
-                    ],
1040
-                ],
1041
-            ]
1042
-        );
1043
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1044
-        $event_update_callbacks = apply_filters(
1045
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1046
-            [
1047
-                [$this, '_default_venue_update'],
1048
-                [$this, '_default_tickets_update'],
1049
-            ]
1050
-        );
1051
-        $att_success            = true;
1052
-        foreach ($event_update_callbacks as $e_callback) {
1053
-            $_success = is_callable($e_callback)
1054
-                ? call_user_func($e_callback, $event, $this->request->requestParams())
1055
-                : false;
1056
-            // if ANY of these updates fail then we want the appropriate global error message
1057
-            $att_success = ! $att_success ? $att_success : $_success;
1058
-        }
1059
-        // any errors?
1060
-        if ($success && false === $att_success) {
1061
-            EE_Error::add_error(
1062
-                esc_html__(
1063
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1064
-                    'event_espresso'
1065
-                ),
1066
-                __FILE__,
1067
-                __FUNCTION__,
1068
-                __LINE__
1069
-            );
1070
-        } elseif ($success === false) {
1071
-            EE_Error::add_error(
1072
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1073
-                __FILE__,
1074
-                __FUNCTION__,
1075
-                __LINE__
1076
-            );
1077
-        }
1078
-    }
1079
-
1080
-
1081
-    /**
1082
-     * @param int $post_id
1083
-     * @param int $revision_id
1084
-     * @throws EE_Error
1085
-     * @throws EE_Error
1086
-     * @throws ReflectionException
1087
-     * @see parent::restore_item()
1088
-     */
1089
-    protected function _restore_cpt_item($post_id, $revision_id)
1090
-    {
1091
-        // copy existing event meta to new post
1092
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1093
-        if ($post_evt instanceof EE_Event) {
1094
-            // meta revision restore
1095
-            $post_evt->restore_revision($revision_id);
1096
-            // related objs restore
1097
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1098
-        }
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * Attach the venue to the Event
1104
-     *
1105
-     * @param EE_Event $event Event Object to add the venue to
1106
-     * @param array    $data  The request data from the form
1107
-     * @return bool           Success or fail.
1108
-     * @throws EE_Error
1109
-     * @throws ReflectionException
1110
-     */
1111
-    protected function _default_venue_update(EE_Event $event, $data)
1112
-    {
1113
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1114
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1115
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1116
-        // very important.  If we don't have a venue name...
1117
-        // then we'll get out because not necessary to create empty venue
1118
-        if (empty($data['venue_title'])) {
1119
-            return false;
1120
-        }
1121
-        $venue_array = [
1122
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1123
-            'VNU_name'            => $data['venue_title'],
1124
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1125
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1126
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1127
-                ? $data['venue_short_description']
1128
-                : null,
1129
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1130
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1131
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1132
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1133
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1134
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1135
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1136
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1137
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1138
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1139
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1140
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1141
-            'status'              => 'publish',
1142
-        ];
1143
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1144
-        if (! empty($venue_id)) {
1145
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1146
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1147
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1148
-            $event->_add_relation_to($venue_id, 'Venue');
1149
-            return $rows_affected > 0;
1150
-        }
1151
-        // we insert the venue
1152
-        $venue_id = $venue_model->insert($venue_array);
1153
-        $event->_add_relation_to($venue_id, 'Venue');
1154
-        return ! empty($venue_id);
1155
-        // when we have the ancestor come in it's already been handled by the revision save.
1156
-    }
1157
-
1158
-
1159
-    /**
1160
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1161
-     *
1162
-     * @param EE_Event $event The Event object we're attaching data to
1163
-     * @param array    $data  The request data from the form
1164
-     * @return array
1165
-     * @throws EE_Error
1166
-     * @throws ReflectionException
1167
-     * @throws Exception
1168
-     */
1169
-    protected function _default_tickets_update(EE_Event $event, $data)
1170
-    {
1171
-        $datetime       = null;
1172
-        $saved_tickets  = [];
1173
-        $event_timezone = $event->get_timezone();
1174
-        $date_formats   = ['Y-m-d', 'h:i a'];
1175
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1176
-            // trim all values to ensure any excess whitespace is removed.
1177
-            $datetime_data                = array_map('trim', $datetime_data);
1178
-            $datetime_data['DTT_EVT_end'] =
1179
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1180
-                    ? $datetime_data['DTT_EVT_end']
1181
-                    : $datetime_data['DTT_EVT_start'];
1182
-            $datetime_values              = [
1183
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1184
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1185
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1186
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1187
-                'DTT_order'     => $row,
1188
-            ];
1189
-            // if we have an id then let's get existing object first and then set the new values.
1190
-            //  Otherwise we instantiate a new object for save.
1191
-            if (! empty($datetime_data['DTT_ID'])) {
1192
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1193
-                if (! $datetime instanceof EE_Datetime) {
1194
-                    throw new RuntimeException(
1195
-                        sprintf(
1196
-                            esc_html__(
1197
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1198
-                                'event_espresso'
1199
-                            ),
1200
-                            $datetime_data['DTT_ID']
1201
-                        )
1202
-                    );
1203
-                }
1204
-                $datetime->set_date_format($date_formats[0]);
1205
-                $datetime->set_time_format($date_formats[1]);
1206
-                foreach ($datetime_values as $field => $value) {
1207
-                    $datetime->set($field, $value);
1208
-                }
1209
-            } else {
1210
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1211
-            }
1212
-            if (! $datetime instanceof EE_Datetime) {
1213
-                throw new RuntimeException(
1214
-                    sprintf(
1215
-                        esc_html__(
1216
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1217
-                            'event_espresso'
1218
-                        ),
1219
-                        print_r($datetime_values, true)
1220
-                    )
1221
-                );
1222
-            }
1223
-            // before going any further make sure our dates are setup correctly
1224
-            // so that the end date is always equal or greater than the start date.
1225
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1226
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1227
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1228
-            }
1229
-            $datetime->save();
1230
-            $event->_add_relation_to($datetime, 'Datetime');
1231
-        }
1232
-        // no datetimes get deleted so we don't do any of that logic here.
1233
-        // update tickets next
1234
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1235
-
1236
-        // set up some default start and end dates in case those are not present in the incoming data
1237
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1238
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1239
-        // use the start date of the first datetime for the end date
1240
-        $first_datetime   = $event->first_datetime();
1241
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1242
-
1243
-        // now process the incoming data
1244
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1245
-            $update_prices = false;
1246
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1247
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1248
-                : 0;
1249
-            // trim inputs to ensure any excess whitespace is removed.
1250
-            $ticket_data   = array_map('trim', $ticket_data);
1251
-            $ticket_values = [
1252
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1253
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1254
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1255
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1256
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1257
-                    ? $ticket_data['TKT_start_date']
1258
-                    : $default_start_date,
1259
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1260
-                    ? $ticket_data['TKT_end_date']
1261
-                    : $default_end_date,
1262
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1263
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1264
-                    ? $ticket_data['TKT_qty']
1265
-                    : EE_INF,
1266
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1267
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1268
-                    ? $ticket_data['TKT_uses']
1269
-                    : EE_INF,
1270
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1271
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1272
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1273
-                'TKT_price'       => $ticket_price,
1274
-                'TKT_row'         => $row,
1275
-            ];
1276
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1277
-            // which means in turn that the prices will become new prices as well.
1278
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1279
-                $ticket_values['TKT_ID']         = 0;
1280
-                $ticket_values['TKT_is_default'] = 0;
1281
-                $update_prices                   = true;
1282
-            }
1283
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1284
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1285
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1286
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1287
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1288
-            if (! empty($ticket_data['TKT_ID'])) {
1289
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1290
-                if (! $existing_ticket instanceof EE_Ticket) {
1291
-                    throw new RuntimeException(
1292
-                        sprintf(
1293
-                            esc_html__(
1294
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1295
-                                'event_espresso'
1296
-                            ),
1297
-                            $ticket_data['TKT_ID']
1298
-                        )
1299
-                    );
1300
-                }
1301
-                $ticket_sold = $existing_ticket->count_related(
1302
-                    'Registration',
1303
-                    [
1304
-                        [
1305
-                            'STS_ID' => [
1306
-                                'NOT IN',
1307
-                                [EEM_Registration::status_id_incomplete],
1308
-                            ],
1309
-                        ],
1310
-                    ]
1311
-                ) > 0;
1312
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1313
-                // if they are different then we create a new ticket (if $ticket_sold)
1314
-                // if they aren't different then we go ahead and modify existing ticket.
1315
-                $create_new_ticket = $ticket_sold
1316
-                                     && $ticket_price !== $existing_ticket->price()
1317
-                                     && ! $existing_ticket->deleted();
1318
-                $existing_ticket->set_date_format($date_formats[0]);
1319
-                $existing_ticket->set_time_format($date_formats[1]);
1320
-                // set new values
1321
-                foreach ($ticket_values as $field => $value) {
1322
-                    if ($field == 'TKT_qty') {
1323
-                        $existing_ticket->set_qty($value);
1324
-                    } elseif ($field == 'TKT_price') {
1325
-                        $existing_ticket->set('TKT_price', $ticket_price);
1326
-                    } else {
1327
-                        $existing_ticket->set($field, $value);
1328
-                    }
1329
-                }
1330
-                $ticket = $existing_ticket;
1331
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1332
-                //  Otherwise we have to create a new ticket.
1333
-                if ($create_new_ticket) {
1334
-                    // archive the old ticket first
1335
-                    $existing_ticket->set('TKT_deleted', 1);
1336
-                    $existing_ticket->save();
1337
-                    // make sure this ticket is still recorded in our $saved_tickets
1338
-                    // so we don't run it through the regular trash routine.
1339
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1340
-                    // create new ticket that's a copy of the existing except,
1341
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1342
-                    $new_ticket = clone $existing_ticket;
1343
-                    $new_ticket->set('TKT_ID', 0);
1344
-                    $new_ticket->set('TKT_deleted', 0);
1345
-                    $new_ticket->set('TKT_sold', 0);
1346
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1347
-                    $update_prices = true;
1348
-                    $ticket        = $new_ticket;
1349
-                }
1350
-            } else {
1351
-                // no TKT_id so a new ticket
1352
-                $ticket_values['TKT_price'] = $ticket_price;
1353
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1354
-                $update_prices              = true;
1355
-            }
1356
-            if (! $ticket instanceof EE_Ticket) {
1357
-                throw new RuntimeException(
1358
-                    sprintf(
1359
-                        esc_html__(
1360
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1361
-                            'event_espresso'
1362
-                        ),
1363
-                        print_r($ticket_values, true)
1364
-                    )
1365
-                );
1366
-            }
1367
-            // cap ticket qty by datetime reg limits
1368
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1369
-            // update ticket.
1370
-            $ticket->save();
1371
-            // before going any further make sure our dates are setup correctly
1372
-            // so that the end date is always equal or greater than the start date.
1373
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1374
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1375
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1376
-                $ticket->save();
1377
-            }
1378
-            // initially let's add the ticket to the datetime
1379
-            $datetime->_add_relation_to($ticket, 'Ticket');
1380
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1381
-            // add prices to ticket
1382
-            $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1383
-                ? $data['edit_prices'][ $row ]
1384
-                : [];
1385
-            $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1386
-        }
1387
-        // however now we need to handle permanently deleting tickets via the ui.
1388
-        // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1389
-        // However, it does allow for deleting tickets that have no tickets sold,
1390
-        // in which case we want to get rid of permanently because there is no need to save in db.
1391
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1392
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1393
-        foreach ($tickets_removed as $id) {
1394
-            $id = absint($id);
1395
-            // get the ticket for this id
1396
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1397
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1398
-                continue;
1399
-            }
1400
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1401
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1402
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1403
-            foreach ($related_datetimes as $related_datetime) {
1404
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1405
-            }
1406
-            // need to do the same for prices (except these prices can also be deleted because again,
1407
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1408
-            $ticket_to_remove->delete_related_permanently('Price');
1409
-            // finally let's delete this ticket
1410
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1411
-            $ticket_to_remove->delete_permanently();
1412
-        }
1413
-        return [$datetime, $saved_tickets];
1414
-    }
1415
-
1416
-
1417
-    /**
1418
-     * This attaches a list of given prices to a ticket.
1419
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1420
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1421
-     * price info and prices are automatically "archived" via the ticket.
1422
-     *
1423
-     * @access  private
1424
-     * @param array     $prices_data Array of prices from the form.
1425
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1426
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1427
-     * @return  void
1428
-     * @throws EE_Error
1429
-     * @throws ReflectionException
1430
-     */
1431
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1432
-    {
1433
-        $timezone = $ticket->get_timezone();
1434
-        foreach ($prices_data as $row => $price_data) {
1435
-            $price_values = [
1436
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1437
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1438
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1439
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1440
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1441
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1442
-                'PRC_order'      => $row,
1443
-            ];
1444
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1445
-                $price_values['PRC_ID'] = 0;
1446
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1447
-            } else {
1448
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1449
-                // update this price with new values
1450
-                foreach ($price_values as $field => $new_price) {
1451
-                    $price->set($field, $new_price);
1452
-                }
1453
-            }
1454
-            if (! $price instanceof EE_Price) {
1455
-                throw new RuntimeException(
1456
-                    sprintf(
1457
-                        esc_html__(
1458
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1459
-                            'event_espresso'
1460
-                        ),
1461
-                        print_r($price_values, true)
1462
-                    )
1463
-                );
1464
-            }
1465
-            $price->save();
1466
-            $ticket->_add_relation_to($price, 'Price');
1467
-        }
1468
-    }
1469
-
1470
-
1471
-    /**
1472
-     * Add in our autosave ajax handlers
1473
-     *
1474
-     */
1475
-    protected function _ee_autosave_create_new()
1476
-    {
1477
-    }
1478
-
1479
-
1480
-    /**
1481
-     * More autosave handlers.
1482
-     */
1483
-    protected function _ee_autosave_edit()
1484
-    {
1485
-        // TEMPORARILY EXITING CAUSE THIS IS A TODO
1486
-    }
1487
-
1488
-
1489
-    /**
1490
-     * @throws EE_Error
1491
-     * @throws ReflectionException
1492
-     */
1493
-    private function _generate_publish_box_extra_content()
1494
-    {
1495
-        // load formatter helper
1496
-        // args for getting related registrations
1497
-        $approved_query_args        = [
1498
-            [
1499
-                'REG_deleted' => 0,
1500
-                'STS_ID'      => EEM_Registration::status_id_approved,
1501
-            ],
1502
-        ];
1503
-        $not_approved_query_args    = [
1504
-            [
1505
-                'REG_deleted' => 0,
1506
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1507
-            ],
1508
-        ];
1509
-        $pending_payment_query_args = [
1510
-            [
1511
-                'REG_deleted' => 0,
1512
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1513
-            ],
1514
-        ];
1515
-        // publish box
1516
-        $publish_box_extra_args = [
1517
-            'view_approved_reg_url'        => add_query_arg(
1518
-                [
1519
-                    'action'      => 'default',
1520
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1521
-                    '_reg_status' => EEM_Registration::status_id_approved,
1522
-                    'use_filters' => true,
1523
-                ],
1524
-                REG_ADMIN_URL
1525
-            ),
1526
-            'view_not_approved_reg_url'    => add_query_arg(
1527
-                [
1528
-                    'action'      => 'default',
1529
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1530
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1531
-                    'use_filters' => true,
1532
-                ],
1533
-                REG_ADMIN_URL
1534
-            ),
1535
-            'view_pending_payment_reg_url' => add_query_arg(
1536
-                [
1537
-                    'action'      => 'default',
1538
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1539
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1540
-                    'use_filters' => true,
1541
-                ],
1542
-                REG_ADMIN_URL
1543
-            ),
1544
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1545
-                'Registration',
1546
-                $approved_query_args
1547
-            ),
1548
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1549
-                'Registration',
1550
-                $not_approved_query_args
1551
-            ),
1552
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1553
-                'Registration',
1554
-                $pending_payment_query_args
1555
-            ),
1556
-            'misc_pub_section_class'       => apply_filters(
1557
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1558
-                'misc-pub-section'
1559
-            ),
1560
-        ];
1561
-        ob_start();
1562
-        do_action(
1563
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1564
-            $this->_cpt_model_obj
1565
-        );
1566
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1567
-        // load template
1568
-        EEH_Template::display_template(
1569
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1570
-            $publish_box_extra_args
1571
-        );
1572
-    }
1573
-
1574
-
1575
-    /**
1576
-     * @return EE_Event
1577
-     */
1578
-    public function get_event_object()
1579
-    {
1580
-        return $this->_cpt_model_obj;
1581
-    }
1582
-
1583
-
1584
-
1585
-
1586
-    /** METABOXES * */
1587
-    /**
1588
-     * _register_event_editor_meta_boxes
1589
-     * add all metaboxes related to the event_editor
1590
-     *
1591
-     * @return void
1592
-     * @throws EE_Error
1593
-     * @throws ReflectionException
1594
-     */
1595
-    protected function _register_event_editor_meta_boxes()
1596
-    {
1597
-        $this->verify_cpt_object();
1598
-        add_meta_box(
1599
-            'espresso_event_editor_tickets',
1600
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1601
-            [$this, 'ticket_metabox'],
1602
-            $this->page_slug,
1603
-            'normal',
1604
-            'high'
1605
-        );
1606
-        add_meta_box(
1607
-            'espresso_event_editor_event_options',
1608
-            esc_html__('Event Registration Options', 'event_espresso'),
1609
-            [$this, 'registration_options_meta_box'],
1610
-            $this->page_slug,
1611
-            'side'
1612
-        );
1613
-        // NOTE: if you're looking for other metaboxes in here,
1614
-        // where a metabox has a related management page in the admin
1615
-        // you will find it setup in the related management page's "_Hooks" file.
1616
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1617
-    }
1618
-
1619
-
1620
-    /**
1621
-     * @throws DomainException
1622
-     * @throws EE_Error
1623
-     * @throws ReflectionException
1624
-     */
1625
-    public function ticket_metabox()
1626
-    {
1627
-        $existing_datetime_ids = $existing_ticket_ids = [];
1628
-        // defaults for template args
1629
-        $template_args = [
1630
-            'existing_datetime_ids'    => '',
1631
-            'event_datetime_help_link' => '',
1632
-            'ticket_options_help_link' => '',
1633
-            'time'                     => null,
1634
-            'ticket_rows'              => '',
1635
-            'existing_ticket_ids'      => '',
1636
-            'total_ticket_rows'        => 1,
1637
-            'ticket_js_structure'      => '',
1638
-            'trash_icon'               => 'ee-lock-icon',
1639
-            'disabled'                 => '',
1640
-        ];
1641
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1642
-        /**
1643
-         * 1. Start with retrieving Datetimes
1644
-         * 2. Fore each datetime get related tickets
1645
-         * 3. For each ticket get related prices
1646
-         */
1647
-        $times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1648
-        $first_datetime = reset($times);
1649
-        // do we get related tickets?
1650
-        if (
1651
-            $first_datetime instanceof EE_Datetime
1652
-            && $first_datetime->ID() !== 0
1653
-        ) {
1654
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1655
-            $template_args['time']   = $first_datetime;
1656
-            $related_tickets         = $first_datetime->tickets(
1657
-                [
1658
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1659
-                    'default_where_conditions' => 'none',
1660
-                ]
1661
-            );
1662
-            if (! empty($related_tickets)) {
1663
-                $template_args['total_ticket_rows'] = count($related_tickets);
1664
-                $row                                = 0;
1665
-                foreach ($related_tickets as $ticket) {
1666
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1667
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1668
-                    $row++;
1669
-                }
1670
-            } else {
1671
-                $template_args['total_ticket_rows'] = 1;
1672
-                /** @type EE_Ticket $ticket */
1673
-                $ticket                       = EEM_Ticket::instance()->create_default_object();
1674
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1675
-            }
1676
-        } else {
1677
-            $template_args['time']        = $times[0];
1678
-            $tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1679
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1680
-            // NOTE: we're just sending the first default row
1681
-            // (decaf can't manage default tickets so this should be sufficient);
1682
-        }
1683
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1684
-            'event_editor_event_datetimes_help_tab'
1685
-        );
1686
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1687
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1688
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1689
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1690
-            EEM_Ticket::instance()->create_default_object(),
1691
-            true
1692
-        );
1693
-        $template                                  = apply_filters(
1694
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1695
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1696
-        );
1697
-        EEH_Template::display_template($template, $template_args);
1698
-    }
1699
-
1700
-
1701
-    /**
1702
-     * Setup an individual ticket form for the decaf event editor page
1703
-     *
1704
-     * @access private
1705
-     * @param EE_Ticket $ticket   the ticket object
1706
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1707
-     * @param int       $row
1708
-     * @return string generated html for the ticket row.
1709
-     * @throws EE_Error
1710
-     * @throws ReflectionException
1711
-     */
1712
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1713
-    {
1714
-        $template_args = [
1715
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1716
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1717
-                : '',
1718
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1719
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1720
-            'TKT_name'            => $ticket->get('TKT_name'),
1721
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1722
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1723
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1724
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1725
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1726
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1727
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1728
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1729
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1730
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1731
-                : ' disabled=disabled',
1732
-        ];
1733
-        $price         = $ticket->ID() !== 0
1734
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1735
-            : null;
1736
-        $price         = $price instanceof EE_Price
1737
-            ? $price
1738
-            : EEM_Price::instance()->create_default_object();
1739
-        $price_args    = [
1740
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1741
-            'PRC_amount'            => $price->get('PRC_amount'),
1742
-            'PRT_ID'                => $price->get('PRT_ID'),
1743
-            'PRC_ID'                => $price->get('PRC_ID'),
1744
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1745
-        ];
1746
-        // make sure we have default start and end dates if skeleton
1747
-        // handle rows that should NOT be empty
1748
-        if (empty($template_args['TKT_start_date'])) {
1749
-            // if empty then the start date will be now.
1750
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1751
-        }
1752
-        if (empty($template_args['TKT_end_date'])) {
1753
-            // get the earliest datetime (if present);
1754
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1755
-                ? $this->_cpt_model_obj->get_first_related(
1756
-                    'Datetime',
1757
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1758
-                )
1759
-                : null;
1760
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1761
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1762
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1763
-        }
1764
-        $template_args = array_merge($template_args, $price_args);
1765
-        $template      = apply_filters(
1766
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1767
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1768
-            $ticket
1769
-        );
1770
-        return EEH_Template::display_template($template, $template_args, true);
1771
-    }
1772
-
1773
-
1774
-    /**
1775
-     * @throws EE_Error
1776
-     * @throws ReflectionException
1777
-     */
1778
-    public function registration_options_meta_box()
1779
-    {
1780
-        $yes_no_values             = [
1781
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1782
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1783
-        ];
1784
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1785
-            [
1786
-                EEM_Registration::status_id_cancelled,
1787
-                EEM_Registration::status_id_declined,
1788
-                EEM_Registration::status_id_incomplete,
1789
-            ],
1790
-            true
1791
-        );
1792
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1793
-        $template_args['_event']                          = $this->_cpt_model_obj;
1794
-        $template_args['event']                           = $this->_cpt_model_obj;
1795
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1796
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1797
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1798
-            'default_reg_status',
1799
-            $default_reg_status_values,
1800
-            $this->_cpt_model_obj->default_registration_status()
1801
-        );
1802
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1803
-            'display_desc',
1804
-            $yes_no_values,
1805
-            $this->_cpt_model_obj->display_description()
1806
-        );
1807
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1808
-            'display_ticket_selector',
1809
-            $yes_no_values,
1810
-            $this->_cpt_model_obj->display_ticket_selector(),
1811
-            '',
1812
-            '',
1813
-            false
1814
-        );
1815
-        $template_args['additional_registration_options'] = apply_filters(
1816
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1817
-            '',
1818
-            $template_args,
1819
-            $yes_no_values,
1820
-            $default_reg_status_values
1821
-        );
1822
-        EEH_Template::display_template(
1823
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1824
-            $template_args
1825
-        );
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * _get_events()
1831
-     * This method simply returns all the events (for the given _view and paging)
1832
-     *
1833
-     * @access public
1834
-     * @param int  $per_page     count of items per page (20 default);
1835
-     * @param int  $current_page what is the current page being viewed.
1836
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1837
-     *                           If FALSE then we return an array of event objects
1838
-     *                           that match the given _view and paging parameters.
1839
-     * @return array|int         an array of event objects or a count of them.
1840
-     * @throws Exception
1841
-     */
1842
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1843
-    {
1844
-        $EEM_Event   = $this->_event_model();
1845
-        $offset      = ($current_page - 1) * $per_page;
1846
-        $limit       = $count ? null : $offset . ',' . $per_page;
1847
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1848
-        $order       = $this->request->getRequestParam('order', 'DESC');
1849
-        $month_range = $this->request->getRequestParam('month_range');
1850
-        if ($month_range) {
1851
-            $pieces = explode(' ', $month_range, 3);
1852
-            // simulate the FIRST day of the month, that fixes issues for months like February
1853
-            // where PHP doesn't know what to assume for date.
1854
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1855
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1856
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1857
-        }
1858
-        $where  = [];
1859
-        $status = $this->request->getRequestParam('status');
1860
-        // determine what post_status our condition will have for the query.
1861
-        switch ($status) {
1862
-            case 'month':
1863
-            case 'today':
1864
-            case null:
1865
-            case 'all':
1866
-                break;
1867
-            case 'draft':
1868
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1869
-                break;
1870
-            default:
1871
-                $where['status'] = $status;
1872
-        }
1873
-        // categories? The default for all categories is -1
1874
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1875
-        if ($category !== -1) {
1876
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1877
-            $where['Term_Taxonomy.term_id']  = $category;
1878
-        }
1879
-        // date where conditions
1880
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1881
-        if ($month_range) {
1882
-            $DateTime = new DateTime(
1883
-                $year_r . '-' . $month_r . '-01 00:00:00',
1884
-                new DateTimeZone('UTC')
1885
-            );
1886
-            $start    = $DateTime->getTimestamp();
1887
-            // set the datetime to be the end of the month
1888
-            $DateTime->setDate(
1889
-                $year_r,
1890
-                $month_r,
1891
-                $DateTime->format('t')
1892
-            )->setTime(23, 59, 59);
1893
-            $end                             = $DateTime->getTimestamp();
1894
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1895
-        } elseif ($status === 'today') {
1896
-            $DateTime                        =
1897
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1898
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1899
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1900
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1901
-        } elseif ($status === 'month') {
1902
-            $now                             = date('Y-m-01');
1903
-            $DateTime                        =
1904
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1905
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1906
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1907
-                                                        ->setTime(23, 59, 59)
1908
-                                                        ->format(implode(' ', $start_formats));
1909
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1910
-        }
1911
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1912
-            $where['EVT_wp_user'] = get_current_user_id();
1913
-        } else {
1914
-            if (! isset($where['status'])) {
1915
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1916
-                    $where['OR'] = [
1917
-                        'status*restrict_private' => ['!=', 'private'],
1918
-                        'AND'                     => [
1919
-                            'status*inclusive' => ['=', 'private'],
1920
-                            'EVT_wp_user'      => get_current_user_id(),
1921
-                        ],
1922
-                    ];
1923
-                }
1924
-            }
1925
-        }
1926
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1927
-        if (
1928
-            $wp_user
1929
-            && $wp_user !== get_current_user_id()
1930
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1931
-        ) {
1932
-            $where['EVT_wp_user'] = $wp_user;
1933
-        }
1934
-        // search query handling
1935
-        $search_term = $this->request->getRequestParam('s');
1936
-        if ($search_term) {
1937
-            $search_term = '%' . $search_term . '%';
1938
-            $where['OR'] = [
1939
-                'EVT_name'       => ['LIKE', $search_term],
1940
-                'EVT_desc'       => ['LIKE', $search_term],
1941
-                'EVT_short_desc' => ['LIKE', $search_term],
1942
-            ];
1943
-        }
1944
-        // filter events by venue.
1945
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
1946
-        if ($venue) {
1947
-            $where['Venue.VNU_ID'] = $venue;
1948
-        }
1949
-        $request_params = $this->request->requestParams();
1950
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1951
-        $query_params   = apply_filters(
1952
-            'FHEE__Events_Admin_Page__get_events__query_params',
1953
-            [
1954
-                $where,
1955
-                'limit'    => $limit,
1956
-                'order_by' => $orderby,
1957
-                'order'    => $order,
1958
-                'group_by' => 'EVT_ID',
1959
-            ],
1960
-            $request_params
1961
-        );
1962
-
1963
-        // let's first check if we have special requests coming in.
1964
-        $active_status = $this->request->getRequestParam('active_status');
1965
-        if ($active_status) {
1966
-            switch ($active_status) {
1967
-                case 'upcoming':
1968
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
1969
-                case 'expired':
1970
-                    return $EEM_Event->get_expired_events($query_params, $count);
1971
-                case 'active':
1972
-                    return $EEM_Event->get_active_events($query_params, $count);
1973
-                case 'inactive':
1974
-                    return $EEM_Event->get_inactive_events($query_params, $count);
1975
-            }
1976
-        }
1977
-
1978
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1979
-    }
1980
-
1981
-
1982
-    /**
1983
-     * handling for WordPress CPT actions (trash, restore, delete)
1984
-     *
1985
-     * @param string $post_id
1986
-     * @throws EE_Error
1987
-     * @throws ReflectionException
1988
-     */
1989
-    public function trash_cpt_item($post_id)
1990
-    {
1991
-        $this->request->setRequestParam('EVT_ID', $post_id);
1992
-        $this->_trash_or_restore_event('trash', false);
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * @param string $post_id
1998
-     * @throws EE_Error
1999
-     * @throws ReflectionException
2000
-     */
2001
-    public function restore_cpt_item($post_id)
2002
-    {
2003
-        $this->request->setRequestParam('EVT_ID', $post_id);
2004
-        $this->_trash_or_restore_event('draft', false);
2005
-    }
2006
-
2007
-
2008
-    /**
2009
-     * @param string $post_id
2010
-     * @throws EE_Error
2011
-     * @throws EE_Error
2012
-     */
2013
-    public function delete_cpt_item($post_id)
2014
-    {
2015
-        throw new EE_Error(
2016
-            esc_html__(
2017
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2018
-                'event_espresso'
2019
-            )
2020
-        );
2021
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2022
-        // $this->_delete_event();
2023
-    }
2024
-
2025
-
2026
-    /**
2027
-     * _trash_or_restore_event
2028
-     *
2029
-     * @access protected
2030
-     * @param string $event_status
2031
-     * @param bool   $redirect_after
2032
-     * @throws EE_Error
2033
-     * @throws EE_Error
2034
-     * @throws ReflectionException
2035
-     */
2036
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2037
-    {
2038
-        // determine the event id and set to array.
2039
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2040
-        // loop thru events
2041
-        if ($EVT_ID) {
2042
-            // clean status
2043
-            $event_status = sanitize_key($event_status);
2044
-            // grab status
2045
-            if (! empty($event_status)) {
2046
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2047
-            } else {
2048
-                $success = false;
2049
-                $msg     = esc_html__(
2050
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2051
-                    'event_espresso'
2052
-                );
2053
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2054
-            }
2055
-        } else {
2056
-            $success = false;
2057
-            $msg     = esc_html__(
2058
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2059
-                'event_espresso'
2060
-            );
2061
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2062
-        }
2063
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2064
-        if ($redirect_after) {
2065
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2066
-        }
2067
-    }
2068
-
2069
-
2070
-    /**
2071
-     * _trash_or_restore_events
2072
-     *
2073
-     * @access protected
2074
-     * @param string $event_status
2075
-     * @return void
2076
-     * @throws EE_Error
2077
-     * @throws EE_Error
2078
-     * @throws ReflectionException
2079
-     */
2080
-    protected function _trash_or_restore_events($event_status = 'trash')
2081
-    {
2082
-        // clean status
2083
-        $event_status = sanitize_key($event_status);
2084
-        // grab status
2085
-        if (! empty($event_status)) {
2086
-            $success = true;
2087
-            // determine the event id and set to array.
2088
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2089
-            // loop thru events
2090
-            foreach ($EVT_IDs as $EVT_ID) {
2091
-                if ($EVT_ID = absint($EVT_ID)) {
2092
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2093
-                    $success = $results !== false ? $success : false;
2094
-                } else {
2095
-                    $msg = sprintf(
2096
-                        esc_html__(
2097
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2098
-                            'event_espresso'
2099
-                        ),
2100
-                        $EVT_ID
2101
-                    );
2102
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2103
-                    $success = false;
2104
-                }
2105
-            }
2106
-        } else {
2107
-            $success = false;
2108
-            $msg     = esc_html__(
2109
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2110
-                'event_espresso'
2111
-            );
2112
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2113
-        }
2114
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2115
-        $success = $success ? 2 : false;
2116
-        $action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2117
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2118
-    }
2119
-
2120
-
2121
-    /**
2122
-     * @param int    $EVT_ID
2123
-     * @param string $event_status
2124
-     * @return bool
2125
-     * @throws EE_Error
2126
-     * @throws ReflectionException
2127
-     */
2128
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2129
-    {
2130
-        // grab event id
2131
-        if (! $EVT_ID) {
2132
-            $msg = esc_html__(
2133
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2134
-                'event_espresso'
2135
-            );
2136
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2137
-            return false;
2138
-        }
2139
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2140
-        // clean status
2141
-        $event_status = sanitize_key($event_status);
2142
-        // grab status
2143
-        if (empty($event_status)) {
2144
-            $msg = esc_html__(
2145
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2146
-                'event_espresso'
2147
-            );
2148
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2149
-            return false;
2150
-        }
2151
-        // was event trashed or restored ?
2152
-        switch ($event_status) {
2153
-            case 'draft':
2154
-                $action = 'restored from the trash';
2155
-                $hook   = 'AHEE_event_restored_from_trash';
2156
-                break;
2157
-            case 'trash':
2158
-                $action = 'moved to the trash';
2159
-                $hook   = 'AHEE_event_moved_to_trash';
2160
-                break;
2161
-            default:
2162
-                $action = 'updated';
2163
-                $hook   = false;
2164
-        }
2165
-        // use class to change status
2166
-        $this->_cpt_model_obj->set_status($event_status);
2167
-        $success = $this->_cpt_model_obj->save();
2168
-        if (! $success) {
2169
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2170
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
-            return false;
2172
-        }
2173
-        if ($hook) {
2174
-            do_action($hook);
2175
-        }
2176
-        return true;
2177
-    }
2178
-
2179
-
2180
-    /**
2181
-     * @param array $event_ids
2182
-     * @return array
2183
-     * @since   4.10.23.p
2184
-     */
2185
-    private function cleanEventIds(array $event_ids)
2186
-    {
2187
-        return array_map('absint', $event_ids);
2188
-    }
2189
-
2190
-
2191
-    /**
2192
-     * @return array
2193
-     * @since   4.10.23.p
2194
-     */
2195
-    private function getEventIdsFromRequest()
2196
-    {
2197
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2198
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2199
-        } else {
2200
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2201
-        }
2202
-    }
2203
-
2204
-
2205
-    /**
2206
-     * @param bool $preview_delete
2207
-     * @throws EE_Error
2208
-     */
2209
-    protected function _delete_event($preview_delete = true)
2210
-    {
2211
-        $this->_delete_events($preview_delete);
2212
-    }
2213
-
2214
-
2215
-    /**
2216
-     * Gets the tree traversal batch persister.
2217
-     *
2218
-     * @return NodeGroupDao
2219
-     * @throws InvalidArgumentException
2220
-     * @throws InvalidDataTypeException
2221
-     * @throws InvalidInterfaceException
2222
-     * @since 4.10.12.p
2223
-     */
2224
-    protected function getModelObjNodeGroupPersister()
2225
-    {
2226
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2227
-            $this->model_obj_node_group_persister =
2228
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2229
-        }
2230
-        return $this->model_obj_node_group_persister;
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     * @param bool $preview_delete
2236
-     * @return void
2237
-     * @throws EE_Error
2238
-     */
2239
-    protected function _delete_events($preview_delete = true)
2240
-    {
2241
-        $event_ids = $this->getEventIdsFromRequest();
2242
-        if ($preview_delete) {
2243
-            $this->generateDeletionPreview($event_ids);
2244
-        } else {
2245
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2246
-        }
2247
-    }
2248
-
2249
-
2250
-    /**
2251
-     * @param array $event_ids
2252
-     */
2253
-    protected function generateDeletionPreview(array $event_ids)
2254
-    {
2255
-        $event_ids = $this->cleanEventIds($event_ids);
2256
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2257
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2258
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2259
-            [
2260
-                'action'            => 'preview_deletion',
2261
-                'deletion_job_code' => $deletion_job_code,
2262
-            ],
2263
-            $this->_admin_base_url
2264
-        );
2265
-        EEH_URL::safeRedirectAndExit(
2266
-            EE_Admin_Page::add_query_args_and_nonce(
2267
-                [
2268
-                    'page'              => 'espresso_batch',
2269
-                    'batch'             => EED_Batch::batch_job,
2270
-                    'EVT_IDs'           => $event_ids,
2271
-                    'deletion_job_code' => $deletion_job_code,
2272
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2273
-                    'return_url'        => urlencode($return_url),
2274
-                ],
2275
-                admin_url()
2276
-            )
2277
-        );
2278
-    }
2279
-
2280
-
2281
-    /**
2282
-     * Checks for a POST submission
2283
-     *
2284
-     * @since 4.10.12.p
2285
-     */
2286
-    protected function confirmDeletion()
2287
-    {
2288
-        $deletion_redirect_logic =
2289
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2290
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2291
-    }
2292
-
2293
-
2294
-    /**
2295
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2296
-     *
2297
-     * @throws EE_Error
2298
-     * @since 4.10.12.p
2299
-     */
2300
-    protected function previewDeletion()
2301
-    {
2302
-        $preview_deletion_logic =
2303
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2304
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2305
-        $this->display_admin_page_with_no_sidebar();
2306
-    }
2307
-
2308
-
2309
-    /**
2310
-     * get total number of events
2311
-     *
2312
-     * @access public
2313
-     * @return int
2314
-     * @throws EE_Error
2315
-     * @throws EE_Error
2316
-     */
2317
-    public function total_events()
2318
-    {
2319
-        return EEM_Event::instance()->count(
2320
-            ['caps' => 'read_admin'],
2321
-            'EVT_ID',
2322
-            true
2323
-        );
2324
-    }
2325
-
2326
-
2327
-    /**
2328
-     * get total number of draft events
2329
-     *
2330
-     * @access public
2331
-     * @return int
2332
-     * @throws EE_Error
2333
-     * @throws EE_Error
2334
-     */
2335
-    public function total_events_draft()
2336
-    {
2337
-        return EEM_Event::instance()->count(
2338
-            [
2339
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2340
-                'caps' => 'read_admin',
2341
-            ],
2342
-            'EVT_ID',
2343
-            true
2344
-        );
2345
-    }
2346
-
2347
-
2348
-    /**
2349
-     * get total number of trashed events
2350
-     *
2351
-     * @access public
2352
-     * @return int
2353
-     * @throws EE_Error
2354
-     * @throws EE_Error
2355
-     */
2356
-    public function total_trashed_events()
2357
-    {
2358
-        return EEM_Event::instance()->count(
2359
-            [
2360
-                ['status' => 'trash'],
2361
-                'caps' => 'read_admin',
2362
-            ],
2363
-            'EVT_ID',
2364
-            true
2365
-        );
2366
-    }
2367
-
2368
-
2369
-    /**
2370
-     *    _default_event_settings
2371
-     *    This generates the Default Settings Tab
2372
-     *
2373
-     * @return void
2374
-     * @throws EE_Error
2375
-     */
2376
-    protected function _default_event_settings()
2377
-    {
2378
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2379
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2380
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2381
-        $this->display_admin_page_with_sidebar();
2382
-    }
2383
-
2384
-
2385
-    /**
2386
-     * Return the form for event settings.
2387
-     *
2388
-     * @return EE_Form_Section_Proper
2389
-     * @throws EE_Error
2390
-     */
2391
-    protected function _default_event_settings_form()
2392
-    {
2393
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2394
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2395
-        // exclude
2396
-            [
2397
-                EEM_Registration::status_id_cancelled,
2398
-                EEM_Registration::status_id_declined,
2399
-                EEM_Registration::status_id_incomplete,
2400
-                EEM_Registration::status_id_wait_list,
2401
-            ],
2402
-            true
2403
-        );
2404
-        return new EE_Form_Section_Proper(
2405
-            [
2406
-                'name'            => 'update_default_event_settings',
2407
-                'html_id'         => 'update_default_event_settings',
2408
-                'html_class'      => 'form-table',
2409
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2410
-                'subsections'     => apply_filters(
2411
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2412
-                    [
2413
-                        'default_reg_status'  => new EE_Select_Input(
2414
-                            $registration_stati_for_selection,
2415
-                            [
2416
-                                'default'         => isset($registration_config->default_STS_ID)
2417
-                                                     && array_key_exists(
2418
-                                                         $registration_config->default_STS_ID,
2419
-                                                         $registration_stati_for_selection
2420
-                                                     )
2421
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2422
-                                    : EEM_Registration::status_id_pending_payment,
2423
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2424
-                                                     . EEH_Template::get_help_tab_link(
2425
-                                                         'default_settings_status_help_tab'
2426
-                                                     ),
2427
-                                'html_help_text'  => esc_html__(
2428
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2429
-                                    'event_espresso'
2430
-                                ),
2431
-                            ]
2432
-                        ),
2433
-                        'default_max_tickets' => new EE_Integer_Input(
2434
-                            [
2435
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2436
-                                    ? $registration_config->default_maximum_number_of_tickets
2437
-                                    : EEM_Event::get_default_additional_limit(),
2438
-                                'html_label_text' => esc_html__(
2439
-                                    'Default Maximum Tickets Allowed Per Order:',
2440
-                                    'event_espresso'
2441
-                                )
2442
-                                . EEH_Template::get_help_tab_link(
2443
-                                    'default_maximum_tickets_help_tab"'
2444
-                                ),
2445
-                                'html_help_text'  => esc_html__(
2446
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2447
-                                    'event_espresso'
2448
-                                ),
2449
-                            ]
2450
-                        ),
2451
-                    ]
2452
-                ),
2453
-            ]
2454
-        );
2455
-    }
2456
-
2457
-
2458
-    /**
2459
-     * _update_default_event_settings
2460
-     *
2461
-     * @access protected
2462
-     * @return void
2463
-     * @throws EE_Error
2464
-     */
2465
-    protected function _update_default_event_settings()
2466
-    {
2467
-        $registration_config = EE_Registry::instance()->CFG->registration;
2468
-        $form                = $this->_default_event_settings_form();
2469
-        if ($form->was_submitted()) {
2470
-            $form->receive_form_submission();
2471
-            if ($form->is_valid()) {
2472
-                $valid_data = $form->valid_data();
2473
-                if (isset($valid_data['default_reg_status'])) {
2474
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2475
-                }
2476
-                if (isset($valid_data['default_max_tickets'])) {
2477
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2478
-                }
2479
-                // update because data was valid!
2480
-                EE_Registry::instance()->CFG->update_espresso_config();
2481
-                EE_Error::overwrite_success();
2482
-                EE_Error::add_success(
2483
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2484
-                );
2485
-            }
2486
-        }
2487
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2488
-    }
2489
-
2490
-
2491
-    /*************        Templates        *************
2492
-     *
2493
-     * @throws EE_Error
2494
-     */
2495
-    protected function _template_settings()
2496
-    {
2497
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2498
-        $this->_template_args['preview_img']  = '<img src="'
2499
-                                                . EVENTS_ASSETS_URL
2500
-                                                . '/images/'
2501
-                                                . 'caffeinated_template_features.jpg" alt="'
2502
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2503
-                                                . '" />';
2504
-        $this->_template_args['preview_text'] = '<strong>'
2505
-                                                . esc_html__(
2506
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2507
-                                                    'event_espresso'
2508
-                                                ) . '</strong>';
2509
-        $this->display_admin_caf_preview_page('template_settings_tab');
2510
-    }
2511
-
2512
-
2513
-    /** Event Category Stuff **/
2514
-    /**
2515
-     * set the _category property with the category object for the loaded page.
2516
-     *
2517
-     * @access private
2518
-     * @return void
2519
-     */
2520
-    private function _set_category_object()
2521
-    {
2522
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2523
-            return;
2524
-        } //already have the category object so get out.
2525
-        // set default category object
2526
-        $this->_set_empty_category_object();
2527
-        // only set if we've got an id
2528
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2529
-        if (! $category_ID) {
2530
-            return;
2531
-        }
2532
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2533
-        if (! empty($term)) {
2534
-            $this->_category->category_name       = $term->name;
2535
-            $this->_category->category_identifier = $term->slug;
2536
-            $this->_category->category_desc       = $term->description;
2537
-            $this->_category->id                  = $term->term_id;
2538
-            $this->_category->parent              = $term->parent;
2539
-        }
2540
-    }
2541
-
2542
-
2543
-    /**
2544
-     * Clears out category properties.
2545
-     */
2546
-    private function _set_empty_category_object()
2547
-    {
2548
-        $this->_category                = new stdClass();
2549
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2550
-        $this->_category->id            = $this->_category->parent = 0;
2551
-    }
2552
-
2553
-
2554
-    /**
2555
-     * @throws EE_Error
2556
-     */
2557
-    protected function _category_list_table()
2558
-    {
2559
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2560
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2561
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2562
-            'add_category',
2563
-            'add_category',
2564
-            [],
2565
-            'add-new-h2'
2566
-        );
2567
-        $this->display_admin_list_table_page_with_sidebar();
2568
-    }
2569
-
2570
-
2571
-    /**
2572
-     * Output category details view.
2573
-     *
2574
-     * @throws EE_Error
2575
-     * @throws EE_Error
2576
-     */
2577
-    protected function _category_details($view)
2578
-    {
2579
-        // load formatter helper
2580
-        // load field generator helper
2581
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2582
-        $this->_set_add_edit_form_tags($route);
2583
-        $this->_set_category_object();
2584
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2585
-        $delete_action = 'delete_category';
2586
-        // custom redirect
2587
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2588
-            ['action' => 'category_list'],
2589
-            $this->_admin_base_url
2590
-        );
2591
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2592
-        // take care of contents
2593
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2594
-        $this->display_admin_page_with_sidebar();
2595
-    }
2596
-
2597
-
2598
-    /**
2599
-     * Output category details content.
2600
-     */
2601
-    protected function _category_details_content()
2602
-    {
2603
-        $editor_args['category_desc'] = [
2604
-            'type'          => 'wp_editor',
2605
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2606
-            'class'         => 'my_editor_custom',
2607
-            'wpeditor_args' => ['media_buttons' => false],
2608
-        ];
2609
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2610
-        $all_terms                    = get_terms(
2611
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2612
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2613
-        );
2614
-        // setup category select for term parents.
2615
-        $category_select_values[] = [
2616
-            'text' => esc_html__('No Parent', 'event_espresso'),
2617
-            'id'   => 0,
2618
-        ];
2619
-        foreach ($all_terms as $term) {
2620
-            $category_select_values[] = [
2621
-                'text' => $term->name,
2622
-                'id'   => $term->term_id,
2623
-            ];
2624
-        }
2625
-        $category_select = EEH_Form_Fields::select_input(
2626
-            'category_parent',
2627
-            $category_select_values,
2628
-            $this->_category->parent
2629
-        );
2630
-        $template_args   = [
2631
-            'category'                 => $this->_category,
2632
-            'category_select'          => $category_select,
2633
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2634
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2635
-            'disable'                  => '',
2636
-            'disabled_message'         => false,
2637
-        ];
2638
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2639
-        return EEH_Template::display_template($template, $template_args, true);
2640
-    }
2641
-
2642
-
2643
-    /**
2644
-     * Handles deleting categories.
2645
-     *
2646
-     * @throws EE_Error
2647
-     */
2648
-    protected function _delete_categories()
2649
-    {
2650
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2651
-        foreach ($category_IDs as $category_ID) {
2652
-            $this->_delete_category($category_ID);
2653
-        }
2654
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2655
-        $query_args = [
2656
-            'action' => 'category_list',
2657
-        ];
2658
-        $this->_redirect_after_action(0, '', '', $query_args);
2659
-    }
2660
-
2661
-
2662
-    /**
2663
-     * Handles deleting specific category.
2664
-     *
2665
-     * @param int $cat_id
2666
-     */
2667
-    protected function _delete_category($cat_id)
2668
-    {
2669
-        $cat_id = absint($cat_id);
2670
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2671
-    }
2672
-
2673
-
2674
-    /**
2675
-     * Handles triggering the update or insertion of a new category.
2676
-     *
2677
-     * @param bool $new_category true means we're triggering the insert of a new category.
2678
-     * @throws EE_Error
2679
-     * @throws EE_Error
2680
-     */
2681
-    protected function _insert_or_update_category($new_category)
2682
-    {
2683
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2684
-        $success = 0; // we already have a success message so lets not send another.
2685
-        if ($cat_id) {
2686
-            $query_args = [
2687
-                'action'     => 'edit_category',
2688
-                'EVT_CAT_ID' => $cat_id,
2689
-            ];
2690
-        } else {
2691
-            $query_args = ['action' => 'add_category'];
2692
-        }
2693
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2694
-    }
2695
-
2696
-
2697
-    /**
2698
-     * Inserts or updates category
2699
-     *
2700
-     * @param bool $update (true indicates we're updating a category).
2701
-     * @return bool|mixed|string
2702
-     */
2703
-    private function _insert_category($update = false)
2704
-    {
2705
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2706
-        $category_name       = $this->request->getRequestParam('category_name', '');
2707
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2708
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2709
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2710
-
2711
-        if (empty($category_name)) {
2712
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2713
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2714
-            return false;
2715
-        }
2716
-        $term_args = [
2717
-            'name'        => $category_name,
2718
-            'description' => $category_desc,
2719
-            'parent'      => $category_parent,
2720
-        ];
2721
-        // was the category_identifier input disabled?
2722
-        if ($category_identifier) {
2723
-            $term_args['slug'] = $category_identifier;
2724
-        }
2725
-        $insert_ids = $update
2726
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2727
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2728
-        if (! is_array($insert_ids)) {
2729
-            $msg = esc_html__(
2730
-                'An error occurred and the category has not been saved to the database.',
2731
-                'event_espresso'
2732
-            );
2733
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2734
-        } else {
2735
-            $category_ID = $insert_ids['term_id'];
2736
-            $msg         =
2737
-                sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2738
-            EE_Error::add_success($msg);
2739
-        }
2740
-        return $category_ID;
2741
-    }
2742
-
2743
-
2744
-    /**
2745
-     * Gets categories or count of categories matching the arguments in the request.
2746
-     *
2747
-     * @param int  $per_page
2748
-     * @param int  $current_page
2749
-     * @param bool $count
2750
-     * @return EE_Term_Taxonomy[]|int
2751
-     * @throws EE_Error
2752
-     * @throws EE_Error
2753
-     */
2754
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2755
-    {
2756
-        // testing term stuff
2757
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2758
-        $order       = $this->request->getRequestParam('order', 'DESC');
2759
-        $limit       = ($current_page - 1) * $per_page;
2760
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2761
-        $search_term = $this->request->getRequestParam('s');
2762
-        if ($search_term) {
2763
-            $search_term = '%' . $search_term . '%';
2764
-            $where['OR'] = [
2765
-                'Term.name'   => ['LIKE', $search_term],
2766
-                'description' => ['LIKE', $search_term],
2767
-            ];
2768
-        }
2769
-        $query_params = [
2770
-            $where,
2771
-            'order_by'   => [$orderby => $order],
2772
-            'limit'      => $limit . ',' . $per_page,
2773
-            'force_join' => ['Term'],
2774
-        ];
2775
-        return $count
2776
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2777
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2778
-    }
2779
-
2780
-    /* end category stuff */
2781
-    /**************/
2782
-
2783
-
2784
-    /**
2785
-     * Callback for the `ee_save_timezone_setting` ajax action.
2786
-     *
2787
-     * @throws EE_Error
2788
-     */
2789
-    public function saveTimezoneString()
2790
-    {
2791
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2792
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2793
-            EE_Error::add_error(
2794
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2795
-                __FILE__,
2796
-                __FUNCTION__,
2797
-                __LINE__
2798
-            );
2799
-            $this->_template_args['error'] = true;
2800
-            $this->_return_json();
2801
-        }
2802
-
2803
-        update_option('timezone_string', $timezone_string);
2804
-        EE_Error::add_success(
2805
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2806
-        );
2807
-        $this->_template_args['success'] = true;
2808
-        $this->_return_json(true, ['action' => 'create_new']);
2809
-    }
2810
-
2811
-
2812
-    /**
2813 2493
      * @throws EE_Error
2814
-     * @deprecated 4.10.25.p
2815 2494
      */
2816
-    public function save_timezonestring_setting()
2817
-    {
2818
-        $this->saveTimezoneString();
2819
-    }
2495
+	protected function _template_settings()
2496
+	{
2497
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2498
+		$this->_template_args['preview_img']  = '<img src="'
2499
+												. EVENTS_ASSETS_URL
2500
+												. '/images/'
2501
+												. 'caffeinated_template_features.jpg" alt="'
2502
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2503
+												. '" />';
2504
+		$this->_template_args['preview_text'] = '<strong>'
2505
+												. esc_html__(
2506
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2507
+													'event_espresso'
2508
+												) . '</strong>';
2509
+		$this->display_admin_caf_preview_page('template_settings_tab');
2510
+	}
2511
+
2512
+
2513
+	/** Event Category Stuff **/
2514
+	/**
2515
+	 * set the _category property with the category object for the loaded page.
2516
+	 *
2517
+	 * @access private
2518
+	 * @return void
2519
+	 */
2520
+	private function _set_category_object()
2521
+	{
2522
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2523
+			return;
2524
+		} //already have the category object so get out.
2525
+		// set default category object
2526
+		$this->_set_empty_category_object();
2527
+		// only set if we've got an id
2528
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2529
+		if (! $category_ID) {
2530
+			return;
2531
+		}
2532
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2533
+		if (! empty($term)) {
2534
+			$this->_category->category_name       = $term->name;
2535
+			$this->_category->category_identifier = $term->slug;
2536
+			$this->_category->category_desc       = $term->description;
2537
+			$this->_category->id                  = $term->term_id;
2538
+			$this->_category->parent              = $term->parent;
2539
+		}
2540
+	}
2541
+
2542
+
2543
+	/**
2544
+	 * Clears out category properties.
2545
+	 */
2546
+	private function _set_empty_category_object()
2547
+	{
2548
+		$this->_category                = new stdClass();
2549
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2550
+		$this->_category->id            = $this->_category->parent = 0;
2551
+	}
2552
+
2553
+
2554
+	/**
2555
+	 * @throws EE_Error
2556
+	 */
2557
+	protected function _category_list_table()
2558
+	{
2559
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2560
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2561
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2562
+			'add_category',
2563
+			'add_category',
2564
+			[],
2565
+			'add-new-h2'
2566
+		);
2567
+		$this->display_admin_list_table_page_with_sidebar();
2568
+	}
2569
+
2570
+
2571
+	/**
2572
+	 * Output category details view.
2573
+	 *
2574
+	 * @throws EE_Error
2575
+	 * @throws EE_Error
2576
+	 */
2577
+	protected function _category_details($view)
2578
+	{
2579
+		// load formatter helper
2580
+		// load field generator helper
2581
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2582
+		$this->_set_add_edit_form_tags($route);
2583
+		$this->_set_category_object();
2584
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2585
+		$delete_action = 'delete_category';
2586
+		// custom redirect
2587
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2588
+			['action' => 'category_list'],
2589
+			$this->_admin_base_url
2590
+		);
2591
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2592
+		// take care of contents
2593
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2594
+		$this->display_admin_page_with_sidebar();
2595
+	}
2596
+
2597
+
2598
+	/**
2599
+	 * Output category details content.
2600
+	 */
2601
+	protected function _category_details_content()
2602
+	{
2603
+		$editor_args['category_desc'] = [
2604
+			'type'          => 'wp_editor',
2605
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2606
+			'class'         => 'my_editor_custom',
2607
+			'wpeditor_args' => ['media_buttons' => false],
2608
+		];
2609
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2610
+		$all_terms                    = get_terms(
2611
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2612
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2613
+		);
2614
+		// setup category select for term parents.
2615
+		$category_select_values[] = [
2616
+			'text' => esc_html__('No Parent', 'event_espresso'),
2617
+			'id'   => 0,
2618
+		];
2619
+		foreach ($all_terms as $term) {
2620
+			$category_select_values[] = [
2621
+				'text' => $term->name,
2622
+				'id'   => $term->term_id,
2623
+			];
2624
+		}
2625
+		$category_select = EEH_Form_Fields::select_input(
2626
+			'category_parent',
2627
+			$category_select_values,
2628
+			$this->_category->parent
2629
+		);
2630
+		$template_args   = [
2631
+			'category'                 => $this->_category,
2632
+			'category_select'          => $category_select,
2633
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2634
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2635
+			'disable'                  => '',
2636
+			'disabled_message'         => false,
2637
+		];
2638
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2639
+		return EEH_Template::display_template($template, $template_args, true);
2640
+	}
2641
+
2642
+
2643
+	/**
2644
+	 * Handles deleting categories.
2645
+	 *
2646
+	 * @throws EE_Error
2647
+	 */
2648
+	protected function _delete_categories()
2649
+	{
2650
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2651
+		foreach ($category_IDs as $category_ID) {
2652
+			$this->_delete_category($category_ID);
2653
+		}
2654
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2655
+		$query_args = [
2656
+			'action' => 'category_list',
2657
+		];
2658
+		$this->_redirect_after_action(0, '', '', $query_args);
2659
+	}
2660
+
2661
+
2662
+	/**
2663
+	 * Handles deleting specific category.
2664
+	 *
2665
+	 * @param int $cat_id
2666
+	 */
2667
+	protected function _delete_category($cat_id)
2668
+	{
2669
+		$cat_id = absint($cat_id);
2670
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2671
+	}
2672
+
2673
+
2674
+	/**
2675
+	 * Handles triggering the update or insertion of a new category.
2676
+	 *
2677
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2678
+	 * @throws EE_Error
2679
+	 * @throws EE_Error
2680
+	 */
2681
+	protected function _insert_or_update_category($new_category)
2682
+	{
2683
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2684
+		$success = 0; // we already have a success message so lets not send another.
2685
+		if ($cat_id) {
2686
+			$query_args = [
2687
+				'action'     => 'edit_category',
2688
+				'EVT_CAT_ID' => $cat_id,
2689
+			];
2690
+		} else {
2691
+			$query_args = ['action' => 'add_category'];
2692
+		}
2693
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2694
+	}
2695
+
2696
+
2697
+	/**
2698
+	 * Inserts or updates category
2699
+	 *
2700
+	 * @param bool $update (true indicates we're updating a category).
2701
+	 * @return bool|mixed|string
2702
+	 */
2703
+	private function _insert_category($update = false)
2704
+	{
2705
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2706
+		$category_name       = $this->request->getRequestParam('category_name', '');
2707
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2708
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2709
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2710
+
2711
+		if (empty($category_name)) {
2712
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2713
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2714
+			return false;
2715
+		}
2716
+		$term_args = [
2717
+			'name'        => $category_name,
2718
+			'description' => $category_desc,
2719
+			'parent'      => $category_parent,
2720
+		];
2721
+		// was the category_identifier input disabled?
2722
+		if ($category_identifier) {
2723
+			$term_args['slug'] = $category_identifier;
2724
+		}
2725
+		$insert_ids = $update
2726
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2727
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2728
+		if (! is_array($insert_ids)) {
2729
+			$msg = esc_html__(
2730
+				'An error occurred and the category has not been saved to the database.',
2731
+				'event_espresso'
2732
+			);
2733
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2734
+		} else {
2735
+			$category_ID = $insert_ids['term_id'];
2736
+			$msg         =
2737
+				sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2738
+			EE_Error::add_success($msg);
2739
+		}
2740
+		return $category_ID;
2741
+	}
2742
+
2743
+
2744
+	/**
2745
+	 * Gets categories or count of categories matching the arguments in the request.
2746
+	 *
2747
+	 * @param int  $per_page
2748
+	 * @param int  $current_page
2749
+	 * @param bool $count
2750
+	 * @return EE_Term_Taxonomy[]|int
2751
+	 * @throws EE_Error
2752
+	 * @throws EE_Error
2753
+	 */
2754
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2755
+	{
2756
+		// testing term stuff
2757
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2758
+		$order       = $this->request->getRequestParam('order', 'DESC');
2759
+		$limit       = ($current_page - 1) * $per_page;
2760
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2761
+		$search_term = $this->request->getRequestParam('s');
2762
+		if ($search_term) {
2763
+			$search_term = '%' . $search_term . '%';
2764
+			$where['OR'] = [
2765
+				'Term.name'   => ['LIKE', $search_term],
2766
+				'description' => ['LIKE', $search_term],
2767
+			];
2768
+		}
2769
+		$query_params = [
2770
+			$where,
2771
+			'order_by'   => [$orderby => $order],
2772
+			'limit'      => $limit . ',' . $per_page,
2773
+			'force_join' => ['Term'],
2774
+		];
2775
+		return $count
2776
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2777
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2778
+	}
2779
+
2780
+	/* end category stuff */
2781
+	/**************/
2782
+
2783
+
2784
+	/**
2785
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2786
+	 *
2787
+	 * @throws EE_Error
2788
+	 */
2789
+	public function saveTimezoneString()
2790
+	{
2791
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2792
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2793
+			EE_Error::add_error(
2794
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2795
+				__FILE__,
2796
+				__FUNCTION__,
2797
+				__LINE__
2798
+			);
2799
+			$this->_template_args['error'] = true;
2800
+			$this->_return_json();
2801
+		}
2802
+
2803
+		update_option('timezone_string', $timezone_string);
2804
+		EE_Error::add_success(
2805
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2806
+		);
2807
+		$this->_template_args['success'] = true;
2808
+		$this->_return_json(true, ['action' => 'create_new']);
2809
+	}
2810
+
2811
+
2812
+	/**
2813
+	 * @throws EE_Error
2814
+	 * @deprecated 4.10.25.p
2815
+	 */
2816
+	public function save_timezonestring_setting()
2817
+	{
2818
+		$this->saveTimezoneString();
2819
+	}
2820 2820
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 1 patch
Indentation   +1788 added lines, -1788 removed lines patch added patch discarded remove patch
@@ -19,1792 +19,1792 @@
 block discarded – undo
19 19
  */
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22
-    /**
23
-     * $_initialized - has the SPCO controller already been initialized ?
24
-     *
25
-     * @var bool $_initialized
26
-     */
27
-    private static $_initialized = false;
28
-
29
-
30
-    /**
31
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
32
-     *
33
-     * @var bool $_valid_checkout
34
-     */
35
-    private static $_checkout_verified = true;
36
-
37
-    /**
38
-     *    $_reg_steps_array - holds initial array of reg steps
39
-     *
40
-     * @var array $_reg_steps_array
41
-     */
42
-    private static $_reg_steps_array = array();
43
-
44
-    /**
45
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
46
-     *
47
-     * @var EE_Checkout $checkout
48
-     */
49
-    public $checkout;
50
-
51
-    /**
52
-     * @var RequestInterface $request
53
-     */
54
-    protected $request;
55
-
56
-
57
-    /**
58
-     * @return EED_Single_Page_Checkout|EED_Module
59
-     * @throws EE_Error
60
-     * @throws ReflectionException
61
-     */
62
-    public static function instance()
63
-    {
64
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
-        return parent::get_instance(__CLASS__);
66
-    }
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-    /**
79
-     * @return RequestInterface
80
-     * @since   4.10.14.p
81
-     */
82
-    public static function getRequest()
83
-    {
84
-        return LoaderFactory::getLoader()->getShared(RequestInterface::class);
85
-    }
86
-
87
-
88
-    /**
89
-     * @return EE_Transaction
90
-     */
91
-    public function transaction()
92
-    {
93
-        return $this->checkout->transaction;
94
-    }
95
-
96
-
97
-    /**
98
-     *    set_hooks - for hooking into EE Core, other modules, etc
99
-     *
100
-     * @return    void
101
-     * @throws EE_Error
102
-     */
103
-    public static function set_hooks()
104
-    {
105
-        EED_Single_Page_Checkout::set_definitions();
106
-    }
107
-
108
-
109
-    /**
110
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
111
-     *
112
-     * @return    void
113
-     * @throws EE_Error
114
-     */
115
-    public static function set_hooks_admin()
116
-    {
117
-        EED_Single_Page_Checkout::set_definitions();
118
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
119
-            return;
120
-        }
121
-        // going to start an output buffer in case anything gets accidentally output
122
-        // that might disrupt our JSON response
123
-        ob_start();
124
-        EED_Single_Page_Checkout::load_reg_steps();
125
-        // set ajax hooks
126
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
127
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
128
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
129
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
130
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
131
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
132
-    }
133
-
134
-
135
-    /**
136
-     *    process ajax request
137
-     *
138
-     * @param string $ajax_action
139
-     * @throws EE_Error
140
-     * @throws ReflectionException
141
-     */
142
-    public static function process_ajax_request($ajax_action)
143
-    {
144
-        $request = EED_Single_Page_Checkout::getRequest();
145
-        $request->setRequestParam('action', $ajax_action);
146
-        EED_Single_Page_Checkout::instance()->_initialize();
147
-    }
148
-
149
-
150
-    /**
151
-     * ajax display registration step
152
-     *
153
-     * @throws EE_Error
154
-     * @throws ReflectionException
155
-     */
156
-    public static function display_reg_step()
157
-    {
158
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
159
-    }
160
-
161
-
162
-    /**
163
-     * ajax process registration step
164
-     *
165
-     * @throws EE_Error
166
-     * @throws ReflectionException
167
-     */
168
-    public static function process_reg_step()
169
-    {
170
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
171
-    }
172
-
173
-
174
-    /**
175
-     * ajax process registration step
176
-     *
177
-     * @throws EE_Error
178
-     * @throws ReflectionException
179
-     */
180
-    public static function update_reg_step()
181
-    {
182
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
183
-    }
184
-
185
-
186
-    /**
187
-     * update_checkout
188
-     *
189
-     * @return void
190
-     * @throws ReflectionException
191
-     * @throws EE_Error
192
-     */
193
-    public static function update_checkout()
194
-    {
195
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
196
-    }
197
-
198
-
199
-    /**
200
-     * @return void
201
-     * @deprecated 4.10.14.p
202
-     */
203
-    public static function load_request_handler()
204
-    {
205
-    }
206
-
207
-
208
-    /**
209
-     *    set_definitions
210
-     *
211
-     * @return    void
212
-     * @throws EE_Error
213
-     */
214
-    public static function set_definitions()
215
-    {
216
-        if (defined('SPCO_BASE_PATH')) {
217
-            return;
218
-        }
219
-        define(
220
-            'SPCO_BASE_PATH',
221
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
222
-        );
223
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
224
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
225
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
226
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
227
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
228
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
229
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
230
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     * load_reg_steps
237
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
238
-     *
239
-     * @throws EE_Error
240
-     */
241
-    public static function load_reg_steps()
242
-    {
243
-        static $reg_steps_loaded = false;
244
-        if ($reg_steps_loaded) {
245
-            return;
246
-        }
247
-        // filter list of reg_steps
248
-        $reg_steps_to_load = (array) apply_filters(
249
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
250
-            EED_Single_Page_Checkout::get_reg_steps()
251
-        );
252
-        // sort by key (order)
253
-        ksort($reg_steps_to_load);
254
-        // loop through folders
255
-        foreach ($reg_steps_to_load as $order => $reg_step) {
256
-            // we need a
257
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
258
-                // copy over to the reg_steps_array
259
-                EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
260
-                // register custom key route for each reg step
261
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
262
-                EE_Config::register_route(
263
-                    $reg_step['slug'],
264
-                    'EED_Single_Page_Checkout',
265
-                    'run',
266
-                    'step'
267
-                );
268
-                // add AJAX or other hooks
269
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
270
-                    // setup autoloaders if necessary
271
-                    if (! class_exists($reg_step['class_name'])) {
272
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
273
-                            $reg_step['file_path'],
274
-                            true
275
-                        );
276
-                    }
277
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
278
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
279
-                    }
280
-                }
281
-            }
282
-        }
283
-        $reg_steps_loaded = true;
284
-    }
285
-
286
-
287
-    /**
288
-     *    get_reg_steps
289
-     *
290
-     * @return    array
291
-     */
292
-    public static function get_reg_steps()
293
-    {
294
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
295
-        if (empty($reg_steps)) {
296
-            $reg_steps = array(
297
-                10  => array(
298
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
299
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
300
-                    'slug'       => 'attendee_information',
301
-                    'has_hooks'  => false,
302
-                ),
303
-                30  => array(
304
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
305
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
306
-                    'slug'       => 'payment_options',
307
-                    'has_hooks'  => true,
308
-                ),
309
-                999 => array(
310
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
311
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
312
-                    'slug'       => 'finalize_registration',
313
-                    'has_hooks'  => false,
314
-                ),
315
-            );
316
-        }
317
-        return $reg_steps;
318
-    }
319
-
320
-
321
-    /**
322
-     *    registration_checkout_for_admin
323
-     *
324
-     * @return    string
325
-     * @throws EE_Error
326
-     * @throws ReflectionException
327
-     */
328
-    public static function registration_checkout_for_admin()
329
-    {
330
-        $request = EED_Single_Page_Checkout::getRequest();
331
-        $request->setRequestParam('step', 'attendee_information');
332
-        $request->setRequestParam('action', 'display_spco_reg_step');
333
-        $request->setRequestParam('process_form_submission', false);
334
-        EED_Single_Page_Checkout::instance()->_initialize();
335
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
336
-        return EED_Single_Page_Checkout::getResponse()->getOutput();
337
-    }
338
-
339
-
340
-    /**
341
-     * process_registration_from_admin
342
-     *
343
-     * @return EE_Transaction
344
-     * @throws EE_Error
345
-     * @throws ReflectionException
346
-     */
347
-    public static function process_registration_from_admin()
348
-    {
349
-        $request = EED_Single_Page_Checkout::getRequest();
350
-        $request->setRequestParam('step', 'attendee_information');
351
-        $request->setRequestParam('action', 'process_reg_step');
352
-        $request->setRequestParam('process_form_submission', true);
353
-        EED_Single_Page_Checkout::instance()->_initialize();
354
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
355
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
356
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
357
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
358
-                if ($final_reg_step->process_reg_step()) {
359
-                    $final_reg_step->set_completed();
360
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
361
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
362
-                }
363
-            }
364
-        }
365
-        return null;
366
-    }
367
-
368
-
369
-    /**
370
-     *    run
371
-     *
372
-     * @param WP_Query $WP
373
-     * @return    void
374
-     */
375
-    public function run($WP)
376
-    {
377
-        if (
378
-            $WP instanceof WP_Query
379
-            && $WP->is_main_query()
380
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
381
-            && $this->_is_reg_checkout()
382
-        ) {
383
-            $this->_initialize();
384
-        }
385
-    }
386
-
387
-
388
-    /**
389
-     * determines whether current url matches reg page url
390
-     *
391
-     * @return bool
392
-     */
393
-    protected function _is_reg_checkout()
394
-    {
395
-        // get current permalink for reg page without any extra query args
396
-        $reg_page_url = get_permalink(EE_Config::instance()->core->reg_page_id);
397
-        // get request URI for current request, but without the scheme or host
398
-        $current_request_uri = EEH_URL::filter_input_server_url();
399
-        $current_request_uri = html_entity_decode($current_request_uri);
400
-        // get array of query args from the current request URI
401
-        $query_args = EEH_URL::get_query_string($current_request_uri);
402
-        // grab page id if it is set
403
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
404
-        // and remove the page id from the query args (we will re-add it later)
405
-        unset($query_args['page_id']);
406
-        // now strip all query args from current request URI
407
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
408
-        // and re-add the page id if it was set
409
-        if ($page_id) {
410
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
411
-        }
412
-        // remove slashes and ?
413
-        $current_request_uri = trim($current_request_uri, '?/');
414
-        // is current request URI part of the known full reg page URL ?
415
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
416
-    }
417
-
418
-
419
-    /**
420
-     * @param WP_Query $wp_query
421
-     * @return    void
422
-     * @throws EE_Error
423
-     * @throws ReflectionException
424
-     */
425
-    public static function init($wp_query)
426
-    {
427
-        EED_Single_Page_Checkout::instance()->run($wp_query);
428
-    }
429
-
430
-
431
-    /**
432
-     *    _initialize - initial module setup
433
-     *
434
-     * @return    void
435
-     */
436
-    private function _initialize()
437
-    {
438
-        // ensure SPCO doesn't run twice
439
-        if (EED_Single_Page_Checkout::$_initialized) {
440
-            return;
441
-        }
442
-        try {
443
-            $this->request = EED_Single_Page_Checkout::getRequest();
444
-            EED_Single_Page_Checkout::load_reg_steps();
445
-            $this->_verify_session();
446
-            // setup the EE_Checkout object
447
-            $this->checkout = $this->_initialize_checkout();
448
-            // filter checkout
449
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
450
-            // get the $_GET
451
-            $this->_get_request_vars();
452
-            if ($this->_block_bots()) {
453
-                return;
454
-            }
455
-            // filter continue_reg
456
-            $this->checkout->continue_reg = apply_filters(
457
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
458
-                true,
459
-                $this->checkout
460
-            );
461
-            // load the reg steps array
462
-            if (! $this->_load_and_instantiate_reg_steps()) {
463
-                EED_Single_Page_Checkout::$_initialized = true;
464
-                return;
465
-            }
466
-            // set the current step
467
-            $this->checkout->set_current_step($this->checkout->step);
468
-            // and the next step
469
-            $this->checkout->set_next_step();
470
-            // verify that everything has been setup correctly
471
-            if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
472
-                EED_Single_Page_Checkout::$_initialized = true;
473
-                return;
474
-            }
475
-            // lock the transaction
476
-            $this->checkout->transaction->lock();
477
-            // make sure all of our cached objects are added to their respective model entity mappers
478
-            $this->checkout->refresh_all_entities();
479
-            // set amount owing
480
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
481
-            // initialize each reg step, which gives them the chance to potentially alter the process
482
-            $this->_initialize_reg_steps();
483
-            // DEBUG LOG
484
-            // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
485
-            // get reg form
486
-            if (! $this->_check_form_submission()) {
487
-                EED_Single_Page_Checkout::$_initialized = true;
488
-                return;
489
-            }
490
-            // checkout the action!!!
491
-            $this->_process_form_action();
492
-            // add some style and make it dance
493
-            $this->add_styles_and_scripts($this);
494
-            // kk... SPCO has successfully run
495
-            EED_Single_Page_Checkout::$_initialized = true;
496
-            // set no cache headers and constants
497
-            EE_System::do_not_cache();
498
-            // add anchor
499
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
500
-            // remove transaction lock
501
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
502
-        } catch (Exception $e) {
503
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
504
-        }
505
-    }
506
-
507
-
508
-    /**
509
-     *    _verify_session
510
-     * checks that the session is valid and not expired
511
-     *
512
-     * @throws EE_Error
513
-     * @throws ReflectionException
514
-     */
515
-    private function _verify_session()
516
-    {
517
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
518
-            throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
519
-        }
520
-        $clear_session_requested = $this->request->getRequestParam('clear_session', false, 'bool');
521
-        // is session still valid ?
522
-        if (
523
-            $clear_session_requested
524
-            || (
525
-                EE_Registry::instance()->SSN->expired()
526
-                && $this->request->getRequestParam('e_reg_url_link') === ''
527
-            )
528
-        ) {
529
-            $this->checkout = new EE_Checkout();
530
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
531
-            // EE_Registry::instance()->SSN->reset_cart();
532
-            // EE_Registry::instance()->SSN->reset_checkout();
533
-            // EE_Registry::instance()->SSN->reset_transaction();
534
-            if (! $clear_session_requested) {
535
-                EE_Error::add_attention(
536
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
537
-                    __FILE__,
538
-                    __FUNCTION__,
539
-                    __LINE__
540
-                );
541
-            }
542
-            // EE_Registry::instance()->SSN->reset_expired();
543
-        }
544
-    }
545
-
546
-
547
-    /**
548
-     *    _initialize_checkout
549
-     * loads and instantiates EE_Checkout
550
-     *
551
-     * @return EE_Checkout
552
-     * @throws EE_Error
553
-     * @throws ReflectionException
554
-     */
555
-    private function _initialize_checkout()
556
-    {
557
-        // look in session for existing checkout
558
-        /** @type EE_Checkout $checkout */
559
-        $checkout = EE_Registry::instance()->SSN->checkout();
560
-        // verify
561
-        if (! $checkout instanceof EE_Checkout) {
562
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
563
-            $checkout = EE_Registry::instance()->load_file(
564
-                SPCO_INC_PATH,
565
-                'EE_Checkout',
566
-                'class',
567
-                array(),
568
-                false
569
-            );
570
-        } else {
571
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
572
-                $this->unlock_transaction();
573
-                wp_safe_redirect($checkout->redirect_url);
574
-                exit();
575
-            }
576
-        }
577
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
578
-        // verify again
579
-        if (! $checkout instanceof EE_Checkout) {
580
-            throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
581
-        }
582
-        // reset anything that needs a clean slate for each request
583
-        $checkout->reset_for_current_request();
584
-        return $checkout;
585
-    }
586
-
587
-
588
-    /**
589
-     *    _get_request_vars
590
-     *
591
-     * @return    void
592
-     */
593
-    private function _get_request_vars()
594
-    {
595
-        // make sure this request is marked as belonging to EE
596
-        /** @var CurrentPage $current_page */
597
-        $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
598
-        $current_page->setEspressoPage(true);
599
-        // which step is being requested ?
600
-        $this->checkout->step = $this->request->getRequestParam('step', $this->_get_first_step());
601
-        // which step is being edited ?
602
-        $this->checkout->edit_step = $this->request->getRequestParam('edit_step');
603
-        // and what we're doing on the current step
604
-        $this->checkout->action = $this->request->getRequestParam('action', 'display_spco_reg_step');
605
-        // timestamp
606
-        $this->checkout->uts = $this->request->getRequestParam('uts', 0, 'int');
607
-        // returning to edit ?
608
-        $this->checkout->reg_url_link = $this->request->getRequestParam('e_reg_url_link');
609
-        // add reg url link to registration query params
610
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
611
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
612
-        }
613
-        // or some other kind of revisit ?
614
-        $this->checkout->revisit = $this->request->getRequestParam('revisit', false, 'bool');
615
-        // and whether or not to generate a reg form for this request
616
-        $this->checkout->generate_reg_form = $this->request->getRequestParam('generate_reg_form', true, 'bool');
617
-        // and whether or not to process a reg form submission for this request
618
-        $this->checkout->process_form_submission = $this->request->getRequestParam(
619
-            'process_form_submission',
620
-            $this->checkout->action === 'process_reg_step',
621
-            'bool'
622
-        );
623
-        $this->checkout->process_form_submission = filter_var(
624
-            $this->checkout->action !== 'display_spco_reg_step'
625
-                ? $this->checkout->process_form_submission
626
-                : false,
627
-            FILTER_VALIDATE_BOOLEAN
628
-        );
629
-        // $this->_display_request_vars();
630
-    }
631
-
632
-
633
-    /**
634
-     *  _display_request_vars
635
-     *
636
-     * @return    void
637
-     */
638
-    protected function _display_request_vars()
639
-    {
640
-        if (! WP_DEBUG) {
641
-            return;
642
-        }
643
-        EEH_Debug_Tools::printr($this->request->requestParams(), 'requestParams', __FILE__, __LINE__);
644
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
645
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
646
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
647
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
648
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
649
-        EEH_Debug_Tools::printr(
650
-            $this->checkout->generate_reg_form,
651
-            '$this->checkout->generate_reg_form',
652
-            __FILE__,
653
-            __LINE__
654
-        );
655
-        EEH_Debug_Tools::printr(
656
-            $this->checkout->process_form_submission,
657
-            '$this->checkout->process_form_submission',
658
-            __FILE__,
659
-            __LINE__
660
-        );
661
-    }
662
-
663
-
664
-    /**
665
-     * _block_bots
666
-     * checks that the incoming request has either of the following set:
667
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
668
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
669
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
670
-     * then where you coming from man?
671
-     *
672
-     * @return boolean
673
-     */
674
-    private function _block_bots()
675
-    {
676
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
677
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
678
-            return true;
679
-        }
680
-        return false;
681
-    }
682
-
683
-
684
-    /**
685
-     *    _get_first_step
686
-     *  gets slug for first step in $_reg_steps_array
687
-     *
688
-     * @return    string
689
-     */
690
-    private function _get_first_step()
691
-    {
692
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
693
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
694
-    }
695
-
696
-
697
-    /**
698
-     * instantiates each reg step based on the loaded reg_steps array
699
-     *
700
-     * @return    bool
701
-     * @throws EE_Error
702
-     * @throws InvalidArgumentException
703
-     * @throws InvalidDataTypeException
704
-     * @throws InvalidInterfaceException
705
-     * @throws ReflectionException
706
-     */
707
-    private function _load_and_instantiate_reg_steps()
708
-    {
709
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
710
-        // have reg_steps already been instantiated ?
711
-        if (
712
-            empty($this->checkout->reg_steps)
713
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
714
-        ) {
715
-            // if not, then loop through raw reg steps array
716
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
717
-                if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
718
-                    return false;
719
-                }
720
-            }
721
-            if (isset($this->checkout->reg_steps['registration_confirmation'])) {
722
-                // skip the registration_confirmation page ?
723
-                if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
724
-                    // just remove it from the reg steps array
725
-                    $this->checkout->remove_reg_step('registration_confirmation', false);
726
-                } elseif (
727
-                    EE_Registry::instance()->CFG->registration->reg_confirmation_last
728
-                ) {
729
-                    // set the order to something big like 100
730
-                    $this->checkout->set_reg_step_order('registration_confirmation');
731
-                }
732
-            }
733
-            // filter the array for good luck
734
-            $this->checkout->reg_steps = apply_filters(
735
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
736
-                $this->checkout->reg_steps
737
-            );
738
-            // finally re-sort based on the reg step class order properties
739
-            $this->checkout->sort_reg_steps();
740
-        } else {
741
-            foreach ($this->checkout->reg_steps as $reg_step) {
742
-                // set all current step stati to FALSE
743
-                $reg_step->set_is_current_step(false);
744
-            }
745
-        }
746
-        if (empty($this->checkout->reg_steps)) {
747
-            EE_Error::add_error(
748
-                esc_html__('No Reg Steps were loaded..', 'event_espresso'),
749
-                __FILE__,
750
-                __FUNCTION__,
751
-                __LINE__
752
-            );
753
-            return false;
754
-        }
755
-        // make reg step details available to JS
756
-        $this->checkout->set_reg_step_JSON_info();
757
-        return true;
758
-    }
759
-
760
-
761
-    /**
762
-     *     _load_and_instantiate_reg_step
763
-     *
764
-     * @param array $reg_step
765
-     * @param int   $order
766
-     * @return bool
767
-     * @throws EE_Error
768
-     * @throws ReflectionException
769
-     */
770
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
771
-    {
772
-        // we need a file_path, class_name, and slug to add a reg step
773
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
774
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
775
-            if (
776
-                $this->checkout->reg_url_link
777
-                && $this->checkout->step !== $reg_step['slug']
778
-                && $reg_step['slug'] !== 'finalize_registration'
779
-                // normally at this point we would NOT load the reg step, but this filter can change that
780
-                && apply_filters(
781
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
782
-                    true,
783
-                    $reg_step,
784
-                    $this->checkout
785
-                )
786
-            ) {
787
-                return true;
788
-            }
789
-
790
-            // instantiate step class using file path and class name
791
-            $reg_step_obj = EE_Registry::instance()->load_file(
792
-                $reg_step['file_path'],
793
-                $reg_step['class_name'],
794
-                'class',
795
-                [$this->checkout],
796
-                false
797
-            );
798
-            // did we gets the goods ?
799
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
800
-                // set reg step order based on config
801
-                $reg_step_obj->set_order($order);
802
-                // add instantiated reg step object to the master reg steps array
803
-                $this->checkout->add_reg_step($reg_step_obj);
804
-            } else {
805
-                EE_Error::add_error(
806
-                    esc_html__('The current step could not be set.', 'event_espresso'),
807
-                    __FILE__,
808
-                    __FUNCTION__,
809
-                    __LINE__
810
-                );
811
-                return false;
812
-            }
813
-        } else {
814
-            if (WP_DEBUG) {
815
-                EE_Error::add_error(
816
-                    sprintf(
817
-                        esc_html__(
818
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
819
-                            'event_espresso'
820
-                        ),
821
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
822
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
823
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
824
-                        '<ul>',
825
-                        '<li>',
826
-                        '</li>',
827
-                        '</ul>'
828
-                    ),
829
-                    __FILE__,
830
-                    __FUNCTION__,
831
-                    __LINE__
832
-                );
833
-            }
834
-            return false;
835
-        }
836
-        return true;
837
-    }
838
-
839
-
840
-    /**
841
-     * _verify_transaction_and_get_registrations
842
-     *
843
-     * @return bool
844
-     * @throws EE_Error
845
-     * @throws ReflectionException
846
-     */
847
-    private function _verify_transaction_and_get_registrations()
848
-    {
849
-        // was there already a valid transaction in the checkout from the session ?
850
-        if (! $this->checkout->transaction instanceof EE_Transaction) {
851
-            // get transaction from db or session
852
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
853
-                ? $this->_get_transaction_and_cart_for_previous_visit()
854
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
855
-            if (! $this->checkout->transaction instanceof EE_Transaction) {
856
-                EE_Error::add_error(
857
-                    esc_html__(
858
-                        'Your Registration and Transaction information could not be retrieved from the db.',
859
-                        'event_espresso'
860
-                    ),
861
-                    __FILE__,
862
-                    __FUNCTION__,
863
-                    __LINE__
864
-                );
865
-                $this->checkout->transaction = EE_Transaction::new_instance();
866
-                // add some style and make it dance
867
-                $this->add_styles_and_scripts($this);
868
-                EED_Single_Page_Checkout::$_initialized = true;
869
-                return false;
870
-            }
871
-            // and the registrations for the transaction
872
-            $this->_get_registrations($this->checkout->transaction);
873
-        }
874
-        return true;
875
-    }
876
-
877
-
878
-    /**
879
-     * _get_transaction_and_cart_for_previous_visit
880
-     *
881
-     * @return EE_Transaction|null
882
-     * @throws EE_Error
883
-     * @throws ReflectionException
884
-     */
885
-    private function _get_transaction_and_cart_for_previous_visit()
886
-    {
887
-        /** @var $TXN_model EEM_Transaction */
888
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
889
-        // because the reg_url_link is present in the request,
890
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
891
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
892
-        // verify transaction
893
-        if ($transaction instanceof EE_Transaction) {
894
-            // and get the cart that was used for that transaction
895
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
896
-            return $transaction;
897
-        }
898
-        EE_Error::add_error(
899
-            esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
900
-            __FILE__,
901
-            __FUNCTION__,
902
-            __LINE__
903
-        );
904
-        return null;
905
-    }
906
-
907
-
908
-    /**
909
-     * _get_cart_for_transaction
910
-     *
911
-     * @param EE_Transaction $transaction
912
-     * @return EE_Cart
913
-     */
914
-    private function _get_cart_for_transaction($transaction)
915
-    {
916
-        return $this->checkout->get_cart_for_transaction($transaction);
917
-    }
918
-
919
-
920
-    /**
921
-     * get_cart_for_transaction
922
-     *
923
-     * @param EE_Transaction $transaction
924
-     * @return EE_Cart
925
-     */
926
-    public function get_cart_for_transaction(EE_Transaction $transaction)
927
-    {
928
-        return $this->checkout->get_cart_for_transaction($transaction);
929
-    }
930
-
931
-
932
-    /**
933
-     * _get_transaction_and_cart_for_current_session
934
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
935
-     *
936
-     * @return EE_Transaction
937
-     * @throws EE_Error
938
-     * @throws ReflectionException
939
-     */
940
-    private function _get_cart_for_current_session_and_setup_new_transaction()
941
-    {
942
-        //  if there's no transaction, then this is the FIRST visit to SPCO
943
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
944
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
945
-        // and then create a new transaction
946
-        $transaction = $this->_initialize_transaction();
947
-        // verify transaction
948
-        if ($transaction instanceof EE_Transaction) {
949
-            // save it so that we have an ID for other objects to use
950
-            $transaction->save();
951
-            // and save TXN data to the cart
952
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
953
-        } else {
954
-            EE_Error::add_error(
955
-                esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
956
-                __FILE__,
957
-                __FUNCTION__,
958
-                __LINE__
959
-            );
960
-        }
961
-        return $transaction;
962
-    }
963
-
964
-
965
-    /**
966
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
967
-     *
968
-     * @return EE_Transaction|null
969
-     */
970
-    private function _initialize_transaction()
971
-    {
972
-        try {
973
-            // ensure cart totals have been calculated
974
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
975
-            // grab the cart grand total
976
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
977
-            // create new TXN
978
-            $transaction = EE_Transaction::new_instance(
979
-                array(
980
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
981
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
982
-                    'TXN_paid'      => 0,
983
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
984
-                )
985
-            );
986
-            // save it so that we have an ID for other objects to use
987
-            $transaction->save();
988
-            // set cron job for following up on TXNs after their session has expired
989
-            EE_Cron_Tasks::schedule_expired_transaction_check(
990
-                EE_Registry::instance()->SSN->expiration() + 1,
991
-                $transaction->ID()
992
-            );
993
-            return $transaction;
994
-        } catch (Exception $e) {
995
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
996
-        }
997
-        return null;
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * _get_registrations
1003
-     *
1004
-     * @param EE_Transaction $transaction
1005
-     * @return void
1006
-     * @throws EE_Error
1007
-     * @throws ReflectionException
1008
-     */
1009
-    private function _get_registrations(EE_Transaction $transaction)
1010
-    {
1011
-        // first step: grab the registrants  { : o
1012
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1013
-        $this->checkout->total_ticket_count = count($registrations);
1014
-        // verify registrations have been set
1015
-        if (empty($registrations)) {
1016
-            // if no cached registrations, then check the db
1017
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1018
-            // still nothing ? well as long as this isn't a revisit
1019
-            if (empty($registrations) && ! $this->checkout->revisit) {
1020
-                // generate new registrations from scratch
1021
-                $registrations = $this->_initialize_registrations($transaction);
1022
-            }
1023
-        }
1024
-        // sort by their original registration order
1025
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1026
-        // then loop thru the array
1027
-        foreach ($registrations as $registration) {
1028
-            // verify each registration
1029
-            if ($registration instanceof EE_Registration) {
1030
-                // we display all attendee info for the primary registrant
1031
-                if (
1032
-                    $this->checkout->reg_url_link === $registration->reg_url_link()
1033
-                    && $registration->is_primary_registrant()
1034
-                ) {
1035
-                    $this->checkout->primary_revisit = true;
1036
-                    break;
1037
-                }
1038
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1039
-                    // but hide info if it doesn't belong to you
1040
-                    $transaction->clear_cache('Registration', $registration->ID());
1041
-                    $this->checkout->total_ticket_count--;
1042
-                }
1043
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1044
-            }
1045
-        }
1046
-    }
1047
-
1048
-
1049
-    /**
1050
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1051
-     *
1052
-     * @param EE_Transaction $transaction
1053
-     * @return    array
1054
-     * @throws EE_Error
1055
-     * @throws ReflectionException
1056
-     */
1057
-    private function _initialize_registrations(EE_Transaction $transaction)
1058
-    {
1059
-        $att_nmbr = 0;
1060
-        $registrations = array();
1061
-        if ($transaction instanceof EE_Transaction) {
1062
-            /** @type EE_Registration_Processor $registration_processor */
1063
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1064
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1065
-            // now let's add the cart items to the $transaction
1066
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1067
-                // do the following for each ticket of this type they selected
1068
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1069
-                    $att_nmbr++;
1070
-                    /** @var CreateRegistrationCommand $CreateRegistrationCommand */
1071
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1072
-                        CreateRegistrationCommand::class,
1073
-                        [
1074
-                            $transaction,
1075
-                            $line_item,
1076
-                            $att_nmbr,
1077
-                            $this->checkout->total_ticket_count,
1078
-                        ]
1079
-                    );
1080
-                    // override capabilities for frontend registrations
1081
-                    if ($this->request->isFrontend()) {
1082
-                        $CreateRegistrationCommand->setCapCheck(
1083
-                            new PublicCapabilities('', 'create_new_registration')
1084
-                        );
1085
-                    }
1086
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1087
-                    if (! $registration instanceof EE_Registration) {
1088
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1089
-                    }
1090
-                    $registrations[ $registration->ID() ] = $registration;
1091
-                }
1092
-            }
1093
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1094
-        }
1095
-        return $registrations;
1096
-    }
1097
-
1098
-
1099
-    /**
1100
-     * sorts registrations by REG_count
1101
-     *
1102
-     * @param EE_Registration $reg_A
1103
-     * @param EE_Registration $reg_B
1104
-     * @return int
1105
-     */
1106
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1107
-    {
1108
-        // this shouldn't ever happen within the same TXN, but oh well
1109
-        if ($reg_A->count() === $reg_B->count()) {
1110
-            return 0;
1111
-        }
1112
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1113
-    }
1114
-
1115
-
1116
-    /**
1117
-     *    _final_verifications
1118
-     * just makes sure that everything is set up correctly before proceeding
1119
-     *
1120
-     * @return    bool
1121
-     * @throws EE_Error
1122
-     * @throws ReflectionException
1123
-     */
1124
-    private function _final_verifications()
1125
-    {
1126
-        // filter checkout
1127
-        $this->checkout = apply_filters(
1128
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1129
-            $this->checkout
1130
-        );
1131
-        // verify that current step is still set correctly
1132
-        if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1133
-            EE_Error::add_error(
1134
-                esc_html__(
1135
-                    'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1136
-                    'event_espresso'
1137
-                ),
1138
-                __FILE__,
1139
-                __FUNCTION__,
1140
-                __LINE__
1141
-            );
1142
-            return false;
1143
-        }
1144
-        // if returning to SPCO, then verify that primary registrant is set
1145
-        if (! empty($this->checkout->reg_url_link)) {
1146
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1147
-            if (! $valid_registrant instanceof EE_Registration) {
1148
-                EE_Error::add_error(
1149
-                    esc_html__(
1150
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1151
-                        'event_espresso'
1152
-                    ),
1153
-                    __FILE__,
1154
-                    __FUNCTION__,
1155
-                    __LINE__
1156
-                );
1157
-                return false;
1158
-            }
1159
-            $valid_registrant = null;
1160
-            foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1161
-                if (
1162
-                    $registration instanceof EE_Registration
1163
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1164
-                ) {
1165
-                    $valid_registrant = $registration;
1166
-                }
1167
-            }
1168
-            if (! $valid_registrant instanceof EE_Registration) {
1169
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1170
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1171
-                    // clear the session, mark the checkout as unverified, and try again
1172
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1173
-                    EED_Single_Page_Checkout::$_initialized = false;
1174
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1175
-                    $this->_initialize();
1176
-                    EE_Error::reset_notices();
1177
-                    return false;
1178
-                }
1179
-                EE_Error::add_error(
1180
-                    esc_html__(
1181
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1182
-                        'event_espresso'
1183
-                    ),
1184
-                    __FILE__,
1185
-                    __FUNCTION__,
1186
-                    __LINE__
1187
-                );
1188
-                return false;
1189
-            }
1190
-        }
1191
-        // now that things have been kinda sufficiently verified,
1192
-        // let's add the checkout to the session so that it's available to other systems
1193
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1194
-        return true;
1195
-    }
1196
-
1197
-
1198
-    /**
1199
-     *    _initialize_reg_steps
1200
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1201
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1202
-     *
1203
-     * @param bool $reinitializing
1204
-     * @throws EE_Error
1205
-     */
1206
-    private function _initialize_reg_steps($reinitializing = false)
1207
-    {
1208
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1209
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1210
-        foreach ($this->checkout->reg_steps as $reg_step) {
1211
-            if (! $reg_step->initialize_reg_step()) {
1212
-                // if not initialized then maybe this step is being removed...
1213
-                if (! $reinitializing && $reg_step->is_current_step()) {
1214
-                    // if it was the current step, then we need to start over here
1215
-                    $this->_initialize_reg_steps(true);
1216
-                    return;
1217
-                }
1218
-                continue;
1219
-            }
1220
-            // add css and JS for current step
1221
-            $this->add_styles_and_scripts($reg_step);
1222
-            if ($reg_step->is_current_step()) {
1223
-                // the text that appears on the reg step form submit button
1224
-                $reg_step->set_submit_button_text();
1225
-            }
1226
-        }
1227
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1228
-        do_action(
1229
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1230
-            $this->checkout->current_step
1231
-        );
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     * _check_form_submission
1237
-     *
1238
-     * @return boolean
1239
-     * @throws EE_Error
1240
-     * @throws ReflectionException
1241
-     */
1242
-    private function _check_form_submission()
1243
-    {
1244
-        // does this request require the reg form to be generated ?
1245
-        if ($this->checkout->generate_reg_form) {
1246
-            // ever heard that song by Blue Rodeo ?
1247
-            try {
1248
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1249
-                // if not displaying a form, then check for form submission
1250
-                if (
1251
-                    $this->checkout->process_form_submission
1252
-                    && $this->checkout->current_step->reg_form->was_submitted()
1253
-                ) {
1254
-                    // clear out any old data in case this step is being run again
1255
-                    $this->checkout->current_step->set_valid_data(array());
1256
-                    // capture submitted form data
1257
-                    $request_data = $this->request->requestParams();
1258
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1259
-                        (array) apply_filters(
1260
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1261
-                            $request_data,
1262
-                            $this->checkout
1263
-                        )
1264
-                    );
1265
-                    // validate submitted form data
1266
-                    if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1267
-                        // thou shall not pass !!!
1268
-                        $this->checkout->continue_reg = false;
1269
-                        // any form validation errors?
1270
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1271
-                            EE_Error::add_error(
1272
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1273
-                                __FILE__,
1274
-                                __FUNCTION__,
1275
-                                __LINE__
1276
-                            );
1277
-                        }
1278
-                        // well not really... what will happen is
1279
-                        // we'll just get redirected back to redo the current step
1280
-                        $this->go_to_next_step();
1281
-                        return false;
1282
-                    }
1283
-                }
1284
-            } catch (EE_Error $e) {
1285
-                $e->get_error();
1286
-            }
1287
-        }
1288
-        return true;
1289
-    }
1290
-
1291
-
1292
-    /**
1293
-     * _process_action
1294
-     *
1295
-     * @return void
1296
-     * @throws EE_Error
1297
-     * @throws ReflectionException
1298
-     */
1299
-    private function _process_form_action()
1300
-    {
1301
-        // what cha wanna do?
1302
-        switch ($this->checkout->action) {
1303
-            // AJAX next step reg form
1304
-            case 'display_spco_reg_step':
1305
-                $this->checkout->redirect = false;
1306
-                if ($this->request->isAjax()) {
1307
-                    $this->checkout->json_response->set_reg_step_html(
1308
-                        $this->checkout->current_step->display_reg_form()
1309
-                    );
1310
-                }
1311
-                break;
1312
-            default:
1313
-                // meh... do one of those other steps first
1314
-                if (
1315
-                    ! empty($this->checkout->action)
1316
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1317
-                ) {
1318
-                    // dynamically creates hook point like:
1319
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1320
-                    do_action(
1321
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1322
-                        $this->checkout->current_step
1323
-                    );
1324
-                    $process_reg_step = apply_filters(
1325
-                        "AHEE__Single_Page_Checkout__process_reg_step__{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1326
-                        true,
1327
-                        $this->checkout->current_step,
1328
-                        $this
1329
-                    );
1330
-                    // call action on current step
1331
-                    if ($process_reg_step && call_user_func([$this->checkout->current_step, $this->checkout->action])) {
1332
-                        // good registrant, you get to proceed
1333
-                        if (
1334
-                            $this->checkout->current_step->success_message() !== ''
1335
-                            && apply_filters(
1336
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1337
-                                false
1338
-                            )
1339
-                        ) {
1340
-                            EE_Error::add_success(
1341
-                                $this->checkout->current_step->success_message()
1342
-                                . '<br />' . $this->checkout->next_step->_instructions()
1343
-                            );
1344
-                        }
1345
-                        // pack it up, pack it in...
1346
-                        $this->_setup_redirect();
1347
-                    }
1348
-                    // dynamically creates hook point like:
1349
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1350
-                    do_action(
1351
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1352
-                        $this->checkout->current_step
1353
-                    );
1354
-                } else {
1355
-                    EE_Error::add_error(
1356
-                        sprintf(
1357
-                            esc_html__(
1358
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1359
-                                'event_espresso'
1360
-                            ),
1361
-                            $this->checkout->action,
1362
-                            $this->checkout->current_step->name()
1363
-                        ),
1364
-                        __FILE__,
1365
-                        __FUNCTION__,
1366
-                        __LINE__
1367
-                    );
1368
-                }
1369
-            // end default
1370
-        }
1371
-        // store our progress so far
1372
-        $this->checkout->stash_transaction_and_checkout();
1373
-        // advance to the next step! If you pass GO, collect $200
1374
-        $this->go_to_next_step();
1375
-    }
1376
-
1377
-
1378
-    /**
1379
-     * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target an object with the method `translate_js_strings` and
1380
-     *                                                          `enqueue_styles_and_scripts`.
1381
-     * @return        void
1382
-     */
1383
-    public function add_styles_and_scripts($target)
1384
-    {
1385
-        // i18n
1386
-        $target->translate_js_strings();
1387
-        if ($this->checkout->admin_request) {
1388
-            add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1389
-        } else {
1390
-            add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1391
-        }
1392
-    }
1393
-
1394
-    /**
1395
-     *        translate_js_strings
1396
-     *
1397
-     * @return        void
1398
-     */
1399
-    public function translate_js_strings()
1400
-    {
1401
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1402
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1403
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1404
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1405
-            'event_espresso'
1406
-        );
1407
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1408
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1409
-            'event_espresso'
1410
-        );
1411
-        EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1412
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1413
-            'event_espresso'
1414
-        );
1415
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1416
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1417
-            'event_espresso'
1418
-        );
1419
-        EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1420
-            'This registration step could not be completed. Please refresh the page and try again.',
1421
-            'event_espresso'
1422
-        );
1423
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1424
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1425
-            'event_espresso'
1426
-        );
1427
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1428
-            esc_html__(
1429
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1430
-                'event_espresso'
1431
-            ),
1432
-            '<br/>',
1433
-            '<br/>'
1434
-        );
1435
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1436
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1437
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1438
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1439
-        EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1440
-        EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1441
-        EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1442
-        EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1443
-        EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1444
-        EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1445
-        EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1446
-        EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1447
-        EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1448
-        EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1449
-        EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1450
-        EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1451
-        EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1452
-        EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1453
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1454
-        );
1455
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1456
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1457
-            true
1458
-        );
1459
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1460
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1461
-        );
1462
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1463
-            'M d, Y H:i:s',
1464
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1465
-        );
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     *    enqueue_styles_and_scripts
1471
-     *
1472
-     * @return        void
1473
-     * @throws EE_Error
1474
-     */
1475
-    public function enqueue_styles_and_scripts()
1476
-    {
1477
-        // load css
1478
-        wp_register_style(
1479
-            'single_page_checkout',
1480
-            SPCO_CSS_URL . 'single_page_checkout.css',
1481
-            array('espresso_default'),
1482
-            EVENT_ESPRESSO_VERSION
1483
-        );
1484
-        wp_enqueue_style('single_page_checkout');
1485
-        // load JS
1486
-        wp_register_script(
1487
-            'jquery_plugin',
1488
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1489
-            array('jquery'),
1490
-            '1.0.1',
1491
-            true
1492
-        );
1493
-        wp_register_script(
1494
-            'jquery_countdown',
1495
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1496
-            array('jquery_plugin'),
1497
-            '2.1.0',
1498
-            true
1499
-        );
1500
-        wp_register_script(
1501
-            'single_page_checkout',
1502
-            SPCO_JS_URL . 'single_page_checkout.js',
1503
-            array('espresso_core', 'underscore', 'ee_form_section_validation'),
1504
-            EVENT_ESPRESSO_VERSION,
1505
-            true
1506
-        );
1507
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1508
-            $this->checkout->registration_form->enqueue_js();
1509
-        }
1510
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1511
-            $this->checkout->current_step->reg_form->enqueue_js();
1512
-        }
1513
-        wp_enqueue_script('single_page_checkout');
1514
-        if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1515
-            wp_enqueue_script('jquery_countdown');
1516
-        }
1517
-        /**
1518
-         * global action hook for enqueueing styles and scripts with
1519
-         * spco calls.
1520
-         */
1521
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1522
-        /**
1523
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1524
-         * The hook will end up being something like:
1525
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1526
-         */
1527
-        do_action(
1528
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1529
-            $this
1530
-        );
1531
-    }
1532
-
1533
-
1534
-    /**
1535
-     *    display the Registration Single Page Checkout Form
1536
-     *
1537
-     * @return    void
1538
-     * @throws EE_Error
1539
-     * @throws ReflectionException
1540
-     */
1541
-    private function _display_spco_reg_form()
1542
-    {
1543
-        // if registering via the admin, just display the reg form for the current step
1544
-        if ($this->checkout->admin_request) {
1545
-            EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->current_step->display_reg_form());
1546
-        } else {
1547
-            // add powered by EE msg
1548
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1549
-            $empty_cart = count(
1550
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1551
-            ) < 1;
1552
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1553
-            $cookies_not_set_msg = '';
1554
-            if ($empty_cart) {
1555
-                $cookies_not_set_msg = apply_filters(
1556
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1557
-                    sprintf(
1558
-                        esc_html__(
1559
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1560
-                            'event_espresso'
1561
-                        ),
1562
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1563
-                        '</div>',
1564
-                        '<h6 class="important-notice">',
1565
-                        '</h6>',
1566
-                        '<p>',
1567
-                        '</p>',
1568
-                        '<br />',
1569
-                        '<a href="https://www.whatismybrowser.com/guides/how-to-enable-cookies/" target="_blank" rel="noopener noreferrer">',
1570
-                        '</a>'
1571
-                    )
1572
-                );
1573
-            }
1574
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1575
-                array(
1576
-                    'name'            => 'single-page-checkout',
1577
-                    'html_id'         => 'ee-single-page-checkout-dv',
1578
-                    'layout_strategy' =>
1579
-                        new EE_Template_Layout(
1580
-                            array(
1581
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1582
-                                'template_args'        => array(
1583
-                                    'empty_cart'              => $empty_cart,
1584
-                                    'revisit'                 => $this->checkout->revisit,
1585
-                                    'reg_steps'               => $this->checkout->reg_steps,
1586
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1587
-                                        ? $this->checkout->next_step->slug()
1588
-                                        : '',
1589
-                                    'empty_msg'               => apply_filters(
1590
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1591
-                                        sprintf(
1592
-                                            esc_html__(
1593
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1594
-                                                'event_espresso'
1595
-                                            ),
1596
-                                            '<a href="'
1597
-                                            . get_post_type_archive_link('espresso_events')
1598
-                                            . '" title="',
1599
-                                            '">',
1600
-                                            '</a>'
1601
-                                        )
1602
-                                    ),
1603
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1604
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1605
-                                    'session_expiration'      => gmdate(
1606
-                                        'M d, Y H:i:s',
1607
-                                        EE_Registry::instance()->SSN->expiration()
1608
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1609
-                                    ),
1610
-                                ),
1611
-                            )
1612
-                        ),
1613
-                )
1614
-            );
1615
-            // load template and add to output sent that gets filtered into the_content()
1616
-            EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->registration_form->get_html());
1617
-        }
1618
-    }
1619
-
1620
-
1621
-    /**
1622
-     *    add_extra_finalize_registration_inputs
1623
-     *
1624
-     * @param $next_step
1625
-     * @internal  param string $label
1626
-     * @return void
1627
-     */
1628
-    public function add_extra_finalize_registration_inputs($next_step)
1629
-    {
1630
-        if ($next_step === 'finalize_registration') {
1631
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1632
-        }
1633
-    }
1634
-
1635
-
1636
-    /**
1637
-     *    display_registration_footer
1638
-     *
1639
-     * @return    string
1640
-     */
1641
-    public static function display_registration_footer()
1642
-    {
1643
-        if (
1644
-            apply_filters(
1645
-                'FHEE__EE_Front__Controller__show_reg_footer',
1646
-                EE_Registry::instance()->CFG->admin->show_reg_footer
1647
-            )
1648
-        ) {
1649
-            add_filter(
1650
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1651
-                function ($url) {
1652
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1653
-                }
1654
-            );
1655
-            echo apply_filters(
1656
-                'FHEE__EE_Front_Controller__display_registration_footer',
1657
-                EEH_Template::powered_by_event_espresso(
1658
-                    '',
1659
-                    'espresso-registration-footer-dv',
1660
-                    array('utm_content' => 'registration_checkout')
1661
-                )
1662
-            );
1663
-        }
1664
-        return '';
1665
-    }
1666
-
1667
-
1668
-    /**
1669
-     *    unlock_transaction
1670
-     *
1671
-     * @return    void
1672
-     * @throws EE_Error
1673
-     * @throws ReflectionException
1674
-     */
1675
-    public function unlock_transaction()
1676
-    {
1677
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1678
-            $this->checkout->transaction->unlock();
1679
-        }
1680
-    }
1681
-
1682
-
1683
-    /**
1684
-     *        _setup_redirect
1685
-     *
1686
-     * @return void
1687
-     */
1688
-    private function _setup_redirect()
1689
-    {
1690
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1691
-            $this->checkout->redirect = true;
1692
-            if (empty($this->checkout->redirect_url)) {
1693
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1694
-            }
1695
-            $this->checkout->redirect_url = apply_filters(
1696
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1697
-                $this->checkout->redirect_url,
1698
-                $this->checkout
1699
-            );
1700
-        }
1701
-    }
1702
-
1703
-
1704
-    /**
1705
-     *   handle ajax message responses and redirects
1706
-     *
1707
-     * @return void
1708
-     * @throws EE_Error
1709
-     * @throws ReflectionException
1710
-     */
1711
-    public function go_to_next_step()
1712
-    {
1713
-        if ($this->request->isAjax()) {
1714
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1715
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1716
-        }
1717
-        $this->unlock_transaction();
1718
-        // just return for these conditions
1719
-        if (
1720
-            $this->checkout->admin_request
1721
-            || $this->checkout->action === 'redirect_form'
1722
-            || $this->checkout->action === 'update_checkout'
1723
-        ) {
1724
-            return;
1725
-        }
1726
-        // AJAX response
1727
-        $this->_handle_json_response();
1728
-        // redirect to next step or the Thank You page
1729
-        $this->_handle_html_redirects();
1730
-        // hmmm... must be something wrong, so let's just display the form again !
1731
-        $this->_display_spco_reg_form();
1732
-    }
1733
-
1734
-
1735
-    /**
1736
-     *   _handle_json_response
1737
-     *
1738
-     * @return void
1739
-     * @throws EE_Error
1740
-     */
1741
-    protected function _handle_json_response()
1742
-    {
1743
-        // if this is an ajax request
1744
-        if ($this->request->isAjax()) {
1745
-            $this->checkout->json_response->set_registration_time_limit(
1746
-                $this->checkout->get_registration_time_limit()
1747
-            );
1748
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1749
-            // just send the ajax (
1750
-            $json_response = apply_filters(
1751
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1752
-                $this->checkout->json_response
1753
-            );
1754
-            echo ($json_response);
1755
-            exit();
1756
-        }
1757
-    }
1758
-
1759
-
1760
-    /**
1761
-     *   _handle_redirects
1762
-     *
1763
-     * @return void
1764
-     */
1765
-    protected function _handle_html_redirects()
1766
-    {
1767
-        // going somewhere ?
1768
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1769
-            // store notices in a transient
1770
-            EE_Error::get_notices(false, true);
1771
-            wp_safe_redirect($this->checkout->redirect_url);
1772
-            exit();
1773
-        }
1774
-    }
1775
-
1776
-
1777
-    /**
1778
-     *   set_checkout_anchor
1779
-     *
1780
-     * @return void
1781
-     */
1782
-    public function set_checkout_anchor()
1783
-    {
1784
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1785
-    }
1786
-
1787
-    /**
1788
-     *    getRegistrationExpirationNotice
1789
-     *
1790
-     * @since     4.9.59.p
1791
-     * @return    string
1792
-     */
1793
-    public static function getRegistrationExpirationNotice()
1794
-    {
1795
-        return sprintf(
1796
-            esc_html__(
1797
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1798
-                'event_espresso'
1799
-            ),
1800
-            '<h4 class="important-notice">',
1801
-            '</h4>',
1802
-            '<br />',
1803
-            '<p>',
1804
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1805
-            '">',
1806
-            '</a>',
1807
-            '</p>'
1808
-        );
1809
-    }
22
+	/**
23
+	 * $_initialized - has the SPCO controller already been initialized ?
24
+	 *
25
+	 * @var bool $_initialized
26
+	 */
27
+	private static $_initialized = false;
28
+
29
+
30
+	/**
31
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
32
+	 *
33
+	 * @var bool $_valid_checkout
34
+	 */
35
+	private static $_checkout_verified = true;
36
+
37
+	/**
38
+	 *    $_reg_steps_array - holds initial array of reg steps
39
+	 *
40
+	 * @var array $_reg_steps_array
41
+	 */
42
+	private static $_reg_steps_array = array();
43
+
44
+	/**
45
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
46
+	 *
47
+	 * @var EE_Checkout $checkout
48
+	 */
49
+	public $checkout;
50
+
51
+	/**
52
+	 * @var RequestInterface $request
53
+	 */
54
+	protected $request;
55
+
56
+
57
+	/**
58
+	 * @return EED_Single_Page_Checkout|EED_Module
59
+	 * @throws EE_Error
60
+	 * @throws ReflectionException
61
+	 */
62
+	public static function instance()
63
+	{
64
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
+		return parent::get_instance(__CLASS__);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+	/**
79
+	 * @return RequestInterface
80
+	 * @since   4.10.14.p
81
+	 */
82
+	public static function getRequest()
83
+	{
84
+		return LoaderFactory::getLoader()->getShared(RequestInterface::class);
85
+	}
86
+
87
+
88
+	/**
89
+	 * @return EE_Transaction
90
+	 */
91
+	public function transaction()
92
+	{
93
+		return $this->checkout->transaction;
94
+	}
95
+
96
+
97
+	/**
98
+	 *    set_hooks - for hooking into EE Core, other modules, etc
99
+	 *
100
+	 * @return    void
101
+	 * @throws EE_Error
102
+	 */
103
+	public static function set_hooks()
104
+	{
105
+		EED_Single_Page_Checkout::set_definitions();
106
+	}
107
+
108
+
109
+	/**
110
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
111
+	 *
112
+	 * @return    void
113
+	 * @throws EE_Error
114
+	 */
115
+	public static function set_hooks_admin()
116
+	{
117
+		EED_Single_Page_Checkout::set_definitions();
118
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
119
+			return;
120
+		}
121
+		// going to start an output buffer in case anything gets accidentally output
122
+		// that might disrupt our JSON response
123
+		ob_start();
124
+		EED_Single_Page_Checkout::load_reg_steps();
125
+		// set ajax hooks
126
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
127
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
128
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
129
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
130
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
131
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
132
+	}
133
+
134
+
135
+	/**
136
+	 *    process ajax request
137
+	 *
138
+	 * @param string $ajax_action
139
+	 * @throws EE_Error
140
+	 * @throws ReflectionException
141
+	 */
142
+	public static function process_ajax_request($ajax_action)
143
+	{
144
+		$request = EED_Single_Page_Checkout::getRequest();
145
+		$request->setRequestParam('action', $ajax_action);
146
+		EED_Single_Page_Checkout::instance()->_initialize();
147
+	}
148
+
149
+
150
+	/**
151
+	 * ajax display registration step
152
+	 *
153
+	 * @throws EE_Error
154
+	 * @throws ReflectionException
155
+	 */
156
+	public static function display_reg_step()
157
+	{
158
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
159
+	}
160
+
161
+
162
+	/**
163
+	 * ajax process registration step
164
+	 *
165
+	 * @throws EE_Error
166
+	 * @throws ReflectionException
167
+	 */
168
+	public static function process_reg_step()
169
+	{
170
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
171
+	}
172
+
173
+
174
+	/**
175
+	 * ajax process registration step
176
+	 *
177
+	 * @throws EE_Error
178
+	 * @throws ReflectionException
179
+	 */
180
+	public static function update_reg_step()
181
+	{
182
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
183
+	}
184
+
185
+
186
+	/**
187
+	 * update_checkout
188
+	 *
189
+	 * @return void
190
+	 * @throws ReflectionException
191
+	 * @throws EE_Error
192
+	 */
193
+	public static function update_checkout()
194
+	{
195
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
196
+	}
197
+
198
+
199
+	/**
200
+	 * @return void
201
+	 * @deprecated 4.10.14.p
202
+	 */
203
+	public static function load_request_handler()
204
+	{
205
+	}
206
+
207
+
208
+	/**
209
+	 *    set_definitions
210
+	 *
211
+	 * @return    void
212
+	 * @throws EE_Error
213
+	 */
214
+	public static function set_definitions()
215
+	{
216
+		if (defined('SPCO_BASE_PATH')) {
217
+			return;
218
+		}
219
+		define(
220
+			'SPCO_BASE_PATH',
221
+			rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
222
+		);
223
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
224
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
225
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
226
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
227
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
228
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
229
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
230
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 * load_reg_steps
237
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
238
+	 *
239
+	 * @throws EE_Error
240
+	 */
241
+	public static function load_reg_steps()
242
+	{
243
+		static $reg_steps_loaded = false;
244
+		if ($reg_steps_loaded) {
245
+			return;
246
+		}
247
+		// filter list of reg_steps
248
+		$reg_steps_to_load = (array) apply_filters(
249
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
250
+			EED_Single_Page_Checkout::get_reg_steps()
251
+		);
252
+		// sort by key (order)
253
+		ksort($reg_steps_to_load);
254
+		// loop through folders
255
+		foreach ($reg_steps_to_load as $order => $reg_step) {
256
+			// we need a
257
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
258
+				// copy over to the reg_steps_array
259
+				EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
260
+				// register custom key route for each reg step
261
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
262
+				EE_Config::register_route(
263
+					$reg_step['slug'],
264
+					'EED_Single_Page_Checkout',
265
+					'run',
266
+					'step'
267
+				);
268
+				// add AJAX or other hooks
269
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
270
+					// setup autoloaders if necessary
271
+					if (! class_exists($reg_step['class_name'])) {
272
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
273
+							$reg_step['file_path'],
274
+							true
275
+						);
276
+					}
277
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
278
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
279
+					}
280
+				}
281
+			}
282
+		}
283
+		$reg_steps_loaded = true;
284
+	}
285
+
286
+
287
+	/**
288
+	 *    get_reg_steps
289
+	 *
290
+	 * @return    array
291
+	 */
292
+	public static function get_reg_steps()
293
+	{
294
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
295
+		if (empty($reg_steps)) {
296
+			$reg_steps = array(
297
+				10  => array(
298
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
299
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
300
+					'slug'       => 'attendee_information',
301
+					'has_hooks'  => false,
302
+				),
303
+				30  => array(
304
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
305
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
306
+					'slug'       => 'payment_options',
307
+					'has_hooks'  => true,
308
+				),
309
+				999 => array(
310
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
311
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
312
+					'slug'       => 'finalize_registration',
313
+					'has_hooks'  => false,
314
+				),
315
+			);
316
+		}
317
+		return $reg_steps;
318
+	}
319
+
320
+
321
+	/**
322
+	 *    registration_checkout_for_admin
323
+	 *
324
+	 * @return    string
325
+	 * @throws EE_Error
326
+	 * @throws ReflectionException
327
+	 */
328
+	public static function registration_checkout_for_admin()
329
+	{
330
+		$request = EED_Single_Page_Checkout::getRequest();
331
+		$request->setRequestParam('step', 'attendee_information');
332
+		$request->setRequestParam('action', 'display_spco_reg_step');
333
+		$request->setRequestParam('process_form_submission', false);
334
+		EED_Single_Page_Checkout::instance()->_initialize();
335
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
336
+		return EED_Single_Page_Checkout::getResponse()->getOutput();
337
+	}
338
+
339
+
340
+	/**
341
+	 * process_registration_from_admin
342
+	 *
343
+	 * @return EE_Transaction
344
+	 * @throws EE_Error
345
+	 * @throws ReflectionException
346
+	 */
347
+	public static function process_registration_from_admin()
348
+	{
349
+		$request = EED_Single_Page_Checkout::getRequest();
350
+		$request->setRequestParam('step', 'attendee_information');
351
+		$request->setRequestParam('action', 'process_reg_step');
352
+		$request->setRequestParam('process_form_submission', true);
353
+		EED_Single_Page_Checkout::instance()->_initialize();
354
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
355
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
356
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
357
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
358
+				if ($final_reg_step->process_reg_step()) {
359
+					$final_reg_step->set_completed();
360
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
361
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
362
+				}
363
+			}
364
+		}
365
+		return null;
366
+	}
367
+
368
+
369
+	/**
370
+	 *    run
371
+	 *
372
+	 * @param WP_Query $WP
373
+	 * @return    void
374
+	 */
375
+	public function run($WP)
376
+	{
377
+		if (
378
+			$WP instanceof WP_Query
379
+			&& $WP->is_main_query()
380
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
381
+			&& $this->_is_reg_checkout()
382
+		) {
383
+			$this->_initialize();
384
+		}
385
+	}
386
+
387
+
388
+	/**
389
+	 * determines whether current url matches reg page url
390
+	 *
391
+	 * @return bool
392
+	 */
393
+	protected function _is_reg_checkout()
394
+	{
395
+		// get current permalink for reg page without any extra query args
396
+		$reg_page_url = get_permalink(EE_Config::instance()->core->reg_page_id);
397
+		// get request URI for current request, but without the scheme or host
398
+		$current_request_uri = EEH_URL::filter_input_server_url();
399
+		$current_request_uri = html_entity_decode($current_request_uri);
400
+		// get array of query args from the current request URI
401
+		$query_args = EEH_URL::get_query_string($current_request_uri);
402
+		// grab page id if it is set
403
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
404
+		// and remove the page id from the query args (we will re-add it later)
405
+		unset($query_args['page_id']);
406
+		// now strip all query args from current request URI
407
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
408
+		// and re-add the page id if it was set
409
+		if ($page_id) {
410
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
411
+		}
412
+		// remove slashes and ?
413
+		$current_request_uri = trim($current_request_uri, '?/');
414
+		// is current request URI part of the known full reg page URL ?
415
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
416
+	}
417
+
418
+
419
+	/**
420
+	 * @param WP_Query $wp_query
421
+	 * @return    void
422
+	 * @throws EE_Error
423
+	 * @throws ReflectionException
424
+	 */
425
+	public static function init($wp_query)
426
+	{
427
+		EED_Single_Page_Checkout::instance()->run($wp_query);
428
+	}
429
+
430
+
431
+	/**
432
+	 *    _initialize - initial module setup
433
+	 *
434
+	 * @return    void
435
+	 */
436
+	private function _initialize()
437
+	{
438
+		// ensure SPCO doesn't run twice
439
+		if (EED_Single_Page_Checkout::$_initialized) {
440
+			return;
441
+		}
442
+		try {
443
+			$this->request = EED_Single_Page_Checkout::getRequest();
444
+			EED_Single_Page_Checkout::load_reg_steps();
445
+			$this->_verify_session();
446
+			// setup the EE_Checkout object
447
+			$this->checkout = $this->_initialize_checkout();
448
+			// filter checkout
449
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
450
+			// get the $_GET
451
+			$this->_get_request_vars();
452
+			if ($this->_block_bots()) {
453
+				return;
454
+			}
455
+			// filter continue_reg
456
+			$this->checkout->continue_reg = apply_filters(
457
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
458
+				true,
459
+				$this->checkout
460
+			);
461
+			// load the reg steps array
462
+			if (! $this->_load_and_instantiate_reg_steps()) {
463
+				EED_Single_Page_Checkout::$_initialized = true;
464
+				return;
465
+			}
466
+			// set the current step
467
+			$this->checkout->set_current_step($this->checkout->step);
468
+			// and the next step
469
+			$this->checkout->set_next_step();
470
+			// verify that everything has been setup correctly
471
+			if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
472
+				EED_Single_Page_Checkout::$_initialized = true;
473
+				return;
474
+			}
475
+			// lock the transaction
476
+			$this->checkout->transaction->lock();
477
+			// make sure all of our cached objects are added to their respective model entity mappers
478
+			$this->checkout->refresh_all_entities();
479
+			// set amount owing
480
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
481
+			// initialize each reg step, which gives them the chance to potentially alter the process
482
+			$this->_initialize_reg_steps();
483
+			// DEBUG LOG
484
+			// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
485
+			// get reg form
486
+			if (! $this->_check_form_submission()) {
487
+				EED_Single_Page_Checkout::$_initialized = true;
488
+				return;
489
+			}
490
+			// checkout the action!!!
491
+			$this->_process_form_action();
492
+			// add some style and make it dance
493
+			$this->add_styles_and_scripts($this);
494
+			// kk... SPCO has successfully run
495
+			EED_Single_Page_Checkout::$_initialized = true;
496
+			// set no cache headers and constants
497
+			EE_System::do_not_cache();
498
+			// add anchor
499
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
500
+			// remove transaction lock
501
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
502
+		} catch (Exception $e) {
503
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
504
+		}
505
+	}
506
+
507
+
508
+	/**
509
+	 *    _verify_session
510
+	 * checks that the session is valid and not expired
511
+	 *
512
+	 * @throws EE_Error
513
+	 * @throws ReflectionException
514
+	 */
515
+	private function _verify_session()
516
+	{
517
+		if (! EE_Registry::instance()->SSN instanceof EE_Session) {
518
+			throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
519
+		}
520
+		$clear_session_requested = $this->request->getRequestParam('clear_session', false, 'bool');
521
+		// is session still valid ?
522
+		if (
523
+			$clear_session_requested
524
+			|| (
525
+				EE_Registry::instance()->SSN->expired()
526
+				&& $this->request->getRequestParam('e_reg_url_link') === ''
527
+			)
528
+		) {
529
+			$this->checkout = new EE_Checkout();
530
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
531
+			// EE_Registry::instance()->SSN->reset_cart();
532
+			// EE_Registry::instance()->SSN->reset_checkout();
533
+			// EE_Registry::instance()->SSN->reset_transaction();
534
+			if (! $clear_session_requested) {
535
+				EE_Error::add_attention(
536
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
537
+					__FILE__,
538
+					__FUNCTION__,
539
+					__LINE__
540
+				);
541
+			}
542
+			// EE_Registry::instance()->SSN->reset_expired();
543
+		}
544
+	}
545
+
546
+
547
+	/**
548
+	 *    _initialize_checkout
549
+	 * loads and instantiates EE_Checkout
550
+	 *
551
+	 * @return EE_Checkout
552
+	 * @throws EE_Error
553
+	 * @throws ReflectionException
554
+	 */
555
+	private function _initialize_checkout()
556
+	{
557
+		// look in session for existing checkout
558
+		/** @type EE_Checkout $checkout */
559
+		$checkout = EE_Registry::instance()->SSN->checkout();
560
+		// verify
561
+		if (! $checkout instanceof EE_Checkout) {
562
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
563
+			$checkout = EE_Registry::instance()->load_file(
564
+				SPCO_INC_PATH,
565
+				'EE_Checkout',
566
+				'class',
567
+				array(),
568
+				false
569
+			);
570
+		} else {
571
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
572
+				$this->unlock_transaction();
573
+				wp_safe_redirect($checkout->redirect_url);
574
+				exit();
575
+			}
576
+		}
577
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
578
+		// verify again
579
+		if (! $checkout instanceof EE_Checkout) {
580
+			throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
581
+		}
582
+		// reset anything that needs a clean slate for each request
583
+		$checkout->reset_for_current_request();
584
+		return $checkout;
585
+	}
586
+
587
+
588
+	/**
589
+	 *    _get_request_vars
590
+	 *
591
+	 * @return    void
592
+	 */
593
+	private function _get_request_vars()
594
+	{
595
+		// make sure this request is marked as belonging to EE
596
+		/** @var CurrentPage $current_page */
597
+		$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
598
+		$current_page->setEspressoPage(true);
599
+		// which step is being requested ?
600
+		$this->checkout->step = $this->request->getRequestParam('step', $this->_get_first_step());
601
+		// which step is being edited ?
602
+		$this->checkout->edit_step = $this->request->getRequestParam('edit_step');
603
+		// and what we're doing on the current step
604
+		$this->checkout->action = $this->request->getRequestParam('action', 'display_spco_reg_step');
605
+		// timestamp
606
+		$this->checkout->uts = $this->request->getRequestParam('uts', 0, 'int');
607
+		// returning to edit ?
608
+		$this->checkout->reg_url_link = $this->request->getRequestParam('e_reg_url_link');
609
+		// add reg url link to registration query params
610
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
611
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
612
+		}
613
+		// or some other kind of revisit ?
614
+		$this->checkout->revisit = $this->request->getRequestParam('revisit', false, 'bool');
615
+		// and whether or not to generate a reg form for this request
616
+		$this->checkout->generate_reg_form = $this->request->getRequestParam('generate_reg_form', true, 'bool');
617
+		// and whether or not to process a reg form submission for this request
618
+		$this->checkout->process_form_submission = $this->request->getRequestParam(
619
+			'process_form_submission',
620
+			$this->checkout->action === 'process_reg_step',
621
+			'bool'
622
+		);
623
+		$this->checkout->process_form_submission = filter_var(
624
+			$this->checkout->action !== 'display_spco_reg_step'
625
+				? $this->checkout->process_form_submission
626
+				: false,
627
+			FILTER_VALIDATE_BOOLEAN
628
+		);
629
+		// $this->_display_request_vars();
630
+	}
631
+
632
+
633
+	/**
634
+	 *  _display_request_vars
635
+	 *
636
+	 * @return    void
637
+	 */
638
+	protected function _display_request_vars()
639
+	{
640
+		if (! WP_DEBUG) {
641
+			return;
642
+		}
643
+		EEH_Debug_Tools::printr($this->request->requestParams(), 'requestParams', __FILE__, __LINE__);
644
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
645
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
646
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
647
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
648
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
649
+		EEH_Debug_Tools::printr(
650
+			$this->checkout->generate_reg_form,
651
+			'$this->checkout->generate_reg_form',
652
+			__FILE__,
653
+			__LINE__
654
+		);
655
+		EEH_Debug_Tools::printr(
656
+			$this->checkout->process_form_submission,
657
+			'$this->checkout->process_form_submission',
658
+			__FILE__,
659
+			__LINE__
660
+		);
661
+	}
662
+
663
+
664
+	/**
665
+	 * _block_bots
666
+	 * checks that the incoming request has either of the following set:
667
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
668
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
669
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
670
+	 * then where you coming from man?
671
+	 *
672
+	 * @return boolean
673
+	 */
674
+	private function _block_bots()
675
+	{
676
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
677
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
678
+			return true;
679
+		}
680
+		return false;
681
+	}
682
+
683
+
684
+	/**
685
+	 *    _get_first_step
686
+	 *  gets slug for first step in $_reg_steps_array
687
+	 *
688
+	 * @return    string
689
+	 */
690
+	private function _get_first_step()
691
+	{
692
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
693
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
694
+	}
695
+
696
+
697
+	/**
698
+	 * instantiates each reg step based on the loaded reg_steps array
699
+	 *
700
+	 * @return    bool
701
+	 * @throws EE_Error
702
+	 * @throws InvalidArgumentException
703
+	 * @throws InvalidDataTypeException
704
+	 * @throws InvalidInterfaceException
705
+	 * @throws ReflectionException
706
+	 */
707
+	private function _load_and_instantiate_reg_steps()
708
+	{
709
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
710
+		// have reg_steps already been instantiated ?
711
+		if (
712
+			empty($this->checkout->reg_steps)
713
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
714
+		) {
715
+			// if not, then loop through raw reg steps array
716
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
717
+				if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
718
+					return false;
719
+				}
720
+			}
721
+			if (isset($this->checkout->reg_steps['registration_confirmation'])) {
722
+				// skip the registration_confirmation page ?
723
+				if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
724
+					// just remove it from the reg steps array
725
+					$this->checkout->remove_reg_step('registration_confirmation', false);
726
+				} elseif (
727
+					EE_Registry::instance()->CFG->registration->reg_confirmation_last
728
+				) {
729
+					// set the order to something big like 100
730
+					$this->checkout->set_reg_step_order('registration_confirmation');
731
+				}
732
+			}
733
+			// filter the array for good luck
734
+			$this->checkout->reg_steps = apply_filters(
735
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
736
+				$this->checkout->reg_steps
737
+			);
738
+			// finally re-sort based on the reg step class order properties
739
+			$this->checkout->sort_reg_steps();
740
+		} else {
741
+			foreach ($this->checkout->reg_steps as $reg_step) {
742
+				// set all current step stati to FALSE
743
+				$reg_step->set_is_current_step(false);
744
+			}
745
+		}
746
+		if (empty($this->checkout->reg_steps)) {
747
+			EE_Error::add_error(
748
+				esc_html__('No Reg Steps were loaded..', 'event_espresso'),
749
+				__FILE__,
750
+				__FUNCTION__,
751
+				__LINE__
752
+			);
753
+			return false;
754
+		}
755
+		// make reg step details available to JS
756
+		$this->checkout->set_reg_step_JSON_info();
757
+		return true;
758
+	}
759
+
760
+
761
+	/**
762
+	 *     _load_and_instantiate_reg_step
763
+	 *
764
+	 * @param array $reg_step
765
+	 * @param int   $order
766
+	 * @return bool
767
+	 * @throws EE_Error
768
+	 * @throws ReflectionException
769
+	 */
770
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
771
+	{
772
+		// we need a file_path, class_name, and slug to add a reg step
773
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
774
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
775
+			if (
776
+				$this->checkout->reg_url_link
777
+				&& $this->checkout->step !== $reg_step['slug']
778
+				&& $reg_step['slug'] !== 'finalize_registration'
779
+				// normally at this point we would NOT load the reg step, but this filter can change that
780
+				&& apply_filters(
781
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
782
+					true,
783
+					$reg_step,
784
+					$this->checkout
785
+				)
786
+			) {
787
+				return true;
788
+			}
789
+
790
+			// instantiate step class using file path and class name
791
+			$reg_step_obj = EE_Registry::instance()->load_file(
792
+				$reg_step['file_path'],
793
+				$reg_step['class_name'],
794
+				'class',
795
+				[$this->checkout],
796
+				false
797
+			);
798
+			// did we gets the goods ?
799
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
800
+				// set reg step order based on config
801
+				$reg_step_obj->set_order($order);
802
+				// add instantiated reg step object to the master reg steps array
803
+				$this->checkout->add_reg_step($reg_step_obj);
804
+			} else {
805
+				EE_Error::add_error(
806
+					esc_html__('The current step could not be set.', 'event_espresso'),
807
+					__FILE__,
808
+					__FUNCTION__,
809
+					__LINE__
810
+				);
811
+				return false;
812
+			}
813
+		} else {
814
+			if (WP_DEBUG) {
815
+				EE_Error::add_error(
816
+					sprintf(
817
+						esc_html__(
818
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
819
+							'event_espresso'
820
+						),
821
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
822
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
823
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
824
+						'<ul>',
825
+						'<li>',
826
+						'</li>',
827
+						'</ul>'
828
+					),
829
+					__FILE__,
830
+					__FUNCTION__,
831
+					__LINE__
832
+				);
833
+			}
834
+			return false;
835
+		}
836
+		return true;
837
+	}
838
+
839
+
840
+	/**
841
+	 * _verify_transaction_and_get_registrations
842
+	 *
843
+	 * @return bool
844
+	 * @throws EE_Error
845
+	 * @throws ReflectionException
846
+	 */
847
+	private function _verify_transaction_and_get_registrations()
848
+	{
849
+		// was there already a valid transaction in the checkout from the session ?
850
+		if (! $this->checkout->transaction instanceof EE_Transaction) {
851
+			// get transaction from db or session
852
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
853
+				? $this->_get_transaction_and_cart_for_previous_visit()
854
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
855
+			if (! $this->checkout->transaction instanceof EE_Transaction) {
856
+				EE_Error::add_error(
857
+					esc_html__(
858
+						'Your Registration and Transaction information could not be retrieved from the db.',
859
+						'event_espresso'
860
+					),
861
+					__FILE__,
862
+					__FUNCTION__,
863
+					__LINE__
864
+				);
865
+				$this->checkout->transaction = EE_Transaction::new_instance();
866
+				// add some style and make it dance
867
+				$this->add_styles_and_scripts($this);
868
+				EED_Single_Page_Checkout::$_initialized = true;
869
+				return false;
870
+			}
871
+			// and the registrations for the transaction
872
+			$this->_get_registrations($this->checkout->transaction);
873
+		}
874
+		return true;
875
+	}
876
+
877
+
878
+	/**
879
+	 * _get_transaction_and_cart_for_previous_visit
880
+	 *
881
+	 * @return EE_Transaction|null
882
+	 * @throws EE_Error
883
+	 * @throws ReflectionException
884
+	 */
885
+	private function _get_transaction_and_cart_for_previous_visit()
886
+	{
887
+		/** @var $TXN_model EEM_Transaction */
888
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
889
+		// because the reg_url_link is present in the request,
890
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
891
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
892
+		// verify transaction
893
+		if ($transaction instanceof EE_Transaction) {
894
+			// and get the cart that was used for that transaction
895
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
896
+			return $transaction;
897
+		}
898
+		EE_Error::add_error(
899
+			esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
900
+			__FILE__,
901
+			__FUNCTION__,
902
+			__LINE__
903
+		);
904
+		return null;
905
+	}
906
+
907
+
908
+	/**
909
+	 * _get_cart_for_transaction
910
+	 *
911
+	 * @param EE_Transaction $transaction
912
+	 * @return EE_Cart
913
+	 */
914
+	private function _get_cart_for_transaction($transaction)
915
+	{
916
+		return $this->checkout->get_cart_for_transaction($transaction);
917
+	}
918
+
919
+
920
+	/**
921
+	 * get_cart_for_transaction
922
+	 *
923
+	 * @param EE_Transaction $transaction
924
+	 * @return EE_Cart
925
+	 */
926
+	public function get_cart_for_transaction(EE_Transaction $transaction)
927
+	{
928
+		return $this->checkout->get_cart_for_transaction($transaction);
929
+	}
930
+
931
+
932
+	/**
933
+	 * _get_transaction_and_cart_for_current_session
934
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
935
+	 *
936
+	 * @return EE_Transaction
937
+	 * @throws EE_Error
938
+	 * @throws ReflectionException
939
+	 */
940
+	private function _get_cart_for_current_session_and_setup_new_transaction()
941
+	{
942
+		//  if there's no transaction, then this is the FIRST visit to SPCO
943
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
944
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
945
+		// and then create a new transaction
946
+		$transaction = $this->_initialize_transaction();
947
+		// verify transaction
948
+		if ($transaction instanceof EE_Transaction) {
949
+			// save it so that we have an ID for other objects to use
950
+			$transaction->save();
951
+			// and save TXN data to the cart
952
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
953
+		} else {
954
+			EE_Error::add_error(
955
+				esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
956
+				__FILE__,
957
+				__FUNCTION__,
958
+				__LINE__
959
+			);
960
+		}
961
+		return $transaction;
962
+	}
963
+
964
+
965
+	/**
966
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
967
+	 *
968
+	 * @return EE_Transaction|null
969
+	 */
970
+	private function _initialize_transaction()
971
+	{
972
+		try {
973
+			// ensure cart totals have been calculated
974
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
975
+			// grab the cart grand total
976
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
977
+			// create new TXN
978
+			$transaction = EE_Transaction::new_instance(
979
+				array(
980
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
981
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
982
+					'TXN_paid'      => 0,
983
+					'STS_ID'        => EEM_Transaction::failed_status_code,
984
+				)
985
+			);
986
+			// save it so that we have an ID for other objects to use
987
+			$transaction->save();
988
+			// set cron job for following up on TXNs after their session has expired
989
+			EE_Cron_Tasks::schedule_expired_transaction_check(
990
+				EE_Registry::instance()->SSN->expiration() + 1,
991
+				$transaction->ID()
992
+			);
993
+			return $transaction;
994
+		} catch (Exception $e) {
995
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
996
+		}
997
+		return null;
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * _get_registrations
1003
+	 *
1004
+	 * @param EE_Transaction $transaction
1005
+	 * @return void
1006
+	 * @throws EE_Error
1007
+	 * @throws ReflectionException
1008
+	 */
1009
+	private function _get_registrations(EE_Transaction $transaction)
1010
+	{
1011
+		// first step: grab the registrants  { : o
1012
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1013
+		$this->checkout->total_ticket_count = count($registrations);
1014
+		// verify registrations have been set
1015
+		if (empty($registrations)) {
1016
+			// if no cached registrations, then check the db
1017
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1018
+			// still nothing ? well as long as this isn't a revisit
1019
+			if (empty($registrations) && ! $this->checkout->revisit) {
1020
+				// generate new registrations from scratch
1021
+				$registrations = $this->_initialize_registrations($transaction);
1022
+			}
1023
+		}
1024
+		// sort by their original registration order
1025
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1026
+		// then loop thru the array
1027
+		foreach ($registrations as $registration) {
1028
+			// verify each registration
1029
+			if ($registration instanceof EE_Registration) {
1030
+				// we display all attendee info for the primary registrant
1031
+				if (
1032
+					$this->checkout->reg_url_link === $registration->reg_url_link()
1033
+					&& $registration->is_primary_registrant()
1034
+				) {
1035
+					$this->checkout->primary_revisit = true;
1036
+					break;
1037
+				}
1038
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1039
+					// but hide info if it doesn't belong to you
1040
+					$transaction->clear_cache('Registration', $registration->ID());
1041
+					$this->checkout->total_ticket_count--;
1042
+				}
1043
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1044
+			}
1045
+		}
1046
+	}
1047
+
1048
+
1049
+	/**
1050
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1051
+	 *
1052
+	 * @param EE_Transaction $transaction
1053
+	 * @return    array
1054
+	 * @throws EE_Error
1055
+	 * @throws ReflectionException
1056
+	 */
1057
+	private function _initialize_registrations(EE_Transaction $transaction)
1058
+	{
1059
+		$att_nmbr = 0;
1060
+		$registrations = array();
1061
+		if ($transaction instanceof EE_Transaction) {
1062
+			/** @type EE_Registration_Processor $registration_processor */
1063
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1064
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1065
+			// now let's add the cart items to the $transaction
1066
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1067
+				// do the following for each ticket of this type they selected
1068
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1069
+					$att_nmbr++;
1070
+					/** @var CreateRegistrationCommand $CreateRegistrationCommand */
1071
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1072
+						CreateRegistrationCommand::class,
1073
+						[
1074
+							$transaction,
1075
+							$line_item,
1076
+							$att_nmbr,
1077
+							$this->checkout->total_ticket_count,
1078
+						]
1079
+					);
1080
+					// override capabilities for frontend registrations
1081
+					if ($this->request->isFrontend()) {
1082
+						$CreateRegistrationCommand->setCapCheck(
1083
+							new PublicCapabilities('', 'create_new_registration')
1084
+						);
1085
+					}
1086
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1087
+					if (! $registration instanceof EE_Registration) {
1088
+						throw new InvalidEntityException($registration, 'EE_Registration');
1089
+					}
1090
+					$registrations[ $registration->ID() ] = $registration;
1091
+				}
1092
+			}
1093
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1094
+		}
1095
+		return $registrations;
1096
+	}
1097
+
1098
+
1099
+	/**
1100
+	 * sorts registrations by REG_count
1101
+	 *
1102
+	 * @param EE_Registration $reg_A
1103
+	 * @param EE_Registration $reg_B
1104
+	 * @return int
1105
+	 */
1106
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1107
+	{
1108
+		// this shouldn't ever happen within the same TXN, but oh well
1109
+		if ($reg_A->count() === $reg_B->count()) {
1110
+			return 0;
1111
+		}
1112
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1113
+	}
1114
+
1115
+
1116
+	/**
1117
+	 *    _final_verifications
1118
+	 * just makes sure that everything is set up correctly before proceeding
1119
+	 *
1120
+	 * @return    bool
1121
+	 * @throws EE_Error
1122
+	 * @throws ReflectionException
1123
+	 */
1124
+	private function _final_verifications()
1125
+	{
1126
+		// filter checkout
1127
+		$this->checkout = apply_filters(
1128
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1129
+			$this->checkout
1130
+		);
1131
+		// verify that current step is still set correctly
1132
+		if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1133
+			EE_Error::add_error(
1134
+				esc_html__(
1135
+					'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1136
+					'event_espresso'
1137
+				),
1138
+				__FILE__,
1139
+				__FUNCTION__,
1140
+				__LINE__
1141
+			);
1142
+			return false;
1143
+		}
1144
+		// if returning to SPCO, then verify that primary registrant is set
1145
+		if (! empty($this->checkout->reg_url_link)) {
1146
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1147
+			if (! $valid_registrant instanceof EE_Registration) {
1148
+				EE_Error::add_error(
1149
+					esc_html__(
1150
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1151
+						'event_espresso'
1152
+					),
1153
+					__FILE__,
1154
+					__FUNCTION__,
1155
+					__LINE__
1156
+				);
1157
+				return false;
1158
+			}
1159
+			$valid_registrant = null;
1160
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1161
+				if (
1162
+					$registration instanceof EE_Registration
1163
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1164
+				) {
1165
+					$valid_registrant = $registration;
1166
+				}
1167
+			}
1168
+			if (! $valid_registrant instanceof EE_Registration) {
1169
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1170
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1171
+					// clear the session, mark the checkout as unverified, and try again
1172
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1173
+					EED_Single_Page_Checkout::$_initialized = false;
1174
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1175
+					$this->_initialize();
1176
+					EE_Error::reset_notices();
1177
+					return false;
1178
+				}
1179
+				EE_Error::add_error(
1180
+					esc_html__(
1181
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1182
+						'event_espresso'
1183
+					),
1184
+					__FILE__,
1185
+					__FUNCTION__,
1186
+					__LINE__
1187
+				);
1188
+				return false;
1189
+			}
1190
+		}
1191
+		// now that things have been kinda sufficiently verified,
1192
+		// let's add the checkout to the session so that it's available to other systems
1193
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1194
+		return true;
1195
+	}
1196
+
1197
+
1198
+	/**
1199
+	 *    _initialize_reg_steps
1200
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1201
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1202
+	 *
1203
+	 * @param bool $reinitializing
1204
+	 * @throws EE_Error
1205
+	 */
1206
+	private function _initialize_reg_steps($reinitializing = false)
1207
+	{
1208
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1209
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1210
+		foreach ($this->checkout->reg_steps as $reg_step) {
1211
+			if (! $reg_step->initialize_reg_step()) {
1212
+				// if not initialized then maybe this step is being removed...
1213
+				if (! $reinitializing && $reg_step->is_current_step()) {
1214
+					// if it was the current step, then we need to start over here
1215
+					$this->_initialize_reg_steps(true);
1216
+					return;
1217
+				}
1218
+				continue;
1219
+			}
1220
+			// add css and JS for current step
1221
+			$this->add_styles_and_scripts($reg_step);
1222
+			if ($reg_step->is_current_step()) {
1223
+				// the text that appears on the reg step form submit button
1224
+				$reg_step->set_submit_button_text();
1225
+			}
1226
+		}
1227
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1228
+		do_action(
1229
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1230
+			$this->checkout->current_step
1231
+		);
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 * _check_form_submission
1237
+	 *
1238
+	 * @return boolean
1239
+	 * @throws EE_Error
1240
+	 * @throws ReflectionException
1241
+	 */
1242
+	private function _check_form_submission()
1243
+	{
1244
+		// does this request require the reg form to be generated ?
1245
+		if ($this->checkout->generate_reg_form) {
1246
+			// ever heard that song by Blue Rodeo ?
1247
+			try {
1248
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1249
+				// if not displaying a form, then check for form submission
1250
+				if (
1251
+					$this->checkout->process_form_submission
1252
+					&& $this->checkout->current_step->reg_form->was_submitted()
1253
+				) {
1254
+					// clear out any old data in case this step is being run again
1255
+					$this->checkout->current_step->set_valid_data(array());
1256
+					// capture submitted form data
1257
+					$request_data = $this->request->requestParams();
1258
+					$this->checkout->current_step->reg_form->receive_form_submission(
1259
+						(array) apply_filters(
1260
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1261
+							$request_data,
1262
+							$this->checkout
1263
+						)
1264
+					);
1265
+					// validate submitted form data
1266
+					if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1267
+						// thou shall not pass !!!
1268
+						$this->checkout->continue_reg = false;
1269
+						// any form validation errors?
1270
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1271
+							EE_Error::add_error(
1272
+								$this->checkout->current_step->reg_form->submission_error_message(),
1273
+								__FILE__,
1274
+								__FUNCTION__,
1275
+								__LINE__
1276
+							);
1277
+						}
1278
+						// well not really... what will happen is
1279
+						// we'll just get redirected back to redo the current step
1280
+						$this->go_to_next_step();
1281
+						return false;
1282
+					}
1283
+				}
1284
+			} catch (EE_Error $e) {
1285
+				$e->get_error();
1286
+			}
1287
+		}
1288
+		return true;
1289
+	}
1290
+
1291
+
1292
+	/**
1293
+	 * _process_action
1294
+	 *
1295
+	 * @return void
1296
+	 * @throws EE_Error
1297
+	 * @throws ReflectionException
1298
+	 */
1299
+	private function _process_form_action()
1300
+	{
1301
+		// what cha wanna do?
1302
+		switch ($this->checkout->action) {
1303
+			// AJAX next step reg form
1304
+			case 'display_spco_reg_step':
1305
+				$this->checkout->redirect = false;
1306
+				if ($this->request->isAjax()) {
1307
+					$this->checkout->json_response->set_reg_step_html(
1308
+						$this->checkout->current_step->display_reg_form()
1309
+					);
1310
+				}
1311
+				break;
1312
+			default:
1313
+				// meh... do one of those other steps first
1314
+				if (
1315
+					! empty($this->checkout->action)
1316
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1317
+				) {
1318
+					// dynamically creates hook point like:
1319
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1320
+					do_action(
1321
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1322
+						$this->checkout->current_step
1323
+					);
1324
+					$process_reg_step = apply_filters(
1325
+						"AHEE__Single_Page_Checkout__process_reg_step__{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1326
+						true,
1327
+						$this->checkout->current_step,
1328
+						$this
1329
+					);
1330
+					// call action on current step
1331
+					if ($process_reg_step && call_user_func([$this->checkout->current_step, $this->checkout->action])) {
1332
+						// good registrant, you get to proceed
1333
+						if (
1334
+							$this->checkout->current_step->success_message() !== ''
1335
+							&& apply_filters(
1336
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1337
+								false
1338
+							)
1339
+						) {
1340
+							EE_Error::add_success(
1341
+								$this->checkout->current_step->success_message()
1342
+								. '<br />' . $this->checkout->next_step->_instructions()
1343
+							);
1344
+						}
1345
+						// pack it up, pack it in...
1346
+						$this->_setup_redirect();
1347
+					}
1348
+					// dynamically creates hook point like:
1349
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1350
+					do_action(
1351
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1352
+						$this->checkout->current_step
1353
+					);
1354
+				} else {
1355
+					EE_Error::add_error(
1356
+						sprintf(
1357
+							esc_html__(
1358
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1359
+								'event_espresso'
1360
+							),
1361
+							$this->checkout->action,
1362
+							$this->checkout->current_step->name()
1363
+						),
1364
+						__FILE__,
1365
+						__FUNCTION__,
1366
+						__LINE__
1367
+					);
1368
+				}
1369
+			// end default
1370
+		}
1371
+		// store our progress so far
1372
+		$this->checkout->stash_transaction_and_checkout();
1373
+		// advance to the next step! If you pass GO, collect $200
1374
+		$this->go_to_next_step();
1375
+	}
1376
+
1377
+
1378
+	/**
1379
+	 * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target an object with the method `translate_js_strings` and
1380
+	 *                                                          `enqueue_styles_and_scripts`.
1381
+	 * @return        void
1382
+	 */
1383
+	public function add_styles_and_scripts($target)
1384
+	{
1385
+		// i18n
1386
+		$target->translate_js_strings();
1387
+		if ($this->checkout->admin_request) {
1388
+			add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1389
+		} else {
1390
+			add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1391
+		}
1392
+	}
1393
+
1394
+	/**
1395
+	 *        translate_js_strings
1396
+	 *
1397
+	 * @return        void
1398
+	 */
1399
+	public function translate_js_strings()
1400
+	{
1401
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1402
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1403
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1404
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1405
+			'event_espresso'
1406
+		);
1407
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1408
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1409
+			'event_espresso'
1410
+		);
1411
+		EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1412
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1413
+			'event_espresso'
1414
+		);
1415
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1416
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1417
+			'event_espresso'
1418
+		);
1419
+		EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1420
+			'This registration step could not be completed. Please refresh the page and try again.',
1421
+			'event_espresso'
1422
+		);
1423
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1424
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1425
+			'event_espresso'
1426
+		);
1427
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1428
+			esc_html__(
1429
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1430
+				'event_espresso'
1431
+			),
1432
+			'<br/>',
1433
+			'<br/>'
1434
+		);
1435
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1436
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1437
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1438
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1439
+		EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1440
+		EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1441
+		EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1442
+		EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1443
+		EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1444
+		EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1445
+		EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1446
+		EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1447
+		EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1448
+		EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1449
+		EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1450
+		EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1451
+		EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1452
+		EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1453
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1454
+		);
1455
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1456
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1457
+			true
1458
+		);
1459
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1460
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1461
+		);
1462
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1463
+			'M d, Y H:i:s',
1464
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1465
+		);
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 *    enqueue_styles_and_scripts
1471
+	 *
1472
+	 * @return        void
1473
+	 * @throws EE_Error
1474
+	 */
1475
+	public function enqueue_styles_and_scripts()
1476
+	{
1477
+		// load css
1478
+		wp_register_style(
1479
+			'single_page_checkout',
1480
+			SPCO_CSS_URL . 'single_page_checkout.css',
1481
+			array('espresso_default'),
1482
+			EVENT_ESPRESSO_VERSION
1483
+		);
1484
+		wp_enqueue_style('single_page_checkout');
1485
+		// load JS
1486
+		wp_register_script(
1487
+			'jquery_plugin',
1488
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1489
+			array('jquery'),
1490
+			'1.0.1',
1491
+			true
1492
+		);
1493
+		wp_register_script(
1494
+			'jquery_countdown',
1495
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1496
+			array('jquery_plugin'),
1497
+			'2.1.0',
1498
+			true
1499
+		);
1500
+		wp_register_script(
1501
+			'single_page_checkout',
1502
+			SPCO_JS_URL . 'single_page_checkout.js',
1503
+			array('espresso_core', 'underscore', 'ee_form_section_validation'),
1504
+			EVENT_ESPRESSO_VERSION,
1505
+			true
1506
+		);
1507
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1508
+			$this->checkout->registration_form->enqueue_js();
1509
+		}
1510
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1511
+			$this->checkout->current_step->reg_form->enqueue_js();
1512
+		}
1513
+		wp_enqueue_script('single_page_checkout');
1514
+		if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1515
+			wp_enqueue_script('jquery_countdown');
1516
+		}
1517
+		/**
1518
+		 * global action hook for enqueueing styles and scripts with
1519
+		 * spco calls.
1520
+		 */
1521
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1522
+		/**
1523
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1524
+		 * The hook will end up being something like:
1525
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1526
+		 */
1527
+		do_action(
1528
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1529
+			$this
1530
+		);
1531
+	}
1532
+
1533
+
1534
+	/**
1535
+	 *    display the Registration Single Page Checkout Form
1536
+	 *
1537
+	 * @return    void
1538
+	 * @throws EE_Error
1539
+	 * @throws ReflectionException
1540
+	 */
1541
+	private function _display_spco_reg_form()
1542
+	{
1543
+		// if registering via the admin, just display the reg form for the current step
1544
+		if ($this->checkout->admin_request) {
1545
+			EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->current_step->display_reg_form());
1546
+		} else {
1547
+			// add powered by EE msg
1548
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1549
+			$empty_cart = count(
1550
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1551
+			) < 1;
1552
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1553
+			$cookies_not_set_msg = '';
1554
+			if ($empty_cart) {
1555
+				$cookies_not_set_msg = apply_filters(
1556
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1557
+					sprintf(
1558
+						esc_html__(
1559
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1560
+							'event_espresso'
1561
+						),
1562
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1563
+						'</div>',
1564
+						'<h6 class="important-notice">',
1565
+						'</h6>',
1566
+						'<p>',
1567
+						'</p>',
1568
+						'<br />',
1569
+						'<a href="https://www.whatismybrowser.com/guides/how-to-enable-cookies/" target="_blank" rel="noopener noreferrer">',
1570
+						'</a>'
1571
+					)
1572
+				);
1573
+			}
1574
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1575
+				array(
1576
+					'name'            => 'single-page-checkout',
1577
+					'html_id'         => 'ee-single-page-checkout-dv',
1578
+					'layout_strategy' =>
1579
+						new EE_Template_Layout(
1580
+							array(
1581
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1582
+								'template_args'        => array(
1583
+									'empty_cart'              => $empty_cart,
1584
+									'revisit'                 => $this->checkout->revisit,
1585
+									'reg_steps'               => $this->checkout->reg_steps,
1586
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1587
+										? $this->checkout->next_step->slug()
1588
+										: '',
1589
+									'empty_msg'               => apply_filters(
1590
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1591
+										sprintf(
1592
+											esc_html__(
1593
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1594
+												'event_espresso'
1595
+											),
1596
+											'<a href="'
1597
+											. get_post_type_archive_link('espresso_events')
1598
+											. '" title="',
1599
+											'">',
1600
+											'</a>'
1601
+										)
1602
+									),
1603
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1604
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1605
+									'session_expiration'      => gmdate(
1606
+										'M d, Y H:i:s',
1607
+										EE_Registry::instance()->SSN->expiration()
1608
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1609
+									),
1610
+								),
1611
+							)
1612
+						),
1613
+				)
1614
+			);
1615
+			// load template and add to output sent that gets filtered into the_content()
1616
+			EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->registration_form->get_html());
1617
+		}
1618
+	}
1619
+
1620
+
1621
+	/**
1622
+	 *    add_extra_finalize_registration_inputs
1623
+	 *
1624
+	 * @param $next_step
1625
+	 * @internal  param string $label
1626
+	 * @return void
1627
+	 */
1628
+	public function add_extra_finalize_registration_inputs($next_step)
1629
+	{
1630
+		if ($next_step === 'finalize_registration') {
1631
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1632
+		}
1633
+	}
1634
+
1635
+
1636
+	/**
1637
+	 *    display_registration_footer
1638
+	 *
1639
+	 * @return    string
1640
+	 */
1641
+	public static function display_registration_footer()
1642
+	{
1643
+		if (
1644
+			apply_filters(
1645
+				'FHEE__EE_Front__Controller__show_reg_footer',
1646
+				EE_Registry::instance()->CFG->admin->show_reg_footer
1647
+			)
1648
+		) {
1649
+			add_filter(
1650
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1651
+				function ($url) {
1652
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1653
+				}
1654
+			);
1655
+			echo apply_filters(
1656
+				'FHEE__EE_Front_Controller__display_registration_footer',
1657
+				EEH_Template::powered_by_event_espresso(
1658
+					'',
1659
+					'espresso-registration-footer-dv',
1660
+					array('utm_content' => 'registration_checkout')
1661
+				)
1662
+			);
1663
+		}
1664
+		return '';
1665
+	}
1666
+
1667
+
1668
+	/**
1669
+	 *    unlock_transaction
1670
+	 *
1671
+	 * @return    void
1672
+	 * @throws EE_Error
1673
+	 * @throws ReflectionException
1674
+	 */
1675
+	public function unlock_transaction()
1676
+	{
1677
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1678
+			$this->checkout->transaction->unlock();
1679
+		}
1680
+	}
1681
+
1682
+
1683
+	/**
1684
+	 *        _setup_redirect
1685
+	 *
1686
+	 * @return void
1687
+	 */
1688
+	private function _setup_redirect()
1689
+	{
1690
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1691
+			$this->checkout->redirect = true;
1692
+			if (empty($this->checkout->redirect_url)) {
1693
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1694
+			}
1695
+			$this->checkout->redirect_url = apply_filters(
1696
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1697
+				$this->checkout->redirect_url,
1698
+				$this->checkout
1699
+			);
1700
+		}
1701
+	}
1702
+
1703
+
1704
+	/**
1705
+	 *   handle ajax message responses and redirects
1706
+	 *
1707
+	 * @return void
1708
+	 * @throws EE_Error
1709
+	 * @throws ReflectionException
1710
+	 */
1711
+	public function go_to_next_step()
1712
+	{
1713
+		if ($this->request->isAjax()) {
1714
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1715
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1716
+		}
1717
+		$this->unlock_transaction();
1718
+		// just return for these conditions
1719
+		if (
1720
+			$this->checkout->admin_request
1721
+			|| $this->checkout->action === 'redirect_form'
1722
+			|| $this->checkout->action === 'update_checkout'
1723
+		) {
1724
+			return;
1725
+		}
1726
+		// AJAX response
1727
+		$this->_handle_json_response();
1728
+		// redirect to next step or the Thank You page
1729
+		$this->_handle_html_redirects();
1730
+		// hmmm... must be something wrong, so let's just display the form again !
1731
+		$this->_display_spco_reg_form();
1732
+	}
1733
+
1734
+
1735
+	/**
1736
+	 *   _handle_json_response
1737
+	 *
1738
+	 * @return void
1739
+	 * @throws EE_Error
1740
+	 */
1741
+	protected function _handle_json_response()
1742
+	{
1743
+		// if this is an ajax request
1744
+		if ($this->request->isAjax()) {
1745
+			$this->checkout->json_response->set_registration_time_limit(
1746
+				$this->checkout->get_registration_time_limit()
1747
+			);
1748
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1749
+			// just send the ajax (
1750
+			$json_response = apply_filters(
1751
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1752
+				$this->checkout->json_response
1753
+			);
1754
+			echo ($json_response);
1755
+			exit();
1756
+		}
1757
+	}
1758
+
1759
+
1760
+	/**
1761
+	 *   _handle_redirects
1762
+	 *
1763
+	 * @return void
1764
+	 */
1765
+	protected function _handle_html_redirects()
1766
+	{
1767
+		// going somewhere ?
1768
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1769
+			// store notices in a transient
1770
+			EE_Error::get_notices(false, true);
1771
+			wp_safe_redirect($this->checkout->redirect_url);
1772
+			exit();
1773
+		}
1774
+	}
1775
+
1776
+
1777
+	/**
1778
+	 *   set_checkout_anchor
1779
+	 *
1780
+	 * @return void
1781
+	 */
1782
+	public function set_checkout_anchor()
1783
+	{
1784
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1785
+	}
1786
+
1787
+	/**
1788
+	 *    getRegistrationExpirationNotice
1789
+	 *
1790
+	 * @since     4.9.59.p
1791
+	 * @return    string
1792
+	 */
1793
+	public static function getRegistrationExpirationNotice()
1794
+	{
1795
+		return sprintf(
1796
+			esc_html__(
1797
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1798
+				'event_espresso'
1799
+			),
1800
+			'<h4 class="important-notice">',
1801
+			'</h4>',
1802
+			'<br />',
1803
+			'<p>',
1804
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1805
+			'">',
1806
+			'</a>',
1807
+			'</p>'
1808
+		);
1809
+	}
1810 1810
 }
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +2145 added lines, -2145 removed lines patch added patch discarded remove patch
@@ -14,2205 +14,2205 @@
 block discarded – undo
14 14
  */
15 15
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
16 16
 {
17
-    /**
18
-     * This property is just used to hold the status of whether an event is currently being
19
-     * created (true) or edited (false)
20
-     *
21
-     * @access protected
22
-     * @var bool
23
-     */
24
-    protected $_is_creating_event;
17
+	/**
18
+	 * This property is just used to hold the status of whether an event is currently being
19
+	 * created (true) or edited (false)
20
+	 *
21
+	 * @access protected
22
+	 * @var bool
23
+	 */
24
+	protected $_is_creating_event;
25 25
 
26
-    /**
27
-     * Used to contain the format strings for date and time that will be used for php date and
28
-     * time.
29
-     * Is set in the _set_hooks_properties() method.
30
-     *
31
-     * @var array
32
-     */
33
-    protected $_date_format_strings;
26
+	/**
27
+	 * Used to contain the format strings for date and time that will be used for php date and
28
+	 * time.
29
+	 * Is set in the _set_hooks_properties() method.
30
+	 *
31
+	 * @var array
32
+	 */
33
+	protected $_date_format_strings;
34 34
 
35
-    /**
36
-     * @var string $_date_time_format
37
-     */
38
-    protected $_date_time_format;
35
+	/**
36
+	 * @var string $_date_time_format
37
+	 */
38
+	protected $_date_time_format;
39 39
 
40 40
 
41
-    /**
42
-     * @throws InvalidArgumentException
43
-     * @throws InvalidInterfaceException
44
-     * @throws InvalidDataTypeException
45
-     */
46
-    protected function _set_hooks_properties()
47
-    {
48
-        $this->_name = 'pricing';
49
-        // capability check
50
-        if (
51
-            ! EE_Registry::instance()->CAP->current_user_can(
52
-                'ee_read_default_prices',
53
-                'advanced_ticket_datetime_metabox'
54
-            )
55
-        ) {
56
-            return;
57
-        }
58
-        $this->_setup_metaboxes();
59
-        $this->_set_date_time_formats();
60
-        $this->_validate_format_strings();
61
-        $this->_set_scripts_styles();
62
-        // commented out temporarily until logic is implemented in callback
63
-        // add_action(
64
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
65
-        //     array($this, 'autosave_handling')
66
-        // );
67
-        add_filter(
68
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
69
-            array($this, 'caf_updates')
70
-        );
71
-    }
41
+	/**
42
+	 * @throws InvalidArgumentException
43
+	 * @throws InvalidInterfaceException
44
+	 * @throws InvalidDataTypeException
45
+	 */
46
+	protected function _set_hooks_properties()
47
+	{
48
+		$this->_name = 'pricing';
49
+		// capability check
50
+		if (
51
+			! EE_Registry::instance()->CAP->current_user_can(
52
+				'ee_read_default_prices',
53
+				'advanced_ticket_datetime_metabox'
54
+			)
55
+		) {
56
+			return;
57
+		}
58
+		$this->_setup_metaboxes();
59
+		$this->_set_date_time_formats();
60
+		$this->_validate_format_strings();
61
+		$this->_set_scripts_styles();
62
+		// commented out temporarily until logic is implemented in callback
63
+		// add_action(
64
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
65
+		//     array($this, 'autosave_handling')
66
+		// );
67
+		add_filter(
68
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
69
+			array($this, 'caf_updates')
70
+		);
71
+	}
72 72
 
73 73
 
74
-    /**
75
-     * @return void
76
-     */
77
-    protected function _setup_metaboxes()
78
-    {
79
-        // if we were going to add our own metaboxes we'd use the below.
80
-        $this->_metaboxes = array(
81
-            0 => array(
82
-                'page_route' => array('edit', 'create_new'),
83
-                'func'       => 'pricing_metabox',
84
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
85
-                'priority'   => 'high',
86
-                'context'    => 'normal',
87
-            ),
88
-        );
89
-        $this->_remove_metaboxes = array(
90
-            0 => array(
91
-                'page_route' => array('edit', 'create_new'),
92
-                'id'         => 'espresso_event_editor_tickets',
93
-                'context'    => 'normal',
94
-            ),
95
-        );
96
-    }
74
+	/**
75
+	 * @return void
76
+	 */
77
+	protected function _setup_metaboxes()
78
+	{
79
+		// if we were going to add our own metaboxes we'd use the below.
80
+		$this->_metaboxes = array(
81
+			0 => array(
82
+				'page_route' => array('edit', 'create_new'),
83
+				'func'       => 'pricing_metabox',
84
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
85
+				'priority'   => 'high',
86
+				'context'    => 'normal',
87
+			),
88
+		);
89
+		$this->_remove_metaboxes = array(
90
+			0 => array(
91
+				'page_route' => array('edit', 'create_new'),
92
+				'id'         => 'espresso_event_editor_tickets',
93
+				'context'    => 'normal',
94
+			),
95
+		);
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * @return void
101
-     */
102
-    protected function _set_date_time_formats()
103
-    {
104
-        /**
105
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
106
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
107
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
108
-         *
109
-         * @since 4.6.7
110
-         * @var array  Expected an array returned with 'date' and 'time' keys.
111
-         */
112
-        $this->_date_format_strings = apply_filters(
113
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
114
-            array(
115
-                'date' => 'Y-m-d',
116
-                'time' => 'h:i a',
117
-            )
118
-        );
119
-        // validate
120
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
121
-            ? $this->_date_format_strings['date']
122
-            : null;
123
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
124
-            ? $this->_date_format_strings['time']
125
-            : null;
126
-        $this->_date_time_format = $this->_date_format_strings['date']
127
-                                   . ' '
128
-                                   . $this->_date_format_strings['time'];
129
-    }
99
+	/**
100
+	 * @return void
101
+	 */
102
+	protected function _set_date_time_formats()
103
+	{
104
+		/**
105
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
106
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
107
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
108
+		 *
109
+		 * @since 4.6.7
110
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
111
+		 */
112
+		$this->_date_format_strings = apply_filters(
113
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
114
+			array(
115
+				'date' => 'Y-m-d',
116
+				'time' => 'h:i a',
117
+			)
118
+		);
119
+		// validate
120
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
121
+			? $this->_date_format_strings['date']
122
+			: null;
123
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
124
+			? $this->_date_format_strings['time']
125
+			: null;
126
+		$this->_date_time_format = $this->_date_format_strings['date']
127
+								   . ' '
128
+								   . $this->_date_format_strings['time'];
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * @return void
134
-     */
135
-    protected function _validate_format_strings()
136
-    {
137
-        // validate format strings
138
-        $format_validation = EEH_DTT_Helper::validate_format_string(
139
-            $this->_date_time_format
140
-        );
141
-        if (is_array($format_validation)) {
142
-            $msg = '<p>';
143
-            $msg .= sprintf(
144
-                esc_html__(
145
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
146
-                    'event_espresso'
147
-                ),
148
-                $this->_date_time_format
149
-            );
150
-            $msg .= '</p><ul>';
151
-            foreach ($format_validation as $error) {
152
-                $msg .= '<li>' . $error . '</li>';
153
-            }
154
-            $msg .= '</ul><p>';
155
-            $msg .= sprintf(
156
-                esc_html__(
157
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
158
-                    'event_espresso'
159
-                ),
160
-                '<span style="color:#D54E21;">',
161
-                '</span>'
162
-            );
163
-            $msg .= '</p>';
164
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
165
-            $this->_date_format_strings = array(
166
-                'date' => 'Y-m-d',
167
-                'time' => 'h:i a',
168
-            );
169
-        }
170
-    }
132
+	/**
133
+	 * @return void
134
+	 */
135
+	protected function _validate_format_strings()
136
+	{
137
+		// validate format strings
138
+		$format_validation = EEH_DTT_Helper::validate_format_string(
139
+			$this->_date_time_format
140
+		);
141
+		if (is_array($format_validation)) {
142
+			$msg = '<p>';
143
+			$msg .= sprintf(
144
+				esc_html__(
145
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
146
+					'event_espresso'
147
+				),
148
+				$this->_date_time_format
149
+			);
150
+			$msg .= '</p><ul>';
151
+			foreach ($format_validation as $error) {
152
+				$msg .= '<li>' . $error . '</li>';
153
+			}
154
+			$msg .= '</ul><p>';
155
+			$msg .= sprintf(
156
+				esc_html__(
157
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
158
+					'event_espresso'
159
+				),
160
+				'<span style="color:#D54E21;">',
161
+				'</span>'
162
+			);
163
+			$msg .= '</p>';
164
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
165
+			$this->_date_format_strings = array(
166
+				'date' => 'Y-m-d',
167
+				'time' => 'h:i a',
168
+			);
169
+		}
170
+	}
171 171
 
172 172
 
173
-    /**
174
-     * @return void
175
-     */
176
-    protected function _set_scripts_styles()
177
-    {
178
-        $this->_scripts_styles = array(
179
-            'registers'   => array(
180
-                'ee-tickets-datetimes-css' => array(
181
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
182
-                    'type' => 'css',
183
-                ),
184
-                'ee-dtt-ticket-metabox'    => array(
185
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
186
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
187
-                ),
188
-            ),
189
-            'deregisters' => array(
190
-                'event-editor-css'       => array('type' => 'css'),
191
-                'event-datetime-metabox' => array('type' => 'js'),
192
-            ),
193
-            'enqueues'    => array(
194
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
195
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
196
-            ),
197
-            'localize'    => array(
198
-                'ee-dtt-ticket-metabox' => array(
199
-                    'DTT_TRASH_BLOCK'       => array(
200
-                        'main_warning'            => esc_html__(
201
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
202
-                            'event_espresso'
203
-                        ),
204
-                        'after_warning'           => esc_html__(
205
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
206
-                            'event_espresso'
207
-                        ),
208
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
209
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
210
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
211
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
212
-                        'single_warning_from_tkt' => esc_html__(
213
-                            'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
214
-                            'event_espresso'
215
-                        ),
216
-                        'single_warning_from_dtt' => esc_html__(
217
-                            'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
218
-                            'event_espresso'
219
-                        ),
220
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
221
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
222
-                    ),
223
-                    'DTT_ERROR_MSG'         => array(
224
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
225
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
226
-                                            . '<button class="button-secondary ee-modal-cancel">'
227
-                                            . esc_html__('Dismiss', 'event_espresso')
228
-                                            . '</button></div>',
229
-                    ),
230
-                    'DTT_OVERSELL_WARNING'  => array(
231
-                        'datetime_ticket' => esc_html__(
232
-                            'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
233
-                            'event_espresso'
234
-                        ),
235
-                        'ticket_datetime' => esc_html__(
236
-                            'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
237
-                            'event_espresso'
238
-                        ),
239
-                    ),
240
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
241
-                        $this->_date_format_strings['date'],
242
-                        $this->_date_format_strings['time']
243
-                    ),
244
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
245
-                ),
246
-            ),
247
-        );
248
-    }
173
+	/**
174
+	 * @return void
175
+	 */
176
+	protected function _set_scripts_styles()
177
+	{
178
+		$this->_scripts_styles = array(
179
+			'registers'   => array(
180
+				'ee-tickets-datetimes-css' => array(
181
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
182
+					'type' => 'css',
183
+				),
184
+				'ee-dtt-ticket-metabox'    => array(
185
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
186
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
187
+				),
188
+			),
189
+			'deregisters' => array(
190
+				'event-editor-css'       => array('type' => 'css'),
191
+				'event-datetime-metabox' => array('type' => 'js'),
192
+			),
193
+			'enqueues'    => array(
194
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
195
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
196
+			),
197
+			'localize'    => array(
198
+				'ee-dtt-ticket-metabox' => array(
199
+					'DTT_TRASH_BLOCK'       => array(
200
+						'main_warning'            => esc_html__(
201
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
202
+							'event_espresso'
203
+						),
204
+						'after_warning'           => esc_html__(
205
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
206
+							'event_espresso'
207
+						),
208
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
209
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
210
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
211
+													 . esc_html__('Close', 'event_espresso') . '</button>',
212
+						'single_warning_from_tkt' => esc_html__(
213
+							'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
214
+							'event_espresso'
215
+						),
216
+						'single_warning_from_dtt' => esc_html__(
217
+							'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
218
+							'event_espresso'
219
+						),
220
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
221
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
222
+					),
223
+					'DTT_ERROR_MSG'         => array(
224
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
225
+						'dismiss_button' => '<div class="save-cancel-button-container">'
226
+											. '<button class="button-secondary ee-modal-cancel">'
227
+											. esc_html__('Dismiss', 'event_espresso')
228
+											. '</button></div>',
229
+					),
230
+					'DTT_OVERSELL_WARNING'  => array(
231
+						'datetime_ticket' => esc_html__(
232
+							'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
233
+							'event_espresso'
234
+						),
235
+						'ticket_datetime' => esc_html__(
236
+							'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
237
+							'event_espresso'
238
+						),
239
+					),
240
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
241
+						$this->_date_format_strings['date'],
242
+						$this->_date_format_strings['time']
243
+					),
244
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
245
+				),
246
+			),
247
+		);
248
+	}
249 249
 
250 250
 
251
-    /**
252
-     * @param array $update_callbacks
253
-     * @return array
254
-     */
255
-    public function caf_updates(array $update_callbacks)
256
-    {
257
-        foreach ($update_callbacks as $key => $callback) {
258
-            if ($callback[1] === '_default_tickets_update') {
259
-                unset($update_callbacks[ $key ]);
260
-            }
261
-        }
262
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
263
-        return $update_callbacks;
264
-    }
251
+	/**
252
+	 * @param array $update_callbacks
253
+	 * @return array
254
+	 */
255
+	public function caf_updates(array $update_callbacks)
256
+	{
257
+		foreach ($update_callbacks as $key => $callback) {
258
+			if ($callback[1] === '_default_tickets_update') {
259
+				unset($update_callbacks[ $key ]);
260
+			}
261
+		}
262
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
263
+		return $update_callbacks;
264
+	}
265 265
 
266 266
 
267
-    /**
268
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
269
-     *
270
-     * @param  EE_Event $event The Event object we're attaching data to
271
-     * @param  array    $data  The request data from the form
272
-     * @throws ReflectionException
273
-     * @throws Exception
274
-     * @throws InvalidInterfaceException
275
-     * @throws InvalidDataTypeException
276
-     * @throws EE_Error
277
-     * @throws InvalidArgumentException
278
-     */
279
-    public function datetime_and_tickets_caf_update($event, $data)
280
-    {
281
-        // first we need to start with datetimes cause they are the "root" items attached to events.
282
-        $saved_datetimes = $this->_update_datetimes($event, $data);
283
-        // next tackle the tickets (and prices?)
284
-        $this->_update_tickets($event, $saved_datetimes, $data);
285
-    }
267
+	/**
268
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
269
+	 *
270
+	 * @param  EE_Event $event The Event object we're attaching data to
271
+	 * @param  array    $data  The request data from the form
272
+	 * @throws ReflectionException
273
+	 * @throws Exception
274
+	 * @throws InvalidInterfaceException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws EE_Error
277
+	 * @throws InvalidArgumentException
278
+	 */
279
+	public function datetime_and_tickets_caf_update($event, $data)
280
+	{
281
+		// first we need to start with datetimes cause they are the "root" items attached to events.
282
+		$saved_datetimes = $this->_update_datetimes($event, $data);
283
+		// next tackle the tickets (and prices?)
284
+		$this->_update_tickets($event, $saved_datetimes, $data);
285
+	}
286 286
 
287 287
 
288
-    /**
289
-     * update event_datetimes
290
-     *
291
-     * @param  EE_Event $event Event being updated
292
-     * @param  array    $data  the request data from the form
293
-     * @return EE_Datetime[]
294
-     * @throws Exception
295
-     * @throws ReflectionException
296
-     * @throws InvalidInterfaceException
297
-     * @throws InvalidDataTypeException
298
-     * @throws InvalidArgumentException
299
-     * @throws EE_Error
300
-     */
301
-    protected function _update_datetimes($event, $data)
302
-    {
303
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
304
-        $saved_dtt_ids = array();
305
-        $saved_dtt_objs = array();
306
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
307
-            throw new InvalidArgumentException(
308
-                esc_html__(
309
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
310
-                    'event_espresso'
311
-                )
312
-            );
313
-        }
314
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
315
-            // trim all values to ensure any excess whitespace is removed.
316
-            $datetime_data = array_map(
317
-                function ($datetime_data) {
318
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
319
-                },
320
-                $datetime_data
321
-            );
322
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
323
-                                            && ! empty($datetime_data['DTT_EVT_end'])
324
-                ? $datetime_data['DTT_EVT_end']
325
-                : $datetime_data['DTT_EVT_start'];
326
-            $datetime_values = array(
327
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
328
-                    ? $datetime_data['DTT_ID']
329
-                    : null,
330
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
331
-                    ? $datetime_data['DTT_name']
332
-                    : '',
333
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
334
-                    ? $datetime_data['DTT_description']
335
-                    : '',
336
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
337
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
338
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
339
-                    ? EE_INF
340
-                    : $datetime_data['DTT_reg_limit'],
341
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
342
-                    ? $row
343
-                    : $datetime_data['DTT_order'],
344
-            );
345
-            // if we have an id then let's get existing object first and then set the new values.
346
-            // Otherwise we instantiate a new object for save.
347
-            if (! empty($datetime_data['DTT_ID'])) {
348
-                $datetime = EE_Registry::instance()
349
-                                       ->load_model('Datetime', array($timezone))
350
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
351
-                // set date and time format according to what is set in this class.
352
-                $datetime->set_date_format($this->_date_format_strings['date']);
353
-                $datetime->set_time_format($this->_date_format_strings['time']);
354
-                foreach ($datetime_values as $field => $value) {
355
-                    $datetime->set($field, $value);
356
-                }
357
-                // make sure the $dtt_id here is saved just in case
358
-                // after the add_relation_to() the autosave replaces it.
359
-                // We need to do this so we dont' TRASH the parent DTT.
360
-                // (save the ID for both key and value to avoid duplications)
361
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
362
-            } else {
363
-                $datetime = EE_Registry::instance()->load_class(
364
-                    'Datetime',
365
-                    array(
366
-                        $datetime_values,
367
-                        $timezone,
368
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
369
-                    ),
370
-                    false,
371
-                    false
372
-                );
373
-                foreach ($datetime_values as $field => $value) {
374
-                    $datetime->set($field, $value);
375
-                }
376
-            }
377
-            $datetime->save();
378
-            do_action(
379
-                'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
380
-                $datetime,
381
-                $row,
382
-                $datetime_data,
383
-                $data
384
-            );
385
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
386
-            // before going any further make sure our dates are setup correctly
387
-            // so that the end date is always equal or greater than the start date.
388
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
389
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
390
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
391
-                $datetime->save();
392
-            }
393
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
394
-            // because it is possible there was a new one created for the autosave.
395
-            // (save the ID for both key and value to avoid duplications)
396
-            $DTT_ID = $datetime->ID();
397
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
398
-            $saved_dtt_objs[ $row ] = $datetime;
399
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
400
-        }
401
-        $event->save();
402
-        // now we need to REMOVE any datetimes that got deleted.
403
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
404
-        // So its safe to permanently delete at this point.
405
-        $old_datetimes = explode(',', $data['datetime_IDs']);
406
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
407
-        if (is_array($old_datetimes)) {
408
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
409
-            foreach ($datetimes_to_delete as $id) {
410
-                $id = absint($id);
411
-                if (empty($id)) {
412
-                    continue;
413
-                }
414
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
415
-                // remove tkt relationships.
416
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
417
-                foreach ($related_tickets as $tkt) {
418
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
419
-                }
420
-                $event->_remove_relation_to($id, 'Datetime');
421
-                $dtt_to_remove->refresh_cache_of_related_objects();
422
-            }
423
-        }
424
-        return $saved_dtt_objs;
425
-    }
288
+	/**
289
+	 * update event_datetimes
290
+	 *
291
+	 * @param  EE_Event $event Event being updated
292
+	 * @param  array    $data  the request data from the form
293
+	 * @return EE_Datetime[]
294
+	 * @throws Exception
295
+	 * @throws ReflectionException
296
+	 * @throws InvalidInterfaceException
297
+	 * @throws InvalidDataTypeException
298
+	 * @throws InvalidArgumentException
299
+	 * @throws EE_Error
300
+	 */
301
+	protected function _update_datetimes($event, $data)
302
+	{
303
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
304
+		$saved_dtt_ids = array();
305
+		$saved_dtt_objs = array();
306
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
307
+			throw new InvalidArgumentException(
308
+				esc_html__(
309
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
310
+					'event_espresso'
311
+				)
312
+			);
313
+		}
314
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
315
+			// trim all values to ensure any excess whitespace is removed.
316
+			$datetime_data = array_map(
317
+				function ($datetime_data) {
318
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
319
+				},
320
+				$datetime_data
321
+			);
322
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
323
+											&& ! empty($datetime_data['DTT_EVT_end'])
324
+				? $datetime_data['DTT_EVT_end']
325
+				: $datetime_data['DTT_EVT_start'];
326
+			$datetime_values = array(
327
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
328
+					? $datetime_data['DTT_ID']
329
+					: null,
330
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
331
+					? $datetime_data['DTT_name']
332
+					: '',
333
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
334
+					? $datetime_data['DTT_description']
335
+					: '',
336
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
337
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
338
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
339
+					? EE_INF
340
+					: $datetime_data['DTT_reg_limit'],
341
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
342
+					? $row
343
+					: $datetime_data['DTT_order'],
344
+			);
345
+			// if we have an id then let's get existing object first and then set the new values.
346
+			// Otherwise we instantiate a new object for save.
347
+			if (! empty($datetime_data['DTT_ID'])) {
348
+				$datetime = EE_Registry::instance()
349
+									   ->load_model('Datetime', array($timezone))
350
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
351
+				// set date and time format according to what is set in this class.
352
+				$datetime->set_date_format($this->_date_format_strings['date']);
353
+				$datetime->set_time_format($this->_date_format_strings['time']);
354
+				foreach ($datetime_values as $field => $value) {
355
+					$datetime->set($field, $value);
356
+				}
357
+				// make sure the $dtt_id here is saved just in case
358
+				// after the add_relation_to() the autosave replaces it.
359
+				// We need to do this so we dont' TRASH the parent DTT.
360
+				// (save the ID for both key and value to avoid duplications)
361
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
362
+			} else {
363
+				$datetime = EE_Registry::instance()->load_class(
364
+					'Datetime',
365
+					array(
366
+						$datetime_values,
367
+						$timezone,
368
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
369
+					),
370
+					false,
371
+					false
372
+				);
373
+				foreach ($datetime_values as $field => $value) {
374
+					$datetime->set($field, $value);
375
+				}
376
+			}
377
+			$datetime->save();
378
+			do_action(
379
+				'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
380
+				$datetime,
381
+				$row,
382
+				$datetime_data,
383
+				$data
384
+			);
385
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
386
+			// before going any further make sure our dates are setup correctly
387
+			// so that the end date is always equal or greater than the start date.
388
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
389
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
390
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
391
+				$datetime->save();
392
+			}
393
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
394
+			// because it is possible there was a new one created for the autosave.
395
+			// (save the ID for both key and value to avoid duplications)
396
+			$DTT_ID = $datetime->ID();
397
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
398
+			$saved_dtt_objs[ $row ] = $datetime;
399
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
400
+		}
401
+		$event->save();
402
+		// now we need to REMOVE any datetimes that got deleted.
403
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
404
+		// So its safe to permanently delete at this point.
405
+		$old_datetimes = explode(',', $data['datetime_IDs']);
406
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
407
+		if (is_array($old_datetimes)) {
408
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
409
+			foreach ($datetimes_to_delete as $id) {
410
+				$id = absint($id);
411
+				if (empty($id)) {
412
+					continue;
413
+				}
414
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
415
+				// remove tkt relationships.
416
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
417
+				foreach ($related_tickets as $tkt) {
418
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
419
+				}
420
+				$event->_remove_relation_to($id, 'Datetime');
421
+				$dtt_to_remove->refresh_cache_of_related_objects();
422
+			}
423
+		}
424
+		return $saved_dtt_objs;
425
+	}
426 426
 
427 427
 
428
-    /**
429
-     * update tickets
430
-     *
431
-     * @param  EE_Event      $event           Event object being updated
432
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
433
-     * @param  array         $data            incoming request data
434
-     * @return EE_Ticket[]
435
-     * @throws Exception
436
-     * @throws ReflectionException
437
-     * @throws InvalidInterfaceException
438
-     * @throws InvalidDataTypeException
439
-     * @throws InvalidArgumentException
440
-     * @throws EE_Error
441
-     */
442
-    protected function _update_tickets($event, $saved_datetimes, $data)
443
-    {
444
-        $new_tkt = null;
445
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
446
-        $data = stripslashes_deep($data);
447
-        $timezone = $data['timezone_string'] ?? null;
448
-        $saved_tickets = array();
449
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
450
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
451
-            throw new InvalidArgumentException(
452
-                esc_html__(
453
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
454
-                    'event_espresso'
455
-                )
456
-            );
457
-        }
458
-        foreach ($data['edit_tickets'] as $row => $tkt) {
459
-            $update_prices = $create_new_TKT = false;
460
-            // figure out what datetimes were added to the ticket
461
-            // and what datetimes were removed from the ticket in the session.
462
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
463
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
464
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
465
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
466
-            // trim inputs to ensure any excess whitespace is removed.
467
-            $tkt = array_map(
468
-                function ($ticket_data) {
469
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
470
-                },
471
-                $tkt
472
-            );
473
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
474
-            // because we're doing calculations prior to using the models.
475
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
476
-            $ticket_price = isset($tkt['TKT_price'])
477
-                ? round((float) $tkt['TKT_price'], 3)
478
-                : 0;
479
-            // note incoming base price needs converted from localized value.
480
-            $base_price = isset($tkt['TKT_base_price'])
481
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
482
-                : 0;
483
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
484
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
485
-                ? $base_price
486
-                : $ticket_price;
487
-            $base_price_id = $tkt['TKT_base_price_ID'] ?? 0;
488
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
489
-                ? $data['edit_prices'][ $row ]
490
-                : array();
491
-            $now = null;
492
-            if (empty($tkt['TKT_start_date'])) {
493
-                // lets' use now in the set timezone.
494
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
495
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
496
-            }
497
-            if (empty($tkt['TKT_end_date'])) {
498
-                /**
499
-                 * set the TKT_end_date to the first datetime attached to the ticket.
500
-                 */
501
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
502
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
503
-            }
504
-            $TKT_values = array(
505
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
506
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
507
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
508
-                'TKT_description' => ! empty($tkt['TKT_description'])
509
-                                     && $tkt['TKT_description'] !== esc_html__(
510
-                                         'You can modify this description',
511
-                                         'event_espresso'
512
-                                     )
513
-                    ? $tkt['TKT_description']
514
-                    : '',
515
-                'TKT_start_date'  => $tkt['TKT_start_date'],
516
-                'TKT_end_date'    => $tkt['TKT_end_date'],
517
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
518
-                    ? EE_INF
519
-                    : $tkt['TKT_qty'],
520
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
521
-                    ? EE_INF
522
-                    : $tkt['TKT_uses'],
523
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
524
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
525
-                'TKT_row'         => $row,
526
-                'TKT_order'       => $tkt['TKT_order'] ?? 0,
527
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
528
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
529
-                'TKT_price'       => $ticket_price,
530
-            );
531
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
532
-            // which means in turn that the prices will become new prices as well.
533
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
534
-                $TKT_values['TKT_ID'] = 0;
535
-                $TKT_values['TKT_is_default'] = 0;
536
-                $update_prices = true;
537
-            }
538
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
539
-            // we actually do our saves ahead of doing any add_relations to
540
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
541
-            // but DID have it's items modified.
542
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
543
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
544
-            if (absint($TKT_values['TKT_ID'])) {
545
-                $ticket = EE_Registry::instance()
546
-                                     ->load_model('Ticket', array($timezone))
547
-                                     ->get_one_by_ID($tkt['TKT_ID']);
548
-                if ($ticket instanceof EE_Ticket) {
549
-                    $ticket = $this->_update_ticket_datetimes(
550
-                        $ticket,
551
-                        $saved_datetimes,
552
-                        $datetimes_added,
553
-                        $datetimes_removed
554
-                    );
555
-                    // are there any registrations using this ticket ?
556
-                    $tickets_sold = $ticket->count_related(
557
-                        'Registration',
558
-                        array(
559
-                            array(
560
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
561
-                            ),
562
-                        )
563
-                    );
564
-                    // set ticket formats
565
-                    $ticket->set_date_format($this->_date_format_strings['date']);
566
-                    $ticket->set_time_format($this->_date_format_strings['time']);
567
-                    // let's just check the total price for the existing ticket
568
-                    // and determine if it matches the new total price.
569
-                    // if they are different then we create a new ticket (if tickets sold)
570
-                    // if they aren't different then we go ahead and modify existing ticket.
571
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
572
-                    // set new values
573
-                    foreach ($TKT_values as $field => $value) {
574
-                        if ($field === 'TKT_qty') {
575
-                            $ticket->set_qty($value);
576
-                        } else {
577
-                            $ticket->set($field, $value);
578
-                        }
579
-                    }
580
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
581
-                    // Otherwise we have to create a new ticket.
582
-                    if ($create_new_TKT) {
583
-                        $new_tkt = $this->_duplicate_ticket(
584
-                            $ticket,
585
-                            $price_rows,
586
-                            $ticket_price,
587
-                            $base_price,
588
-                            $base_price_id
589
-                        );
590
-                    }
591
-                }
592
-            } else {
593
-                // no TKT_id so a new TKT
594
-                $ticket = EE_Ticket::new_instance(
595
-                    $TKT_values,
596
-                    $timezone,
597
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
598
-                );
599
-                if ($ticket instanceof EE_Ticket) {
600
-                    // make sure ticket has an ID of setting relations won't work
601
-                    $ticket->save();
602
-                    $ticket = $this->_update_ticket_datetimes(
603
-                        $ticket,
604
-                        $saved_datetimes,
605
-                        $datetimes_added,
606
-                        $datetimes_removed
607
-                    );
608
-                    $update_prices = true;
609
-                }
610
-            }
611
-            // make sure any current values have been saved.
612
-            // $ticket->save();
613
-            // before going any further make sure our dates are setup correctly
614
-            // so that the end date is always equal or greater than the start date.
615
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
616
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
617
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
618
-            }
619
-            // let's make sure the base price is handled
620
-            $ticket = ! $create_new_TKT
621
-                ? $this->_add_prices_to_ticket(
622
-                    array(),
623
-                    $ticket,
624
-                    $update_prices,
625
-                    $base_price,
626
-                    $base_price_id
627
-                )
628
-                : $ticket;
629
-            // add/update price_modifiers
630
-            $ticket = ! $create_new_TKT
631
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
632
-                : $ticket;
633
-            // need to make sue that the TKT_price is accurate after saving the prices.
634
-            $ticket->ensure_TKT_Price_correct();
635
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
636
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
637
-                $update_prices = true;
638
-                $new_default = clone $ticket;
639
-                $new_default->set('TKT_ID', 0);
640
-                $new_default->set('TKT_is_default', 1);
641
-                $new_default->set('TKT_row', 1);
642
-                $new_default->set('TKT_price', $ticket_price);
643
-                // remove any dtt relations cause we DON'T want dtt relations attached
644
-                // (note this is just removing the cached relations in the object)
645
-                $new_default->_remove_relations('Datetime');
646
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
647
-                $new_default = $this->_add_prices_to_ticket(
648
-                    $price_rows,
649
-                    $new_default,
650
-                    $update_prices
651
-                );
652
-                // don't forget the base price!
653
-                $new_default = $this->_add_prices_to_ticket(
654
-                    array(),
655
-                    $new_default,
656
-                    $update_prices,
657
-                    $base_price,
658
-                    $base_price_id
659
-                );
660
-                $new_default->save();
661
-                do_action(
662
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
663
-                    $new_default,
664
-                    $row,
665
-                    $ticket,
666
-                    $data
667
-                );
668
-            }
669
-            // DO ALL dtt relationships for both current tickets and any archived tickets
670
-            // for the given dtt that are related to the current ticket.
671
-            // TODO... not sure exactly how we're going to do this considering we don't know
672
-            // what current ticket the archived tickets are related to
673
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
674
-            // let's assign any tickets that have been setup to the saved_tickets tracker
675
-            // save existing TKT
676
-            $ticket->save();
677
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
678
-                // save new TKT
679
-                $new_tkt->save();
680
-                // add new ticket to array
681
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
682
-                do_action(
683
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
684
-                    $new_tkt,
685
-                    $row,
686
-                    $tkt,
687
-                    $data
688
-                );
689
-            } else {
690
-                // add tkt to saved tkts
691
-                $saved_tickets[ $ticket->ID() ] = $ticket;
692
-                do_action(
693
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
694
-                    $ticket,
695
-                    $row,
696
-                    $tkt,
697
-                    $data
698
-                );
699
-            }
700
-        }
701
-        // now we need to handle tickets actually "deleted permanently".
702
-        // There are cases where we'd want this to happen
703
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
704
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
705
-        // No sense in keeping all the related data in the db!
706
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
707
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
708
-        foreach ($tickets_removed as $id) {
709
-            $id = absint($id);
710
-            // get the ticket for this id
711
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
712
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
713
-            if ($tkt_to_remove->get('TKT_is_default')) {
714
-                continue;
715
-            }
716
-            // if this tkt has any registrations attached so then we just ARCHIVE
717
-            // because we don't actually permanently delete these tickets.
718
-            if ($tkt_to_remove->count_related('Registration') > 0) {
719
-                $tkt_to_remove->delete();
720
-                continue;
721
-            }
722
-            // need to get all the related datetimes on this ticket and remove from every single one of them
723
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
724
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
725
-            foreach ($datetimes as $datetime) {
726
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
727
-            }
728
-            // need to do the same for prices (except these prices can also be deleted because again,
729
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
730
-            $tkt_to_remove->delete_related_permanently('Price');
731
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
732
-            // finally let's delete this ticket
733
-            // (which should not be blocked at this point b/c we've removed all our relationships)
734
-            $tkt_to_remove->delete_permanently();
735
-        }
736
-        return $saved_tickets;
737
-    }
428
+	/**
429
+	 * update tickets
430
+	 *
431
+	 * @param  EE_Event      $event           Event object being updated
432
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
433
+	 * @param  array         $data            incoming request data
434
+	 * @return EE_Ticket[]
435
+	 * @throws Exception
436
+	 * @throws ReflectionException
437
+	 * @throws InvalidInterfaceException
438
+	 * @throws InvalidDataTypeException
439
+	 * @throws InvalidArgumentException
440
+	 * @throws EE_Error
441
+	 */
442
+	protected function _update_tickets($event, $saved_datetimes, $data)
443
+	{
444
+		$new_tkt = null;
445
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
446
+		$data = stripslashes_deep($data);
447
+		$timezone = $data['timezone_string'] ?? null;
448
+		$saved_tickets = array();
449
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
450
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
451
+			throw new InvalidArgumentException(
452
+				esc_html__(
453
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
454
+					'event_espresso'
455
+				)
456
+			);
457
+		}
458
+		foreach ($data['edit_tickets'] as $row => $tkt) {
459
+			$update_prices = $create_new_TKT = false;
460
+			// figure out what datetimes were added to the ticket
461
+			// and what datetimes were removed from the ticket in the session.
462
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
463
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
464
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
465
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
466
+			// trim inputs to ensure any excess whitespace is removed.
467
+			$tkt = array_map(
468
+				function ($ticket_data) {
469
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
470
+				},
471
+				$tkt
472
+			);
473
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
474
+			// because we're doing calculations prior to using the models.
475
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
476
+			$ticket_price = isset($tkt['TKT_price'])
477
+				? round((float) $tkt['TKT_price'], 3)
478
+				: 0;
479
+			// note incoming base price needs converted from localized value.
480
+			$base_price = isset($tkt['TKT_base_price'])
481
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
482
+				: 0;
483
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
484
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
485
+				? $base_price
486
+				: $ticket_price;
487
+			$base_price_id = $tkt['TKT_base_price_ID'] ?? 0;
488
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
489
+				? $data['edit_prices'][ $row ]
490
+				: array();
491
+			$now = null;
492
+			if (empty($tkt['TKT_start_date'])) {
493
+				// lets' use now in the set timezone.
494
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
495
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
496
+			}
497
+			if (empty($tkt['TKT_end_date'])) {
498
+				/**
499
+				 * set the TKT_end_date to the first datetime attached to the ticket.
500
+				 */
501
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
502
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
503
+			}
504
+			$TKT_values = array(
505
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
506
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
507
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
508
+				'TKT_description' => ! empty($tkt['TKT_description'])
509
+									 && $tkt['TKT_description'] !== esc_html__(
510
+										 'You can modify this description',
511
+										 'event_espresso'
512
+									 )
513
+					? $tkt['TKT_description']
514
+					: '',
515
+				'TKT_start_date'  => $tkt['TKT_start_date'],
516
+				'TKT_end_date'    => $tkt['TKT_end_date'],
517
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
518
+					? EE_INF
519
+					: $tkt['TKT_qty'],
520
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
521
+					? EE_INF
522
+					: $tkt['TKT_uses'],
523
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
524
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
525
+				'TKT_row'         => $row,
526
+				'TKT_order'       => $tkt['TKT_order'] ?? 0,
527
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
528
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
529
+				'TKT_price'       => $ticket_price,
530
+			);
531
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
532
+			// which means in turn that the prices will become new prices as well.
533
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
534
+				$TKT_values['TKT_ID'] = 0;
535
+				$TKT_values['TKT_is_default'] = 0;
536
+				$update_prices = true;
537
+			}
538
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
539
+			// we actually do our saves ahead of doing any add_relations to
540
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
541
+			// but DID have it's items modified.
542
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
543
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
544
+			if (absint($TKT_values['TKT_ID'])) {
545
+				$ticket = EE_Registry::instance()
546
+									 ->load_model('Ticket', array($timezone))
547
+									 ->get_one_by_ID($tkt['TKT_ID']);
548
+				if ($ticket instanceof EE_Ticket) {
549
+					$ticket = $this->_update_ticket_datetimes(
550
+						$ticket,
551
+						$saved_datetimes,
552
+						$datetimes_added,
553
+						$datetimes_removed
554
+					);
555
+					// are there any registrations using this ticket ?
556
+					$tickets_sold = $ticket->count_related(
557
+						'Registration',
558
+						array(
559
+							array(
560
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
561
+							),
562
+						)
563
+					);
564
+					// set ticket formats
565
+					$ticket->set_date_format($this->_date_format_strings['date']);
566
+					$ticket->set_time_format($this->_date_format_strings['time']);
567
+					// let's just check the total price for the existing ticket
568
+					// and determine if it matches the new total price.
569
+					// if they are different then we create a new ticket (if tickets sold)
570
+					// if they aren't different then we go ahead and modify existing ticket.
571
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
572
+					// set new values
573
+					foreach ($TKT_values as $field => $value) {
574
+						if ($field === 'TKT_qty') {
575
+							$ticket->set_qty($value);
576
+						} else {
577
+							$ticket->set($field, $value);
578
+						}
579
+					}
580
+					// if $create_new_TKT is false then we can safely update the existing ticket.
581
+					// Otherwise we have to create a new ticket.
582
+					if ($create_new_TKT) {
583
+						$new_tkt = $this->_duplicate_ticket(
584
+							$ticket,
585
+							$price_rows,
586
+							$ticket_price,
587
+							$base_price,
588
+							$base_price_id
589
+						);
590
+					}
591
+				}
592
+			} else {
593
+				// no TKT_id so a new TKT
594
+				$ticket = EE_Ticket::new_instance(
595
+					$TKT_values,
596
+					$timezone,
597
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
598
+				);
599
+				if ($ticket instanceof EE_Ticket) {
600
+					// make sure ticket has an ID of setting relations won't work
601
+					$ticket->save();
602
+					$ticket = $this->_update_ticket_datetimes(
603
+						$ticket,
604
+						$saved_datetimes,
605
+						$datetimes_added,
606
+						$datetimes_removed
607
+					);
608
+					$update_prices = true;
609
+				}
610
+			}
611
+			// make sure any current values have been saved.
612
+			// $ticket->save();
613
+			// before going any further make sure our dates are setup correctly
614
+			// so that the end date is always equal or greater than the start date.
615
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
616
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
617
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
618
+			}
619
+			// let's make sure the base price is handled
620
+			$ticket = ! $create_new_TKT
621
+				? $this->_add_prices_to_ticket(
622
+					array(),
623
+					$ticket,
624
+					$update_prices,
625
+					$base_price,
626
+					$base_price_id
627
+				)
628
+				: $ticket;
629
+			// add/update price_modifiers
630
+			$ticket = ! $create_new_TKT
631
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
632
+				: $ticket;
633
+			// need to make sue that the TKT_price is accurate after saving the prices.
634
+			$ticket->ensure_TKT_Price_correct();
635
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
636
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
637
+				$update_prices = true;
638
+				$new_default = clone $ticket;
639
+				$new_default->set('TKT_ID', 0);
640
+				$new_default->set('TKT_is_default', 1);
641
+				$new_default->set('TKT_row', 1);
642
+				$new_default->set('TKT_price', $ticket_price);
643
+				// remove any dtt relations cause we DON'T want dtt relations attached
644
+				// (note this is just removing the cached relations in the object)
645
+				$new_default->_remove_relations('Datetime');
646
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
647
+				$new_default = $this->_add_prices_to_ticket(
648
+					$price_rows,
649
+					$new_default,
650
+					$update_prices
651
+				);
652
+				// don't forget the base price!
653
+				$new_default = $this->_add_prices_to_ticket(
654
+					array(),
655
+					$new_default,
656
+					$update_prices,
657
+					$base_price,
658
+					$base_price_id
659
+				);
660
+				$new_default->save();
661
+				do_action(
662
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
663
+					$new_default,
664
+					$row,
665
+					$ticket,
666
+					$data
667
+				);
668
+			}
669
+			// DO ALL dtt relationships for both current tickets and any archived tickets
670
+			// for the given dtt that are related to the current ticket.
671
+			// TODO... not sure exactly how we're going to do this considering we don't know
672
+			// what current ticket the archived tickets are related to
673
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
674
+			// let's assign any tickets that have been setup to the saved_tickets tracker
675
+			// save existing TKT
676
+			$ticket->save();
677
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
678
+				// save new TKT
679
+				$new_tkt->save();
680
+				// add new ticket to array
681
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
682
+				do_action(
683
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
684
+					$new_tkt,
685
+					$row,
686
+					$tkt,
687
+					$data
688
+				);
689
+			} else {
690
+				// add tkt to saved tkts
691
+				$saved_tickets[ $ticket->ID() ] = $ticket;
692
+				do_action(
693
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
694
+					$ticket,
695
+					$row,
696
+					$tkt,
697
+					$data
698
+				);
699
+			}
700
+		}
701
+		// now we need to handle tickets actually "deleted permanently".
702
+		// There are cases where we'd want this to happen
703
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
704
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
705
+		// No sense in keeping all the related data in the db!
706
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
707
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
708
+		foreach ($tickets_removed as $id) {
709
+			$id = absint($id);
710
+			// get the ticket for this id
711
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
712
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
713
+			if ($tkt_to_remove->get('TKT_is_default')) {
714
+				continue;
715
+			}
716
+			// if this tkt has any registrations attached so then we just ARCHIVE
717
+			// because we don't actually permanently delete these tickets.
718
+			if ($tkt_to_remove->count_related('Registration') > 0) {
719
+				$tkt_to_remove->delete();
720
+				continue;
721
+			}
722
+			// need to get all the related datetimes on this ticket and remove from every single one of them
723
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
724
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
725
+			foreach ($datetimes as $datetime) {
726
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
727
+			}
728
+			// need to do the same for prices (except these prices can also be deleted because again,
729
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
730
+			$tkt_to_remove->delete_related_permanently('Price');
731
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
732
+			// finally let's delete this ticket
733
+			// (which should not be blocked at this point b/c we've removed all our relationships)
734
+			$tkt_to_remove->delete_permanently();
735
+		}
736
+		return $saved_tickets;
737
+	}
738 738
 
739 739
 
740
-    /**
741
-     * @access  protected
742
-     * @param EE_Ticket      $ticket
743
-     * @param \EE_Datetime[] $saved_datetimes
744
-     * @param \EE_Datetime[] $added_datetimes
745
-     * @param \EE_Datetime[] $removed_datetimes
746
-     * @return EE_Ticket
747
-     * @throws EE_Error
748
-     */
749
-    protected function _update_ticket_datetimes(
750
-        EE_Ticket $ticket,
751
-        $saved_datetimes = array(),
752
-        $added_datetimes = array(),
753
-        $removed_datetimes = array()
754
-    ) {
755
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
756
-        // and removing the ticket from datetimes it got removed from.
757
-        // first let's add datetimes
758
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
759
-            foreach ($added_datetimes as $row_id) {
760
-                $row_id = (int) $row_id;
761
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
762
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
763
-                    // Is this an existing ticket (has an ID) and does it have any sold?
764
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
765
-                    if ($ticket->ID() && $ticket->sold() > 0) {
766
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
767
-                    }
768
-                }
769
-            }
770
-        }
771
-        // then remove datetimes
772
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
773
-            foreach ($removed_datetimes as $row_id) {
774
-                $row_id = (int) $row_id;
775
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
776
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
777
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
778
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
779
-                    // Is this an existing ticket (has an ID) and does it have any sold?
780
-                    // If so, then we need to remove it's sold from the DTT_sold.
781
-                    if ($ticket->ID() && $ticket->sold() > 0) {
782
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
783
-                    }
784
-                }
785
-            }
786
-        }
787
-        // cap ticket qty by datetime reg limits
788
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
789
-        return $ticket;
790
-    }
740
+	/**
741
+	 * @access  protected
742
+	 * @param EE_Ticket      $ticket
743
+	 * @param \EE_Datetime[] $saved_datetimes
744
+	 * @param \EE_Datetime[] $added_datetimes
745
+	 * @param \EE_Datetime[] $removed_datetimes
746
+	 * @return EE_Ticket
747
+	 * @throws EE_Error
748
+	 */
749
+	protected function _update_ticket_datetimes(
750
+		EE_Ticket $ticket,
751
+		$saved_datetimes = array(),
752
+		$added_datetimes = array(),
753
+		$removed_datetimes = array()
754
+	) {
755
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
756
+		// and removing the ticket from datetimes it got removed from.
757
+		// first let's add datetimes
758
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
759
+			foreach ($added_datetimes as $row_id) {
760
+				$row_id = (int) $row_id;
761
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
762
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
763
+					// Is this an existing ticket (has an ID) and does it have any sold?
764
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
765
+					if ($ticket->ID() && $ticket->sold() > 0) {
766
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
767
+					}
768
+				}
769
+			}
770
+		}
771
+		// then remove datetimes
772
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
773
+			foreach ($removed_datetimes as $row_id) {
774
+				$row_id = (int) $row_id;
775
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
776
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
777
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
778
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
779
+					// Is this an existing ticket (has an ID) and does it have any sold?
780
+					// If so, then we need to remove it's sold from the DTT_sold.
781
+					if ($ticket->ID() && $ticket->sold() > 0) {
782
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
783
+					}
784
+				}
785
+			}
786
+		}
787
+		// cap ticket qty by datetime reg limits
788
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
789
+		return $ticket;
790
+	}
791 791
 
792 792
 
793
-    /**
794
-     * @access  protected
795
-     * @param EE_Ticket $ticket
796
-     * @param array     $price_rows
797
-     * @param int       $ticket_price
798
-     * @param int       $base_price
799
-     * @param int       $base_price_id
800
-     * @return EE_Ticket
801
-     * @throws ReflectionException
802
-     * @throws InvalidArgumentException
803
-     * @throws InvalidInterfaceException
804
-     * @throws InvalidDataTypeException
805
-     * @throws EE_Error
806
-     */
807
-    protected function _duplicate_ticket(
808
-        EE_Ticket $ticket,
809
-        $price_rows = array(),
810
-        $ticket_price = 0,
811
-        $base_price = 0,
812
-        $base_price_id = 0
813
-    ) {
814
-        // create new ticket that's a copy of the existing
815
-        // except a new id of course (and not archived)
816
-        // AND has the new TKT_price associated with it.
817
-        $new_ticket = clone $ticket;
818
-        $new_ticket->set('TKT_ID', 0);
819
-        $new_ticket->set_deleted(0);
820
-        $new_ticket->set_price($ticket_price);
821
-        $new_ticket->set_sold(0);
822
-        // let's get a new ID for this ticket
823
-        $new_ticket->save();
824
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
825
-        $datetimes_on_existing = $ticket->datetimes();
826
-        $new_ticket = $this->_update_ticket_datetimes(
827
-            $new_ticket,
828
-            $datetimes_on_existing,
829
-            array_keys($datetimes_on_existing)
830
-        );
831
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
832
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
833
-        // available.
834
-        if ($ticket->sold() > 0) {
835
-            $new_qty = $ticket->qty() - $ticket->sold();
836
-            $new_ticket->set_qty($new_qty);
837
-        }
838
-        // now we update the prices just for this ticket
839
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
840
-        // and we update the base price
841
-        $new_ticket = $this->_add_prices_to_ticket(
842
-            array(),
843
-            $new_ticket,
844
-            true,
845
-            $base_price,
846
-            $base_price_id
847
-        );
848
-        return $new_ticket;
849
-    }
793
+	/**
794
+	 * @access  protected
795
+	 * @param EE_Ticket $ticket
796
+	 * @param array     $price_rows
797
+	 * @param int       $ticket_price
798
+	 * @param int       $base_price
799
+	 * @param int       $base_price_id
800
+	 * @return EE_Ticket
801
+	 * @throws ReflectionException
802
+	 * @throws InvalidArgumentException
803
+	 * @throws InvalidInterfaceException
804
+	 * @throws InvalidDataTypeException
805
+	 * @throws EE_Error
806
+	 */
807
+	protected function _duplicate_ticket(
808
+		EE_Ticket $ticket,
809
+		$price_rows = array(),
810
+		$ticket_price = 0,
811
+		$base_price = 0,
812
+		$base_price_id = 0
813
+	) {
814
+		// create new ticket that's a copy of the existing
815
+		// except a new id of course (and not archived)
816
+		// AND has the new TKT_price associated with it.
817
+		$new_ticket = clone $ticket;
818
+		$new_ticket->set('TKT_ID', 0);
819
+		$new_ticket->set_deleted(0);
820
+		$new_ticket->set_price($ticket_price);
821
+		$new_ticket->set_sold(0);
822
+		// let's get a new ID for this ticket
823
+		$new_ticket->save();
824
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
825
+		$datetimes_on_existing = $ticket->datetimes();
826
+		$new_ticket = $this->_update_ticket_datetimes(
827
+			$new_ticket,
828
+			$datetimes_on_existing,
829
+			array_keys($datetimes_on_existing)
830
+		);
831
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
832
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
833
+		// available.
834
+		if ($ticket->sold() > 0) {
835
+			$new_qty = $ticket->qty() - $ticket->sold();
836
+			$new_ticket->set_qty($new_qty);
837
+		}
838
+		// now we update the prices just for this ticket
839
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
840
+		// and we update the base price
841
+		$new_ticket = $this->_add_prices_to_ticket(
842
+			array(),
843
+			$new_ticket,
844
+			true,
845
+			$base_price,
846
+			$base_price_id
847
+		);
848
+		return $new_ticket;
849
+	}
850 850
 
851 851
 
852
-    /**
853
-     * This attaches a list of given prices to a ticket.
854
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
855
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
856
-     * price info and prices are automatically "archived" via the ticket.
857
-     *
858
-     * @access  private
859
-     * @param array     $prices        Array of prices from the form.
860
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
861
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
862
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
863
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
864
-     * @return EE_Ticket
865
-     * @throws ReflectionException
866
-     * @throws InvalidArgumentException
867
-     * @throws InvalidInterfaceException
868
-     * @throws InvalidDataTypeException
869
-     * @throws EE_Error
870
-     */
871
-    protected function _add_prices_to_ticket(
872
-        array $prices,
873
-        EE_Ticket $ticket,
874
-        $new_prices = false,
875
-        $base_price = false,
876
-        $base_price_id = false
877
-    ) {
878
-        // let's just get any current prices that may exist on the given ticket
879
-        // so we can remove any prices that got trashed in this session.
880
-        $current_prices_on_ticket = $base_price !== false
881
-            ? $ticket->base_price(true)
882
-            : $ticket->price_modifiers();
883
-        $updated_prices = array();
884
-        // if $base_price ! FALSE then updating a base price.
885
-        if ($base_price !== false) {
886
-            $prices[1] = array(
887
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
888
-                'PRT_ID'     => 1,
889
-                'PRC_amount' => $base_price,
890
-                'PRC_name'   => $ticket->get('TKT_name'),
891
-                'PRC_desc'   => $ticket->get('TKT_description'),
892
-            );
893
-        }
894
-        // possibly need to save tkt
895
-        if (! $ticket->ID()) {
896
-            $ticket->save();
897
-        }
898
-        foreach ($prices as $row => $prc) {
899
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
900
-            if (empty($prt_id)) {
901
-                continue;
902
-            } //prices MUST have a price type id.
903
-            $PRC_values = array(
904
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
905
-                'PRT_ID'         => $prt_id,
906
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
907
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
908
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
909
-                'PRC_is_default' => false,
910
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
911
-                'PRC_order'      => $row,
912
-            );
913
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
914
-                $PRC_values['PRC_ID'] = 0;
915
-                $price = EE_Registry::instance()->load_class(
916
-                    'Price',
917
-                    array($PRC_values),
918
-                    false,
919
-                    false
920
-                );
921
-            } else {
922
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
923
-                // update this price with new values
924
-                foreach ($PRC_values as $field => $value) {
925
-                    $price->set($field, $value);
926
-                }
927
-            }
928
-            $price->save();
929
-            $updated_prices[ $price->ID() ] = $price;
930
-            $ticket->_add_relation_to($price, 'Price');
931
-        }
932
-        // now let's remove any prices that got removed from the ticket
933
-        if (! empty($current_prices_on_ticket)) {
934
-            $current = array_keys($current_prices_on_ticket);
935
-            $updated = array_keys($updated_prices);
936
-            $prices_to_remove = array_diff($current, $updated);
937
-            if (! empty($prices_to_remove)) {
938
-                foreach ($prices_to_remove as $prc_id) {
939
-                    $p = $current_prices_on_ticket[ $prc_id ];
940
-                    $ticket->_remove_relation_to($p, 'Price');
941
-                    // delete permanently the price
942
-                    $p->delete_permanently();
943
-                }
944
-            }
945
-        }
946
-        return $ticket;
947
-    }
852
+	/**
853
+	 * This attaches a list of given prices to a ticket.
854
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
855
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
856
+	 * price info and prices are automatically "archived" via the ticket.
857
+	 *
858
+	 * @access  private
859
+	 * @param array     $prices        Array of prices from the form.
860
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
861
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
862
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
863
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
864
+	 * @return EE_Ticket
865
+	 * @throws ReflectionException
866
+	 * @throws InvalidArgumentException
867
+	 * @throws InvalidInterfaceException
868
+	 * @throws InvalidDataTypeException
869
+	 * @throws EE_Error
870
+	 */
871
+	protected function _add_prices_to_ticket(
872
+		array $prices,
873
+		EE_Ticket $ticket,
874
+		$new_prices = false,
875
+		$base_price = false,
876
+		$base_price_id = false
877
+	) {
878
+		// let's just get any current prices that may exist on the given ticket
879
+		// so we can remove any prices that got trashed in this session.
880
+		$current_prices_on_ticket = $base_price !== false
881
+			? $ticket->base_price(true)
882
+			: $ticket->price_modifiers();
883
+		$updated_prices = array();
884
+		// if $base_price ! FALSE then updating a base price.
885
+		if ($base_price !== false) {
886
+			$prices[1] = array(
887
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
888
+				'PRT_ID'     => 1,
889
+				'PRC_amount' => $base_price,
890
+				'PRC_name'   => $ticket->get('TKT_name'),
891
+				'PRC_desc'   => $ticket->get('TKT_description'),
892
+			);
893
+		}
894
+		// possibly need to save tkt
895
+		if (! $ticket->ID()) {
896
+			$ticket->save();
897
+		}
898
+		foreach ($prices as $row => $prc) {
899
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
900
+			if (empty($prt_id)) {
901
+				continue;
902
+			} //prices MUST have a price type id.
903
+			$PRC_values = array(
904
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
905
+				'PRT_ID'         => $prt_id,
906
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
907
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
908
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
909
+				'PRC_is_default' => false,
910
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
911
+				'PRC_order'      => $row,
912
+			);
913
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
914
+				$PRC_values['PRC_ID'] = 0;
915
+				$price = EE_Registry::instance()->load_class(
916
+					'Price',
917
+					array($PRC_values),
918
+					false,
919
+					false
920
+				);
921
+			} else {
922
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
923
+				// update this price with new values
924
+				foreach ($PRC_values as $field => $value) {
925
+					$price->set($field, $value);
926
+				}
927
+			}
928
+			$price->save();
929
+			$updated_prices[ $price->ID() ] = $price;
930
+			$ticket->_add_relation_to($price, 'Price');
931
+		}
932
+		// now let's remove any prices that got removed from the ticket
933
+		if (! empty($current_prices_on_ticket)) {
934
+			$current = array_keys($current_prices_on_ticket);
935
+			$updated = array_keys($updated_prices);
936
+			$prices_to_remove = array_diff($current, $updated);
937
+			if (! empty($prices_to_remove)) {
938
+				foreach ($prices_to_remove as $prc_id) {
939
+					$p = $current_prices_on_ticket[ $prc_id ];
940
+					$ticket->_remove_relation_to($p, 'Price');
941
+					// delete permanently the price
942
+					$p->delete_permanently();
943
+				}
944
+			}
945
+		}
946
+		return $ticket;
947
+	}
948 948
 
949 949
 
950
-    /**
951
-     * @param Events_Admin_Page $event_admin_obj
952
-     * @return Events_Admin_Page
953
-     */
954
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
955
-    {
956
-        return $event_admin_obj;
957
-        // doing nothing for the moment.
958
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
959
-        // (use the set_template_args() method)
960
-        /**
961
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
962
-         * 1. TKT_is_default_selector (visible)
963
-         * 2. TKT_is_default (hidden)
964
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
965
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
966
-         * this ticket to be saved as a default.
967
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
968
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
969
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
970
-         * the TKT HAS been saved as a default..
971
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
972
-         * On Autosave:
973
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
974
-         * then set the TKT_is_default to false.
975
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
976
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
977
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
978
-         */
979
-    }
950
+	/**
951
+	 * @param Events_Admin_Page $event_admin_obj
952
+	 * @return Events_Admin_Page
953
+	 */
954
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
955
+	{
956
+		return $event_admin_obj;
957
+		// doing nothing for the moment.
958
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
959
+		// (use the set_template_args() method)
960
+		/**
961
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
962
+		 * 1. TKT_is_default_selector (visible)
963
+		 * 2. TKT_is_default (hidden)
964
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
965
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
966
+		 * this ticket to be saved as a default.
967
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
968
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
969
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
970
+		 * the TKT HAS been saved as a default..
971
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
972
+		 * On Autosave:
973
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
974
+		 * then set the TKT_is_default to false.
975
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
976
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
977
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
978
+		 */
979
+	}
980 980
 
981 981
 
982
-    /**
983
-     * @throws ReflectionException
984
-     * @throws InvalidArgumentException
985
-     * @throws InvalidInterfaceException
986
-     * @throws InvalidDataTypeException
987
-     * @throws DomainException
988
-     * @throws EE_Error
989
-     */
990
-    public function pricing_metabox()
991
-    {
992
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
993
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
994
-        // set is_creating_event property.
995
-        $EVT_ID = $event->ID();
996
-        $this->_is_creating_event = empty($this->_req_data['post']);
997
-        // default main template args
998
-        $main_template_args = array(
999
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1000
-                'event_editor_event_datetimes_help_tab',
1001
-                $this->_adminpage_obj->page_slug,
1002
-                $this->_adminpage_obj->get_req_action(),
1003
-                false,
1004
-                false
1005
-            ),
1006
-            // todo need to add a filter to the template for the help text
1007
-            // in the Events_Admin_Page core file so we can add further help
1008
-            'existing_datetime_ids'    => '',
1009
-            'total_dtt_rows'           => 1,
1010
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1011
-                'add_new_dtt_info',
1012
-                $this->_adminpage_obj->page_slug,
1013
-                $this->_adminpage_obj->get_req_action(),
1014
-                false,
1015
-                false
1016
-            ),
1017
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1018
-            'datetime_rows'            => '',
1019
-            'show_tickets_container'   => '',
1020
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1021
-            'ticket_rows'              => '',
1022
-            'existing_ticket_ids'      => '',
1023
-            'total_ticket_rows'        => 1,
1024
-            'ticket_js_structure'      => '',
1025
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1026
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1027
-        );
1028
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1029
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1030
-        /**
1031
-         * 1. Start with retrieving Datetimes
1032
-         * 2. For each datetime get related tickets
1033
-         * 3. For each ticket get related prices
1034
-         */
1035
-        /** @var EEM_Datetime $datetime_model */
1036
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1037
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1038
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1039
-        /**
1040
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1041
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1042
-         */
1043
-        $datetime_row = 1;
1044
-        foreach ($datetimes as $datetime) {
1045
-            $DTT_ID = $datetime->get('DTT_ID');
1046
-            $datetime->set('DTT_order', $datetime_row);
1047
-            $existing_datetime_ids[] = $DTT_ID;
1048
-            // tickets attached
1049
-            $related_tickets = $datetime->ID() > 0
1050
-                ? $datetime->get_many_related(
1051
-                    'Ticket',
1052
-                    array(
1053
-                        array(
1054
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1055
-                        ),
1056
-                        'default_where_conditions' => 'none',
1057
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1058
-                    )
1059
-                )
1060
-                : array();
1061
-            // if there are no related tickets this is likely a new event OR autodraft
1062
-            // event so we need to generate the default tickets because datetimes
1063
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1064
-            // datetime on the event.
1065
-            if (empty($related_tickets) && count($datetimes) < 2) {
1066
-                /** @var EEM_Ticket $ticket_model */
1067
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1068
-                $related_tickets = $ticket_model->get_all_default_tickets();
1069
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1070
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1071
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1072
-                $main_default_ticket = reset($related_tickets);
1073
-                if ($main_default_ticket instanceof EE_Ticket) {
1074
-                    foreach ($default_prices as $default_price) {
1075
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1076
-                            continue;
1077
-                        }
1078
-                        $main_default_ticket->cache('Price', $default_price);
1079
-                    }
1080
-                }
1081
-            }
1082
-            // we can't actually setup rows in this loop yet cause we don't know all
1083
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1084
-            // So we're going to temporarily cache some of that information.
1085
-            // loop through and setup the ticket rows and make sure the order is set.
1086
-            foreach ($related_tickets as $ticket) {
1087
-                $TKT_ID = $ticket->get('TKT_ID');
1088
-                $ticket_row = $ticket->get('TKT_row');
1089
-                // we only want unique tickets in our final display!!
1090
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1091
-                    $existing_ticket_ids[] = $TKT_ID;
1092
-                    $all_tickets[] = $ticket;
1093
-                }
1094
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1095
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1096
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1097
-                if (
1098
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1099
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1100
-                ) {
1101
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1102
-                }
1103
-            }
1104
-            $datetime_row++;
1105
-        }
1106
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1107
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1108
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1109
-        // sort $all_tickets by order
1110
-        usort(
1111
-            $all_tickets,
1112
-            function (EE_Ticket $a, EE_Ticket $b) {
1113
-                $a_order = (int) $a->get('TKT_order');
1114
-                $b_order = (int) $b->get('TKT_order');
1115
-                if ($a_order === $b_order) {
1116
-                    return 0;
1117
-                }
1118
-                return ($a_order < $b_order) ? -1 : 1;
1119
-            }
1120
-        );
1121
-        // k NOW we have all the data we need for setting up the dtt rows
1122
-        // and ticket rows so we start our dtt loop again.
1123
-        $datetime_row = 1;
1124
-        foreach ($datetimes as $datetime) {
1125
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1126
-                $datetime_row,
1127
-                $datetime,
1128
-                $datetime_tickets,
1129
-                $all_tickets,
1130
-                false,
1131
-                $datetimes
1132
-            );
1133
-            $datetime_row++;
1134
-        }
1135
-        // then loop through all tickets for the ticket rows.
1136
-        $ticket_row = 1;
1137
-        foreach ($all_tickets as $ticket) {
1138
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1139
-                $ticket_row,
1140
-                $ticket,
1141
-                $ticket_datetimes,
1142
-                $datetimes,
1143
-                false,
1144
-                $all_tickets
1145
-            );
1146
-            $ticket_row++;
1147
-        }
1148
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1149
-        EEH_Template::display_template(
1150
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1151
-            $main_template_args
1152
-        );
1153
-    }
982
+	/**
983
+	 * @throws ReflectionException
984
+	 * @throws InvalidArgumentException
985
+	 * @throws InvalidInterfaceException
986
+	 * @throws InvalidDataTypeException
987
+	 * @throws DomainException
988
+	 * @throws EE_Error
989
+	 */
990
+	public function pricing_metabox()
991
+	{
992
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
993
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
994
+		// set is_creating_event property.
995
+		$EVT_ID = $event->ID();
996
+		$this->_is_creating_event = empty($this->_req_data['post']);
997
+		// default main template args
998
+		$main_template_args = array(
999
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1000
+				'event_editor_event_datetimes_help_tab',
1001
+				$this->_adminpage_obj->page_slug,
1002
+				$this->_adminpage_obj->get_req_action(),
1003
+				false,
1004
+				false
1005
+			),
1006
+			// todo need to add a filter to the template for the help text
1007
+			// in the Events_Admin_Page core file so we can add further help
1008
+			'existing_datetime_ids'    => '',
1009
+			'total_dtt_rows'           => 1,
1010
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1011
+				'add_new_dtt_info',
1012
+				$this->_adminpage_obj->page_slug,
1013
+				$this->_adminpage_obj->get_req_action(),
1014
+				false,
1015
+				false
1016
+			),
1017
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1018
+			'datetime_rows'            => '',
1019
+			'show_tickets_container'   => '',
1020
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1021
+			'ticket_rows'              => '',
1022
+			'existing_ticket_ids'      => '',
1023
+			'total_ticket_rows'        => 1,
1024
+			'ticket_js_structure'      => '',
1025
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1026
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1027
+		);
1028
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1029
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1030
+		/**
1031
+		 * 1. Start with retrieving Datetimes
1032
+		 * 2. For each datetime get related tickets
1033
+		 * 3. For each ticket get related prices
1034
+		 */
1035
+		/** @var EEM_Datetime $datetime_model */
1036
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1037
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1038
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1039
+		/**
1040
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1041
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1042
+		 */
1043
+		$datetime_row = 1;
1044
+		foreach ($datetimes as $datetime) {
1045
+			$DTT_ID = $datetime->get('DTT_ID');
1046
+			$datetime->set('DTT_order', $datetime_row);
1047
+			$existing_datetime_ids[] = $DTT_ID;
1048
+			// tickets attached
1049
+			$related_tickets = $datetime->ID() > 0
1050
+				? $datetime->get_many_related(
1051
+					'Ticket',
1052
+					array(
1053
+						array(
1054
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1055
+						),
1056
+						'default_where_conditions' => 'none',
1057
+						'order_by'                 => array('TKT_order' => 'ASC'),
1058
+					)
1059
+				)
1060
+				: array();
1061
+			// if there are no related tickets this is likely a new event OR autodraft
1062
+			// event so we need to generate the default tickets because datetimes
1063
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1064
+			// datetime on the event.
1065
+			if (empty($related_tickets) && count($datetimes) < 2) {
1066
+				/** @var EEM_Ticket $ticket_model */
1067
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1068
+				$related_tickets = $ticket_model->get_all_default_tickets();
1069
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1070
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1071
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1072
+				$main_default_ticket = reset($related_tickets);
1073
+				if ($main_default_ticket instanceof EE_Ticket) {
1074
+					foreach ($default_prices as $default_price) {
1075
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1076
+							continue;
1077
+						}
1078
+						$main_default_ticket->cache('Price', $default_price);
1079
+					}
1080
+				}
1081
+			}
1082
+			// we can't actually setup rows in this loop yet cause we don't know all
1083
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1084
+			// So we're going to temporarily cache some of that information.
1085
+			// loop through and setup the ticket rows and make sure the order is set.
1086
+			foreach ($related_tickets as $ticket) {
1087
+				$TKT_ID = $ticket->get('TKT_ID');
1088
+				$ticket_row = $ticket->get('TKT_row');
1089
+				// we only want unique tickets in our final display!!
1090
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1091
+					$existing_ticket_ids[] = $TKT_ID;
1092
+					$all_tickets[] = $ticket;
1093
+				}
1094
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1095
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1096
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1097
+				if (
1098
+					! isset($ticket_datetimes[ $TKT_ID ])
1099
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1100
+				) {
1101
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1102
+				}
1103
+			}
1104
+			$datetime_row++;
1105
+		}
1106
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1107
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1108
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1109
+		// sort $all_tickets by order
1110
+		usort(
1111
+			$all_tickets,
1112
+			function (EE_Ticket $a, EE_Ticket $b) {
1113
+				$a_order = (int) $a->get('TKT_order');
1114
+				$b_order = (int) $b->get('TKT_order');
1115
+				if ($a_order === $b_order) {
1116
+					return 0;
1117
+				}
1118
+				return ($a_order < $b_order) ? -1 : 1;
1119
+			}
1120
+		);
1121
+		// k NOW we have all the data we need for setting up the dtt rows
1122
+		// and ticket rows so we start our dtt loop again.
1123
+		$datetime_row = 1;
1124
+		foreach ($datetimes as $datetime) {
1125
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1126
+				$datetime_row,
1127
+				$datetime,
1128
+				$datetime_tickets,
1129
+				$all_tickets,
1130
+				false,
1131
+				$datetimes
1132
+			);
1133
+			$datetime_row++;
1134
+		}
1135
+		// then loop through all tickets for the ticket rows.
1136
+		$ticket_row = 1;
1137
+		foreach ($all_tickets as $ticket) {
1138
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1139
+				$ticket_row,
1140
+				$ticket,
1141
+				$ticket_datetimes,
1142
+				$datetimes,
1143
+				false,
1144
+				$all_tickets
1145
+			);
1146
+			$ticket_row++;
1147
+		}
1148
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1149
+		EEH_Template::display_template(
1150
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1151
+			$main_template_args
1152
+		);
1153
+	}
1154 1154
 
1155 1155
 
1156
-    /**
1157
-     * @param int         $datetime_row
1158
-     * @param EE_Datetime $datetime
1159
-     * @param array       $datetime_tickets
1160
-     * @param array       $all_tickets
1161
-     * @param bool        $default
1162
-     * @param array       $all_datetimes
1163
-     * @return mixed
1164
-     * @throws DomainException
1165
-     * @throws EE_Error
1166
-     */
1167
-    protected function _get_datetime_row(
1168
-        $datetime_row,
1169
-        EE_Datetime $datetime,
1170
-        $datetime_tickets = array(),
1171
-        $all_tickets = array(),
1172
-        $default = false,
1173
-        $all_datetimes = array()
1174
-    ) {
1175
-        $dtt_display_template_args = array(
1176
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1177
-                $datetime_row,
1178
-                $datetime,
1179
-                $default,
1180
-                $all_datetimes
1181
-            ),
1182
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1183
-                $datetime_row,
1184
-                $datetime,
1185
-                $datetime_tickets,
1186
-                $all_tickets,
1187
-                $default
1188
-            ),
1189
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1190
-        );
1191
-        return EEH_Template::display_template(
1192
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1193
-            $dtt_display_template_args,
1194
-            true
1195
-        );
1196
-    }
1156
+	/**
1157
+	 * @param int         $datetime_row
1158
+	 * @param EE_Datetime $datetime
1159
+	 * @param array       $datetime_tickets
1160
+	 * @param array       $all_tickets
1161
+	 * @param bool        $default
1162
+	 * @param array       $all_datetimes
1163
+	 * @return mixed
1164
+	 * @throws DomainException
1165
+	 * @throws EE_Error
1166
+	 */
1167
+	protected function _get_datetime_row(
1168
+		$datetime_row,
1169
+		EE_Datetime $datetime,
1170
+		$datetime_tickets = array(),
1171
+		$all_tickets = array(),
1172
+		$default = false,
1173
+		$all_datetimes = array()
1174
+	) {
1175
+		$dtt_display_template_args = array(
1176
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1177
+				$datetime_row,
1178
+				$datetime,
1179
+				$default,
1180
+				$all_datetimes
1181
+			),
1182
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1183
+				$datetime_row,
1184
+				$datetime,
1185
+				$datetime_tickets,
1186
+				$all_tickets,
1187
+				$default
1188
+			),
1189
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1190
+		);
1191
+		return EEH_Template::display_template(
1192
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1193
+			$dtt_display_template_args,
1194
+			true
1195
+		);
1196
+	}
1197 1197
 
1198 1198
 
1199
-    /**
1200
-     * This method is used to generate a dtt fields  edit row.
1201
-     * The same row is used to generate a row with valid DTT objects
1202
-     * and the default row that is used as the skeleton by the js.
1203
-     *
1204
-     * @param int           $datetime_row  The row number for the row being generated.
1205
-     * @param EE_Datetime   $datetime
1206
-     * @param bool          $default       Whether a default row is being generated or not.
1207
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1208
-     * @return string
1209
-     * @throws DomainException
1210
-     * @throws EE_Error
1211
-     */
1212
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1213
-    {
1214
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1215
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1216
-        $template_args = array(
1217
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1218
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1219
-            'edit_dtt_expanded'    => '',
1220
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1221
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1222
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1223
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1224
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1225
-            'DTT_reg_limit'        => $default
1226
-                ? ''
1227
-                : $datetime->get_pretty(
1228
-                    'DTT_reg_limit',
1229
-                    'input'
1230
-                ),
1231
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1232
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1233
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1234
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1235
-                ? ''
1236
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1237
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1238
-                ? 'ee-lock-icon'
1239
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1240
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1241
-                ? ''
1242
-                : EE_Admin_Page::add_query_args_and_nonce(
1243
-                    array(
1244
-                        'event_id' => $datetime->event()->ID(),
1245
-                        'datetime_id' => $datetime->ID(),
1246
-                        'use_filters' => true
1247
-                    ),
1248
-                    REG_ADMIN_URL
1249
-                ),
1250
-        );
1251
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1252
-            ? 'display:none'
1253
-            : '';
1254
-        // allow filtering of template args at this point.
1255
-        $template_args = apply_filters(
1256
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1257
-            $template_args,
1258
-            $datetime_row,
1259
-            $datetime,
1260
-            $default,
1261
-            $all_datetimes,
1262
-            $this->_is_creating_event
1263
-        );
1264
-        return EEH_Template::display_template(
1265
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1266
-            $template_args,
1267
-            true
1268
-        );
1269
-    }
1199
+	/**
1200
+	 * This method is used to generate a dtt fields  edit row.
1201
+	 * The same row is used to generate a row with valid DTT objects
1202
+	 * and the default row that is used as the skeleton by the js.
1203
+	 *
1204
+	 * @param int           $datetime_row  The row number for the row being generated.
1205
+	 * @param EE_Datetime   $datetime
1206
+	 * @param bool          $default       Whether a default row is being generated or not.
1207
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1208
+	 * @return string
1209
+	 * @throws DomainException
1210
+	 * @throws EE_Error
1211
+	 */
1212
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1213
+	{
1214
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1215
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1216
+		$template_args = array(
1217
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1218
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1219
+			'edit_dtt_expanded'    => '',
1220
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1221
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1222
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1223
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1224
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1225
+			'DTT_reg_limit'        => $default
1226
+				? ''
1227
+				: $datetime->get_pretty(
1228
+					'DTT_reg_limit',
1229
+					'input'
1230
+				),
1231
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1232
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1233
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1234
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1235
+				? ''
1236
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1237
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1238
+				? 'ee-lock-icon'
1239
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1240
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1241
+				? ''
1242
+				: EE_Admin_Page::add_query_args_and_nonce(
1243
+					array(
1244
+						'event_id' => $datetime->event()->ID(),
1245
+						'datetime_id' => $datetime->ID(),
1246
+						'use_filters' => true
1247
+					),
1248
+					REG_ADMIN_URL
1249
+				),
1250
+		);
1251
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1252
+			? 'display:none'
1253
+			: '';
1254
+		// allow filtering of template args at this point.
1255
+		$template_args = apply_filters(
1256
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1257
+			$template_args,
1258
+			$datetime_row,
1259
+			$datetime,
1260
+			$default,
1261
+			$all_datetimes,
1262
+			$this->_is_creating_event
1263
+		);
1264
+		return EEH_Template::display_template(
1265
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1266
+			$template_args,
1267
+			true
1268
+		);
1269
+	}
1270 1270
 
1271 1271
 
1272
-    /**
1273
-     * @param int         $datetime_row
1274
-     * @param EE_Datetime $datetime
1275
-     * @param array       $datetime_tickets
1276
-     * @param array       $all_tickets
1277
-     * @param bool       $default
1278
-     * @return mixed
1279
-     * @throws DomainException
1280
-     * @throws EE_Error
1281
-     */
1282
-    protected function _get_dtt_attached_tickets_row(
1283
-        $datetime_row,
1284
-        $datetime,
1285
-        $datetime_tickets = array(),
1286
-        $all_tickets = array(),
1287
-        $default = false
1288
-    ) {
1289
-        $template_args = array(
1290
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1291
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1292
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1293
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1294
-            'show_tickets_row'                  => 'display:none;',
1295
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1296
-                'add_new_ticket_via_datetime',
1297
-                $this->_adminpage_obj->page_slug,
1298
-                $this->_adminpage_obj->get_req_action(),
1299
-                false,
1300
-                false
1301
-            ),
1302
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1303
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1304
-        );
1305
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1306
-        if (! $default) {
1307
-            $ticket_row = 1;
1308
-            foreach ($all_tickets as $ticket) {
1309
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1310
-                    $datetime_row,
1311
-                    $ticket_row,
1312
-                    $datetime,
1313
-                    $ticket,
1314
-                    $datetime_tickets,
1315
-                    $default
1316
-                );
1317
-                $ticket_row++;
1318
-            }
1319
-        }
1320
-        // filter template args at this point
1321
-        $template_args = apply_filters(
1322
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1323
-            $template_args,
1324
-            $datetime_row,
1325
-            $datetime,
1326
-            $datetime_tickets,
1327
-            $all_tickets,
1328
-            $default,
1329
-            $this->_is_creating_event
1330
-        );
1331
-        return EEH_Template::display_template(
1332
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1333
-            $template_args,
1334
-            true
1335
-        );
1336
-    }
1272
+	/**
1273
+	 * @param int         $datetime_row
1274
+	 * @param EE_Datetime $datetime
1275
+	 * @param array       $datetime_tickets
1276
+	 * @param array       $all_tickets
1277
+	 * @param bool       $default
1278
+	 * @return mixed
1279
+	 * @throws DomainException
1280
+	 * @throws EE_Error
1281
+	 */
1282
+	protected function _get_dtt_attached_tickets_row(
1283
+		$datetime_row,
1284
+		$datetime,
1285
+		$datetime_tickets = array(),
1286
+		$all_tickets = array(),
1287
+		$default = false
1288
+	) {
1289
+		$template_args = array(
1290
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1291
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1292
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1293
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1294
+			'show_tickets_row'                  => 'display:none;',
1295
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1296
+				'add_new_ticket_via_datetime',
1297
+				$this->_adminpage_obj->page_slug,
1298
+				$this->_adminpage_obj->get_req_action(),
1299
+				false,
1300
+				false
1301
+			),
1302
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1303
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1304
+		);
1305
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1306
+		if (! $default) {
1307
+			$ticket_row = 1;
1308
+			foreach ($all_tickets as $ticket) {
1309
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1310
+					$datetime_row,
1311
+					$ticket_row,
1312
+					$datetime,
1313
+					$ticket,
1314
+					$datetime_tickets,
1315
+					$default
1316
+				);
1317
+				$ticket_row++;
1318
+			}
1319
+		}
1320
+		// filter template args at this point
1321
+		$template_args = apply_filters(
1322
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1323
+			$template_args,
1324
+			$datetime_row,
1325
+			$datetime,
1326
+			$datetime_tickets,
1327
+			$all_tickets,
1328
+			$default,
1329
+			$this->_is_creating_event
1330
+		);
1331
+		return EEH_Template::display_template(
1332
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1333
+			$template_args,
1334
+			true
1335
+		);
1336
+	}
1337 1337
 
1338 1338
 
1339
-    /**
1340
-     * @param int         $datetime_row
1341
-     * @param int         $ticket_row
1342
-     * @param EE_Datetime $datetime
1343
-     * @param EE_Ticket   $ticket
1344
-     * @param array       $datetime_tickets
1345
-     * @param bool        $default
1346
-     * @return mixed
1347
-     * @throws DomainException
1348
-     * @throws EE_Error
1349
-     */
1350
-    protected function _get_datetime_tickets_list_item(
1351
-        $datetime_row,
1352
-        $ticket_row,
1353
-        $datetime,
1354
-        $ticket,
1355
-        $datetime_tickets = array(),
1356
-        $default = false
1357
-    ) {
1358
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1359
-            ? $datetime_tickets[ $datetime->ID() ]
1360
-            : array();
1361
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1362
-        $no_ticket = $default && empty($ticket);
1363
-        $template_args = array(
1364
-            'dtt_row'                 => $default
1365
-                ? 'DTTNUM'
1366
-                : $datetime_row,
1367
-            'tkt_row'                 => $no_ticket
1368
-                ? 'TICKETNUM'
1369
-                : $ticket_row,
1370
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1371
-                ? ' checked'
1372
-                : '',
1373
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1374
-                ? ' ticket-selected'
1375
-                : '',
1376
-            'TKT_name'                => $no_ticket
1377
-                ? 'TKTNAME'
1378
-                : $ticket->get('TKT_name'),
1379
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1380
-                ? ' tkt-status-' . EE_Ticket::onsale
1381
-                : ' tkt-status-' . $ticket->ticket_status(),
1382
-        );
1383
-        // filter template args
1384
-        $template_args = apply_filters(
1385
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1386
-            $template_args,
1387
-            $datetime_row,
1388
-            $ticket_row,
1389
-            $datetime,
1390
-            $ticket,
1391
-            $datetime_tickets,
1392
-            $default,
1393
-            $this->_is_creating_event
1394
-        );
1395
-        return EEH_Template::display_template(
1396
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1397
-            $template_args,
1398
-            true
1399
-        );
1400
-    }
1339
+	/**
1340
+	 * @param int         $datetime_row
1341
+	 * @param int         $ticket_row
1342
+	 * @param EE_Datetime $datetime
1343
+	 * @param EE_Ticket   $ticket
1344
+	 * @param array       $datetime_tickets
1345
+	 * @param bool        $default
1346
+	 * @return mixed
1347
+	 * @throws DomainException
1348
+	 * @throws EE_Error
1349
+	 */
1350
+	protected function _get_datetime_tickets_list_item(
1351
+		$datetime_row,
1352
+		$ticket_row,
1353
+		$datetime,
1354
+		$ticket,
1355
+		$datetime_tickets = array(),
1356
+		$default = false
1357
+	) {
1358
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1359
+			? $datetime_tickets[ $datetime->ID() ]
1360
+			: array();
1361
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1362
+		$no_ticket = $default && empty($ticket);
1363
+		$template_args = array(
1364
+			'dtt_row'                 => $default
1365
+				? 'DTTNUM'
1366
+				: $datetime_row,
1367
+			'tkt_row'                 => $no_ticket
1368
+				? 'TICKETNUM'
1369
+				: $ticket_row,
1370
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1371
+				? ' checked'
1372
+				: '',
1373
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1374
+				? ' ticket-selected'
1375
+				: '',
1376
+			'TKT_name'                => $no_ticket
1377
+				? 'TKTNAME'
1378
+				: $ticket->get('TKT_name'),
1379
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1380
+				? ' tkt-status-' . EE_Ticket::onsale
1381
+				: ' tkt-status-' . $ticket->ticket_status(),
1382
+		);
1383
+		// filter template args
1384
+		$template_args = apply_filters(
1385
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1386
+			$template_args,
1387
+			$datetime_row,
1388
+			$ticket_row,
1389
+			$datetime,
1390
+			$ticket,
1391
+			$datetime_tickets,
1392
+			$default,
1393
+			$this->_is_creating_event
1394
+		);
1395
+		return EEH_Template::display_template(
1396
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1397
+			$template_args,
1398
+			true
1399
+		);
1400
+	}
1401 1401
 
1402 1402
 
1403
-    /**
1404
-     * This generates the ticket row for tickets.
1405
-     * This same method is used to generate both the actual rows and the js skeleton row
1406
-     * (when default === true)
1407
-     *
1408
-     * @param int           $ticket_row       Represents the row number being generated.
1409
-     * @param               $ticket
1410
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1411
-     *                                        or empty for default
1412
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1413
-     * @param bool          $default          Whether default row being generated or not.
1414
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1415
-     *                                        (or empty in the case of defaults)
1416
-     * @return mixed
1417
-     * @throws InvalidArgumentException
1418
-     * @throws InvalidInterfaceException
1419
-     * @throws InvalidDataTypeException
1420
-     * @throws DomainException
1421
-     * @throws EE_Error
1422
-     * @throws ReflectionException
1423
-     */
1424
-    protected function _get_ticket_row(
1425
-        $ticket_row,
1426
-        $ticket,
1427
-        $ticket_datetimes,
1428
-        $all_datetimes,
1429
-        $default = false,
1430
-        $all_tickets = array()
1431
-    ) {
1432
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1433
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1434
-        $prices = ! empty($ticket) && ! $default
1435
-            ? $ticket->get_many_related(
1436
-                'Price',
1437
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1438
-            )
1439
-            : array();
1440
-        // if there is only one price (which would be the base price)
1441
-        // or NO prices and this ticket is a default ticket,
1442
-        // let's just make sure there are no cached default prices on the object.
1443
-        // This is done by not including any query_params.
1444
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1445
-            $prices = $ticket->prices();
1446
-        }
1447
-        // check if we're dealing with a default ticket in which case
1448
-        // we don't want any starting_ticket_datetime_row values set
1449
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1450
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1451
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1452
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1453
-            ? $ticket_datetimes[ $ticket->ID() ]
1454
-            : array();
1455
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1456
-        $base_price = $default ? null : $ticket->base_price();
1457
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1458
-        // breaking out complicated condition for ticket_status
1459
-        if ($default) {
1460
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1461
-        } else {
1462
-            $ticket_status_class = $ticket->is_default()
1463
-                ? ' tkt-status-' . EE_Ticket::onsale
1464
-                : ' tkt-status-' . $ticket->ticket_status();
1465
-        }
1466
-        // breaking out complicated condition for TKT_taxable
1467
-        if ($default) {
1468
-            $TKT_taxable = '';
1469
-        } else {
1470
-            $TKT_taxable = $ticket->taxable()
1471
-                ? 'checked'
1472
-                : '';
1473
-        }
1474
-        if ($default) {
1475
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1476
-        } elseif ($ticket->is_default()) {
1477
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1478
-        } else {
1479
-            $TKT_status = $ticket->ticket_status(true);
1480
-        }
1481
-        if ($default) {
1482
-            $TKT_min = '';
1483
-        } else {
1484
-            $TKT_min = $ticket->min();
1485
-            if ($TKT_min === -1 || $TKT_min === 0) {
1486
-                $TKT_min = '';
1487
-            }
1488
-        }
1489
-        $template_args = array(
1490
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1491
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1492
-            // on initial page load this will always be the correct order.
1493
-            'tkt_status_class'              => $ticket_status_class,
1494
-            'display_edit_tkt_row'          => 'display:none;',
1495
-            'edit_tkt_expanded'             => '',
1496
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1497
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1498
-            'TKT_start_date'                => $default
1499
-                ? ''
1500
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1501
-            'TKT_end_date'                  => $default
1502
-                ? ''
1503
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1504
-            'TKT_status'                    => $TKT_status,
1505
-            'TKT_price'                     => $default
1506
-                ? ''
1507
-                : EEH_Template::format_currency(
1508
-                    $ticket->get_ticket_total_with_taxes(),
1509
-                    false,
1510
-                    false
1511
-                ),
1512
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1513
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1514
-            'TKT_qty'                       => $default
1515
-                ? ''
1516
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1517
-            'TKT_qty_for_input'             => $default
1518
-                ? ''
1519
-                : $ticket->get_pretty('TKT_qty', 'input'),
1520
-            'TKT_uses'                      => $default
1521
-                ? ''
1522
-                : $ticket->get_pretty('TKT_uses', 'input'),
1523
-            'TKT_min'                       => $TKT_min,
1524
-            'TKT_max'                       => $default
1525
-                ? ''
1526
-                : $ticket->get_pretty('TKT_max', 'input'),
1527
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1528
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1529
-            'TKT_registrations'             => $default
1530
-                ? 0
1531
-                : $ticket->count_registrations(
1532
-                    array(
1533
-                        array(
1534
-                            'STS_ID' => array(
1535
-                                '!=',
1536
-                                EEM_Registration::status_id_incomplete,
1537
-                            ),
1538
-                        ),
1539
-                    )
1540
-                ),
1541
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1542
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1543
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1544
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1545
-            'TKT_is_default_selector'       => '',
1546
-            'ticket_price_rows'             => '',
1547
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1548
-                ? ''
1549
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1550
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1551
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1552
-                ? ''
1553
-                : 'display:none;',
1554
-            'show_price_mod_button'         => count($prices) > 1
1555
-                                               || ($default && $count_price_mods > 0)
1556
-                                               || (! $default && $ticket->deleted())
1557
-                ? 'display:none;'
1558
-                : '',
1559
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1560
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1561
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1562
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1563
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1564
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1565
-            'TKT_taxable'                   => $TKT_taxable,
1566
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1567
-                ? ''
1568
-                : 'display:none;',
1569
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1570
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1571
-                $ticket_subtotal,
1572
-                false,
1573
-                false
1574
-            ),
1575
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1576
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1577
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1578
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1579
-                ? ' ticket-archived'
1580
-                : '',
1581
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1582
-                                               && $ticket->deleted()
1583
-                                               && ! $ticket->is_permanently_deleteable()
1584
-                ? 'ee-lock-icon '
1585
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1586
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1587
-                ? ''
1588
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1589
-        );
1590
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1591
-            ? 'display:none'
1592
-            : '';
1593
-        // handle rows that should NOT be empty
1594
-        if (empty($template_args['TKT_start_date'])) {
1595
-            // if empty then the start date will be now.
1596
-            $template_args['TKT_start_date'] = date(
1597
-                $this->_date_time_format,
1598
-                current_time('timestamp')
1599
-            );
1600
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1601
-        }
1602
-        if (empty($template_args['TKT_end_date'])) {
1603
-            // get the earliest datetime (if present);
1604
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1605
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1606
-                    'Datetime',
1607
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1608
-                )
1609
-                : null;
1610
-            if (! empty($earliest_dtt)) {
1611
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1612
-                    'DTT_EVT_start',
1613
-                    $this->_date_time_format
1614
-                );
1615
-            } else {
1616
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1617
-                $template_args['TKT_end_date'] = date(
1618
-                    $this->_date_time_format,
1619
-                    mktime(
1620
-                        24,
1621
-                        0,
1622
-                        0,
1623
-                        date('m'),
1624
-                        date('d') + 29,
1625
-                        date('Y')
1626
-                    )
1627
-                );
1628
-            }
1629
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1630
-        }
1631
-        // generate ticket_datetime items
1632
-        if (! $default) {
1633
-            $datetime_row = 1;
1634
-            foreach ($all_datetimes as $datetime) {
1635
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1636
-                    $datetime_row,
1637
-                    $ticket_row,
1638
-                    $datetime,
1639
-                    $ticket,
1640
-                    $ticket_datetimes,
1641
-                    $default
1642
-                );
1643
-                $datetime_row++;
1644
-            }
1645
-        }
1646
-        $price_row = 1;
1647
-        foreach ($prices as $price) {
1648
-            if (! $price instanceof EE_Price) {
1649
-                continue;
1650
-            }
1651
-            if ($price->is_base_price()) {
1652
-                $price_row++;
1653
-                continue;
1654
-            }
1655
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1656
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1657
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1658
-                $ticket_row,
1659
-                $price_row,
1660
-                $price,
1661
-                $default,
1662
-                $ticket,
1663
-                $show_trash,
1664
-                $show_create
1665
-            );
1666
-            $price_row++;
1667
-        }
1668
-        // filter $template_args
1669
-        $template_args = apply_filters(
1670
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1671
-            $template_args,
1672
-            $ticket_row,
1673
-            $ticket,
1674
-            $ticket_datetimes,
1675
-            $all_datetimes,
1676
-            $default,
1677
-            $all_tickets,
1678
-            $this->_is_creating_event
1679
-        );
1680
-        return EEH_Template::display_template(
1681
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1682
-            $template_args,
1683
-            true
1684
-        );
1685
-    }
1403
+	/**
1404
+	 * This generates the ticket row for tickets.
1405
+	 * This same method is used to generate both the actual rows and the js skeleton row
1406
+	 * (when default === true)
1407
+	 *
1408
+	 * @param int           $ticket_row       Represents the row number being generated.
1409
+	 * @param               $ticket
1410
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1411
+	 *                                        or empty for default
1412
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1413
+	 * @param bool          $default          Whether default row being generated or not.
1414
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1415
+	 *                                        (or empty in the case of defaults)
1416
+	 * @return mixed
1417
+	 * @throws InvalidArgumentException
1418
+	 * @throws InvalidInterfaceException
1419
+	 * @throws InvalidDataTypeException
1420
+	 * @throws DomainException
1421
+	 * @throws EE_Error
1422
+	 * @throws ReflectionException
1423
+	 */
1424
+	protected function _get_ticket_row(
1425
+		$ticket_row,
1426
+		$ticket,
1427
+		$ticket_datetimes,
1428
+		$all_datetimes,
1429
+		$default = false,
1430
+		$all_tickets = array()
1431
+	) {
1432
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1433
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1434
+		$prices = ! empty($ticket) && ! $default
1435
+			? $ticket->get_many_related(
1436
+				'Price',
1437
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1438
+			)
1439
+			: array();
1440
+		// if there is only one price (which would be the base price)
1441
+		// or NO prices and this ticket is a default ticket,
1442
+		// let's just make sure there are no cached default prices on the object.
1443
+		// This is done by not including any query_params.
1444
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1445
+			$prices = $ticket->prices();
1446
+		}
1447
+		// check if we're dealing with a default ticket in which case
1448
+		// we don't want any starting_ticket_datetime_row values set
1449
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1450
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1451
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1452
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1453
+			? $ticket_datetimes[ $ticket->ID() ]
1454
+			: array();
1455
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1456
+		$base_price = $default ? null : $ticket->base_price();
1457
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1458
+		// breaking out complicated condition for ticket_status
1459
+		if ($default) {
1460
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1461
+		} else {
1462
+			$ticket_status_class = $ticket->is_default()
1463
+				? ' tkt-status-' . EE_Ticket::onsale
1464
+				: ' tkt-status-' . $ticket->ticket_status();
1465
+		}
1466
+		// breaking out complicated condition for TKT_taxable
1467
+		if ($default) {
1468
+			$TKT_taxable = '';
1469
+		} else {
1470
+			$TKT_taxable = $ticket->taxable()
1471
+				? 'checked'
1472
+				: '';
1473
+		}
1474
+		if ($default) {
1475
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1476
+		} elseif ($ticket->is_default()) {
1477
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1478
+		} else {
1479
+			$TKT_status = $ticket->ticket_status(true);
1480
+		}
1481
+		if ($default) {
1482
+			$TKT_min = '';
1483
+		} else {
1484
+			$TKT_min = $ticket->min();
1485
+			if ($TKT_min === -1 || $TKT_min === 0) {
1486
+				$TKT_min = '';
1487
+			}
1488
+		}
1489
+		$template_args = array(
1490
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1491
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1492
+			// on initial page load this will always be the correct order.
1493
+			'tkt_status_class'              => $ticket_status_class,
1494
+			'display_edit_tkt_row'          => 'display:none;',
1495
+			'edit_tkt_expanded'             => '',
1496
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1497
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1498
+			'TKT_start_date'                => $default
1499
+				? ''
1500
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1501
+			'TKT_end_date'                  => $default
1502
+				? ''
1503
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1504
+			'TKT_status'                    => $TKT_status,
1505
+			'TKT_price'                     => $default
1506
+				? ''
1507
+				: EEH_Template::format_currency(
1508
+					$ticket->get_ticket_total_with_taxes(),
1509
+					false,
1510
+					false
1511
+				),
1512
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1513
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1514
+			'TKT_qty'                       => $default
1515
+				? ''
1516
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1517
+			'TKT_qty_for_input'             => $default
1518
+				? ''
1519
+				: $ticket->get_pretty('TKT_qty', 'input'),
1520
+			'TKT_uses'                      => $default
1521
+				? ''
1522
+				: $ticket->get_pretty('TKT_uses', 'input'),
1523
+			'TKT_min'                       => $TKT_min,
1524
+			'TKT_max'                       => $default
1525
+				? ''
1526
+				: $ticket->get_pretty('TKT_max', 'input'),
1527
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1528
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1529
+			'TKT_registrations'             => $default
1530
+				? 0
1531
+				: $ticket->count_registrations(
1532
+					array(
1533
+						array(
1534
+							'STS_ID' => array(
1535
+								'!=',
1536
+								EEM_Registration::status_id_incomplete,
1537
+							),
1538
+						),
1539
+					)
1540
+				),
1541
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1542
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1543
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1544
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1545
+			'TKT_is_default_selector'       => '',
1546
+			'ticket_price_rows'             => '',
1547
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1548
+				? ''
1549
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1550
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1551
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1552
+				? ''
1553
+				: 'display:none;',
1554
+			'show_price_mod_button'         => count($prices) > 1
1555
+											   || ($default && $count_price_mods > 0)
1556
+											   || (! $default && $ticket->deleted())
1557
+				? 'display:none;'
1558
+				: '',
1559
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1560
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1561
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1562
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1563
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1564
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1565
+			'TKT_taxable'                   => $TKT_taxable,
1566
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1567
+				? ''
1568
+				: 'display:none;',
1569
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1570
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1571
+				$ticket_subtotal,
1572
+				false,
1573
+				false
1574
+			),
1575
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1576
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1577
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1578
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1579
+				? ' ticket-archived'
1580
+				: '',
1581
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1582
+											   && $ticket->deleted()
1583
+											   && ! $ticket->is_permanently_deleteable()
1584
+				? 'ee-lock-icon '
1585
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1586
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1587
+				? ''
1588
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1589
+		);
1590
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1591
+			? 'display:none'
1592
+			: '';
1593
+		// handle rows that should NOT be empty
1594
+		if (empty($template_args['TKT_start_date'])) {
1595
+			// if empty then the start date will be now.
1596
+			$template_args['TKT_start_date'] = date(
1597
+				$this->_date_time_format,
1598
+				current_time('timestamp')
1599
+			);
1600
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1601
+		}
1602
+		if (empty($template_args['TKT_end_date'])) {
1603
+			// get the earliest datetime (if present);
1604
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1605
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1606
+					'Datetime',
1607
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1608
+				)
1609
+				: null;
1610
+			if (! empty($earliest_dtt)) {
1611
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1612
+					'DTT_EVT_start',
1613
+					$this->_date_time_format
1614
+				);
1615
+			} else {
1616
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1617
+				$template_args['TKT_end_date'] = date(
1618
+					$this->_date_time_format,
1619
+					mktime(
1620
+						24,
1621
+						0,
1622
+						0,
1623
+						date('m'),
1624
+						date('d') + 29,
1625
+						date('Y')
1626
+					)
1627
+				);
1628
+			}
1629
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1630
+		}
1631
+		// generate ticket_datetime items
1632
+		if (! $default) {
1633
+			$datetime_row = 1;
1634
+			foreach ($all_datetimes as $datetime) {
1635
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1636
+					$datetime_row,
1637
+					$ticket_row,
1638
+					$datetime,
1639
+					$ticket,
1640
+					$ticket_datetimes,
1641
+					$default
1642
+				);
1643
+				$datetime_row++;
1644
+			}
1645
+		}
1646
+		$price_row = 1;
1647
+		foreach ($prices as $price) {
1648
+			if (! $price instanceof EE_Price) {
1649
+				continue;
1650
+			}
1651
+			if ($price->is_base_price()) {
1652
+				$price_row++;
1653
+				continue;
1654
+			}
1655
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1656
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1657
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1658
+				$ticket_row,
1659
+				$price_row,
1660
+				$price,
1661
+				$default,
1662
+				$ticket,
1663
+				$show_trash,
1664
+				$show_create
1665
+			);
1666
+			$price_row++;
1667
+		}
1668
+		// filter $template_args
1669
+		$template_args = apply_filters(
1670
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1671
+			$template_args,
1672
+			$ticket_row,
1673
+			$ticket,
1674
+			$ticket_datetimes,
1675
+			$all_datetimes,
1676
+			$default,
1677
+			$all_tickets,
1678
+			$this->_is_creating_event
1679
+		);
1680
+		return EEH_Template::display_template(
1681
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1682
+			$template_args,
1683
+			true
1684
+		);
1685
+	}
1686 1686
 
1687 1687
 
1688
-    /**
1689
-     * @param int            $ticket_row
1690
-     * @param EE_Ticket|null $ticket
1691
-     * @return string
1692
-     * @throws DomainException
1693
-     * @throws EE_Error
1694
-     */
1695
-    protected function _get_tax_rows($ticket_row, $ticket)
1696
-    {
1697
-        $tax_rows = '';
1698
-        /** @var EE_Price[] $taxes */
1699
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1700
-        foreach ($taxes as $tax) {
1701
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1702
-            $template_args = array(
1703
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1704
-                    ? ''
1705
-                    : 'display:none;',
1706
-                'tax_id'            => $tax->ID(),
1707
-                'tkt_row'           => $ticket_row,
1708
-                'tax_label'         => $tax->get('PRC_name'),
1709
-                'tax_added'         => $tax_added,
1710
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1711
-                'tax_amount'        => $tax->get('PRC_amount'),
1712
-            );
1713
-            $template_args = apply_filters(
1714
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1715
-                $template_args,
1716
-                $ticket_row,
1717
-                $ticket,
1718
-                $this->_is_creating_event
1719
-            );
1720
-            $tax_rows .= EEH_Template::display_template(
1721
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1722
-                $template_args,
1723
-                true
1724
-            );
1725
-        }
1726
-        return $tax_rows;
1727
-    }
1688
+	/**
1689
+	 * @param int            $ticket_row
1690
+	 * @param EE_Ticket|null $ticket
1691
+	 * @return string
1692
+	 * @throws DomainException
1693
+	 * @throws EE_Error
1694
+	 */
1695
+	protected function _get_tax_rows($ticket_row, $ticket)
1696
+	{
1697
+		$tax_rows = '';
1698
+		/** @var EE_Price[] $taxes */
1699
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1700
+		foreach ($taxes as $tax) {
1701
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1702
+			$template_args = array(
1703
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1704
+					? ''
1705
+					: 'display:none;',
1706
+				'tax_id'            => $tax->ID(),
1707
+				'tkt_row'           => $ticket_row,
1708
+				'tax_label'         => $tax->get('PRC_name'),
1709
+				'tax_added'         => $tax_added,
1710
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1711
+				'tax_amount'        => $tax->get('PRC_amount'),
1712
+			);
1713
+			$template_args = apply_filters(
1714
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1715
+				$template_args,
1716
+				$ticket_row,
1717
+				$ticket,
1718
+				$this->_is_creating_event
1719
+			);
1720
+			$tax_rows .= EEH_Template::display_template(
1721
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1722
+				$template_args,
1723
+				true
1724
+			);
1725
+		}
1726
+		return $tax_rows;
1727
+	}
1728 1728
 
1729 1729
 
1730
-    /**
1731
-     * @param EE_Price       $tax
1732
-     * @param EE_Ticket|null $ticket
1733
-     * @return float|int
1734
-     * @throws EE_Error
1735
-     */
1736
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1737
-    {
1738
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1739
-        return $subtotal * $tax->get('PRC_amount') / 100;
1740
-    }
1730
+	/**
1731
+	 * @param EE_Price       $tax
1732
+	 * @param EE_Ticket|null $ticket
1733
+	 * @return float|int
1734
+	 * @throws EE_Error
1735
+	 */
1736
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1737
+	{
1738
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1739
+		return $subtotal * $tax->get('PRC_amount') / 100;
1740
+	}
1741 1741
 
1742 1742
 
1743
-    /**
1744
-     * @param int            $ticket_row
1745
-     * @param int            $price_row
1746
-     * @param EE_Price|null  $price
1747
-     * @param bool           $default
1748
-     * @param EE_Ticket|null $ticket
1749
-     * @param bool           $show_trash
1750
-     * @param bool           $show_create
1751
-     * @return mixed
1752
-     * @throws InvalidArgumentException
1753
-     * @throws InvalidInterfaceException
1754
-     * @throws InvalidDataTypeException
1755
-     * @throws DomainException
1756
-     * @throws EE_Error
1757
-     * @throws ReflectionException
1758
-     */
1759
-    protected function _get_ticket_price_row(
1760
-        $ticket_row,
1761
-        $price_row,
1762
-        $price,
1763
-        $default,
1764
-        $ticket,
1765
-        $show_trash = true,
1766
-        $show_create = true
1767
-    ) {
1768
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1769
-        $template_args = array(
1770
-            'tkt_row'               => $default && empty($ticket)
1771
-                ? 'TICKETNUM'
1772
-                : $ticket_row,
1773
-            'PRC_order'             => $default && empty($price)
1774
-                ? 'PRICENUM'
1775
-                : $price_row,
1776
-            'edit_prices_name'      => $default && empty($price)
1777
-                ? 'PRICENAMEATTR'
1778
-                : 'edit_prices',
1779
-            'price_type_selector'   => $default && empty($price)
1780
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1781
-                : $this->_get_price_type_selector(
1782
-                    $ticket_row,
1783
-                    $price_row,
1784
-                    $price,
1785
-                    $default,
1786
-                    $send_disabled
1787
-                ),
1788
-            'PRC_ID'                => $default && empty($price)
1789
-                ? 0
1790
-                : $price->ID(),
1791
-            'PRC_is_default'        => $default && empty($price)
1792
-                ? 0
1793
-                : $price->get('PRC_is_default'),
1794
-            'PRC_name'              => $default && empty($price)
1795
-                ? ''
1796
-                : $price->get('PRC_name'),
1797
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1798
-            'show_plus_or_minus'    => $default && empty($price)
1799
-                ? ''
1800
-                : 'display:none;',
1801
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1802
-                ? 'display:none;'
1803
-                : '',
1804
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1805
-                ? 'display:none;'
1806
-                : '',
1807
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1808
-                ? 'display:none'
1809
-                : '',
1810
-            'PRC_amount'            => $default && empty($price)
1811
-                ? 0
1812
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1813
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1814
-                ? 'display:none;'
1815
-                : '',
1816
-            'show_trash_icon'       => $show_trash
1817
-                ? ''
1818
-                : ' style="display:none;"',
1819
-            'show_create_button'    => $show_create
1820
-                ? ''
1821
-                : ' style="display:none;"',
1822
-            'PRC_desc'              => $default && empty($price)
1823
-                ? ''
1824
-                : $price->get('PRC_desc'),
1825
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1826
-        );
1827
-        $template_args = apply_filters(
1828
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1829
-            $template_args,
1830
-            $ticket_row,
1831
-            $price_row,
1832
-            $price,
1833
-            $default,
1834
-            $ticket,
1835
-            $show_trash,
1836
-            $show_create,
1837
-            $this->_is_creating_event
1838
-        );
1839
-        return EEH_Template::display_template(
1840
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1841
-            $template_args,
1842
-            true
1843
-        );
1844
-    }
1743
+	/**
1744
+	 * @param int            $ticket_row
1745
+	 * @param int            $price_row
1746
+	 * @param EE_Price|null  $price
1747
+	 * @param bool           $default
1748
+	 * @param EE_Ticket|null $ticket
1749
+	 * @param bool           $show_trash
1750
+	 * @param bool           $show_create
1751
+	 * @return mixed
1752
+	 * @throws InvalidArgumentException
1753
+	 * @throws InvalidInterfaceException
1754
+	 * @throws InvalidDataTypeException
1755
+	 * @throws DomainException
1756
+	 * @throws EE_Error
1757
+	 * @throws ReflectionException
1758
+	 */
1759
+	protected function _get_ticket_price_row(
1760
+		$ticket_row,
1761
+		$price_row,
1762
+		$price,
1763
+		$default,
1764
+		$ticket,
1765
+		$show_trash = true,
1766
+		$show_create = true
1767
+	) {
1768
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1769
+		$template_args = array(
1770
+			'tkt_row'               => $default && empty($ticket)
1771
+				? 'TICKETNUM'
1772
+				: $ticket_row,
1773
+			'PRC_order'             => $default && empty($price)
1774
+				? 'PRICENUM'
1775
+				: $price_row,
1776
+			'edit_prices_name'      => $default && empty($price)
1777
+				? 'PRICENAMEATTR'
1778
+				: 'edit_prices',
1779
+			'price_type_selector'   => $default && empty($price)
1780
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1781
+				: $this->_get_price_type_selector(
1782
+					$ticket_row,
1783
+					$price_row,
1784
+					$price,
1785
+					$default,
1786
+					$send_disabled
1787
+				),
1788
+			'PRC_ID'                => $default && empty($price)
1789
+				? 0
1790
+				: $price->ID(),
1791
+			'PRC_is_default'        => $default && empty($price)
1792
+				? 0
1793
+				: $price->get('PRC_is_default'),
1794
+			'PRC_name'              => $default && empty($price)
1795
+				? ''
1796
+				: $price->get('PRC_name'),
1797
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1798
+			'show_plus_or_minus'    => $default && empty($price)
1799
+				? ''
1800
+				: 'display:none;',
1801
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1802
+				? 'display:none;'
1803
+				: '',
1804
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1805
+				? 'display:none;'
1806
+				: '',
1807
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1808
+				? 'display:none'
1809
+				: '',
1810
+			'PRC_amount'            => $default && empty($price)
1811
+				? 0
1812
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1813
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1814
+				? 'display:none;'
1815
+				: '',
1816
+			'show_trash_icon'       => $show_trash
1817
+				? ''
1818
+				: ' style="display:none;"',
1819
+			'show_create_button'    => $show_create
1820
+				? ''
1821
+				: ' style="display:none;"',
1822
+			'PRC_desc'              => $default && empty($price)
1823
+				? ''
1824
+				: $price->get('PRC_desc'),
1825
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1826
+		);
1827
+		$template_args = apply_filters(
1828
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1829
+			$template_args,
1830
+			$ticket_row,
1831
+			$price_row,
1832
+			$price,
1833
+			$default,
1834
+			$ticket,
1835
+			$show_trash,
1836
+			$show_create,
1837
+			$this->_is_creating_event
1838
+		);
1839
+		return EEH_Template::display_template(
1840
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1841
+			$template_args,
1842
+			true
1843
+		);
1844
+	}
1845 1845
 
1846 1846
 
1847
-    /**
1848
-     * @param int      $ticket_row
1849
-     * @param int      $price_row
1850
-     * @param EE_Price $price
1851
-     * @param bool     $default
1852
-     * @param bool     $disabled
1853
-     * @return mixed
1854
-     * @throws ReflectionException
1855
-     * @throws InvalidArgumentException
1856
-     * @throws InvalidInterfaceException
1857
-     * @throws InvalidDataTypeException
1858
-     * @throws DomainException
1859
-     * @throws EE_Error
1860
-     */
1861
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1862
-    {
1863
-        if ($price->is_base_price()) {
1864
-            return $this->_get_base_price_template(
1865
-                $ticket_row,
1866
-                $price_row,
1867
-                $price,
1868
-                $default
1869
-            );
1870
-        }
1871
-        return $this->_get_price_modifier_template(
1872
-            $ticket_row,
1873
-            $price_row,
1874
-            $price,
1875
-            $default,
1876
-            $disabled
1877
-        );
1878
-    }
1847
+	/**
1848
+	 * @param int      $ticket_row
1849
+	 * @param int      $price_row
1850
+	 * @param EE_Price $price
1851
+	 * @param bool     $default
1852
+	 * @param bool     $disabled
1853
+	 * @return mixed
1854
+	 * @throws ReflectionException
1855
+	 * @throws InvalidArgumentException
1856
+	 * @throws InvalidInterfaceException
1857
+	 * @throws InvalidDataTypeException
1858
+	 * @throws DomainException
1859
+	 * @throws EE_Error
1860
+	 */
1861
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1862
+	{
1863
+		if ($price->is_base_price()) {
1864
+			return $this->_get_base_price_template(
1865
+				$ticket_row,
1866
+				$price_row,
1867
+				$price,
1868
+				$default
1869
+			);
1870
+		}
1871
+		return $this->_get_price_modifier_template(
1872
+			$ticket_row,
1873
+			$price_row,
1874
+			$price,
1875
+			$default,
1876
+			$disabled
1877
+		);
1878
+	}
1879 1879
 
1880 1880
 
1881
-    /**
1882
-     * @param int      $ticket_row
1883
-     * @param int      $price_row
1884
-     * @param EE_Price $price
1885
-     * @param bool     $default
1886
-     * @return mixed
1887
-     * @throws DomainException
1888
-     * @throws EE_Error
1889
-     */
1890
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1891
-    {
1892
-        $template_args = array(
1893
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1894
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1895
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1896
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1897
-            'price_selected_operator'   => '+',
1898
-            'price_selected_is_percent' => 0,
1899
-        );
1900
-        $template_args = apply_filters(
1901
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1902
-            $template_args,
1903
-            $ticket_row,
1904
-            $price_row,
1905
-            $price,
1906
-            $default,
1907
-            $this->_is_creating_event
1908
-        );
1909
-        return EEH_Template::display_template(
1910
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1911
-            $template_args,
1912
-            true
1913
-        );
1914
-    }
1881
+	/**
1882
+	 * @param int      $ticket_row
1883
+	 * @param int      $price_row
1884
+	 * @param EE_Price $price
1885
+	 * @param bool     $default
1886
+	 * @return mixed
1887
+	 * @throws DomainException
1888
+	 * @throws EE_Error
1889
+	 */
1890
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1891
+	{
1892
+		$template_args = array(
1893
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1894
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1895
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1896
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1897
+			'price_selected_operator'   => '+',
1898
+			'price_selected_is_percent' => 0,
1899
+		);
1900
+		$template_args = apply_filters(
1901
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1902
+			$template_args,
1903
+			$ticket_row,
1904
+			$price_row,
1905
+			$price,
1906
+			$default,
1907
+			$this->_is_creating_event
1908
+		);
1909
+		return EEH_Template::display_template(
1910
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1911
+			$template_args,
1912
+			true
1913
+		);
1914
+	}
1915 1915
 
1916 1916
 
1917
-    /**
1918
-     * @param int      $ticket_row
1919
-     * @param int      $price_row
1920
-     * @param EE_Price $price
1921
-     * @param bool     $default
1922
-     * @param bool     $disabled
1923
-     * @return mixed
1924
-     * @throws ReflectionException
1925
-     * @throws InvalidArgumentException
1926
-     * @throws InvalidInterfaceException
1927
-     * @throws InvalidDataTypeException
1928
-     * @throws DomainException
1929
-     * @throws EE_Error
1930
-     */
1931
-    protected function _get_price_modifier_template(
1932
-        $ticket_row,
1933
-        $price_row,
1934
-        $price,
1935
-        $default,
1936
-        $disabled = false
1937
-    ) {
1938
-        $select_name = $default && ! $price instanceof EE_Price
1939
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1940
-            : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]';
1941
-        /** @var EEM_Price_Type $price_type_model */
1942
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1943
-        $price_types = $price_type_model->get_all(array(
1944
-            array(
1945
-                'OR' => array(
1946
-                    'PBT_ID'  => '2',
1947
-                    'PBT_ID*' => '3',
1948
-                ),
1949
-            ),
1950
-        ));
1951
-        $all_price_types = $default && ! $price instanceof EE_Price
1952
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1953
-            : array();
1954
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1955
-        $price_option_spans = '';
1956
-        // setup price types for selector
1957
-        foreach ($price_types as $price_type) {
1958
-            if (! $price_type instanceof EE_Price_Type) {
1959
-                continue;
1960
-            }
1961
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1962
-            // while we're in the loop let's setup the option spans used by js
1963
-            $span_args = array(
1964
-                'PRT_ID'         => $price_type->ID(),
1965
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1966
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1967
-            );
1968
-            $price_option_spans .= EEH_Template::display_template(
1969
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1970
-                $span_args,
1971
-                true
1972
-            );
1973
-        }
1974
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1975
-            : $select_name;
1976
-        $select_input = new EE_Select_Input(
1977
-            $all_price_types,
1978
-            array(
1979
-                'default'               => $selected_price_type_id,
1980
-                'html_name'             => $select_name,
1981
-                'html_class'            => 'edit-price-PRT_ID',
1982
-                'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1983
-            )
1984
-        );
1985
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1986
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1987
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1988
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1989
-        $template_args = array(
1990
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1991
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1992
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1993
-            'main_name'                 => $select_name,
1994
-            'selected_price_type_id'    => $selected_price_type_id,
1995
-            'price_option_spans'        => $price_option_spans,
1996
-            'price_selected_operator'   => $price_selected_operator,
1997
-            'price_selected_is_percent' => $price_selected_is_percent,
1998
-            'disabled'                  => $disabled,
1999
-        );
2000
-        $template_args = apply_filters(
2001
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
2002
-            $template_args,
2003
-            $ticket_row,
2004
-            $price_row,
2005
-            $price,
2006
-            $default,
2007
-            $disabled,
2008
-            $this->_is_creating_event
2009
-        );
2010
-        return EEH_Template::display_template(
2011
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2012
-            $template_args,
2013
-            true
2014
-        );
2015
-    }
1917
+	/**
1918
+	 * @param int      $ticket_row
1919
+	 * @param int      $price_row
1920
+	 * @param EE_Price $price
1921
+	 * @param bool     $default
1922
+	 * @param bool     $disabled
1923
+	 * @return mixed
1924
+	 * @throws ReflectionException
1925
+	 * @throws InvalidArgumentException
1926
+	 * @throws InvalidInterfaceException
1927
+	 * @throws InvalidDataTypeException
1928
+	 * @throws DomainException
1929
+	 * @throws EE_Error
1930
+	 */
1931
+	protected function _get_price_modifier_template(
1932
+		$ticket_row,
1933
+		$price_row,
1934
+		$price,
1935
+		$default,
1936
+		$disabled = false
1937
+	) {
1938
+		$select_name = $default && ! $price instanceof EE_Price
1939
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1940
+			: 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]';
1941
+		/** @var EEM_Price_Type $price_type_model */
1942
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1943
+		$price_types = $price_type_model->get_all(array(
1944
+			array(
1945
+				'OR' => array(
1946
+					'PBT_ID'  => '2',
1947
+					'PBT_ID*' => '3',
1948
+				),
1949
+			),
1950
+		));
1951
+		$all_price_types = $default && ! $price instanceof EE_Price
1952
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1953
+			: array();
1954
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1955
+		$price_option_spans = '';
1956
+		// setup price types for selector
1957
+		foreach ($price_types as $price_type) {
1958
+			if (! $price_type instanceof EE_Price_Type) {
1959
+				continue;
1960
+			}
1961
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1962
+			// while we're in the loop let's setup the option spans used by js
1963
+			$span_args = array(
1964
+				'PRT_ID'         => $price_type->ID(),
1965
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1966
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1967
+			);
1968
+			$price_option_spans .= EEH_Template::display_template(
1969
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1970
+				$span_args,
1971
+				true
1972
+			);
1973
+		}
1974
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1975
+			: $select_name;
1976
+		$select_input = new EE_Select_Input(
1977
+			$all_price_types,
1978
+			array(
1979
+				'default'               => $selected_price_type_id,
1980
+				'html_name'             => $select_name,
1981
+				'html_class'            => 'edit-price-PRT_ID',
1982
+				'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1983
+			)
1984
+		);
1985
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1986
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1987
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1988
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1989
+		$template_args = array(
1990
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1991
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1992
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1993
+			'main_name'                 => $select_name,
1994
+			'selected_price_type_id'    => $selected_price_type_id,
1995
+			'price_option_spans'        => $price_option_spans,
1996
+			'price_selected_operator'   => $price_selected_operator,
1997
+			'price_selected_is_percent' => $price_selected_is_percent,
1998
+			'disabled'                  => $disabled,
1999
+		);
2000
+		$template_args = apply_filters(
2001
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
2002
+			$template_args,
2003
+			$ticket_row,
2004
+			$price_row,
2005
+			$price,
2006
+			$default,
2007
+			$disabled,
2008
+			$this->_is_creating_event
2009
+		);
2010
+		return EEH_Template::display_template(
2011
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2012
+			$template_args,
2013
+			true
2014
+		);
2015
+	}
2016 2016
 
2017 2017
 
2018
-    /**
2019
-     * @param int              $datetime_row
2020
-     * @param int              $ticket_row
2021
-     * @param EE_Datetime|null $datetime
2022
-     * @param EE_Ticket|null   $ticket
2023
-     * @param array            $ticket_datetimes
2024
-     * @param bool             $default
2025
-     * @return mixed
2026
-     * @throws DomainException
2027
-     * @throws EE_Error
2028
-     */
2029
-    protected function _get_ticket_datetime_list_item(
2030
-        $datetime_row,
2031
-        $ticket_row,
2032
-        $datetime,
2033
-        $ticket,
2034
-        $ticket_datetimes = array(),
2035
-        $default = false
2036
-    ) {
2037
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2038
-            ? $ticket_datetimes[ $ticket->ID() ]
2039
-            : array();
2040
-        $template_args = array(
2041
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2042
-                ? 'DTTNUM'
2043
-                : $datetime_row,
2044
-            'tkt_row'                  => $default
2045
-                ? 'TICKETNUM'
2046
-                : $ticket_row,
2047
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2048
-                ? ' ticket-selected'
2049
-                : '',
2050
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2051
-                ? ' checked'
2052
-                : '',
2053
-            'DTT_name'                 => $default && empty($datetime)
2054
-                ? 'DTTNAME'
2055
-                : $datetime->get_dtt_display_name(true),
2056
-            'tkt_status_class'         => '',
2057
-        );
2058
-        $template_args = apply_filters(
2059
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2060
-            $template_args,
2061
-            $datetime_row,
2062
-            $ticket_row,
2063
-            $datetime,
2064
-            $ticket,
2065
-            $ticket_datetimes,
2066
-            $default,
2067
-            $this->_is_creating_event
2068
-        );
2069
-        return EEH_Template::display_template(
2070
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2071
-            $template_args,
2072
-            true
2073
-        );
2074
-    }
2018
+	/**
2019
+	 * @param int              $datetime_row
2020
+	 * @param int              $ticket_row
2021
+	 * @param EE_Datetime|null $datetime
2022
+	 * @param EE_Ticket|null   $ticket
2023
+	 * @param array            $ticket_datetimes
2024
+	 * @param bool             $default
2025
+	 * @return mixed
2026
+	 * @throws DomainException
2027
+	 * @throws EE_Error
2028
+	 */
2029
+	protected function _get_ticket_datetime_list_item(
2030
+		$datetime_row,
2031
+		$ticket_row,
2032
+		$datetime,
2033
+		$ticket,
2034
+		$ticket_datetimes = array(),
2035
+		$default = false
2036
+	) {
2037
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2038
+			? $ticket_datetimes[ $ticket->ID() ]
2039
+			: array();
2040
+		$template_args = array(
2041
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2042
+				? 'DTTNUM'
2043
+				: $datetime_row,
2044
+			'tkt_row'                  => $default
2045
+				? 'TICKETNUM'
2046
+				: $ticket_row,
2047
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2048
+				? ' ticket-selected'
2049
+				: '',
2050
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2051
+				? ' checked'
2052
+				: '',
2053
+			'DTT_name'                 => $default && empty($datetime)
2054
+				? 'DTTNAME'
2055
+				: $datetime->get_dtt_display_name(true),
2056
+			'tkt_status_class'         => '',
2057
+		);
2058
+		$template_args = apply_filters(
2059
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2060
+			$template_args,
2061
+			$datetime_row,
2062
+			$ticket_row,
2063
+			$datetime,
2064
+			$ticket,
2065
+			$ticket_datetimes,
2066
+			$default,
2067
+			$this->_is_creating_event
2068
+		);
2069
+		return EEH_Template::display_template(
2070
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2071
+			$template_args,
2072
+			true
2073
+		);
2074
+	}
2075 2075
 
2076 2076
 
2077
-    /**
2078
-     * @param array $all_datetimes
2079
-     * @param array $all_tickets
2080
-     * @return mixed
2081
-     * @throws ReflectionException
2082
-     * @throws InvalidArgumentException
2083
-     * @throws InvalidInterfaceException
2084
-     * @throws InvalidDataTypeException
2085
-     * @throws DomainException
2086
-     * @throws EE_Error
2087
-     */
2088
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2089
-    {
2090
-        $template_args = array(
2091
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2092
-                'DTTNUM',
2093
-                null,
2094
-                true,
2095
-                $all_datetimes
2096
-            ),
2097
-            'default_ticket_row'                       => $this->_get_ticket_row(
2098
-                'TICKETNUM',
2099
-                null,
2100
-                array(),
2101
-                array(),
2102
-                true
2103
-            ),
2104
-            'default_price_row'                        => $this->_get_ticket_price_row(
2105
-                'TICKETNUM',
2106
-                'PRICENUM',
2107
-                null,
2108
-                true,
2109
-                null
2110
-            ),
2111
-            'default_price_rows'                       => '',
2112
-            'default_base_price_amount'                => 0,
2113
-            'default_base_price_name'                  => '',
2114
-            'default_base_price_description'           => '',
2115
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2116
-                'TICKETNUM',
2117
-                'PRICENUM',
2118
-                null,
2119
-                true
2120
-            ),
2121
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2122
-                'DTTNUM',
2123
-                null,
2124
-                array(),
2125
-                array(),
2126
-                true
2127
-            ),
2128
-            'existing_available_datetime_tickets_list' => '',
2129
-            'existing_available_ticket_datetimes_list' => '',
2130
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2131
-                'DTTNUM',
2132
-                'TICKETNUM',
2133
-                null,
2134
-                null,
2135
-                array(),
2136
-                true
2137
-            ),
2138
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2139
-                'DTTNUM',
2140
-                'TICKETNUM',
2141
-                null,
2142
-                null,
2143
-                array(),
2144
-                true
2145
-            ),
2146
-        );
2147
-        $ticket_row = 1;
2148
-        foreach ($all_tickets as $ticket) {
2149
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2150
-                'DTTNUM',
2151
-                $ticket_row,
2152
-                null,
2153
-                $ticket,
2154
-                array(),
2155
-                true
2156
-            );
2157
-            $ticket_row++;
2158
-        }
2159
-        $datetime_row = 1;
2160
-        foreach ($all_datetimes as $datetime) {
2161
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2162
-                $datetime_row,
2163
-                'TICKETNUM',
2164
-                $datetime,
2165
-                null,
2166
-                array(),
2167
-                true
2168
-            );
2169
-            $datetime_row++;
2170
-        }
2171
-        /** @var EEM_Price $price_model */
2172
-        $price_model = EE_Registry::instance()->load_model('Price');
2173
-        $default_prices = $price_model->get_all_default_prices();
2174
-        $price_row = 1;
2175
-        foreach ($default_prices as $price) {
2176
-            if (! $price instanceof EE_Price) {
2177
-                continue;
2178
-            }
2179
-            if ($price->is_base_price()) {
2180
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2181
-                    'PRC_amount',
2182
-                    'localized_float'
2183
-                );
2184
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2185
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2186
-                $price_row++;
2187
-                continue;
2188
-            }
2189
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2190
-                             || count($default_prices) === 1);
2191
-            $show_create = ! (count($default_prices) > 1
2192
-                              && count($default_prices)
2193
-                                 !== $price_row);
2194
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2195
-                'TICKETNUM',
2196
-                $price_row,
2197
-                $price,
2198
-                true,
2199
-                null,
2200
-                $show_trash,
2201
-                $show_create
2202
-            );
2203
-            $price_row++;
2204
-        }
2205
-        $template_args = apply_filters(
2206
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2207
-            $template_args,
2208
-            $all_datetimes,
2209
-            $all_tickets,
2210
-            $this->_is_creating_event
2211
-        );
2212
-        return EEH_Template::display_template(
2213
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2214
-            $template_args,
2215
-            true
2216
-        );
2217
-    }
2077
+	/**
2078
+	 * @param array $all_datetimes
2079
+	 * @param array $all_tickets
2080
+	 * @return mixed
2081
+	 * @throws ReflectionException
2082
+	 * @throws InvalidArgumentException
2083
+	 * @throws InvalidInterfaceException
2084
+	 * @throws InvalidDataTypeException
2085
+	 * @throws DomainException
2086
+	 * @throws EE_Error
2087
+	 */
2088
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2089
+	{
2090
+		$template_args = array(
2091
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2092
+				'DTTNUM',
2093
+				null,
2094
+				true,
2095
+				$all_datetimes
2096
+			),
2097
+			'default_ticket_row'                       => $this->_get_ticket_row(
2098
+				'TICKETNUM',
2099
+				null,
2100
+				array(),
2101
+				array(),
2102
+				true
2103
+			),
2104
+			'default_price_row'                        => $this->_get_ticket_price_row(
2105
+				'TICKETNUM',
2106
+				'PRICENUM',
2107
+				null,
2108
+				true,
2109
+				null
2110
+			),
2111
+			'default_price_rows'                       => '',
2112
+			'default_base_price_amount'                => 0,
2113
+			'default_base_price_name'                  => '',
2114
+			'default_base_price_description'           => '',
2115
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2116
+				'TICKETNUM',
2117
+				'PRICENUM',
2118
+				null,
2119
+				true
2120
+			),
2121
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2122
+				'DTTNUM',
2123
+				null,
2124
+				array(),
2125
+				array(),
2126
+				true
2127
+			),
2128
+			'existing_available_datetime_tickets_list' => '',
2129
+			'existing_available_ticket_datetimes_list' => '',
2130
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2131
+				'DTTNUM',
2132
+				'TICKETNUM',
2133
+				null,
2134
+				null,
2135
+				array(),
2136
+				true
2137
+			),
2138
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2139
+				'DTTNUM',
2140
+				'TICKETNUM',
2141
+				null,
2142
+				null,
2143
+				array(),
2144
+				true
2145
+			),
2146
+		);
2147
+		$ticket_row = 1;
2148
+		foreach ($all_tickets as $ticket) {
2149
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2150
+				'DTTNUM',
2151
+				$ticket_row,
2152
+				null,
2153
+				$ticket,
2154
+				array(),
2155
+				true
2156
+			);
2157
+			$ticket_row++;
2158
+		}
2159
+		$datetime_row = 1;
2160
+		foreach ($all_datetimes as $datetime) {
2161
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2162
+				$datetime_row,
2163
+				'TICKETNUM',
2164
+				$datetime,
2165
+				null,
2166
+				array(),
2167
+				true
2168
+			);
2169
+			$datetime_row++;
2170
+		}
2171
+		/** @var EEM_Price $price_model */
2172
+		$price_model = EE_Registry::instance()->load_model('Price');
2173
+		$default_prices = $price_model->get_all_default_prices();
2174
+		$price_row = 1;
2175
+		foreach ($default_prices as $price) {
2176
+			if (! $price instanceof EE_Price) {
2177
+				continue;
2178
+			}
2179
+			if ($price->is_base_price()) {
2180
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2181
+					'PRC_amount',
2182
+					'localized_float'
2183
+				);
2184
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2185
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2186
+				$price_row++;
2187
+				continue;
2188
+			}
2189
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2190
+							 || count($default_prices) === 1);
2191
+			$show_create = ! (count($default_prices) > 1
2192
+							  && count($default_prices)
2193
+								 !== $price_row);
2194
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2195
+				'TICKETNUM',
2196
+				$price_row,
2197
+				$price,
2198
+				true,
2199
+				null,
2200
+				$show_trash,
2201
+				$show_create
2202
+			);
2203
+			$price_row++;
2204
+		}
2205
+		$template_args = apply_filters(
2206
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2207
+			$template_args,
2208
+			$all_datetimes,
2209
+			$all_tickets,
2210
+			$this->_is_creating_event
2211
+		);
2212
+		return EEH_Template::display_template(
2213
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2214
+			$template_args,
2215
+			true
2216
+		);
2217
+	}
2218 2218
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.36.rc.002');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.36.rc.002');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.