Completed
Branch FET-10304-welcome-to-vue (5b2425)
by
unknown
25:35 queued 13:40
created
core/db_classes/EE_Datetime.class.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 * increments reserved by amount passed by $qty
254 254
 	 *
255 255
 	 * @param int $qty
256
-	 * @return boolean
256
+	 * @return boolean|null
257 257
 	 */
258 258
 	public function increase_reserved( $qty = 1 ) {
259 259
 		$reserved = $this->reserved() + absint( $qty );
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 	 * decrements (subtracts) reserved by amount passed by $qty
267 267
 	 *
268 268
 	 * @param int $qty
269
-	 * @return boolean
269
+	 * @return boolean|null
270 270
 	 */
271 271
 	public function decrease_reserved( $qty = 1 ) {
272 272
 		$reserved = $this->reserved() - absint( $qty );
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 	 * @param string $dt_frmt     - string representation of date format defaults to WP settings
412 412
 	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with
413 413
 	 *                            the end date ie: Jan 01 "to" Dec 31
414
-	 * @return mixed        string on success, FALSE on fail
414
+	 * @return string        string on success, FALSE on fail
415 415
 	 * @throws \EE_Error
416 416
 	 */
417 417
 	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 	 * @param string $tm_format   string representation of time format defaults to 'g:i a'
484 484
 	 * @param string $conjunction conjunction junction what's your function ?
485 485
 	 *                            this string joins the start date with the end date ie: Jan 01 "to" Dec 31
486
-	 * @return mixed              string on success, FALSE on fail
486
+	 * @return string              string on success, FALSE on fail
487 487
 	 * @throws \EE_Error
488 488
 	 */
489 489
 	public function time_range( $tm_format = '', $conjunction = ' - ' ) {
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -358,13 +358,13 @@  discard block
 block discarded – undo
358 358
 
359 359
 
360 360
 
361
-    /**
362
-     * get event start date.  Provide either the date format, or NULL to re-use the
363
-     * last-used format, or '' to use the default date format
364
-     *
365
-     * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
366
-     * @return        mixed        string on success, FALSE on fail
367
-     */
361
+	/**
362
+	 * get event start date.  Provide either the date format, or NULL to re-use the
363
+	 * last-used format, or '' to use the default date format
364
+	 *
365
+	 * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
366
+	 * @return        mixed        string on success, FALSE on fail
367
+	 */
368 368
 	public function start_date( $dt_frmt = '' ) {
369 369
 		return $this->_show_datetime( 'D', 'start', $dt_frmt );
370 370
 	}
@@ -381,13 +381,13 @@  discard block
 block discarded – undo
381 381
 
382 382
 
383 383
 
384
-    /**
385
-     * get end date. Provide either the date format, or NULL to re-use the
386
-     * last-used format, or '' to use the default date format
387
-     *
388
-     * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
389
-     * @return        mixed        string on success, FALSE on fail
390
-     */
384
+	/**
385
+	 * get end date. Provide either the date format, or NULL to re-use the
386
+	 * last-used format, or '' to use the default date format
387
+	 *
388
+	 * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
389
+	 * @return        mixed        string on success, FALSE on fail
390
+	 */
391 391
 	public function end_date( $dt_frmt = '' ) {
392 392
 		return $this->_show_datetime( 'D', 'end', $dt_frmt );
393 393
 	}
@@ -531,14 +531,14 @@  discard block
 block discarded – undo
531 531
 			//start and end date are the same but times are different
532 532
 			case ( $this->start_date() === $this->end_date() ) :
533 533
 				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format )
534
-				          . $conjunction
535
-				          . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format );
534
+						  . $conjunction
535
+						  . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format );
536 536
 				break;
537 537
 			//all other conditions
538 538
 			default :
539 539
 				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format )
540
-				          . $conjunction
541
-				          . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format );
540
+						  . $conjunction
541
+						  . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format );
542 542
 				break;
543 543
 		}
544 544
 		return $output;
@@ -622,13 +622,13 @@  discard block
 block discarded – undo
622 622
 
623 623
 
624 624
 	/**
625
-     *        get end date and time
626
-     *
627
-     * @param string $dt_frmt   - string representation of date format defaults to 'F j, Y'
628
-     * @param string $tm_format - string representation of time format defaults to 'g:i a'
629
-     * @return    mixed                string on success, FALSE on fail
630
-     */
631
-    public function end_date_and_time($dt_frmt = '', $tm_format = '') {
625
+	 *        get end date and time
626
+	 *
627
+	 * @param string $dt_frmt   - string representation of date format defaults to 'F j, Y'
628
+	 * @param string $tm_format - string representation of time format defaults to 'g:i a'
629
+	 * @return    mixed                string on success, FALSE on fail
630
+	 */
631
+	public function end_date_and_time($dt_frmt = '', $tm_format = '') {
632 632
 		return $this->_show_datetime( '', 'end', $dt_frmt, $tm_format );
633 633
 	}
634 634
 
Please login to merge, or discard this patch.
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
 	 *                             		    date_format and the second value is the time format
75 75
 	 * @return EE_Datetime
76 76
 	 */
77
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
78
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
79
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
77
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
78
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
79
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
80 80
 	}
81 81
 
82 82
 
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 	 *                          		the website will be used.
88 88
 	 * @return EE_Datetime
89 89
 	 */
90
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
91
-		return new self( $props_n_values, TRUE, $timezone );
90
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
91
+		return new self($props_n_values, TRUE, $timezone);
92 92
 	}
93 93
 
94 94
 
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 	/**
97 97
 	 * @param $name
98 98
 	 */
99
-	public function set_name( $name ) {
100
-		$this->set( 'DTT_name', $name );
99
+	public function set_name($name) {
100
+		$this->set('DTT_name', $name);
101 101
 	}
102 102
 
103 103
 
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	/**
106 106
 	 * @param $description
107 107
 	 */
108
-	public function set_description( $description ) {
109
-		$this->set( 'DTT_description', $description );
108
+	public function set_description($description) {
109
+		$this->set('DTT_description', $description);
110 110
 	}
111 111
 
112 112
 
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @param        string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
120 120
 	 */
121
-	public function set_start_date( $date ) {
122
-		$this->_set_date_for( $date, 'DTT_EVT_start' );
121
+	public function set_start_date($date) {
122
+		$this->_set_date_for($date, 'DTT_EVT_start');
123 123
 	}
124 124
 
125 125
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @param        string $time a string representation of the event time ex:  9am  or  7:30 PM
133 133
 	 */
134
-	public function set_start_time( $time ) {
135
-		$this->_set_time_for( $time, 'DTT_EVT_start' );
134
+	public function set_start_time($time) {
135
+		$this->_set_time_for($time, 'DTT_EVT_start');
136 136
 	}
137 137
 
138 138
 
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	 *
145 145
 	 * @param        string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
146 146
 	 */
147
-	public function set_end_date( $date ) {
148
-		$this->_set_date_for( $date, 'DTT_EVT_end' );
147
+	public function set_end_date($date) {
148
+		$this->_set_date_for($date, 'DTT_EVT_end');
149 149
 	}
150 150
 
151 151
 
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @param        string $time a string representation of the event time ex:  9am  or  7:30 PM
159 159
 	 */
160
-	public function set_end_time( $time ) {
161
-		$this->_set_time_for( $time, 'DTT_EVT_end' );
160
+	public function set_end_time($time) {
161
+		$this->_set_time_for($time, 'DTT_EVT_end');
162 162
 	}
163 163
 
164 164
 
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @param        int $reg_limit
172 172
 	 */
173
-	public function set_reg_limit( $reg_limit ) {
174
-		$this->set( 'DTT_reg_limit', $reg_limit );
173
+	public function set_reg_limit($reg_limit) {
174
+		$this->set('DTT_reg_limit', $reg_limit);
175 175
 	}
176 176
 
177 177
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * @return        mixed        int on success, FALSE on fail
184 184
 	 */
185 185
 	public function sold() {
186
-		return $this->get_raw( 'DTT_sold' );
186
+		return $this->get_raw('DTT_sold');
187 187
 	}
188 188
 
189 189
 
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
 	 *
194 194
 	 * @param        int $sold
195 195
 	 */
196
-	public function set_sold( $sold ) {
196
+	public function set_sold($sold) {
197 197
 		// sold can not go below zero
198
-		$sold = max( 0, $sold );
199
-		$this->set( 'DTT_sold', $sold );
198
+		$sold = max(0, $sold);
199
+		$this->set('DTT_sold', $sold);
200 200
 	}
201 201
 
202 202
 
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
 	 * increments sold by amount passed by $qty
206 206
 	 * @param int $qty
207 207
 	 */
208
-	public function increase_sold( $qty = 1 ) {
208
+	public function increase_sold($qty = 1) {
209 209
 		$sold = $this->sold() + $qty;
210 210
 		// remove ticket reservation
211
-		$this->decrease_reserved( $qty );
212
-		$this->set_sold( $sold );
211
+		$this->decrease_reserved($qty);
212
+		$this->set_sold($sold);
213 213
 	}
214 214
 
215 215
 
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
 	 * decrements (subtracts) sold amount passed by $qty
219 219
 	 * @param int $qty
220 220
 	 */
221
-	public function decrease_sold( $qty = 1 ) {
221
+	public function decrease_sold($qty = 1) {
222 222
 		$sold = $this->sold() - $qty;
223
-		$this->set_sold( $sold );
223
+		$this->set_sold($sold);
224 224
 	}
225 225
 
226 226
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	 * @return int
232 232
 	 */
233 233
 	public function reserved() {
234
-		return $this->get_raw( 'DTT_reserved' );
234
+		return $this->get_raw('DTT_reserved');
235 235
 	}
236 236
 
237 237
 
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 	 *
242 242
 	 * @param int $reserved
243 243
 	 */
244
-	public function set_reserved( $reserved ) {
244
+	public function set_reserved($reserved) {
245 245
 		// reserved can not go below zero
246
-		$reserved = max( 0, (int) $reserved );
247
-		$this->set( 'DTT_reserved', $reserved );
246
+		$reserved = max(0, (int) $reserved);
247
+		$this->set('DTT_reserved', $reserved);
248 248
 	}
249 249
 
250 250
 
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 	 * @param int $qty
256 256
 	 * @return boolean
257 257
 	 */
258
-	public function increase_reserved( $qty = 1 ) {
259
-		$reserved = $this->reserved() + absint( $qty );
260
-		return $this->set_reserved( $reserved );
258
+	public function increase_reserved($qty = 1) {
259
+		$reserved = $this->reserved() + absint($qty);
260
+		return $this->set_reserved($reserved);
261 261
 	}
262 262
 
263 263
 
@@ -268,9 +268,9 @@  discard block
 block discarded – undo
268 268
 	 * @param int $qty
269 269
 	 * @return boolean
270 270
 	 */
271
-	public function decrease_reserved( $qty = 1 ) {
272
-		$reserved = $this->reserved() - absint( $qty );
273
-		return $this->set_reserved( $reserved );
271
+	public function decrease_reserved($qty = 1) {
272
+		$reserved = $this->reserved() - absint($qty);
273
+		return $this->set_reserved($reserved);
274 274
 	}
275 275
 
276 276
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 * @return string
292 292
 	 */
293 293
 	public function name() {
294
-		return $this->get( 'DTT_name' );
294
+		return $this->get('DTT_name');
295 295
 	}
296 296
 
297 297
 
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 	 * @return string
302 302
 	 */
303 303
 	public function description() {
304
-		return $this->get( 'DTT_description' );
304
+		return $this->get('DTT_description');
305 305
 	}
306 306
 
307 307
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * @return boolean          TRUE if is primary, FALSE if not.
312 312
 	 */
313 313
 	public function is_primary() {
314
-		return $this->get( 'DTT_is_primary' );
314
+		return $this->get('DTT_is_primary');
315 315
 	}
316 316
 
317 317
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	 * @return int         The order of the datetime for this event.
322 322
 	 */
323 323
 	public function order() {
324
-		return $this->get( 'DTT_order' );
324
+		return $this->get('DTT_order');
325 325
 	}
326 326
 
327 327
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	 * @return int
332 332
 	 */
333 333
 	public function parent() {
334
-		return $this->get( 'DTT_parent' );
334
+		return $this->get('DTT_parent');
335 335
 	}
336 336
 
337 337
 
@@ -347,10 +347,10 @@  discard block
 block discarded – undo
347 347
 	 * @param    bool   $echo         - whether we echo or return (note echoing uses "pretty" formats, otherwise we use the standard formats)
348 348
 	 * @return    string|bool  string on success, FALSE on fail
349 349
 	 */
350
-	private function _show_datetime( $date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE ) {
350
+	private function _show_datetime($date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE) {
351 351
 		$field_name = "DTT_EVT_{$start_or_end}";
352
-		$dtt = $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo );
353
-		if ( ! $echo ) {
352
+		$dtt = $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo);
353
+		if ( ! $echo) {
354 354
 			return $dtt;
355 355
 		}
356 356
 		return '';
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
      * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
366 366
      * @return        mixed        string on success, FALSE on fail
367 367
      */
368
-	public function start_date( $dt_frmt = '' ) {
369
-		return $this->_show_datetime( 'D', 'start', $dt_frmt );
368
+	public function start_date($dt_frmt = '') {
369
+		return $this->_show_datetime('D', 'start', $dt_frmt);
370 370
 	}
371 371
 
372 372
 
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * Echoes start_date()
376 376
 	 * @param string $dt_frmt
377 377
 	 */
378
-	public function e_start_date( $dt_frmt = '' ) {
379
-		$this->_show_datetime( 'D', 'start', $dt_frmt, NULL, TRUE );
378
+	public function e_start_date($dt_frmt = '') {
379
+		$this->_show_datetime('D', 'start', $dt_frmt, NULL, TRUE);
380 380
 	}
381 381
 
382 382
 
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
      * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
389 389
      * @return        mixed        string on success, FALSE on fail
390 390
      */
391
-	public function end_date( $dt_frmt = '' ) {
392
-		return $this->_show_datetime( 'D', 'end', $dt_frmt );
391
+	public function end_date($dt_frmt = '') {
392
+		return $this->_show_datetime('D', 'end', $dt_frmt);
393 393
 	}
394 394
 
395 395
 
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 	 * Echoes the end date. See end_date()
399 399
 	 * @param string $dt_frmt
400 400
 	 */
401
-	public function e_end_date( $dt_frmt = '' ) {
402
-		$this->_show_datetime( 'D', 'end', $dt_frmt, NULL, TRUE );
401
+	public function e_end_date($dt_frmt = '') {
402
+		$this->_show_datetime('D', 'end', $dt_frmt, NULL, TRUE);
403 403
 	}
404 404
 
405 405
 
@@ -414,11 +414,11 @@  discard block
 block discarded – undo
414 414
 	 * @return mixed        string on success, FALSE on fail
415 415
 	 * @throws \EE_Error
416 416
 	 */
417
-	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
418
-		$dt_frmt = ! empty( $dt_frmt ) ? $dt_frmt : $this->_dt_frmt;
419
-		$start = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_start', $dt_frmt ) );
420
-		$end = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_end', $dt_frmt ) );
421
-		return $start !== $end ? $start . $conjunction . $end : $start;
417
+	public function date_range($dt_frmt = '', $conjunction = ' - ') {
418
+		$dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt;
419
+		$start = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt));
420
+		$end = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt));
421
+		return $start !== $end ? $start.$conjunction.$end : $start;
422 422
 	}
423 423
 
424 424
 
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
 	 * @param string $conjunction
429 429
 	 * @throws \EE_Error
430 430
 	 */
431
-	public function e_date_range( $dt_frmt = '', $conjunction = ' - ' ) {
432
-		echo $this->date_range( $dt_frmt, $conjunction );
431
+	public function e_date_range($dt_frmt = '', $conjunction = ' - ') {
432
+		echo $this->date_range($dt_frmt, $conjunction);
433 433
 	}
434 434
 
435 435
 
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 	 * @param string $tm_format - string representation of time format defaults to 'g:i a'
441 441
 	 * @return mixed        string on success, FALSE on fail
442 442
 	 */
443
-	public function start_time( $tm_format = '' ) {
444
-		return $this->_show_datetime( 'T', 'start', NULL, $tm_format );
443
+	public function start_time($tm_format = '') {
444
+		return $this->_show_datetime('T', 'start', NULL, $tm_format);
445 445
 	}
446 446
 
447 447
 
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
 	/**
450 450
 	 * @param string $tm_format
451 451
 	 */
452
-	public function e_start_time( $tm_format = '' ) {
453
-		$this->_show_datetime( 'T', 'start', NULL, $tm_format, TRUE );
452
+	public function e_start_time($tm_format = '') {
453
+		$this->_show_datetime('T', 'start', NULL, $tm_format, TRUE);
454 454
 	}
455 455
 
456 456
 
@@ -461,8 +461,8 @@  discard block
 block discarded – undo
461 461
 	 * @param string $tm_format - string representation of time format defaults to 'g:i a'
462 462
 	 * @return mixed        string on success, FALSE on fail
463 463
 	 */
464
-	public function end_time( $tm_format = '' ) {
465
-		return $this->_show_datetime( 'T', 'end', NULL, $tm_format );
464
+	public function end_time($tm_format = '') {
465
+		return $this->_show_datetime('T', 'end', NULL, $tm_format);
466 466
 	}
467 467
 
468 468
 
@@ -470,8 +470,8 @@  discard block
 block discarded – undo
470 470
 	/**
471 471
 	 * @param string $tm_format
472 472
 	 */
473
-	public function e_end_time( $tm_format = '' ) {
474
-		$this->_show_datetime( 'T', 'end', NULL, $tm_format, TRUE );
473
+	public function e_end_time($tm_format = '') {
474
+		$this->_show_datetime('T', 'end', NULL, $tm_format, TRUE);
475 475
 	}
476 476
 
477 477
 
@@ -486,11 +486,11 @@  discard block
 block discarded – undo
486 486
 	 * @return mixed              string on success, FALSE on fail
487 487
 	 * @throws \EE_Error
488 488
 	 */
489
-	public function time_range( $tm_format = '', $conjunction = ' - ' ) {
490
-		$tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt;
491
-		$start = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_start', $tm_format ) );
492
-		$end = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_end',  $tm_format ) );
493
-		return $start !== $end ? $start . $conjunction . $end : $start;
489
+	public function time_range($tm_format = '', $conjunction = ' - ') {
490
+		$tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt;
491
+		$start = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_start', $tm_format));
492
+		$end = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_end', $tm_format));
493
+		return $start !== $end ? $start.$conjunction.$end : $start;
494 494
 	}
495 495
 
496 496
 
@@ -500,8 +500,8 @@  discard block
 block discarded – undo
500 500
 	 * @param string $conjunction
501 501
 	 * @throws \EE_Error
502 502
 	 */
503
-	public function e_time_range( $tm_format = '', $conjunction = ' - ' ) {
504
-		echo $this->time_range( $tm_format, $conjunction );
503
+	public function e_time_range($tm_format = '', $conjunction = ' - ') {
504
+		echo $this->time_range($tm_format, $conjunction);
505 505
 	}
506 506
 
507 507
 
@@ -517,28 +517,28 @@  discard block
 block discarded – undo
517 517
 	 * @return string
518 518
 	 * @throws \EE_Error
519 519
 	 */
520
-	public function date_and_time_range( $dt_format = '', $tm_format = '', $conjunction = ' - '  ) {
520
+	public function date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ') {
521 521
 		$dt_format = $dt_format !== '' ? $dt_format : $this->_dt_frmt;
522 522
 		$tm_format = $tm_format !== '' ? $tm_format : $this->_tm_frmt;
523
-		$full_format = $dt_format . ' ' . $tm_format;
523
+		$full_format = $dt_format.' '.$tm_format;
524 524
 
525 525
 		//the range output depends on various conditions
526
-		switch ( true ) {
526
+		switch (true) {
527 527
 			//start date timestamp and end date timestamp are the same.
528
-			case ( $this->get_raw( 'DTT_EVT_start' ) === $this->get_raw( 'DTT_EVT_end' ) ) :
529
-				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format );
528
+			case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')) :
529
+				$output = $this->get_i18n_datetime('DTT_EVT_start', $full_format);
530 530
 				break;
531 531
 			//start and end date are the same but times are different
532
-			case ( $this->start_date() === $this->end_date() ) :
533
-				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format )
532
+			case ($this->start_date() === $this->end_date()) :
533
+				$output = $this->get_i18n_datetime('DTT_EVT_start', $full_format)
534 534
 				          . $conjunction
535
-				          . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format );
535
+				          . $this->get_i18n_datetime('DTT_EVT_end', $tm_format);
536 536
 				break;
537 537
 			//all other conditions
538 538
 			default :
539
-				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format )
539
+				$output = $this->get_i18n_datetime('DTT_EVT_start', $full_format)
540 540
 				          . $conjunction
541
-				          . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format );
541
+				          . $this->get_i18n_datetime('DTT_EVT_end', $full_format);
542 542
 				break;
543 543
 		}
544 544
 		return $output;
@@ -556,8 +556,8 @@  discard block
 block discarded – undo
556 556
 	 * @return void
557 557
 	 * @throws \EE_Error
558 558
 	 */
559
-	public function e_date_and_time_range( $dt_format = '', $tm_format = '', $conjunction = ' - ' ) {
560
-		echo $this->date_and_time_range( $dt_format, $tm_format, $conjunction );
559
+	public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ') {
560
+		echo $this->date_and_time_range($dt_format, $tm_format, $conjunction);
561 561
 	}
562 562
 
563 563
 
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
 	 * @param 	string 	$tm_format - string representation of time format defaults to 'g:i a'
570 570
 	 * @return 	mixed 	string on success, FALSE on fail
571 571
 	 */
572
-	public function start_date_and_time( $dt_format = '', $tm_format = '' ) {
573
-		return $this->_show_datetime( '', 'start', $dt_format, $tm_format );
572
+	public function start_date_and_time($dt_format = '', $tm_format = '') {
573
+		return $this->_show_datetime('', 'start', $dt_format, $tm_format);
574 574
 	}
575 575
 
576 576
 
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
 	 * @param string $dt_frmt
580 580
 	 * @param string $tm_format
581 581
 	 */
582
-	public function e_start_date_and_time( $dt_frmt = '', $tm_format = '' ) {
583
-		$this->_show_datetime( '', 'start', $dt_frmt, $tm_format, TRUE );
582
+	public function e_start_date_and_time($dt_frmt = '', $tm_format = '') {
583
+		$this->_show_datetime('', 'start', $dt_frmt, $tm_format, TRUE);
584 584
 	}
585 585
 
586 586
 
@@ -594,11 +594,11 @@  discard block
 block discarded – undo
594 594
 	 * @param bool   $round_up
595 595
 	 * @return float|int|mixed
596 596
 	 */
597
-	public function length( $units = 'seconds', $round_up = FALSE ) {
598
-		$start = $this->get_raw( 'DTT_EVT_start' );
599
-		$end = $this->get_raw( 'DTT_EVT_end' );
597
+	public function length($units = 'seconds', $round_up = FALSE) {
598
+		$start = $this->get_raw('DTT_EVT_start');
599
+		$end = $this->get_raw('DTT_EVT_end');
600 600
 		$length_in_units = $end - $start;
601
-		switch ( $units ) {
601
+		switch ($units) {
602 602
 			//NOTE: We purposefully don't use "break;" in order to chain the divisions
603 603
 			/** @noinspection PhpMissingBreakStatementInspection */
604 604
 			case 'days':
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 				$length_in_units /= 60;
612 612
 			case 'seconds':
613 613
 			default:
614
-				$length_in_units = ceil( $length_in_units );
614
+				$length_in_units = ceil($length_in_units);
615 615
 		}
616
-		if ( $round_up ) {
617
-			$length_in_units = max( $length_in_units, 1 );
616
+		if ($round_up) {
617
+			$length_in_units = max($length_in_units, 1);
618 618
 		}
619 619
 		return $length_in_units;
620 620
 	}
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
      * @return    mixed                string on success, FALSE on fail
630 630
      */
631 631
     public function end_date_and_time($dt_frmt = '', $tm_format = '') {
632
-		return $this->_show_datetime( '', 'end', $dt_frmt, $tm_format );
632
+		return $this->_show_datetime('', 'end', $dt_frmt, $tm_format);
633 633
 	}
634 634
 
635 635
 
@@ -638,8 +638,8 @@  discard block
 block discarded – undo
638 638
 	 * @param string $dt_frmt
639 639
 	 * @param string $tm_format
640 640
 	 */
641
-	public function e_end_date_and_time( $dt_frmt = '', $tm_format = '' ) {
642
-		$this->_show_datetime( '', 'end', $dt_frmt, $tm_format, TRUE );
641
+	public function e_end_date_and_time($dt_frmt = '', $tm_format = '') {
642
+		$this->_show_datetime('', 'end', $dt_frmt, $tm_format, TRUE);
643 643
 	}
644 644
 
645 645
 
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 	 * @return        int
651 651
 	 */
652 652
 	public function start() {
653
-		return $this->get_raw( 'DTT_EVT_start' );
653
+		return $this->get_raw('DTT_EVT_start');
654 654
 	}
655 655
 
656 656
 
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
 	 * @return        int
662 662
 	 */
663 663
 	public function end() {
664
-		return $this->get_raw( 'DTT_EVT_end' );
664
+		return $this->get_raw('DTT_EVT_end');
665 665
 	}
666 666
 
667 667
 
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 	 * @return        mixed        int on success, FALSE on fail
673 673
 	 */
674 674
 	public function reg_limit() {
675
-		return $this->get_raw( 'DTT_reg_limit' );
675
+		return $this->get_raw('DTT_reg_limit');
676 676
 	}
677 677
 
678 678
 
@@ -700,15 +700,15 @@  discard block
 block discarded – undo
700 700
 	 * 																	the spaces remaining for this particular datetime, hence the flag.
701 701
 	 * @return 	int
702 702
 	 */
703
-	public function spaces_remaining( $consider_tickets = FALSE ) {
703
+	public function spaces_remaining($consider_tickets = FALSE) {
704 704
 		// tickets remaining available for purchase
705 705
 		//no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF
706 706
 		$dtt_remaining = $this->reg_limit() - $this->sold();
707
-		if ( ! $consider_tickets ) {
707
+		if ( ! $consider_tickets) {
708 708
 			return $dtt_remaining;
709 709
 		}
710 710
 		$tickets_remaining = $this->tickets_remaining();
711
-		return min( $dtt_remaining, $tickets_remaining );
711
+		return min($dtt_remaining, $tickets_remaining);
712 712
 	}
713 713
 
714 714
 
@@ -719,19 +719,19 @@  discard block
 block discarded – undo
719 719
 	 * @param array $query_params like EEM_Base::get_all's
720 720
 	 * @return int
721 721
 	 */
722
-	public function tickets_remaining( $query_params = array() ) {
722
+	public function tickets_remaining($query_params = array()) {
723 723
 		$sum = 0;
724
-		$tickets = $this->tickets( $query_params );
725
-		if ( ! empty( $tickets ) ) {
726
-			foreach ( $tickets as $ticket ) {
727
-				if ( $ticket instanceof EE_Ticket ) {
724
+		$tickets = $this->tickets($query_params);
725
+		if ( ! empty($tickets)) {
726
+			foreach ($tickets as $ticket) {
727
+				if ($ticket instanceof EE_Ticket) {
728 728
 					// get the actual amount of tickets that can be sold
729
-					$qty = $ticket->qty( 'saleable' );
730
-					if ( $qty === EE_INF ) {
729
+					$qty = $ticket->qty('saleable');
730
+					if ($qty === EE_INF) {
731 731
 						return EE_INF;
732 732
 					}
733 733
 					// no negative ticket quantities plz
734
-					if ( $qty > 0 ) {
734
+					if ($qty > 0) {
735 735
 						$sum += $qty;
736 736
 					}
737 737
 				}
@@ -748,8 +748,8 @@  discard block
 block discarded – undo
748 748
 	 * @param array $query_params like EEM_Base::get_all's
749 749
 	 * @return int
750 750
 	 */
751
-	public function sum_tickets_initially_available( $query_params = array() ) {
752
-		return $this->sum_related( 'Ticket', $query_params, 'TKT_qty' );
751
+	public function sum_tickets_initially_available($query_params = array()) {
752
+		return $this->sum_related('Ticket', $query_params, 'TKT_qty');
753 753
 	}
754 754
 
755 755
 
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 	 * @return int
762 762
 	 */
763 763
 	public function total_tickets_available_at_this_datetime() {
764
-		return $this->spaces_remaining( true );
764
+		return $this->spaces_remaining(true);
765 765
 	}
766 766
 
767 767
 
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 	 * @return boolean
773 773
 	 */
774 774
 	public function is_upcoming() {
775
-		return ( $this->get_raw( 'DTT_EVT_start' ) > time() );
775
+		return ($this->get_raw('DTT_EVT_start') > time());
776 776
 	}
777 777
 
778 778
 
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 	 * @return boolean
783 783
 	 */
784 784
 	public function is_active() {
785
-		return ( $this->get_raw( 'DTT_EVT_start' ) < time() && $this->get_raw( 'DTT_EVT_end' ) > time() );
785
+		return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time());
786 786
 	}
787 787
 
788 788
 
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 	 * @return boolean
793 793
 	 */
794 794
 	public function is_expired() {
795
-		return ( $this->get_raw( 'DTT_EVT_end' ) < time() );
795
+		return ($this->get_raw('DTT_EVT_end') < time());
796 796
 	}
797 797
 
798 798
 
@@ -803,16 +803,16 @@  discard block
 block discarded – undo
803 803
 	 */
804 804
 	public function get_active_status() {
805 805
 		$total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime();
806
-		if ( $total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1 ) {
806
+		if ($total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1) {
807 807
 			return EE_Datetime::sold_out;
808 808
 		}
809
-		if ( $this->is_expired() ) {
809
+		if ($this->is_expired()) {
810 810
 			return EE_Datetime::expired;
811 811
 		}
812
-		if ( $this->is_upcoming() ) {
812
+		if ($this->is_upcoming()) {
813 813
 			return EE_Datetime::upcoming;
814 814
 		}
815
-		if ( $this->is_active() ) {
815
+		if ($this->is_active()) {
816 816
 			return EE_Datetime::active;
817 817
 		}
818 818
 		return NULL;
@@ -826,24 +826,24 @@  discard block
 block discarded – undo
826 826
 	 * @param  boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty.
827 827
 	 * @return string
828 828
 	 */
829
-	public function get_dtt_display_name( $use_dtt_name = FALSE ) {
830
-		if ( $use_dtt_name ) {
829
+	public function get_dtt_display_name($use_dtt_name = FALSE) {
830
+		if ($use_dtt_name) {
831 831
 			$dtt_name = $this->name();
832
-			if ( !empty( $dtt_name ) ) {
832
+			if ( ! empty($dtt_name)) {
833 833
 				return $dtt_name;
834 834
 			}
835 835
 		}
836 836
 		//first condition is to see if the months are different
837
-		if ( date( 'm', $this->get_raw( 'DTT_EVT_start' ) ) != date( 'm', $this->get_raw( 'DTT_EVT_end' ) ) ) {
838
-			$display_date = $this->start_date( 'M j\, Y g:i a' ) . ' - ' . $this->end_date( 'M j\, Y g:i a' );
837
+		if (date('m', $this->get_raw('DTT_EVT_start')) != date('m', $this->get_raw('DTT_EVT_end'))) {
838
+			$display_date = $this->start_date('M j\, Y g:i a').' - '.$this->end_date('M j\, Y g:i a');
839 839
 			//next condition is if its the same month but different day
840 840
 		}
841 841
 		else {
842
-			if ( date( 'm', $this->get_raw( 'DTT_EVT_start' ) ) == date( 'm', $this->get_raw( 'DTT_EVT_end' ) ) && date( 'd', $this->get_raw( 'DTT_EVT_start' ) ) != date( 'd', $this->get_raw( 'DTT_EVT_end' ) ) ) {
843
-				$display_date = $this->start_date( 'M j\, g:i a' ) . ' - ' . $this->end_date( 'M j\, g:i a Y' );
842
+			if (date('m', $this->get_raw('DTT_EVT_start')) == date('m', $this->get_raw('DTT_EVT_end')) && date('d', $this->get_raw('DTT_EVT_start')) != date('d', $this->get_raw('DTT_EVT_end'))) {
843
+				$display_date = $this->start_date('M j\, g:i a').' - '.$this->end_date('M j\, g:i a Y');
844 844
 			}
845 845
 			else {
846
-				$display_date = $this->start_date( 'F j\, Y' ) . ' @ ' . $this->start_date( 'g:i a' ) . ' - ' . $this->end_date( 'g:i a' );
846
+				$display_date = $this->start_date('F j\, Y').' @ '.$this->start_date('g:i a').' - '.$this->end_date('g:i a');
847 847
 			}
848 848
 		}
849 849
 		return $display_date;
@@ -857,8 +857,8 @@  discard block
 block discarded – undo
857 857
 *@param array $query_params see EEM_Base::get_all()
858 858
 	 * @return EE_Ticket[]
859 859
 	 */
860
-	public function tickets( $query_params = array() ) {
861
-		return $this->get_many_related( 'Ticket', $query_params );
860
+	public function tickets($query_params = array()) {
861
+		return $this->get_many_related('Ticket', $query_params);
862 862
 	}
863 863
 
864 864
 
@@ -868,21 +868,21 @@  discard block
 block discarded – undo
868 868
 	 * @param array $query_params like EEM_Base::get_all's
869 869
 	 * @return EE_Ticket[]
870 870
 	 */
871
-	public function ticket_types_available_for_purchase( $query_params = array() ) {
871
+	public function ticket_types_available_for_purchase($query_params = array()) {
872 872
 		// first check if datetime is valid
873
-		if ( ! ( $this->is_upcoming() || $this->is_active() ) || $this->sold_out() ) {
873
+		if ( ! ($this->is_upcoming() || $this->is_active()) || $this->sold_out()) {
874 874
 			return array();
875 875
 		}
876
-		if ( empty( $query_params ) ) {
876
+		if (empty($query_params)) {
877 877
 			$query_params = array(
878 878
 				array(
879
-					'TKT_start_date' => array( '<=', EEM_Ticket::instance()->current_time_for_query( 'TKT_start_date' ) ),
880
-					'TKT_end_date'   => array( '>=', EEM_Ticket::instance()->current_time_for_query( 'TKT_end_date' ) ),
879
+					'TKT_start_date' => array('<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')),
880
+					'TKT_end_date'   => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
881 881
 					'TKT_deleted'    => false
882 882
 				)
883 883
 			);
884 884
 		}
885
-		return $this->tickets( $query_params );
885
+		return $this->tickets($query_params);
886 886
 	}
887 887
 
888 888
 
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
 	 * @return EE_Event
893 893
 	 */
894 894
 	public function event() {
895
-		return $this->get_first_related( 'Event' );
895
+		return $this->get_first_related('Event');
896 896
 	}
897 897
 
898 898
 
@@ -904,13 +904,13 @@  discard block
 block discarded – undo
904 904
 	 */
905 905
 	public function update_sold() {
906 906
 		$count_regs_for_this_datetime = EEM_Registration::instance()->count(
907
-			array( array(
907
+			array(array(
908 908
 				'STS_ID' 					=> EEM_Registration::status_id_approved,
909 909
 				'REG_deleted' 				=> 0,
910 910
 				'Ticket.Datetime.DTT_ID' 	=> $this->ID(),
911
-			) )
911
+			))
912 912
 		);
913
-		$this->set( 'DTT_sold', $count_regs_for_this_datetime );
913
+		$this->set('DTT_sold', $count_regs_for_this_datetime);
914 914
 		$this->save();
915 915
 		return $count_regs_for_this_datetime;
916 916
 	}
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket.class.php 2 patches
Indentation   +566 added lines, -566 removed lines patch added patch discarded remove patch
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * @param array  $props_n_values          incoming values
66
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
-     *                                        used.)
68
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
-     *                                        date_format and the second value is the time format
70
-     * @return EE_Ticket
71
-     * @throws \EE_Error
72
-     */
64
+	/**
65
+	 * @param array  $props_n_values          incoming values
66
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
+	 *                                        used.)
68
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
+	 *                                        date_format and the second value is the time format
70
+	 * @return EE_Ticket
71
+	 * @throws \EE_Error
72
+	 */
73 73
 	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
74 74
 		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
75 75
 		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
@@ -77,36 +77,36 @@  discard block
 block discarded – undo
77 77
 
78 78
 
79 79
 
80
-    /**
81
-     * @param array  $props_n_values  incoming values from the database
82
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
-     *                                the website will be used.
84
-     * @return EE_Ticket
85
-     * @throws \EE_Error
86
-     */
80
+	/**
81
+	 * @param array  $props_n_values  incoming values from the database
82
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
+	 *                                the website will be used.
84
+	 * @return EE_Ticket
85
+	 * @throws \EE_Error
86
+	 */
87 87
 	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
88 88
 		return new self( $props_n_values, TRUE, $timezone );
89 89
 	}
90 90
 
91 91
 
92 92
 
93
-    /**
94
-     * @return bool
95
-     * @throws \EE_Error
96
-     */
93
+	/**
94
+	 * @return bool
95
+	 * @throws \EE_Error
96
+	 */
97 97
 	public function parent() {
98 98
 		return $this->get( 'TKT_parent' );
99 99
 	}
100 100
 
101 101
 
102 102
 
103
-    /**
104
-     * return if a ticket has quantities available for purchase
105
-     *
106
-     * @param  int $DTT_ID the primary key for a particular datetime
107
-     * @return boolean
108
-     * @throws \EE_Error
109
-     */
103
+	/**
104
+	 * return if a ticket has quantities available for purchase
105
+	 *
106
+	 * @param  int $DTT_ID the primary key for a particular datetime
107
+	 * @return boolean
108
+	 * @throws \EE_Error
109
+	 */
110 110
 	public function available( $DTT_ID = 0 ) {
111 111
 		// are we checking availability for a particular datetime ?
112 112
 		if ( $DTT_ID ) {
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 
124 124
 
125 125
 
126
-    /**
127
-     * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
-     *
129
-     * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
-     * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
-     * @return mixed status int if the display string isn't requested
132
-     * @throws \EE_Error
133
-     */
126
+	/**
127
+	 * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
+	 *
129
+	 * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
+	 * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
+	 * @return mixed status int if the display string isn't requested
132
+	 * @throws \EE_Error
133
+	 */
134 134
 	public function ticket_status( $display = FALSE, $remaining = null ) {
135 135
 		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
136 136
 		if ( ! $remaining ) {
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 
154 154
 
155 155
 
156
-    /**
157
-     * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
-     *
159
-     * @access public
160
-     * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
-     * @return boolean         true = tickets remaining, false not.
162
-     * @throws \EE_Error
163
-     */
156
+	/**
157
+	 * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
+	 *
159
+	 * @access public
160
+	 * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
+	 * @return boolean         true = tickets remaining, false not.
162
+	 * @throws \EE_Error
163
+	 */
164 164
 	public function is_remaining( $DTT_ID = 0 ) {
165 165
 		$num_remaining = $this->remaining( $DTT_ID );
166 166
 		if ( $num_remaining === 0 ) {
@@ -174,76 +174,76 @@  discard block
 block discarded – undo
174 174
 
175 175
 
176 176
 
177
-    /**
178
-     * return the total number of tickets available for purchase
179
-     *
180
-     * @param  int $DTT_ID the primary key for a particular datetime.
181
-     *                     set to 0 for all related datetimes
182
-     * @return int
183
-     * @throws \EE_Error
184
-     */
177
+	/**
178
+	 * return the total number of tickets available for purchase
179
+	 *
180
+	 * @param  int $DTT_ID the primary key for a particular datetime.
181
+	 *                     set to 0 for all related datetimes
182
+	 * @return int
183
+	 * @throws \EE_Error
184
+	 */
185 185
 	public function remaining( $DTT_ID = 0 ) {
186 186
 		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
187 187
 	}
188 188
 
189 189
 
190 190
 
191
-    /**
192
-     * Gets min
193
-     *
194
-     * @return int
195
-     * @throws \EE_Error
196
-     */
191
+	/**
192
+	 * Gets min
193
+	 *
194
+	 * @return int
195
+	 * @throws \EE_Error
196
+	 */
197 197
 	public function min() {
198 198
 		return $this->get( 'TKT_min' );
199 199
 	}
200 200
 
201 201
 
202 202
 
203
-    /**
204
-     * return if a ticket is no longer available cause its available dates have expired.
205
-     *
206
-     * @return boolean
207
-     * @throws \EE_Error
208
-     */
203
+	/**
204
+	 * return if a ticket is no longer available cause its available dates have expired.
205
+	 *
206
+	 * @return boolean
207
+	 * @throws \EE_Error
208
+	 */
209 209
 	public function is_expired() {
210 210
 		return ( $this->get_raw( 'TKT_end_date' ) < time() );
211 211
 	}
212 212
 
213 213
 
214 214
 
215
-    /**
216
-     * Return if a ticket is yet to go on sale or not
217
-     *
218
-     * @return boolean
219
-     * @throws \EE_Error
220
-     */
215
+	/**
216
+	 * Return if a ticket is yet to go on sale or not
217
+	 *
218
+	 * @return boolean
219
+	 * @throws \EE_Error
220
+	 */
221 221
 	public function is_pending() {
222 222
 		return ( $this->get_raw( 'TKT_start_date' ) > time() );
223 223
 	}
224 224
 
225 225
 
226 226
 
227
-    /**
228
-     * Return if a ticket is on sale or not
229
-     *
230
-     * @return boolean
231
-     * @throws \EE_Error
232
-     */
227
+	/**
228
+	 * Return if a ticket is on sale or not
229
+	 *
230
+	 * @return boolean
231
+	 * @throws \EE_Error
232
+	 */
233 233
 	public function is_on_sale() {
234 234
 		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
235 235
 	}
236 236
 
237 237
 
238 238
 
239
-    /**
240
-     * This returns the chronologically last datetime that this ticket is associated with
241
-     *
242
-     * @param string $dt_frmt
243
-     * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
-     * @return string
245
-     * @throws \EE_Error
246
-     */
239
+	/**
240
+	 * This returns the chronologically last datetime that this ticket is associated with
241
+	 *
242
+	 * @param string $dt_frmt
243
+	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
+	 * @return string
245
+	 * @throws \EE_Error
246
+	 */
247 247
 	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
248 248
 		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
249 249
 		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
 
254 254
 
255 255
 
256
-    /**
257
-     * This returns the chronologically first datetime that this ticket is associated with
258
-     *
259
-     * @return EE_Datetime
260
-     * @throws \EE_Error
261
-     */
256
+	/**
257
+	 * This returns the chronologically first datetime that this ticket is associated with
258
+	 *
259
+	 * @return EE_Datetime
260
+	 * @throws \EE_Error
261
+	 */
262 262
 	public function first_datetime() {
263 263
 		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
264 264
 		return reset( $datetimes );
@@ -266,14 +266,14 @@  discard block
 block discarded – undo
266 266
 
267 267
 
268 268
 
269
-    /**
270
-     * Gets all the datetimes this ticket can be used for attending.
271
-     * Unless otherwise specified, orders datetimes by start date.
272
-     *
273
-     * @param array $query_params see EEM_Base::get_all()
274
-     * @return EE_Datetime[]|EE_Base_Class[]
275
-     * @throws \EE_Error
276
-     */
269
+	/**
270
+	 * Gets all the datetimes this ticket can be used for attending.
271
+	 * Unless otherwise specified, orders datetimes by start date.
272
+	 *
273
+	 * @param array $query_params see EEM_Base::get_all()
274
+	 * @return EE_Datetime[]|EE_Base_Class[]
275
+	 * @throws \EE_Error
276
+	 */
277 277
 	public function datetimes( $query_params = array() ) {
278 278
 		if ( ! isset( $query_params[ 'order_by' ] ) ) {
279 279
 			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
@@ -283,12 +283,12 @@  discard block
 block discarded – undo
283 283
 
284 284
 
285 285
 
286
-    /**
287
-     * This returns the chronologically last datetime that this ticket is associated with
288
-     *
289
-     * @return EE_Datetime
290
-     * @throws \EE_Error
291
-     */
286
+	/**
287
+	 * This returns the chronologically last datetime that this ticket is associated with
288
+	 *
289
+	 * @return EE_Datetime
290
+	 * @throws \EE_Error
291
+	 */
292 292
 	public function last_datetime() {
293 293
 		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
294 294
 		return end( $datetimes );
@@ -296,19 +296,19 @@  discard block
 block discarded – undo
296 296
 
297 297
 
298 298
 
299
-    /**
300
-     * This returns the total tickets sold depending on the given parameters.
301
-     *
302
-     * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
-     *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
-     *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
-     *                        'datetime' = total ticket sales in the datetime_ticket table.
306
-     *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
-     *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
-     * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
-     * @return mixed (array|int)          how many tickets have sold
310
-     * @throws \EE_Error
311
-     */
299
+	/**
300
+	 * This returns the total tickets sold depending on the given parameters.
301
+	 *
302
+	 * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
+	 *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
+	 *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
+	 *                        'datetime' = total ticket sales in the datetime_ticket table.
306
+	 *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
+	 *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
+	 * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
+	 * @return mixed (array|int)          how many tickets have sold
310
+	 * @throws \EE_Error
311
+	 */
312 312
 	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
313 313
 		$total = 0;
314 314
 		$tickets_sold = $this->_all_tickets_sold();
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
 
334 334
 
335 335
 
336
-    /**
337
-     * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
-     *
339
-     * @return EE_Ticket[]
340
-     * @throws \EE_Error
341
-     */
336
+	/**
337
+	 * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
+	 *
339
+	 * @return EE_Ticket[]
340
+	 * @throws \EE_Error
341
+	 */
342 342
 	protected function _all_tickets_sold() {
343 343
 		$datetimes = $this->get_many_related( 'Datetime' );
344 344
 		$tickets_sold = array();
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 
355 355
 
356 356
 
357
-    /**
358
-     * This returns the base price object for the ticket.
359
-     *
360
-     * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
-     * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
-     * @throws \EE_Error
363
-     */
357
+	/**
358
+	 * This returns the base price object for the ticket.
359
+	 *
360
+	 * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
+	 * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
+	 * @throws \EE_Error
363
+	 */
364 364
 	public function base_price( $return_array = FALSE ) {
365 365
 		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
366 366
 		return $return_array
367
-            ? $this->get_many_related( 'Price', array( $_where ) )
368
-            : $this->get_first_related( 'Price', array( $_where ) );
367
+			? $this->get_many_related( 'Price', array( $_where ) )
368
+			: $this->get_first_related( 'Price', array( $_where ) );
369 369
 	}
370 370
 
371 371
 
372 372
 
373
-    /**
374
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
-     *
376
-     * @access public
377
-     * @return EE_Price[]
378
-     * @throws \EE_Error
379
-     */
373
+	/**
374
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
+	 *
376
+	 * @access public
377
+	 * @return EE_Price[]
378
+	 * @throws \EE_Error
379
+	 */
380 380
 	public function price_modifiers() {
381 381
 		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
382 382
 		return $this->prices( $query_params );
@@ -384,132 +384,132 @@  discard block
 block discarded – undo
384 384
 
385 385
 
386 386
 
387
-    /**
388
-     * Gets all the prices that combine to form the final price of this ticket
389
-     *
390
-     * @param array $query_params like EEM_Base::get_all
391
-     * @return EE_Price[]|EE_Base_Class[]
392
-     * @throws \EE_Error
393
-     */
387
+	/**
388
+	 * Gets all the prices that combine to form the final price of this ticket
389
+	 *
390
+	 * @param array $query_params like EEM_Base::get_all
391
+	 * @return EE_Price[]|EE_Base_Class[]
392
+	 * @throws \EE_Error
393
+	 */
394 394
 	public function prices( $query_params = array() ) {
395 395
 		return $this->get_many_related( 'Price', $query_params );
396 396
 	}
397 397
 
398 398
 
399 399
 
400
-    /**
401
-     * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
-     *
403
-     * @param array $query_params see EEM_Base::get_all()
404
-     * @return EE_Datetime_Ticket|EE_Base_Class[]
405
-     * @throws \EE_Error
406
-     */
400
+	/**
401
+	 * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
+	 *
403
+	 * @param array $query_params see EEM_Base::get_all()
404
+	 * @return EE_Datetime_Ticket|EE_Base_Class[]
405
+	 * @throws \EE_Error
406
+	 */
407 407
 	public function datetime_tickets( $query_params = array() ) {
408 408
 		return $this->get_many_related( 'Datetime_Ticket', $query_params );
409 409
 	}
410 410
 
411 411
 
412 412
 
413
-    /**
414
-     * Gets all the datetimes from the db ordered by DTT_order
415
-     *
416
-     * @param boolean $show_expired
417
-     * @param boolean $show_deleted
418
-     * @return EE_Datetime[]
419
-     * @throws \EE_Error
420
-     */
413
+	/**
414
+	 * Gets all the datetimes from the db ordered by DTT_order
415
+	 *
416
+	 * @param boolean $show_expired
417
+	 * @param boolean $show_deleted
418
+	 * @return EE_Datetime[]
419
+	 * @throws \EE_Error
420
+	 */
421 421
 	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
422 422
 		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
423 423
 	}
424 424
 
425 425
 
426 426
 
427
-    /**
428
-     * Gets ID
429
-     *
430
-     * @return string
431
-     * @throws \EE_Error
432
-     */
427
+	/**
428
+	 * Gets ID
429
+	 *
430
+	 * @return string
431
+	 * @throws \EE_Error
432
+	 */
433 433
 	public function ID() {
434 434
 		return $this->get( 'TKT_ID' );
435 435
 	}
436 436
 
437 437
 
438 438
 
439
-    /**
440
-     * get the author of the ticket.
441
-     *
442
-     * @since 4.5.0
443
-     * @return int
444
-     * @throws \EE_Error
445
-     */
439
+	/**
440
+	 * get the author of the ticket.
441
+	 *
442
+	 * @since 4.5.0
443
+	 * @return int
444
+	 * @throws \EE_Error
445
+	 */
446 446
 	public function wp_user() {
447 447
 		return $this->get('TKT_wp_user');
448 448
 	}
449 449
 
450 450
 
451 451
 
452
-    /**
453
-     * Gets the template for the ticket
454
-     *
455
-     * @return EE_Ticket_Template|EE_Base_Class
456
-     * @throws \EE_Error
457
-     */
452
+	/**
453
+	 * Gets the template for the ticket
454
+	 *
455
+	 * @return EE_Ticket_Template|EE_Base_Class
456
+	 * @throws \EE_Error
457
+	 */
458 458
 	public function template() {
459 459
 		return $this->get_first_related( 'Ticket_Template' );
460 460
 	}
461 461
 
462 462
 
463 463
 
464
-    /**
465
-     * Simply returns an array of EE_Price objects that are taxes.
466
-     *
467
-     * @return EE_Price[]
468
-     * @throws \EE_Error
469
-     */
464
+	/**
465
+	 * Simply returns an array of EE_Price objects that are taxes.
466
+	 *
467
+	 * @return EE_Price[]
468
+	 * @throws \EE_Error
469
+	 */
470 470
 	public function get_ticket_taxes_for_admin() {
471 471
 		return EE_Taxes::get_taxes_for_admin();
472 472
 	}
473 473
 
474 474
 
475 475
 
476
-    /**
477
-     * @return float
478
-     * @throws \EE_Error
479
-     */
476
+	/**
477
+	 * @return float
478
+	 * @throws \EE_Error
479
+	 */
480 480
 	public function ticket_price() {
481 481
 		return $this->get( 'TKT_price' );
482 482
 	}
483 483
 
484 484
 
485 485
 
486
-    /**
487
-     * @return mixed
488
-     * @throws \EE_Error
489
-     */
486
+	/**
487
+	 * @return mixed
488
+	 * @throws \EE_Error
489
+	 */
490 490
 	public function pretty_price() {
491 491
 		return $this->get_pretty( 'TKT_price' );
492 492
 	}
493 493
 
494 494
 
495 495
 
496
-    /**
497
-     * @return bool
498
-     * @throws \EE_Error
499
-     */
496
+	/**
497
+	 * @return bool
498
+	 * @throws \EE_Error
499
+	 */
500 500
 	public function is_free() {
501 501
 		return $this->get_ticket_total_with_taxes() === 0;
502 502
 	}
503 503
 
504 504
 
505 505
 
506
-    /**
507
-     * get_ticket_total_with_taxes
508
-     *
509
-     * @param bool $no_cache
510
-     * @return float
511
-     * @throws \EE_Error
512
-     */
506
+	/**
507
+	 * get_ticket_total_with_taxes
508
+	 *
509
+	 * @param bool $no_cache
510
+	 * @return float
511
+	 * @throws \EE_Error
512
+	 */
513 513
 	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
514 514
 		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
515 515
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
@@ -526,201 +526,201 @@  discard block
 block discarded – undo
526 526
 
527 527
 
528 528
 
529
-    /**
530
-     * @return float
531
-     * @throws \EE_Error
532
-     */
529
+	/**
530
+	 * @return float
531
+	 * @throws \EE_Error
532
+	 */
533 533
 	public function get_ticket_subtotal() {
534 534
 		return EE_Taxes::get_subtotal_for_admin( $this );
535 535
 	}
536 536
 
537 537
 
538 538
 
539
-    /**
540
-     * Returns the total taxes applied to this ticket
541
-     *
542
-     * @return float
543
-     * @throws \EE_Error
544
-     */
539
+	/**
540
+	 * Returns the total taxes applied to this ticket
541
+	 *
542
+	 * @return float
543
+	 * @throws \EE_Error
544
+	 */
545 545
 	public function get_ticket_taxes_total_for_admin() {
546 546
 		return EE_Taxes::get_total_taxes_for_admin( $this );
547 547
 	}
548 548
 
549 549
 
550 550
 
551
-    /**
552
-     * Sets name
553
-     *
554
-     * @param string $name
555
-     * @throws \EE_Error
556
-     */
551
+	/**
552
+	 * Sets name
553
+	 *
554
+	 * @param string $name
555
+	 * @throws \EE_Error
556
+	 */
557 557
 	public function set_name( $name ) {
558 558
 		$this->set( 'TKT_name', $name );
559 559
 	}
560 560
 
561 561
 
562 562
 
563
-    /**
564
-     * Gets description
565
-     *
566
-     * @return string
567
-     * @throws \EE_Error
568
-     */
563
+	/**
564
+	 * Gets description
565
+	 *
566
+	 * @return string
567
+	 * @throws \EE_Error
568
+	 */
569 569
 	public function description() {
570 570
 		return $this->get( 'TKT_description' );
571 571
 	}
572 572
 
573 573
 
574 574
 
575
-    /**
576
-     * Sets description
577
-     *
578
-     * @param string $description
579
-     * @throws \EE_Error
580
-     */
575
+	/**
576
+	 * Sets description
577
+	 *
578
+	 * @param string $description
579
+	 * @throws \EE_Error
580
+	 */
581 581
 	public function set_description( $description ) {
582 582
 		$this->set( 'TKT_description', $description );
583 583
 	}
584 584
 
585 585
 
586 586
 
587
-    /**
588
-     * Gets start_date
589
-     *
590
-     * @param string $dt_frmt
591
-     * @param string $tm_frmt
592
-     * @return string
593
-     * @throws \EE_Error
594
-     */
587
+	/**
588
+	 * Gets start_date
589
+	 *
590
+	 * @param string $dt_frmt
591
+	 * @param string $tm_frmt
592
+	 * @return string
593
+	 * @throws \EE_Error
594
+	 */
595 595
 	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
596 596
 		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
597 597
 	}
598 598
 
599 599
 
600 600
 
601
-    /**
602
-     * Sets start_date
603
-     *
604
-     * @param string $start_date
605
-     * @return void
606
-     * @throws \EE_Error
607
-     */
601
+	/**
602
+	 * Sets start_date
603
+	 *
604
+	 * @param string $start_date
605
+	 * @return void
606
+	 * @throws \EE_Error
607
+	 */
608 608
 	public function set_start_date( $start_date ) {
609 609
 		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
610 610
 	}
611 611
 
612 612
 
613 613
 
614
-    /**
615
-     * Gets end_date
616
-     *
617
-     * @param string $dt_frmt
618
-     * @param string $tm_frmt
619
-     * @return string
620
-     * @throws \EE_Error
621
-     */
614
+	/**
615
+	 * Gets end_date
616
+	 *
617
+	 * @param string $dt_frmt
618
+	 * @param string $tm_frmt
619
+	 * @return string
620
+	 * @throws \EE_Error
621
+	 */
622 622
 	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
623 623
 		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
624 624
 	}
625 625
 
626 626
 
627 627
 
628
-    /**
629
-     * Sets end_date
630
-     *
631
-     * @param string $end_date
632
-     * @return void
633
-     * @throws \EE_Error
634
-     */
628
+	/**
629
+	 * Sets end_date
630
+	 *
631
+	 * @param string $end_date
632
+	 * @return void
633
+	 * @throws \EE_Error
634
+	 */
635 635
 	public function set_end_date( $end_date ) {
636 636
 		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
637 637
 	}
638 638
 
639 639
 
640 640
 
641
-    /**
642
-     * Sets sell until time
643
-     *
644
-     * @since 4.5.0
645
-     * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
-     * @throws \EE_Error
647
-     */
641
+	/**
642
+	 * Sets sell until time
643
+	 *
644
+	 * @since 4.5.0
645
+	 * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
+	 * @throws \EE_Error
647
+	 */
648 648
 	public function set_end_time( $time ) {
649 649
 		$this->_set_time_for( $time, 'TKT_end_date' );
650 650
 	}
651 651
 
652 652
 
653 653
 
654
-    /**
655
-     * Sets min
656
-     *
657
-     * @param int $min
658
-     * @return void
659
-     * @throws \EE_Error
660
-     */
654
+	/**
655
+	 * Sets min
656
+	 *
657
+	 * @param int $min
658
+	 * @return void
659
+	 * @throws \EE_Error
660
+	 */
661 661
 	public function set_min( $min ) {
662 662
 		$this->set( 'TKT_min', $min );
663 663
 	}
664 664
 
665 665
 
666 666
 
667
-    /**
668
-     * Gets max
669
-     *
670
-     * @return int
671
-     * @throws \EE_Error
672
-     */
667
+	/**
668
+	 * Gets max
669
+	 *
670
+	 * @return int
671
+	 * @throws \EE_Error
672
+	 */
673 673
 	public function max() {
674 674
 		return $this->get( 'TKT_max' );
675 675
 	}
676 676
 
677 677
 
678 678
 
679
-    /**
680
-     * Sets max
681
-     *
682
-     * @param int $max
683
-     * @return void
684
-     * @throws \EE_Error
685
-     */
679
+	/**
680
+	 * Sets max
681
+	 *
682
+	 * @param int $max
683
+	 * @return void
684
+	 * @throws \EE_Error
685
+	 */
686 686
 	public function set_max( $max ) {
687 687
 		$this->set( 'TKT_max', $max );
688 688
 	}
689 689
 
690 690
 
691 691
 
692
-    /**
693
-     * Sets price
694
-     *
695
-     * @param float $price
696
-     * @return void
697
-     * @throws \EE_Error
698
-     */
692
+	/**
693
+	 * Sets price
694
+	 *
695
+	 * @param float $price
696
+	 * @return void
697
+	 * @throws \EE_Error
698
+	 */
699 699
 	public function set_price( $price ) {
700 700
 		$this->set( 'TKT_price', $price );
701 701
 	}
702 702
 
703 703
 
704 704
 
705
-    /**
706
-     * Gets sold
707
-     *
708
-     * @return int
709
-     * @throws \EE_Error
710
-     */
705
+	/**
706
+	 * Gets sold
707
+	 *
708
+	 * @return int
709
+	 * @throws \EE_Error
710
+	 */
711 711
 	public function sold() {
712 712
 		return $this->get_raw( 'TKT_sold' );
713 713
 	}
714 714
 
715 715
 
716 716
 
717
-    /**
718
-     * Sets sold
719
-     *
720
-     * @param int $sold
721
-     * @return void
722
-     * @throws \EE_Error
723
-     */
717
+	/**
718
+	 * Sets sold
719
+	 *
720
+	 * @param int $sold
721
+	 * @return void
722
+	 * @throws \EE_Error
723
+	 */
724 724
 	public function set_sold( $sold ) {
725 725
 		// sold can not go below zero
726 726
 		$sold = max( 0, $sold );
@@ -729,13 +729,13 @@  discard block
 block discarded – undo
729 729
 
730 730
 
731 731
 
732
-    /**
733
-     * increments sold by amount passed by $qty
734
-     *
735
-     * @param int $qty
736
-     * @return void
737
-     * @throws \EE_Error
738
-     */
732
+	/**
733
+	 * increments sold by amount passed by $qty
734
+	 *
735
+	 * @param int $qty
736
+	 * @return void
737
+	 * @throws \EE_Error
738
+	 */
739 739
 	public function increase_sold( $qty = 1 ) {
740 740
 		$sold = $this->sold() + $qty;
741 741
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
@@ -747,13 +747,13 @@  discard block
 block discarded – undo
747 747
 
748 748
 
749 749
 
750
-    /**
751
-     * Increases sold on related datetimes
752
-     *
753
-     * @param int $qty
754
-     * @return void
755
-     * @throws \EE_Error
756
-     */
750
+	/**
751
+	 * Increases sold on related datetimes
752
+	 *
753
+	 * @param int $qty
754
+	 * @return void
755
+	 * @throws \EE_Error
756
+	 */
757 757
 	protected function _increase_sold_for_datetimes( $qty = 1 ) {
758 758
 		$datetimes = $this->datetimes();
759 759
 		if ( is_array( $datetimes ) ) {
@@ -768,13 +768,13 @@  discard block
 block discarded – undo
768 768
 
769 769
 
770 770
 
771
-    /**
772
-     * decrements (subtracts) sold by amount passed by $qty
773
-     *
774
-     * @param int $qty
775
-     * @return void
776
-     * @throws \EE_Error
777
-     */
771
+	/**
772
+	 * decrements (subtracts) sold by amount passed by $qty
773
+	 *
774
+	 * @param int $qty
775
+	 * @return void
776
+	 * @throws \EE_Error
777
+	 */
778 778
 	public function decrease_sold( $qty = 1 ) {
779 779
 		$sold = $this->sold() - $qty;
780 780
 		$this->_decrease_sold_for_datetimes( $qty );
@@ -783,13 +783,13 @@  discard block
 block discarded – undo
783 783
 
784 784
 
785 785
 
786
-    /**
787
-     * Decreases sold on related datetimes
788
-     *
789
-     * @param int $qty
790
-     * @return void
791
-     * @throws \EE_Error
792
-     */
786
+	/**
787
+	 * Decreases sold on related datetimes
788
+	 *
789
+	 * @param int $qty
790
+	 * @return void
791
+	 * @throws \EE_Error
792
+	 */
793 793
 	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
794 794
 		$datetimes = $this->datetimes();
795 795
 		if ( is_array( $datetimes ) ) {
@@ -804,25 +804,25 @@  discard block
 block discarded – undo
804 804
 
805 805
 
806 806
 
807
-    /**
808
-     * Gets qty of reserved tickets
809
-     *
810
-     * @return int
811
-     * @throws \EE_Error
812
-     */
807
+	/**
808
+	 * Gets qty of reserved tickets
809
+	 *
810
+	 * @return int
811
+	 * @throws \EE_Error
812
+	 */
813 813
 	public function reserved() {
814 814
 		return $this->get_raw( 'TKT_reserved' );
815 815
 	}
816 816
 
817 817
 
818 818
 
819
-    /**
820
-     * Sets reserved
821
-     *
822
-     * @param int $reserved
823
-     * @return void
824
-     * @throws \EE_Error
825
-     */
819
+	/**
820
+	 * Sets reserved
821
+	 *
822
+	 * @param int $reserved
823
+	 * @return void
824
+	 * @throws \EE_Error
825
+	 */
826 826
 	public function set_reserved( $reserved ) {
827 827
 		// reserved can not go below zero
828 828
 		$reserved = max( 0, (int) $reserved );
@@ -831,13 +831,13 @@  discard block
 block discarded – undo
831 831
 
832 832
 
833 833
 
834
-    /**
835
-     * increments reserved by amount passed by $qty
836
-     *
837
-     * @param int $qty
838
-     * @return void
839
-     * @throws \EE_Error
840
-     */
834
+	/**
835
+	 * increments reserved by amount passed by $qty
836
+	 *
837
+	 * @param int $qty
838
+	 * @return void
839
+	 * @throws \EE_Error
840
+	 */
841 841
 	public function increase_reserved( $qty = 1 ) {
842 842
 		$qty = absint( $qty );
843 843
 		$reserved = $this->reserved() + $qty;
@@ -847,13 +847,13 @@  discard block
 block discarded – undo
847 847
 
848 848
 
849 849
 
850
-    /**
851
-     * Increases sold on related datetimes
852
-     *
853
-     * @param int $qty
854
-     * @return void
855
-     * @throws \EE_Error
856
-     */
850
+	/**
851
+	 * Increases sold on related datetimes
852
+	 *
853
+	 * @param int $qty
854
+	 * @return void
855
+	 * @throws \EE_Error
856
+	 */
857 857
 	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
858 858
 		$datetimes = $this->datetimes();
859 859
 		if ( is_array( $datetimes ) ) {
@@ -868,14 +868,14 @@  discard block
 block discarded – undo
868 868
 
869 869
 
870 870
 
871
-    /**
872
-     * decrements (subtracts) reserved by amount passed by $qty
873
-     *
874
-     * @param int  $qty
875
-     * @param bool $adjust_datetimes
876
-     * @return void
877
-     * @throws \EE_Error
878
-     */
871
+	/**
872
+	 * decrements (subtracts) reserved by amount passed by $qty
873
+	 *
874
+	 * @param int  $qty
875
+	 * @param bool $adjust_datetimes
876
+	 * @return void
877
+	 * @throws \EE_Error
878
+	 */
879 879
 	public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) {
880 880
 		$reserved = $this->reserved() - absint( $qty );
881 881
 		if ( $adjust_datetimes ) {
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
 
887 887
 
888 888
 
889
-    /**
890
-     * Increases sold on related datetimes
891
-     *
892
-     * @param int $qty
893
-     * @return void
894
-     * @throws \EE_Error
895
-     */
889
+	/**
890
+	 * Increases sold on related datetimes
891
+	 *
892
+	 * @param int $qty
893
+	 * @return void
894
+	 * @throws \EE_Error
895
+	 */
896 896
 	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
897 897
 		$datetimes = $this->datetimes();
898 898
 		if ( is_array( $datetimes ) ) {
@@ -907,18 +907,18 @@  discard block
 block discarded – undo
907 907
 
908 908
 
909 909
 
910
-    /**
911
-     * Gets ticket quantity
912
-     *
913
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
914
-     *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
915
-     *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
916
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
917
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
918
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
919
-     * @return int
920
-     * @throws \EE_Error
921
-     */
910
+	/**
911
+	 * Gets ticket quantity
912
+	 *
913
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
914
+	 *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
915
+	 *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
916
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
917
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
918
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
919
+	 * @return int
920
+	 * @throws \EE_Error
921
+	 */
922 922
 	public function qty( $context = '' ) {
923 923
 		switch ( $context ) {
924 924
 			case 'reg_limit' :
@@ -932,19 +932,19 @@  discard block
 block discarded – undo
932 932
 
933 933
 
934 934
 
935
-    /**
936
-     * Gets ticket quantity
937
-     *
938
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
939
-     *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
940
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
943
-     * @param  int   $DTT_ID      the primary key for a particular datetime.
944
-     *                            set to 0 for all related datetimes
945
-     * @return int
946
-     * @throws \EE_Error
947
-     */
935
+	/**
936
+	 * Gets ticket quantity
937
+	 *
938
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
939
+	 *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
940
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
943
+	 * @param  int   $DTT_ID      the primary key for a particular datetime.
944
+	 *                            set to 0 for all related datetimes
945
+	 * @return int
946
+	 * @throws \EE_Error
947
+	 */
948 948
 	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
949 949
 		$raw = $this->get_raw( 'TKT_qty' );
950 950
 		// return immediately if it's zero
@@ -1027,212 +1027,212 @@  discard block
 block discarded – undo
1027 1027
 
1028 1028
 
1029 1029
 
1030
-    /**
1031
-     * Gets uses
1032
-     *
1033
-     * @return int
1034
-     * @throws \EE_Error
1035
-     */
1030
+	/**
1031
+	 * Gets uses
1032
+	 *
1033
+	 * @return int
1034
+	 * @throws \EE_Error
1035
+	 */
1036 1036
 	public function uses() {
1037 1037
 		return $this->get( 'TKT_uses' );
1038 1038
 	}
1039 1039
 
1040 1040
 
1041 1041
 
1042
-    /**
1043
-     * Sets uses
1044
-     *
1045
-     * @param int $uses
1046
-     * @return void
1047
-     * @throws \EE_Error
1048
-     */
1042
+	/**
1043
+	 * Sets uses
1044
+	 *
1045
+	 * @param int $uses
1046
+	 * @return void
1047
+	 * @throws \EE_Error
1048
+	 */
1049 1049
 	public function set_uses( $uses ) {
1050 1050
 		$this->set( 'TKT_uses', $uses );
1051 1051
 	}
1052 1052
 
1053 1053
 
1054 1054
 
1055
-    /**
1056
-     * returns whether ticket is required or not.
1057
-     *
1058
-     * @return boolean
1059
-     * @throws \EE_Error
1060
-     */
1055
+	/**
1056
+	 * returns whether ticket is required or not.
1057
+	 *
1058
+	 * @return boolean
1059
+	 * @throws \EE_Error
1060
+	 */
1061 1061
 	public function required() {
1062 1062
 		return $this->get( 'TKT_required' );
1063 1063
 	}
1064 1064
 
1065 1065
 
1066 1066
 
1067
-    /**
1068
-     * sets the TKT_required property
1069
-     *
1070
-     * @param boolean $required
1071
-     * @return void
1072
-     * @throws \EE_Error
1073
-     */
1067
+	/**
1068
+	 * sets the TKT_required property
1069
+	 *
1070
+	 * @param boolean $required
1071
+	 * @return void
1072
+	 * @throws \EE_Error
1073
+	 */
1074 1074
 	public function set_required( $required ) {
1075 1075
 		$this->set( 'TKT_required', $required );
1076 1076
 	}
1077 1077
 
1078 1078
 
1079 1079
 
1080
-    /**
1081
-     * Gets taxable
1082
-     *
1083
-     * @return boolean
1084
-     * @throws \EE_Error
1085
-     */
1080
+	/**
1081
+	 * Gets taxable
1082
+	 *
1083
+	 * @return boolean
1084
+	 * @throws \EE_Error
1085
+	 */
1086 1086
 	public function taxable() {
1087 1087
 		return $this->get( 'TKT_taxable' );
1088 1088
 	}
1089 1089
 
1090 1090
 
1091 1091
 
1092
-    /**
1093
-     * Sets taxable
1094
-     *
1095
-     * @param boolean $taxable
1096
-     * @return void
1097
-     * @throws \EE_Error
1098
-     */
1092
+	/**
1093
+	 * Sets taxable
1094
+	 *
1095
+	 * @param boolean $taxable
1096
+	 * @return void
1097
+	 * @throws \EE_Error
1098
+	 */
1099 1099
 	public function set_taxable( $taxable ) {
1100 1100
 		$this->set( 'TKT_taxable', $taxable );
1101 1101
 	}
1102 1102
 
1103 1103
 
1104 1104
 
1105
-    /**
1106
-     * Gets is_default
1107
-     *
1108
-     * @return boolean
1109
-     * @throws \EE_Error
1110
-     */
1105
+	/**
1106
+	 * Gets is_default
1107
+	 *
1108
+	 * @return boolean
1109
+	 * @throws \EE_Error
1110
+	 */
1111 1111
 	public function is_default() {
1112 1112
 		return $this->get( 'TKT_is_default' );
1113 1113
 	}
1114 1114
 
1115 1115
 
1116 1116
 
1117
-    /**
1118
-     * Sets is_default
1119
-     *
1120
-     * @param boolean $is_default
1121
-     * @return void
1122
-     * @throws \EE_Error
1123
-     */
1117
+	/**
1118
+	 * Sets is_default
1119
+	 *
1120
+	 * @param boolean $is_default
1121
+	 * @return void
1122
+	 * @throws \EE_Error
1123
+	 */
1124 1124
 	public function set_is_default( $is_default ) {
1125 1125
 		$this->set( 'TKT_is_default', $is_default );
1126 1126
 	}
1127 1127
 
1128 1128
 
1129 1129
 
1130
-    /**
1131
-     * Gets order
1132
-     *
1133
-     * @return int
1134
-     * @throws \EE_Error
1135
-     */
1130
+	/**
1131
+	 * Gets order
1132
+	 *
1133
+	 * @return int
1134
+	 * @throws \EE_Error
1135
+	 */
1136 1136
 	public function order() {
1137 1137
 		return $this->get( 'TKT_order' );
1138 1138
 	}
1139 1139
 
1140 1140
 
1141 1141
 
1142
-    /**
1143
-     * Sets order
1144
-     *
1145
-     * @param int $order
1146
-     * @return void
1147
-     * @throws \EE_Error
1148
-     */
1142
+	/**
1143
+	 * Sets order
1144
+	 *
1145
+	 * @param int $order
1146
+	 * @return void
1147
+	 * @throws \EE_Error
1148
+	 */
1149 1149
 	public function set_order( $order ) {
1150 1150
 		$this->set( 'TKT_order', $order );
1151 1151
 	}
1152 1152
 
1153 1153
 
1154 1154
 
1155
-    /**
1156
-     * Gets row
1157
-     *
1158
-     * @return int
1159
-     * @throws \EE_Error
1160
-     */
1155
+	/**
1156
+	 * Gets row
1157
+	 *
1158
+	 * @return int
1159
+	 * @throws \EE_Error
1160
+	 */
1161 1161
 	public function row() {
1162 1162
 		return $this->get( 'TKT_row' );
1163 1163
 	}
1164 1164
 
1165 1165
 
1166 1166
 
1167
-    /**
1168
-     * Sets row
1169
-     *
1170
-     * @param int $row
1171
-     * @return void
1172
-     * @throws \EE_Error
1173
-     */
1167
+	/**
1168
+	 * Sets row
1169
+	 *
1170
+	 * @param int $row
1171
+	 * @return void
1172
+	 * @throws \EE_Error
1173
+	 */
1174 1174
 	public function set_row( $row ) {
1175 1175
 		$this->set( 'TKT_row', $row );
1176 1176
 	}
1177 1177
 
1178 1178
 
1179 1179
 
1180
-    /**
1181
-     * Gets deleted
1182
-     *
1183
-     * @return boolean
1184
-     * @throws \EE_Error
1185
-     */
1180
+	/**
1181
+	 * Gets deleted
1182
+	 *
1183
+	 * @return boolean
1184
+	 * @throws \EE_Error
1185
+	 */
1186 1186
 	public function deleted() {
1187 1187
 		return $this->get( 'TKT_deleted' );
1188 1188
 	}
1189 1189
 
1190 1190
 
1191 1191
 
1192
-    /**
1193
-     * Sets deleted
1194
-     *
1195
-     * @param boolean $deleted
1196
-     * @return void
1197
-     * @throws \EE_Error
1198
-     */
1192
+	/**
1193
+	 * Sets deleted
1194
+	 *
1195
+	 * @param boolean $deleted
1196
+	 * @return void
1197
+	 * @throws \EE_Error
1198
+	 */
1199 1199
 	public function set_deleted( $deleted ) {
1200 1200
 		$this->set( 'TKT_deleted', $deleted );
1201 1201
 	}
1202 1202
 
1203 1203
 
1204 1204
 
1205
-    /**
1206
-     * Gets parent
1207
-     *
1208
-     * @return int
1209
-     * @throws \EE_Error
1210
-     */
1205
+	/**
1206
+	 * Gets parent
1207
+	 *
1208
+	 * @return int
1209
+	 * @throws \EE_Error
1210
+	 */
1211 1211
 	public function parent_ID() {
1212 1212
 		return $this->get( 'TKT_parent' );
1213 1213
 	}
1214 1214
 
1215 1215
 
1216 1216
 
1217
-    /**
1218
-     * Sets parent
1219
-     *
1220
-     * @param int $parent
1221
-     * @return void
1222
-     * @throws \EE_Error
1223
-     */
1217
+	/**
1218
+	 * Sets parent
1219
+	 *
1220
+	 * @param int $parent
1221
+	 * @return void
1222
+	 * @throws \EE_Error
1223
+	 */
1224 1224
 	public function set_parent_ID( $parent ) {
1225 1225
 		$this->set( 'TKT_parent', $parent );
1226 1226
 	}
1227 1227
 
1228 1228
 
1229 1229
 
1230
-    /**
1231
-     * Gets a string which is handy for showing in gateways etc that describes the ticket.
1232
-     *
1233
-     * @return string
1234
-     * @throws \EE_Error
1235
-     */
1230
+	/**
1231
+	 * Gets a string which is handy for showing in gateways etc that describes the ticket.
1232
+	 *
1233
+	 * @return string
1234
+	 * @throws \EE_Error
1235
+	 */
1236 1236
 	public function name_and_info() {
1237 1237
 		$times = array();
1238 1238
 		foreach ( $this->datetimes() as $datetime ) {
@@ -1243,50 +1243,50 @@  discard block
 block discarded – undo
1243 1243
 
1244 1244
 
1245 1245
 
1246
-    /**
1247
-     * Gets name
1248
-     *
1249
-     * @return string
1250
-     * @throws \EE_Error
1251
-     */
1246
+	/**
1247
+	 * Gets name
1248
+	 *
1249
+	 * @return string
1250
+	 * @throws \EE_Error
1251
+	 */
1252 1252
 	public function name() {
1253 1253
 		return $this->get( 'TKT_name' );
1254 1254
 	}
1255 1255
 
1256 1256
 
1257 1257
 
1258
-    /**
1259
-     * Gets price
1260
-     *
1261
-     * @return float
1262
-     * @throws \EE_Error
1263
-     */
1258
+	/**
1259
+	 * Gets price
1260
+	 *
1261
+	 * @return float
1262
+	 * @throws \EE_Error
1263
+	 */
1264 1264
 	public function price() {
1265 1265
 		return $this->get( 'TKT_price' );
1266 1266
 	}
1267 1267
 
1268 1268
 
1269 1269
 
1270
-    /**
1271
-     * Gets all the registrations for this ticket
1272
-     *
1273
-     * @param array $query_params like EEM_Base::get_all's
1274
-     * @return EE_Registration[]|EE_Base_Class[]
1275
-     * @throws \EE_Error
1276
-     */
1270
+	/**
1271
+	 * Gets all the registrations for this ticket
1272
+	 *
1273
+	 * @param array $query_params like EEM_Base::get_all's
1274
+	 * @return EE_Registration[]|EE_Base_Class[]
1275
+	 * @throws \EE_Error
1276
+	 */
1277 1277
 	public function registrations( $query_params = array() ) {
1278 1278
 		return $this->get_many_related( 'Registration', $query_params );
1279 1279
 	}
1280 1280
 
1281 1281
 
1282 1282
 
1283
-    /**
1284
-     * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1285
-     * into account
1286
-     *
1287
-     * @return int
1288
-     * @throws \EE_Error
1289
-     */
1283
+	/**
1284
+	 * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1285
+	 * into account
1286
+	 *
1287
+	 * @return int
1288
+	 * @throws \EE_Error
1289
+	 */
1290 1290
 	public function update_tickets_sold() {
1291 1291
 		$count_regs_for_this_ticket = $this->count_registrations( array( array( 'STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0 ) ) );
1292 1292
 		$this->set_sold( $count_regs_for_this_ticket );
@@ -1318,21 +1318,21 @@  discard block
 block discarded – undo
1318 1318
 
1319 1319
 
1320 1320
 
1321
-    /**
1322
-     * Implementation of the EEI_Event_Relation interface method
1323
-     *
1324
-     * @see EEI_Event_Relation for comments
1325
-     * @return EE_Event
1326
-     * @throws \EE_Error
1327
-     * @throws UnexpectedEntityException
1328
-     */
1321
+	/**
1322
+	 * Implementation of the EEI_Event_Relation interface method
1323
+	 *
1324
+	 * @see EEI_Event_Relation for comments
1325
+	 * @return EE_Event
1326
+	 * @throws \EE_Error
1327
+	 * @throws UnexpectedEntityException
1328
+	 */
1329 1329
 	public function get_related_event() {
1330 1330
 		//get one datetime to use for getting the event
1331 1331
 		$datetime = $this->first_datetime();
1332 1332
 		if ( ! $datetime instanceof \EE_Datetime ) {
1333 1333
 			throw new UnexpectedEntityException(
1334 1334
 				$datetime,
1335
-                'EE_Datetime',
1335
+				'EE_Datetime',
1336 1336
 				sprintf(
1337 1337
 					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1338 1338
 					$datetime->name()
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
 		if ( ! $event instanceof \EE_Event ) {
1344 1344
 			throw new UnexpectedEntityException(
1345 1345
 				$event,
1346
-                'EE_Event',
1346
+				'EE_Event',
1347 1347
 				sprintf(
1348 1348
 					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1349 1349
 					$this->name()
@@ -1355,14 +1355,14 @@  discard block
 block discarded – undo
1355 1355
 
1356 1356
 
1357 1357
 
1358
-    /**
1359
-     * Implementation of the EEI_Event_Relation interface method
1360
-     *
1361
-     * @see EEI_Event_Relation for comments
1362
-     * @return string
1363
-     * @throws UnexpectedEntityException
1364
-     * @throws \EE_Error
1365
-     */
1358
+	/**
1359
+	 * Implementation of the EEI_Event_Relation interface method
1360
+	 *
1361
+	 * @see EEI_Event_Relation for comments
1362
+	 * @return string
1363
+	 * @throws UnexpectedEntityException
1364
+	 * @throws \EE_Error
1365
+	 */
1366 1366
 	public function get_event_name() {
1367 1367
 		$event = $this->get_related_event();
1368 1368
 		return $event instanceof EE_Event ? $event->name() : '';
@@ -1370,14 +1370,14 @@  discard block
 block discarded – undo
1370 1370
 
1371 1371
 
1372 1372
 
1373
-    /**
1374
-     * Implementation of the EEI_Event_Relation interface method
1375
-     *
1376
-     * @see EEI_Event_Relation for comments
1377
-     * @return int
1378
-     * @throws UnexpectedEntityException
1379
-     * @throws \EE_Error
1380
-     */
1373
+	/**
1374
+	 * Implementation of the EEI_Event_Relation interface method
1375
+	 *
1376
+	 * @see EEI_Event_Relation for comments
1377
+	 * @return int
1378
+	 * @throws UnexpectedEntityException
1379
+	 * @throws \EE_Error
1380
+	 */
1381 1381
 	public function get_event_ID() {
1382 1382
 		$event = $this->get_related_event();
1383 1383
 		return $event instanceof EE_Event ? $event->ID() : 0;
Please login to merge, or discard this patch.
Spacing   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\UnexpectedEntityException;
2 2
 
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  * Event Espresso
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
      * @return EE_Ticket
71 71
      * @throws \EE_Error
72 72
      */
73
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
74
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
75
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
73
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
74
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
75
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
76 76
 	}
77 77
 
78 78
 
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
      * @return EE_Ticket
85 85
      * @throws \EE_Error
86 86
      */
87
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
88
-		return new self( $props_n_values, TRUE, $timezone );
87
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
88
+		return new self($props_n_values, TRUE, $timezone);
89 89
 	}
90 90
 
91 91
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      * @throws \EE_Error
96 96
      */
97 97
 	public function parent() {
98
-		return $this->get( 'TKT_parent' );
98
+		return $this->get('TKT_parent');
99 99
 	}
100 100
 
101 101
 
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
      * @return boolean
108 108
      * @throws \EE_Error
109 109
      */
110
-	public function available( $DTT_ID = 0 ) {
110
+	public function available($DTT_ID = 0) {
111 111
 		// are we checking availability for a particular datetime ?
112
-		if ( $DTT_ID ) {
112
+		if ($DTT_ID) {
113 113
 			// get that datetime object
114
-			$datetime = $this->get_first_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) );
114
+			$datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID)));
115 115
 			// if  ticket sales for this datetime have exceeded the reg limit...
116
-			if ( $datetime instanceof EE_Datetime && $datetime->sold_out() ) {
116
+			if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
117 117
 				return FALSE;
118 118
 			}
119 119
 		}
@@ -131,22 +131,22 @@  discard block
 block discarded – undo
131 131
      * @return mixed status int if the display string isn't requested
132 132
      * @throws \EE_Error
133 133
      */
134
-	public function ticket_status( $display = FALSE, $remaining = null ) {
135
-		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
136
-		if ( ! $remaining ) {
137
-			return $display ? EEH_Template::pretty_status( EE_Ticket::sold_out, FALSE, 'sentence' ) : EE_Ticket::sold_out;
134
+	public function ticket_status($display = FALSE, $remaining = null) {
135
+		$remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
136
+		if ( ! $remaining) {
137
+			return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, FALSE, 'sentence') : EE_Ticket::sold_out;
138 138
 		}
139
-		if ( $this->get( 'TKT_deleted' ) ) {
140
-			return $display ? EEH_Template::pretty_status( EE_Ticket::archived, FALSE, 'sentence' ) : EE_Ticket::archived;
139
+		if ($this->get('TKT_deleted')) {
140
+			return $display ? EEH_Template::pretty_status(EE_Ticket::archived, FALSE, 'sentence') : EE_Ticket::archived;
141 141
 		}
142
-		if ( $this->is_expired() ) {
143
-			return $display ? EEH_Template::pretty_status( EE_Ticket::expired, FALSE, 'sentence' ) : EE_Ticket::expired;
142
+		if ($this->is_expired()) {
143
+			return $display ? EEH_Template::pretty_status(EE_Ticket::expired, FALSE, 'sentence') : EE_Ticket::expired;
144 144
 		}
145
-		if ( $this->is_pending() ) {
146
-			return $display ? EEH_Template::pretty_status( EE_Ticket::pending, FALSE, 'sentence' ) : EE_Ticket::pending;
145
+		if ($this->is_pending()) {
146
+			return $display ? EEH_Template::pretty_status(EE_Ticket::pending, FALSE, 'sentence') : EE_Ticket::pending;
147 147
 		}
148
-		if ( $this->is_on_sale() ) {
149
-			return $display ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence' ) : EE_Ticket::onsale;
148
+		if ($this->is_on_sale()) {
149
+			return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : EE_Ticket::onsale;
150 150
 		}
151 151
 		return '';
152 152
 	}
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
      * @return boolean         true = tickets remaining, false not.
162 162
      * @throws \EE_Error
163 163
      */
164
-	public function is_remaining( $DTT_ID = 0 ) {
165
-		$num_remaining = $this->remaining( $DTT_ID );
166
-		if ( $num_remaining === 0 ) {
164
+	public function is_remaining($DTT_ID = 0) {
165
+		$num_remaining = $this->remaining($DTT_ID);
166
+		if ($num_remaining === 0) {
167 167
 			return FALSE;
168 168
 		}
169
-		if ( $num_remaining > 0 && $num_remaining < $this->min() ) {
169
+		if ($num_remaining > 0 && $num_remaining < $this->min()) {
170 170
 			return FALSE;
171 171
 		}
172 172
 		return TRUE;
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
      * @return int
183 183
      * @throws \EE_Error
184 184
      */
185
-	public function remaining( $DTT_ID = 0 ) {
186
-		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
185
+	public function remaining($DTT_ID = 0) {
186
+		return $this->real_quantity_on_ticket('saleable', $DTT_ID);
187 187
 	}
188 188
 
189 189
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      * @throws \EE_Error
196 196
      */
197 197
 	public function min() {
198
-		return $this->get( 'TKT_min' );
198
+		return $this->get('TKT_min');
199 199
 	}
200 200
 
201 201
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      * @throws \EE_Error
208 208
      */
209 209
 	public function is_expired() {
210
-		return ( $this->get_raw( 'TKT_end_date' ) < time() );
210
+		return ($this->get_raw('TKT_end_date') < time());
211 211
 	}
212 212
 
213 213
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * @throws \EE_Error
220 220
      */
221 221
 	public function is_pending() {
222
-		return ( $this->get_raw( 'TKT_start_date' ) > time() );
222
+		return ($this->get_raw('TKT_start_date') > time());
223 223
 	}
224 224
 
225 225
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * @throws \EE_Error
232 232
      */
233 233
 	public function is_on_sale() {
234
-		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
234
+		return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time());
235 235
 	}
236 236
 
237 237
 
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
      * @return string
245 245
      * @throws \EE_Error
246 246
      */
247
-	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
248
-		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
249
-		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
247
+	public function date_range($dt_frmt = '', $conjunction = ' - ') {
248
+		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) : '';
249
+		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : '';
250 250
 
251
-		return $first_date && $last_date ? $first_date . $conjunction  . $last_date : '';
251
+		return $first_date && $last_date ? $first_date.$conjunction.$last_date : '';
252 252
 	}
253 253
 
254 254
 
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
      * @throws \EE_Error
261 261
      */
262 262
 	public function first_datetime() {
263
-		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
264
-		return reset( $datetimes );
263
+		$datetimes = $this->datetimes(array('limit' => 1));
264
+		return reset($datetimes);
265 265
 	}
266 266
 
267 267
 
@@ -274,11 +274,11 @@  discard block
 block discarded – undo
274 274
      * @return EE_Datetime[]|EE_Base_Class[]
275 275
      * @throws \EE_Error
276 276
      */
277
-	public function datetimes( $query_params = array() ) {
278
-		if ( ! isset( $query_params[ 'order_by' ] ) ) {
279
-			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
277
+	public function datetimes($query_params = array()) {
278
+		if ( ! isset($query_params['order_by'])) {
279
+			$query_params['order_by']['DTT_order'] = 'ASC';
280 280
 		}
281
-		return $this->get_many_related( 'Datetime', $query_params );
281
+		return $this->get_many_related('Datetime', $query_params);
282 282
 	}
283 283
 
284 284
 
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
      * @throws \EE_Error
291 291
      */
292 292
 	public function last_datetime() {
293
-		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
294
-		return end( $datetimes );
293
+		$datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC')));
294
+		return end($datetimes);
295 295
 	}
296 296
 
297 297
 
@@ -309,22 +309,22 @@  discard block
 block discarded – undo
309 309
      * @return mixed (array|int)          how many tickets have sold
310 310
      * @throws \EE_Error
311 311
      */
312
-	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
312
+	public function tickets_sold($what = 'ticket', $dtt_id = NULL) {
313 313
 		$total = 0;
314 314
 		$tickets_sold = $this->_all_tickets_sold();
315
-		switch ( $what ) {
315
+		switch ($what) {
316 316
 			case 'ticket' :
317
-				return $tickets_sold[ 'ticket' ];
317
+				return $tickets_sold['ticket'];
318 318
 				break;
319 319
 			case 'datetime' :
320
-				if ( empty( $tickets_sold[ 'datetime' ] ) ) {
320
+				if (empty($tickets_sold['datetime'])) {
321 321
 					return $total;
322 322
 				}
323
-				if ( ! empty( $dtt_id ) && ! isset( $tickets_sold[ 'datetime' ][ $dtt_id ] ) ) {
324
-					EE_Error::add_error( __( 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
323
+				if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) {
324
+					EE_Error::add_error(__('You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
325 325
 					return $total;
326 326
 				}
327
-				return empty( $dtt_id ) ? $tickets_sold[ 'datetime' ] : $tickets_sold[ 'datetime' ][ $dtt_id ];
327
+				return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id];
328 328
 				break;
329 329
 			default:
330 330
 				return $total;
@@ -340,15 +340,15 @@  discard block
 block discarded – undo
340 340
      * @throws \EE_Error
341 341
      */
342 342
 	protected function _all_tickets_sold() {
343
-		$datetimes = $this->get_many_related( 'Datetime' );
343
+		$datetimes = $this->get_many_related('Datetime');
344 344
 		$tickets_sold = array();
345
-		if ( ! empty( $datetimes ) ) {
346
-			foreach ( $datetimes as $datetime ) {
347
-				$tickets_sold[ 'datetime' ][ $datetime->ID() ] = $datetime->get( 'DTT_sold' );
345
+		if ( ! empty($datetimes)) {
346
+			foreach ($datetimes as $datetime) {
347
+				$tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold');
348 348
 			}
349 349
 		}
350 350
 		//Tickets sold
351
-		$tickets_sold[ 'ticket' ] = $this->sold();
351
+		$tickets_sold['ticket'] = $this->sold();
352 352
 		return $tickets_sold;
353 353
 	}
354 354
 
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
      * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362 362
      * @throws \EE_Error
363 363
      */
364
-	public function base_price( $return_array = FALSE ) {
365
-		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
364
+	public function base_price($return_array = FALSE) {
365
+		$_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price);
366 366
 		return $return_array
367
-            ? $this->get_many_related( 'Price', array( $_where ) )
368
-            : $this->get_first_related( 'Price', array( $_where ) );
367
+            ? $this->get_many_related('Price', array($_where))
368
+            : $this->get_first_related('Price', array($_where));
369 369
 	}
370 370
 
371 371
 
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
      * @throws \EE_Error
379 379
      */
380 380
 	public function price_modifiers() {
381
-		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
382
-		return $this->prices( $query_params );
381
+		$query_params = array(0 => array('Price_Type.PBT_ID' => array('NOT IN', array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax))));
382
+		return $this->prices($query_params);
383 383
 	}
384 384
 
385 385
 
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
      * @return EE_Price[]|EE_Base_Class[]
392 392
      * @throws \EE_Error
393 393
      */
394
-	public function prices( $query_params = array() ) {
395
-		return $this->get_many_related( 'Price', $query_params );
394
+	public function prices($query_params = array()) {
395
+		return $this->get_many_related('Price', $query_params);
396 396
 	}
397 397
 
398 398
 
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
      * @return EE_Datetime_Ticket|EE_Base_Class[]
405 405
      * @throws \EE_Error
406 406
      */
407
-	public function datetime_tickets( $query_params = array() ) {
408
-		return $this->get_many_related( 'Datetime_Ticket', $query_params );
407
+	public function datetime_tickets($query_params = array()) {
408
+		return $this->get_many_related('Datetime_Ticket', $query_params);
409 409
 	}
410 410
 
411 411
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
      * @return EE_Datetime[]
419 419
      * @throws \EE_Error
420 420
      */
421
-	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
422
-		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
421
+	public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE) {
422
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted);
423 423
 	}
424 424
 
425 425
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
      * @throws \EE_Error
432 432
      */
433 433
 	public function ID() {
434
-		return $this->get( 'TKT_ID' );
434
+		return $this->get('TKT_ID');
435 435
 	}
436 436
 
437 437
 
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
      * @throws \EE_Error
457 457
      */
458 458
 	public function template() {
459
-		return $this->get_first_related( 'Ticket_Template' );
459
+		return $this->get_first_related('Ticket_Template');
460 460
 	}
461 461
 
462 462
 
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
      * @throws \EE_Error
479 479
      */
480 480
 	public function ticket_price() {
481
-		return $this->get( 'TKT_price' );
481
+		return $this->get('TKT_price');
482 482
 	}
483 483
 
484 484
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
      * @throws \EE_Error
489 489
      */
490 490
 	public function pretty_price() {
491
-		return $this->get_pretty( 'TKT_price' );
491
+		return $this->get_pretty('TKT_price');
492 492
 	}
493 493
 
494 494
 
@@ -510,8 +510,8 @@  discard block
 block discarded – undo
510 510
      * @return float
511 511
      * @throws \EE_Error
512 512
      */
513
-	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
514
-		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
513
+	public function get_ticket_total_with_taxes($no_cache = FALSE) {
514
+		if ($this->_ticket_total_with_taxes === null || $no_cache) {
515 515
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
516 516
 		}
517 517
 		return (float) $this->_ticket_total_with_taxes;
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 
521 521
 
522 522
 	public function ensure_TKT_Price_correct() {
523
-		$this->set( 'TKT_price', EE_Taxes::get_subtotal_for_admin( $this ) );
523
+		$this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
524 524
 		$this->save();
525 525
 	}
526 526
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
      * @throws \EE_Error
532 532
      */
533 533
 	public function get_ticket_subtotal() {
534
-		return EE_Taxes::get_subtotal_for_admin( $this );
534
+		return EE_Taxes::get_subtotal_for_admin($this);
535 535
 	}
536 536
 
537 537
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
      * @throws \EE_Error
544 544
      */
545 545
 	public function get_ticket_taxes_total_for_admin() {
546
-		return EE_Taxes::get_total_taxes_for_admin( $this );
546
+		return EE_Taxes::get_total_taxes_for_admin($this);
547 547
 	}
548 548
 
549 549
 
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
      * @param string $name
555 555
      * @throws \EE_Error
556 556
      */
557
-	public function set_name( $name ) {
558
-		$this->set( 'TKT_name', $name );
557
+	public function set_name($name) {
558
+		$this->set('TKT_name', $name);
559 559
 	}
560 560
 
561 561
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      * @throws \EE_Error
568 568
      */
569 569
 	public function description() {
570
-		return $this->get( 'TKT_description' );
570
+		return $this->get('TKT_description');
571 571
 	}
572 572
 
573 573
 
@@ -578,8 +578,8 @@  discard block
 block discarded – undo
578 578
      * @param string $description
579 579
      * @throws \EE_Error
580 580
      */
581
-	public function set_description( $description ) {
582
-		$this->set( 'TKT_description', $description );
581
+	public function set_description($description) {
582
+		$this->set('TKT_description', $description);
583 583
 	}
584 584
 
585 585
 
@@ -592,8 +592,8 @@  discard block
 block discarded – undo
592 592
      * @return string
593 593
      * @throws \EE_Error
594 594
      */
595
-	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
596
-		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
595
+	public function start_date($dt_frmt = '', $tm_frmt = '') {
596
+		return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt);
597 597
 	}
598 598
 
599 599
 
@@ -605,8 +605,8 @@  discard block
 block discarded – undo
605 605
      * @return void
606 606
      * @throws \EE_Error
607 607
      */
608
-	public function set_start_date( $start_date ) {
609
-		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
608
+	public function set_start_date($start_date) {
609
+		$this->_set_date_time('B', $start_date, 'TKT_start_date');
610 610
 	}
611 611
 
612 612
 
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
      * @return string
620 620
      * @throws \EE_Error
621 621
      */
622
-	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
623
-		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
622
+	public function end_date($dt_frmt = '', $tm_frmt = '') {
623
+		return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt);
624 624
 	}
625 625
 
626 626
 
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
      * @return void
633 633
      * @throws \EE_Error
634 634
      */
635
-	public function set_end_date( $end_date ) {
636
-		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
635
+	public function set_end_date($end_date) {
636
+		$this->_set_date_time('B', $end_date, 'TKT_end_date');
637 637
 	}
638 638
 
639 639
 
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
      * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646 646
      * @throws \EE_Error
647 647
      */
648
-	public function set_end_time( $time ) {
649
-		$this->_set_time_for( $time, 'TKT_end_date' );
648
+	public function set_end_time($time) {
649
+		$this->_set_time_for($time, 'TKT_end_date');
650 650
 	}
651 651
 
652 652
 
@@ -658,8 +658,8 @@  discard block
 block discarded – undo
658 658
      * @return void
659 659
      * @throws \EE_Error
660 660
      */
661
-	public function set_min( $min ) {
662
-		$this->set( 'TKT_min', $min );
661
+	public function set_min($min) {
662
+		$this->set('TKT_min', $min);
663 663
 	}
664 664
 
665 665
 
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
      * @throws \EE_Error
672 672
      */
673 673
 	public function max() {
674
-		return $this->get( 'TKT_max' );
674
+		return $this->get('TKT_max');
675 675
 	}
676 676
 
677 677
 
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
      * @return void
684 684
      * @throws \EE_Error
685 685
      */
686
-	public function set_max( $max ) {
687
-		$this->set( 'TKT_max', $max );
686
+	public function set_max($max) {
687
+		$this->set('TKT_max', $max);
688 688
 	}
689 689
 
690 690
 
@@ -696,8 +696,8 @@  discard block
 block discarded – undo
696 696
      * @return void
697 697
      * @throws \EE_Error
698 698
      */
699
-	public function set_price( $price ) {
700
-		$this->set( 'TKT_price', $price );
699
+	public function set_price($price) {
700
+		$this->set('TKT_price', $price);
701 701
 	}
702 702
 
703 703
 
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
      * @throws \EE_Error
710 710
      */
711 711
 	public function sold() {
712
-		return $this->get_raw( 'TKT_sold' );
712
+		return $this->get_raw('TKT_sold');
713 713
 	}
714 714
 
715 715
 
@@ -721,10 +721,10 @@  discard block
 block discarded – undo
721 721
      * @return void
722 722
      * @throws \EE_Error
723 723
      */
724
-	public function set_sold( $sold ) {
724
+	public function set_sold($sold) {
725 725
 		// sold can not go below zero
726
-		$sold = max( 0, $sold );
727
-		$this->set( 'TKT_sold', $sold );
726
+		$sold = max(0, $sold);
727
+		$this->set('TKT_sold', $sold);
728 728
 	}
729 729
 
730 730
 
@@ -736,13 +736,13 @@  discard block
 block discarded – undo
736 736
      * @return void
737 737
      * @throws \EE_Error
738 738
      */
739
-	public function increase_sold( $qty = 1 ) {
739
+	public function increase_sold($qty = 1) {
740 740
 		$sold = $this->sold() + $qty;
741 741
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
742 742
 		// via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called
743
-		$this->decrease_reserved( $qty, false );
744
-		$this->_increase_sold_for_datetimes( $qty );
745
-		$this->set_sold( $sold );
743
+		$this->decrease_reserved($qty, false);
744
+		$this->_increase_sold_for_datetimes($qty);
745
+		$this->set_sold($sold);
746 746
 	}
747 747
 
748 748
 
@@ -754,12 +754,12 @@  discard block
 block discarded – undo
754 754
      * @return void
755 755
      * @throws \EE_Error
756 756
      */
757
-	protected function _increase_sold_for_datetimes( $qty = 1 ) {
757
+	protected function _increase_sold_for_datetimes($qty = 1) {
758 758
 		$datetimes = $this->datetimes();
759
-		if ( is_array( $datetimes ) ) {
760
-			foreach ( $datetimes as $datetime ) {
761
-				if ( $datetime instanceof EE_Datetime ) {
762
-					$datetime->increase_sold( $qty );
759
+		if (is_array($datetimes)) {
760
+			foreach ($datetimes as $datetime) {
761
+				if ($datetime instanceof EE_Datetime) {
762
+					$datetime->increase_sold($qty);
763 763
 					$datetime->save();
764 764
 				}
765 765
 			}
@@ -775,10 +775,10 @@  discard block
 block discarded – undo
775 775
      * @return void
776 776
      * @throws \EE_Error
777 777
      */
778
-	public function decrease_sold( $qty = 1 ) {
778
+	public function decrease_sold($qty = 1) {
779 779
 		$sold = $this->sold() - $qty;
780
-		$this->_decrease_sold_for_datetimes( $qty );
781
-		$this->set_sold( $sold );
780
+		$this->_decrease_sold_for_datetimes($qty);
781
+		$this->set_sold($sold);
782 782
 	}
783 783
 
784 784
 
@@ -790,12 +790,12 @@  discard block
 block discarded – undo
790 790
      * @return void
791 791
      * @throws \EE_Error
792 792
      */
793
-	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
793
+	protected function _decrease_sold_for_datetimes($qty = 1) {
794 794
 		$datetimes = $this->datetimes();
795
-		if ( is_array( $datetimes ) ) {
796
-			foreach ( $datetimes as $datetime ) {
797
-				if ( $datetime instanceof EE_Datetime ) {
798
-					$datetime->decrease_sold( $qty );
795
+		if (is_array($datetimes)) {
796
+			foreach ($datetimes as $datetime) {
797
+				if ($datetime instanceof EE_Datetime) {
798
+					$datetime->decrease_sold($qty);
799 799
 					$datetime->save();
800 800
 				}
801 801
 			}
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
      * @throws \EE_Error
812 812
      */
813 813
 	public function reserved() {
814
-		return $this->get_raw( 'TKT_reserved' );
814
+		return $this->get_raw('TKT_reserved');
815 815
 	}
816 816
 
817 817
 
@@ -823,10 +823,10 @@  discard block
 block discarded – undo
823 823
      * @return void
824 824
      * @throws \EE_Error
825 825
      */
826
-	public function set_reserved( $reserved ) {
826
+	public function set_reserved($reserved) {
827 827
 		// reserved can not go below zero
828
-		$reserved = max( 0, (int) $reserved );
829
-		$this->set( 'TKT_reserved', $reserved );
828
+		$reserved = max(0, (int) $reserved);
829
+		$this->set('TKT_reserved', $reserved);
830 830
 	}
831 831
 
832 832
 
@@ -838,11 +838,11 @@  discard block
 block discarded – undo
838 838
      * @return void
839 839
      * @throws \EE_Error
840 840
      */
841
-	public function increase_reserved( $qty = 1 ) {
842
-		$qty = absint( $qty );
841
+	public function increase_reserved($qty = 1) {
842
+		$qty = absint($qty);
843 843
 		$reserved = $this->reserved() + $qty;
844
-		$this->_increase_reserved_for_datetimes( $qty );
845
-		$this->set_reserved( $reserved );
844
+		$this->_increase_reserved_for_datetimes($qty);
845
+		$this->set_reserved($reserved);
846 846
 	}
847 847
 
848 848
 
@@ -854,12 +854,12 @@  discard block
 block discarded – undo
854 854
      * @return void
855 855
      * @throws \EE_Error
856 856
      */
857
-	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
857
+	protected function _increase_reserved_for_datetimes($qty = 1) {
858 858
 		$datetimes = $this->datetimes();
859
-		if ( is_array( $datetimes ) ) {
860
-			foreach ( $datetimes as $datetime ) {
861
-				if ( $datetime instanceof EE_Datetime ) {
862
-					$datetime->increase_reserved( $qty );
859
+		if (is_array($datetimes)) {
860
+			foreach ($datetimes as $datetime) {
861
+				if ($datetime instanceof EE_Datetime) {
862
+					$datetime->increase_reserved($qty);
863 863
 					$datetime->save();
864 864
 				}
865 865
 			}
@@ -876,12 +876,12 @@  discard block
 block discarded – undo
876 876
      * @return void
877 877
      * @throws \EE_Error
878 878
      */
879
-	public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) {
880
-		$reserved = $this->reserved() - absint( $qty );
881
-		if ( $adjust_datetimes ) {
882
-			$this->_decrease_reserved_for_datetimes( $qty );
879
+	public function decrease_reserved($qty = 1, $adjust_datetimes = true) {
880
+		$reserved = $this->reserved() - absint($qty);
881
+		if ($adjust_datetimes) {
882
+			$this->_decrease_reserved_for_datetimes($qty);
883 883
 		}
884
-		$this->set_reserved( $reserved );
884
+		$this->set_reserved($reserved);
885 885
 	}
886 886
 
887 887
 
@@ -893,12 +893,12 @@  discard block
 block discarded – undo
893 893
      * @return void
894 894
      * @throws \EE_Error
895 895
      */
896
-	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
896
+	protected function _decrease_reserved_for_datetimes($qty = 1) {
897 897
 		$datetimes = $this->datetimes();
898
-		if ( is_array( $datetimes ) ) {
899
-			foreach ( $datetimes as $datetime ) {
900
-				if ( $datetime instanceof EE_Datetime ) {
901
-					$datetime->decrease_reserved( $qty );
898
+		if (is_array($datetimes)) {
899
+			foreach ($datetimes as $datetime) {
900
+				if ($datetime instanceof EE_Datetime) {
901
+					$datetime->decrease_reserved($qty);
902 902
 					$datetime->save();
903 903
 				}
904 904
 			}
@@ -919,14 +919,14 @@  discard block
 block discarded – undo
919 919
      * @return int
920 920
      * @throws \EE_Error
921 921
      */
922
-	public function qty( $context = '' ) {
923
-		switch ( $context ) {
922
+	public function qty($context = '') {
923
+		switch ($context) {
924 924
 			case 'reg_limit' :
925 925
 				return $this->real_quantity_on_ticket();
926 926
 			case 'saleable' :
927
-				return $this->real_quantity_on_ticket( 'saleable' );
927
+				return $this->real_quantity_on_ticket('saleable');
928 928
 			default:
929
-				return $this->get_raw( 'TKT_qty' );
929
+				return $this->get_raw('TKT_qty');
930 930
 		}
931 931
 	}
932 932
 
@@ -945,15 +945,15 @@  discard block
 block discarded – undo
945 945
      * @return int
946 946
      * @throws \EE_Error
947 947
      */
948
-	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
949
-		$raw = $this->get_raw( 'TKT_qty' );
948
+	public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) {
949
+		$raw = $this->get_raw('TKT_qty');
950 950
 		// return immediately if it's zero
951
-		if ( $raw === 0 ) {
951
+		if ($raw === 0) {
952 952
 			return $raw;
953 953
 		}
954 954
 		//echo "\n\n<br />Ticket: " . $this->name() . '<br />';
955 955
 		// ensure qty doesn't exceed raw value for THIS ticket
956
-		$qty = min( EE_INF, $raw );
956
+		$qty = min(EE_INF, $raw);
957 957
 		//echo "\n . qty: " . $qty . '<br />';
958 958
 		// calculate this ticket's total sales and reservations
959 959
 		$sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
@@ -962,23 +962,23 @@  discard block
 block discarded – undo
962 962
 		//echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
963 963
 		// first we need to calculate the maximum number of tickets available for the datetime
964 964
 		// do we want data for one datetime or all of them ?
965
-		$query_params = $DTT_ID ? array( array( 'DTT_ID' => $DTT_ID ) ) : array();
966
-		$datetimes = $this->datetimes( $query_params );
967
-		if ( is_array( $datetimes ) && ! empty( $datetimes ) ) {
968
-			foreach ( $datetimes as $datetime ) {
969
-				if ( $datetime instanceof EE_Datetime ) {
965
+		$query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array();
966
+		$datetimes = $this->datetimes($query_params);
967
+		if (is_array($datetimes) && ! empty($datetimes)) {
968
+			foreach ($datetimes as $datetime) {
969
+				if ($datetime instanceof EE_Datetime) {
970 970
 					$datetime->refresh_from_db();
971 971
 					//echo "\n . . datetime name: " . $datetime->name() . '<br />';
972 972
 					//echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
973 973
 					// initialize with no restrictions for each datetime
974 974
 					// but adjust datetime qty based on datetime reg limit
975
-					$datetime_qty = min( EE_INF, $datetime->reg_limit() );
975
+					$datetime_qty = min(EE_INF, $datetime->reg_limit());
976 976
 					//echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
977 977
 					//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
978 978
 					// if we want the actual saleable amount, then we need to consider OTHER ticket sales
979 979
 					// and reservations for this datetime, that do NOT include sales and reservations
980 980
 					// for this ticket (so we add $this->sold() and $this->reserved() back in)
981
-					if ( $context === 'saleable' ) {
981
+					if ($context === 'saleable') {
982 982
 						$datetime_qty = max(
983 983
 							$datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
984 984
 							0
@@ -990,16 +990,16 @@  discard block
 block discarded – undo
990 990
 						$datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
991 991
 						//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
992 992
 					}
993
-					$qty = min( $datetime_qty, $qty );
993
+					$qty = min($datetime_qty, $qty);
994 994
 					//echo "\n . . qty: " . $qty . '<br />';
995 995
 				}
996 996
 			}
997 997
 		}
998 998
 		// NOW that we know the  maximum number of tickets available for the datetime
999 999
 		// we can finally factor in the details for this specific ticket
1000
-		if ( $qty > 0 && $context === 'saleable' ) {
1000
+		if ($qty > 0 && $context === 'saleable') {
1001 1001
 			// and subtract the sales for THIS ticket
1002
-			$qty = max( $qty - $sold_and_reserved_for_this_ticket, 0 );
1002
+			$qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1003 1003
 			//echo "\n . qty: " . $qty . '<br />';
1004 1004
 		}
1005 1005
 		//echo "\nFINAL QTY: " . $qty . "<br /><br />";
@@ -1015,14 +1015,14 @@  discard block
 block discarded – undo
1015 1015
 	 * @return void
1016 1016
 	 * @throws \EE_Error
1017 1017
 	 */
1018
-	public function set_qty( $qty ) {
1018
+	public function set_qty($qty) {
1019 1019
 		$datetimes = $this->datetimes();
1020
-		foreach ( $datetimes as $datetime ) {
1021
-			if ( $datetime instanceof EE_Datetime ) {
1022
-				$qty = min( $qty, $datetime->reg_limit() );
1020
+		foreach ($datetimes as $datetime) {
1021
+			if ($datetime instanceof EE_Datetime) {
1022
+				$qty = min($qty, $datetime->reg_limit());
1023 1023
 			}
1024 1024
 		}
1025
-		$this->set( 'TKT_qty', $qty );
1025
+		$this->set('TKT_qty', $qty);
1026 1026
 	}
1027 1027
 
1028 1028
 
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
      * @throws \EE_Error
1035 1035
      */
1036 1036
 	public function uses() {
1037
-		return $this->get( 'TKT_uses' );
1037
+		return $this->get('TKT_uses');
1038 1038
 	}
1039 1039
 
1040 1040
 
@@ -1046,8 +1046,8 @@  discard block
 block discarded – undo
1046 1046
      * @return void
1047 1047
      * @throws \EE_Error
1048 1048
      */
1049
-	public function set_uses( $uses ) {
1050
-		$this->set( 'TKT_uses', $uses );
1049
+	public function set_uses($uses) {
1050
+		$this->set('TKT_uses', $uses);
1051 1051
 	}
1052 1052
 
1053 1053
 
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
      * @throws \EE_Error
1060 1060
      */
1061 1061
 	public function required() {
1062
-		return $this->get( 'TKT_required' );
1062
+		return $this->get('TKT_required');
1063 1063
 	}
1064 1064
 
1065 1065
 
@@ -1071,8 +1071,8 @@  discard block
 block discarded – undo
1071 1071
      * @return void
1072 1072
      * @throws \EE_Error
1073 1073
      */
1074
-	public function set_required( $required ) {
1075
-		$this->set( 'TKT_required', $required );
1074
+	public function set_required($required) {
1075
+		$this->set('TKT_required', $required);
1076 1076
 	}
1077 1077
 
1078 1078
 
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
      * @throws \EE_Error
1085 1085
      */
1086 1086
 	public function taxable() {
1087
-		return $this->get( 'TKT_taxable' );
1087
+		return $this->get('TKT_taxable');
1088 1088
 	}
1089 1089
 
1090 1090
 
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
      * @return void
1097 1097
      * @throws \EE_Error
1098 1098
      */
1099
-	public function set_taxable( $taxable ) {
1100
-		$this->set( 'TKT_taxable', $taxable );
1099
+	public function set_taxable($taxable) {
1100
+		$this->set('TKT_taxable', $taxable);
1101 1101
 	}
1102 1102
 
1103 1103
 
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
      * @throws \EE_Error
1110 1110
      */
1111 1111
 	public function is_default() {
1112
-		return $this->get( 'TKT_is_default' );
1112
+		return $this->get('TKT_is_default');
1113 1113
 	}
1114 1114
 
1115 1115
 
@@ -1121,8 +1121,8 @@  discard block
 block discarded – undo
1121 1121
      * @return void
1122 1122
      * @throws \EE_Error
1123 1123
      */
1124
-	public function set_is_default( $is_default ) {
1125
-		$this->set( 'TKT_is_default', $is_default );
1124
+	public function set_is_default($is_default) {
1125
+		$this->set('TKT_is_default', $is_default);
1126 1126
 	}
1127 1127
 
1128 1128
 
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
      * @throws \EE_Error
1135 1135
      */
1136 1136
 	public function order() {
1137
-		return $this->get( 'TKT_order' );
1137
+		return $this->get('TKT_order');
1138 1138
 	}
1139 1139
 
1140 1140
 
@@ -1146,8 +1146,8 @@  discard block
 block discarded – undo
1146 1146
      * @return void
1147 1147
      * @throws \EE_Error
1148 1148
      */
1149
-	public function set_order( $order ) {
1150
-		$this->set( 'TKT_order', $order );
1149
+	public function set_order($order) {
1150
+		$this->set('TKT_order', $order);
1151 1151
 	}
1152 1152
 
1153 1153
 
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
      * @throws \EE_Error
1160 1160
      */
1161 1161
 	public function row() {
1162
-		return $this->get( 'TKT_row' );
1162
+		return $this->get('TKT_row');
1163 1163
 	}
1164 1164
 
1165 1165
 
@@ -1171,8 +1171,8 @@  discard block
 block discarded – undo
1171 1171
      * @return void
1172 1172
      * @throws \EE_Error
1173 1173
      */
1174
-	public function set_row( $row ) {
1175
-		$this->set( 'TKT_row', $row );
1174
+	public function set_row($row) {
1175
+		$this->set('TKT_row', $row);
1176 1176
 	}
1177 1177
 
1178 1178
 
@@ -1184,7 +1184,7 @@  discard block
 block discarded – undo
1184 1184
      * @throws \EE_Error
1185 1185
      */
1186 1186
 	public function deleted() {
1187
-		return $this->get( 'TKT_deleted' );
1187
+		return $this->get('TKT_deleted');
1188 1188
 	}
1189 1189
 
1190 1190
 
@@ -1196,8 +1196,8 @@  discard block
 block discarded – undo
1196 1196
      * @return void
1197 1197
      * @throws \EE_Error
1198 1198
      */
1199
-	public function set_deleted( $deleted ) {
1200
-		$this->set( 'TKT_deleted', $deleted );
1199
+	public function set_deleted($deleted) {
1200
+		$this->set('TKT_deleted', $deleted);
1201 1201
 	}
1202 1202
 
1203 1203
 
@@ -1209,7 +1209,7 @@  discard block
 block discarded – undo
1209 1209
      * @throws \EE_Error
1210 1210
      */
1211 1211
 	public function parent_ID() {
1212
-		return $this->get( 'TKT_parent' );
1212
+		return $this->get('TKT_parent');
1213 1213
 	}
1214 1214
 
1215 1215
 
@@ -1221,8 +1221,8 @@  discard block
 block discarded – undo
1221 1221
      * @return void
1222 1222
      * @throws \EE_Error
1223 1223
      */
1224
-	public function set_parent_ID( $parent ) {
1225
-		$this->set( 'TKT_parent', $parent );
1224
+	public function set_parent_ID($parent) {
1225
+		$this->set('TKT_parent', $parent);
1226 1226
 	}
1227 1227
 
1228 1228
 
@@ -1235,10 +1235,10 @@  discard block
 block discarded – undo
1235 1235
      */
1236 1236
 	public function name_and_info() {
1237 1237
 		$times = array();
1238
-		foreach ( $this->datetimes() as $datetime ) {
1238
+		foreach ($this->datetimes() as $datetime) {
1239 1239
 			$times[] = $datetime->start_date_and_time();
1240 1240
 		}
1241
-		return $this->name() . ' @ ' . implode( ', ', $times ) . ' for ' . $this->pretty_price();
1241
+		return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price();
1242 1242
 	}
1243 1243
 
1244 1244
 
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
      * @throws \EE_Error
1251 1251
      */
1252 1252
 	public function name() {
1253
-		return $this->get( 'TKT_name' );
1253
+		return $this->get('TKT_name');
1254 1254
 	}
1255 1255
 
1256 1256
 
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
      * @throws \EE_Error
1263 1263
      */
1264 1264
 	public function price() {
1265
-		return $this->get( 'TKT_price' );
1265
+		return $this->get('TKT_price');
1266 1266
 	}
1267 1267
 
1268 1268
 
@@ -1274,8 +1274,8 @@  discard block
 block discarded – undo
1274 1274
      * @return EE_Registration[]|EE_Base_Class[]
1275 1275
      * @throws \EE_Error
1276 1276
      */
1277
-	public function registrations( $query_params = array() ) {
1278
-		return $this->get_many_related( 'Registration', $query_params );
1277
+	public function registrations($query_params = array()) {
1278
+		return $this->get_many_related('Registration', $query_params);
1279 1279
 	}
1280 1280
 
1281 1281
 
@@ -1288,8 +1288,8 @@  discard block
 block discarded – undo
1288 1288
      * @throws \EE_Error
1289 1289
      */
1290 1290
 	public function update_tickets_sold() {
1291
-		$count_regs_for_this_ticket = $this->count_registrations( array( array( 'STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0 ) ) );
1292
-		$this->set_sold( $count_regs_for_this_ticket );
1291
+		$count_regs_for_this_ticket = $this->count_registrations(array(array('STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0)));
1292
+		$this->set_sold($count_regs_for_this_ticket);
1293 1293
 		$this->save();
1294 1294
 		return $count_regs_for_this_ticket;
1295 1295
 	}
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
 	 * @param array $query_params like EEM_Base::get_all's
1302 1302
 	 * @return int
1303 1303
 	 */
1304
-	public function count_registrations( $query_params = array() ) {
1304
+	public function count_registrations($query_params = array()) {
1305 1305
 		return $this->count_related('Registration', $query_params);
1306 1306
 	}
1307 1307
 
@@ -1329,23 +1329,23 @@  discard block
 block discarded – undo
1329 1329
 	public function get_related_event() {
1330 1330
 		//get one datetime to use for getting the event
1331 1331
 		$datetime = $this->first_datetime();
1332
-		if ( ! $datetime instanceof \EE_Datetime ) {
1332
+		if ( ! $datetime instanceof \EE_Datetime) {
1333 1333
 			throw new UnexpectedEntityException(
1334 1334
 				$datetime,
1335 1335
                 'EE_Datetime',
1336 1336
 				sprintf(
1337
-					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1337
+					__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1338 1338
 					$datetime->name()
1339 1339
 				)
1340 1340
 			);
1341 1341
 		}
1342 1342
 		$event = $datetime->event();
1343
-		if ( ! $event instanceof \EE_Event ) {
1343
+		if ( ! $event instanceof \EE_Event) {
1344 1344
 			throw new UnexpectedEntityException(
1345 1345
 				$event,
1346 1346
                 'EE_Event',
1347 1347
 				sprintf(
1348
-					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1348
+					__('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1349 1349
 					$this->name()
1350 1350
 				)
1351 1351
 			);
Please login to merge, or discard this patch.
core/helpers/EEH_Schema.helper.php 2 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
             $VNU_ID
70 70
         );
71 71
         extract($template_args, EXTR_OVERWRITE);
72
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
72
+        include EE_TEMPLATES.'json_linked_data_for_event.template.php';
73 73
     }
74 74
 
75 75
 
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	 * @param string $location
83 83
 	 * @return string
84 84
 	 */
85
-	public static function location( $location = null ) {
86
-		return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
85
+	public static function location($location = null) {
86
+		return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
87 87
 		                              . $location
88 88
 		                              . '</div>' : '';
89 89
 	}
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 	 * @param string $name
99 99
 	 * @return string
100 100
 	 */
101
-	public static function name( $name = null ) {
102
-		return ! empty( $name ) ? '<span itemprop="name">' . $name . '</span>' : '';
101
+	public static function name($name = null) {
102
+		return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : '';
103 103
 	}
104 104
 
105 105
 
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	 * @param EEI_Address $obj_with_address
113 113
 	 * @return string
114 114
 	 */
115
-	public static function streetAddress( EEI_Address $obj_with_address = null ) {
115
+	public static function streetAddress(EEI_Address $obj_with_address = null) {
116 116
 		return $obj_with_address->address() !== null && $obj_with_address->address() !== ''
117
-			? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : '';
117
+			? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : '';
118 118
 	}
119 119
 
120 120
 
@@ -127,14 +127,14 @@  discard block
 block discarded – undo
127 127
 	 * @param EEI_Address $obj_with_address
128 128
 	 * @return string
129 129
 	 */
130
-	public static function postOfficeBoxNumber( EEI_Address $obj_with_address = null ) {
130
+	public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) {
131 131
 		// regex check for some form of PO Box or P.O. Box, etc, etc, etc
132
-		if ( preg_match(
132
+		if (preg_match(
133 133
 			"/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i",
134 134
 			$obj_with_address->address2()
135
-		) ) {
135
+		)) {
136 136
 			return $obj_with_address->address2() !== null && $obj_with_address->address2() !== ''
137
-				? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : '';
137
+				? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : '';
138 138
 		} else {
139 139
 			return $obj_with_address->address2();
140 140
 		}
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
 	 * @param EEI_Address $obj_with_address
151 151
 	 * @return string
152 152
 	 */
153
-	public static function addressLocality( EEI_Address $obj_with_address = null ) {
153
+	public static function addressLocality(EEI_Address $obj_with_address = null) {
154 154
 		return $obj_with_address->city() !== null && $obj_with_address->city() !== ''
155
-			? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : '';
155
+			? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : '';
156 156
 	}
157 157
 
158 158
 
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
 	 * @param EEI_Address $obj_with_address
166 166
 	 * @return string
167 167
 	 */
168
-	public static function addressRegion( EEI_Address $obj_with_address = null ) {
168
+	public static function addressRegion(EEI_Address $obj_with_address = null) {
169 169
 		$state = $obj_with_address->state_name();
170
-		if ( ! empty( $state ) ) {
171
-			return '<span itemprop="addressRegion">' . $state . '</span>';
170
+		if ( ! empty($state)) {
171
+			return '<span itemprop="addressRegion">'.$state.'</span>';
172 172
 		} else {
173 173
 			return '';
174 174
 		}
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
 	 * @param EEI_Address $obj_with_address
185 185
 	 * @return string
186 186
 	 */
187
-	public static function addressCountry( EEI_Address $obj_with_address = null ) {
187
+	public static function addressCountry(EEI_Address $obj_with_address = null) {
188 188
 		$country = $obj_with_address->country_name();
189
-		if ( ! empty( $country ) ) {
190
-			return '<span itemprop="addressCountry">' . $country . '</span>';
189
+		if ( ! empty($country)) {
190
+			return '<span itemprop="addressCountry">'.$country.'</span>';
191 191
 		} else {
192 192
 			return '';
193 193
 		}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @param EEI_Address $obj_with_address
204 204
 	 * @return string
205 205
 	 */
206
-	public static function postalCode( EEI_Address $obj_with_address = null ) {
206
+	public static function postalCode(EEI_Address $obj_with_address = null) {
207 207
 		return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
208 208
 		                                                                              . $obj_with_address->zip()
209 209
 		                                                                              . '</span>' : '';
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 	 * @param string $phone_nmbr
220 220
 	 * @return string
221 221
 	 */
222
-	public static function telephone( $phone_nmbr = null ) {
223
-		return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>'
222
+	public static function telephone($phone_nmbr = null) {
223
+		return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>'
224 224
 			: '';
225 225
 	}
226 226
 
@@ -236,13 +236,13 @@  discard block
 block discarded – undo
236 236
 	 * @param array  $attributes - array of additional link attributes in  attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' )
237 237
 	 * @return string (link)
238 238
 	 */
239
-	public static function url( $url = null, $text = null, $attributes = array() ) {
239
+	public static function url($url = null, $text = null, $attributes = array()) {
240 240
 		$atts = '';
241
-		foreach ( $attributes as $attribute => $value ) {
242
-			$atts .= ' ' . $attribute . '="' . $value . '"';
241
+		foreach ($attributes as $attribute => $value) {
242
+			$atts .= ' '.$attribute.'="'.$value.'"';
243 243
 		}
244 244
 		$text = $text !== null && $text !== '' ? $text : $url;
245
-		return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>'
245
+		return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>'
246 246
 			: '';
247 247
 	}
248 248
 
Please login to merge, or discard this patch.
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -17,62 +17,62 @@  discard block
 block discarded – undo
17 17
 class EEH_Schema {
18 18
 
19 19
 
20
-    /**
21
-     * generates JSON-based linked data for an event
22
-     *
23
-     * @param \EE_Event $event
24
-     */
25
-    public static function add_json_linked_data_for_event(\EE_Event $event)
26
-    {
27
-        $template_args = array(
28
-            'event_permalink' => '',
29
-            'event_name' => '',
30
-            'event_description' => '',
31
-            'event_start' => '',
32
-            'event_end' => '',
33
-            'currency' => '',
34
-            'event_tickets' => array(),
35
-            'venue_name' => '',
36
-            'venue_url' => '',
37
-            'venue_locality' => '',
38
-            'venue_region' => '',
39
-            'event_image' => '',
40
-        );
41
-        $template_args['event_permalink'] = $event->get_permalink();
42
-        $template_args['event_name'] = $event->name();
43
-        $template_args['event_description'] = $event->description();
44
-        $template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM);
45
-        $template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM);
46
-        $template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
47
-        foreach ($event->tickets() as $ticket) {
48
-            $ID = $ticket->ID();
49
-            $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
50
-            $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
51
-            $template_args['event_tickets'][$ID]['price'] = number_format(
52
-                $ticket->price(),
53
-                EE_Registry::instance()->CFG->currency->dec_plc,
54
-                EE_Registry::instance()->CFG->currency->dec_mrk,
55
-                EE_Registry::instance()->CFG->currency->thsnds
56
-            );
57
-        }
58
-        $VNU_ID = espresso_venue_id();
59
-        if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
60
-            $venue = EEH_Venue_View::get_venue($VNU_ID);
61
-            $template_args['venue_name'] = get_the_title($VNU_ID);
62
-            $template_args['venue_url'] = get_permalink($VNU_ID);
63
-            $template_args['venue_locality'] = $venue->city();
64
-            $template_args['venue_region'] = $venue->state_name();
65
-        }
66
-        $template_args['event_image'] = $event->feature_image_url();
67
-        $template_args = apply_filters(
68
-            'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
69
-            $template_args,
70
-            $event,
71
-            $VNU_ID
72
-        );
73
-        extract($template_args, EXTR_OVERWRITE);
74
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
75
-    }
20
+	/**
21
+	 * generates JSON-based linked data for an event
22
+	 *
23
+	 * @param \EE_Event $event
24
+	 */
25
+	public static function add_json_linked_data_for_event(\EE_Event $event)
26
+	{
27
+		$template_args = array(
28
+			'event_permalink' => '',
29
+			'event_name' => '',
30
+			'event_description' => '',
31
+			'event_start' => '',
32
+			'event_end' => '',
33
+			'currency' => '',
34
+			'event_tickets' => array(),
35
+			'venue_name' => '',
36
+			'venue_url' => '',
37
+			'venue_locality' => '',
38
+			'venue_region' => '',
39
+			'event_image' => '',
40
+		);
41
+		$template_args['event_permalink'] = $event->get_permalink();
42
+		$template_args['event_name'] = $event->name();
43
+		$template_args['event_description'] = $event->description();
44
+		$template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM);
45
+		$template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM);
46
+		$template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
47
+		foreach ($event->tickets() as $ticket) {
48
+			$ID = $ticket->ID();
49
+			$template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
50
+			$template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
51
+			$template_args['event_tickets'][$ID]['price'] = number_format(
52
+				$ticket->price(),
53
+				EE_Registry::instance()->CFG->currency->dec_plc,
54
+				EE_Registry::instance()->CFG->currency->dec_mrk,
55
+				EE_Registry::instance()->CFG->currency->thsnds
56
+			);
57
+		}
58
+		$VNU_ID = espresso_venue_id();
59
+		if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
60
+			$venue = EEH_Venue_View::get_venue($VNU_ID);
61
+			$template_args['venue_name'] = get_the_title($VNU_ID);
62
+			$template_args['venue_url'] = get_permalink($VNU_ID);
63
+			$template_args['venue_locality'] = $venue->city();
64
+			$template_args['venue_region'] = $venue->state_name();
65
+		}
66
+		$template_args['event_image'] = $event->feature_image_url();
67
+		$template_args = apply_filters(
68
+			'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
69
+			$template_args,
70
+			$event,
71
+			$VNU_ID
72
+		);
73
+		extract($template_args, EXTR_OVERWRITE);
74
+		include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
75
+	}
76 76
 
77 77
 
78 78
 	/**
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	public static function location( $location = null ) {
88 88
 		return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
89
-		                              . $location
90
-		                              . '</div>' : '';
89
+									  . $location
90
+									  . '</div>' : '';
91 91
 	}
92 92
 
93 93
 
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 */
208 208
 	public static function postalCode( EEI_Address $obj_with_address = null ) {
209 209
 		return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
210
-		                                                                              . $obj_with_address->zip()
211
-		                                                                              . '</span>' : '';
210
+																					  . $obj_with_address->zip()
211
+																					  . '</span>' : '';
212 212
 	}
213 213
 
214 214
 
Please login to merge, or discard this patch.
core/helpers/EEH_Template.helper.php 1 patch
Indentation   +911 added lines, -911 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 /**
6 6
  * Event Espresso
@@ -16,35 +16,35 @@  discard block
 block discarded – undo
16 16
 
17 17
 
18 18
 if ( ! function_exists('espresso_get_template_part')) {
19
-    /**
20
-     * espresso_get_template_part
21
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
22
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
23
-     *
24
-     * @param string $slug The slug name for the generic template.
25
-     * @param string $name The name of the specialised template.
26
-     * @return string        the html output for the formatted money value
27
-     */
28
-    function espresso_get_template_part($slug = null, $name = null)
29
-    {
30
-        EEH_Template::get_template_part($slug, $name);
31
-    }
19
+	/**
20
+	 * espresso_get_template_part
21
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
22
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
23
+	 *
24
+	 * @param string $slug The slug name for the generic template.
25
+	 * @param string $name The name of the specialised template.
26
+	 * @return string        the html output for the formatted money value
27
+	 */
28
+	function espresso_get_template_part($slug = null, $name = null)
29
+	{
30
+		EEH_Template::get_template_part($slug, $name);
31
+	}
32 32
 }
33 33
 
34 34
 
35 35
 if ( ! function_exists('espresso_get_object_css_class')) {
36
-    /**
37
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
38
-     *
39
-     * @param EE_Base_Class $object the EE object the css class is being generated for
40
-     * @param  string       $prefix added to the beginning of the generated class
41
-     * @param  string       $suffix added to the end of the generated class
42
-     * @return string
43
-     */
44
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
45
-    {
46
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
47
-    }
36
+	/**
37
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
38
+	 *
39
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
40
+	 * @param  string       $prefix added to the beginning of the generated class
41
+	 * @param  string       $suffix added to the end of the generated class
42
+	 * @return string
43
+	 */
44
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
45
+	{
46
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
47
+	}
48 48
 }
49 49
 
50 50
 
@@ -59,631 +59,631 @@  discard block
 block discarded – undo
59 59
 class EEH_Template
60 60
 {
61 61
 
62
-    private static $_espresso_themes = array();
63
-
64
-
65
-    /**
66
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
67
-     *
68
-     * @return boolean
69
-     */
70
-    public static function is_espresso_theme()
71
-    {
72
-        return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
73
-    }
74
-
75
-    /**
76
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
77
-     *    load it's functions.php file ( if not already loaded )
78
-     *
79
-     * @return void
80
-     */
81
-    public static function load_espresso_theme_functions()
82
-    {
83
-        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
84
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
85
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
86
-            }
87
-        }
88
-    }
89
-
90
-
91
-    /**
92
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
93
-     *
94
-     * @return array
95
-     */
96
-    public static function get_espresso_themes()
97
-    {
98
-        if (empty(EEH_Template::$_espresso_themes)) {
99
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
100
-            if (empty($espresso_themes)) {
101
-                return array();
102
-            }
103
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
104
-                unset($espresso_themes[$key]);
105
-            }
106
-            EEH_Template::$_espresso_themes = array();
107
-            foreach ($espresso_themes as $espresso_theme) {
108
-                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
109
-            }
110
-        }
111
-        return EEH_Template::$_espresso_themes;
112
-    }
113
-
114
-
115
-    /**
116
-     * EEH_Template::get_template_part
117
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
118
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
119
-     * filtering based off of the entire template part name
120
-     *
121
-     * @param string $slug The slug name for the generic template.
122
-     * @param string $name The name of the specialised template.
123
-     * @param array  $template_args
124
-     * @param bool   $return_string
125
-     * @return string        the html output for the formatted money value
126
-     */
127
-    public static function get_template_part(
128
-        $slug = null,
129
-        $name = null,
130
-        $template_args = array(),
131
-        $return_string = false
132
-    ) {
133
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
134
-        $templates = array();
135
-        $name      = (string)$name;
136
-        if ($name != '') {
137
-            $templates[] = "{$slug}-{$name}.php";
138
-        }
139
-        // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
140
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
141
-            EEH_Template::locate_template($templates, $template_args, true, $return_string);
142
-        }
143
-    }
144
-
145
-
146
-    /**
147
-     *    locate_template
148
-     *    locate a template file by looking in the following places, in the following order:
149
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
150
-     *        <assumed full absolute server path>
151
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
152
-     *        <server path up to>/wp-content/uploads/espresso/templates/
153
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
154
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
155
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
156
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
157
-     *        Example:
158
-     *          You are using the WordPress Twenty Sixteen theme,
159
-     *        and you want to customize the "some-event.template.php" template,
160
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
161
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
162
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
163
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
164
-     *        /relative/path/to/some-event.template.php
165
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
166
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
167
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
168
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
169
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
170
-     *          Had you passed an absolute path to your template that was in some other location,
171
-     *        ie: "/absolute/path/to/some-event.template.php"
172
-     *          then the search would have been :
173
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
174
-     *        /absolute/path/to/some-event.template.php
175
-     *          and stopped there upon finding it in the second location
176
-     *
177
-     * @param array|string $templates       array of template file names including extension (or just a single string)
178
-     * @param  array       $template_args   an array of arguments to be extracted for use in the template
179
-     * @param  boolean     $load            whether to pass the located template path on to the
180
-     *                                      EEH_Template::display_template() method or simply return it
181
-     * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
182
-     *                                      string
183
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
184
-     *                                      generate a custom template or not. Used in places where you don't actually
185
-     *                                      load the template, you just want to know if there's a custom version of it.
186
-     * @return mixed
187
-     */
188
-    public static function locate_template(
189
-        $templates = array(),
190
-        $template_args = array(),
191
-        $load = true,
192
-        $return_string = true,
193
-        $check_if_custom = false
194
-    ) {
195
-        // first use WP locate_template to check for template in the current theme folder
196
-        $template_path = locate_template($templates);
197
-
198
-        if ($check_if_custom && ! empty($template_path)) {
199
-            return true;
200
-        }
201
-
202
-        // not in the theme
203
-        if (empty($template_path)) {
204
-            // not even a template to look for ?
205
-            if (empty($templates)) {
206
-                // get post_type
207
-                $post_type = EE_Registry::instance()->REQ->get('post_type');
208
-                // get array of EE Custom Post Types
209
-                $EE_CPTs = EE_Register_CPTs::get_CPTs();
210
-                // build template name based on request
211
-                if (isset($EE_CPTs[$post_type])) {
212
-                    $archive_or_single = is_archive() ? 'archive' : '';
213
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
214
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
215
-                }
216
-            }
217
-            // currently active EE template theme
218
-            $current_theme = EE_Config::get_current_theme();
219
-
220
-            // array of paths to folders that may contain templates
221
-            $template_folder_paths = array(
222
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
223
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
224
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
225
-                EVENT_ESPRESSO_TEMPLATE_DIR,
226
-            );
227
-
228
-            //add core plugin folders for checking only if we're not $check_if_custom
229
-            if ( ! $check_if_custom) {
230
-                $core_paths            = array(
231
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
232
-                    EE_PUBLIC . $current_theme,
233
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
234
-                    EE_TEMPLATES . $current_theme,
235
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
236
-                    EE_PLUGIN_DIR_PATH,
237
-                );
238
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
239
-            }
240
-
241
-            // now filter that array
242
-            $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths',
243
-                $template_folder_paths);
244
-            $templates             = is_array($templates) ? $templates : array($templates);
245
-            $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
246
-            // array to hold all possible template paths
247
-            $full_template_paths = array();
248
-
249
-            // loop through $templates
250
-            foreach ($templates as $template) {
251
-                // normalize directory separators
252
-                $template                      = EEH_File::standardise_directory_separators($template);
253
-                $file_name                     = basename($template);
254
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
255
-                // while looping through all template folder paths
256
-                foreach ($template_folder_paths as $template_folder_path) {
257
-                    // normalize directory separators
258
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
259
-                    // determine if any common base path exists between the two paths
260
-                    $common_base_path = EEH_Template::_find_common_base_path(
261
-                        array($template_folder_path, $template_path_minus_file_name)
262
-                    );
263
-                    if ($common_base_path !== '') {
264
-                        // both paths have a common base, so just tack the filename onto our search path
265
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
266
-                    } else {
267
-                        // no common base path, so let's just concatenate
268
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
269
-                    }
270
-                    // build up our template locations array by adding our resolved paths
271
-                    $full_template_paths[] = $resolved_path;
272
-                }
273
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
274
-                array_unshift($full_template_paths, $template);
275
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
276
-                array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
277
-            }
278
-            // filter final array of full template paths
279
-            $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths',
280
-                $full_template_paths, $file_name);
281
-            // now loop through our final array of template location paths and check each location
282
-            foreach ((array)$full_template_paths as $full_template_path) {
283
-                if (is_readable($full_template_path)) {
284
-                    $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
285
-                    // hook that can be used to display the full template path that will be used
286
-                    do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
287
-                    break;
288
-                }
289
-            }
290
-        }
291
-        // if we got it and you want to see it...
292
-        if ($template_path && $load && ! $check_if_custom) {
293
-            if ($return_string) {
294
-                return EEH_Template::display_template($template_path, $template_args, true);
295
-            } else {
296
-                EEH_Template::display_template($template_path, $template_args, false);
297
-            }
298
-        }
299
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
300
-    }
301
-
302
-
303
-    /**
304
-     * _find_common_base_path
305
-     * given two paths, this determines if there is a common base path between the two
306
-     *
307
-     * @param array $paths
308
-     * @return string
309
-     */
310
-    protected static function _find_common_base_path($paths)
311
-    {
312
-        $last_offset      = 0;
313
-        $common_base_path = '';
314
-        while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
315
-            $dir_length = $index - $last_offset + 1;
316
-            $directory  = substr($paths[0], $last_offset, $dir_length);
317
-            foreach ($paths as $path) {
318
-                if (substr($path, $last_offset, $dir_length) != $directory) {
319
-                    return $common_base_path;
320
-                }
321
-            }
322
-            $common_base_path .= $directory;
323
-            $last_offset = $index + 1;
324
-        }
325
-        return substr($common_base_path, 0, -1);
326
-    }
327
-
328
-
329
-    /**
330
-     * load and display a template
331
-     *
332
-     * @param bool|string $template_path server path to the file to be loaded, including file name and extension
333
-     * @param  array      $template_args an array of arguments to be extracted for use in the template
334
-     * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
335
-     * @return mixed string
336
-     */
337
-    public static function display_template($template_path = false, $template_args = array(), $return_string = false)
338
-    {
339
-
340
-        /**
341
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
342
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
343
-         * the display_template method are templates we DON'T want modified (usually because of js
344
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
345
-         * using this.
346
-         *
347
-         * @since 4.6.0
348
-         */
349
-        $template_path = apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
350
-        $template_args = apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
351
-
352
-        // you gimme nuttin - YOU GET NUTTIN !!
353
-        if ( ! $template_path || ! is_readable($template_path)) {
354
-            return '';
355
-        }
356
-        // if $template_args are not in an array, then make it so
357
-        if ( ! is_array($template_args) && ! is_object($template_args)) {
358
-            $template_args = array($template_args);
359
-        }
360
-        extract((array)$template_args);
361
-
362
-        if ($return_string) {
363
-            // because we want to return a string, we are going to capture the output
364
-            ob_start();
365
-            include($template_path);
366
-            return ob_get_clean();
367
-        } else {
368
-            include($template_path);
369
-        }
370
-        return '';
371
-    }
372
-
373
-
374
-    /**
375
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
376
-     *
377
-     * @param EE_Base_Class $object the EE object the css class is being generated for
378
-     * @param  string       $prefix added to the beginning of the generated class
379
-     * @param  string       $suffix added to the end of the generated class
380
-     * @return string
381
-     */
382
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
383
-    {
384
-        // in the beginning...
385
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
386
-        // da muddle
387
-        $class = '';
388
-        // the end
389
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
390
-        // is the passed object an EE object ?
391
-        if ($object instanceof EE_Base_Class) {
392
-            // grab the exact type of object
393
-            $obj_class = get_class($object);
394
-            // depending on the type of object...
395
-            switch ($obj_class) {
396
-                // no specifics just yet...
397
-                default :
398
-                    $class = strtolower(str_replace('_', '-', $obj_class));
399
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
400
-
401
-            }
402
-        }
403
-        return $prefix . $class . $suffix;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * EEH_Template::format_currency
410
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
411
-     * the country currency settings from the supplied country ISO code
412
-     *
413
-     * @param  float   $amount       raw money value
414
-     * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
415
-     * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
416
-     * @param string   $CNT_ISO      2 letter ISO code for a country
417
-     * @param string   $cur_code_span_class
418
-     * @return string        the html output for the formatted money value
419
-     * @throws \EE_Error
420
-     */
421
-    public static function format_currency(
422
-        $amount = null,
423
-        $return_raw = false,
424
-        $display_code = true,
425
-        $CNT_ISO = '',
426
-        $cur_code_span_class = 'currency-code'
427
-    ) {
428
-        // ensure amount was received
429
-        if ($amount === null) {
430
-            $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
431
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
432
-            return '';
433
-        }
434
-        //ensure amount is float
435
-        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount);
436
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
437
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
438
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
439
-        // still a number or was amount converted to a string like "free" ?
440
-        if (is_float($amount_formatted)) {
441
-            // was a country ISO code passed ? if so generate currency config object for that country
442
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
443
-            // verify results
444
-            if ( ! $mny instanceof EE_Currency_Config) {
445
-                // set default config country currency settings
446
-                $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
447
-                    ? EE_Registry::instance()->CFG->currency
448
-                    : new EE_Currency_Config();
449
-            }
450
-            // format float
451
-            $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
452
-            // add formatting ?
453
-            if ( ! $return_raw) {
454
-                // add currency sign
455
-                if ($mny->sign_b4) {
456
-                    if ($amount >= 0) {
457
-                        $amount_formatted = $mny->sign . $amount_formatted;
458
-                    } else {
459
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
460
-                    }
461
-
462
-                } else {
463
-                    $amount_formatted = $amount_formatted . $mny->sign;
464
-                }
465
-
466
-                // filter to allow global setting of display_code
467
-                $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
468
-
469
-                // add currency code ?
470
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
471
-            }
472
-            // filter results
473
-            $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted',
474
-                $amount_formatted, $mny, $return_raw);
475
-        }
476
-        // clean up vars
477
-        unset($mny);
478
-        // return formatted currency amount
479
-        return $amount_formatted;
480
-    }
481
-
482
-
483
-    /**
484
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
485
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
486
-     * related status model or model object (i.e. in documentation etc.)
487
-     *
488
-     * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
489
-     *                            match, then 'Unknown' will be returned.
490
-     * @param  boolean $plural    Whether to return plural or not
491
-     * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
492
-     * @return string             The localized label for the status id.
493
-     */
494
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
495
-    {
496
-        /** @type EEM_Status $EEM_Status */
497
-        $EEM_Status = EE_Registry::instance()->load_model('Status');
498
-        $status     = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural,
499
-            $schema);
500
-        return $status[$status_id];
501
-    }
502
-
503
-
504
-    /**
505
-     * This helper just returns a button or link for the given parameters
506
-     *
507
-     * @param  string $url   the url for the link
508
-     * @param  string $label What is the label you want displayed for the button
509
-     * @param  string $class what class is used for the button (defaults to 'button-primary')
510
-     * @param string  $icon
511
-     * @param string  $title
512
-     * @return string the html output for the button
513
-     */
514
-    public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
515
-    {
516
-        $icon_html = '';
517
-        if ( ! empty($icon)) {
518
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
519
-            $dashicons = array_filter($dashicons);
520
-            $count     = count($dashicons);
521
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
522
-            foreach ($dashicons as $dashicon) {
523
-                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
524
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
525
-            }
526
-            $icon_html .= $count > 1 ? '</span>' : '';
527
-        }
528
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
529
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
530
-        return $button;
531
-    }
532
-
533
-
534
-    /**
535
-     * This returns a generated link that will load the related help tab on admin pages.
536
-     *
537
-     * @param  string     $help_tab_id the id for the connected help tab
538
-     * @param bool|string $page        The page identifier for the page the help tab is on
539
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
540
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
541
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
542
-     * @return string              generated link
543
-     */
544
-    public static function get_help_tab_link(
545
-        $help_tab_id,
546
-        $page = false,
547
-        $action = false,
548
-        $icon_style = false,
549
-        $help_text = false
550
-    ) {
551
-
552
-        if ( ! $page) {
553
-            $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
554
-        }
555
-
556
-        if ( ! $action) {
557
-            $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
558
-        }
559
-
560
-        $action = empty($action) ? 'default' : $action;
561
-
562
-
563
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
564
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
565
-        $help_text    = ! $help_text ? '' : $help_text;
566
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
567
-                'event_espresso') . '" > ' . $help_text . ' </a>';
568
-    }
569
-
570
-
571
-    /**
572
-     * This helper generates the html structure for the jquery joyride plugin with the given params.
573
-     *
574
-     * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
575
-     * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
576
-     * @param EE_Help_Tour
577
-     * @return string         html
578
-     */
579
-    public static function help_tour_stops_generator(EE_Help_Tour $tour)
580
-    {
581
-        $id    = $tour->get_slug();
582
-        $stops = $tour->get_stops();
583
-
584
-        $content = '<ol style="display:none" id="' . $id . '">';
585
-
586
-        foreach ($stops as $stop) {
587
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
588
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
589
-
590
-            //if container is set to modal then let's make sure we set the options accordingly
591
-            if (empty($data_id) && empty($data_class)) {
592
-                $stop['options']['modal']  = true;
593
-                $stop['options']['expose'] = true;
594
-            }
595
-
596
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
597
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
598
-            $inner_content = isset($stop['content']) ? $stop['content'] : '';
599
-
600
-            //options
601
-            if (isset($stop['options']) && is_array($stop['options'])) {
602
-                $options = ' data-options="';
603
-                foreach ($stop['options'] as $option => $value) {
604
-                    $options .= $option . ':' . $value . ';';
605
-                }
606
-                $options .= '"';
607
-            } else {
608
-                $options = '';
609
-            }
610
-
611
-            //let's put all together
612
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
613
-        }
614
-
615
-        $content .= '</ol>';
616
-        return $content;
617
-    }
618
-
619
-
620
-    /**
621
-     * This is a helper method to generate a status legend for a given status array.
622
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
623
-     * status_array.
624
-     *
625
-     * @param  array  $status_array  array of statuses that will make up the legend. In format:
626
-     *                               array(
627
-     *                               'status_item' => 'status_name'
628
-     *                               )
629
-     * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
630
-     *                               the legend.
631
-     * @throws EE_Error
632
-     * @return string               html structure for status.
633
-     */
634
-    public static function status_legend($status_array, $active_status = '')
635
-    {
636
-        if ( ! is_array($status_array)) {
637
-            throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
638
-                'event_espresso'));
639
-        }
640
-
641
-        $setup_array = array();
642
-        foreach ($status_array as $item => $status) {
643
-            $setup_array[$item] = array(
644
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
645
-                'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
646
-                'status' => $status,
647
-            );
648
-        }
649
-
650
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
651
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
652
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
653
-        foreach ($setup_array as $item => $details) {
654
-            $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
655
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
656
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
657
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
658
-            $content .= '</dt>' . "\n";
659
-        }
660
-        $content .= '</dl>' . "\n";
661
-        $content .= '</div>' . "\n";
662
-        return $content;
663
-    }
664
-
665
-
666
-    /**
667
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
668
-     * that's nice for presenting in the wp admin
669
-     *
670
-     * @param mixed $data
671
-     * @return string
672
-     */
673
-    public static function layout_array_as_table($data)
674
-    {
675
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
676
-            $data = (array)$data;
677
-        }
678
-        ob_start();
679
-        if (is_array($data)) {
680
-            if (EEH_Array::is_associative_array($data)) {
681
-                ?>
62
+	private static $_espresso_themes = array();
63
+
64
+
65
+	/**
66
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
67
+	 *
68
+	 * @return boolean
69
+	 */
70
+	public static function is_espresso_theme()
71
+	{
72
+		return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
73
+	}
74
+
75
+	/**
76
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
77
+	 *    load it's functions.php file ( if not already loaded )
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function load_espresso_theme_functions()
82
+	{
83
+		if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
84
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
85
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
86
+			}
87
+		}
88
+	}
89
+
90
+
91
+	/**
92
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
93
+	 *
94
+	 * @return array
95
+	 */
96
+	public static function get_espresso_themes()
97
+	{
98
+		if (empty(EEH_Template::$_espresso_themes)) {
99
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
100
+			if (empty($espresso_themes)) {
101
+				return array();
102
+			}
103
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
104
+				unset($espresso_themes[$key]);
105
+			}
106
+			EEH_Template::$_espresso_themes = array();
107
+			foreach ($espresso_themes as $espresso_theme) {
108
+				EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
109
+			}
110
+		}
111
+		return EEH_Template::$_espresso_themes;
112
+	}
113
+
114
+
115
+	/**
116
+	 * EEH_Template::get_template_part
117
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
118
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
119
+	 * filtering based off of the entire template part name
120
+	 *
121
+	 * @param string $slug The slug name for the generic template.
122
+	 * @param string $name The name of the specialised template.
123
+	 * @param array  $template_args
124
+	 * @param bool   $return_string
125
+	 * @return string        the html output for the formatted money value
126
+	 */
127
+	public static function get_template_part(
128
+		$slug = null,
129
+		$name = null,
130
+		$template_args = array(),
131
+		$return_string = false
132
+	) {
133
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
134
+		$templates = array();
135
+		$name      = (string)$name;
136
+		if ($name != '') {
137
+			$templates[] = "{$slug}-{$name}.php";
138
+		}
139
+		// allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
140
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
141
+			EEH_Template::locate_template($templates, $template_args, true, $return_string);
142
+		}
143
+	}
144
+
145
+
146
+	/**
147
+	 *    locate_template
148
+	 *    locate a template file by looking in the following places, in the following order:
149
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
150
+	 *        <assumed full absolute server path>
151
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
152
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
153
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
154
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
155
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
156
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
157
+	 *        Example:
158
+	 *          You are using the WordPress Twenty Sixteen theme,
159
+	 *        and you want to customize the "some-event.template.php" template,
160
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
161
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
162
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
163
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
164
+	 *        /relative/path/to/some-event.template.php
165
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
166
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
167
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
168
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
169
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
170
+	 *          Had you passed an absolute path to your template that was in some other location,
171
+	 *        ie: "/absolute/path/to/some-event.template.php"
172
+	 *          then the search would have been :
173
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
174
+	 *        /absolute/path/to/some-event.template.php
175
+	 *          and stopped there upon finding it in the second location
176
+	 *
177
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
178
+	 * @param  array       $template_args   an array of arguments to be extracted for use in the template
179
+	 * @param  boolean     $load            whether to pass the located template path on to the
180
+	 *                                      EEH_Template::display_template() method or simply return it
181
+	 * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
182
+	 *                                      string
183
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
184
+	 *                                      generate a custom template or not. Used in places where you don't actually
185
+	 *                                      load the template, you just want to know if there's a custom version of it.
186
+	 * @return mixed
187
+	 */
188
+	public static function locate_template(
189
+		$templates = array(),
190
+		$template_args = array(),
191
+		$load = true,
192
+		$return_string = true,
193
+		$check_if_custom = false
194
+	) {
195
+		// first use WP locate_template to check for template in the current theme folder
196
+		$template_path = locate_template($templates);
197
+
198
+		if ($check_if_custom && ! empty($template_path)) {
199
+			return true;
200
+		}
201
+
202
+		// not in the theme
203
+		if (empty($template_path)) {
204
+			// not even a template to look for ?
205
+			if (empty($templates)) {
206
+				// get post_type
207
+				$post_type = EE_Registry::instance()->REQ->get('post_type');
208
+				// get array of EE Custom Post Types
209
+				$EE_CPTs = EE_Register_CPTs::get_CPTs();
210
+				// build template name based on request
211
+				if (isset($EE_CPTs[$post_type])) {
212
+					$archive_or_single = is_archive() ? 'archive' : '';
213
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
214
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
215
+				}
216
+			}
217
+			// currently active EE template theme
218
+			$current_theme = EE_Config::get_current_theme();
219
+
220
+			// array of paths to folders that may contain templates
221
+			$template_folder_paths = array(
222
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
223
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
224
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
225
+				EVENT_ESPRESSO_TEMPLATE_DIR,
226
+			);
227
+
228
+			//add core plugin folders for checking only if we're not $check_if_custom
229
+			if ( ! $check_if_custom) {
230
+				$core_paths            = array(
231
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
232
+					EE_PUBLIC . $current_theme,
233
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
234
+					EE_TEMPLATES . $current_theme,
235
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
236
+					EE_PLUGIN_DIR_PATH,
237
+				);
238
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
239
+			}
240
+
241
+			// now filter that array
242
+			$template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths',
243
+				$template_folder_paths);
244
+			$templates             = is_array($templates) ? $templates : array($templates);
245
+			$template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
246
+			// array to hold all possible template paths
247
+			$full_template_paths = array();
248
+
249
+			// loop through $templates
250
+			foreach ($templates as $template) {
251
+				// normalize directory separators
252
+				$template                      = EEH_File::standardise_directory_separators($template);
253
+				$file_name                     = basename($template);
254
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
255
+				// while looping through all template folder paths
256
+				foreach ($template_folder_paths as $template_folder_path) {
257
+					// normalize directory separators
258
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
259
+					// determine if any common base path exists between the two paths
260
+					$common_base_path = EEH_Template::_find_common_base_path(
261
+						array($template_folder_path, $template_path_minus_file_name)
262
+					);
263
+					if ($common_base_path !== '') {
264
+						// both paths have a common base, so just tack the filename onto our search path
265
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
266
+					} else {
267
+						// no common base path, so let's just concatenate
268
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
269
+					}
270
+					// build up our template locations array by adding our resolved paths
271
+					$full_template_paths[] = $resolved_path;
272
+				}
273
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
274
+				array_unshift($full_template_paths, $template);
275
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
276
+				array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
277
+			}
278
+			// filter final array of full template paths
279
+			$full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths',
280
+				$full_template_paths, $file_name);
281
+			// now loop through our final array of template location paths and check each location
282
+			foreach ((array)$full_template_paths as $full_template_path) {
283
+				if (is_readable($full_template_path)) {
284
+					$template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
285
+					// hook that can be used to display the full template path that will be used
286
+					do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
287
+					break;
288
+				}
289
+			}
290
+		}
291
+		// if we got it and you want to see it...
292
+		if ($template_path && $load && ! $check_if_custom) {
293
+			if ($return_string) {
294
+				return EEH_Template::display_template($template_path, $template_args, true);
295
+			} else {
296
+				EEH_Template::display_template($template_path, $template_args, false);
297
+			}
298
+		}
299
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
300
+	}
301
+
302
+
303
+	/**
304
+	 * _find_common_base_path
305
+	 * given two paths, this determines if there is a common base path between the two
306
+	 *
307
+	 * @param array $paths
308
+	 * @return string
309
+	 */
310
+	protected static function _find_common_base_path($paths)
311
+	{
312
+		$last_offset      = 0;
313
+		$common_base_path = '';
314
+		while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
315
+			$dir_length = $index - $last_offset + 1;
316
+			$directory  = substr($paths[0], $last_offset, $dir_length);
317
+			foreach ($paths as $path) {
318
+				if (substr($path, $last_offset, $dir_length) != $directory) {
319
+					return $common_base_path;
320
+				}
321
+			}
322
+			$common_base_path .= $directory;
323
+			$last_offset = $index + 1;
324
+		}
325
+		return substr($common_base_path, 0, -1);
326
+	}
327
+
328
+
329
+	/**
330
+	 * load and display a template
331
+	 *
332
+	 * @param bool|string $template_path server path to the file to be loaded, including file name and extension
333
+	 * @param  array      $template_args an array of arguments to be extracted for use in the template
334
+	 * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
335
+	 * @return mixed string
336
+	 */
337
+	public static function display_template($template_path = false, $template_args = array(), $return_string = false)
338
+	{
339
+
340
+		/**
341
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
342
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
343
+		 * the display_template method are templates we DON'T want modified (usually because of js
344
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
345
+		 * using this.
346
+		 *
347
+		 * @since 4.6.0
348
+		 */
349
+		$template_path = apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
350
+		$template_args = apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
351
+
352
+		// you gimme nuttin - YOU GET NUTTIN !!
353
+		if ( ! $template_path || ! is_readable($template_path)) {
354
+			return '';
355
+		}
356
+		// if $template_args are not in an array, then make it so
357
+		if ( ! is_array($template_args) && ! is_object($template_args)) {
358
+			$template_args = array($template_args);
359
+		}
360
+		extract((array)$template_args);
361
+
362
+		if ($return_string) {
363
+			// because we want to return a string, we are going to capture the output
364
+			ob_start();
365
+			include($template_path);
366
+			return ob_get_clean();
367
+		} else {
368
+			include($template_path);
369
+		}
370
+		return '';
371
+	}
372
+
373
+
374
+	/**
375
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
376
+	 *
377
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
378
+	 * @param  string       $prefix added to the beginning of the generated class
379
+	 * @param  string       $suffix added to the end of the generated class
380
+	 * @return string
381
+	 */
382
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
383
+	{
384
+		// in the beginning...
385
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
386
+		// da muddle
387
+		$class = '';
388
+		// the end
389
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
390
+		// is the passed object an EE object ?
391
+		if ($object instanceof EE_Base_Class) {
392
+			// grab the exact type of object
393
+			$obj_class = get_class($object);
394
+			// depending on the type of object...
395
+			switch ($obj_class) {
396
+				// no specifics just yet...
397
+				default :
398
+					$class = strtolower(str_replace('_', '-', $obj_class));
399
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
400
+
401
+			}
402
+		}
403
+		return $prefix . $class . $suffix;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * EEH_Template::format_currency
410
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
411
+	 * the country currency settings from the supplied country ISO code
412
+	 *
413
+	 * @param  float   $amount       raw money value
414
+	 * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
415
+	 * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
416
+	 * @param string   $CNT_ISO      2 letter ISO code for a country
417
+	 * @param string   $cur_code_span_class
418
+	 * @return string        the html output for the formatted money value
419
+	 * @throws \EE_Error
420
+	 */
421
+	public static function format_currency(
422
+		$amount = null,
423
+		$return_raw = false,
424
+		$display_code = true,
425
+		$CNT_ISO = '',
426
+		$cur_code_span_class = 'currency-code'
427
+	) {
428
+		// ensure amount was received
429
+		if ($amount === null) {
430
+			$msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
431
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
432
+			return '';
433
+		}
434
+		//ensure amount is float
435
+		$amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount);
436
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
437
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
438
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
439
+		// still a number or was amount converted to a string like "free" ?
440
+		if (is_float($amount_formatted)) {
441
+			// was a country ISO code passed ? if so generate currency config object for that country
442
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
443
+			// verify results
444
+			if ( ! $mny instanceof EE_Currency_Config) {
445
+				// set default config country currency settings
446
+				$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
447
+					? EE_Registry::instance()->CFG->currency
448
+					: new EE_Currency_Config();
449
+			}
450
+			// format float
451
+			$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
452
+			// add formatting ?
453
+			if ( ! $return_raw) {
454
+				// add currency sign
455
+				if ($mny->sign_b4) {
456
+					if ($amount >= 0) {
457
+						$amount_formatted = $mny->sign . $amount_formatted;
458
+					} else {
459
+						$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
460
+					}
461
+
462
+				} else {
463
+					$amount_formatted = $amount_formatted . $mny->sign;
464
+				}
465
+
466
+				// filter to allow global setting of display_code
467
+				$display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
468
+
469
+				// add currency code ?
470
+				$amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
471
+			}
472
+			// filter results
473
+			$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted',
474
+				$amount_formatted, $mny, $return_raw);
475
+		}
476
+		// clean up vars
477
+		unset($mny);
478
+		// return formatted currency amount
479
+		return $amount_formatted;
480
+	}
481
+
482
+
483
+	/**
484
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
485
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
486
+	 * related status model or model object (i.e. in documentation etc.)
487
+	 *
488
+	 * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
489
+	 *                            match, then 'Unknown' will be returned.
490
+	 * @param  boolean $plural    Whether to return plural or not
491
+	 * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
492
+	 * @return string             The localized label for the status id.
493
+	 */
494
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
495
+	{
496
+		/** @type EEM_Status $EEM_Status */
497
+		$EEM_Status = EE_Registry::instance()->load_model('Status');
498
+		$status     = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural,
499
+			$schema);
500
+		return $status[$status_id];
501
+	}
502
+
503
+
504
+	/**
505
+	 * This helper just returns a button or link for the given parameters
506
+	 *
507
+	 * @param  string $url   the url for the link
508
+	 * @param  string $label What is the label you want displayed for the button
509
+	 * @param  string $class what class is used for the button (defaults to 'button-primary')
510
+	 * @param string  $icon
511
+	 * @param string  $title
512
+	 * @return string the html output for the button
513
+	 */
514
+	public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
515
+	{
516
+		$icon_html = '';
517
+		if ( ! empty($icon)) {
518
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
519
+			$dashicons = array_filter($dashicons);
520
+			$count     = count($dashicons);
521
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
522
+			foreach ($dashicons as $dashicon) {
523
+				$type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
524
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
525
+			}
526
+			$icon_html .= $count > 1 ? '</span>' : '';
527
+		}
528
+		$label  = ! empty($icon) ? $icon_html . $label : $label;
529
+		$button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
530
+		return $button;
531
+	}
532
+
533
+
534
+	/**
535
+	 * This returns a generated link that will load the related help tab on admin pages.
536
+	 *
537
+	 * @param  string     $help_tab_id the id for the connected help tab
538
+	 * @param bool|string $page        The page identifier for the page the help tab is on
539
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
540
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
541
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
542
+	 * @return string              generated link
543
+	 */
544
+	public static function get_help_tab_link(
545
+		$help_tab_id,
546
+		$page = false,
547
+		$action = false,
548
+		$icon_style = false,
549
+		$help_text = false
550
+	) {
551
+
552
+		if ( ! $page) {
553
+			$page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
554
+		}
555
+
556
+		if ( ! $action) {
557
+			$action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
558
+		}
559
+
560
+		$action = empty($action) ? 'default' : $action;
561
+
562
+
563
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
564
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
565
+		$help_text    = ! $help_text ? '' : $help_text;
566
+		return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
567
+				'event_espresso') . '" > ' . $help_text . ' </a>';
568
+	}
569
+
570
+
571
+	/**
572
+	 * This helper generates the html structure for the jquery joyride plugin with the given params.
573
+	 *
574
+	 * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
575
+	 * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
576
+	 * @param EE_Help_Tour
577
+	 * @return string         html
578
+	 */
579
+	public static function help_tour_stops_generator(EE_Help_Tour $tour)
580
+	{
581
+		$id    = $tour->get_slug();
582
+		$stops = $tour->get_stops();
583
+
584
+		$content = '<ol style="display:none" id="' . $id . '">';
585
+
586
+		foreach ($stops as $stop) {
587
+			$data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
588
+			$data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
589
+
590
+			//if container is set to modal then let's make sure we set the options accordingly
591
+			if (empty($data_id) && empty($data_class)) {
592
+				$stop['options']['modal']  = true;
593
+				$stop['options']['expose'] = true;
594
+			}
595
+
596
+			$custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
597
+			$button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
598
+			$inner_content = isset($stop['content']) ? $stop['content'] : '';
599
+
600
+			//options
601
+			if (isset($stop['options']) && is_array($stop['options'])) {
602
+				$options = ' data-options="';
603
+				foreach ($stop['options'] as $option => $value) {
604
+					$options .= $option . ':' . $value . ';';
605
+				}
606
+				$options .= '"';
607
+			} else {
608
+				$options = '';
609
+			}
610
+
611
+			//let's put all together
612
+			$content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
613
+		}
614
+
615
+		$content .= '</ol>';
616
+		return $content;
617
+	}
618
+
619
+
620
+	/**
621
+	 * This is a helper method to generate a status legend for a given status array.
622
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
623
+	 * status_array.
624
+	 *
625
+	 * @param  array  $status_array  array of statuses that will make up the legend. In format:
626
+	 *                               array(
627
+	 *                               'status_item' => 'status_name'
628
+	 *                               )
629
+	 * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
630
+	 *                               the legend.
631
+	 * @throws EE_Error
632
+	 * @return string               html structure for status.
633
+	 */
634
+	public static function status_legend($status_array, $active_status = '')
635
+	{
636
+		if ( ! is_array($status_array)) {
637
+			throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
638
+				'event_espresso'));
639
+		}
640
+
641
+		$setup_array = array();
642
+		foreach ($status_array as $item => $status) {
643
+			$setup_array[$item] = array(
644
+				'class'  => 'ee-status-legend ee-status-legend-' . $status,
645
+				'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
646
+				'status' => $status,
647
+			);
648
+		}
649
+
650
+		$content = '<div class="ee-list-table-legend-container">' . "\n";
651
+		$content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
652
+		$content .= '<dl class="ee-list-table-legend">' . "\n\t";
653
+		foreach ($setup_array as $item => $details) {
654
+			$active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
655
+			$content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
656
+			$content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
657
+			$content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
658
+			$content .= '</dt>' . "\n";
659
+		}
660
+		$content .= '</dl>' . "\n";
661
+		$content .= '</div>' . "\n";
662
+		return $content;
663
+	}
664
+
665
+
666
+	/**
667
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
668
+	 * that's nice for presenting in the wp admin
669
+	 *
670
+	 * @param mixed $data
671
+	 * @return string
672
+	 */
673
+	public static function layout_array_as_table($data)
674
+	{
675
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
676
+			$data = (array)$data;
677
+		}
678
+		ob_start();
679
+		if (is_array($data)) {
680
+			if (EEH_Array::is_associative_array($data)) {
681
+				?>
682 682
                 <table class="widefat">
683 683
                     <tbody>
684 684
                     <?php
685
-                    foreach ($data as $data_key => $data_values) {
686
-                        ?>
685
+					foreach ($data as $data_key => $data_values) {
686
+						?>
687 687
                         <tr>
688 688
                             <td>
689 689
                                 <?php echo $data_key; ?>
@@ -693,247 +693,247 @@  discard block
 block discarded – undo
693 693
                             </td>
694 694
                         </tr>
695 695
                         <?php
696
-                    } ?>
696
+					} ?>
697 697
                     </tbody>
698 698
                 </table>
699 699
                 <?php
700
-            } else {
701
-                ?>
700
+			} else {
701
+				?>
702 702
                 <ul>
703 703
                     <?php
704
-                    foreach ($data as $datum) {
705
-                        echo "<li>";
706
-                        echo self::layout_array_as_table($datum);
707
-                        echo "</li>";
708
-                    } ?>
704
+					foreach ($data as $datum) {
705
+						echo "<li>";
706
+						echo self::layout_array_as_table($datum);
707
+						echo "</li>";
708
+					} ?>
709 709
                 </ul>
710 710
                 <?php
711
-            }
712
-        } else {
713
-            //simple value
714
-            echo esc_html($data);
715
-        }
716
-        return ob_get_clean();
717
-    }
718
-
719
-
720
-    /**
721
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
722
-     *
723
-     * @since 4.4.0
724
-     * @see   self:get_paging_html() for argument docs.
725
-     * @param        $total_items
726
-     * @param        $current
727
-     * @param        $per_page
728
-     * @param        $url
729
-     * @param bool   $show_num_field
730
-     * @param string $paged_arg_name
731
-     * @param array  $items_label
732
-     * @return string
733
-     */
734
-    public static function paging_html(
735
-        $total_items,
736
-        $current,
737
-        $per_page,
738
-        $url,
739
-        $show_num_field = true,
740
-        $paged_arg_name = 'paged',
741
-        $items_label = array()
742
-    ) {
743
-        echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name,
744
-            $items_label);
745
-    }
746
-
747
-
748
-    /**
749
-     * A method for generating paging similar to WP_List_Table
750
-     *
751
-     * @since    4.4.0
752
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
753
-     * @param  integer $total_items     How many total items there are to page.
754
-     * @param  integer $current         What the current page is.
755
-     * @param  integer $per_page        How many items per page.
756
-     * @param  string  $url             What the base url for page links is.
757
-     * @param  boolean $show_num_field  Whether to show the input for changing page number.
758
-     * @param  string  $paged_arg_name  The name of the key for the paged query argument.
759
-     * @param  array   $items_label     An array of singular/plural values for the items label:
760
-     *                                  array(
761
-     *                                  'single' => 'item',
762
-     *                                  'plural' => 'items'
763
-     *                                  )
764
-     * @return  string
765
-     */
766
-    public static function get_paging_html(
767
-        $total_items,
768
-        $current,
769
-        $per_page,
770
-        $url,
771
-        $show_num_field = true,
772
-        $paged_arg_name = 'paged',
773
-        $items_label = array()
774
-    ) {
775
-        $page_links     = array();
776
-        $disable_first  = $disable_last = '';
777
-        $total_items    = (int)$total_items;
778
-        $per_page       = (int)$per_page;
779
-        $current        = (int)$current;
780
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
781
-
782
-        //filter items_label
783
-        $items_label = apply_filters(
784
-            'FHEE__EEH_Template__get_paging_html__items_label',
785
-            $items_label
786
-        );
787
-
788
-        if (empty($items_label)
789
-            || ! is_array($items_label)
790
-            || ! isset($items_label['single'])
791
-            || ! isset($items_label['plural'])
792
-        ) {
793
-            $items_label = array(
794
-                'single' => __('1 item', 'event_espresso'),
795
-                'plural' => __('%s items', 'event_espresso'),
796
-            );
797
-        } else {
798
-            $items_label = array(
799
-                'single' => '1 ' . esc_html($items_label['single']),
800
-                'plural' => '%s ' . esc_html($items_label['plural']),
801
-            );
802
-        }
803
-
804
-        $total_pages = ceil($total_items / $per_page);
805
-
806
-        if ($total_pages <= 1) {
807
-            return '';
808
-        }
809
-
810
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
811
-
812
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
813
-
814
-        if ($current === 1) {
815
-            $disable_first = ' disabled';
816
-        }
817
-        if ($current == $total_pages) {
818
-            $disable_last = ' disabled';
819
-        }
820
-
821
-        $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>",
822
-            'first-page' . $disable_first,
823
-            esc_attr__('Go to the first page'),
824
-            esc_url(remove_query_arg($paged_arg_name, $url)),
825
-            '&laquo;'
826
-        );
827
-
828
-        $page_links[] = sprintf(
829
-            '<a class="%s" title="%s" href="%s">%s</a>',
830
-            'prev-page' . $disable_first,
831
-            esc_attr__('Go to the previous page'),
832
-            esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
833
-            '&lsaquo;'
834
-        );
835
-
836
-        if ( ! $show_num_field) {
837
-            $html_current_page = $current;
838
-        } else {
839
-            $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
840
-                esc_attr__('Current page'),
841
-                $current,
842
-                strlen($total_pages)
843
-            );
844
-        }
845
-
846
-        $html_total_pages = sprintf(
847
-            '<span class="total-pages">%s</span>',
848
-            number_format_i18n($total_pages)
849
-        );
850
-        $page_links[]     = sprintf(
851
-            _x('%3$s%1$s of %2$s%4$s', 'paging'),
852
-            $html_current_page,
853
-            $html_total_pages,
854
-            '<span class="paging-input">',
855
-            '</span>'
856
-        );
857
-
858
-        $page_links[] = sprintf(
859
-            '<a class="%s" title="%s" href="%s">%s</a>',
860
-            'next-page' . $disable_last,
861
-            esc_attr__('Go to the next page'),
862
-            esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
863
-            '&rsaquo;'
864
-        );
865
-
866
-        $page_links[] = sprintf(
867
-            '<a class="%s" title="%s" href="%s">%s</a>',
868
-            'last-page' . $disable_last,
869
-            esc_attr__('Go to the last page'),
870
-            esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
871
-            '&raquo;'
872
-        );
873
-
874
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
875
-        // set page class
876
-        if ($total_pages) {
877
-            $page_class = $total_pages < 2 ? ' one-page' : '';
878
-        } else {
879
-            $page_class = ' no-pages';
880
-        }
881
-
882
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
883
-    }
884
-
885
-
886
-    /**
887
-     * @param string $wrap_class
888
-     * @param string $wrap_id
889
-     * @return string
890
-     */
891
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
892
-    {
893
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
894
-        if (
895
-            ! $admin &&
896
-            ! apply_filters(
897
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
898
-                EE_Registry::instance()->CFG->admin->show_reg_footer
899
-            )
900
-        ) {
901
-            return '';
902
-        }
903
-        $tag        = $admin ? 'span' : 'div';
904
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
905
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
906
-        $attributes .= ! empty($wrap_class)
907
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
908
-            : ' class="powered-by-event-espresso-credit"';
909
-        $query_args = array_merge(
910
-            array(
911
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
912
-                'utm_source'   => 'powered_by_event_espresso',
913
-                'utm_medium'   => 'link',
914
-                'utm_campaign' => 'powered_by',
915
-            ),
916
-            $query_args
917
-        );
918
-        $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text',
919
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso');
920
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
921
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
922
-        return (string)apply_filters(
923
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
924
-            sprintf(
925
-                esc_html_x(
926
-                    '%1$sOnline event registration and ticketing powered by %2$s',
927
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
928
-                    'event_espresso'
929
-                ),
930
-                "<{$tag}{$attributes}>",
931
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>"
932
-            ),
933
-            $wrap_class,
934
-            $wrap_id
935
-        );
936
-    }
711
+			}
712
+		} else {
713
+			//simple value
714
+			echo esc_html($data);
715
+		}
716
+		return ob_get_clean();
717
+	}
718
+
719
+
720
+	/**
721
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
722
+	 *
723
+	 * @since 4.4.0
724
+	 * @see   self:get_paging_html() for argument docs.
725
+	 * @param        $total_items
726
+	 * @param        $current
727
+	 * @param        $per_page
728
+	 * @param        $url
729
+	 * @param bool   $show_num_field
730
+	 * @param string $paged_arg_name
731
+	 * @param array  $items_label
732
+	 * @return string
733
+	 */
734
+	public static function paging_html(
735
+		$total_items,
736
+		$current,
737
+		$per_page,
738
+		$url,
739
+		$show_num_field = true,
740
+		$paged_arg_name = 'paged',
741
+		$items_label = array()
742
+	) {
743
+		echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name,
744
+			$items_label);
745
+	}
746
+
747
+
748
+	/**
749
+	 * A method for generating paging similar to WP_List_Table
750
+	 *
751
+	 * @since    4.4.0
752
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
753
+	 * @param  integer $total_items     How many total items there are to page.
754
+	 * @param  integer $current         What the current page is.
755
+	 * @param  integer $per_page        How many items per page.
756
+	 * @param  string  $url             What the base url for page links is.
757
+	 * @param  boolean $show_num_field  Whether to show the input for changing page number.
758
+	 * @param  string  $paged_arg_name  The name of the key for the paged query argument.
759
+	 * @param  array   $items_label     An array of singular/plural values for the items label:
760
+	 *                                  array(
761
+	 *                                  'single' => 'item',
762
+	 *                                  'plural' => 'items'
763
+	 *                                  )
764
+	 * @return  string
765
+	 */
766
+	public static function get_paging_html(
767
+		$total_items,
768
+		$current,
769
+		$per_page,
770
+		$url,
771
+		$show_num_field = true,
772
+		$paged_arg_name = 'paged',
773
+		$items_label = array()
774
+	) {
775
+		$page_links     = array();
776
+		$disable_first  = $disable_last = '';
777
+		$total_items    = (int)$total_items;
778
+		$per_page       = (int)$per_page;
779
+		$current        = (int)$current;
780
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
781
+
782
+		//filter items_label
783
+		$items_label = apply_filters(
784
+			'FHEE__EEH_Template__get_paging_html__items_label',
785
+			$items_label
786
+		);
787
+
788
+		if (empty($items_label)
789
+			|| ! is_array($items_label)
790
+			|| ! isset($items_label['single'])
791
+			|| ! isset($items_label['plural'])
792
+		) {
793
+			$items_label = array(
794
+				'single' => __('1 item', 'event_espresso'),
795
+				'plural' => __('%s items', 'event_espresso'),
796
+			);
797
+		} else {
798
+			$items_label = array(
799
+				'single' => '1 ' . esc_html($items_label['single']),
800
+				'plural' => '%s ' . esc_html($items_label['plural']),
801
+			);
802
+		}
803
+
804
+		$total_pages = ceil($total_items / $per_page);
805
+
806
+		if ($total_pages <= 1) {
807
+			return '';
808
+		}
809
+
810
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
811
+
812
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
813
+
814
+		if ($current === 1) {
815
+			$disable_first = ' disabled';
816
+		}
817
+		if ($current == $total_pages) {
818
+			$disable_last = ' disabled';
819
+		}
820
+
821
+		$page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>",
822
+			'first-page' . $disable_first,
823
+			esc_attr__('Go to the first page'),
824
+			esc_url(remove_query_arg($paged_arg_name, $url)),
825
+			'&laquo;'
826
+		);
827
+
828
+		$page_links[] = sprintf(
829
+			'<a class="%s" title="%s" href="%s">%s</a>',
830
+			'prev-page' . $disable_first,
831
+			esc_attr__('Go to the previous page'),
832
+			esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
833
+			'&lsaquo;'
834
+		);
835
+
836
+		if ( ! $show_num_field) {
837
+			$html_current_page = $current;
838
+		} else {
839
+			$html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
840
+				esc_attr__('Current page'),
841
+				$current,
842
+				strlen($total_pages)
843
+			);
844
+		}
845
+
846
+		$html_total_pages = sprintf(
847
+			'<span class="total-pages">%s</span>',
848
+			number_format_i18n($total_pages)
849
+		);
850
+		$page_links[]     = sprintf(
851
+			_x('%3$s%1$s of %2$s%4$s', 'paging'),
852
+			$html_current_page,
853
+			$html_total_pages,
854
+			'<span class="paging-input">',
855
+			'</span>'
856
+		);
857
+
858
+		$page_links[] = sprintf(
859
+			'<a class="%s" title="%s" href="%s">%s</a>',
860
+			'next-page' . $disable_last,
861
+			esc_attr__('Go to the next page'),
862
+			esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
863
+			'&rsaquo;'
864
+		);
865
+
866
+		$page_links[] = sprintf(
867
+			'<a class="%s" title="%s" href="%s">%s</a>',
868
+			'last-page' . $disable_last,
869
+			esc_attr__('Go to the last page'),
870
+			esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
871
+			'&raquo;'
872
+		);
873
+
874
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
875
+		// set page class
876
+		if ($total_pages) {
877
+			$page_class = $total_pages < 2 ? ' one-page' : '';
878
+		} else {
879
+			$page_class = ' no-pages';
880
+		}
881
+
882
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
883
+	}
884
+
885
+
886
+	/**
887
+	 * @param string $wrap_class
888
+	 * @param string $wrap_id
889
+	 * @return string
890
+	 */
891
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
892
+	{
893
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
894
+		if (
895
+			! $admin &&
896
+			! apply_filters(
897
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
898
+				EE_Registry::instance()->CFG->admin->show_reg_footer
899
+			)
900
+		) {
901
+			return '';
902
+		}
903
+		$tag        = $admin ? 'span' : 'div';
904
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
905
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
906
+		$attributes .= ! empty($wrap_class)
907
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
908
+			: ' class="powered-by-event-espresso-credit"';
909
+		$query_args = array_merge(
910
+			array(
911
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
912
+				'utm_source'   => 'powered_by_event_espresso',
913
+				'utm_medium'   => 'link',
914
+				'utm_campaign' => 'powered_by',
915
+			),
916
+			$query_args
917
+		);
918
+		$powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text',
919
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso');
920
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
921
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
922
+		return (string)apply_filters(
923
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
924
+			sprintf(
925
+				esc_html_x(
926
+					'%1$sOnline event registration and ticketing powered by %2$s',
927
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
928
+					'event_espresso'
929
+				),
930
+				"<{$tag}{$attributes}>",
931
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>"
932
+			),
933
+			$wrap_class,
934
+			$wrap_id
935
+		);
936
+	}
937 937
 
938 938
 
939 939
 } //end EEH_Template class
@@ -950,33 +950,33 @@  discard block
 block discarded – undo
950 950
 
951 951
 
952 952
 if ( ! function_exists('espresso_pagination')) {
953
-    /**
954
-     *    espresso_pagination
955
-     *
956
-     * @access    public
957
-     * @return    void
958
-     */
959
-    function espresso_pagination()
960
-    {
961
-        global $wp_query;
962
-        $big        = 999999999; // need an unlikely integer
963
-        $pagination = paginate_links(
964
-            array(
965
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
966
-                'format'       => '?paged=%#%',
967
-                'current'      => max(1, get_query_var('paged')),
968
-                'total'        => $wp_query->max_num_pages,
969
-                'show_all'     => true,
970
-                'end_size'     => 10,
971
-                'mid_size'     => 6,
972
-                'prev_next'    => true,
973
-                'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
974
-                'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
975
-                'type'         => 'plain',
976
-                'add_args'     => false,
977
-                'add_fragment' => '',
978
-            )
979
-        );
980
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
981
-    }
953
+	/**
954
+	 *    espresso_pagination
955
+	 *
956
+	 * @access    public
957
+	 * @return    void
958
+	 */
959
+	function espresso_pagination()
960
+	{
961
+		global $wp_query;
962
+		$big        = 999999999; // need an unlikely integer
963
+		$pagination = paginate_links(
964
+			array(
965
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
966
+				'format'       => '?paged=%#%',
967
+				'current'      => max(1, get_query_var('paged')),
968
+				'total'        => $wp_query->max_num_pages,
969
+				'show_all'     => true,
970
+				'end_size'     => 10,
971
+				'mid_size'     => 6,
972
+				'prev_next'    => true,
973
+				'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
974
+				'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
975
+				'type'         => 'plain',
976
+				'add_args'     => false,
977
+				'add_fragment' => '',
978
+			)
979
+		);
980
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
981
+	}
982 982
 }
983 983
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Front_Controller.core.php 1 patch
Indentation   +681 added lines, -681 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -22,686 +22,686 @@  discard block
 block discarded – undo
22 22
 final class EE_Front_Controller
23 23
 {
24 24
 
25
-    /**
26
-     *    $_template_path
27
-     * @var    string $_template_path
28
-     * @access    public
29
-     */
30
-    private $_template_path;
31
-
32
-    /**
33
-     *    $_template
34
-     * @var    string $_template
35
-     * @access    public
36
-     */
37
-    private $_template;
38
-
39
-    /**
40
-     * @type  EE_Registry $Registry
41
-     * @access    protected
42
-     */
43
-    protected $Registry;
44
-
45
-    /**
46
-     * @type  EE_Request_Handler $Request_Handler
47
-     * @access    protected
48
-     */
49
-    protected $Request_Handler;
50
-
51
-    /**
52
-     * @type  EE_Module_Request_Router $Module_Request_Router
53
-     * @access    protected
54
-     */
55
-    protected $Module_Request_Router;
56
-
57
-
58
-    /**
59
-     *    class constructor
60
-     *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
61
-     *
62
-     * @access    public
63
-     * @param \EE_Registry              $Registry
64
-     * @param \EE_Request_Handler       $Request_Handler
65
-     * @param \EE_Module_Request_Router $Module_Request_Router
66
-     */
67
-    public function __construct(
68
-        EE_Registry $Registry,
69
-        EE_Request_Handler $Request_Handler,
70
-        EE_Module_Request_Router $Module_Request_Router
71
-    ) {
72
-        $this->Registry              = $Registry;
73
-        $this->Request_Handler       = $Request_Handler;
74
-        $this->Module_Request_Router = $Module_Request_Router;
75
-        // make sure template tags are loaded immediately so that themes don't break
76
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'load_espresso_template_tags'), 10);
77
-        // determine how to integrate WP_Query with the EE models
78
-        add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy'));
79
-        // load other resources and begin to actually run shortcodes and modules
80
-        add_action('wp_loaded', array($this, 'wp_loaded'), 5);
81
-        // analyse the incoming WP request
82
-        add_action('parse_request', array($this, 'get_request'), 1, 1);
83
-        // process any content shortcodes
84
-        add_action('parse_request', array($this, '_initialize_shortcodes'), 5);
85
-        // process request with module factory
86
-        add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
87
-        // before headers sent
88
-        add_action('wp', array($this, 'wp'), 5);
89
-        // load css and js
90
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1);
91
-        // header
92
-        add_action('wp_head', array($this, 'header_meta_tag'), 5);
93
-        add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
94
-        add_filter('template_include', array($this, 'template_include'), 1);
95
-        // display errors
96
-        add_action('loop_start', array($this, 'display_errors'), 2);
97
-        // the content
98
-        // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
99
-        //exclude our private cpt comments
100
-        add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
101
-        //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
102
-        add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
103
-        // action hook EE
104
-        do_action('AHEE__EE_Front_Controller__construct__done', $this);
105
-        // for checking that browser cookies are enabled
106
-        if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) {
107
-            setcookie('ee_cookie_test', uniqid(), time() + 24 * HOUR_IN_SECONDS, '/');
108
-        }
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EE_Request_Handler
114
-     */
115
-    public function Request_Handler()
116
-    {
117
-        return $this->Request_Handler;
118
-    }
119
-
120
-
121
-    /**
122
-     * @return EE_Module_Request_Router
123
-     */
124
-    public function Module_Request_Router()
125
-    {
126
-        return $this->Module_Request_Router;
127
-    }
128
-
129
-
130
-
131
-
132
-
133
-    /***********************************************        INIT ACTION HOOK         ***********************************************/
134
-
135
-
136
-    /**
137
-     *    load_espresso_template_tags - if current theme is an espresso theme, or uses ee theme template parts, then
138
-     *    load it's functions.php file ( if not already loaded )
139
-     *
140
-     * @return void
141
-     */
142
-    public function load_espresso_template_tags()
143
-    {
144
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
145
-            require_once(EE_PUBLIC . 'template_tags.php');
146
-        }
147
-    }
148
-
149
-
150
-    /**
151
-     * filter_wp_comments
152
-     * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
153
-     * widgets/queries done on frontend
154
-     *
155
-     * @param  array $clauses array of comment clauses setup by WP_Comment_Query
156
-     * @return array array of comment clauses with modifications.
157
-     */
158
-    public function filter_wp_comments($clauses)
159
-    {
160
-        global $wpdb;
161
-        if (strpos($clauses['join'], $wpdb->posts) !== false) {
162
-            $cpts = EE_Register_CPTs::get_private_CPTs();
163
-            foreach ($cpts as $cpt => $details) {
164
-                $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
165
-            }
166
-        }
167
-        return $clauses;
168
-    }
169
-
170
-
171
-    /**
172
-     *    employ_CPT_Strategy
173
-     *
174
-     * @access    public
175
-     * @return    void
176
-     */
177
-    public function employ_CPT_Strategy()
178
-    {
179
-        if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) {
180
-            $this->Registry->load_core('CPT_Strategy');
181
-        }
182
-    }
183
-
184
-
185
-    /**
186
-     * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
187
-     *
188
-     * @param  string $url incoming url
189
-     * @return string         final assembled url
190
-     */
191
-    public function maybe_force_admin_ajax_ssl($url)
192
-    {
193
-        if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
194
-            $url = str_replace('http://', 'https://', $url);
195
-        }
196
-        return $url;
197
-    }
198
-
199
-
200
-
201
-
202
-
203
-
204
-    /***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
205
-
206
-
207
-    /**
208
-     *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
209
-     *    default priority init phases have run
210
-     *
211
-     * @access    public
212
-     * @return    void
213
-     */
214
-    public function wp_loaded()
215
-    {
216
-    }
217
-
218
-
219
-
220
-
221
-
222
-    /***********************************************        PARSE_REQUEST HOOK         ***********************************************/
223
-    /**
224
-     *    _get_request
225
-     *
226
-     * @access public
227
-     * @param WP $WP
228
-     * @return void
229
-     */
230
-    public function get_request(WP $WP)
231
-    {
232
-        do_action('AHEE__EE_Front_Controller__get_request__start');
233
-        $this->Request_Handler->parse_request($WP);
234
-        do_action('AHEE__EE_Front_Controller__get_request__complete');
235
-    }
236
-
237
-
238
-    /**
239
-     *    _initialize_shortcodes - calls init method on shortcodes that have been determined to be in the_content for
240
-     *    the currently requested page
241
-     *
242
-     * @access    public
243
-     * @param WP $WP
244
-     * @return    void
245
-     */
246
-    public function _initialize_shortcodes(WP $WP)
247
-    {
248
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this);
249
-        $this->Request_Handler->set_request_vars($WP);
250
-        // grab post_name from request
251
-        $current_post  = apply_filters('FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
252
-            $this->Request_Handler->get('post_name'));
253
-        $show_on_front = get_option('show_on_front');
254
-        // if it's not set, then check if frontpage is blog
255
-        if (empty($current_post)) {
256
-            // yup.. this is the posts page, prepare to load all shortcode modules
257
-            $current_post = 'posts';
258
-            // unless..
259
-            if ($show_on_front === 'page') {
260
-                // some other page is set as the homepage
261
-                $page_on_front = get_option('page_on_front');
262
-                if ($page_on_front) {
263
-                    // k now we need to find the post_name for this page
264
-                    global $wpdb;
265
-                    $page_on_front = $wpdb->get_var(
266
-                        $wpdb->prepare(
267
-                            "SELECT post_name from $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID=%d",
268
-                            $page_on_front
269
-                        )
270
-                    );
271
-                    // set the current post slug to what it actually is
272
-                    $current_post = $page_on_front ? $page_on_front : $current_post;
273
-                }
274
-            }
275
-        }
276
-        // where are posts being displayed ?
277
-        $page_for_posts = EE_Config::get_page_for_posts();
278
-        // in case $current_post is hierarchical like: /parent-page/current-page
279
-        $current_post = basename($current_post);
280
-        // are we on a category page?
281
-        $term_exists = is_array(term_exists($current_post, 'category')) || array_key_exists('category_name',
282
-                $WP->query_vars);
283
-        // make sure shortcodes are set
284
-        if (isset($this->Registry->CFG->core->post_shortcodes)) {
285
-            if ( ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])) {
286
-                $this->Registry->CFG->core->post_shortcodes[$page_for_posts] = array();
287
-            }
288
-            // cycle thru all posts with shortcodes set
289
-            foreach ($this->Registry->CFG->core->post_shortcodes as $post_name => $post_shortcodes) {
290
-                // filter shortcodes so
291
-                $post_shortcodes = apply_filters('FHEE__Front_Controller__initialize_shortcodes__post_shortcodes',
292
-                    $post_shortcodes);
293
-                // now cycle thru shortcodes
294
-                foreach ($post_shortcodes as $shortcode_class => $post_id) {
295
-                    // are we on this page, or on the blog page, or an EE CPT category page ?
296
-                    if ($current_post === $post_name || $term_exists) {
297
-                        // maybe init the shortcode
298
-                        $this->initialize_shortcode_if_active_on_page(
299
-                            $shortcode_class,
300
-                            $current_post,
301
-                            $page_for_posts,
302
-                            $post_id,
303
-                            $term_exists,
304
-                            $WP
305
-                        );
306
-                        // if this is NOT the "Posts page" and we have a valid entry
307
-                        // for the "Posts page" in our tracked post_shortcodes array
308
-                        // but the shortcode is not being tracked for this page
309
-                    } else if (
310
-                        $post_name !== $page_for_posts
311
-                        && isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])
312
-                        && ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts][$shortcode_class])
313
-                    ) {
314
-                        // then remove the "fallback" shortcode processor
315
-                        remove_shortcode($shortcode_class);
316
-                    }
317
-                }
318
-            }
319
-        }
320
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $this);
321
-    }
322
-
323
-
324
-    /**
325
-     * @param string $shortcode_class
326
-     * @param string $current_post
327
-     * @param string $page_for_posts
328
-     * @param int    $post_id
329
-     * @param bool   $term_exists
330
-     * @param WP     $WP
331
-     */
332
-    protected function initialize_shortcode_if_active_on_page(
333
-        $shortcode_class,
334
-        $current_post,
335
-        $page_for_posts,
336
-        $post_id,
337
-        $term_exists,
338
-        $WP
339
-    ) {
340
-        // verify shortcode is in list of registered shortcodes
341
-        if ( ! isset($this->Registry->shortcodes->{$shortcode_class})) {
342
-            if ($current_post !== $page_for_posts && current_user_can('edit_post', $post_id)) {
343
-                EE_Error::add_error(
344
-                    sprintf(
345
-                        __(
346
-                            'The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.',
347
-                            'event_espresso'
348
-                        ),
349
-                        $shortcode_class
350
-                    ),
351
-                    __FILE__,
352
-                    __FUNCTION__,
353
-                    __LINE__
354
-                );
355
-                add_filter('FHEE_run_EE_the_content', '__return_true');
356
-            }
357
-            add_shortcode($shortcode_class, array('EES_Shortcode', 'invalid_shortcode_processor'));
358
-            return;
359
-        }
360
-        // is this : a shortcodes set exclusively for this post, or for the home page, or a category, or a taxonomy ?
361
-        if (
362
-            $term_exists
363
-            || $current_post === $page_for_posts
364
-            || isset($this->Registry->CFG->core->post_shortcodes[$current_post])
365
-        ) {
366
-            // let's pause to reflect on this...
367
-            $sc_reflector = new ReflectionClass('EES_' . $shortcode_class);
368
-            // ensure that class is actually a shortcode
369
-            if (
370
-                defined('WP_DEBUG')
371
-                && WP_DEBUG === true
372
-                && ! $sc_reflector->isSubclassOf('EES_Shortcode')
373
-            ) {
374
-                EE_Error::add_error(
375
-                    sprintf(
376
-                        __(
377
-                            'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
378
-                            'event_espresso'
379
-                        ),
380
-                        $shortcode_class
381
-                    ),
382
-                    __FILE__,
383
-                    __FUNCTION__,
384
-                    __LINE__
385
-                );
386
-                add_filter('FHEE_run_EE_the_content', '__return_true');
387
-                return;
388
-            }
389
-            // and pass the request object to the run method
390
-            $this->Registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
391
-            // fire the shortcode class's run method, so that it can activate resources
392
-            $this->Registry->shortcodes->{$shortcode_class}->run($WP);
393
-        }
394
-    }
395
-
396
-
397
-    /**
398
-     *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
399
-     *
400
-     * @access    public
401
-     * @param   WP_Query $WP_Query
402
-     * @return    void
403
-     */
404
-    public function pre_get_posts($WP_Query)
405
-    {
406
-        // only load Module_Request_Router if this is the main query
407
-        if (
408
-            $this->Module_Request_Router instanceof EE_Module_Request_Router
409
-            && $WP_Query->is_main_query()
410
-        ) {
411
-            // cycle thru module routes
412
-            while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
413
-                // determine module and method for route
414
-                $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
415
-                if ($module instanceof EED_Module) {
416
-                    // get registered view for route
417
-                    $this->_template_path = $this->Module_Request_Router->get_view($route);
418
-                    // grab module name
419
-                    $module_name = $module->module_name();
420
-                    // map the module to the module objects
421
-                    $this->Registry->modules->{$module_name} = $module;
422
-                }
423
-            }
424
-        }
425
-    }
426
-
427
-
428
-
429
-
430
-
431
-    /***********************************************        WP HOOK         ***********************************************/
432
-
433
-
434
-    /**
435
-     *    wp - basically last chance to do stuff before headers sent
436
-     *
437
-     * @access    public
438
-     * @return    void
439
-     */
440
-    public function wp()
441
-    {
442
-    }
443
-
444
-
445
-
446
-    /***********************************************        WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK         ***********************************************/
447
-
448
-
449
-    /**
450
-     *    wp_enqueue_scripts
451
-     *
452
-     * @access    public
453
-     * @return    void
454
-     */
455
-    public function wp_enqueue_scripts()
456
-    {
457
-
458
-        // css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_css', '__return_false' );
459
-        if (apply_filters('FHEE_load_css', true)) {
460
-
461
-            $this->Registry->CFG->template_settings->enable_default_style = true;
462
-            //Load the ThemeRoller styles if enabled
463
-            if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) {
464
-
465
-                //Load custom style sheet if available
466
-                if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) {
467
-                    wp_register_style('espresso_custom_css',
468
-                        EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet,
469
-                        EVENT_ESPRESSO_VERSION);
470
-                    wp_enqueue_style('espresso_custom_css');
471
-                }
472
-
473
-                if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) {
474
-                    wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css',
475
-                        array('dashicons'), EVENT_ESPRESSO_VERSION);
476
-                } else {
477
-                    wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
478
-                        array('dashicons'), EVENT_ESPRESSO_VERSION);
479
-                }
480
-                wp_enqueue_style('espresso_default');
481
-
482
-                if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) {
483
-                    wp_register_style('espresso_style',
484
-                        get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css',
485
-                        array('dashicons', 'espresso_default'));
486
-                } else {
487
-                    wp_register_style('espresso_style',
488
-                        EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css',
489
-                        array('dashicons', 'espresso_default'));
490
-                }
491
-
492
-            }
493
-
494
-        }
495
-
496
-        // js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_js', '__return_false' );
497
-        if (apply_filters('FHEE_load_js', true)) {
498
-
499
-            wp_enqueue_script('jquery');
500
-            //let's make sure that all required scripts have been setup
501
-            if (function_exists('wp_script_is') && ! wp_script_is('jquery')) {
502
-                $msg = sprintf(
503
-                    __('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.',
504
-                        'event_espresso'),
505
-                    '<em><br />',
506
-                    '</em>'
507
-                );
508
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
509
-            }
510
-            // load core js
511
-            wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'),
512
-                EVENT_ESPRESSO_VERSION, true);
513
-            wp_enqueue_script('espresso_core');
514
-            wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
515
-
516
-        }
517
-
518
-        //qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
519
-        if (apply_filters('FHEE_load_qtip', false)) {
520
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
521
-        }
522
-
523
-
524
-        //accounting.js library
525
-        // @link http://josscrowcroft.github.io/accounting.js/
526
-        if (apply_filters('FHEE_load_accounting_js', false)) {
527
-            $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js';
528
-            wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
529
-                array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true);
530
-            wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true);
531
-            wp_enqueue_script('ee-accounting');
532
-
533
-            $currency_config = array(
534
-                'currency' => array(
535
-                    'symbol'    => $this->Registry->CFG->currency->sign,
536
-                    'format'    => array(
537
-                        'pos'  => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s',
538
-                        'neg'  => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s',
539
-                        'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s',
540
-                    ),
541
-                    'decimal'   => $this->Registry->CFG->currency->dec_mrk,
542
-                    'thousand'  => $this->Registry->CFG->currency->thsnds,
543
-                    'precision' => $this->Registry->CFG->currency->dec_plc,
544
-                ),
545
-                'number'   => array(
546
-                    'precision' => 0,
547
-                    'thousand'  => $this->Registry->CFG->currency->thsnds,
548
-                    'decimal'   => $this->Registry->CFG->currency->dec_mrk,
549
-                ),
550
-            );
551
-            wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config);
552
-        }
553
-
554
-        if ( ! function_exists('wp_head')) {
555
-            $msg = sprintf(
556
-                __('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
557
-                    'event_espresso'),
558
-                '<em><br />',
559
-                '</em>'
560
-            );
561
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
562
-        }
563
-        if ( ! function_exists('wp_footer')) {
564
-            $msg = sprintf(
565
-                __('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
566
-                    'event_espresso'),
567
-                '<em><br />',
568
-                '</em>'
569
-            );
570
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
571
-        }
572
-
573
-    }
574
-
575
-
576
-    /**
577
-     *    header_meta_tag
578
-     *
579
-     * @access    public
580
-     * @return    void
581
-     */
582
-    public function header_meta_tag()
583
-    {
584
-        print(
585
-            apply_filters(
586
-                'FHEE__EE_Front_Controller__header_meta_tag',
587
-                '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
588
-        );
589
-
590
-        //let's exclude all event type taxonomy term archive pages from search engine indexing
591
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249
592
-        if (
593
-            is_tax('espresso_event_type')
594
-            && get_option( 'blog_public' ) !== '0'
595
-        ) {
596
-            print(
597
-                apply_filters(
598
-                    'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
599
-                    '<meta name="robots" content="noindex,follow" />' . "\n"
600
-                )
601
-            );
602
-        }
603
-    }
604
-
605
-
606
-
607
-    /**
608
-     * wp_print_scripts
609
-     *
610
-     * @return void
611
-     */
612
-    public function wp_print_scripts()
613
-    {
614
-        global $post;
615
-        if (get_post_type() === 'espresso_events' && is_singular()) {
616
-            \EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
617
-        }
618
-    }
619
-
620
-
621
-
622
-    /***********************************************        THE_CONTENT FILTER HOOK         ***********************************************/
623
-
624
-
625
-
626
-    /**
627
-     *    the_content
628
-     *
629
-     * @access    public
630
-     * @param   $the_content
631
-     * @return    string
632
-     */
633
-    // public function the_content( $the_content ) {
634
-    // 	// nothing gets loaded at this point unless other systems turn this hookpoint on by using:  add_filter( 'FHEE_run_EE_the_content', '__return_true' );
635
-    // 	if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) {
636
-    // 	}
637
-    // 	return $the_content;
638
-    // }
639
-
640
-
641
-    /***********************************************        WP_FOOTER         ***********************************************/
642
-
643
-
644
-    /**
645
-     *    display_errors
646
-     *
647
-     * @access    public
648
-     * @return    string
649
-     */
650
-    public function display_errors()
651
-    {
652
-        static $shown_already = false;
653
-        do_action('AHEE__EE_Front_Controller__display_errors__begin');
654
-        if (
655
-            ! $shown_already
656
-            && apply_filters('FHEE__EE_Front_Controller__display_errors', true)
657
-            && is_main_query()
658
-            && ! is_feed()
659
-            && in_the_loop()
660
-            && $this->Request_Handler->is_espresso_page()
661
-        ) {
662
-            echo EE_Error::get_notices();
663
-            $shown_already = true;
664
-            EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
665
-        }
666
-        do_action('AHEE__EE_Front_Controller__display_errors__end');
667
-    }
668
-
669
-
670
-
671
-
672
-
673
-    /***********************************************        UTILITIES         ***********************************************/
674
-    /**
675
-     *    template_include
676
-     *
677
-     * @access    public
678
-     * @param   string $template_include_path
679
-     * @return    string
680
-     */
681
-    public function template_include($template_include_path = null)
682
-    {
683
-        if ($this->Request_Handler->is_espresso_page()) {
684
-            $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
685
-            $template_path        = EEH_Template::locate_template($this->_template_path, array(), false);
686
-            $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
687
-            $this->_template      = basename($this->_template_path);
688
-            return $this->_template_path;
689
-        }
690
-        return $template_include_path;
691
-    }
692
-
693
-
694
-    /**
695
-     *    get_selected_template
696
-     *
697
-     * @access    public
698
-     * @param bool $with_path
699
-     * @return    string
700
-     */
701
-    public function get_selected_template($with_path = false)
702
-    {
703
-        return $with_path ? $this->_template_path : $this->_template;
704
-    }
25
+	/**
26
+	 *    $_template_path
27
+	 * @var    string $_template_path
28
+	 * @access    public
29
+	 */
30
+	private $_template_path;
31
+
32
+	/**
33
+	 *    $_template
34
+	 * @var    string $_template
35
+	 * @access    public
36
+	 */
37
+	private $_template;
38
+
39
+	/**
40
+	 * @type  EE_Registry $Registry
41
+	 * @access    protected
42
+	 */
43
+	protected $Registry;
44
+
45
+	/**
46
+	 * @type  EE_Request_Handler $Request_Handler
47
+	 * @access    protected
48
+	 */
49
+	protected $Request_Handler;
50
+
51
+	/**
52
+	 * @type  EE_Module_Request_Router $Module_Request_Router
53
+	 * @access    protected
54
+	 */
55
+	protected $Module_Request_Router;
56
+
57
+
58
+	/**
59
+	 *    class constructor
60
+	 *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
61
+	 *
62
+	 * @access    public
63
+	 * @param \EE_Registry              $Registry
64
+	 * @param \EE_Request_Handler       $Request_Handler
65
+	 * @param \EE_Module_Request_Router $Module_Request_Router
66
+	 */
67
+	public function __construct(
68
+		EE_Registry $Registry,
69
+		EE_Request_Handler $Request_Handler,
70
+		EE_Module_Request_Router $Module_Request_Router
71
+	) {
72
+		$this->Registry              = $Registry;
73
+		$this->Request_Handler       = $Request_Handler;
74
+		$this->Module_Request_Router = $Module_Request_Router;
75
+		// make sure template tags are loaded immediately so that themes don't break
76
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'load_espresso_template_tags'), 10);
77
+		// determine how to integrate WP_Query with the EE models
78
+		add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy'));
79
+		// load other resources and begin to actually run shortcodes and modules
80
+		add_action('wp_loaded', array($this, 'wp_loaded'), 5);
81
+		// analyse the incoming WP request
82
+		add_action('parse_request', array($this, 'get_request'), 1, 1);
83
+		// process any content shortcodes
84
+		add_action('parse_request', array($this, '_initialize_shortcodes'), 5);
85
+		// process request with module factory
86
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
87
+		// before headers sent
88
+		add_action('wp', array($this, 'wp'), 5);
89
+		// load css and js
90
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1);
91
+		// header
92
+		add_action('wp_head', array($this, 'header_meta_tag'), 5);
93
+		add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
94
+		add_filter('template_include', array($this, 'template_include'), 1);
95
+		// display errors
96
+		add_action('loop_start', array($this, 'display_errors'), 2);
97
+		// the content
98
+		// add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
99
+		//exclude our private cpt comments
100
+		add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
101
+		//make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
102
+		add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
103
+		// action hook EE
104
+		do_action('AHEE__EE_Front_Controller__construct__done', $this);
105
+		// for checking that browser cookies are enabled
106
+		if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) {
107
+			setcookie('ee_cookie_test', uniqid(), time() + 24 * HOUR_IN_SECONDS, '/');
108
+		}
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EE_Request_Handler
114
+	 */
115
+	public function Request_Handler()
116
+	{
117
+		return $this->Request_Handler;
118
+	}
119
+
120
+
121
+	/**
122
+	 * @return EE_Module_Request_Router
123
+	 */
124
+	public function Module_Request_Router()
125
+	{
126
+		return $this->Module_Request_Router;
127
+	}
128
+
129
+
130
+
131
+
132
+
133
+	/***********************************************        INIT ACTION HOOK         ***********************************************/
134
+
135
+
136
+	/**
137
+	 *    load_espresso_template_tags - if current theme is an espresso theme, or uses ee theme template parts, then
138
+	 *    load it's functions.php file ( if not already loaded )
139
+	 *
140
+	 * @return void
141
+	 */
142
+	public function load_espresso_template_tags()
143
+	{
144
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
145
+			require_once(EE_PUBLIC . 'template_tags.php');
146
+		}
147
+	}
148
+
149
+
150
+	/**
151
+	 * filter_wp_comments
152
+	 * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
153
+	 * widgets/queries done on frontend
154
+	 *
155
+	 * @param  array $clauses array of comment clauses setup by WP_Comment_Query
156
+	 * @return array array of comment clauses with modifications.
157
+	 */
158
+	public function filter_wp_comments($clauses)
159
+	{
160
+		global $wpdb;
161
+		if (strpos($clauses['join'], $wpdb->posts) !== false) {
162
+			$cpts = EE_Register_CPTs::get_private_CPTs();
163
+			foreach ($cpts as $cpt => $details) {
164
+				$clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
165
+			}
166
+		}
167
+		return $clauses;
168
+	}
169
+
170
+
171
+	/**
172
+	 *    employ_CPT_Strategy
173
+	 *
174
+	 * @access    public
175
+	 * @return    void
176
+	 */
177
+	public function employ_CPT_Strategy()
178
+	{
179
+		if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) {
180
+			$this->Registry->load_core('CPT_Strategy');
181
+		}
182
+	}
183
+
184
+
185
+	/**
186
+	 * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
187
+	 *
188
+	 * @param  string $url incoming url
189
+	 * @return string         final assembled url
190
+	 */
191
+	public function maybe_force_admin_ajax_ssl($url)
192
+	{
193
+		if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
194
+			$url = str_replace('http://', 'https://', $url);
195
+		}
196
+		return $url;
197
+	}
198
+
199
+
200
+
201
+
202
+
203
+
204
+	/***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
205
+
206
+
207
+	/**
208
+	 *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
209
+	 *    default priority init phases have run
210
+	 *
211
+	 * @access    public
212
+	 * @return    void
213
+	 */
214
+	public function wp_loaded()
215
+	{
216
+	}
217
+
218
+
219
+
220
+
221
+
222
+	/***********************************************        PARSE_REQUEST HOOK         ***********************************************/
223
+	/**
224
+	 *    _get_request
225
+	 *
226
+	 * @access public
227
+	 * @param WP $WP
228
+	 * @return void
229
+	 */
230
+	public function get_request(WP $WP)
231
+	{
232
+		do_action('AHEE__EE_Front_Controller__get_request__start');
233
+		$this->Request_Handler->parse_request($WP);
234
+		do_action('AHEE__EE_Front_Controller__get_request__complete');
235
+	}
236
+
237
+
238
+	/**
239
+	 *    _initialize_shortcodes - calls init method on shortcodes that have been determined to be in the_content for
240
+	 *    the currently requested page
241
+	 *
242
+	 * @access    public
243
+	 * @param WP $WP
244
+	 * @return    void
245
+	 */
246
+	public function _initialize_shortcodes(WP $WP)
247
+	{
248
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this);
249
+		$this->Request_Handler->set_request_vars($WP);
250
+		// grab post_name from request
251
+		$current_post  = apply_filters('FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
252
+			$this->Request_Handler->get('post_name'));
253
+		$show_on_front = get_option('show_on_front');
254
+		// if it's not set, then check if frontpage is blog
255
+		if (empty($current_post)) {
256
+			// yup.. this is the posts page, prepare to load all shortcode modules
257
+			$current_post = 'posts';
258
+			// unless..
259
+			if ($show_on_front === 'page') {
260
+				// some other page is set as the homepage
261
+				$page_on_front = get_option('page_on_front');
262
+				if ($page_on_front) {
263
+					// k now we need to find the post_name for this page
264
+					global $wpdb;
265
+					$page_on_front = $wpdb->get_var(
266
+						$wpdb->prepare(
267
+							"SELECT post_name from $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID=%d",
268
+							$page_on_front
269
+						)
270
+					);
271
+					// set the current post slug to what it actually is
272
+					$current_post = $page_on_front ? $page_on_front : $current_post;
273
+				}
274
+			}
275
+		}
276
+		// where are posts being displayed ?
277
+		$page_for_posts = EE_Config::get_page_for_posts();
278
+		// in case $current_post is hierarchical like: /parent-page/current-page
279
+		$current_post = basename($current_post);
280
+		// are we on a category page?
281
+		$term_exists = is_array(term_exists($current_post, 'category')) || array_key_exists('category_name',
282
+				$WP->query_vars);
283
+		// make sure shortcodes are set
284
+		if (isset($this->Registry->CFG->core->post_shortcodes)) {
285
+			if ( ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])) {
286
+				$this->Registry->CFG->core->post_shortcodes[$page_for_posts] = array();
287
+			}
288
+			// cycle thru all posts with shortcodes set
289
+			foreach ($this->Registry->CFG->core->post_shortcodes as $post_name => $post_shortcodes) {
290
+				// filter shortcodes so
291
+				$post_shortcodes = apply_filters('FHEE__Front_Controller__initialize_shortcodes__post_shortcodes',
292
+					$post_shortcodes);
293
+				// now cycle thru shortcodes
294
+				foreach ($post_shortcodes as $shortcode_class => $post_id) {
295
+					// are we on this page, or on the blog page, or an EE CPT category page ?
296
+					if ($current_post === $post_name || $term_exists) {
297
+						// maybe init the shortcode
298
+						$this->initialize_shortcode_if_active_on_page(
299
+							$shortcode_class,
300
+							$current_post,
301
+							$page_for_posts,
302
+							$post_id,
303
+							$term_exists,
304
+							$WP
305
+						);
306
+						// if this is NOT the "Posts page" and we have a valid entry
307
+						// for the "Posts page" in our tracked post_shortcodes array
308
+						// but the shortcode is not being tracked for this page
309
+					} else if (
310
+						$post_name !== $page_for_posts
311
+						&& isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])
312
+						&& ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts][$shortcode_class])
313
+					) {
314
+						// then remove the "fallback" shortcode processor
315
+						remove_shortcode($shortcode_class);
316
+					}
317
+				}
318
+			}
319
+		}
320
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $this);
321
+	}
322
+
323
+
324
+	/**
325
+	 * @param string $shortcode_class
326
+	 * @param string $current_post
327
+	 * @param string $page_for_posts
328
+	 * @param int    $post_id
329
+	 * @param bool   $term_exists
330
+	 * @param WP     $WP
331
+	 */
332
+	protected function initialize_shortcode_if_active_on_page(
333
+		$shortcode_class,
334
+		$current_post,
335
+		$page_for_posts,
336
+		$post_id,
337
+		$term_exists,
338
+		$WP
339
+	) {
340
+		// verify shortcode is in list of registered shortcodes
341
+		if ( ! isset($this->Registry->shortcodes->{$shortcode_class})) {
342
+			if ($current_post !== $page_for_posts && current_user_can('edit_post', $post_id)) {
343
+				EE_Error::add_error(
344
+					sprintf(
345
+						__(
346
+							'The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.',
347
+							'event_espresso'
348
+						),
349
+						$shortcode_class
350
+					),
351
+					__FILE__,
352
+					__FUNCTION__,
353
+					__LINE__
354
+				);
355
+				add_filter('FHEE_run_EE_the_content', '__return_true');
356
+			}
357
+			add_shortcode($shortcode_class, array('EES_Shortcode', 'invalid_shortcode_processor'));
358
+			return;
359
+		}
360
+		// is this : a shortcodes set exclusively for this post, or for the home page, or a category, or a taxonomy ?
361
+		if (
362
+			$term_exists
363
+			|| $current_post === $page_for_posts
364
+			|| isset($this->Registry->CFG->core->post_shortcodes[$current_post])
365
+		) {
366
+			// let's pause to reflect on this...
367
+			$sc_reflector = new ReflectionClass('EES_' . $shortcode_class);
368
+			// ensure that class is actually a shortcode
369
+			if (
370
+				defined('WP_DEBUG')
371
+				&& WP_DEBUG === true
372
+				&& ! $sc_reflector->isSubclassOf('EES_Shortcode')
373
+			) {
374
+				EE_Error::add_error(
375
+					sprintf(
376
+						__(
377
+							'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
378
+							'event_espresso'
379
+						),
380
+						$shortcode_class
381
+					),
382
+					__FILE__,
383
+					__FUNCTION__,
384
+					__LINE__
385
+				);
386
+				add_filter('FHEE_run_EE_the_content', '__return_true');
387
+				return;
388
+			}
389
+			// and pass the request object to the run method
390
+			$this->Registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
391
+			// fire the shortcode class's run method, so that it can activate resources
392
+			$this->Registry->shortcodes->{$shortcode_class}->run($WP);
393
+		}
394
+	}
395
+
396
+
397
+	/**
398
+	 *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
399
+	 *
400
+	 * @access    public
401
+	 * @param   WP_Query $WP_Query
402
+	 * @return    void
403
+	 */
404
+	public function pre_get_posts($WP_Query)
405
+	{
406
+		// only load Module_Request_Router if this is the main query
407
+		if (
408
+			$this->Module_Request_Router instanceof EE_Module_Request_Router
409
+			&& $WP_Query->is_main_query()
410
+		) {
411
+			// cycle thru module routes
412
+			while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
413
+				// determine module and method for route
414
+				$module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
415
+				if ($module instanceof EED_Module) {
416
+					// get registered view for route
417
+					$this->_template_path = $this->Module_Request_Router->get_view($route);
418
+					// grab module name
419
+					$module_name = $module->module_name();
420
+					// map the module to the module objects
421
+					$this->Registry->modules->{$module_name} = $module;
422
+				}
423
+			}
424
+		}
425
+	}
426
+
427
+
428
+
429
+
430
+
431
+	/***********************************************        WP HOOK         ***********************************************/
432
+
433
+
434
+	/**
435
+	 *    wp - basically last chance to do stuff before headers sent
436
+	 *
437
+	 * @access    public
438
+	 * @return    void
439
+	 */
440
+	public function wp()
441
+	{
442
+	}
443
+
444
+
445
+
446
+	/***********************************************        WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK         ***********************************************/
447
+
448
+
449
+	/**
450
+	 *    wp_enqueue_scripts
451
+	 *
452
+	 * @access    public
453
+	 * @return    void
454
+	 */
455
+	public function wp_enqueue_scripts()
456
+	{
457
+
458
+		// css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_css', '__return_false' );
459
+		if (apply_filters('FHEE_load_css', true)) {
460
+
461
+			$this->Registry->CFG->template_settings->enable_default_style = true;
462
+			//Load the ThemeRoller styles if enabled
463
+			if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) {
464
+
465
+				//Load custom style sheet if available
466
+				if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) {
467
+					wp_register_style('espresso_custom_css',
468
+						EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet,
469
+						EVENT_ESPRESSO_VERSION);
470
+					wp_enqueue_style('espresso_custom_css');
471
+				}
472
+
473
+				if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) {
474
+					wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css',
475
+						array('dashicons'), EVENT_ESPRESSO_VERSION);
476
+				} else {
477
+					wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
478
+						array('dashicons'), EVENT_ESPRESSO_VERSION);
479
+				}
480
+				wp_enqueue_style('espresso_default');
481
+
482
+				if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) {
483
+					wp_register_style('espresso_style',
484
+						get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css',
485
+						array('dashicons', 'espresso_default'));
486
+				} else {
487
+					wp_register_style('espresso_style',
488
+						EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css',
489
+						array('dashicons', 'espresso_default'));
490
+				}
491
+
492
+			}
493
+
494
+		}
495
+
496
+		// js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_js', '__return_false' );
497
+		if (apply_filters('FHEE_load_js', true)) {
498
+
499
+			wp_enqueue_script('jquery');
500
+			//let's make sure that all required scripts have been setup
501
+			if (function_exists('wp_script_is') && ! wp_script_is('jquery')) {
502
+				$msg = sprintf(
503
+					__('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.',
504
+						'event_espresso'),
505
+					'<em><br />',
506
+					'</em>'
507
+				);
508
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
509
+			}
510
+			// load core js
511
+			wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'),
512
+				EVENT_ESPRESSO_VERSION, true);
513
+			wp_enqueue_script('espresso_core');
514
+			wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
515
+
516
+		}
517
+
518
+		//qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
519
+		if (apply_filters('FHEE_load_qtip', false)) {
520
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
521
+		}
522
+
523
+
524
+		//accounting.js library
525
+		// @link http://josscrowcroft.github.io/accounting.js/
526
+		if (apply_filters('FHEE_load_accounting_js', false)) {
527
+			$acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js';
528
+			wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
529
+				array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true);
530
+			wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true);
531
+			wp_enqueue_script('ee-accounting');
532
+
533
+			$currency_config = array(
534
+				'currency' => array(
535
+					'symbol'    => $this->Registry->CFG->currency->sign,
536
+					'format'    => array(
537
+						'pos'  => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s',
538
+						'neg'  => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s',
539
+						'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s',
540
+					),
541
+					'decimal'   => $this->Registry->CFG->currency->dec_mrk,
542
+					'thousand'  => $this->Registry->CFG->currency->thsnds,
543
+					'precision' => $this->Registry->CFG->currency->dec_plc,
544
+				),
545
+				'number'   => array(
546
+					'precision' => 0,
547
+					'thousand'  => $this->Registry->CFG->currency->thsnds,
548
+					'decimal'   => $this->Registry->CFG->currency->dec_mrk,
549
+				),
550
+			);
551
+			wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config);
552
+		}
553
+
554
+		if ( ! function_exists('wp_head')) {
555
+			$msg = sprintf(
556
+				__('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
557
+					'event_espresso'),
558
+				'<em><br />',
559
+				'</em>'
560
+			);
561
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
562
+		}
563
+		if ( ! function_exists('wp_footer')) {
564
+			$msg = sprintf(
565
+				__('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
566
+					'event_espresso'),
567
+				'<em><br />',
568
+				'</em>'
569
+			);
570
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
571
+		}
572
+
573
+	}
574
+
575
+
576
+	/**
577
+	 *    header_meta_tag
578
+	 *
579
+	 * @access    public
580
+	 * @return    void
581
+	 */
582
+	public function header_meta_tag()
583
+	{
584
+		print(
585
+			apply_filters(
586
+				'FHEE__EE_Front_Controller__header_meta_tag',
587
+				'<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
588
+		);
589
+
590
+		//let's exclude all event type taxonomy term archive pages from search engine indexing
591
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/10249
592
+		if (
593
+			is_tax('espresso_event_type')
594
+			&& get_option( 'blog_public' ) !== '0'
595
+		) {
596
+			print(
597
+				apply_filters(
598
+					'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
599
+					'<meta name="robots" content="noindex,follow" />' . "\n"
600
+				)
601
+			);
602
+		}
603
+	}
604
+
605
+
606
+
607
+	/**
608
+	 * wp_print_scripts
609
+	 *
610
+	 * @return void
611
+	 */
612
+	public function wp_print_scripts()
613
+	{
614
+		global $post;
615
+		if (get_post_type() === 'espresso_events' && is_singular()) {
616
+			\EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
617
+		}
618
+	}
619
+
620
+
621
+
622
+	/***********************************************        THE_CONTENT FILTER HOOK         ***********************************************/
623
+
624
+
625
+
626
+	/**
627
+	 *    the_content
628
+	 *
629
+	 * @access    public
630
+	 * @param   $the_content
631
+	 * @return    string
632
+	 */
633
+	// public function the_content( $the_content ) {
634
+	// 	// nothing gets loaded at this point unless other systems turn this hookpoint on by using:  add_filter( 'FHEE_run_EE_the_content', '__return_true' );
635
+	// 	if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) {
636
+	// 	}
637
+	// 	return $the_content;
638
+	// }
639
+
640
+
641
+	/***********************************************        WP_FOOTER         ***********************************************/
642
+
643
+
644
+	/**
645
+	 *    display_errors
646
+	 *
647
+	 * @access    public
648
+	 * @return    string
649
+	 */
650
+	public function display_errors()
651
+	{
652
+		static $shown_already = false;
653
+		do_action('AHEE__EE_Front_Controller__display_errors__begin');
654
+		if (
655
+			! $shown_already
656
+			&& apply_filters('FHEE__EE_Front_Controller__display_errors', true)
657
+			&& is_main_query()
658
+			&& ! is_feed()
659
+			&& in_the_loop()
660
+			&& $this->Request_Handler->is_espresso_page()
661
+		) {
662
+			echo EE_Error::get_notices();
663
+			$shown_already = true;
664
+			EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
665
+		}
666
+		do_action('AHEE__EE_Front_Controller__display_errors__end');
667
+	}
668
+
669
+
670
+
671
+
672
+
673
+	/***********************************************        UTILITIES         ***********************************************/
674
+	/**
675
+	 *    template_include
676
+	 *
677
+	 * @access    public
678
+	 * @param   string $template_include_path
679
+	 * @return    string
680
+	 */
681
+	public function template_include($template_include_path = null)
682
+	{
683
+		if ($this->Request_Handler->is_espresso_page()) {
684
+			$this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
685
+			$template_path        = EEH_Template::locate_template($this->_template_path, array(), false);
686
+			$this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
687
+			$this->_template      = basename($this->_template_path);
688
+			return $this->_template_path;
689
+		}
690
+		return $template_include_path;
691
+	}
692
+
693
+
694
+	/**
695
+	 *    get_selected_template
696
+	 *
697
+	 * @access    public
698
+	 * @param bool $with_path
699
+	 * @return    string
700
+	 */
701
+	public function get_selected_template($with_path = false)
702
+	{
703
+		return $with_path ? $this->_template_path : $this->_template;
704
+	}
705 705
 
706 706
 
707 707
 }
Please login to merge, or discard this patch.
core/templates/json_linked_data_for_event.template.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@
 block discarded – undo
31 31
       "price": "<?php echo $ticket['price'] ?>",
32 32
       "priceCurrency": "<?php echo $currency ?>"
33 33
     }<?php if (is_array($event_tickets) && end($event_tickets) !== $ticket) { echo ','; }
34
-    }
35
-    ?>
34
+	}
35
+	?>
36 36
     ]<?php if ($venue_name) { ?>,
37 37
   "location": {
38 38
     "@type": "Place",
Please login to merge, or discard this patch.
core/db_classes/EE_Base_Class.class.php 2 patches
Doc Comments   +9 added lines, -8 removed lines patch added patch discarded remove patch
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      *
575 575
      * @param \EE_Datetime_Field $datetime_field
576 576
      * @param bool               $pretty
577
-     * @param null $date_or_time
577
+     * @param string|null $date_or_time
578 578
      * @return void
579 579
      * @throws \EE_Error
580 580
      */
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
      *
893 893
      * @param null  $field_to_order_by  What field is being used as the reference point.
894 894
      * @param array $query_params       Any additional conditions on the query.
895
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
895
+     * @param string  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
896 896
      *                                  you can indicate just the columns you want returned
897 897
      * @return array|EE_Base_Class
898 898
      * @throws \EE_Error
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
      *
918 918
      * @param null  $field_to_order_by  What field is being used as the reference point.
919 919
      * @param array $query_params       Any additional conditions on the query.
920
-     * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
920
+     * @param string  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
921 921
      *                                  you can indicate just the column you want returned
922 922
      * @return array|EE_Base_Class
923 923
      * @throws \EE_Error
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
      * This method simply returns the RAW unprocessed value for the given property in this class
991 991
      *
992 992
      * @param  string $field_name A valid fieldname
993
-     * @return mixed              Whatever the raw value stored on the property is.
993
+     * @return integer|null              Whatever the raw value stored on the property is.
994 994
      * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
995 995
      */
996 996
     public function get_raw($field_name)
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
      * sets the time on a datetime property
1257 1257
      *
1258 1258
      * @access protected
1259
-     * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1259
+     * @param string $time      a valid time string for php datetime functions (or DateTime object)
1260 1260
      * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1261 1261
      * @throws \EE_Error
1262 1262
      */
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
      * sets the date on a datetime property
1272 1272
      *
1273 1273
      * @access protected
1274
-     * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1274
+     * @param string $date      a valid date string for php datetime functions ( or DateTime object)
1275 1275
      * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1276 1276
      * @throws \EE_Error
1277 1277
      */
@@ -1329,6 +1329,7 @@  discard block
 block discarded – undo
1329 1329
      * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1330 1330
      * @param string               $prepend    You can include something to prepend on the timestamp
1331 1331
      * @param string               $append     You can include something to append on the timestamp
1332
+     * @param string $args
1332 1333
      * @throws EE_Error
1333 1334
      * @return string timestamp
1334 1335
      */
@@ -1699,7 +1700,7 @@  discard block
 block discarded – undo
1699 1700
      *
1700 1701
      * @param  array  $props_n_values   incoming array of properties and their values
1701 1702
      * @param  string $classname        the classname of the child class
1702
-     * @param null    $timezone
1703
+     * @param string|null    $timezone
1703 1704
      * @param array   $date_formats     incoming date_formats in an array where the first value is the
1704 1705
      *                                  date_format and the second value is the time format
1705 1706
      * @return mixed (EE_Base_Class|bool)
@@ -1777,7 +1778,7 @@  discard block
 block discarded – undo
1777 1778
      * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1778 1779
      *
1779 1780
      * @param string $model_classname
1780
-     * @param null   $timezone
1781
+     * @param string|null   $timezone
1781 1782
      * @return EEM_Base
1782 1783
      */
1783 1784
     protected static function _get_model_instance_with_name($model_classname, $timezone = null)
Please login to merge, or discard this patch.
Indentation   +2550 added lines, -2550 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 do_action('AHEE_log', __FILE__, ' FILE LOADED', '');
5 5
 
@@ -25,2555 +25,2555 @@  discard block
 block discarded – undo
25 25
 abstract class EE_Base_Class
26 26
 {
27 27
 
28
-    /**
29
-     * This is an array of the original properties and values provided during construction
30
-     * of this model object. (keys are model field names, values are their values).
31
-     * This list is important to remember so that when we are merging data from the db, we know
32
-     * which values to override and which to not override.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $_props_n_values_provided_in_constructor;
37
-
38
-    /**
39
-     * Timezone
40
-     * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings coming out of the object to be in.  NOT all
41
-     * EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have access to it.
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_timezone;
46
-
47
-
48
-
49
-    /**
50
-     * date format
51
-     * pattern or format for displaying dates
52
-     *
53
-     * @var string $_dt_frmt
54
-     */
55
-    protected $_dt_frmt;
56
-
57
-
58
-
59
-    /**
60
-     * time format
61
-     * pattern or format for displaying time
62
-     *
63
-     * @var string $_tm_frmt
64
-     */
65
-    protected $_tm_frmt;
66
-
67
-
68
-
69
-    /**
70
-     * This property is for holding a cached array of object properties indexed by property name as the key.
71
-     * The purpose of this is for setting a cache on properties that may have calculated values after a prepare_for_get.  That way the cache can be checked first and the calculated property returned instead of having to recalculate.
72
-     * Used by _set_cached_property() and _get_cached_property() methods.
73
-     *
74
-     * @var array
75
-     */
76
-    protected $_cached_properties = array();
77
-
78
-    /**
79
-     * An array containing keys of the related model, and values are either an array of related mode objects or a single
80
-     * related model object. see the model's _model_relations. The keys should match those specified. And if the relation
81
-     * is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, all others have an array)
82
-     *
83
-     * @var array
84
-     */
85
-    protected $_model_relations = array();
86
-
87
-    /**
88
-     * Array where keys are field names (see the model's _fields property) and values are their values. To see what
89
-     * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods)
90
-     *
91
-     * @var array
92
-     */
93
-    protected $_fields = array();
94
-
95
-    /**
96
-     * @var boolean indicating whether or not this model object is intended to ever be saved
97
-     * For example, we might create model objects intended to only be used for the duration
98
-     * of this request and to be thrown away, and if they were accidentally saved
99
-     * it would be a bug.
100
-     */
101
-    protected $_allow_persist = true;
102
-
103
-
104
-
105
-    /**
106
-     * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children play nice
107
-     *
108
-     * @param array   $fieldValues                             where each key is a field (ie, array key in the 2nd layer of the model's _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their values
109
-     * @param boolean $bydb                                    a flag for setting if the class is instantiated by the corresponding db model or not.
110
-     * @param string  $timezone                                indicate what timezone you want any datetime fields to be in when instantiating a EE_Base_Class object.
111
-     * @param array   $date_formats                            An array of date formats to set on construct where first
112
-     *                                                         value is the date_format and second value is the time
113
-     *                                                         format.
114
-     * @throws EE_Error
115
-     */
116
-    protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array())
117
-    {
118
-        $className = get_class($this);
119
-        do_action("AHEE__{$className}__construct", $this, $fieldValues);
120
-        $model = $this->get_model();
121
-        $model_fields = $model->field_settings(false);
122
-        // ensure $fieldValues is an array
123
-        $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues);
124
-        // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
125
-        // verify client code has not passed any invalid field names
126
-        foreach ($fieldValues as $field_name => $field_value) {
127
-            if ( ! isset($model_fields[$field_name])) {
128
-                throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields))));
129
-            }
130
-        }
131
-        // EEH_Debug_Tools::printr( $model_fields, '$model_fields  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
132
-        $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
133
-        if ( ! empty($date_formats) && is_array($date_formats)) {
134
-            list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
135
-        } else {
136
-            //set default formats for date and time
137
-            $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
138
-            $this->_tm_frmt = (string)get_option('time_format', 'g:i a');
139
-        }
140
-        //if db model is instantiating
141
-        if ($bydb) {
142
-            //client code has indicated these field values are from the database
143
-            foreach ($model_fields as $fieldName => $field) {
144
-                $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null);
145
-            }
146
-        } else {
147
-            //we're constructing a brand
148
-            //new instance of the model object. Generally, this means we'll need to do more field validation
149
-            foreach ($model_fields as $fieldName => $field) {
150
-                $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true);
151
-            }
152
-        }
153
-        //remember what values were passed to this constructor
154
-        $this->_props_n_values_provided_in_constructor = $fieldValues;
155
-        //remember in entity mapper
156
-        if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) {
157
-            $model->add_to_entity_map($this);
158
-        }
159
-        //setup all the relations
160
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
161
-            if ($relation_obj instanceof EE_Belongs_To_Relation) {
162
-                $this->_model_relations[$relation_name] = null;
163
-            } else {
164
-                $this->_model_relations[$relation_name] = array();
165
-            }
166
-        }
167
-        /**
168
-         * Action done at the end of each model object construction
169
-         *
170
-         * @param EE_Base_Class $this the model object just created
171
-         */
172
-        do_action('AHEE__EE_Base_Class__construct__finished', $this);
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * Gets whether or not this model object is allowed to persist/be saved to the database.
179
-     *
180
-     * @return boolean
181
-     */
182
-    public function allow_persist()
183
-    {
184
-        return $this->_allow_persist;
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * Sets whether or not this model object should be allowed to be saved to the DB.
191
-     * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless
192
-     * you got new information that somehow made you change your mind.
193
-     *
194
-     * @param boolean $allow_persist
195
-     * @return boolean
196
-     */
197
-    public function set_allow_persist($allow_persist)
198
-    {
199
-        return $this->_allow_persist = $allow_persist;
200
-    }
201
-
202
-
203
-
204
-    /**
205
-     * Gets the field's original value when this object was constructed during this request.
206
-     * This can be helpful when determining if a model object has changed or not
207
-     *
208
-     * @param string $field_name
209
-     * @return mixed|null
210
-     * @throws \EE_Error
211
-     */
212
-    public function get_original($field_name)
213
-    {
214
-        if (isset($this->_props_n_values_provided_in_constructor[$field_name])
215
-            && $field_settings = $this->get_model()->field_settings_for($field_name)
216
-        ) {
217
-            return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]);
218
-        } else {
219
-            return null;
220
-        }
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     * @param EE_Base_Class $obj
227
-     * @return string
228
-     */
229
-    public function get_class($obj)
230
-    {
231
-        return get_class($obj);
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * Overrides parent because parent expects old models.
238
-     * This also doesn't do any validation, and won't work for serialized arrays
239
-     *
240
-     * @param    string $field_name
241
-     * @param    mixed  $field_value
242
-     * @param bool      $use_default
243
-     * @throws \EE_Error
244
-     */
245
-    public function set($field_name, $field_value, $use_default = false)
246
-    {
247
-        $field_obj = $this->get_model()->field_settings_for($field_name);
248
-        if ($field_obj instanceof EE_Model_Field_Base) {
249
-            //			if ( method_exists( $field_obj, 'set_timezone' )) {
250
-            if ($field_obj instanceof EE_Datetime_Field) {
251
-                $field_obj->set_timezone($this->_timezone);
252
-                $field_obj->set_date_format($this->_dt_frmt);
253
-                $field_obj->set_time_format($this->_tm_frmt);
254
-            }
255
-            $holder_of_value = $field_obj->prepare_for_set($field_value);
256
-            //should the value be null?
257
-            if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) {
258
-                $this->_fields[$field_name] = $field_obj->get_default_value();
259
-                /**
260
-                 * To save having to refactor all the models, if a default value is used for a
261
-                 * EE_Datetime_Field, and that value is not null nor is it a DateTime
262
-                 * object.  Then let's do a set again to ensure that it becomes a DateTime
263
-                 * object.
264
-                 *
265
-                 * @since 4.6.10+
266
-                 */
267
-                if (
268
-                    $field_obj instanceof EE_Datetime_Field
269
-                    && $this->_fields[$field_name] !== null
270
-                    && ! $this->_fields[$field_name] instanceof DateTime
271
-                ) {
272
-                    empty($this->_fields[$field_name])
273
-                        ? $this->set($field_name, time())
274
-                        : $this->set($field_name, $this->_fields[$field_name]);
275
-                }
276
-            } else {
277
-                $this->_fields[$field_name] = $holder_of_value;
278
-            }
279
-            //if we're not in the constructor...
280
-            //now check if what we set was a primary key
281
-            if (
282
-                //note: props_n_values_provided_in_constructor is only set at the END of the constructor
283
-                $this->_props_n_values_provided_in_constructor
284
-                && $field_value
285
-                && $field_name === self::_get_primary_key_name(get_class($this))
286
-            ) {
287
-                //if so, we want all this object's fields to be filled either with
288
-                //what we've explicitly set on this model
289
-                //or what we have in the db
290
-                // echo "setting primary key!";
291
-                $fields_on_model = self::_get_model(get_class($this))->field_settings();
292
-                $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value);
293
-                foreach ($fields_on_model as $field_obj) {
294
-                    if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
295
-                         && $field_obj->get_name() !== $field_name
296
-                    ) {
297
-                        $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name()));
298
-                    }
299
-                }
300
-                //oh this model object has an ID? well make sure its in the entity mapper
301
-                $this->get_model()->add_to_entity_map($this);
302
-            }
303
-            //let's unset any cache for this field_name from the $_cached_properties property.
304
-            $this->_clear_cached_property($field_name);
305
-        } else {
306
-            throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name));
307
-        }
308
-    }
309
-
310
-
311
-
312
-    /**
313
-     * This sets the field value on the db column if it exists for the given $column_name or
314
-     * saves it to EE_Extra_Meta if the given $column_name does not match a db column.
315
-     *
316
-     * @see EE_message::get_column_value for related documentation on the necessity of this method.
317
-     * @param string $field_name  Must be the exact column name.
318
-     * @param mixed  $field_value The value to set.
319
-     * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs.
320
-     * @throws \EE_Error
321
-     */
322
-    public function set_field_or_extra_meta($field_name, $field_value)
323
-    {
324
-        if ($this->get_model()->has_field($field_name)) {
325
-            $this->set($field_name, $field_value);
326
-            return true;
327
-        } else {
328
-            //ensure this object is saved first so that extra meta can be properly related.
329
-            $this->save();
330
-            return $this->update_extra_meta($field_name, $field_value);
331
-        }
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * This retrieves the value of the db column set on this class or if that's not present
338
-     * it will attempt to retrieve from extra_meta if found.
339
-     * Example Usage:
340
-     * Via EE_Message child class:
341
-     * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to",
342
-     * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may
343
-     * also have additional main fields specific to the messenger.  The system accommodates those extra
344
-     * fields through the EE_Extra_Meta table.  This method allows for EE_messengers to retrieve the
345
-     * value for those extra fields dynamically via the EE_message object.
346
-     *
347
-     * @param  string $field_name expecting the fully qualified field name.
348
-     * @return mixed|null  value for the field if found.  null if not found.
349
-     * @throws \EE_Error
350
-     */
351
-    public function get_field_or_extra_meta($field_name)
352
-    {
353
-        if ($this->get_model()->has_field($field_name)) {
354
-            $column_value = $this->get($field_name);
355
-        } else {
356
-            //This isn't a column in the main table, let's see if it is in the extra meta.
357
-            $column_value = $this->get_extra_meta($field_name, true, null);
358
-        }
359
-        return $column_value;
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally for being able to reference what timezone we are running conversions on when converting TO the internal timezone (UTC
366
-     * Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is available to all child classes that may be using the EE_Datetime_Field for a field data type.
367
-     *
368
-     * @access public
369
-     * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php
370
-     * @return void
371
-     * @throws \EE_Error
372
-     */
373
-    public function set_timezone($timezone = '')
374
-    {
375
-        $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
376
-        //make sure we clear all cached properties because they won't be relevant now
377
-        $this->_clear_cached_properties();
378
-        //make sure we update field settings and the date for all EE_Datetime_Fields
379
-        $model_fields = $this->get_model()->field_settings(false);
380
-        foreach ($model_fields as $field_name => $field_obj) {
381
-            if ($field_obj instanceof EE_Datetime_Field) {
382
-                $field_obj->set_timezone($this->_timezone);
383
-                if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
384
-                    $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
385
-                }
386
-            }
387
-        }
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * This just returns whatever is set for the current timezone.
394
-     *
395
-     * @access public
396
-     * @return string timezone string
397
-     */
398
-    public function get_timezone()
399
-    {
400
-        return $this->_timezone;
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * This sets the internal date format to what is sent in to be used as the new default for the class
407
-     * internally instead of wp set date format options
408
-     *
409
-     * @since 4.6
410
-     * @param string $format should be a format recognizable by PHP date() functions.
411
-     */
412
-    public function set_date_format($format)
413
-    {
414
-        $this->_dt_frmt = $format;
415
-        //clear cached_properties because they won't be relevant now.
416
-        $this->_clear_cached_properties();
417
-    }
418
-
419
-
420
-
421
-    /**
422
-     * This sets the internal time format string to what is sent in to be used as the new default for the
423
-     * class internally instead of wp set time format options.
424
-     *
425
-     * @since 4.6
426
-     * @param string $format should be a format recognizable by PHP date() functions.
427
-     */
428
-    public function set_time_format($format)
429
-    {
430
-        $this->_tm_frmt = $format;
431
-        //clear cached_properties because they won't be relevant now.
432
-        $this->_clear_cached_properties();
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     * This returns the current internal set format for the date and time formats.
439
-     *
440
-     * @param bool $full           if true (default), then return the full format.  Otherwise will return an array where the
441
-     *                             first value is the date format and the second value is the time format.
442
-     * @return mixed string|array
443
-     */
444
-    public function get_format($full = true)
445
-    {
446
-        return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     * cache
453
-     * stores the passed model object on the current model object.
454
-     * In certain circumstances, we can use this cached model object instead of querying for another one entirely.
455
-     *
456
-     * @param string        $relationName    one of the keys in the _model_relations array on the model. Eg 'Registration' associated with this model object
457
-     * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, that could be a payment or a registration)
458
-     * @param null          $cache_id        a string or number that will be used as the key for any Belongs_To_Many items which will be stored in an array on this object
459
-     * @throws EE_Error
460
-     * @return mixed    index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array)
461
-     */
462
-    public function cache($relationName = '', $object_to_cache = null, $cache_id = null)
463
-    {
464
-        // its entirely possible that there IS no related object yet in which case there is nothing to cache.
465
-        if ( ! $object_to_cache instanceof EE_Base_Class) {
466
-            return false;
467
-        }
468
-        // also get "how" the object is related, or throw an error
469
-        if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) {
470
-            throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this)));
471
-        }
472
-        // how many things are related ?
473
-        if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
474
-            // if it's a "belongs to" relationship, then there's only one related model object  eg, if this is a registration, there's only 1 attendee for it
475
-            // so for these model objects just set it to be cached
476
-            $this->_model_relations[$relationName] = $object_to_cache;
477
-            $return = true;
478
-        } else {
479
-            // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type.
480
-            // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array
481
-            if ( ! is_array($this->_model_relations[$relationName])) {
482
-                // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array
483
-                $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array();
484
-            }
485
-            // first check for a cache_id which is normally empty
486
-            if ( ! empty($cache_id)) {
487
-                // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on
488
-                $this->_model_relations[$relationName][$cache_id] = $object_to_cache;
489
-                $return = $cache_id;
490
-            } elseif ($object_to_cache->ID()) {
491
-                // OR the cached object originally came from the db, so let's just use it's PK for an ID
492
-                $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache;
493
-                $return = $object_to_cache->ID();
494
-            } else {
495
-                // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID
496
-                $this->_model_relations[$relationName][] = $object_to_cache;
497
-                // move the internal pointer to the end of the array
498
-                end($this->_model_relations[$relationName]);
499
-                // and grab the key so that we can return it
500
-                $return = key($this->_model_relations[$relationName]);
501
-            }
502
-        }
503
-        return $return;
504
-    }
505
-
506
-
507
-
508
-    /**
509
-     * For adding an item to the cached_properties property.
510
-     *
511
-     * @access protected
512
-     * @param string      $fieldname the property item the corresponding value is for.
513
-     * @param mixed       $value     The value we are caching.
514
-     * @param string|null $cache_type
515
-     * @return void
516
-     * @throws \EE_Error
517
-     */
518
-    protected function _set_cached_property($fieldname, $value, $cache_type = null)
519
-    {
520
-        //first make sure this property exists
521
-        $this->get_model()->field_settings_for($fieldname);
522
-        $cache_type = empty($cache_type) ? 'standard' : $cache_type;
523
-        $this->_cached_properties[$fieldname][$cache_type] = $value;
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist.
530
-     * This also SETS the cache if we return the actual property!
531
-     *
532
-     * @param string $fieldname        the name of the property we're trying to retrieve
533
-     * @param bool   $pretty
534
-     * @param string $extra_cache_ref  This allows the user to specify an extra cache ref for the given property
535
-     *                                 (in cases where the same property may be used for different outputs
536
-     *                                 - i.e. datetime, money etc.)
537
-     *                                 It can also accept certain pre-defined "schema" strings
538
-     *                                 to define how to output the property.
539
-     *                                 see the field's prepare_for_pretty_echoing for what strings can be used
540
-     * @return mixed                   whatever the value for the property is we're retrieving
541
-     * @throws \EE_Error
542
-     */
543
-    protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null)
544
-    {
545
-        //verify the field exists
546
-        $this->get_model()->field_settings_for($fieldname);
547
-        $cache_type = $pretty ? 'pretty' : 'standard';
548
-        $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
549
-        if (isset($this->_cached_properties[$fieldname][$cache_type])) {
550
-            return $this->_cached_properties[$fieldname][$cache_type];
551
-        }
552
-        $field_obj = $this->get_model()->field_settings_for($fieldname);
553
-        if ($field_obj instanceof EE_Model_Field_Base) {
554
-            // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct
555
-            if ($field_obj instanceof EE_Datetime_Field) {
556
-                $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref);
557
-            }
558
-            if ( ! isset($this->_fields[$fieldname])) {
559
-                $this->_fields[$fieldname] = null;
560
-            }
561
-            $value = $pretty
562
-                ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
563
-                : $field_obj->prepare_for_get($this->_fields[$fieldname]);
564
-            $this->_set_cached_property($fieldname, $value, $cache_type);
565
-            return $value;
566
-        }
567
-        return null;
568
-    }
569
-
570
-
571
-
572
-    /**
573
-     * set timezone, formats, and output for EE_Datetime_Field objects
574
-     *
575
-     * @param \EE_Datetime_Field $datetime_field
576
-     * @param bool               $pretty
577
-     * @param null $date_or_time
578
-     * @return void
579
-     * @throws \EE_Error
580
-     */
581
-    protected function _prepare_datetime_field(
582
-        EE_Datetime_Field $datetime_field,
583
-        $pretty = false,
584
-        $date_or_time = null
585
-    ) {
586
-        $datetime_field->set_timezone($this->_timezone);
587
-        $datetime_field->set_date_format($this->_dt_frmt, $pretty);
588
-        $datetime_field->set_time_format($this->_tm_frmt, $pretty);
589
-        //set the output returned
590
-        switch ($date_or_time) {
591
-            case 'D' :
592
-                $datetime_field->set_date_time_output('date');
593
-                break;
594
-            case 'T' :
595
-                $datetime_field->set_date_time_output('time');
596
-                break;
597
-            default :
598
-                $datetime_field->set_date_time_output();
599
-        }
600
-    }
601
-
602
-
603
-
604
-    /**
605
-     * This just takes care of clearing out the cached_properties
606
-     *
607
-     * @return void
608
-     */
609
-    protected function _clear_cached_properties()
610
-    {
611
-        $this->_cached_properties = array();
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * This just clears out ONE property if it exists in the cache
618
-     *
619
-     * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
620
-     * @return void
621
-     */
622
-    protected function _clear_cached_property($property_name)
623
-    {
624
-        if (isset($this->_cached_properties[$property_name])) {
625
-            unset($this->_cached_properties[$property_name]);
626
-        }
627
-    }
628
-
629
-
630
-
631
-    /**
632
-     * Ensures that this related thing is a model object.
633
-     *
634
-     * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
635
-     * @param string $model_name   name of the related thing, eg 'Attendee',
636
-     * @return EE_Base_Class
637
-     * @throws \EE_Error
638
-     */
639
-    protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
640
-    {
641
-        $other_model_instance = self::_get_model_instance_with_name(
642
-            self::_get_model_classname($model_name),
643
-            $this->_timezone
644
-        );
645
-        return $other_model_instance->ensure_is_obj($object_or_id);
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * Forgets the cached model of the given relation Name. So the next time we request it,
652
-     * we will fetch it again from the database. (Handy if you know it's changed somehow).
653
-     * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
654
-     * then only remove that one object from our cached array. Otherwise, clear the entire list
655
-     *
656
-     * @param string $relationName                         one of the keys in the _model_relations array on the model. Eg 'Registration'
657
-     * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
658
-     *                                                     if you intend to use $clear_all = TRUE, or the relation only has 1 object anyways (ie, it's a BelongsToRelation)
659
-     * @param bool   $clear_all                            This flags clearing the entire cache relation property if this is HasMany or HABTM.
660
-     * @throws EE_Error
661
-     * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all
662
-     */
663
-    public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
664
-    {
665
-        $relationship_to_model = $this->get_model()->related_settings_for($relationName);
666
-        $index_in_cache = '';
667
-        if ( ! $relationship_to_model) {
668
-            throw new EE_Error(
669
-                sprintf(
670
-                    __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
671
-                    $relationName,
672
-                    get_class($this)
673
-                )
674
-            );
675
-        }
676
-        if ($clear_all) {
677
-            $obj_removed = true;
678
-            $this->_model_relations[$relationName] = null;
679
-        } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
680
-            $obj_removed = $this->_model_relations[$relationName];
681
-            $this->_model_relations[$relationName] = null;
682
-        } else {
683
-            if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) {
684
-                $index_in_cache = $object_to_remove_or_index_into_array->ID();
685
-                if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) {
686
-                    $index_found_at = null;
687
-                    //find this object in the array even though it has a different key
688
-                    foreach ($this->_model_relations[$relationName] as $index => $obj) {
689
-                        if (
690
-                            $obj instanceof EE_Base_Class
691
-                            && (
692
-                                $obj == $object_to_remove_or_index_into_array
693
-                                || $obj->ID() === $object_to_remove_or_index_into_array->ID()
694
-                            )
695
-                        ) {
696
-                            $index_found_at = $index;
697
-                            break;
698
-                        }
699
-                    }
700
-                    if ($index_found_at) {
701
-                        $index_in_cache = $index_found_at;
702
-                    } else {
703
-                        //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
704
-                        //if it wasn't in it to begin with. So we're done
705
-                        return $object_to_remove_or_index_into_array;
706
-                    }
707
-                }
708
-            } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
709
-                //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
710
-                foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
711
-                    if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
712
-                        $index_in_cache = $index;
713
-                    }
714
-                }
715
-            } else {
716
-                $index_in_cache = $object_to_remove_or_index_into_array;
717
-            }
718
-            //supposedly we've found it. But it could just be that the client code
719
-            //provided a bad index/object
720
-            if (
721
-            isset(
722
-                $this->_model_relations[$relationName],
723
-                $this->_model_relations[$relationName][$index_in_cache]
724
-            )
725
-            ) {
726
-                $obj_removed = $this->_model_relations[$relationName][$index_in_cache];
727
-                unset($this->_model_relations[$relationName][$index_in_cache]);
728
-            } else {
729
-                //that thing was never cached anyways.
730
-                $obj_removed = null;
731
-            }
732
-        }
733
-        return $obj_removed;
734
-    }
735
-
736
-
737
-
738
-    /**
739
-     * update_cache_after_object_save
740
-     * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has obtained after being saved to the db
741
-     *
742
-     * @param string         $relationName       - the type of object that is cached
743
-     * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
744
-     * @param string         $current_cache_id   - the ID that was used when originally caching the object
745
-     * @return boolean TRUE on success, FALSE on fail
746
-     * @throws \EE_Error
747
-     */
748
-    public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '')
749
-    {
750
-        // verify that incoming object is of the correct type
751
-        $obj_class = 'EE_' . $relationName;
752
-        if ($newly_saved_object instanceof $obj_class) {
753
-            /* @type EE_Base_Class $newly_saved_object */
754
-            // now get the type of relation
755
-            $relationship_to_model = $this->get_model()->related_settings_for($relationName);
756
-            // if this is a 1:1 relationship
757
-            if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
758
-                // then just replace the cached object with the newly saved object
759
-                $this->_model_relations[$relationName] = $newly_saved_object;
760
-                return true;
761
-                // or if it's some kind of sordid feral polyamorous relationship...
762
-            } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) {
763
-                // then remove the current cached item
764
-                unset($this->_model_relations[$relationName][$current_cache_id]);
765
-                // and cache the newly saved object using it's new ID
766
-                $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
767
-                return true;
768
-            }
769
-        }
770
-        return false;
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
777
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
778
-     *
779
-     * @param string $relationName
780
-     * @return EE_Base_Class
781
-     */
782
-    public function get_one_from_cache($relationName)
783
-    {
784
-        $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null;
785
-        if (is_array($cached_array_or_object)) {
786
-            return array_shift($cached_array_or_object);
787
-        } else {
788
-            return $cached_array_or_object;
789
-        }
790
-    }
791
-
792
-
793
-
794
-    /**
795
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
796
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
797
-     *
798
-     * @param string $relationName
799
-     * @throws \EE_Error
800
-     * @return EE_Base_Class[] NOT necessarily indexed by primary keys
801
-     */
802
-    public function get_all_from_cache($relationName)
803
-    {
804
-        $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
805
-        // if the result is not an array, but exists, make it an array
806
-        $objects = is_array($objects) ? $objects : array($objects);
807
-        //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
808
-        //basically, if this model object was stored in the session, and these cached model objects
809
-        //already have IDs, let's make sure they're in their model's entity mapper
810
-        //otherwise we will have duplicates next time we call
811
-        // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
812
-        $model = EE_Registry::instance()->load_model($relationName);
813
-        foreach ($objects as $model_object) {
814
-            if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
815
-                //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
816
-                if ($model_object->ID()) {
817
-                    $model->add_to_entity_map($model_object);
818
-                }
819
-            } else {
820
-                throw new EE_Error(
821
-                    sprintf(
822
-                        __(
823
-                            'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
824
-                            'event_espresso'
825
-                        ),
826
-                        $relationName,
827
-                        gettype($model_object)
828
-                    )
829
-                );
830
-            }
831
-        }
832
-        return $objects;
833
-    }
834
-
835
-
836
-
837
-    /**
838
-     * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
839
-     * matching the given query conditions.
840
-     *
841
-     * @param null  $field_to_order_by  What field is being used as the reference point.
842
-     * @param int   $limit              How many objects to return.
843
-     * @param array $query_params       Any additional conditions on the query.
844
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
845
-     *                                  you can indicate just the columns you want returned
846
-     * @return array|EE_Base_Class[]
847
-     * @throws \EE_Error
848
-     */
849
-    public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
850
-    {
851
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
852
-            ? $this->get_model()->get_primary_key_field()->get_name()
853
-            : $field_to_order_by;
854
-        $current_value = ! empty($field) ? $this->get($field) : null;
855
-        if (empty($field) || empty($current_value)) {
856
-            return array();
857
-        }
858
-        return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
859
-    }
860
-
861
-
862
-
863
-    /**
864
-     * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
865
-     * matching the given query conditions.
866
-     *
867
-     * @param null  $field_to_order_by  What field is being used as the reference point.
868
-     * @param int   $limit              How many objects to return.
869
-     * @param array $query_params       Any additional conditions on the query.
870
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
871
-     *                                  you can indicate just the columns you want returned
872
-     * @return array|EE_Base_Class[]
873
-     * @throws \EE_Error
874
-     */
875
-    public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
876
-    {
877
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
878
-            ? $this->get_model()->get_primary_key_field()->get_name()
879
-            : $field_to_order_by;
880
-        $current_value = ! empty($field) ? $this->get($field) : null;
881
-        if (empty($field) || empty($current_value)) {
882
-            return array();
883
-        }
884
-        return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
885
-    }
886
-
887
-
888
-
889
-    /**
890
-     * Returns the next EE_Base_Class object in sequence from this object as found in the database
891
-     * matching the given query conditions.
892
-     *
893
-     * @param null  $field_to_order_by  What field is being used as the reference point.
894
-     * @param array $query_params       Any additional conditions on the query.
895
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
896
-     *                                  you can indicate just the columns you want returned
897
-     * @return array|EE_Base_Class
898
-     * @throws \EE_Error
899
-     */
900
-    public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
901
-    {
902
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
903
-            ? $this->get_model()->get_primary_key_field()->get_name()
904
-            : $field_to_order_by;
905
-        $current_value = ! empty($field) ? $this->get($field) : null;
906
-        if (empty($field) || empty($current_value)) {
907
-            return array();
908
-        }
909
-        return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select);
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * Returns the previous EE_Base_Class object in sequence from this object as found in the database
916
-     * matching the given query conditions.
917
-     *
918
-     * @param null  $field_to_order_by  What field is being used as the reference point.
919
-     * @param array $query_params       Any additional conditions on the query.
920
-     * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
921
-     *                                  you can indicate just the column you want returned
922
-     * @return array|EE_Base_Class
923
-     * @throws \EE_Error
924
-     */
925
-    public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
926
-    {
927
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
928
-            ? $this->get_model()->get_primary_key_field()->get_name()
929
-            : $field_to_order_by;
930
-        $current_value = ! empty($field) ? $this->get($field) : null;
931
-        if (empty($field) || empty($current_value)) {
932
-            return array();
933
-        }
934
-        return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select);
935
-    }
936
-
937
-
938
-
939
-    /**
940
-     * Overrides parent because parent expects old models.
941
-     * This also doesn't do any validation, and won't work for serialized arrays
942
-     *
943
-     * @param string $field_name
944
-     * @param mixed  $field_value_from_db
945
-     * @throws \EE_Error
946
-     */
947
-    public function set_from_db($field_name, $field_value_from_db)
948
-    {
949
-        $field_obj = $this->get_model()->field_settings_for($field_name);
950
-        if ($field_obj instanceof EE_Model_Field_Base) {
951
-            //you would think the DB has no NULLs for non-null label fields right? wrong!
952
-            //eg, a CPT model object could have an entry in the posts table, but no
953
-            //entry in the meta table. Meaning that all its columns in the meta table
954
-            //are null! yikes! so when we find one like that, use defaults for its meta columns
955
-            if ($field_value_from_db === null) {
956
-                if ($field_obj->is_nullable()) {
957
-                    //if the field allows nulls, then let it be null
958
-                    $field_value = null;
959
-                } else {
960
-                    $field_value = $field_obj->get_default_value();
961
-                }
962
-            } else {
963
-                $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
964
-            }
965
-            $this->_fields[$field_name] = $field_value;
966
-            $this->_clear_cached_property($field_name);
967
-        }
968
-    }
969
-
970
-
971
-
972
-    /**
973
-     * verifies that the specified field is of the correct type
974
-     *
975
-     * @param string $field_name
976
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
977
-     *                                (in cases where the same property may be used for different outputs
978
-     *                                - i.e. datetime, money etc.)
979
-     * @return mixed
980
-     * @throws \EE_Error
981
-     */
982
-    public function get($field_name, $extra_cache_ref = null)
983
-    {
984
-        return $this->_get_cached_property($field_name, false, $extra_cache_ref);
985
-    }
986
-
987
-
988
-
989
-    /**
990
-     * This method simply returns the RAW unprocessed value for the given property in this class
991
-     *
992
-     * @param  string $field_name A valid fieldname
993
-     * @return mixed              Whatever the raw value stored on the property is.
994
-     * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
995
-     */
996
-    public function get_raw($field_name)
997
-    {
998
-        $field_settings = $this->get_model()->field_settings_for($field_name);
999
-        return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
1000
-            ? $this->_fields[$field_name]->format('U')
1001
-            : $this->_fields[$field_name];
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * This is used to return the internal DateTime object used for a field that is a
1008
-     * EE_Datetime_Field.
1009
-     *
1010
-     * @param string $field_name               The field name retrieving the DateTime object.
1011
-     * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
1012
-     * @throws \EE_Error
1013
-     *                                         an error is set and false returned.  If the field IS an
1014
-     *                                         EE_Datetime_Field and but the field value is null, then
1015
-     *                                         just null is returned (because that indicates that likely
1016
-     *                                         this field is nullable).
1017
-     */
1018
-    public function get_DateTime_object($field_name)
1019
-    {
1020
-        $field_settings = $this->get_model()->field_settings_for($field_name);
1021
-        if ( ! $field_settings instanceof EE_Datetime_Field) {
1022
-            EE_Error::add_error(
1023
-                sprintf(
1024
-                    __(
1025
-                        'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
1026
-                        'event_espresso'
1027
-                    ),
1028
-                    $field_name
1029
-                ),
1030
-                __FILE__,
1031
-                __FUNCTION__,
1032
-                __LINE__
1033
-            );
1034
-            return false;
1035
-        }
1036
-        return $this->_fields[$field_name];
1037
-    }
1038
-
1039
-
1040
-
1041
-    /**
1042
-     * To be used in template to immediately echo out the value, and format it for output.
1043
-     * Eg, should call stripslashes and whatnot before echoing
1044
-     *
1045
-     * @param string $field_name      the name of the field as it appears in the DB
1046
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1047
-     *                                (in cases where the same property may be used for different outputs
1048
-     *                                - i.e. datetime, money etc.)
1049
-     * @return void
1050
-     * @throws \EE_Error
1051
-     */
1052
-    public function e($field_name, $extra_cache_ref = null)
1053
-    {
1054
-        echo $this->get_pretty($field_name, $extra_cache_ref);
1055
-    }
1056
-
1057
-
1058
-
1059
-    /**
1060
-     * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1061
-     * can be easily used as the value of form input.
1062
-     *
1063
-     * @param string $field_name
1064
-     * @return void
1065
-     * @throws \EE_Error
1066
-     */
1067
-    public function f($field_name)
1068
-    {
1069
-        $this->e($field_name, 'form_input');
1070
-    }
1071
-
1072
-
1073
-
1074
-    /**
1075
-     * @param string $field_name
1076
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1077
-     *                                (in cases where the same property may be used for different outputs
1078
-     *                                - i.e. datetime, money etc.)
1079
-     * @return mixed
1080
-     * @throws \EE_Error
1081
-     */
1082
-    public function get_pretty($field_name, $extra_cache_ref = null)
1083
-    {
1084
-        return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1085
-    }
1086
-
1087
-
1088
-
1089
-    /**
1090
-     * This simply returns the datetime for the given field name
1091
-     * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1092
-     * (and the equivalent e_date, e_time, e_datetime).
1093
-     *
1094
-     * @access   protected
1095
-     * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1096
-     * @param string   $dt_frmt      valid datetime format used for date
1097
-     *                               (if '' then we just use the default on the field,
1098
-     *                               if NULL we use the last-used format)
1099
-     * @param string   $tm_frmt      Same as above except this is for time format
1100
-     * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1101
-     * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1102
-     * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1103
-     *                               if field is not a valid dtt field, or void if echoing
1104
-     * @throws \EE_Error
1105
-     */
1106
-    protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1107
-    {
1108
-        // clear cached property
1109
-        $this->_clear_cached_property($field_name);
1110
-        //reset format properties because they are used in get()
1111
-        $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt;
1112
-        $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt;
1113
-        if ($echo) {
1114
-            $this->e($field_name, $date_or_time);
1115
-            return '';
1116
-        }
1117
-        return $this->get($field_name, $date_or_time);
1118
-    }
1119
-
1120
-
1121
-
1122
-    /**
1123
-     * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other echoes
1124
-     * the pretty value for dtt)
1125
-     *
1126
-     * @param  string $field_name name of model object datetime field holding the value
1127
-     * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1128
-     * @return string            datetime value formatted
1129
-     * @throws \EE_Error
1130
-     */
1131
-    public function get_date($field_name, $format = '')
1132
-    {
1133
-        return $this->_get_datetime($field_name, $format, null, 'D');
1134
-    }
1135
-
1136
-
1137
-
1138
-    /**
1139
-     * @param      $field_name
1140
-     * @param string $format
1141
-     * @throws \EE_Error
1142
-     */
1143
-    public function e_date($field_name, $format = '')
1144
-    {
1145
-        $this->_get_datetime($field_name, $format, null, 'D', true);
1146
-    }
1147
-
1148
-
1149
-
1150
-    /**
1151
-     * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other echoes
1152
-     * the pretty value for dtt)
1153
-     *
1154
-     * @param  string $field_name name of model object datetime field holding the value
1155
-     * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1156
-     * @return string             datetime value formatted
1157
-     * @throws \EE_Error
1158
-     */
1159
-    public function get_time($field_name, $format = '')
1160
-    {
1161
-        return $this->_get_datetime($field_name, null, $format, 'T');
1162
-    }
1163
-
1164
-
1165
-
1166
-    /**
1167
-     * @param      $field_name
1168
-     * @param string $format
1169
-     * @throws \EE_Error
1170
-     */
1171
-    public function e_time($field_name, $format = '')
1172
-    {
1173
-        $this->_get_datetime($field_name, null, $format, 'T', true);
1174
-    }
1175
-
1176
-
1177
-
1178
-    /**
1179
-     * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other
1180
-     * echoes the pretty value for dtt)
1181
-     *
1182
-     * @param  string $field_name name of model object datetime field holding the value
1183
-     * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1184
-     * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1185
-     * @return string             datetime value formatted
1186
-     * @throws \EE_Error
1187
-     */
1188
-    public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1189
-    {
1190
-        return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1191
-    }
1192
-
1193
-
1194
-
1195
-    /**
1196
-     * @param string $field_name
1197
-     * @param string $dt_frmt
1198
-     * @param string $tm_frmt
1199
-     * @throws \EE_Error
1200
-     */
1201
-    public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1202
-    {
1203
-        $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1204
-    }
1205
-
1206
-
1207
-
1208
-    /**
1209
-     * Get the i8ln value for a date using the WordPress @see date_i18n function.
1210
-     *
1211
-     * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1212
-     * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format on the object will be used.
1213
-     * @return string Date and time string in set locale or false if no field exists for the given
1214
-     * @throws \EE_Error
1215
-     *                           field name.
1216
-     */
1217
-    public function get_i18n_datetime($field_name, $format = '')
1218
-    {
1219
-        $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1220
-        return date_i18n(
1221
-            $format,
1222
-            EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1223
-        );
1224
-    }
1225
-
1226
-
1227
-
1228
-    /**
1229
-     * This method validates whether the given field name is a valid field on the model object as well as it is of a type EE_Datetime_Field.  On success there will be returned the field settings.  On fail an EE_Error exception is thrown.
1230
-     *
1231
-     * @param  string $field_name The field name being checked
1232
-     * @throws EE_Error
1233
-     * @return EE_Datetime_Field
1234
-     */
1235
-    protected function _get_dtt_field_settings($field_name)
1236
-    {
1237
-        $field = $this->get_model()->field_settings_for($field_name);
1238
-        //check if field is dtt
1239
-        if ($field instanceof EE_Datetime_Field) {
1240
-            return $field;
1241
-        } else {
1242
-            throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor',
1243
-                'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1244
-        }
1245
-    }
1246
-
1247
-
1248
-
1249
-
1250
-    /**
1251
-     * NOTE ABOUT BELOW:
1252
-     * These convenience date and time setters are for setting date and time independently.  In other words you might want to change the time on a datetime_field but leave the date the same (or vice versa).
1253
-     * IF on the other hand you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) method and make sure you send the entire datetime value for setting.
1254
-     */
1255
-    /**
1256
-     * sets the time on a datetime property
1257
-     *
1258
-     * @access protected
1259
-     * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1260
-     * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1261
-     * @throws \EE_Error
1262
-     */
1263
-    protected function _set_time_for($time, $fieldname)
1264
-    {
1265
-        $this->_set_date_time('T', $time, $fieldname);
1266
-    }
1267
-
1268
-
1269
-
1270
-    /**
1271
-     * sets the date on a datetime property
1272
-     *
1273
-     * @access protected
1274
-     * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1275
-     * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1276
-     * @throws \EE_Error
1277
-     */
1278
-    protected function _set_date_for($date, $fieldname)
1279
-    {
1280
-        $this->_set_date_time('D', $date, $fieldname);
1281
-    }
1282
-
1283
-
1284
-
1285
-    /**
1286
-     * This takes care of setting a date or time independently on a given model object property. This method also verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field
1287
-     *
1288
-     * @access protected
1289
-     * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1290
-     * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1291
-     * @param string          $fieldname      the name of the field the date OR time is being set on (must match a EE_Datetime_Field property)
1292
-     * @throws \EE_Error
1293
-     */
1294
-    protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1295
-    {
1296
-        $field = $this->_get_dtt_field_settings($fieldname);
1297
-        $field->set_timezone($this->_timezone);
1298
-        $field->set_date_format($this->_dt_frmt);
1299
-        $field->set_time_format($this->_tm_frmt);
1300
-        switch ($what) {
1301
-            case 'T' :
1302
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1303
-                    $datetime_value,
1304
-                    $this->_fields[$fieldname]
1305
-                );
1306
-                break;
1307
-            case 'D' :
1308
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1309
-                    $datetime_value,
1310
-                    $this->_fields[$fieldname]
1311
-                );
1312
-                break;
1313
-            case 'B' :
1314
-                $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1315
-                break;
1316
-        }
1317
-        $this->_clear_cached_property($fieldname);
1318
-    }
1319
-
1320
-
1321
-
1322
-    /**
1323
-     * This will return a timestamp for the website timezone but ONLY when the current website timezone is different than the timezone set for the website.
1324
-     * NOTE, this currently only works well with methods that return values.  If you use it with methods that echo values the $_timestamp property may not get reset to its original value and that could lead to some unexpected results!
1325
-     *
1326
-     * @access public
1327
-     * @param string               $field_name This is the name of the field on the object that contains the date/time value being returned.
1328
-     * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1329
-     * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1330
-     * @param string               $prepend    You can include something to prepend on the timestamp
1331
-     * @param string               $append     You can include something to append on the timestamp
1332
-     * @throws EE_Error
1333
-     * @return string timestamp
1334
-     */
1335
-    public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = null, $prepend = '', $append = '')
1336
-    {
1337
-        $timezone = EEH_DTT_Helper::get_timezone();
1338
-        if ($timezone === $this->_timezone) {
1339
-            return '';
1340
-        }
1341
-        $original_timezone = $this->_timezone;
1342
-        $this->set_timezone($timezone);
1343
-        $fn = (array)$field_name;
1344
-        $args = array_merge($fn, (array)$args);
1345
-        if ( ! method_exists($this, $callback)) {
1346
-            throw new EE_Error(
1347
-                sprintf(
1348
-                    __(
1349
-                        'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1350
-                        'event_espresso'
1351
-                    ),
1352
-                    $callback
1353
-                )
1354
-            );
1355
-        }
1356
-        $args = (array)$args;
1357
-        $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1358
-        $this->set_timezone($original_timezone);
1359
-        return $return;
1360
-    }
1361
-
1362
-
1363
-
1364
-    /**
1365
-     * Deletes this model object.
1366
-     * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should override
1367
-     * `EE_Base_Class::_delete` NOT this class.
1368
-     *
1369
-     * @return boolean | int
1370
-     * @throws \EE_Error
1371
-     */
1372
-    public function delete()
1373
-    {
1374
-        /**
1375
-         * Called just before the `EE_Base_Class::_delete` method call.
1376
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1377
-         * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1378
-         * soft deletes (trash) the object and does not permanently delete it.
1379
-         *
1380
-         * @param EE_Base_Class $model_object about to be 'deleted'
1381
-         */
1382
-        do_action('AHEE__EE_Base_Class__delete__before', $this);
1383
-        $result = $this->_delete();
1384
-        /**
1385
-         * Called just after the `EE_Base_Class::_delete` method call.
1386
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1387
-         * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1388
-         * soft deletes (trash) the object and does not permanently delete it.
1389
-         *
1390
-         * @param EE_Base_Class $model_object that was just 'deleted'
1391
-         * @param boolean       $result
1392
-         */
1393
-        do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1394
-        return $result;
1395
-    }
1396
-
1397
-
1398
-
1399
-    /**
1400
-     * Calls the specific delete method for the instantiated class.
1401
-     * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override default
1402
-     * functionality for "delete" (which is to call `permanently_delete`) should override this method NOT `EE_Base_Class::delete`
1403
-     *
1404
-     * @return bool|int
1405
-     * @throws \EE_Error
1406
-     */
1407
-    protected function _delete()
1408
-    {
1409
-        return $this->delete_permanently();
1410
-    }
1411
-
1412
-
1413
-
1414
-    /**
1415
-     * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error)
1416
-     *
1417
-     * @return bool | int
1418
-     * @throws \EE_Error
1419
-     */
1420
-    public function delete_permanently()
1421
-    {
1422
-        /**
1423
-         * Called just before HARD deleting a model object
1424
-         *
1425
-         * @param EE_Base_Class $model_object about to be 'deleted'
1426
-         */
1427
-        do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1428
-        $model = $this->get_model();
1429
-        $result = $model->delete_permanently_by_ID($this->ID());
1430
-        $this->refresh_cache_of_related_objects();
1431
-        /**
1432
-         * Called just after HARD deleting a model object
1433
-         *
1434
-         * @param EE_Base_Class $model_object that was just 'deleted'
1435
-         * @param boolean       $result
1436
-         */
1437
-        do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1438
-        return $result;
1439
-    }
1440
-
1441
-
1442
-
1443
-    /**
1444
-     * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1445
-     * related model objects
1446
-     *
1447
-     * @throws \EE_Error
1448
-     */
1449
-    public function refresh_cache_of_related_objects()
1450
-    {
1451
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1452
-            if ( ! empty($this->_model_relations[$relation_name])) {
1453
-                $related_objects = $this->_model_relations[$relation_name];
1454
-                if ($relation_obj instanceof EE_Belongs_To_Relation) {
1455
-                    //this relation only stores a single model object, not an array
1456
-                    //but let's make it consistent
1457
-                    $related_objects = array($related_objects);
1458
-                }
1459
-                foreach ($related_objects as $related_object) {
1460
-                    //only refresh their cache if they're in memory
1461
-                    if ($related_object instanceof EE_Base_Class) {
1462
-                        $related_object->clear_cache($this->get_model()->get_this_model_name(), $this);
1463
-                    }
1464
-                }
1465
-            }
1466
-        }
1467
-    }
1468
-
1469
-
1470
-
1471
-    /**
1472
-     *        Saves this object to the database. An array may be supplied to set some values on this
1473
-     * object just before saving.
1474
-     *
1475
-     * @access public
1476
-     * @param array $set_cols_n_values keys are field names, values are their new values,
1477
-     *                                 if provided during the save() method (often client code will change the fields' values before calling save)
1478
-     * @throws \EE_Error
1479
-     * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1480
-     *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1481
-     */
1482
-    public function save($set_cols_n_values = array())
1483
-    {
1484
-        /**
1485
-         * Filters the fields we're about to save on the model object
1486
-         *
1487
-         * @param array         $set_cols_n_values
1488
-         * @param EE_Base_Class $model_object
1489
-         */
1490
-        $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this);
1491
-        //set attributes as provided in $set_cols_n_values
1492
-        foreach ($set_cols_n_values as $column => $value) {
1493
-            $this->set($column, $value);
1494
-        }
1495
-        /**
1496
-         * Saving a model object.
1497
-         * Before we perform a save, this action is fired.
1498
-         *
1499
-         * @param EE_Base_Class $model_object the model object about to be saved.
1500
-         */
1501
-        do_action('AHEE__EE_Base_Class__save__begin', $this);
1502
-        if ( ! $this->allow_persist()) {
1503
-            return 0;
1504
-        }
1505
-        //now get current attribute values
1506
-        $save_cols_n_values = $this->_fields;
1507
-        //if the object already has an ID, update it. Otherwise, insert it
1508
-        //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1509
-        $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object();
1510
-        $this->get_model()->assume_values_already_prepared_by_model_object(true);
1511
-        //does this model have an autoincrement PK?
1512
-        if ($this->get_model()->has_primary_key_field()) {
1513
-            if ($this->get_model()->get_primary_key_field()->is_auto_increment()) {
1514
-                //ok check if it's set, if so: update; if not, insert
1515
-                if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) {
1516
-                    $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1517
-                } else {
1518
-                    unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]);
1519
-                    $results = $this->get_model()->insert($save_cols_n_values);
1520
-                    if ($results) {
1521
-                        //if successful, set the primary key
1522
-                        //but don't use the normal SET method, because it will check if
1523
-                        //an item with the same ID exists in the mapper & db, then
1524
-                        //will find it in the db (because we just added it) and THAT object
1525
-                        //will get added to the mapper before we can add this one!
1526
-                        //but if we just avoid using the SET method, all that headache can be avoided
1527
-                        $pk_field_name = self::_get_primary_key_name(get_class($this));
1528
-                        $this->_fields[$pk_field_name] = $results;
1529
-                        $this->_clear_cached_property($pk_field_name);
1530
-                        $this->get_model()->add_to_entity_map($this);
1531
-                        $this->_update_cached_related_model_objs_fks();
1532
-                    }
1533
-                }
1534
-            } else {//PK is NOT auto-increment
1535
-                //so check if one like it already exists in the db
1536
-                if ($this->get_model()->exists_by_ID($this->ID())) {
1537
-                    if (WP_DEBUG && ! $this->in_entity_map()) {
1538
-                        throw new EE_Error(
1539
-                            sprintf(
1540
-                                __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1541
-                                    'event_espresso'),
1542
-                                get_class($this),
1543
-                                get_class($this->get_model()) . '::instance()->add_to_entity_map()',
1544
-                                get_class($this->get_model()) . '::instance()->get_one_by_ID()',
1545
-                                '<br />'
1546
-                            )
1547
-                        );
1548
-                    }
1549
-                    $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1550
-                } else {
1551
-                    $results = $this->get_model()->insert($save_cols_n_values);
1552
-                    $this->_update_cached_related_model_objs_fks();
1553
-                }
1554
-            }
1555
-        } else {//there is NO primary key
1556
-            $already_in_db = false;
1557
-            foreach ($this->get_model()->unique_indexes() as $index) {
1558
-                $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1559
-                if ($this->get_model()->exists(array($uniqueness_where_params))) {
1560
-                    $already_in_db = true;
1561
-                }
1562
-            }
1563
-            if ($already_in_db) {
1564
-                $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields());
1565
-                $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values);
1566
-            } else {
1567
-                $results = $this->get_model()->insert($save_cols_n_values);
1568
-            }
1569
-        }
1570
-        //restore the old assumption about values being prepared by the model object
1571
-        $this->get_model()->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1572
-        /**
1573
-         * After saving the model object this action is called
1574
-         *
1575
-         * @param EE_Base_Class $model_object which was just saved
1576
-         * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1577
-         *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1578
-         */
1579
-        do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1580
-        return $results;
1581
-    }
1582
-
1583
-
1584
-
1585
-    /**
1586
-     * Updates the foreign key on related models objects pointing to this to have this model object's ID
1587
-     * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB is consistent)
1588
-     * Especially useful in case we JUST added this model object ot the database
1589
-     * and we want to let its cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on
1590
-     * the transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether or not they exist in the DB (if they do, their DB records will be automatically updated)
1591
-     *
1592
-     * @return void
1593
-     * @throws \EE_Error
1594
-     */
1595
-    protected function _update_cached_related_model_objs_fks()
1596
-    {
1597
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1598
-            if ($relation_obj instanceof EE_Has_Many_Relation) {
1599
-                foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1600
-                    $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1601
-                        $this->get_model()->get_this_model_name()
1602
-                    );
1603
-                    $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1604
-                    if ($related_model_obj_in_cache->ID()) {
1605
-                        $related_model_obj_in_cache->save();
1606
-                    }
1607
-                }
1608
-            }
1609
-        }
1610
-    }
1611
-
1612
-
1613
-
1614
-    /**
1615
-     * Saves this model object and its NEW cached relations to the database.
1616
-     * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1617
-     * In order for that to work, we would need to mark model objects as dirty/clean...
1618
-     * because otherwise, there's a potential for infinite looping of saving
1619
-     * Saves the cached related model objects, and ensures the relation between them
1620
-     * and this object and properly setup
1621
-     *
1622
-     * @return int ID of new model object on save; 0 on failure+
1623
-     * @throws \EE_Error
1624
-     */
1625
-    public function save_new_cached_related_model_objs()
1626
-    {
1627
-        //make sure this has been saved
1628
-        if ( ! $this->ID()) {
1629
-            $id = $this->save();
1630
-        } else {
1631
-            $id = $this->ID();
1632
-        }
1633
-        //now save all the NEW cached model objects  (ie they don't exist in the DB)
1634
-        foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1635
-            if ($this->_model_relations[$relationName]) {
1636
-                //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1637
-                //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1638
-                if ($relationObj instanceof EE_Belongs_To_Relation) {
1639
-                    //add a relation to that relation type (which saves the appropriate thing in the process)
1640
-                    //but ONLY if it DOES NOT exist in the DB
1641
-                    /* @var $related_model_obj EE_Base_Class */
1642
-                    $related_model_obj = $this->_model_relations[$relationName];
1643
-                    //					if( ! $related_model_obj->ID()){
1644
-                    $this->_add_relation_to($related_model_obj, $relationName);
1645
-                    $related_model_obj->save_new_cached_related_model_objs();
1646
-                    //					}
1647
-                } else {
1648
-                    foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1649
-                        //add a relation to that relation type (which saves the appropriate thing in the process)
1650
-                        //but ONLY if it DOES NOT exist in the DB
1651
-                        //						if( ! $related_model_obj->ID()){
1652
-                        $this->_add_relation_to($related_model_obj, $relationName);
1653
-                        $related_model_obj->save_new_cached_related_model_objs();
1654
-                        //						}
1655
-                    }
1656
-                }
1657
-            }
1658
-        }
1659
-        return $id;
1660
-    }
1661
-
1662
-
1663
-
1664
-    /**
1665
-     * for getting a model while instantiated.
1666
-     *
1667
-     * @return \EEM_Base | \EEM_CPT_Base
1668
-     */
1669
-    public function get_model()
1670
-    {
1671
-        $modelName = self::_get_model_classname(get_class($this));
1672
-        return self::_get_model_instance_with_name($modelName, $this->_timezone);
1673
-    }
1674
-
1675
-
1676
-
1677
-    /**
1678
-     * @param $props_n_values
1679
-     * @param $classname
1680
-     * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1681
-     * @throws \EE_Error
1682
-     */
1683
-    protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1684
-    {
1685
-        //TODO: will not work for Term_Relationships because they have no PK!
1686
-        $primary_id_ref = self::_get_primary_key_name($classname);
1687
-        if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1688
-            $id = $props_n_values[$primary_id_ref];
1689
-            return self::_get_model($classname)->get_from_entity_map($id);
1690
-        }
1691
-        return false;
1692
-    }
1693
-
1694
-
1695
-
1696
-    /**
1697
-     * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for the primary key (if present in incoming values).
1698
-     * If there is a key in the incoming array that matches the primary key for the model AND it is not null, then we check the db. If there's a an object we return it.  If not we return false.
1699
-     *
1700
-     * @param  array  $props_n_values   incoming array of properties and their values
1701
-     * @param  string $classname        the classname of the child class
1702
-     * @param null    $timezone
1703
-     * @param array   $date_formats     incoming date_formats in an array where the first value is the
1704
-     *                                  date_format and the second value is the time format
1705
-     * @return mixed (EE_Base_Class|bool)
1706
-     * @throws \EE_Error
1707
-     */
1708
-    protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1709
-    {
1710
-        $existing = null;
1711
-        if (self::_get_model($classname)->has_primary_key_field()) {
1712
-            $primary_id_ref = self::_get_primary_key_name($classname);
1713
-            if (array_key_exists($primary_id_ref, $props_n_values)
1714
-                && ! empty($props_n_values[$primary_id_ref])
1715
-            ) {
1716
-                $existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1717
-                    $props_n_values[$primary_id_ref]
1718
-                );
1719
-            }
1720
-        } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) {
1721
-            //no primary key on this model, but there's still a matching item in the DB
1722
-            $existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1723
-                self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1724
-            );
1725
-        }
1726
-        if ($existing) {
1727
-            //set date formats if present before setting values
1728
-            if ( ! empty($date_formats) && is_array($date_formats)) {
1729
-                $existing->set_date_format($date_formats[0]);
1730
-                $existing->set_time_format($date_formats[1]);
1731
-            } else {
1732
-                //set default formats for date and time
1733
-                $existing->set_date_format(get_option('date_format'));
1734
-                $existing->set_time_format(get_option('time_format'));
1735
-            }
1736
-            foreach ($props_n_values as $property => $field_value) {
1737
-                $existing->set($property, $field_value);
1738
-            }
1739
-            return $existing;
1740
-        } else {
1741
-            return false;
1742
-        }
1743
-    }
1744
-
1745
-
1746
-
1747
-    /**
1748
-     * Gets the EEM_*_Model for this class
1749
-     *
1750
-     * @access public now, as this is more convenient
1751
-     * @param      $classname
1752
-     * @param null $timezone
1753
-     * @throws EE_Error
1754
-     * @return EEM_Base
1755
-     */
1756
-    protected static function _get_model($classname, $timezone = null)
1757
-    {
1758
-        //find model for this class
1759
-        if ( ! $classname) {
1760
-            throw new EE_Error(
1761
-                sprintf(
1762
-                    __(
1763
-                        "What were you thinking calling _get_model(%s)?? You need to specify the class name",
1764
-                        "event_espresso"
1765
-                    ),
1766
-                    $classname
1767
-                )
1768
-            );
1769
-        }
1770
-        $modelName = self::_get_model_classname($classname);
1771
-        return self::_get_model_instance_with_name($modelName, $timezone);
1772
-    }
1773
-
1774
-
1775
-
1776
-    /**
1777
-     * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1778
-     *
1779
-     * @param string $model_classname
1780
-     * @param null   $timezone
1781
-     * @return EEM_Base
1782
-     */
1783
-    protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1784
-    {
1785
-        $model_classname = str_replace('EEM_', '', $model_classname);
1786
-        $model = EE_Registry::instance()->load_model($model_classname);
1787
-        $model->set_timezone($timezone);
1788
-        return $model;
1789
-    }
1790
-
1791
-
1792
-
1793
-    /**
1794
-     * If a model name is provided (eg Registration), gets the model classname for that model.
1795
-     * Also works if a model class's classname is provided (eg EE_Registration).
1796
-     *
1797
-     * @param null $model_name
1798
-     * @return string like EEM_Attendee
1799
-     */
1800
-    private static function _get_model_classname($model_name = null)
1801
-    {
1802
-        if (strpos($model_name, "EE_") === 0) {
1803
-            $model_classname = str_replace("EE_", "EEM_", $model_name);
1804
-        } else {
1805
-            $model_classname = "EEM_" . $model_name;
1806
-        }
1807
-        return $model_classname;
1808
-    }
1809
-
1810
-
1811
-
1812
-    /**
1813
-     * returns the name of the primary key attribute
1814
-     *
1815
-     * @param null $classname
1816
-     * @throws EE_Error
1817
-     * @return string
1818
-     */
1819
-    protected static function _get_primary_key_name($classname = null)
1820
-    {
1821
-        if ( ! $classname) {
1822
-            throw new EE_Error(
1823
-                sprintf(
1824
-                    __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1825
-                    $classname
1826
-                )
1827
-            );
1828
-        }
1829
-        return self::_get_model($classname)->get_primary_key_field()->get_name();
1830
-    }
1831
-
1832
-
1833
-
1834
-    /**
1835
-     * Gets the value of the primary key.
1836
-     * If the object hasn't yet been saved, it should be whatever the model field's default was
1837
-     * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value is.
1838
-     * Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1839
-     *
1840
-     * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1841
-     * @throws \EE_Error
1842
-     */
1843
-    public function ID()
1844
-    {
1845
-        //now that we know the name of the variable, use a variable variable to get its value and return its
1846
-        if ($this->get_model()->has_primary_key_field()) {
1847
-            return $this->_fields[self::_get_primary_key_name(get_class($this))];
1848
-        } else {
1849
-            return $this->get_model()->get_index_primary_key_string($this->_fields);
1850
-        }
1851
-    }
1852
-
1853
-
1854
-
1855
-    /**
1856
-     * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current model is related
1857
-     * to a group of events, the $relationName should be 'Event', and should be a key in the EE Model's $_model_relations array.
1858
-     * If this model object doesn't exist in the DB, just caches the related thing
1859
-     *
1860
-     * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1861
-     * @param string $relationName                     eg 'Events','Question',etc.
1862
-     *                                                 an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id')
1863
-     * @param array  $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added.  However, keep in mind that the columns (keys) given must match
1864
-     *                                                 a column on the JOIN table and currently only the HABTM models accept these additional conditions.  Also remember that if an exact match isn't found for these extra cols/val pairs,
1865
-     *                                                 then a NEW row is created in the join table.
1866
-     * @param null   $cache_id
1867
-     * @throws EE_Error
1868
-     * @return EE_Base_Class the object the relation was added to
1869
-     */
1870
-    public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = null)
1871
-    {
1872
-        //if this thing exists in the DB, save the relation to the DB
1873
-        if ($this->ID()) {
1874
-            $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values);
1875
-            //clear cache so future get_many_related and get_first_related() return new results.
1876
-            $this->clear_cache($relationName, $otherObject, true);
1877
-            if ($otherObject instanceof EE_Base_Class) {
1878
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1879
-            }
1880
-        } else {
1881
-            //this thing doesn't exist in the DB,  so just cache it
1882
-            if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
1883
-                throw new EE_Error(sprintf(
1884
-                    __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'),
1885
-                    $otherObjectModelObjectOrID,
1886
-                    get_class($this)
1887
-                ));
1888
-            } else {
1889
-                $otherObject = $otherObjectModelObjectOrID;
1890
-            }
1891
-            $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
1892
-        }
1893
-        if ($otherObject instanceof EE_Base_Class) {
1894
-            //fix the reciprocal relation too
1895
-            if ($otherObject->ID()) {
1896
-                //its saved so assumed relations exist in the DB, so we can just
1897
-                //clear the cache so future queries use the updated info in the DB
1898
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true);
1899
-            } else {
1900
-                //it's not saved, so it caches relations like this
1901
-                $otherObject->cache($this->get_model()->get_this_model_name(), $this);
1902
-            }
1903
-        }
1904
-        return $otherObject;
1905
-    }
1906
-
1907
-
1908
-
1909
-    /**
1910
-     * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current model is related
1911
-     * to a group of events, the $relationName should be 'Events', and should be a key in the EE Model's $_model_relations array.
1912
-     * If this model object doesn't exist in the DB, just removes the related thing from the cache
1913
-     *
1914
-     * @param mixed  $otherObjectModelObjectOrID
1915
-     *                EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved to the DB yet
1916
-     * @param string $relationName
1917
-     * @param array  $where_query
1918
-     *                You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added.
1919
-     *                However, keep in mind that the columns (keys) given must match a column on the JOIN table
1920
-     *                and currently only the HABTM models accept these additional conditions.
1921
-     *                Also remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is created in the join table.
1922
-     * @return EE_Base_Class the relation was removed from
1923
-     * @throws \EE_Error
1924
-     */
1925
-    public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
1926
-    {
1927
-        if ($this->ID()) {
1928
-            //if this exists in the DB, save the relation change to the DB too
1929
-            $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query);
1930
-            $this->clear_cache($relationName, $otherObject);
1931
-        } else {
1932
-            //this doesn't exist in the DB, just remove it from the cache
1933
-            $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
1934
-        }
1935
-        if ($otherObject instanceof EE_Base_Class) {
1936
-            $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1937
-        }
1938
-        return $otherObject;
1939
-    }
1940
-
1941
-
1942
-
1943
-    /**
1944
-     * Removes ALL the related things for the $relationName.
1945
-     *
1946
-     * @param string $relationName
1947
-     * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
1948
-     * @return EE_Base_Class
1949
-     * @throws \EE_Error
1950
-     */
1951
-    public function _remove_relations($relationName, $where_query_params = array())
1952
-    {
1953
-        if ($this->ID()) {
1954
-            //if this exists in the DB, save the relation change to the DB too
1955
-            $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
1956
-            $this->clear_cache($relationName, null, true);
1957
-        } else {
1958
-            //this doesn't exist in the DB, just remove it from the cache
1959
-            $otherObjects = $this->clear_cache($relationName, null, true);
1960
-        }
1961
-        if (is_array($otherObjects)) {
1962
-            foreach ($otherObjects as $otherObject) {
1963
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1964
-            }
1965
-        }
1966
-        return $otherObjects;
1967
-    }
1968
-
1969
-
1970
-
1971
-    /**
1972
-     * Gets all the related model objects of the specified type. Eg, if the current class if
1973
-     * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
1974
-     * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
1975
-     * because we want to get even deleted items etc.
1976
-     *
1977
-     * @param string $relationName key in the model's _model_relations array
1978
-     * @param array  $query_params like EEM_Base::get_all
1979
-     * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
1980
-     * @throws \EE_Error
1981
-     *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs
1982
-     */
1983
-    public function get_many_related($relationName, $query_params = array())
1984
-    {
1985
-        if ($this->ID()) {
1986
-            //this exists in the DB, so get the related things from either the cache or the DB
1987
-            //if there are query parameters, forget about caching the related model objects.
1988
-            if ($query_params) {
1989
-                $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1990
-            } else {
1991
-                //did we already cache the result of this query?
1992
-                $cached_results = $this->get_all_from_cache($relationName);
1993
-                if ( ! $cached_results) {
1994
-                    $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1995
-                    //if no query parameters were passed, then we got all the related model objects
1996
-                    //for that relation. We can cache them then.
1997
-                    foreach ($related_model_objects as $related_model_object) {
1998
-                        $this->cache($relationName, $related_model_object);
1999
-                    }
2000
-                } else {
2001
-                    $related_model_objects = $cached_results;
2002
-                }
2003
-            }
2004
-        } else {
2005
-            //this doesn't exist in the DB, so just get the related things from the cache
2006
-            $related_model_objects = $this->get_all_from_cache($relationName);
2007
-        }
2008
-        return $related_model_objects;
2009
-    }
2010
-
2011
-
2012
-
2013
-    /**
2014
-     * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2015
-     * unless otherwise specified in the $query_params
2016
-     *
2017
-     * @param string $relation_name  model_name like 'Event', or 'Registration'
2018
-     * @param array  $query_params   like EEM_Base::get_all's
2019
-     * @param string $field_to_count name of field to count by. By default, uses primary key
2020
-     * @param bool   $distinct       if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
2021
-     * @return int
2022
-     */
2023
-    public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2024
-    {
2025
-        return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2026
-    }
2027
-
2028
-
2029
-
2030
-    /**
2031
-     * Instead of getting the related model objects, simply sums up the values of the specified field.
2032
-     * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2033
-     *
2034
-     * @param string $relation_name model_name like 'Event', or 'Registration'
2035
-     * @param array  $query_params  like EEM_Base::get_all's
2036
-     * @param string $field_to_sum  name of field to count by.
2037
-     *                              By default, uses primary key (which doesn't make much sense, so you should probably change it)
2038
-     * @return int
2039
-     */
2040
-    public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2041
-    {
2042
-        return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2043
-    }
2044
-
2045
-
2046
-
2047
-    /**
2048
-     * Gets the first (ie, one) related model object of the specified type.
2049
-     *
2050
-     * @param string $relationName key in the model's _model_relations array
2051
-     * @param array  $query_params like EEM_Base::get_all
2052
-     * @return EE_Base_Class (not an array, a single object)
2053
-     * @throws \EE_Error
2054
-     */
2055
-    public function get_first_related($relationName, $query_params = array())
2056
-    {
2057
-        if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2058
-            //if they've provided some query parameters, don't bother trying to cache the result
2059
-            //also make sure we're not caching the result of get_first_related
2060
-            //on a relation which should have an array of objects (because the cache might have an array of objects)
2061
-            if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2062
-                $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2063
-            } else {
2064
-                //first, check if we've already cached the result of this query
2065
-                $cached_result = $this->get_one_from_cache($relationName);
2066
-                if ( ! $cached_result) {
2067
-                    $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2068
-                    $this->cache($relationName, $related_model_object);
2069
-                } else {
2070
-                    $related_model_object = $cached_result;
2071
-                }
2072
-            }
2073
-        } else {
2074
-            $related_model_object = null;
2075
-            //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2076
-            if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2077
-                $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2078
-            }
2079
-            //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object
2080
-            if ( ! $related_model_object) {
2081
-                $related_model_object = $this->get_one_from_cache($relationName);
2082
-            }
2083
-        }
2084
-        return $related_model_object;
2085
-    }
2086
-
2087
-
2088
-
2089
-    /**
2090
-     * Does a delete on all related objects of type $relationName and removes
2091
-     * the current model object's relation to them. If they can't be deleted (because
2092
-     * of blocking related model objects) does nothing. If the related model objects are
2093
-     * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2094
-     * If this model object doesn't exist yet in the DB, just removes its related things
2095
-     *
2096
-     * @param string $relationName
2097
-     * @param array  $query_params like EEM_Base::get_all's
2098
-     * @return int how many deleted
2099
-     * @throws \EE_Error
2100
-     */
2101
-    public function delete_related($relationName, $query_params = array())
2102
-    {
2103
-        if ($this->ID()) {
2104
-            $count = $this->get_model()->delete_related($this, $relationName, $query_params);
2105
-        } else {
2106
-            $count = count($this->get_all_from_cache($relationName));
2107
-            $this->clear_cache($relationName, null, true);
2108
-        }
2109
-        return $count;
2110
-    }
2111
-
2112
-
2113
-
2114
-    /**
2115
-     * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2116
-     * the current model object's relation to them. If they can't be deleted (because
2117
-     * of blocking related model objects) just does a soft delete on it instead, if possible.
2118
-     * If the related thing isn't a soft-deletable model object, this function is identical
2119
-     * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2120
-     *
2121
-     * @param string $relationName
2122
-     * @param array  $query_params like EEM_Base::get_all's
2123
-     * @return int how many deleted (including those soft deleted)
2124
-     * @throws \EE_Error
2125
-     */
2126
-    public function delete_related_permanently($relationName, $query_params = array())
2127
-    {
2128
-        if ($this->ID()) {
2129
-            $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2130
-        } else {
2131
-            $count = count($this->get_all_from_cache($relationName));
2132
-        }
2133
-        $this->clear_cache($relationName, null, true);
2134
-        return $count;
2135
-    }
2136
-
2137
-
2138
-
2139
-    /**
2140
-     * is_set
2141
-     * Just a simple utility function children can use for checking if property exists
2142
-     *
2143
-     * @access  public
2144
-     * @param  string $field_name property to check
2145
-     * @return bool                              TRUE if existing,FALSE if not.
2146
-     */
2147
-    public function is_set($field_name)
2148
-    {
2149
-        return isset($this->_fields[$field_name]);
2150
-    }
2151
-
2152
-
2153
-
2154
-    /**
2155
-     * Just a simple utility function children can use for checking if property (or properties) exists and throwing an EE_Error exception if they don't
2156
-     *
2157
-     * @param  mixed (string|array) $properties properties to check
2158
-     * @throws EE_Error
2159
-     * @return bool                              TRUE if existing, throw EE_Error if not.
2160
-     */
2161
-    protected function _property_exists($properties)
2162
-    {
2163
-        foreach ((array)$properties as $property_name) {
2164
-            //first make sure this property exists
2165
-            if ( ! $this->_fields[$property_name]) {
2166
-                throw new EE_Error(
2167
-                    sprintf(
2168
-                        __(
2169
-                            'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2170
-                            'event_espresso'
2171
-                        ),
2172
-                        $property_name
2173
-                    )
2174
-                );
2175
-            }
2176
-        }
2177
-        return true;
2178
-    }
2179
-
2180
-
2181
-
2182
-    /**
2183
-     * This simply returns an array of model fields for this object
2184
-     *
2185
-     * @return array
2186
-     * @throws \EE_Error
2187
-     */
2188
-    public function model_field_array()
2189
-    {
2190
-        $fields = $this->get_model()->field_settings(false);
2191
-        $properties = array();
2192
-        //remove prepended underscore
2193
-        foreach ($fields as $field_name => $settings) {
2194
-            $properties[$field_name] = $this->get($field_name);
2195
-        }
2196
-        return $properties;
2197
-    }
2198
-
2199
-
2200
-
2201
-    /**
2202
-     * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2203
-     * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called (http://www.garfieldtech.com/blog/php-magic-call)
2204
-     * and passed the method's name and arguments.
2205
-     * Instead of requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that happen?)
2206
-     * they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, filters_hook_espresso__EE_Answer__my_great_function)
2207
-     * and accepts 2 arguments: the object on which the function was called, and an array of the original arguments passed to the function. Whatever their callback function returns will be returned by this function.
2208
-     * Example: in functions.php (or in a plugin):
2209
-     * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3);
2210
-     * function my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2211
-     * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2212
-     *        return $previousReturnValue.$returnString;
2213
-     * }
2214
-     * require('EE_Answer.class.php');
2215
-     * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2216
-     * echo $answer->my_callback('monkeys',100);
2217
-     * //will output "you called my_callback! and passed args:monkeys,100"
2218
-     *
2219
-     * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2220
-     * @param array  $args       array of original arguments passed to the function
2221
-     * @throws EE_Error
2222
-     * @return mixed whatever the plugin which calls add_filter decides
2223
-     */
2224
-    public function __call($methodName, $args)
2225
-    {
2226
-        $className = get_class($this);
2227
-        $tagName = "FHEE__{$className}__{$methodName}";
2228
-        if ( ! has_filter($tagName)) {
2229
-            throw new EE_Error(
2230
-                sprintf(
2231
-                    __(
2232
-                        "Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}",
2233
-                        "event_espresso"
2234
-                    ),
2235
-                    $methodName,
2236
-                    $className,
2237
-                    $tagName
2238
-                )
2239
-            );
2240
-        }
2241
-        return apply_filters($tagName, null, $this, $args);
2242
-    }
2243
-
2244
-
2245
-
2246
-    /**
2247
-     * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2248
-     * A $previous_value can be specified in case there are many meta rows with the same key
2249
-     *
2250
-     * @param string $meta_key
2251
-     * @param string $meta_value
2252
-     * @param string $previous_value
2253
-     * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2254
-     * @throws \EE_Error
2255
-     * NOTE: if the values haven't changed, returns 0
2256
-     */
2257
-    public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2258
-    {
2259
-        $query_params = array(
2260
-            array(
2261
-                'EXM_key'  => $meta_key,
2262
-                'OBJ_ID'   => $this->ID(),
2263
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2264
-            ),
2265
-        );
2266
-        if ($previous_value !== null) {
2267
-            $query_params[0]['EXM_value'] = $meta_value;
2268
-        }
2269
-        $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2270
-        if ( ! $existing_rows_like_that) {
2271
-            return $this->add_extra_meta($meta_key, $meta_value);
2272
-        } else {
2273
-            foreach ($existing_rows_like_that as $existing_row) {
2274
-                $existing_row->save(array('EXM_value' => $meta_value));
2275
-            }
2276
-            return count($existing_rows_like_that);
2277
-        }
2278
-    }
2279
-
2280
-
2281
-
2282
-    /**
2283
-     * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2284
-     * no other extra meta for this model object have the same key. Returns TRUE if the
2285
-     * extra meta row was entered, false if not
2286
-     *
2287
-     * @param string  $meta_key
2288
-     * @param string  $meta_value
2289
-     * @param boolean $unique
2290
-     * @return boolean
2291
-     * @throws \EE_Error
2292
-     */
2293
-    public function add_extra_meta($meta_key, $meta_value, $unique = false)
2294
-    {
2295
-        if ($unique) {
2296
-            $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2297
-                array(
2298
-                    array(
2299
-                        'EXM_key'  => $meta_key,
2300
-                        'OBJ_ID'   => $this->ID(),
2301
-                        'EXM_type' => $this->get_model()->get_this_model_name(),
2302
-                    ),
2303
-                )
2304
-            );
2305
-            if ($existing_extra_meta) {
2306
-                return false;
2307
-            }
2308
-        }
2309
-        $new_extra_meta = EE_Extra_Meta::new_instance(
2310
-            array(
2311
-                'EXM_key'   => $meta_key,
2312
-                'EXM_value' => $meta_value,
2313
-                'OBJ_ID'    => $this->ID(),
2314
-                'EXM_type'  => $this->get_model()->get_this_model_name(),
2315
-            )
2316
-        );
2317
-        $new_extra_meta->save();
2318
-        return true;
2319
-    }
2320
-
2321
-
2322
-
2323
-    /**
2324
-     * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2325
-     * is specified, only deletes extra meta records with that value.
2326
-     *
2327
-     * @param string $meta_key
2328
-     * @param string $meta_value
2329
-     * @return int number of extra meta rows deleted
2330
-     * @throws \EE_Error
2331
-     */
2332
-    public function delete_extra_meta($meta_key, $meta_value = null)
2333
-    {
2334
-        $query_params = array(
2335
-            array(
2336
-                'EXM_key'  => $meta_key,
2337
-                'OBJ_ID'   => $this->ID(),
2338
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2339
-            ),
2340
-        );
2341
-        if ($meta_value !== null) {
2342
-            $query_params[0]['EXM_value'] = $meta_value;
2343
-        }
2344
-        return EEM_Extra_Meta::instance()->delete($query_params);
2345
-    }
2346
-
2347
-
2348
-
2349
-    /**
2350
-     * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2351
-     * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2352
-     * You can specify $default is case you haven't found the extra meta
2353
-     *
2354
-     * @param string  $meta_key
2355
-     * @param boolean $single
2356
-     * @param mixed   $default if we don't find anything, what should we return?
2357
-     * @return mixed single value if $single; array if ! $single
2358
-     * @throws \EE_Error
2359
-     */
2360
-    public function get_extra_meta($meta_key, $single = false, $default = null)
2361
-    {
2362
-        if ($single) {
2363
-            $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2364
-            if ($result instanceof EE_Extra_Meta) {
2365
-                return $result->value();
2366
-            } else {
2367
-                return $default;
2368
-            }
2369
-        } else {
2370
-            $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2371
-            if ($results) {
2372
-                $values = array();
2373
-                foreach ($results as $result) {
2374
-                    if ($result instanceof EE_Extra_Meta) {
2375
-                        $values[$result->ID()] = $result->value();
2376
-                    }
2377
-                }
2378
-                return $values;
2379
-            } else {
2380
-                return $default;
2381
-            }
2382
-        }
2383
-    }
2384
-
2385
-
2386
-
2387
-    /**
2388
-     * Returns a simple array of all the extra meta associated with this model object.
2389
-     * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2390
-     * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2391
-     * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2392
-     * If $one_of_each_key is false, it will return an array with the top-level keys being
2393
-     * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2394
-     * finally the extra meta's value as each sub-value. (eg array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2395
-     *
2396
-     * @param boolean $one_of_each_key
2397
-     * @return array
2398
-     * @throws \EE_Error
2399
-     */
2400
-    public function all_extra_meta_array($one_of_each_key = true)
2401
-    {
2402
-        $return_array = array();
2403
-        if ($one_of_each_key) {
2404
-            $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2405
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2406
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2407
-                    $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2408
-                }
2409
-            }
2410
-        } else {
2411
-            $extra_meta_objs = $this->get_many_related('Extra_Meta');
2412
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2413
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2414
-                    if ( ! isset($return_array[$extra_meta_obj->key()])) {
2415
-                        $return_array[$extra_meta_obj->key()] = array();
2416
-                    }
2417
-                    $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2418
-                }
2419
-            }
2420
-        }
2421
-        return $return_array;
2422
-    }
2423
-
2424
-
2425
-
2426
-    /**
2427
-     * Gets a pretty nice displayable nice for this model object. Often overridden
2428
-     *
2429
-     * @return string
2430
-     * @throws \EE_Error
2431
-     */
2432
-    public function name()
2433
-    {
2434
-        //find a field that's not a text field
2435
-        $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2436
-        if ($field_we_can_use) {
2437
-            return $this->get($field_we_can_use->get_name());
2438
-        } else {
2439
-            $first_few_properties = $this->model_field_array();
2440
-            $first_few_properties = array_slice($first_few_properties, 0, 3);
2441
-            $name_parts = array();
2442
-            foreach ($first_few_properties as $name => $value) {
2443
-                $name_parts[] = "$name:$value";
2444
-            }
2445
-            return implode(",", $name_parts);
2446
-        }
2447
-    }
2448
-
2449
-
2450
-
2451
-    /**
2452
-     * in_entity_map
2453
-     * Checks if this model object has been proven to already be in the entity map
2454
-     *
2455
-     * @return boolean
2456
-     * @throws \EE_Error
2457
-     */
2458
-    public function in_entity_map()
2459
-    {
2460
-        if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2461
-            //well, if we looked, did we find it in the entity map?
2462
-            return true;
2463
-        } else {
2464
-            return false;
2465
-        }
2466
-    }
2467
-
2468
-
2469
-
2470
-    /**
2471
-     * refresh_from_db
2472
-     * Makes sure the fields and values on this model object are in-sync with what's in the database.
2473
-     *
2474
-     * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2475
-     * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2476
-     */
2477
-    public function refresh_from_db()
2478
-    {
2479
-        if ($this->ID() && $this->in_entity_map()) {
2480
-            $this->get_model()->refresh_entity_map_from_db($this->ID());
2481
-        } else {
2482
-            //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2483
-            //if it has an ID but it's not in the map, and you're asking me to refresh it
2484
-            //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2485
-            //absolutely nothing in it for this ID
2486
-            if (WP_DEBUG) {
2487
-                throw new EE_Error(
2488
-                    sprintf(
2489
-                        __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2490
-                            'event_espresso'),
2491
-                        $this->ID(),
2492
-                        get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2493
-                        get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2494
-                    )
2495
-                );
2496
-            }
2497
-        }
2498
-    }
2499
-
2500
-
2501
-
2502
-    /**
2503
-     * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2504
-     * (probably a bad assumption they have made, oh well)
2505
-     *
2506
-     * @return string
2507
-     */
2508
-    public function __toString()
2509
-    {
2510
-        try {
2511
-            return sprintf('%s (%s)', $this->name(), $this->ID());
2512
-        } catch (Exception $e) {
2513
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2514
-            return '';
2515
-        }
2516
-    }
2517
-
2518
-
2519
-
2520
-    /**
2521
-     * Clear related model objects if they're already in the DB, because otherwise when we
2522
-     * UN-serialize this model object we'll need to be careful to add them to the entity map.
2523
-     * This means if we have made changes to those related model objects, and want to unserialize
2524
-     * the this model object on a subsequent request, changes to those related model objects will be lost.
2525
-     * Instead, those related model objects should be directly serialized and stored.
2526
-     * Eg, the following won't work:
2527
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2528
-     * $att = $reg->attendee();
2529
-     * $att->set( 'ATT_fname', 'Dirk' );
2530
-     * update_option( 'my_option', serialize( $reg ) );
2531
-     * //END REQUEST
2532
-     * //START NEXT REQUEST
2533
-     * $reg = get_option( 'my_option' );
2534
-     * $reg->attendee()->save();
2535
-     * And would need to be replace with:
2536
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2537
-     * $att = $reg->attendee();
2538
-     * $att->set( 'ATT_fname', 'Dirk' );
2539
-     * update_option( 'my_option', serialize( $reg ) );
2540
-     * //END REQUEST
2541
-     * //START NEXT REQUEST
2542
-     * $att = get_option( 'my_option' );
2543
-     * $att->save();
2544
-     *
2545
-     * @return array
2546
-     * @throws \EE_Error
2547
-     */
2548
-    public function __sleep()
2549
-    {
2550
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2551
-            if ($relation_obj instanceof EE_Belongs_To_Relation) {
2552
-                $classname = 'EE_' . $this->get_model()->get_this_model_name();
2553
-                if (
2554
-                    $this->get_one_from_cache($relation_name) instanceof $classname
2555
-                    && $this->get_one_from_cache($relation_name)->ID()
2556
-                ) {
2557
-                    $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2558
-                }
2559
-            }
2560
-        }
2561
-        $this->_props_n_values_provided_in_constructor = array();
2562
-        return array_keys(get_object_vars($this));
2563
-    }
2564
-
2565
-
2566
-
2567
-    /**
2568
-     * restore _props_n_values_provided_in_constructor
2569
-     * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2570
-     * and therefore should NOT be used to determine if state change has occurred since initial construction.
2571
-     * At best, you would only be able to detect if state change has occurred during THIS request.
2572
-     */
2573
-    public function __wakeup()
2574
-    {
2575
-        $this->_props_n_values_provided_in_constructor = $this->_fields;
2576
-    }
28
+	/**
29
+	 * This is an array of the original properties and values provided during construction
30
+	 * of this model object. (keys are model field names, values are their values).
31
+	 * This list is important to remember so that when we are merging data from the db, we know
32
+	 * which values to override and which to not override.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $_props_n_values_provided_in_constructor;
37
+
38
+	/**
39
+	 * Timezone
40
+	 * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings coming out of the object to be in.  NOT all
41
+	 * EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have access to it.
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_timezone;
46
+
47
+
48
+
49
+	/**
50
+	 * date format
51
+	 * pattern or format for displaying dates
52
+	 *
53
+	 * @var string $_dt_frmt
54
+	 */
55
+	protected $_dt_frmt;
56
+
57
+
58
+
59
+	/**
60
+	 * time format
61
+	 * pattern or format for displaying time
62
+	 *
63
+	 * @var string $_tm_frmt
64
+	 */
65
+	protected $_tm_frmt;
66
+
67
+
68
+
69
+	/**
70
+	 * This property is for holding a cached array of object properties indexed by property name as the key.
71
+	 * The purpose of this is for setting a cache on properties that may have calculated values after a prepare_for_get.  That way the cache can be checked first and the calculated property returned instead of having to recalculate.
72
+	 * Used by _set_cached_property() and _get_cached_property() methods.
73
+	 *
74
+	 * @var array
75
+	 */
76
+	protected $_cached_properties = array();
77
+
78
+	/**
79
+	 * An array containing keys of the related model, and values are either an array of related mode objects or a single
80
+	 * related model object. see the model's _model_relations. The keys should match those specified. And if the relation
81
+	 * is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, all others have an array)
82
+	 *
83
+	 * @var array
84
+	 */
85
+	protected $_model_relations = array();
86
+
87
+	/**
88
+	 * Array where keys are field names (see the model's _fields property) and values are their values. To see what
89
+	 * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods)
90
+	 *
91
+	 * @var array
92
+	 */
93
+	protected $_fields = array();
94
+
95
+	/**
96
+	 * @var boolean indicating whether or not this model object is intended to ever be saved
97
+	 * For example, we might create model objects intended to only be used for the duration
98
+	 * of this request and to be thrown away, and if they were accidentally saved
99
+	 * it would be a bug.
100
+	 */
101
+	protected $_allow_persist = true;
102
+
103
+
104
+
105
+	/**
106
+	 * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children play nice
107
+	 *
108
+	 * @param array   $fieldValues                             where each key is a field (ie, array key in the 2nd layer of the model's _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their values
109
+	 * @param boolean $bydb                                    a flag for setting if the class is instantiated by the corresponding db model or not.
110
+	 * @param string  $timezone                                indicate what timezone you want any datetime fields to be in when instantiating a EE_Base_Class object.
111
+	 * @param array   $date_formats                            An array of date formats to set on construct where first
112
+	 *                                                         value is the date_format and second value is the time
113
+	 *                                                         format.
114
+	 * @throws EE_Error
115
+	 */
116
+	protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array())
117
+	{
118
+		$className = get_class($this);
119
+		do_action("AHEE__{$className}__construct", $this, $fieldValues);
120
+		$model = $this->get_model();
121
+		$model_fields = $model->field_settings(false);
122
+		// ensure $fieldValues is an array
123
+		$fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues);
124
+		// EEH_Debug_Tools::printr( $fieldValues, '$fieldValues  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
125
+		// verify client code has not passed any invalid field names
126
+		foreach ($fieldValues as $field_name => $field_value) {
127
+			if ( ! isset($model_fields[$field_name])) {
128
+				throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields))));
129
+			}
130
+		}
131
+		// EEH_Debug_Tools::printr( $model_fields, '$model_fields  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
132
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
133
+		if ( ! empty($date_formats) && is_array($date_formats)) {
134
+			list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
135
+		} else {
136
+			//set default formats for date and time
137
+			$this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
138
+			$this->_tm_frmt = (string)get_option('time_format', 'g:i a');
139
+		}
140
+		//if db model is instantiating
141
+		if ($bydb) {
142
+			//client code has indicated these field values are from the database
143
+			foreach ($model_fields as $fieldName => $field) {
144
+				$this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null);
145
+			}
146
+		} else {
147
+			//we're constructing a brand
148
+			//new instance of the model object. Generally, this means we'll need to do more field validation
149
+			foreach ($model_fields as $fieldName => $field) {
150
+				$this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true);
151
+			}
152
+		}
153
+		//remember what values were passed to this constructor
154
+		$this->_props_n_values_provided_in_constructor = $fieldValues;
155
+		//remember in entity mapper
156
+		if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) {
157
+			$model->add_to_entity_map($this);
158
+		}
159
+		//setup all the relations
160
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
161
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
162
+				$this->_model_relations[$relation_name] = null;
163
+			} else {
164
+				$this->_model_relations[$relation_name] = array();
165
+			}
166
+		}
167
+		/**
168
+		 * Action done at the end of each model object construction
169
+		 *
170
+		 * @param EE_Base_Class $this the model object just created
171
+		 */
172
+		do_action('AHEE__EE_Base_Class__construct__finished', $this);
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * Gets whether or not this model object is allowed to persist/be saved to the database.
179
+	 *
180
+	 * @return boolean
181
+	 */
182
+	public function allow_persist()
183
+	{
184
+		return $this->_allow_persist;
185
+	}
186
+
187
+
188
+
189
+	/**
190
+	 * Sets whether or not this model object should be allowed to be saved to the DB.
191
+	 * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless
192
+	 * you got new information that somehow made you change your mind.
193
+	 *
194
+	 * @param boolean $allow_persist
195
+	 * @return boolean
196
+	 */
197
+	public function set_allow_persist($allow_persist)
198
+	{
199
+		return $this->_allow_persist = $allow_persist;
200
+	}
201
+
202
+
203
+
204
+	/**
205
+	 * Gets the field's original value when this object was constructed during this request.
206
+	 * This can be helpful when determining if a model object has changed or not
207
+	 *
208
+	 * @param string $field_name
209
+	 * @return mixed|null
210
+	 * @throws \EE_Error
211
+	 */
212
+	public function get_original($field_name)
213
+	{
214
+		if (isset($this->_props_n_values_provided_in_constructor[$field_name])
215
+			&& $field_settings = $this->get_model()->field_settings_for($field_name)
216
+		) {
217
+			return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]);
218
+		} else {
219
+			return null;
220
+		}
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 * @param EE_Base_Class $obj
227
+	 * @return string
228
+	 */
229
+	public function get_class($obj)
230
+	{
231
+		return get_class($obj);
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * Overrides parent because parent expects old models.
238
+	 * This also doesn't do any validation, and won't work for serialized arrays
239
+	 *
240
+	 * @param    string $field_name
241
+	 * @param    mixed  $field_value
242
+	 * @param bool      $use_default
243
+	 * @throws \EE_Error
244
+	 */
245
+	public function set($field_name, $field_value, $use_default = false)
246
+	{
247
+		$field_obj = $this->get_model()->field_settings_for($field_name);
248
+		if ($field_obj instanceof EE_Model_Field_Base) {
249
+			//			if ( method_exists( $field_obj, 'set_timezone' )) {
250
+			if ($field_obj instanceof EE_Datetime_Field) {
251
+				$field_obj->set_timezone($this->_timezone);
252
+				$field_obj->set_date_format($this->_dt_frmt);
253
+				$field_obj->set_time_format($this->_tm_frmt);
254
+			}
255
+			$holder_of_value = $field_obj->prepare_for_set($field_value);
256
+			//should the value be null?
257
+			if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) {
258
+				$this->_fields[$field_name] = $field_obj->get_default_value();
259
+				/**
260
+				 * To save having to refactor all the models, if a default value is used for a
261
+				 * EE_Datetime_Field, and that value is not null nor is it a DateTime
262
+				 * object.  Then let's do a set again to ensure that it becomes a DateTime
263
+				 * object.
264
+				 *
265
+				 * @since 4.6.10+
266
+				 */
267
+				if (
268
+					$field_obj instanceof EE_Datetime_Field
269
+					&& $this->_fields[$field_name] !== null
270
+					&& ! $this->_fields[$field_name] instanceof DateTime
271
+				) {
272
+					empty($this->_fields[$field_name])
273
+						? $this->set($field_name, time())
274
+						: $this->set($field_name, $this->_fields[$field_name]);
275
+				}
276
+			} else {
277
+				$this->_fields[$field_name] = $holder_of_value;
278
+			}
279
+			//if we're not in the constructor...
280
+			//now check if what we set was a primary key
281
+			if (
282
+				//note: props_n_values_provided_in_constructor is only set at the END of the constructor
283
+				$this->_props_n_values_provided_in_constructor
284
+				&& $field_value
285
+				&& $field_name === self::_get_primary_key_name(get_class($this))
286
+			) {
287
+				//if so, we want all this object's fields to be filled either with
288
+				//what we've explicitly set on this model
289
+				//or what we have in the db
290
+				// echo "setting primary key!";
291
+				$fields_on_model = self::_get_model(get_class($this))->field_settings();
292
+				$obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value);
293
+				foreach ($fields_on_model as $field_obj) {
294
+					if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
295
+						 && $field_obj->get_name() !== $field_name
296
+					) {
297
+						$this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name()));
298
+					}
299
+				}
300
+				//oh this model object has an ID? well make sure its in the entity mapper
301
+				$this->get_model()->add_to_entity_map($this);
302
+			}
303
+			//let's unset any cache for this field_name from the $_cached_properties property.
304
+			$this->_clear_cached_property($field_name);
305
+		} else {
306
+			throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name));
307
+		}
308
+	}
309
+
310
+
311
+
312
+	/**
313
+	 * This sets the field value on the db column if it exists for the given $column_name or
314
+	 * saves it to EE_Extra_Meta if the given $column_name does not match a db column.
315
+	 *
316
+	 * @see EE_message::get_column_value for related documentation on the necessity of this method.
317
+	 * @param string $field_name  Must be the exact column name.
318
+	 * @param mixed  $field_value The value to set.
319
+	 * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs.
320
+	 * @throws \EE_Error
321
+	 */
322
+	public function set_field_or_extra_meta($field_name, $field_value)
323
+	{
324
+		if ($this->get_model()->has_field($field_name)) {
325
+			$this->set($field_name, $field_value);
326
+			return true;
327
+		} else {
328
+			//ensure this object is saved first so that extra meta can be properly related.
329
+			$this->save();
330
+			return $this->update_extra_meta($field_name, $field_value);
331
+		}
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * This retrieves the value of the db column set on this class or if that's not present
338
+	 * it will attempt to retrieve from extra_meta if found.
339
+	 * Example Usage:
340
+	 * Via EE_Message child class:
341
+	 * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to",
342
+	 * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may
343
+	 * also have additional main fields specific to the messenger.  The system accommodates those extra
344
+	 * fields through the EE_Extra_Meta table.  This method allows for EE_messengers to retrieve the
345
+	 * value for those extra fields dynamically via the EE_message object.
346
+	 *
347
+	 * @param  string $field_name expecting the fully qualified field name.
348
+	 * @return mixed|null  value for the field if found.  null if not found.
349
+	 * @throws \EE_Error
350
+	 */
351
+	public function get_field_or_extra_meta($field_name)
352
+	{
353
+		if ($this->get_model()->has_field($field_name)) {
354
+			$column_value = $this->get($field_name);
355
+		} else {
356
+			//This isn't a column in the main table, let's see if it is in the extra meta.
357
+			$column_value = $this->get_extra_meta($field_name, true, null);
358
+		}
359
+		return $column_value;
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally for being able to reference what timezone we are running conversions on when converting TO the internal timezone (UTC
366
+	 * Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is available to all child classes that may be using the EE_Datetime_Field for a field data type.
367
+	 *
368
+	 * @access public
369
+	 * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php
370
+	 * @return void
371
+	 * @throws \EE_Error
372
+	 */
373
+	public function set_timezone($timezone = '')
374
+	{
375
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
376
+		//make sure we clear all cached properties because they won't be relevant now
377
+		$this->_clear_cached_properties();
378
+		//make sure we update field settings and the date for all EE_Datetime_Fields
379
+		$model_fields = $this->get_model()->field_settings(false);
380
+		foreach ($model_fields as $field_name => $field_obj) {
381
+			if ($field_obj instanceof EE_Datetime_Field) {
382
+				$field_obj->set_timezone($this->_timezone);
383
+				if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
384
+					$this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
385
+				}
386
+			}
387
+		}
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * This just returns whatever is set for the current timezone.
394
+	 *
395
+	 * @access public
396
+	 * @return string timezone string
397
+	 */
398
+	public function get_timezone()
399
+	{
400
+		return $this->_timezone;
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * This sets the internal date format to what is sent in to be used as the new default for the class
407
+	 * internally instead of wp set date format options
408
+	 *
409
+	 * @since 4.6
410
+	 * @param string $format should be a format recognizable by PHP date() functions.
411
+	 */
412
+	public function set_date_format($format)
413
+	{
414
+		$this->_dt_frmt = $format;
415
+		//clear cached_properties because they won't be relevant now.
416
+		$this->_clear_cached_properties();
417
+	}
418
+
419
+
420
+
421
+	/**
422
+	 * This sets the internal time format string to what is sent in to be used as the new default for the
423
+	 * class internally instead of wp set time format options.
424
+	 *
425
+	 * @since 4.6
426
+	 * @param string $format should be a format recognizable by PHP date() functions.
427
+	 */
428
+	public function set_time_format($format)
429
+	{
430
+		$this->_tm_frmt = $format;
431
+		//clear cached_properties because they won't be relevant now.
432
+		$this->_clear_cached_properties();
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 * This returns the current internal set format for the date and time formats.
439
+	 *
440
+	 * @param bool $full           if true (default), then return the full format.  Otherwise will return an array where the
441
+	 *                             first value is the date format and the second value is the time format.
442
+	 * @return mixed string|array
443
+	 */
444
+	public function get_format($full = true)
445
+	{
446
+		return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 * cache
453
+	 * stores the passed model object on the current model object.
454
+	 * In certain circumstances, we can use this cached model object instead of querying for another one entirely.
455
+	 *
456
+	 * @param string        $relationName    one of the keys in the _model_relations array on the model. Eg 'Registration' associated with this model object
457
+	 * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, that could be a payment or a registration)
458
+	 * @param null          $cache_id        a string or number that will be used as the key for any Belongs_To_Many items which will be stored in an array on this object
459
+	 * @throws EE_Error
460
+	 * @return mixed    index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array)
461
+	 */
462
+	public function cache($relationName = '', $object_to_cache = null, $cache_id = null)
463
+	{
464
+		// its entirely possible that there IS no related object yet in which case there is nothing to cache.
465
+		if ( ! $object_to_cache instanceof EE_Base_Class) {
466
+			return false;
467
+		}
468
+		// also get "how" the object is related, or throw an error
469
+		if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) {
470
+			throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this)));
471
+		}
472
+		// how many things are related ?
473
+		if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
474
+			// if it's a "belongs to" relationship, then there's only one related model object  eg, if this is a registration, there's only 1 attendee for it
475
+			// so for these model objects just set it to be cached
476
+			$this->_model_relations[$relationName] = $object_to_cache;
477
+			$return = true;
478
+		} else {
479
+			// otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type.
480
+			// eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array
481
+			if ( ! is_array($this->_model_relations[$relationName])) {
482
+				// if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array
483
+				$this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array();
484
+			}
485
+			// first check for a cache_id which is normally empty
486
+			if ( ! empty($cache_id)) {
487
+				// if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on
488
+				$this->_model_relations[$relationName][$cache_id] = $object_to_cache;
489
+				$return = $cache_id;
490
+			} elseif ($object_to_cache->ID()) {
491
+				// OR the cached object originally came from the db, so let's just use it's PK for an ID
492
+				$this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache;
493
+				$return = $object_to_cache->ID();
494
+			} else {
495
+				// OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID
496
+				$this->_model_relations[$relationName][] = $object_to_cache;
497
+				// move the internal pointer to the end of the array
498
+				end($this->_model_relations[$relationName]);
499
+				// and grab the key so that we can return it
500
+				$return = key($this->_model_relations[$relationName]);
501
+			}
502
+		}
503
+		return $return;
504
+	}
505
+
506
+
507
+
508
+	/**
509
+	 * For adding an item to the cached_properties property.
510
+	 *
511
+	 * @access protected
512
+	 * @param string      $fieldname the property item the corresponding value is for.
513
+	 * @param mixed       $value     The value we are caching.
514
+	 * @param string|null $cache_type
515
+	 * @return void
516
+	 * @throws \EE_Error
517
+	 */
518
+	protected function _set_cached_property($fieldname, $value, $cache_type = null)
519
+	{
520
+		//first make sure this property exists
521
+		$this->get_model()->field_settings_for($fieldname);
522
+		$cache_type = empty($cache_type) ? 'standard' : $cache_type;
523
+		$this->_cached_properties[$fieldname][$cache_type] = $value;
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist.
530
+	 * This also SETS the cache if we return the actual property!
531
+	 *
532
+	 * @param string $fieldname        the name of the property we're trying to retrieve
533
+	 * @param bool   $pretty
534
+	 * @param string $extra_cache_ref  This allows the user to specify an extra cache ref for the given property
535
+	 *                                 (in cases where the same property may be used for different outputs
536
+	 *                                 - i.e. datetime, money etc.)
537
+	 *                                 It can also accept certain pre-defined "schema" strings
538
+	 *                                 to define how to output the property.
539
+	 *                                 see the field's prepare_for_pretty_echoing for what strings can be used
540
+	 * @return mixed                   whatever the value for the property is we're retrieving
541
+	 * @throws \EE_Error
542
+	 */
543
+	protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null)
544
+	{
545
+		//verify the field exists
546
+		$this->get_model()->field_settings_for($fieldname);
547
+		$cache_type = $pretty ? 'pretty' : 'standard';
548
+		$cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
549
+		if (isset($this->_cached_properties[$fieldname][$cache_type])) {
550
+			return $this->_cached_properties[$fieldname][$cache_type];
551
+		}
552
+		$field_obj = $this->get_model()->field_settings_for($fieldname);
553
+		if ($field_obj instanceof EE_Model_Field_Base) {
554
+			// If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct
555
+			if ($field_obj instanceof EE_Datetime_Field) {
556
+				$this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref);
557
+			}
558
+			if ( ! isset($this->_fields[$fieldname])) {
559
+				$this->_fields[$fieldname] = null;
560
+			}
561
+			$value = $pretty
562
+				? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
563
+				: $field_obj->prepare_for_get($this->_fields[$fieldname]);
564
+			$this->_set_cached_property($fieldname, $value, $cache_type);
565
+			return $value;
566
+		}
567
+		return null;
568
+	}
569
+
570
+
571
+
572
+	/**
573
+	 * set timezone, formats, and output for EE_Datetime_Field objects
574
+	 *
575
+	 * @param \EE_Datetime_Field $datetime_field
576
+	 * @param bool               $pretty
577
+	 * @param null $date_or_time
578
+	 * @return void
579
+	 * @throws \EE_Error
580
+	 */
581
+	protected function _prepare_datetime_field(
582
+		EE_Datetime_Field $datetime_field,
583
+		$pretty = false,
584
+		$date_or_time = null
585
+	) {
586
+		$datetime_field->set_timezone($this->_timezone);
587
+		$datetime_field->set_date_format($this->_dt_frmt, $pretty);
588
+		$datetime_field->set_time_format($this->_tm_frmt, $pretty);
589
+		//set the output returned
590
+		switch ($date_or_time) {
591
+			case 'D' :
592
+				$datetime_field->set_date_time_output('date');
593
+				break;
594
+			case 'T' :
595
+				$datetime_field->set_date_time_output('time');
596
+				break;
597
+			default :
598
+				$datetime_field->set_date_time_output();
599
+		}
600
+	}
601
+
602
+
603
+
604
+	/**
605
+	 * This just takes care of clearing out the cached_properties
606
+	 *
607
+	 * @return void
608
+	 */
609
+	protected function _clear_cached_properties()
610
+	{
611
+		$this->_cached_properties = array();
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * This just clears out ONE property if it exists in the cache
618
+	 *
619
+	 * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
620
+	 * @return void
621
+	 */
622
+	protected function _clear_cached_property($property_name)
623
+	{
624
+		if (isset($this->_cached_properties[$property_name])) {
625
+			unset($this->_cached_properties[$property_name]);
626
+		}
627
+	}
628
+
629
+
630
+
631
+	/**
632
+	 * Ensures that this related thing is a model object.
633
+	 *
634
+	 * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
635
+	 * @param string $model_name   name of the related thing, eg 'Attendee',
636
+	 * @return EE_Base_Class
637
+	 * @throws \EE_Error
638
+	 */
639
+	protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
640
+	{
641
+		$other_model_instance = self::_get_model_instance_with_name(
642
+			self::_get_model_classname($model_name),
643
+			$this->_timezone
644
+		);
645
+		return $other_model_instance->ensure_is_obj($object_or_id);
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * Forgets the cached model of the given relation Name. So the next time we request it,
652
+	 * we will fetch it again from the database. (Handy if you know it's changed somehow).
653
+	 * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
654
+	 * then only remove that one object from our cached array. Otherwise, clear the entire list
655
+	 *
656
+	 * @param string $relationName                         one of the keys in the _model_relations array on the model. Eg 'Registration'
657
+	 * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
658
+	 *                                                     if you intend to use $clear_all = TRUE, or the relation only has 1 object anyways (ie, it's a BelongsToRelation)
659
+	 * @param bool   $clear_all                            This flags clearing the entire cache relation property if this is HasMany or HABTM.
660
+	 * @throws EE_Error
661
+	 * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all
662
+	 */
663
+	public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
664
+	{
665
+		$relationship_to_model = $this->get_model()->related_settings_for($relationName);
666
+		$index_in_cache = '';
667
+		if ( ! $relationship_to_model) {
668
+			throw new EE_Error(
669
+				sprintf(
670
+					__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
671
+					$relationName,
672
+					get_class($this)
673
+				)
674
+			);
675
+		}
676
+		if ($clear_all) {
677
+			$obj_removed = true;
678
+			$this->_model_relations[$relationName] = null;
679
+		} elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
680
+			$obj_removed = $this->_model_relations[$relationName];
681
+			$this->_model_relations[$relationName] = null;
682
+		} else {
683
+			if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) {
684
+				$index_in_cache = $object_to_remove_or_index_into_array->ID();
685
+				if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) {
686
+					$index_found_at = null;
687
+					//find this object in the array even though it has a different key
688
+					foreach ($this->_model_relations[$relationName] as $index => $obj) {
689
+						if (
690
+							$obj instanceof EE_Base_Class
691
+							&& (
692
+								$obj == $object_to_remove_or_index_into_array
693
+								|| $obj->ID() === $object_to_remove_or_index_into_array->ID()
694
+							)
695
+						) {
696
+							$index_found_at = $index;
697
+							break;
698
+						}
699
+					}
700
+					if ($index_found_at) {
701
+						$index_in_cache = $index_found_at;
702
+					} else {
703
+						//it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
704
+						//if it wasn't in it to begin with. So we're done
705
+						return $object_to_remove_or_index_into_array;
706
+					}
707
+				}
708
+			} elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
709
+				//so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
710
+				foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
711
+					if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
712
+						$index_in_cache = $index;
713
+					}
714
+				}
715
+			} else {
716
+				$index_in_cache = $object_to_remove_or_index_into_array;
717
+			}
718
+			//supposedly we've found it. But it could just be that the client code
719
+			//provided a bad index/object
720
+			if (
721
+			isset(
722
+				$this->_model_relations[$relationName],
723
+				$this->_model_relations[$relationName][$index_in_cache]
724
+			)
725
+			) {
726
+				$obj_removed = $this->_model_relations[$relationName][$index_in_cache];
727
+				unset($this->_model_relations[$relationName][$index_in_cache]);
728
+			} else {
729
+				//that thing was never cached anyways.
730
+				$obj_removed = null;
731
+			}
732
+		}
733
+		return $obj_removed;
734
+	}
735
+
736
+
737
+
738
+	/**
739
+	 * update_cache_after_object_save
740
+	 * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has obtained after being saved to the db
741
+	 *
742
+	 * @param string         $relationName       - the type of object that is cached
743
+	 * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
744
+	 * @param string         $current_cache_id   - the ID that was used when originally caching the object
745
+	 * @return boolean TRUE on success, FALSE on fail
746
+	 * @throws \EE_Error
747
+	 */
748
+	public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '')
749
+	{
750
+		// verify that incoming object is of the correct type
751
+		$obj_class = 'EE_' . $relationName;
752
+		if ($newly_saved_object instanceof $obj_class) {
753
+			/* @type EE_Base_Class $newly_saved_object */
754
+			// now get the type of relation
755
+			$relationship_to_model = $this->get_model()->related_settings_for($relationName);
756
+			// if this is a 1:1 relationship
757
+			if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
758
+				// then just replace the cached object with the newly saved object
759
+				$this->_model_relations[$relationName] = $newly_saved_object;
760
+				return true;
761
+				// or if it's some kind of sordid feral polyamorous relationship...
762
+			} elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) {
763
+				// then remove the current cached item
764
+				unset($this->_model_relations[$relationName][$current_cache_id]);
765
+				// and cache the newly saved object using it's new ID
766
+				$this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
767
+				return true;
768
+			}
769
+		}
770
+		return false;
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
777
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
778
+	 *
779
+	 * @param string $relationName
780
+	 * @return EE_Base_Class
781
+	 */
782
+	public function get_one_from_cache($relationName)
783
+	{
784
+		$cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null;
785
+		if (is_array($cached_array_or_object)) {
786
+			return array_shift($cached_array_or_object);
787
+		} else {
788
+			return $cached_array_or_object;
789
+		}
790
+	}
791
+
792
+
793
+
794
+	/**
795
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
796
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
797
+	 *
798
+	 * @param string $relationName
799
+	 * @throws \EE_Error
800
+	 * @return EE_Base_Class[] NOT necessarily indexed by primary keys
801
+	 */
802
+	public function get_all_from_cache($relationName)
803
+	{
804
+		$objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
805
+		// if the result is not an array, but exists, make it an array
806
+		$objects = is_array($objects) ? $objects : array($objects);
807
+		//bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
808
+		//basically, if this model object was stored in the session, and these cached model objects
809
+		//already have IDs, let's make sure they're in their model's entity mapper
810
+		//otherwise we will have duplicates next time we call
811
+		// EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
812
+		$model = EE_Registry::instance()->load_model($relationName);
813
+		foreach ($objects as $model_object) {
814
+			if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
815
+				//ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
816
+				if ($model_object->ID()) {
817
+					$model->add_to_entity_map($model_object);
818
+				}
819
+			} else {
820
+				throw new EE_Error(
821
+					sprintf(
822
+						__(
823
+							'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
824
+							'event_espresso'
825
+						),
826
+						$relationName,
827
+						gettype($model_object)
828
+					)
829
+				);
830
+			}
831
+		}
832
+		return $objects;
833
+	}
834
+
835
+
836
+
837
+	/**
838
+	 * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
839
+	 * matching the given query conditions.
840
+	 *
841
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
842
+	 * @param int   $limit              How many objects to return.
843
+	 * @param array $query_params       Any additional conditions on the query.
844
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
845
+	 *                                  you can indicate just the columns you want returned
846
+	 * @return array|EE_Base_Class[]
847
+	 * @throws \EE_Error
848
+	 */
849
+	public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
850
+	{
851
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
852
+			? $this->get_model()->get_primary_key_field()->get_name()
853
+			: $field_to_order_by;
854
+		$current_value = ! empty($field) ? $this->get($field) : null;
855
+		if (empty($field) || empty($current_value)) {
856
+			return array();
857
+		}
858
+		return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
859
+	}
860
+
861
+
862
+
863
+	/**
864
+	 * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
865
+	 * matching the given query conditions.
866
+	 *
867
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
868
+	 * @param int   $limit              How many objects to return.
869
+	 * @param array $query_params       Any additional conditions on the query.
870
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
871
+	 *                                  you can indicate just the columns you want returned
872
+	 * @return array|EE_Base_Class[]
873
+	 * @throws \EE_Error
874
+	 */
875
+	public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
876
+	{
877
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
878
+			? $this->get_model()->get_primary_key_field()->get_name()
879
+			: $field_to_order_by;
880
+		$current_value = ! empty($field) ? $this->get($field) : null;
881
+		if (empty($field) || empty($current_value)) {
882
+			return array();
883
+		}
884
+		return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
885
+	}
886
+
887
+
888
+
889
+	/**
890
+	 * Returns the next EE_Base_Class object in sequence from this object as found in the database
891
+	 * matching the given query conditions.
892
+	 *
893
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
894
+	 * @param array $query_params       Any additional conditions on the query.
895
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
896
+	 *                                  you can indicate just the columns you want returned
897
+	 * @return array|EE_Base_Class
898
+	 * @throws \EE_Error
899
+	 */
900
+	public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
901
+	{
902
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
903
+			? $this->get_model()->get_primary_key_field()->get_name()
904
+			: $field_to_order_by;
905
+		$current_value = ! empty($field) ? $this->get($field) : null;
906
+		if (empty($field) || empty($current_value)) {
907
+			return array();
908
+		}
909
+		return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select);
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * Returns the previous EE_Base_Class object in sequence from this object as found in the database
916
+	 * matching the given query conditions.
917
+	 *
918
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
919
+	 * @param array $query_params       Any additional conditions on the query.
920
+	 * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
921
+	 *                                  you can indicate just the column you want returned
922
+	 * @return array|EE_Base_Class
923
+	 * @throws \EE_Error
924
+	 */
925
+	public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
926
+	{
927
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
928
+			? $this->get_model()->get_primary_key_field()->get_name()
929
+			: $field_to_order_by;
930
+		$current_value = ! empty($field) ? $this->get($field) : null;
931
+		if (empty($field) || empty($current_value)) {
932
+			return array();
933
+		}
934
+		return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select);
935
+	}
936
+
937
+
938
+
939
+	/**
940
+	 * Overrides parent because parent expects old models.
941
+	 * This also doesn't do any validation, and won't work for serialized arrays
942
+	 *
943
+	 * @param string $field_name
944
+	 * @param mixed  $field_value_from_db
945
+	 * @throws \EE_Error
946
+	 */
947
+	public function set_from_db($field_name, $field_value_from_db)
948
+	{
949
+		$field_obj = $this->get_model()->field_settings_for($field_name);
950
+		if ($field_obj instanceof EE_Model_Field_Base) {
951
+			//you would think the DB has no NULLs for non-null label fields right? wrong!
952
+			//eg, a CPT model object could have an entry in the posts table, but no
953
+			//entry in the meta table. Meaning that all its columns in the meta table
954
+			//are null! yikes! so when we find one like that, use defaults for its meta columns
955
+			if ($field_value_from_db === null) {
956
+				if ($field_obj->is_nullable()) {
957
+					//if the field allows nulls, then let it be null
958
+					$field_value = null;
959
+				} else {
960
+					$field_value = $field_obj->get_default_value();
961
+				}
962
+			} else {
963
+				$field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
964
+			}
965
+			$this->_fields[$field_name] = $field_value;
966
+			$this->_clear_cached_property($field_name);
967
+		}
968
+	}
969
+
970
+
971
+
972
+	/**
973
+	 * verifies that the specified field is of the correct type
974
+	 *
975
+	 * @param string $field_name
976
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
977
+	 *                                (in cases where the same property may be used for different outputs
978
+	 *                                - i.e. datetime, money etc.)
979
+	 * @return mixed
980
+	 * @throws \EE_Error
981
+	 */
982
+	public function get($field_name, $extra_cache_ref = null)
983
+	{
984
+		return $this->_get_cached_property($field_name, false, $extra_cache_ref);
985
+	}
986
+
987
+
988
+
989
+	/**
990
+	 * This method simply returns the RAW unprocessed value for the given property in this class
991
+	 *
992
+	 * @param  string $field_name A valid fieldname
993
+	 * @return mixed              Whatever the raw value stored on the property is.
994
+	 * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
995
+	 */
996
+	public function get_raw($field_name)
997
+	{
998
+		$field_settings = $this->get_model()->field_settings_for($field_name);
999
+		return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
1000
+			? $this->_fields[$field_name]->format('U')
1001
+			: $this->_fields[$field_name];
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * This is used to return the internal DateTime object used for a field that is a
1008
+	 * EE_Datetime_Field.
1009
+	 *
1010
+	 * @param string $field_name               The field name retrieving the DateTime object.
1011
+	 * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
1012
+	 * @throws \EE_Error
1013
+	 *                                         an error is set and false returned.  If the field IS an
1014
+	 *                                         EE_Datetime_Field and but the field value is null, then
1015
+	 *                                         just null is returned (because that indicates that likely
1016
+	 *                                         this field is nullable).
1017
+	 */
1018
+	public function get_DateTime_object($field_name)
1019
+	{
1020
+		$field_settings = $this->get_model()->field_settings_for($field_name);
1021
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1022
+			EE_Error::add_error(
1023
+				sprintf(
1024
+					__(
1025
+						'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
1026
+						'event_espresso'
1027
+					),
1028
+					$field_name
1029
+				),
1030
+				__FILE__,
1031
+				__FUNCTION__,
1032
+				__LINE__
1033
+			);
1034
+			return false;
1035
+		}
1036
+		return $this->_fields[$field_name];
1037
+	}
1038
+
1039
+
1040
+
1041
+	/**
1042
+	 * To be used in template to immediately echo out the value, and format it for output.
1043
+	 * Eg, should call stripslashes and whatnot before echoing
1044
+	 *
1045
+	 * @param string $field_name      the name of the field as it appears in the DB
1046
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1047
+	 *                                (in cases where the same property may be used for different outputs
1048
+	 *                                - i.e. datetime, money etc.)
1049
+	 * @return void
1050
+	 * @throws \EE_Error
1051
+	 */
1052
+	public function e($field_name, $extra_cache_ref = null)
1053
+	{
1054
+		echo $this->get_pretty($field_name, $extra_cache_ref);
1055
+	}
1056
+
1057
+
1058
+
1059
+	/**
1060
+	 * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1061
+	 * can be easily used as the value of form input.
1062
+	 *
1063
+	 * @param string $field_name
1064
+	 * @return void
1065
+	 * @throws \EE_Error
1066
+	 */
1067
+	public function f($field_name)
1068
+	{
1069
+		$this->e($field_name, 'form_input');
1070
+	}
1071
+
1072
+
1073
+
1074
+	/**
1075
+	 * @param string $field_name
1076
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1077
+	 *                                (in cases where the same property may be used for different outputs
1078
+	 *                                - i.e. datetime, money etc.)
1079
+	 * @return mixed
1080
+	 * @throws \EE_Error
1081
+	 */
1082
+	public function get_pretty($field_name, $extra_cache_ref = null)
1083
+	{
1084
+		return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1085
+	}
1086
+
1087
+
1088
+
1089
+	/**
1090
+	 * This simply returns the datetime for the given field name
1091
+	 * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1092
+	 * (and the equivalent e_date, e_time, e_datetime).
1093
+	 *
1094
+	 * @access   protected
1095
+	 * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1096
+	 * @param string   $dt_frmt      valid datetime format used for date
1097
+	 *                               (if '' then we just use the default on the field,
1098
+	 *                               if NULL we use the last-used format)
1099
+	 * @param string   $tm_frmt      Same as above except this is for time format
1100
+	 * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1101
+	 * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1102
+	 * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1103
+	 *                               if field is not a valid dtt field, or void if echoing
1104
+	 * @throws \EE_Error
1105
+	 */
1106
+	protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1107
+	{
1108
+		// clear cached property
1109
+		$this->_clear_cached_property($field_name);
1110
+		//reset format properties because they are used in get()
1111
+		$this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt;
1112
+		$this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt;
1113
+		if ($echo) {
1114
+			$this->e($field_name, $date_or_time);
1115
+			return '';
1116
+		}
1117
+		return $this->get($field_name, $date_or_time);
1118
+	}
1119
+
1120
+
1121
+
1122
+	/**
1123
+	 * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other echoes
1124
+	 * the pretty value for dtt)
1125
+	 *
1126
+	 * @param  string $field_name name of model object datetime field holding the value
1127
+	 * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1128
+	 * @return string            datetime value formatted
1129
+	 * @throws \EE_Error
1130
+	 */
1131
+	public function get_date($field_name, $format = '')
1132
+	{
1133
+		return $this->_get_datetime($field_name, $format, null, 'D');
1134
+	}
1135
+
1136
+
1137
+
1138
+	/**
1139
+	 * @param      $field_name
1140
+	 * @param string $format
1141
+	 * @throws \EE_Error
1142
+	 */
1143
+	public function e_date($field_name, $format = '')
1144
+	{
1145
+		$this->_get_datetime($field_name, $format, null, 'D', true);
1146
+	}
1147
+
1148
+
1149
+
1150
+	/**
1151
+	 * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other echoes
1152
+	 * the pretty value for dtt)
1153
+	 *
1154
+	 * @param  string $field_name name of model object datetime field holding the value
1155
+	 * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1156
+	 * @return string             datetime value formatted
1157
+	 * @throws \EE_Error
1158
+	 */
1159
+	public function get_time($field_name, $format = '')
1160
+	{
1161
+		return $this->_get_datetime($field_name, null, $format, 'T');
1162
+	}
1163
+
1164
+
1165
+
1166
+	/**
1167
+	 * @param      $field_name
1168
+	 * @param string $format
1169
+	 * @throws \EE_Error
1170
+	 */
1171
+	public function e_time($field_name, $format = '')
1172
+	{
1173
+		$this->_get_datetime($field_name, null, $format, 'T', true);
1174
+	}
1175
+
1176
+
1177
+
1178
+	/**
1179
+	 * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other
1180
+	 * echoes the pretty value for dtt)
1181
+	 *
1182
+	 * @param  string $field_name name of model object datetime field holding the value
1183
+	 * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1184
+	 * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1185
+	 * @return string             datetime value formatted
1186
+	 * @throws \EE_Error
1187
+	 */
1188
+	public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1189
+	{
1190
+		return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1191
+	}
1192
+
1193
+
1194
+
1195
+	/**
1196
+	 * @param string $field_name
1197
+	 * @param string $dt_frmt
1198
+	 * @param string $tm_frmt
1199
+	 * @throws \EE_Error
1200
+	 */
1201
+	public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1202
+	{
1203
+		$this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1204
+	}
1205
+
1206
+
1207
+
1208
+	/**
1209
+	 * Get the i8ln value for a date using the WordPress @see date_i18n function.
1210
+	 *
1211
+	 * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1212
+	 * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format on the object will be used.
1213
+	 * @return string Date and time string in set locale or false if no field exists for the given
1214
+	 * @throws \EE_Error
1215
+	 *                           field name.
1216
+	 */
1217
+	public function get_i18n_datetime($field_name, $format = '')
1218
+	{
1219
+		$format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1220
+		return date_i18n(
1221
+			$format,
1222
+			EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1223
+		);
1224
+	}
1225
+
1226
+
1227
+
1228
+	/**
1229
+	 * This method validates whether the given field name is a valid field on the model object as well as it is of a type EE_Datetime_Field.  On success there will be returned the field settings.  On fail an EE_Error exception is thrown.
1230
+	 *
1231
+	 * @param  string $field_name The field name being checked
1232
+	 * @throws EE_Error
1233
+	 * @return EE_Datetime_Field
1234
+	 */
1235
+	protected function _get_dtt_field_settings($field_name)
1236
+	{
1237
+		$field = $this->get_model()->field_settings_for($field_name);
1238
+		//check if field is dtt
1239
+		if ($field instanceof EE_Datetime_Field) {
1240
+			return $field;
1241
+		} else {
1242
+			throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor',
1243
+				'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1244
+		}
1245
+	}
1246
+
1247
+
1248
+
1249
+
1250
+	/**
1251
+	 * NOTE ABOUT BELOW:
1252
+	 * These convenience date and time setters are for setting date and time independently.  In other words you might want to change the time on a datetime_field but leave the date the same (or vice versa).
1253
+	 * IF on the other hand you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) method and make sure you send the entire datetime value for setting.
1254
+	 */
1255
+	/**
1256
+	 * sets the time on a datetime property
1257
+	 *
1258
+	 * @access protected
1259
+	 * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1260
+	 * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1261
+	 * @throws \EE_Error
1262
+	 */
1263
+	protected function _set_time_for($time, $fieldname)
1264
+	{
1265
+		$this->_set_date_time('T', $time, $fieldname);
1266
+	}
1267
+
1268
+
1269
+
1270
+	/**
1271
+	 * sets the date on a datetime property
1272
+	 *
1273
+	 * @access protected
1274
+	 * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1275
+	 * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1276
+	 * @throws \EE_Error
1277
+	 */
1278
+	protected function _set_date_for($date, $fieldname)
1279
+	{
1280
+		$this->_set_date_time('D', $date, $fieldname);
1281
+	}
1282
+
1283
+
1284
+
1285
+	/**
1286
+	 * This takes care of setting a date or time independently on a given model object property. This method also verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field
1287
+	 *
1288
+	 * @access protected
1289
+	 * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1290
+	 * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1291
+	 * @param string          $fieldname      the name of the field the date OR time is being set on (must match a EE_Datetime_Field property)
1292
+	 * @throws \EE_Error
1293
+	 */
1294
+	protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1295
+	{
1296
+		$field = $this->_get_dtt_field_settings($fieldname);
1297
+		$field->set_timezone($this->_timezone);
1298
+		$field->set_date_format($this->_dt_frmt);
1299
+		$field->set_time_format($this->_tm_frmt);
1300
+		switch ($what) {
1301
+			case 'T' :
1302
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1303
+					$datetime_value,
1304
+					$this->_fields[$fieldname]
1305
+				);
1306
+				break;
1307
+			case 'D' :
1308
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1309
+					$datetime_value,
1310
+					$this->_fields[$fieldname]
1311
+				);
1312
+				break;
1313
+			case 'B' :
1314
+				$this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1315
+				break;
1316
+		}
1317
+		$this->_clear_cached_property($fieldname);
1318
+	}
1319
+
1320
+
1321
+
1322
+	/**
1323
+	 * This will return a timestamp for the website timezone but ONLY when the current website timezone is different than the timezone set for the website.
1324
+	 * NOTE, this currently only works well with methods that return values.  If you use it with methods that echo values the $_timestamp property may not get reset to its original value and that could lead to some unexpected results!
1325
+	 *
1326
+	 * @access public
1327
+	 * @param string               $field_name This is the name of the field on the object that contains the date/time value being returned.
1328
+	 * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1329
+	 * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1330
+	 * @param string               $prepend    You can include something to prepend on the timestamp
1331
+	 * @param string               $append     You can include something to append on the timestamp
1332
+	 * @throws EE_Error
1333
+	 * @return string timestamp
1334
+	 */
1335
+	public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = null, $prepend = '', $append = '')
1336
+	{
1337
+		$timezone = EEH_DTT_Helper::get_timezone();
1338
+		if ($timezone === $this->_timezone) {
1339
+			return '';
1340
+		}
1341
+		$original_timezone = $this->_timezone;
1342
+		$this->set_timezone($timezone);
1343
+		$fn = (array)$field_name;
1344
+		$args = array_merge($fn, (array)$args);
1345
+		if ( ! method_exists($this, $callback)) {
1346
+			throw new EE_Error(
1347
+				sprintf(
1348
+					__(
1349
+						'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1350
+						'event_espresso'
1351
+					),
1352
+					$callback
1353
+				)
1354
+			);
1355
+		}
1356
+		$args = (array)$args;
1357
+		$return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1358
+		$this->set_timezone($original_timezone);
1359
+		return $return;
1360
+	}
1361
+
1362
+
1363
+
1364
+	/**
1365
+	 * Deletes this model object.
1366
+	 * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should override
1367
+	 * `EE_Base_Class::_delete` NOT this class.
1368
+	 *
1369
+	 * @return boolean | int
1370
+	 * @throws \EE_Error
1371
+	 */
1372
+	public function delete()
1373
+	{
1374
+		/**
1375
+		 * Called just before the `EE_Base_Class::_delete` method call.
1376
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1377
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1378
+		 * soft deletes (trash) the object and does not permanently delete it.
1379
+		 *
1380
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1381
+		 */
1382
+		do_action('AHEE__EE_Base_Class__delete__before', $this);
1383
+		$result = $this->_delete();
1384
+		/**
1385
+		 * Called just after the `EE_Base_Class::_delete` method call.
1386
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1387
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1388
+		 * soft deletes (trash) the object and does not permanently delete it.
1389
+		 *
1390
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1391
+		 * @param boolean       $result
1392
+		 */
1393
+		do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1394
+		return $result;
1395
+	}
1396
+
1397
+
1398
+
1399
+	/**
1400
+	 * Calls the specific delete method for the instantiated class.
1401
+	 * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override default
1402
+	 * functionality for "delete" (which is to call `permanently_delete`) should override this method NOT `EE_Base_Class::delete`
1403
+	 *
1404
+	 * @return bool|int
1405
+	 * @throws \EE_Error
1406
+	 */
1407
+	protected function _delete()
1408
+	{
1409
+		return $this->delete_permanently();
1410
+	}
1411
+
1412
+
1413
+
1414
+	/**
1415
+	 * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error)
1416
+	 *
1417
+	 * @return bool | int
1418
+	 * @throws \EE_Error
1419
+	 */
1420
+	public function delete_permanently()
1421
+	{
1422
+		/**
1423
+		 * Called just before HARD deleting a model object
1424
+		 *
1425
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1426
+		 */
1427
+		do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1428
+		$model = $this->get_model();
1429
+		$result = $model->delete_permanently_by_ID($this->ID());
1430
+		$this->refresh_cache_of_related_objects();
1431
+		/**
1432
+		 * Called just after HARD deleting a model object
1433
+		 *
1434
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1435
+		 * @param boolean       $result
1436
+		 */
1437
+		do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1438
+		return $result;
1439
+	}
1440
+
1441
+
1442
+
1443
+	/**
1444
+	 * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1445
+	 * related model objects
1446
+	 *
1447
+	 * @throws \EE_Error
1448
+	 */
1449
+	public function refresh_cache_of_related_objects()
1450
+	{
1451
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1452
+			if ( ! empty($this->_model_relations[$relation_name])) {
1453
+				$related_objects = $this->_model_relations[$relation_name];
1454
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
1455
+					//this relation only stores a single model object, not an array
1456
+					//but let's make it consistent
1457
+					$related_objects = array($related_objects);
1458
+				}
1459
+				foreach ($related_objects as $related_object) {
1460
+					//only refresh their cache if they're in memory
1461
+					if ($related_object instanceof EE_Base_Class) {
1462
+						$related_object->clear_cache($this->get_model()->get_this_model_name(), $this);
1463
+					}
1464
+				}
1465
+			}
1466
+		}
1467
+	}
1468
+
1469
+
1470
+
1471
+	/**
1472
+	 *        Saves this object to the database. An array may be supplied to set some values on this
1473
+	 * object just before saving.
1474
+	 *
1475
+	 * @access public
1476
+	 * @param array $set_cols_n_values keys are field names, values are their new values,
1477
+	 *                                 if provided during the save() method (often client code will change the fields' values before calling save)
1478
+	 * @throws \EE_Error
1479
+	 * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1480
+	 *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1481
+	 */
1482
+	public function save($set_cols_n_values = array())
1483
+	{
1484
+		/**
1485
+		 * Filters the fields we're about to save on the model object
1486
+		 *
1487
+		 * @param array         $set_cols_n_values
1488
+		 * @param EE_Base_Class $model_object
1489
+		 */
1490
+		$set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this);
1491
+		//set attributes as provided in $set_cols_n_values
1492
+		foreach ($set_cols_n_values as $column => $value) {
1493
+			$this->set($column, $value);
1494
+		}
1495
+		/**
1496
+		 * Saving a model object.
1497
+		 * Before we perform a save, this action is fired.
1498
+		 *
1499
+		 * @param EE_Base_Class $model_object the model object about to be saved.
1500
+		 */
1501
+		do_action('AHEE__EE_Base_Class__save__begin', $this);
1502
+		if ( ! $this->allow_persist()) {
1503
+			return 0;
1504
+		}
1505
+		//now get current attribute values
1506
+		$save_cols_n_values = $this->_fields;
1507
+		//if the object already has an ID, update it. Otherwise, insert it
1508
+		//also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1509
+		$old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object();
1510
+		$this->get_model()->assume_values_already_prepared_by_model_object(true);
1511
+		//does this model have an autoincrement PK?
1512
+		if ($this->get_model()->has_primary_key_field()) {
1513
+			if ($this->get_model()->get_primary_key_field()->is_auto_increment()) {
1514
+				//ok check if it's set, if so: update; if not, insert
1515
+				if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) {
1516
+					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1517
+				} else {
1518
+					unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]);
1519
+					$results = $this->get_model()->insert($save_cols_n_values);
1520
+					if ($results) {
1521
+						//if successful, set the primary key
1522
+						//but don't use the normal SET method, because it will check if
1523
+						//an item with the same ID exists in the mapper & db, then
1524
+						//will find it in the db (because we just added it) and THAT object
1525
+						//will get added to the mapper before we can add this one!
1526
+						//but if we just avoid using the SET method, all that headache can be avoided
1527
+						$pk_field_name = self::_get_primary_key_name(get_class($this));
1528
+						$this->_fields[$pk_field_name] = $results;
1529
+						$this->_clear_cached_property($pk_field_name);
1530
+						$this->get_model()->add_to_entity_map($this);
1531
+						$this->_update_cached_related_model_objs_fks();
1532
+					}
1533
+				}
1534
+			} else {//PK is NOT auto-increment
1535
+				//so check if one like it already exists in the db
1536
+				if ($this->get_model()->exists_by_ID($this->ID())) {
1537
+					if (WP_DEBUG && ! $this->in_entity_map()) {
1538
+						throw new EE_Error(
1539
+							sprintf(
1540
+								__('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1541
+									'event_espresso'),
1542
+								get_class($this),
1543
+								get_class($this->get_model()) . '::instance()->add_to_entity_map()',
1544
+								get_class($this->get_model()) . '::instance()->get_one_by_ID()',
1545
+								'<br />'
1546
+							)
1547
+						);
1548
+					}
1549
+					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1550
+				} else {
1551
+					$results = $this->get_model()->insert($save_cols_n_values);
1552
+					$this->_update_cached_related_model_objs_fks();
1553
+				}
1554
+			}
1555
+		} else {//there is NO primary key
1556
+			$already_in_db = false;
1557
+			foreach ($this->get_model()->unique_indexes() as $index) {
1558
+				$uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1559
+				if ($this->get_model()->exists(array($uniqueness_where_params))) {
1560
+					$already_in_db = true;
1561
+				}
1562
+			}
1563
+			if ($already_in_db) {
1564
+				$combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields());
1565
+				$results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values);
1566
+			} else {
1567
+				$results = $this->get_model()->insert($save_cols_n_values);
1568
+			}
1569
+		}
1570
+		//restore the old assumption about values being prepared by the model object
1571
+		$this->get_model()->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1572
+		/**
1573
+		 * After saving the model object this action is called
1574
+		 *
1575
+		 * @param EE_Base_Class $model_object which was just saved
1576
+		 * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1577
+		 *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1578
+		 */
1579
+		do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1580
+		return $results;
1581
+	}
1582
+
1583
+
1584
+
1585
+	/**
1586
+	 * Updates the foreign key on related models objects pointing to this to have this model object's ID
1587
+	 * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB is consistent)
1588
+	 * Especially useful in case we JUST added this model object ot the database
1589
+	 * and we want to let its cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on
1590
+	 * the transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether or not they exist in the DB (if they do, their DB records will be automatically updated)
1591
+	 *
1592
+	 * @return void
1593
+	 * @throws \EE_Error
1594
+	 */
1595
+	protected function _update_cached_related_model_objs_fks()
1596
+	{
1597
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1598
+			if ($relation_obj instanceof EE_Has_Many_Relation) {
1599
+				foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1600
+					$fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1601
+						$this->get_model()->get_this_model_name()
1602
+					);
1603
+					$related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1604
+					if ($related_model_obj_in_cache->ID()) {
1605
+						$related_model_obj_in_cache->save();
1606
+					}
1607
+				}
1608
+			}
1609
+		}
1610
+	}
1611
+
1612
+
1613
+
1614
+	/**
1615
+	 * Saves this model object and its NEW cached relations to the database.
1616
+	 * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1617
+	 * In order for that to work, we would need to mark model objects as dirty/clean...
1618
+	 * because otherwise, there's a potential for infinite looping of saving
1619
+	 * Saves the cached related model objects, and ensures the relation between them
1620
+	 * and this object and properly setup
1621
+	 *
1622
+	 * @return int ID of new model object on save; 0 on failure+
1623
+	 * @throws \EE_Error
1624
+	 */
1625
+	public function save_new_cached_related_model_objs()
1626
+	{
1627
+		//make sure this has been saved
1628
+		if ( ! $this->ID()) {
1629
+			$id = $this->save();
1630
+		} else {
1631
+			$id = $this->ID();
1632
+		}
1633
+		//now save all the NEW cached model objects  (ie they don't exist in the DB)
1634
+		foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1635
+			if ($this->_model_relations[$relationName]) {
1636
+				//is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1637
+				//or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1638
+				if ($relationObj instanceof EE_Belongs_To_Relation) {
1639
+					//add a relation to that relation type (which saves the appropriate thing in the process)
1640
+					//but ONLY if it DOES NOT exist in the DB
1641
+					/* @var $related_model_obj EE_Base_Class */
1642
+					$related_model_obj = $this->_model_relations[$relationName];
1643
+					//					if( ! $related_model_obj->ID()){
1644
+					$this->_add_relation_to($related_model_obj, $relationName);
1645
+					$related_model_obj->save_new_cached_related_model_objs();
1646
+					//					}
1647
+				} else {
1648
+					foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1649
+						//add a relation to that relation type (which saves the appropriate thing in the process)
1650
+						//but ONLY if it DOES NOT exist in the DB
1651
+						//						if( ! $related_model_obj->ID()){
1652
+						$this->_add_relation_to($related_model_obj, $relationName);
1653
+						$related_model_obj->save_new_cached_related_model_objs();
1654
+						//						}
1655
+					}
1656
+				}
1657
+			}
1658
+		}
1659
+		return $id;
1660
+	}
1661
+
1662
+
1663
+
1664
+	/**
1665
+	 * for getting a model while instantiated.
1666
+	 *
1667
+	 * @return \EEM_Base | \EEM_CPT_Base
1668
+	 */
1669
+	public function get_model()
1670
+	{
1671
+		$modelName = self::_get_model_classname(get_class($this));
1672
+		return self::_get_model_instance_with_name($modelName, $this->_timezone);
1673
+	}
1674
+
1675
+
1676
+
1677
+	/**
1678
+	 * @param $props_n_values
1679
+	 * @param $classname
1680
+	 * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1681
+	 * @throws \EE_Error
1682
+	 */
1683
+	protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1684
+	{
1685
+		//TODO: will not work for Term_Relationships because they have no PK!
1686
+		$primary_id_ref = self::_get_primary_key_name($classname);
1687
+		if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1688
+			$id = $props_n_values[$primary_id_ref];
1689
+			return self::_get_model($classname)->get_from_entity_map($id);
1690
+		}
1691
+		return false;
1692
+	}
1693
+
1694
+
1695
+
1696
+	/**
1697
+	 * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for the primary key (if present in incoming values).
1698
+	 * If there is a key in the incoming array that matches the primary key for the model AND it is not null, then we check the db. If there's a an object we return it.  If not we return false.
1699
+	 *
1700
+	 * @param  array  $props_n_values   incoming array of properties and their values
1701
+	 * @param  string $classname        the classname of the child class
1702
+	 * @param null    $timezone
1703
+	 * @param array   $date_formats     incoming date_formats in an array where the first value is the
1704
+	 *                                  date_format and the second value is the time format
1705
+	 * @return mixed (EE_Base_Class|bool)
1706
+	 * @throws \EE_Error
1707
+	 */
1708
+	protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1709
+	{
1710
+		$existing = null;
1711
+		if (self::_get_model($classname)->has_primary_key_field()) {
1712
+			$primary_id_ref = self::_get_primary_key_name($classname);
1713
+			if (array_key_exists($primary_id_ref, $props_n_values)
1714
+				&& ! empty($props_n_values[$primary_id_ref])
1715
+			) {
1716
+				$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1717
+					$props_n_values[$primary_id_ref]
1718
+				);
1719
+			}
1720
+		} elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) {
1721
+			//no primary key on this model, but there's still a matching item in the DB
1722
+			$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1723
+				self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1724
+			);
1725
+		}
1726
+		if ($existing) {
1727
+			//set date formats if present before setting values
1728
+			if ( ! empty($date_formats) && is_array($date_formats)) {
1729
+				$existing->set_date_format($date_formats[0]);
1730
+				$existing->set_time_format($date_formats[1]);
1731
+			} else {
1732
+				//set default formats for date and time
1733
+				$existing->set_date_format(get_option('date_format'));
1734
+				$existing->set_time_format(get_option('time_format'));
1735
+			}
1736
+			foreach ($props_n_values as $property => $field_value) {
1737
+				$existing->set($property, $field_value);
1738
+			}
1739
+			return $existing;
1740
+		} else {
1741
+			return false;
1742
+		}
1743
+	}
1744
+
1745
+
1746
+
1747
+	/**
1748
+	 * Gets the EEM_*_Model for this class
1749
+	 *
1750
+	 * @access public now, as this is more convenient
1751
+	 * @param      $classname
1752
+	 * @param null $timezone
1753
+	 * @throws EE_Error
1754
+	 * @return EEM_Base
1755
+	 */
1756
+	protected static function _get_model($classname, $timezone = null)
1757
+	{
1758
+		//find model for this class
1759
+		if ( ! $classname) {
1760
+			throw new EE_Error(
1761
+				sprintf(
1762
+					__(
1763
+						"What were you thinking calling _get_model(%s)?? You need to specify the class name",
1764
+						"event_espresso"
1765
+					),
1766
+					$classname
1767
+				)
1768
+			);
1769
+		}
1770
+		$modelName = self::_get_model_classname($classname);
1771
+		return self::_get_model_instance_with_name($modelName, $timezone);
1772
+	}
1773
+
1774
+
1775
+
1776
+	/**
1777
+	 * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1778
+	 *
1779
+	 * @param string $model_classname
1780
+	 * @param null   $timezone
1781
+	 * @return EEM_Base
1782
+	 */
1783
+	protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1784
+	{
1785
+		$model_classname = str_replace('EEM_', '', $model_classname);
1786
+		$model = EE_Registry::instance()->load_model($model_classname);
1787
+		$model->set_timezone($timezone);
1788
+		return $model;
1789
+	}
1790
+
1791
+
1792
+
1793
+	/**
1794
+	 * If a model name is provided (eg Registration), gets the model classname for that model.
1795
+	 * Also works if a model class's classname is provided (eg EE_Registration).
1796
+	 *
1797
+	 * @param null $model_name
1798
+	 * @return string like EEM_Attendee
1799
+	 */
1800
+	private static function _get_model_classname($model_name = null)
1801
+	{
1802
+		if (strpos($model_name, "EE_") === 0) {
1803
+			$model_classname = str_replace("EE_", "EEM_", $model_name);
1804
+		} else {
1805
+			$model_classname = "EEM_" . $model_name;
1806
+		}
1807
+		return $model_classname;
1808
+	}
1809
+
1810
+
1811
+
1812
+	/**
1813
+	 * returns the name of the primary key attribute
1814
+	 *
1815
+	 * @param null $classname
1816
+	 * @throws EE_Error
1817
+	 * @return string
1818
+	 */
1819
+	protected static function _get_primary_key_name($classname = null)
1820
+	{
1821
+		if ( ! $classname) {
1822
+			throw new EE_Error(
1823
+				sprintf(
1824
+					__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1825
+					$classname
1826
+				)
1827
+			);
1828
+		}
1829
+		return self::_get_model($classname)->get_primary_key_field()->get_name();
1830
+	}
1831
+
1832
+
1833
+
1834
+	/**
1835
+	 * Gets the value of the primary key.
1836
+	 * If the object hasn't yet been saved, it should be whatever the model field's default was
1837
+	 * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value is.
1838
+	 * Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1839
+	 *
1840
+	 * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1841
+	 * @throws \EE_Error
1842
+	 */
1843
+	public function ID()
1844
+	{
1845
+		//now that we know the name of the variable, use a variable variable to get its value and return its
1846
+		if ($this->get_model()->has_primary_key_field()) {
1847
+			return $this->_fields[self::_get_primary_key_name(get_class($this))];
1848
+		} else {
1849
+			return $this->get_model()->get_index_primary_key_string($this->_fields);
1850
+		}
1851
+	}
1852
+
1853
+
1854
+
1855
+	/**
1856
+	 * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current model is related
1857
+	 * to a group of events, the $relationName should be 'Event', and should be a key in the EE Model's $_model_relations array.
1858
+	 * If this model object doesn't exist in the DB, just caches the related thing
1859
+	 *
1860
+	 * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1861
+	 * @param string $relationName                     eg 'Events','Question',etc.
1862
+	 *                                                 an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id')
1863
+	 * @param array  $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added.  However, keep in mind that the columns (keys) given must match
1864
+	 *                                                 a column on the JOIN table and currently only the HABTM models accept these additional conditions.  Also remember that if an exact match isn't found for these extra cols/val pairs,
1865
+	 *                                                 then a NEW row is created in the join table.
1866
+	 * @param null   $cache_id
1867
+	 * @throws EE_Error
1868
+	 * @return EE_Base_Class the object the relation was added to
1869
+	 */
1870
+	public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = null)
1871
+	{
1872
+		//if this thing exists in the DB, save the relation to the DB
1873
+		if ($this->ID()) {
1874
+			$otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values);
1875
+			//clear cache so future get_many_related and get_first_related() return new results.
1876
+			$this->clear_cache($relationName, $otherObject, true);
1877
+			if ($otherObject instanceof EE_Base_Class) {
1878
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1879
+			}
1880
+		} else {
1881
+			//this thing doesn't exist in the DB,  so just cache it
1882
+			if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
1883
+				throw new EE_Error(sprintf(
1884
+					__('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'),
1885
+					$otherObjectModelObjectOrID,
1886
+					get_class($this)
1887
+				));
1888
+			} else {
1889
+				$otherObject = $otherObjectModelObjectOrID;
1890
+			}
1891
+			$this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
1892
+		}
1893
+		if ($otherObject instanceof EE_Base_Class) {
1894
+			//fix the reciprocal relation too
1895
+			if ($otherObject->ID()) {
1896
+				//its saved so assumed relations exist in the DB, so we can just
1897
+				//clear the cache so future queries use the updated info in the DB
1898
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true);
1899
+			} else {
1900
+				//it's not saved, so it caches relations like this
1901
+				$otherObject->cache($this->get_model()->get_this_model_name(), $this);
1902
+			}
1903
+		}
1904
+		return $otherObject;
1905
+	}
1906
+
1907
+
1908
+
1909
+	/**
1910
+	 * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current model is related
1911
+	 * to a group of events, the $relationName should be 'Events', and should be a key in the EE Model's $_model_relations array.
1912
+	 * If this model object doesn't exist in the DB, just removes the related thing from the cache
1913
+	 *
1914
+	 * @param mixed  $otherObjectModelObjectOrID
1915
+	 *                EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved to the DB yet
1916
+	 * @param string $relationName
1917
+	 * @param array  $where_query
1918
+	 *                You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added.
1919
+	 *                However, keep in mind that the columns (keys) given must match a column on the JOIN table
1920
+	 *                and currently only the HABTM models accept these additional conditions.
1921
+	 *                Also remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is created in the join table.
1922
+	 * @return EE_Base_Class the relation was removed from
1923
+	 * @throws \EE_Error
1924
+	 */
1925
+	public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
1926
+	{
1927
+		if ($this->ID()) {
1928
+			//if this exists in the DB, save the relation change to the DB too
1929
+			$otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query);
1930
+			$this->clear_cache($relationName, $otherObject);
1931
+		} else {
1932
+			//this doesn't exist in the DB, just remove it from the cache
1933
+			$otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
1934
+		}
1935
+		if ($otherObject instanceof EE_Base_Class) {
1936
+			$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1937
+		}
1938
+		return $otherObject;
1939
+	}
1940
+
1941
+
1942
+
1943
+	/**
1944
+	 * Removes ALL the related things for the $relationName.
1945
+	 *
1946
+	 * @param string $relationName
1947
+	 * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
1948
+	 * @return EE_Base_Class
1949
+	 * @throws \EE_Error
1950
+	 */
1951
+	public function _remove_relations($relationName, $where_query_params = array())
1952
+	{
1953
+		if ($this->ID()) {
1954
+			//if this exists in the DB, save the relation change to the DB too
1955
+			$otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
1956
+			$this->clear_cache($relationName, null, true);
1957
+		} else {
1958
+			//this doesn't exist in the DB, just remove it from the cache
1959
+			$otherObjects = $this->clear_cache($relationName, null, true);
1960
+		}
1961
+		if (is_array($otherObjects)) {
1962
+			foreach ($otherObjects as $otherObject) {
1963
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1964
+			}
1965
+		}
1966
+		return $otherObjects;
1967
+	}
1968
+
1969
+
1970
+
1971
+	/**
1972
+	 * Gets all the related model objects of the specified type. Eg, if the current class if
1973
+	 * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
1974
+	 * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
1975
+	 * because we want to get even deleted items etc.
1976
+	 *
1977
+	 * @param string $relationName key in the model's _model_relations array
1978
+	 * @param array  $query_params like EEM_Base::get_all
1979
+	 * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
1980
+	 * @throws \EE_Error
1981
+	 *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs
1982
+	 */
1983
+	public function get_many_related($relationName, $query_params = array())
1984
+	{
1985
+		if ($this->ID()) {
1986
+			//this exists in the DB, so get the related things from either the cache or the DB
1987
+			//if there are query parameters, forget about caching the related model objects.
1988
+			if ($query_params) {
1989
+				$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1990
+			} else {
1991
+				//did we already cache the result of this query?
1992
+				$cached_results = $this->get_all_from_cache($relationName);
1993
+				if ( ! $cached_results) {
1994
+					$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1995
+					//if no query parameters were passed, then we got all the related model objects
1996
+					//for that relation. We can cache them then.
1997
+					foreach ($related_model_objects as $related_model_object) {
1998
+						$this->cache($relationName, $related_model_object);
1999
+					}
2000
+				} else {
2001
+					$related_model_objects = $cached_results;
2002
+				}
2003
+			}
2004
+		} else {
2005
+			//this doesn't exist in the DB, so just get the related things from the cache
2006
+			$related_model_objects = $this->get_all_from_cache($relationName);
2007
+		}
2008
+		return $related_model_objects;
2009
+	}
2010
+
2011
+
2012
+
2013
+	/**
2014
+	 * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2015
+	 * unless otherwise specified in the $query_params
2016
+	 *
2017
+	 * @param string $relation_name  model_name like 'Event', or 'Registration'
2018
+	 * @param array  $query_params   like EEM_Base::get_all's
2019
+	 * @param string $field_to_count name of field to count by. By default, uses primary key
2020
+	 * @param bool   $distinct       if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
2021
+	 * @return int
2022
+	 */
2023
+	public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2024
+	{
2025
+		return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2026
+	}
2027
+
2028
+
2029
+
2030
+	/**
2031
+	 * Instead of getting the related model objects, simply sums up the values of the specified field.
2032
+	 * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2033
+	 *
2034
+	 * @param string $relation_name model_name like 'Event', or 'Registration'
2035
+	 * @param array  $query_params  like EEM_Base::get_all's
2036
+	 * @param string $field_to_sum  name of field to count by.
2037
+	 *                              By default, uses primary key (which doesn't make much sense, so you should probably change it)
2038
+	 * @return int
2039
+	 */
2040
+	public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2041
+	{
2042
+		return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2043
+	}
2044
+
2045
+
2046
+
2047
+	/**
2048
+	 * Gets the first (ie, one) related model object of the specified type.
2049
+	 *
2050
+	 * @param string $relationName key in the model's _model_relations array
2051
+	 * @param array  $query_params like EEM_Base::get_all
2052
+	 * @return EE_Base_Class (not an array, a single object)
2053
+	 * @throws \EE_Error
2054
+	 */
2055
+	public function get_first_related($relationName, $query_params = array())
2056
+	{
2057
+		if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2058
+			//if they've provided some query parameters, don't bother trying to cache the result
2059
+			//also make sure we're not caching the result of get_first_related
2060
+			//on a relation which should have an array of objects (because the cache might have an array of objects)
2061
+			if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2062
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2063
+			} else {
2064
+				//first, check if we've already cached the result of this query
2065
+				$cached_result = $this->get_one_from_cache($relationName);
2066
+				if ( ! $cached_result) {
2067
+					$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2068
+					$this->cache($relationName, $related_model_object);
2069
+				} else {
2070
+					$related_model_object = $cached_result;
2071
+				}
2072
+			}
2073
+		} else {
2074
+			$related_model_object = null;
2075
+			//this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2076
+			if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2077
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2078
+			}
2079
+			//this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object
2080
+			if ( ! $related_model_object) {
2081
+				$related_model_object = $this->get_one_from_cache($relationName);
2082
+			}
2083
+		}
2084
+		return $related_model_object;
2085
+	}
2086
+
2087
+
2088
+
2089
+	/**
2090
+	 * Does a delete on all related objects of type $relationName and removes
2091
+	 * the current model object's relation to them. If they can't be deleted (because
2092
+	 * of blocking related model objects) does nothing. If the related model objects are
2093
+	 * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2094
+	 * If this model object doesn't exist yet in the DB, just removes its related things
2095
+	 *
2096
+	 * @param string $relationName
2097
+	 * @param array  $query_params like EEM_Base::get_all's
2098
+	 * @return int how many deleted
2099
+	 * @throws \EE_Error
2100
+	 */
2101
+	public function delete_related($relationName, $query_params = array())
2102
+	{
2103
+		if ($this->ID()) {
2104
+			$count = $this->get_model()->delete_related($this, $relationName, $query_params);
2105
+		} else {
2106
+			$count = count($this->get_all_from_cache($relationName));
2107
+			$this->clear_cache($relationName, null, true);
2108
+		}
2109
+		return $count;
2110
+	}
2111
+
2112
+
2113
+
2114
+	/**
2115
+	 * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2116
+	 * the current model object's relation to them. If they can't be deleted (because
2117
+	 * of blocking related model objects) just does a soft delete on it instead, if possible.
2118
+	 * If the related thing isn't a soft-deletable model object, this function is identical
2119
+	 * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2120
+	 *
2121
+	 * @param string $relationName
2122
+	 * @param array  $query_params like EEM_Base::get_all's
2123
+	 * @return int how many deleted (including those soft deleted)
2124
+	 * @throws \EE_Error
2125
+	 */
2126
+	public function delete_related_permanently($relationName, $query_params = array())
2127
+	{
2128
+		if ($this->ID()) {
2129
+			$count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2130
+		} else {
2131
+			$count = count($this->get_all_from_cache($relationName));
2132
+		}
2133
+		$this->clear_cache($relationName, null, true);
2134
+		return $count;
2135
+	}
2136
+
2137
+
2138
+
2139
+	/**
2140
+	 * is_set
2141
+	 * Just a simple utility function children can use for checking if property exists
2142
+	 *
2143
+	 * @access  public
2144
+	 * @param  string $field_name property to check
2145
+	 * @return bool                              TRUE if existing,FALSE if not.
2146
+	 */
2147
+	public function is_set($field_name)
2148
+	{
2149
+		return isset($this->_fields[$field_name]);
2150
+	}
2151
+
2152
+
2153
+
2154
+	/**
2155
+	 * Just a simple utility function children can use for checking if property (or properties) exists and throwing an EE_Error exception if they don't
2156
+	 *
2157
+	 * @param  mixed (string|array) $properties properties to check
2158
+	 * @throws EE_Error
2159
+	 * @return bool                              TRUE if existing, throw EE_Error if not.
2160
+	 */
2161
+	protected function _property_exists($properties)
2162
+	{
2163
+		foreach ((array)$properties as $property_name) {
2164
+			//first make sure this property exists
2165
+			if ( ! $this->_fields[$property_name]) {
2166
+				throw new EE_Error(
2167
+					sprintf(
2168
+						__(
2169
+							'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2170
+							'event_espresso'
2171
+						),
2172
+						$property_name
2173
+					)
2174
+				);
2175
+			}
2176
+		}
2177
+		return true;
2178
+	}
2179
+
2180
+
2181
+
2182
+	/**
2183
+	 * This simply returns an array of model fields for this object
2184
+	 *
2185
+	 * @return array
2186
+	 * @throws \EE_Error
2187
+	 */
2188
+	public function model_field_array()
2189
+	{
2190
+		$fields = $this->get_model()->field_settings(false);
2191
+		$properties = array();
2192
+		//remove prepended underscore
2193
+		foreach ($fields as $field_name => $settings) {
2194
+			$properties[$field_name] = $this->get($field_name);
2195
+		}
2196
+		return $properties;
2197
+	}
2198
+
2199
+
2200
+
2201
+	/**
2202
+	 * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2203
+	 * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called (http://www.garfieldtech.com/blog/php-magic-call)
2204
+	 * and passed the method's name and arguments.
2205
+	 * Instead of requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that happen?)
2206
+	 * they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, filters_hook_espresso__EE_Answer__my_great_function)
2207
+	 * and accepts 2 arguments: the object on which the function was called, and an array of the original arguments passed to the function. Whatever their callback function returns will be returned by this function.
2208
+	 * Example: in functions.php (or in a plugin):
2209
+	 * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3);
2210
+	 * function my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2211
+	 * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2212
+	 *        return $previousReturnValue.$returnString;
2213
+	 * }
2214
+	 * require('EE_Answer.class.php');
2215
+	 * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2216
+	 * echo $answer->my_callback('monkeys',100);
2217
+	 * //will output "you called my_callback! and passed args:monkeys,100"
2218
+	 *
2219
+	 * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2220
+	 * @param array  $args       array of original arguments passed to the function
2221
+	 * @throws EE_Error
2222
+	 * @return mixed whatever the plugin which calls add_filter decides
2223
+	 */
2224
+	public function __call($methodName, $args)
2225
+	{
2226
+		$className = get_class($this);
2227
+		$tagName = "FHEE__{$className}__{$methodName}";
2228
+		if ( ! has_filter($tagName)) {
2229
+			throw new EE_Error(
2230
+				sprintf(
2231
+					__(
2232
+						"Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}",
2233
+						"event_espresso"
2234
+					),
2235
+					$methodName,
2236
+					$className,
2237
+					$tagName
2238
+				)
2239
+			);
2240
+		}
2241
+		return apply_filters($tagName, null, $this, $args);
2242
+	}
2243
+
2244
+
2245
+
2246
+	/**
2247
+	 * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2248
+	 * A $previous_value can be specified in case there are many meta rows with the same key
2249
+	 *
2250
+	 * @param string $meta_key
2251
+	 * @param string $meta_value
2252
+	 * @param string $previous_value
2253
+	 * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2254
+	 * @throws \EE_Error
2255
+	 * NOTE: if the values haven't changed, returns 0
2256
+	 */
2257
+	public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2258
+	{
2259
+		$query_params = array(
2260
+			array(
2261
+				'EXM_key'  => $meta_key,
2262
+				'OBJ_ID'   => $this->ID(),
2263
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2264
+			),
2265
+		);
2266
+		if ($previous_value !== null) {
2267
+			$query_params[0]['EXM_value'] = $meta_value;
2268
+		}
2269
+		$existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2270
+		if ( ! $existing_rows_like_that) {
2271
+			return $this->add_extra_meta($meta_key, $meta_value);
2272
+		} else {
2273
+			foreach ($existing_rows_like_that as $existing_row) {
2274
+				$existing_row->save(array('EXM_value' => $meta_value));
2275
+			}
2276
+			return count($existing_rows_like_that);
2277
+		}
2278
+	}
2279
+
2280
+
2281
+
2282
+	/**
2283
+	 * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2284
+	 * no other extra meta for this model object have the same key. Returns TRUE if the
2285
+	 * extra meta row was entered, false if not
2286
+	 *
2287
+	 * @param string  $meta_key
2288
+	 * @param string  $meta_value
2289
+	 * @param boolean $unique
2290
+	 * @return boolean
2291
+	 * @throws \EE_Error
2292
+	 */
2293
+	public function add_extra_meta($meta_key, $meta_value, $unique = false)
2294
+	{
2295
+		if ($unique) {
2296
+			$existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2297
+				array(
2298
+					array(
2299
+						'EXM_key'  => $meta_key,
2300
+						'OBJ_ID'   => $this->ID(),
2301
+						'EXM_type' => $this->get_model()->get_this_model_name(),
2302
+					),
2303
+				)
2304
+			);
2305
+			if ($existing_extra_meta) {
2306
+				return false;
2307
+			}
2308
+		}
2309
+		$new_extra_meta = EE_Extra_Meta::new_instance(
2310
+			array(
2311
+				'EXM_key'   => $meta_key,
2312
+				'EXM_value' => $meta_value,
2313
+				'OBJ_ID'    => $this->ID(),
2314
+				'EXM_type'  => $this->get_model()->get_this_model_name(),
2315
+			)
2316
+		);
2317
+		$new_extra_meta->save();
2318
+		return true;
2319
+	}
2320
+
2321
+
2322
+
2323
+	/**
2324
+	 * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2325
+	 * is specified, only deletes extra meta records with that value.
2326
+	 *
2327
+	 * @param string $meta_key
2328
+	 * @param string $meta_value
2329
+	 * @return int number of extra meta rows deleted
2330
+	 * @throws \EE_Error
2331
+	 */
2332
+	public function delete_extra_meta($meta_key, $meta_value = null)
2333
+	{
2334
+		$query_params = array(
2335
+			array(
2336
+				'EXM_key'  => $meta_key,
2337
+				'OBJ_ID'   => $this->ID(),
2338
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2339
+			),
2340
+		);
2341
+		if ($meta_value !== null) {
2342
+			$query_params[0]['EXM_value'] = $meta_value;
2343
+		}
2344
+		return EEM_Extra_Meta::instance()->delete($query_params);
2345
+	}
2346
+
2347
+
2348
+
2349
+	/**
2350
+	 * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2351
+	 * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2352
+	 * You can specify $default is case you haven't found the extra meta
2353
+	 *
2354
+	 * @param string  $meta_key
2355
+	 * @param boolean $single
2356
+	 * @param mixed   $default if we don't find anything, what should we return?
2357
+	 * @return mixed single value if $single; array if ! $single
2358
+	 * @throws \EE_Error
2359
+	 */
2360
+	public function get_extra_meta($meta_key, $single = false, $default = null)
2361
+	{
2362
+		if ($single) {
2363
+			$result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2364
+			if ($result instanceof EE_Extra_Meta) {
2365
+				return $result->value();
2366
+			} else {
2367
+				return $default;
2368
+			}
2369
+		} else {
2370
+			$results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2371
+			if ($results) {
2372
+				$values = array();
2373
+				foreach ($results as $result) {
2374
+					if ($result instanceof EE_Extra_Meta) {
2375
+						$values[$result->ID()] = $result->value();
2376
+					}
2377
+				}
2378
+				return $values;
2379
+			} else {
2380
+				return $default;
2381
+			}
2382
+		}
2383
+	}
2384
+
2385
+
2386
+
2387
+	/**
2388
+	 * Returns a simple array of all the extra meta associated with this model object.
2389
+	 * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2390
+	 * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2391
+	 * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2392
+	 * If $one_of_each_key is false, it will return an array with the top-level keys being
2393
+	 * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2394
+	 * finally the extra meta's value as each sub-value. (eg array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2395
+	 *
2396
+	 * @param boolean $one_of_each_key
2397
+	 * @return array
2398
+	 * @throws \EE_Error
2399
+	 */
2400
+	public function all_extra_meta_array($one_of_each_key = true)
2401
+	{
2402
+		$return_array = array();
2403
+		if ($one_of_each_key) {
2404
+			$extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2405
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2406
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2407
+					$return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2408
+				}
2409
+			}
2410
+		} else {
2411
+			$extra_meta_objs = $this->get_many_related('Extra_Meta');
2412
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2413
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2414
+					if ( ! isset($return_array[$extra_meta_obj->key()])) {
2415
+						$return_array[$extra_meta_obj->key()] = array();
2416
+					}
2417
+					$return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2418
+				}
2419
+			}
2420
+		}
2421
+		return $return_array;
2422
+	}
2423
+
2424
+
2425
+
2426
+	/**
2427
+	 * Gets a pretty nice displayable nice for this model object. Often overridden
2428
+	 *
2429
+	 * @return string
2430
+	 * @throws \EE_Error
2431
+	 */
2432
+	public function name()
2433
+	{
2434
+		//find a field that's not a text field
2435
+		$field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2436
+		if ($field_we_can_use) {
2437
+			return $this->get($field_we_can_use->get_name());
2438
+		} else {
2439
+			$first_few_properties = $this->model_field_array();
2440
+			$first_few_properties = array_slice($first_few_properties, 0, 3);
2441
+			$name_parts = array();
2442
+			foreach ($first_few_properties as $name => $value) {
2443
+				$name_parts[] = "$name:$value";
2444
+			}
2445
+			return implode(",", $name_parts);
2446
+		}
2447
+	}
2448
+
2449
+
2450
+
2451
+	/**
2452
+	 * in_entity_map
2453
+	 * Checks if this model object has been proven to already be in the entity map
2454
+	 *
2455
+	 * @return boolean
2456
+	 * @throws \EE_Error
2457
+	 */
2458
+	public function in_entity_map()
2459
+	{
2460
+		if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2461
+			//well, if we looked, did we find it in the entity map?
2462
+			return true;
2463
+		} else {
2464
+			return false;
2465
+		}
2466
+	}
2467
+
2468
+
2469
+
2470
+	/**
2471
+	 * refresh_from_db
2472
+	 * Makes sure the fields and values on this model object are in-sync with what's in the database.
2473
+	 *
2474
+	 * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2475
+	 * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2476
+	 */
2477
+	public function refresh_from_db()
2478
+	{
2479
+		if ($this->ID() && $this->in_entity_map()) {
2480
+			$this->get_model()->refresh_entity_map_from_db($this->ID());
2481
+		} else {
2482
+			//if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2483
+			//if it has an ID but it's not in the map, and you're asking me to refresh it
2484
+			//that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2485
+			//absolutely nothing in it for this ID
2486
+			if (WP_DEBUG) {
2487
+				throw new EE_Error(
2488
+					sprintf(
2489
+						__('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2490
+							'event_espresso'),
2491
+						$this->ID(),
2492
+						get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2493
+						get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2494
+					)
2495
+				);
2496
+			}
2497
+		}
2498
+	}
2499
+
2500
+
2501
+
2502
+	/**
2503
+	 * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2504
+	 * (probably a bad assumption they have made, oh well)
2505
+	 *
2506
+	 * @return string
2507
+	 */
2508
+	public function __toString()
2509
+	{
2510
+		try {
2511
+			return sprintf('%s (%s)', $this->name(), $this->ID());
2512
+		} catch (Exception $e) {
2513
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2514
+			return '';
2515
+		}
2516
+	}
2517
+
2518
+
2519
+
2520
+	/**
2521
+	 * Clear related model objects if they're already in the DB, because otherwise when we
2522
+	 * UN-serialize this model object we'll need to be careful to add them to the entity map.
2523
+	 * This means if we have made changes to those related model objects, and want to unserialize
2524
+	 * the this model object on a subsequent request, changes to those related model objects will be lost.
2525
+	 * Instead, those related model objects should be directly serialized and stored.
2526
+	 * Eg, the following won't work:
2527
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2528
+	 * $att = $reg->attendee();
2529
+	 * $att->set( 'ATT_fname', 'Dirk' );
2530
+	 * update_option( 'my_option', serialize( $reg ) );
2531
+	 * //END REQUEST
2532
+	 * //START NEXT REQUEST
2533
+	 * $reg = get_option( 'my_option' );
2534
+	 * $reg->attendee()->save();
2535
+	 * And would need to be replace with:
2536
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2537
+	 * $att = $reg->attendee();
2538
+	 * $att->set( 'ATT_fname', 'Dirk' );
2539
+	 * update_option( 'my_option', serialize( $reg ) );
2540
+	 * //END REQUEST
2541
+	 * //START NEXT REQUEST
2542
+	 * $att = get_option( 'my_option' );
2543
+	 * $att->save();
2544
+	 *
2545
+	 * @return array
2546
+	 * @throws \EE_Error
2547
+	 */
2548
+	public function __sleep()
2549
+	{
2550
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2551
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
2552
+				$classname = 'EE_' . $this->get_model()->get_this_model_name();
2553
+				if (
2554
+					$this->get_one_from_cache($relation_name) instanceof $classname
2555
+					&& $this->get_one_from_cache($relation_name)->ID()
2556
+				) {
2557
+					$this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2558
+				}
2559
+			}
2560
+		}
2561
+		$this->_props_n_values_provided_in_constructor = array();
2562
+		return array_keys(get_object_vars($this));
2563
+	}
2564
+
2565
+
2566
+
2567
+	/**
2568
+	 * restore _props_n_values_provided_in_constructor
2569
+	 * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2570
+	 * and therefore should NOT be used to determine if state change has occurred since initial construction.
2571
+	 * At best, you would only be able to detect if state change has occurred during THIS request.
2572
+	 */
2573
+	public function __wakeup()
2574
+	{
2575
+		$this->_props_n_values_provided_in_constructor = $this->_fields;
2576
+	}
2577 2577
 
2578 2578
 
2579 2579
 
Please login to merge, or discard this patch.
core/business/EE_Transaction_Processor.class.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -187,6 +187,7 @@
 block discarded – undo
187 187
      *                                                         when retrieving cached registrations from a transaction
188 188
      * @param bool $trigger_notifications                      whether or not to call
189 189
      *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
190
+     * @param EE_Payment $payment
190 191
      * @return array
191 192
      * @throws \EE_Error
192 193
      */
Please login to merge, or discard this patch.
Indentation   +25 added lines, -26 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
  * the interaction of EE_Transaction and EE_Registration model objects
8 8
  * Provides methods for manipulating and processing changes to an EE_Transaction
9 9
  * and it's related EE_Registrations with regards to the checkout/registration process
10
-
11
-*
10
+ *
12 11
 *@package     Event Espresso
13 12
  * @subpackage 	core
14 13
  * @author      Brent Christensen
@@ -177,24 +176,24 @@  discard block
 block discarded – undo
177 176
 
178 177
 
179 178
 
180
-    /**
181
-     * update_transaction_and_registrations_after_checkout_or_payment
182
-     * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
183
-     *
184
-     * @param EE_Transaction $transaction
185
-     * @param \EE_Payment | NULL $payment
186
-     * @param array              $registration_query_params    array of query WHERE params to use
187
-     *                                                         when retrieving cached registrations from a transaction
188
-     * @param bool $trigger_notifications                      whether or not to call
189
-     *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
190
-     * @return array
191
-     * @throws \EE_Error
192
-     */
179
+	/**
180
+	 * update_transaction_and_registrations_after_checkout_or_payment
181
+	 * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
182
+	 *
183
+	 * @param EE_Transaction $transaction
184
+	 * @param \EE_Payment | NULL $payment
185
+	 * @param array              $registration_query_params    array of query WHERE params to use
186
+	 *                                                         when retrieving cached registrations from a transaction
187
+	 * @param bool $trigger_notifications                      whether or not to call
188
+	 *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
189
+	 * @return array
190
+	 * @throws \EE_Error
191
+	 */
193 192
 	public function update_transaction_and_registrations_after_checkout_or_payment(
194 193
 		EE_Transaction $transaction,
195 194
 		$payment = null,
196 195
 		$registration_query_params = array(),
197
-        $trigger_notifications = true
196
+		$trigger_notifications = true
198 197
 	) {
199 198
 		// make sure some query params are set for retrieving registrations
200 199
 		$this->_set_registration_query_params( $registration_query_params );
@@ -224,15 +223,15 @@  discard block
 block discarded – undo
224 223
 			$update_params
225 224
 		);
226 225
 		if ($trigger_notifications) {
227
-            // send messages
228
-            /** @type EE_Registration_Processor $registration_processor */
229
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
230
-            $registration_processor->trigger_registration_update_notifications(
231
-                $transaction->primary_registration(),
232
-                $update_params
233
-            );
234
-        }
235
-        do_action(
226
+			// send messages
227
+			/** @type EE_Registration_Processor $registration_processor */
228
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
229
+			$registration_processor->trigger_registration_update_notifications(
230
+				$transaction->primary_registration(),
231
+				$update_params
232
+			);
233
+		}
234
+		do_action(
236 235
 			'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
237 236
 			$transaction,
238 237
 			$update_params
@@ -522,7 +521,7 @@  discard block
 block discarded – undo
522 521
 						foreach ( $available_payment_methods as $available_payment_method ) {
523 522
 							if (
524 523
 								$available_payment_method instanceof EE_Payment_Method
525
-							    && $available_payment_method->open_by_default()
524
+								&& $available_payment_method->open_by_default()
526 525
 							) {
527 526
 								$PMD_ID = $available_payment_method->ID();
528 527
 								break;
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
-EE_Registry::instance()->load_class( 'Processor_Base' );
2
+EE_Registry::instance()->load_class('Processor_Base');
3 3
 
4 4
 /**
5 5
  * Class EE_Transaction_Processor
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 	 * @param array $registration_query_params
51 51
 	 *@return EE_Transaction_Processor instance
52 52
 	 */
53
-	public static function instance( $registration_query_params = array() ) {
53
+	public static function instance($registration_query_params = array()) {
54 54
 		// check if class object is instantiated
55
-		if ( ! self::$_instance instanceof EE_Transaction_Processor ) {
56
-			self::$_instance = new self( $registration_query_params );
55
+		if ( ! self::$_instance instanceof EE_Transaction_Processor) {
56
+			self::$_instance = new self($registration_query_params);
57 57
 		}
58 58
 		return self::$_instance;
59 59
 	}
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @param array $registration_query_params
65 65
 	 */
66
-	private function __construct( $registration_query_params = array() ) {
66
+	private function __construct($registration_query_params = array()) {
67 67
 		// make sure some query params are set for retrieving registrations
68
-		$this->_set_registration_query_params( $registration_query_params );
68
+		$this->_set_registration_query_params($registration_query_params);
69 69
 	}
70 70
 
71 71
 
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @access private
75 75
 	 * @param array $registration_query_params
76 76
 	 */
77
-	private function _set_registration_query_params( $registration_query_params ) {
78
-		$this->_registration_query_params = ! empty( $registration_query_params ) ? $registration_query_params : array( 'order_by' => array( 'REG_count' => 'ASC' ));
77
+	private function _set_registration_query_params($registration_query_params) {
78
+		$this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params : array('order_by' => array('REG_count' => 'ASC'));
79 79
 	}
80 80
 
81 81
 
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
 		);
105 105
 		// send messages
106 106
 		/** @type EE_Registration_Processor $registration_processor */
107
-		$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
107
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
108 108
 		$registration_processor->trigger_registration_update_notifications(
109 109
 			$transaction->primary_registration(),
110
-			array( 'manually_updated' 	=> true )
110
+			array('manually_updated' 	=> true)
111 111
 		);
112 112
 		do_action(
113 113
 			'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
         $trigger_notifications = true
198 198
 	) {
199 199
 		// make sure some query params are set for retrieving registrations
200
-		$this->_set_registration_query_params( $registration_query_params );
200
+		$this->_set_registration_query_params($registration_query_params);
201 201
 		// get final reg step status
202 202
 		$finalized = $transaction->final_reg_step_completed();
203 203
 		// if the 'finalize_registration' step has been initiated (has a timestamp)
204 204
 		// but has not yet been fully completed (TRUE)
205
-		if ( is_int( $finalized ) && $finalized !== false && $finalized !== true ) {
206
-			$transaction->set_reg_step_completed( 'finalize_registration' );
205
+		if (is_int($finalized) && $finalized !== false && $finalized !== true) {
206
+			$transaction->set_reg_step_completed('finalize_registration');
207 207
 			$finalized = true;
208 208
 		}
209 209
 		$transaction->save();
@@ -258,22 +258,22 @@  discard block
 block discarded – undo
258 258
 		$update_txn = true
259 259
 	) {
260 260
 		// these reg statuses should not be considered in any calculations involving monies owing
261
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
262
-		if ( in_array( $registration->status_ID(), $closed_reg_statuses ) ) {
261
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
262
+		if (in_array($registration->status_ID(), $closed_reg_statuses)) {
263 263
 			return false;
264 264
 		}
265 265
 		try {
266
-			$transaction = $this->get_transaction_for_registration( $registration );
266
+			$transaction = $this->get_transaction_for_registration($registration);
267 267
 			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
268 268
 				$transaction,
269 269
 				$registration
270 270
 			);
271 271
 			// un-cancel the ticket
272
-			$success = EEH_Line_Item::reinstate_canceled_ticket_line_item( $ticket_line_item );
273
-		} catch ( EE_Error $e ) {
272
+			$success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item);
273
+		} catch (EE_Error $e) {
274 274
 			EE_Error::add_error(
275 275
 				sprintf(
276
-					__( 'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', 'event_espresso' ),
276
+					__('The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', 'event_espresso'),
277 277
 					$registration->ID(),
278 278
 					'<br />',
279 279
 					$e->getMessage()
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 			);
283 283
 			return false;
284 284
 		}
285
-		if ( $update_txn ) {
285
+		if ($update_txn) {
286 286
 			return $transaction->save() ? $success : false;
287 287
 		}
288 288
 		return $success;
@@ -306,18 +306,18 @@  discard block
 block discarded – undo
306 306
 		$update_txn = true
307 307
 	) {
308 308
 		// these reg statuses should not be considered in any calculations involving monies owing
309
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
310
-		if ( ! in_array( $registration->status_ID(), $closed_reg_statuses ) ) {
309
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
310
+		if ( ! in_array($registration->status_ID(), $closed_reg_statuses)) {
311 311
 			return false;
312 312
 		}
313 313
 		try {
314
-			$transaction = $this->get_transaction_for_registration( $registration );
315
-			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( $transaction, $registration );
316
-			EEH_Line_Item::cancel_ticket_line_item( $ticket_line_item );
317
-		} catch ( EE_Error $e ) {
314
+			$transaction = $this->get_transaction_for_registration($registration);
315
+			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration($transaction, $registration);
316
+			EEH_Line_Item::cancel_ticket_line_item($ticket_line_item);
317
+		} catch (EE_Error $e) {
318 318
 			EE_Error::add_error(
319 319
 				sprintf(
320
-					__( 'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', 'event_espresso' ),
320
+					__('The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', 'event_espresso'),
321 321
 					$registration->ID(),
322 322
 					'<br />',
323 323
 					$e->getMessage()
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 			);
327 327
 			return false;
328 328
 		}
329
-		if ( $update_txn ) {
329
+		if ($update_txn) {
330 330
 			return $transaction->save() ? true : false;
331 331
 		}
332 332
 		return true;
@@ -342,12 +342,12 @@  discard block
 block discarded – undo
342 342
 	 * @return 	EE_Transaction
343 343
 	 * @throws 	EE_Error
344 344
 	 */
345
-	public function get_transaction_for_registration( EE_Registration $registration ) {
345
+	public function get_transaction_for_registration(EE_Registration $registration) {
346 346
 		$transaction = $registration->transaction();
347
-		if ( ! $transaction instanceof EE_Transaction ) {
347
+		if ( ! $transaction instanceof EE_Transaction) {
348 348
 			throw new EE_Error(
349 349
 				sprintf(
350
-					__( 'The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso' ),
350
+					__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
351 351
 					$registration->ID()
352 352
 				)
353 353
 			);
@@ -370,16 +370,16 @@  discard block
 block discarded – undo
370 370
 		EE_Transaction $transaction,
371 371
 		EE_Registration $registration
372 372
 	) {
373
-		EE_Registry::instance()->load_helper( 'Line_Item' );
373
+		EE_Registry::instance()->load_helper('Line_Item');
374 374
 		$ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction(
375 375
 			$transaction->ID(),
376 376
 			$registration->ticket_ID()
377 377
 		);
378
-		if ( ! $ticket_line_item instanceof EE_Line_Item ) {
378
+		if ( ! $ticket_line_item instanceof EE_Line_Item) {
379 379
 			throw new EE_Error(
380 380
 				sprintf(
381
-					__( 'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
382
-						'event_espresso' ),
381
+					__('The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
382
+						'event_espresso'),
383 383
 					$transaction->ID(),
384 384
 					$registration->ticket_ID()
385 385
 				)
@@ -412,22 +412,22 @@  discard block
 block discarded – undo
412 412
 		$update_txn = true
413 413
 	) {
414 414
 		// make sure some query params are set for retrieving registrations
415
-		$this->_set_registration_query_params( $registration_query_params );
415
+		$this->_set_registration_query_params($registration_query_params);
416 416
 		// these reg statuses should not be considered in any calculations involving monies owing
417
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
417
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
418 418
 		// loop through cached registrations
419
-		foreach ( $transaction->registrations( $this->_registration_query_params ) as $registration ) {
419
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
420 420
 			if (
421 421
 				$registration instanceof EE_Registration
422
-				&& ! in_array( $registration->status_ID(), $closed_reg_statuses )
422
+				&& ! in_array($registration->status_ID(), $closed_reg_statuses)
423 423
 			) {
424 424
 				return false;
425 425
 			}
426 426
 		}
427
-		if ( in_array( $new_TXN_status, EEM_Transaction::txn_status_array() ) ) {
428
-			$transaction->set_status( $new_TXN_status );
427
+		if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) {
428
+			$transaction->set_status($new_TXN_status);
429 429
 		}
430
-		if ( $update_txn ) {
430
+		if ($update_txn) {
431 431
 			return $transaction->save() ? true : false;
432 432
 		}
433 433
 		return true;
@@ -456,22 +456,22 @@  discard block
 block discarded – undo
456 456
 	) {
457 457
 		$response = false;
458 458
 		/** @type EE_Registration_Processor $registration_processor */
459
-		$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
459
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
460 460
 		// check that method exists
461
-		if ( ! method_exists( $registration_processor, $method_name )) {
462
-			throw new EE_Error( __( 'Method does not exist.', 'event_espresso' ));
461
+		if ( ! method_exists($registration_processor, $method_name)) {
462
+			throw new EE_Error(__('Method does not exist.', 'event_espresso'));
463 463
 		}
464 464
 		// make sure some query params are set for retrieving registrations
465
-		$this->_set_registration_query_params( $registration_query_params );
465
+		$this->_set_registration_query_params($registration_query_params);
466 466
 		// loop through cached registrations
467
-		foreach ( $transaction->registrations( $this->_registration_query_params ) as $registration ) {
468
-			if ( $registration instanceof EE_Registration ) {
469
-				if ( $additional_param ) {
470
-					$response = $registration_processor->{$method_name}( $registration, $additional_param )
467
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
468
+			if ($registration instanceof EE_Registration) {
469
+				if ($additional_param) {
470
+					$response = $registration_processor->{$method_name}($registration, $additional_param)
471 471
 						? true
472 472
 						: $response;
473 473
 				} else {
474
-					$response = $registration_processor->{$method_name}( $registration )
474
+					$response = $registration_processor->{$method_name}($registration)
475 475
 						? true
476 476
 						: $response;
477 477
 				}
@@ -498,28 +498,28 @@  discard block
 block discarded – undo
498 498
 	public function set_transaction_payment_method_based_on_registration_statuses(
499 499
 		EE_Registration $edited_registration
500 500
 	) {
501
-		if ( $edited_registration instanceof EE_Registration ) {
501
+		if ($edited_registration instanceof EE_Registration) {
502 502
 			$transaction = $edited_registration->transaction();
503
-			if ( $transaction instanceof EE_Transaction ) {
503
+			if ($transaction instanceof EE_Transaction) {
504 504
 				$all_not_approved = true;
505
-				foreach ( $transaction->registrations() as $registration ) {
506
-					if ( $registration instanceof EE_Registration ) {
505
+				foreach ($transaction->registrations() as $registration) {
506
+					if ($registration instanceof EE_Registration) {
507 507
 						// if any REG != "Not Approved" then toggle to false
508 508
 						$all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
509 509
 					}
510 510
 				}
511 511
 				// if ALL Registrations are "Not Approved"
512
-				if ( $all_not_approved ) {
513
-					$transaction->set_payment_method_ID( null );
512
+				if ($all_not_approved) {
513
+					$transaction->set_payment_method_ID(null);
514 514
 					$transaction->save();
515 515
 				} else {
516 516
 					$available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
517 517
 						$transaction,
518 518
 						EEM_Payment_Method::scope_cart
519 519
 					);
520
-					if ( ! empty( $available_payment_methods ) ) {
520
+					if ( ! empty($available_payment_methods)) {
521 521
 						$PMD_ID = 0;
522
-						foreach ( $available_payment_methods as $available_payment_method ) {
522
+						foreach ($available_payment_methods as $available_payment_method) {
523 523
 							if (
524 524
 								$available_payment_method instanceof EE_Payment_Method
525 525
 							    && $available_payment_method->open_by_default()
@@ -528,22 +528,22 @@  discard block
 block discarded – undo
528 528
 								break;
529 529
 							}
530 530
 						}
531
-						if ( ! $PMD_ID ) {
532
-							$first_payment_method = reset( $available_payment_methods );
533
-							if ( $first_payment_method instanceof EE_Payment_Method ) {
531
+						if ( ! $PMD_ID) {
532
+							$first_payment_method = reset($available_payment_methods);
533
+							if ($first_payment_method instanceof EE_Payment_Method) {
534 534
 								$PMD_ID = $first_payment_method->ID();
535 535
 							} else {
536 536
 								EE_Error::add_error(
537
-									__( 'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso' ),
537
+									__('A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso'),
538 538
 									__FILE__, __LINE__, __FUNCTION__
539 539
 								);
540 540
 							}
541 541
 						}
542
-						$transaction->set_payment_method_ID( $PMD_ID );
542
+						$transaction->set_payment_method_ID($PMD_ID);
543 543
 						$transaction->save();
544 544
 					} else {
545 545
 						EE_Error::add_error(
546
-							__( 'Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso' ),
546
+							__('Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso'),
547 547
 							__FILE__, __LINE__, __FUNCTION__
548 548
 						);
549 549
 					}
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 	 * @deprecated 4.9.12
581 581
 	 * @param string $old_txn_status
582 582
 	 */
583
-	public function set_old_txn_status( $old_txn_status ) {
583
+	public function set_old_txn_status($old_txn_status) {
584 584
 		EE_Error::doing_it_wrong(
585 585
 			__METHOD__,
586 586
 			esc_html__(
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 			'4.9.12'
591 591
 		);
592 592
 		// only set the first time
593
-		if ( $this->_old_txn_status === null ) {
593
+		if ($this->_old_txn_status === null) {
594 594
 			$this->_old_txn_status = $old_txn_status;
595 595
 		}
596 596
 	}
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 	 * @deprecated 4.9.12
620 620
 	 * @param string $new_txn_status
621 621
 	 */
622
-	public function set_new_txn_status( $new_txn_status ) {
622
+	public function set_new_txn_status($new_txn_status) {
623 623
 		EE_Error::doing_it_wrong(
624 624
 			__METHOD__,
625 625
 			esc_html__(
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 	 * @param EE_Transaction $transaction
664 664
 	 * @return boolean
665 665
 	 */
666
-	public function all_reg_steps_completed( EE_Transaction $transaction ) {
666
+	public function all_reg_steps_completed(EE_Transaction $transaction) {
667 667
 		EE_Error::doing_it_wrong(
668 668
 			__METHOD__,
669 669
 			esc_html__(
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 	 * @param string         $exception
691 691
 	 * @return boolean
692 692
 	 */
693
-	public function all_reg_steps_completed_except( EE_Transaction $transaction, $exception = '' ) {
693
+	public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '') {
694 694
 		EE_Error::doing_it_wrong(
695 695
 			__METHOD__,
696 696
 			esc_html__(
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 			'4.9.12',
701 701
 			'5.0.0'
702 702
 		);
703
-		return $transaction->all_reg_steps_completed_except( $exception );
703
+		return $transaction->all_reg_steps_completed_except($exception);
704 704
 	}
705 705
 
706 706
 
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 	 * @param EE_Transaction $transaction
717 717
 	 * @return boolean
718 718
 	 */
719
-	public function all_reg_steps_completed_except_final_step( EE_Transaction $transaction ) {
719
+	public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction) {
720 720
 		EE_Error::doing_it_wrong(
721 721
 			__METHOD__,
722 722
 			esc_html__(
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
 	 * @param string         $reg_step_slug
744 744
 	 * @return boolean | int
745 745
 	 */
746
-	public function reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) {
746
+	public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug) {
747 747
 		EE_Error::doing_it_wrong(
748 748
 			__METHOD__,
749 749
 			esc_html__(
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
 			'4.9.12',
754 754
 			'5.0.0'
755 755
 		);
756
-		return $transaction->reg_step_completed( $reg_step_slug );
756
+		return $transaction->reg_step_completed($reg_step_slug);
757 757
 	}
758 758
 
759 759
 
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 	 * @param EE_Transaction $transaction
770 770
 	 * @return boolean | int
771 771
 	 */
772
-	public function final_reg_step_completed( EE_Transaction $transaction ) {
772
+	public function final_reg_step_completed(EE_Transaction $transaction) {
773 773
 		EE_Error::doing_it_wrong(
774 774
 			__METHOD__,
775 775
 			esc_html__(
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 	 * @return boolean
796 796
 	 * @throws \EE_Error
797 797
 	 */
798
-	public function set_reg_step_initiated( EE_Transaction $transaction, $reg_step_slug ) {
798
+	public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug) {
799 799
 		EE_Error::doing_it_wrong(
800 800
 			__METHOD__,
801 801
 			esc_html__(
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 			'4.9.12',
806 806
 			'5.0.0'
807 807
 		);
808
-		return $transaction->set_reg_step_initiated( $reg_step_slug );
808
+		return $transaction->set_reg_step_initiated($reg_step_slug);
809 809
 	}
810 810
 
811 811
 
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 	 * @return boolean
822 822
 	 * @throws \EE_Error
823 823
 	 */
824
-	public function set_reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) {
824
+	public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug) {
825 825
 		EE_Error::doing_it_wrong(
826 826
 			__METHOD__,
827 827
 			esc_html__(
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 			'4.9.12',
832 832
 			'5.0.0'
833 833
 		);
834
-		return $transaction->set_reg_step_completed( $reg_step_slug );
834
+		return $transaction->set_reg_step_completed($reg_step_slug);
835 835
 	}
836 836
 
837 837
 
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 	 * @return boolean
848 848
 	 * @throws \EE_Error
849 849
 	 */
850
-	public function set_reg_step_not_completed( EE_Transaction $transaction, $reg_step_slug ) {
850
+	public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug) {
851 851
 		EE_Error::doing_it_wrong(
852 852
 			__METHOD__,
853 853
 			esc_html__(
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 			'4.9.12',
858 858
 			'5.0.0'
859 859
 		);
860
-		return $transaction->set_reg_step_not_completed( $reg_step_slug );
860
+		return $transaction->set_reg_step_not_completed($reg_step_slug);
861 861
 	}
862 862
 
863 863
 
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
 	 * @param string          $reg_step_slug
875 875
 	 * @return void
876 876
 	 */
877
-	public function remove_reg_step( EE_Transaction $transaction, $reg_step_slug ) {
877
+	public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug) {
878 878
 		EE_Error::doing_it_wrong(
879 879
 			__METHOD__,
880 880
 			esc_html__(
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 			'4.9.12',
885 885
 			'5.0.0'
886 886
 		);
887
-		$transaction->remove_reg_step( $reg_step_slug );
887
+		$transaction->remove_reg_step($reg_step_slug);
888 888
 	}
889 889
 
890 890
 
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 	 * @return    boolean
901 901
 	 * @throws \EE_Error
902 902
 	 */
903
-	public function toggle_failed_transaction_status( EE_Transaction $transaction ) {
903
+	public function toggle_failed_transaction_status(EE_Transaction $transaction) {
904 904
 		EE_Error::doing_it_wrong(
905 905
 			__METHOD__,
906 906
 			esc_html__(
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 	 * @param  EE_Transaction $transaction
925 925
 	 * @return boolean
926 926
 	 */
927
-	public function toggle_abandoned_transaction_status( EE_Transaction $transaction ) {
927
+	public function toggle_abandoned_transaction_status(EE_Transaction $transaction) {
928 928
 		EE_Error::doing_it_wrong(
929 929
 			__METHOD__,
930 930
 			esc_html__(
Please login to merge, or discard this patch.
core/business/EE_Registration_Processor.class.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 			}
216 216
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
217 217
 			if ( ! EE_Processor_Base::$IPN ) {
218
-                // otherwise, send out notifications
218
+				// otherwise, send out notifications
219 219
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
220 220
 			}
221 221
 			// DEBUG LOG
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 			}
263 263
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
264 264
 			if ( ! EE_Processor_Base::$IPN ) {
265
-                // otherwise, send out notifications
265
+				// otherwise, send out notifications
266 266
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
267 267
 			}
268 268
 			// DEBUG LOG
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 			}
350 350
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
351 351
 			if ( ! EE_Processor_Base::$IPN ) {
352
-                // otherwise, send out notifications
352
+				// otherwise, send out notifications
353 353
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
354 354
 			}
355 355
 			// DEBUG LOG
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 			// 	false,
391 391
 			// 	'EE_Transaction: ' . $registration->transaction()->ID()
392 392
 			// );
393
-            if ( ! $registration->is_primary_registrant()) {
394
-                return;
395
-            }
396
-            do_action(
393
+			if ( ! $registration->is_primary_registrant()) {
394
+				return;
395
+			}
396
+			do_action(
397 397
 				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
398 398
 				$registration,
399 399
 				$additional_details
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 		// set new  REG_Status
429 429
 		$this->set_new_reg_status( $registration->ID(), $registration->status_ID() );
430 430
 		return $this->reg_status_updated( $registration->ID() )
431
-		       && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
431
+			   && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
432 432
 			? true
433 433
 			: false;
434 434
 	}
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\domain\entities\RegUrlLink;
4 4
 use EventEspresso\core\domain\services\registration\CreateRegistrationService;
5 5
 
6
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
7
-EE_Registry::instance()->load_class( 'Processor_Base' );
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
7
+EE_Registry::instance()->load_class('Processor_Base');
8 8
 
9 9
 /**
10 10
  * Class EE_Registration_Processor
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public static function instance() {
68 68
 		// check if class object is instantiated
69
-		if ( ! self::$_instance instanceof EE_Registration_Processor ) {
69
+		if ( ! self::$_instance instanceof EE_Registration_Processor) {
70 70
 			self::$_instance = new self();
71 71
 		}
72 72
 		return self::$_instance;
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 * @param int $REG_ID
87 87
 	 * @return string
88 88
 	 */
89
-	public function old_reg_status( $REG_ID ) {
90
-		return isset( $this->_old_reg_status[ $REG_ID ] ) ? $this->_old_reg_status[ $REG_ID ] : null;
89
+	public function old_reg_status($REG_ID) {
90
+		return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
91 91
 	}
92 92
 
93 93
 
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @param int $REG_ID
97 97
 	 * @param string $old_reg_status
98 98
 	 */
99
-	public function set_old_reg_status( $REG_ID, $old_reg_status ) {
99
+	public function set_old_reg_status($REG_ID, $old_reg_status) {
100 100
 		// only set the first time
101
-		if ( ! isset( $this->_old_reg_status[ $REG_ID ] ) ) {
102
-			$this->_old_reg_status[ $REG_ID ] = $old_reg_status;
101
+		if ( ! isset($this->_old_reg_status[$REG_ID])) {
102
+			$this->_old_reg_status[$REG_ID] = $old_reg_status;
103 103
 		}
104 104
 	}
105 105
 
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 * @param int $REG_ID
110 110
 	 * @return string
111 111
 	 */
112
-	public function new_reg_status( $REG_ID ) {
113
-		return isset( $this->_new_reg_status[ $REG_ID ] ) ? $this->_new_reg_status[ $REG_ID ] : null;
112
+	public function new_reg_status($REG_ID) {
113
+		return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
114 114
 	}
115 115
 
116 116
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @param int $REG_ID
120 120
 	 * @param string $new_reg_status
121 121
 	 */
122
-	public function set_new_reg_status( $REG_ID, $new_reg_status ) {
123
-		$this->_new_reg_status[ $REG_ID ] = $new_reg_status;
122
+	public function set_new_reg_status($REG_ID, $new_reg_status) {
123
+		$this->_new_reg_status[$REG_ID] = $new_reg_status;
124 124
 	}
125 125
 
126 126
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param int $REG_ID
132 132
 	 * @return bool
133 133
 	 */
134
-	public function reg_status_updated( $REG_ID ) {
135
-		return $this->new_reg_status( $REG_ID ) !== $this->old_reg_status( $REG_ID ) ? true : false;
134
+	public function reg_status_updated($REG_ID) {
135
+		return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID) ? true : false;
136 136
 	}
137 137
 
138 138
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * @param \EE_Registration $registration
142 142
 	 * @throws \EE_Error
143 143
 	 */
144
-	public function update_registration_status_and_trigger_notifications( \EE_Registration $registration ) {
145
-		$this->toggle_incomplete_registration_status_to_default( $registration, false );
146
-		$this->toggle_registration_status_for_default_approved_events( $registration, false );
147
-		$this->toggle_registration_status_if_no_monies_owing( $registration, false );
144
+	public function update_registration_status_and_trigger_notifications(\EE_Registration $registration) {
145
+		$this->toggle_incomplete_registration_status_to_default($registration, false);
146
+		$this->toggle_registration_status_for_default_approved_events($registration, false);
147
+		$this->toggle_registration_status_if_no_monies_owing($registration, false);
148 148
 		$registration->save();
149 149
 		// trigger notifications
150
-		$this->trigger_registration_update_notifications( $registration );
150
+		$this->trigger_registration_update_notifications($registration);
151 151
 	}
152 152
 
153 153
 
@@ -162,18 +162,18 @@  discard block
 block discarded – undo
162 162
 	 * @return boolean
163 163
 	 * @throws \EE_Error
164 164
 	 */
165
-	public function manually_update_registration_status( EE_Registration $registration, $new_reg_status = '', $save = true ) {
165
+	public function manually_update_registration_status(EE_Registration $registration, $new_reg_status = '', $save = true) {
166 166
 		// set initial REG_Status
167
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
167
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
168 168
 		// set incoming REG_Status
169
-		$this->set_new_reg_status( $registration->ID(), $new_reg_status );
169
+		$this->set_new_reg_status($registration->ID(), $new_reg_status);
170 170
 		// toggle reg status but only if it has changed and the user can do so
171 171
 		if (
172
-			$this->reg_status_updated( $registration->ID() ) &&
173
-			EE_Registry::instance()->CAP->current_user_can( 'ee_edit_registration', 'toggle_registration_status', $registration->ID() )
172
+			$this->reg_status_updated($registration->ID()) &&
173
+			EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'toggle_registration_status', $registration->ID())
174 174
 		) {
175 175
 			// change status to new value
176
-			if ( $registration->set_status( $this->new_reg_status( $registration->ID() ) ) && $save ) {
176
+			if ($registration->set_status($this->new_reg_status($registration->ID())) && $save) {
177 177
 				$registration->save();
178 178
 			}
179 179
 			return TRUE;
@@ -193,30 +193,30 @@  discard block
 block discarded – undo
193 193
 	 * @return void
194 194
 	 * @throws \EE_Error
195 195
 	 */
196
-	public function toggle_incomplete_registration_status_to_default( EE_Registration $registration, $save = TRUE ) {
196
+	public function toggle_incomplete_registration_status_to_default(EE_Registration $registration, $save = TRUE) {
197 197
 		$existing_reg_status = $registration->status_ID();
198 198
 		// set initial REG_Status
199
-		$this->set_old_reg_status( $registration->ID(), $existing_reg_status );
199
+		$this->set_old_reg_status($registration->ID(), $existing_reg_status);
200 200
 		// is the registration currently incomplete ?
201
-		if ( $registration->status_ID() === EEM_Registration::status_id_incomplete ) {
201
+		if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
202 202
 			// grab default reg status for the event, if set
203 203
 			$event_default_registration_status = $registration->event()->default_registration_status();
204 204
 			// if no default reg status is set for the event, then use the global value
205
-			$STS_ID = ! empty( $event_default_registration_status )
205
+			$STS_ID = ! empty($event_default_registration_status)
206 206
 				? $event_default_registration_status
207 207
 				: EE_Registry::instance()->CFG->registration->default_STS_ID;
208 208
 			// if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
209 209
 			$STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment : $STS_ID;
210 210
 			// set incoming REG_Status
211
-			$this->set_new_reg_status( $registration->ID(), $STS_ID );
212
-			$registration->set_status( $STS_ID );
213
-			if ( $save ) {
211
+			$this->set_new_reg_status($registration->ID(), $STS_ID);
212
+			$registration->set_status($STS_ID);
213
+			if ($save) {
214 214
 				$registration->save();
215 215
 			}
216 216
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
217
-			if ( ! EE_Processor_Base::$IPN ) {
217
+			if ( ! EE_Processor_Base::$IPN) {
218 218
                 // otherwise, send out notifications
219
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
219
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
220 220
 			}
221 221
 			// DEBUG LOG
222 222
 			//$this->log(
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 	 * @return boolean
242 242
 	 * @throws \EE_Error
243 243
 	 */
244
-	public function toggle_registration_status_for_default_approved_events( EE_Registration $registration, $save = TRUE ) {
244
+	public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = TRUE) {
245 245
 		$reg_status = $registration->status_ID();
246 246
 		// set initial REG_Status
247
-		$this->set_old_reg_status( $registration->ID(), $reg_status );
247
+		$this->set_old_reg_status($registration->ID(), $reg_status);
248 248
 		// if not already, toggle reg status to approved IF the event default reg status is approved
249 249
 		// ( as long as the registration wasn't cancelled or declined at some point )
250 250
 		if (
@@ -254,16 +254,16 @@  discard block
 block discarded – undo
254 254
 			$registration->event()->default_registration_status() === EEM_Registration::status_id_approved
255 255
 		) {
256 256
 			// set incoming REG_Status
257
-			$this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved );
257
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
258 258
 			// toggle status to approved
259
-			$registration->set_status( EEM_Registration::status_id_approved );
260
-			if ( $save ) {
259
+			$registration->set_status(EEM_Registration::status_id_approved);
260
+			if ($save) {
261 261
 				$registration->save();
262 262
 			}
263 263
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
264
-			if ( ! EE_Processor_Base::$IPN ) {
264
+			if ( ! EE_Processor_Base::$IPN) {
265 265
                 // otherwise, send out notifications
266
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
266
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
267 267
 			}
268 268
 			// DEBUG LOG
269 269
 			//$this->log(
@@ -291,19 +291,19 @@  discard block
 block discarded – undo
291 291
 	 * @return bool
292 292
 	 * @throws \EE_Error
293 293
 	 */
294
-	public function toggle_registration_status_if_no_monies_owing( EE_Registration $registration, $save = TRUE, $additional_details = array() ) {
294
+	public function toggle_registration_status_if_no_monies_owing(EE_Registration $registration, $save = TRUE, $additional_details = array()) {
295 295
 		// set initial REG_Status
296
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
296
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
297 297
 		//EEH_Debug_Tools::printr( $additional_details, '$additional_details', __FILE__, __LINE__ );
298 298
 		// was a payment just made ?
299 299
 		if (
300
-			isset( $additional_details[ 'payment_updates' ], $additional_details[ 'last_payment' ] ) &&
301
-			$additional_details[ 'payment_updates' ] &&
302
-			$additional_details[ 'last_payment' ] instanceof EE_Payment
300
+			isset($additional_details['payment_updates'], $additional_details['last_payment']) &&
301
+			$additional_details['payment_updates'] &&
302
+			$additional_details['last_payment'] instanceof EE_Payment
303 303
 		) {
304
-			$payment = $additional_details[ 'last_payment' ];
304
+			$payment = $additional_details['last_payment'];
305 305
 			$total_paid = 0;
306
-			foreach ( self::$_amount_paid as $reg => $amount_paid ) {
306
+			foreach (self::$_amount_paid as $reg => $amount_paid) {
307 307
 				$total_paid += $amount_paid;
308 308
 			}
309 309
 		} else {
@@ -327,30 +327,30 @@  discard block
 block discarded – undo
327 327
 					$registration->transaction()->is_completed() ||
328 328
 					$registration->transaction()->is_overpaid() ||
329 329
 					$registration->transaction()->is_free() ||
330
-					apply_filters( 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration )
330
+					apply_filters('FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration)
331 331
 				) || (
332 332
 					$payment instanceof EE_Payment &&
333 333
 					$payment->is_approved() &&
334 334
 					// this specific registration has not yet been paid for
335
-					! isset( self::$_amount_paid[ $registration->ID() ] ) &&
335
+					! isset(self::$_amount_paid[$registration->ID()]) &&
336 336
 					// payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
337 337
 					$payment->amount() - $total_paid >= $registration->final_price()
338 338
 				)
339 339
 			)
340 340
 		) {
341 341
 			// mark as paid
342
-			self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
342
+			self::$_amount_paid[$registration->ID()] = $registration->final_price();
343 343
 			// track new REG_Status
344
-			$this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved );
344
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
345 345
 			// toggle status to approved
346
-			$registration->set_status( EEM_Registration::status_id_approved );
347
-			if ( $save ) {
346
+			$registration->set_status(EEM_Registration::status_id_approved);
347
+			if ($save) {
348 348
 				$registration->save();
349 349
 			}
350 350
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
351
-			if ( ! EE_Processor_Base::$IPN ) {
351
+			if ( ! EE_Processor_Base::$IPN) {
352 352
                 // otherwise, send out notifications
353
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
353
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
354 354
 			}
355 355
 			// DEBUG LOG
356 356
 			//$this->log(
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
 	 * @param array 	$additional_details
377 377
 	 * @return void
378 378
 	 */
379
-	public function trigger_registration_update_notifications( $registration, $additional_details = array() ) {
379
+	public function trigger_registration_update_notifications($registration, $additional_details = array()) {
380 380
 		try {
381
-			if ( ! $registration instanceof EE_Registration ) {
382
-				throw new EE_Error( __( 'An invalid registration was received.', 'event_espresso' ) );
381
+			if ( ! $registration instanceof EE_Registration) {
382
+				throw new EE_Error(__('An invalid registration was received.', 'event_espresso'));
383 383
 			}
384 384
 			// EE_Registry::instance()->load_helper( 'Debug_Tools' );
385 385
 			// EEH_Debug_Tools::log(
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 				$registration,
399 399
 				$additional_details
400 400
 			);
401
-		} catch( Exception $e ) {
402
-			EE_Error::add_error( $e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine() );
401
+		} catch (Exception $e) {
402
+			EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
403 403
 		}
404 404
 	}
405 405
 
@@ -413,22 +413,22 @@  discard block
 block discarded – undo
413 413
 	 * @return bool
414 414
 	 * @throws \EE_Error
415 415
 	 */
416
-	public function update_registration_after_checkout_or_payment(  EE_Registration $registration, $additional_details = array() ) {
416
+	public function update_registration_after_checkout_or_payment(EE_Registration $registration, $additional_details = array()) {
417 417
 		// set initial REG_Status
418
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
418
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
419 419
 
420 420
 		// if the registration status gets updated, then save the registration
421 421
 		if (
422
-			$this->toggle_registration_status_for_default_approved_events( $registration, false )
423
-			|| $this->toggle_registration_status_if_no_monies_owing( $registration, false, $additional_details )
422
+			$this->toggle_registration_status_for_default_approved_events($registration, false)
423
+			|| $this->toggle_registration_status_if_no_monies_owing($registration, false, $additional_details)
424 424
 		) {
425 425
 			$registration->save();
426 426
 		}
427 427
 
428 428
 		// set new  REG_Status
429
-		$this->set_new_reg_status( $registration->ID(), $registration->status_ID() );
430
-		return $this->reg_status_updated( $registration->ID() )
431
-		       && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
429
+		$this->set_new_reg_status($registration->ID(), $registration->status_ID());
430
+		return $this->reg_status_updated($registration->ID())
431
+		       && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved
432 432
 			? true
433 433
 			: false;
434 434
 	}
@@ -444,20 +444,20 @@  discard block
 block discarded – undo
444 444
 	 * @return void
445 445
 	 * @throws \EE_Error
446 446
 	 */
447
-	public function update_registration_final_prices( $transaction, $save_regs = true ) {
448
-		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $transaction->total_line_item() );
449
-		foreach( $transaction->registrations() as $registration ) {
447
+	public function update_registration_final_prices($transaction, $save_regs = true) {
448
+		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item());
449
+		foreach ($transaction->registrations() as $registration) {
450 450
 			/** @var EE_Line_Item $line_item */
451
-			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration( $registration );
452
-			if( isset( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] ) ) {
453
-				$registration->set_final_price( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] );
454
-				if( $save_regs ) {
451
+			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
452
+			if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
453
+				$registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
454
+				if ($save_regs) {
455 455
 					$registration->save();
456 456
 				}
457 457
 			}
458 458
 		}
459 459
 		//and make sure there's no rounding problem
460
-		$this->fix_reg_final_price_rounding_issue( $transaction );
460
+		$this->fix_reg_final_price_rounding_issue($transaction);
461 461
 	}
462 462
 
463 463
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return boolean success verifying that there is NO difference after this method is done
478 478
 	 * @throws \EE_Error
479 479
 	 */
480
-	public function fix_reg_final_price_rounding_issue( $transaction ) {
480
+	public function fix_reg_final_price_rounding_issue($transaction) {
481 481
 		$reg_final_price_sum = EEM_Registration::instance()->sum(
482 482
 			array(
483 483
 				array(
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
 			),
487 487
 			'REG_final_price'
488 488
 		);
489
-		$diff =  $transaction->total() - (float) $reg_final_price_sum;
489
+		$diff = $transaction->total() - (float) $reg_final_price_sum;
490 490
 		//ok then, just grab one of the registrations
491
-		if( $diff !== 0 ) {
491
+		if ($diff !== 0) {
492 492
 			$a_reg = EEM_Registration::instance()->get_one(
493 493
 					array(
494 494
 						array(
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 					));
498 498
 			$success = $a_reg instanceof EE_Registration
499 499
 				? $a_reg->save(
500
-					array( 'REG_final_price' => $a_reg->final_price() + $diff )
500
+					array('REG_final_price' => $a_reg->final_price() + $diff)
501 501
 				)
502 502
 				: false;
503 503
 			return $success ? true : false;
@@ -522,13 +522,13 @@  discard block
 block discarded – undo
522 522
 		$update_reg = true
523 523
 	) {
524 524
 		// these reg statuses should not be considered in any calculations involving monies owing
525
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses
525
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
526 526
 			: EEM_Registration::closed_reg_statuses();
527
-		if ( ! in_array( $registration->status_ID(), $closed_reg_statuses ) ) {
527
+		if ( ! in_array($registration->status_ID(), $closed_reg_statuses)) {
528 528
 			return false;
529 529
 		}
530 530
 		$registration->set_final_price(0);
531
-		if ( $update_reg ) {
531
+		if ($update_reg) {
532 532
 			$registration->save();
533 533
 		}
534 534
 		return true;
@@ -551,23 +551,23 @@  discard block
 block discarded – undo
551 551
 		$update_reg = true
552 552
 	) {
553 553
 		// these reg statuses should not be considered in any calculations involving monies owing
554
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses
554
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
555 555
 			: EEM_Registration::closed_reg_statuses();
556
-		if ( in_array( $registration->status_ID(), $closed_reg_statuses ) ) {
556
+		if (in_array($registration->status_ID(), $closed_reg_statuses)) {
557 557
 			return false;
558 558
 		}
559 559
 		$ticket = $registration->ticket();
560
-		if ( ! $ticket instanceof EE_Ticket ) {
560
+		if ( ! $ticket instanceof EE_Ticket) {
561 561
 			throw new EE_Error(
562 562
 				sprintf(
563
-					__( 'The Ticket for Registration %1$d was not found or is invalid.',
564
-						'event_espresso' ),
563
+					__('The Ticket for Registration %1$d was not found or is invalid.',
564
+						'event_espresso'),
565 565
 					$registration->ticket_ID()
566 566
 				)
567 567
 			);
568 568
 		}
569
-		$registration->set_final_price( $ticket->price() );
570
-		if ( $update_reg ) {
569
+		$registration->set_final_price($ticket->price());
570
+		if ($update_reg) {
571 571
 			$registration->save();
572 572
 		}
573 573
 		return true;
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 		$total_ticket_count = 1
606 606
 	) {
607 607
 		EE_Error::doing_it_wrong(
608
-			__CLASS__ . '::' . __FUNCTION__,
608
+			__CLASS__.'::'.__FUNCTION__,
609 609
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
610 610
 				'\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'),
611 611
 			'4.9.1',
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 	public function generate_reg_url_link($att_nmbr, $item)
649 649
 	{
650 650
 		EE_Error::doing_it_wrong(
651
-			__CLASS__ . '::' . __FUNCTION__,
651
+			__CLASS__.'::'.__FUNCTION__,
652 652
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
653 653
 				'EventEspresso\core\domain\entities\RegUrlLink'),
654 654
 			'4.9.1',
@@ -668,11 +668,11 @@  discard block
 block discarded – undo
668 668
 	 * @return string
669 669
 	 * @throws \EE_Error
670 670
 	 */
671
-	public function generate_reg_code( EE_Registration $registration ) {
671
+	public function generate_reg_code(EE_Registration $registration) {
672 672
 		EE_Error::doing_it_wrong(
673
-			__CLASS__ . '::' . __FUNCTION__,
673
+			__CLASS__.'::'.__FUNCTION__,
674 674
 			sprintf(
675
-				__( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ),
675
+				__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
676 676
 				'EventEspresso\core\domain\entities\RegCode'
677 677
 			),
678 678
 			'4.9.1',
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 		return apply_filters(
682 682
 			'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
683 683
 			new RegCode(
684
-				RegUrlLink::fromRegistration( $registration ),
684
+				RegUrlLink::fromRegistration($registration),
685 685
 				$registration->transaction(),
686 686
 				$registration->ticket()
687 687
 			),
Please login to merge, or discard this patch.