Completed
Branch FET-3959-event-schema (b99153)
by
unknown
78:22 queued 66:16
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_Base_Class.class.php 1 patch
Indentation   +2552 added lines, -2552 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,2557 +25,2557 @@  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
-            /**
555
-             * maybe this is EE_Datetime_Field.  If so we need to make sure timezone and
556
-             * formats are correct.
557
-             */
558
-            if ($field_obj instanceof EE_Datetime_Field) {
559
-                $field_obj->set_timezone($this->_timezone);
560
-                $field_obj->set_date_format($this->_dt_frmt, $pretty);
561
-                $field_obj->set_time_format($this->_tm_frmt, $pretty);
562
-            }
563
-            if ( ! isset($this->_fields[$fieldname])) {
564
-                $this->_fields[$fieldname] = null;
565
-            }
566
-            $value = $pretty
567
-                ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
568
-                : $field_obj->prepare_for_get($this->_fields[$fieldname]);
569
-            $this->_set_cached_property($fieldname, $value, $cache_type);
570
-            return $value;
571
-        }
572
-        return null;
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * This just takes care of clearing out the cached_properties
579
-     *
580
-     * @return void
581
-     */
582
-    protected function _clear_cached_properties()
583
-    {
584
-        $this->_cached_properties = array();
585
-    }
586
-
587
-
588
-
589
-    /**
590
-     * This just clears out ONE property if it exists in the cache
591
-     *
592
-     * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
593
-     * @return void
594
-     */
595
-    protected function _clear_cached_property($property_name)
596
-    {
597
-        if (isset($this->_cached_properties[$property_name])) {
598
-            unset($this->_cached_properties[$property_name]);
599
-        }
600
-    }
601
-
602
-
603
-
604
-    /**
605
-     * Ensures that this related thing is a model object.
606
-     *
607
-     * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
608
-     * @param string $model_name   name of the related thing, eg 'Attendee',
609
-     * @return EE_Base_Class
610
-     * @throws \EE_Error
611
-     */
612
-    protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
613
-    {
614
-        $other_model_instance = self::_get_model_instance_with_name(
615
-            self::_get_model_classname($model_name),
616
-            $this->_timezone
617
-        );
618
-        return $other_model_instance->ensure_is_obj($object_or_id);
619
-    }
620
-
621
-
622
-
623
-    /**
624
-     * Forgets the cached model of the given relation Name. So the next time we request it,
625
-     * we will fetch it again from the database. (Handy if you know it's changed somehow).
626
-     * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
627
-     * then only remove that one object from our cached array. Otherwise, clear the entire list
628
-     *
629
-     * @param string $relationName                         one of the keys in the _model_relations array on the model. Eg 'Registration'
630
-     * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
631
-     *                                                     if you intend to use $clear_all = TRUE, or the relation only has 1 object anyways (ie, it's a BelongsToRelation)
632
-     * @param bool   $clear_all                            This flags clearing the entire cache relation property if this is HasMany or HABTM.
633
-     * @throws EE_Error
634
-     * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all
635
-     */
636
-    public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
637
-    {
638
-        $relationship_to_model = $this->get_model()->related_settings_for($relationName);
639
-        $index_in_cache = '';
640
-        if ( ! $relationship_to_model) {
641
-            throw new EE_Error(
642
-                sprintf(
643
-                    __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
644
-                    $relationName,
645
-                    get_class($this)
646
-                )
647
-            );
648
-        }
649
-        if ($clear_all) {
650
-            $obj_removed = true;
651
-            $this->_model_relations[$relationName] = null;
652
-        } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
653
-            $obj_removed = $this->_model_relations[$relationName];
654
-            $this->_model_relations[$relationName] = null;
655
-        } else {
656
-            if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) {
657
-                $index_in_cache = $object_to_remove_or_index_into_array->ID();
658
-                if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) {
659
-                    $index_found_at = null;
660
-                    //find this object in the array even though it has a different key
661
-                    foreach ($this->_model_relations[$relationName] as $index => $obj) {
662
-                        if (
663
-                            $obj instanceof EE_Base_Class
664
-                            && (
665
-                                $obj == $object_to_remove_or_index_into_array
666
-                                || $obj->ID() === $object_to_remove_or_index_into_array->ID()
667
-                            )
668
-                        ) {
669
-                            $index_found_at = $index;
670
-                            break;
671
-                        }
672
-                    }
673
-                    if ($index_found_at) {
674
-                        $index_in_cache = $index_found_at;
675
-                    } else {
676
-                        //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
677
-                        //if it wasn't in it to begin with. So we're done
678
-                        return $object_to_remove_or_index_into_array;
679
-                    }
680
-                }
681
-            } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
682
-                //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
683
-                foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
684
-                    if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
685
-                        $index_in_cache = $index;
686
-                    }
687
-                }
688
-            } else {
689
-                $index_in_cache = $object_to_remove_or_index_into_array;
690
-            }
691
-            //supposedly we've found it. But it could just be that the client code
692
-            //provided a bad index/object
693
-            if (
694
-            isset(
695
-                $this->_model_relations[$relationName],
696
-                $this->_model_relations[$relationName][$index_in_cache]
697
-            )
698
-            ) {
699
-                $obj_removed = $this->_model_relations[$relationName][$index_in_cache];
700
-                unset($this->_model_relations[$relationName][$index_in_cache]);
701
-            } else {
702
-                //that thing was never cached anyways.
703
-                $obj_removed = null;
704
-            }
705
-        }
706
-        return $obj_removed;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * update_cache_after_object_save
713
-     * 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
714
-     *
715
-     * @param string         $relationName       - the type of object that is cached
716
-     * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
717
-     * @param string         $current_cache_id   - the ID that was used when originally caching the object
718
-     * @return boolean TRUE on success, FALSE on fail
719
-     * @throws \EE_Error
720
-     */
721
-    public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '')
722
-    {
723
-        // verify that incoming object is of the correct type
724
-        $obj_class = 'EE_' . $relationName;
725
-        if ($newly_saved_object instanceof $obj_class) {
726
-            /* @type EE_Base_Class $newly_saved_object */
727
-            // now get the type of relation
728
-            $relationship_to_model = $this->get_model()->related_settings_for($relationName);
729
-            // if this is a 1:1 relationship
730
-            if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
731
-                // then just replace the cached object with the newly saved object
732
-                $this->_model_relations[$relationName] = $newly_saved_object;
733
-                return true;
734
-                // or if it's some kind of sordid feral polyamorous relationship...
735
-            } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) {
736
-                // then remove the current cached item
737
-                unset($this->_model_relations[$relationName][$current_cache_id]);
738
-                // and cache the newly saved object using it's new ID
739
-                $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
740
-                return true;
741
-            }
742
-        }
743
-        return false;
744
-    }
745
-
746
-
747
-
748
-    /**
749
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
750
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
751
-     *
752
-     * @param string $relationName
753
-     * @return EE_Base_Class
754
-     */
755
-    public function get_one_from_cache($relationName)
756
-    {
757
-        $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null;
758
-        if (is_array($cached_array_or_object)) {
759
-            return array_shift($cached_array_or_object);
760
-        } else {
761
-            return $cached_array_or_object;
762
-        }
763
-    }
764
-
765
-
766
-
767
-    /**
768
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
769
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
770
-     *
771
-     * @param string $relationName
772
-     * @throws \EE_Error
773
-     * @return EE_Base_Class[] NOT necessarily indexed by primary keys
774
-     */
775
-    public function get_all_from_cache($relationName)
776
-    {
777
-        $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
778
-        // if the result is not an array, but exists, make it an array
779
-        $objects = is_array($objects) ? $objects : array($objects);
780
-        //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
781
-        //basically, if this model object was stored in the session, and these cached model objects
782
-        //already have IDs, let's make sure they're in their model's entity mapper
783
-        //otherwise we will have duplicates next time we call
784
-        // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
785
-        $model = EE_Registry::instance()->load_model($relationName);
786
-        foreach ($objects as $model_object) {
787
-            if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
788
-                //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
789
-                if ($model_object->ID()) {
790
-                    $model->add_to_entity_map($model_object);
791
-                }
792
-            } else {
793
-                throw new EE_Error(
794
-                    sprintf(
795
-                        __(
796
-                            'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
797
-                            'event_espresso'
798
-                        ),
799
-                        $relationName,
800
-                        gettype($model_object)
801
-                    )
802
-                );
803
-            }
804
-        }
805
-        return $objects;
806
-    }
807
-
808
-
809
-
810
-    /**
811
-     * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
812
-     * matching the given query conditions.
813
-     *
814
-     * @param null  $field_to_order_by  What field is being used as the reference point.
815
-     * @param int   $limit              How many objects to return.
816
-     * @param array $query_params       Any additional conditions on the query.
817
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
818
-     *                                  you can indicate just the columns you want returned
819
-     * @return array|EE_Base_Class[]
820
-     * @throws \EE_Error
821
-     */
822
-    public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
823
-    {
824
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
825
-            ? $this->get_model()->get_primary_key_field()->get_name()
826
-            : $field_to_order_by;
827
-        $current_value = ! empty($field) ? $this->get($field) : null;
828
-        if (empty($field) || empty($current_value)) {
829
-            return array();
830
-        }
831
-        return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
832
-    }
833
-
834
-
835
-
836
-    /**
837
-     * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
838
-     * matching the given query conditions.
839
-     *
840
-     * @param null  $field_to_order_by  What field is being used as the reference point.
841
-     * @param int   $limit              How many objects to return.
842
-     * @param array $query_params       Any additional conditions on the query.
843
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
844
-     *                                  you can indicate just the columns you want returned
845
-     * @return array|EE_Base_Class[]
846
-     * @throws \EE_Error
847
-     */
848
-    public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
849
-    {
850
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
851
-            ? $this->get_model()->get_primary_key_field()->get_name()
852
-            : $field_to_order_by;
853
-        $current_value = ! empty($field) ? $this->get($field) : null;
854
-        if (empty($field) || empty($current_value)) {
855
-            return array();
856
-        }
857
-        return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
858
-    }
859
-
860
-
861
-
862
-    /**
863
-     * Returns the next EE_Base_Class object in sequence from this object as found in the database
864
-     * matching the given query conditions.
865
-     *
866
-     * @param null  $field_to_order_by  What field is being used as the reference point.
867
-     * @param array $query_params       Any additional conditions on the query.
868
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
869
-     *                                  you can indicate just the columns you want returned
870
-     * @return array|EE_Base_Class
871
-     * @throws \EE_Error
872
-     */
873
-    public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
874
-    {
875
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
876
-            ? $this->get_model()->get_primary_key_field()->get_name()
877
-            : $field_to_order_by;
878
-        $current_value = ! empty($field) ? $this->get($field) : null;
879
-        if (empty($field) || empty($current_value)) {
880
-            return array();
881
-        }
882
-        return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select);
883
-    }
884
-
885
-
886
-
887
-    /**
888
-     * Returns the previous EE_Base_Class object in sequence from this object as found in the database
889
-     * matching the given query conditions.
890
-     *
891
-     * @param null  $field_to_order_by  What field is being used as the reference point.
892
-     * @param array $query_params       Any additional conditions on the query.
893
-     * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
894
-     *                                  you can indicate just the column you want returned
895
-     * @return array|EE_Base_Class
896
-     * @throws \EE_Error
897
-     */
898
-    public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
899
-    {
900
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
901
-            ? $this->get_model()->get_primary_key_field()->get_name()
902
-            : $field_to_order_by;
903
-        $current_value = ! empty($field) ? $this->get($field) : null;
904
-        if (empty($field) || empty($current_value)) {
905
-            return array();
906
-        }
907
-        return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select);
908
-    }
909
-
910
-
911
-
912
-    /**
913
-     * Overrides parent because parent expects old models.
914
-     * This also doesn't do any validation, and won't work for serialized arrays
915
-     *
916
-     * @param string $field_name
917
-     * @param mixed  $field_value_from_db
918
-     * @throws \EE_Error
919
-     */
920
-    public function set_from_db($field_name, $field_value_from_db)
921
-    {
922
-        $field_obj = $this->get_model()->field_settings_for($field_name);
923
-        if ($field_obj instanceof EE_Model_Field_Base) {
924
-            //you would think the DB has no NULLs for non-null label fields right? wrong!
925
-            //eg, a CPT model object could have an entry in the posts table, but no
926
-            //entry in the meta table. Meaning that all its columns in the meta table
927
-            //are null! yikes! so when we find one like that, use defaults for its meta columns
928
-            if ($field_value_from_db === null) {
929
-                if ($field_obj->is_nullable()) {
930
-                    //if the field allows nulls, then let it be null
931
-                    $field_value = null;
932
-                } else {
933
-                    $field_value = $field_obj->get_default_value();
934
-                }
935
-            } else {
936
-                $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
937
-            }
938
-            $this->_fields[$field_name] = $field_value;
939
-            $this->_clear_cached_property($field_name);
940
-        }
941
-    }
942
-
943
-
944
-
945
-    /**
946
-     * verifies that the specified field is of the correct type
947
-     *
948
-     * @param string $field_name
949
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
950
-     *                                (in cases where the same property may be used for different outputs
951
-     *                                - i.e. datetime, money etc.)
952
-     * @return mixed
953
-     * @throws \EE_Error
954
-     */
955
-    public function get($field_name, $extra_cache_ref = null)
956
-    {
957
-        return $this->_get_cached_property($field_name, false, $extra_cache_ref);
958
-    }
959
-
960
-
961
-
962
-    /**
963
-     * This method simply returns the RAW unprocessed value for the given property in this class
964
-     *
965
-     * @param  string $field_name A valid fieldname
966
-     * @return mixed              Whatever the raw value stored on the property is.
967
-     * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
968
-     */
969
-    public function get_raw($field_name)
970
-    {
971
-        $field_settings = $this->get_model()->field_settings_for($field_name);
972
-        return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
973
-            ? $this->_fields[$field_name]->format('U')
974
-            : $this->_fields[$field_name];
975
-    }
976
-
977
-
978
-
979
-    /**
980
-     * This is used to return the internal DateTime object used for a field that is a
981
-     * EE_Datetime_Field.
982
-     *
983
-     * @param string $field_name               The field name retrieving the DateTime object.
984
-     * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
985
-     * @throws \EE_Error
986
-     *                                         an error is set and false returned.  If the field IS an
987
-     *                                         EE_Datetime_Field and but the field value is null, then
988
-     *                                         just null is returned (because that indicates that likely
989
-     *                                         this field is nullable).
990
-     */
991
-    public function get_DateTime_object($field_name)
992
-    {
993
-        $field_settings = $this->get_model()->field_settings_for($field_name);
994
-        if ( ! $field_settings instanceof EE_Datetime_Field) {
995
-            EE_Error::add_error(
996
-                sprintf(
997
-                    __(
998
-                        'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
999
-                        'event_espresso'
1000
-                    ),
1001
-                    $field_name
1002
-                ),
1003
-                __FILE__,
1004
-                __FUNCTION__,
1005
-                __LINE__
1006
-            );
1007
-            return false;
1008
-        }
1009
-        return $this->_fields[$field_name];
1010
-    }
1011
-
1012
-
1013
-
1014
-    /**
1015
-     * To be used in template to immediately echo out the value, and format it for output.
1016
-     * Eg, should call stripslashes and whatnot before echoing
1017
-     *
1018
-     * @param string $field_name      the name of the field as it appears in the DB
1019
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1020
-     *                                (in cases where the same property may be used for different outputs
1021
-     *                                - i.e. datetime, money etc.)
1022
-     * @return void
1023
-     * @throws \EE_Error
1024
-     */
1025
-    public function e($field_name, $extra_cache_ref = null)
1026
-    {
1027
-        echo $this->get_pretty($field_name, $extra_cache_ref);
1028
-    }
1029
-
1030
-
1031
-
1032
-    /**
1033
-     * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1034
-     * can be easily used as the value of form input.
1035
-     *
1036
-     * @param string $field_name
1037
-     * @return void
1038
-     * @throws \EE_Error
1039
-     */
1040
-    public function f($field_name)
1041
-    {
1042
-        $this->e($field_name, 'form_input');
1043
-    }
1044
-
1045
-
1046
-
1047
-    /**
1048
-     * @param string $field_name
1049
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1050
-     *                                (in cases where the same property may be used for different outputs
1051
-     *                                - i.e. datetime, money etc.)
1052
-     * @return mixed
1053
-     * @throws \EE_Error
1054
-     */
1055
-    public function get_pretty($field_name, $extra_cache_ref = null)
1056
-    {
1057
-        return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1058
-    }
1059
-
1060
-
1061
-
1062
-    /**
1063
-     * This simply returns the datetime for the given field name
1064
-     * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1065
-     * (and the equivalent e_date, e_time, e_datetime).
1066
-     *
1067
-     * @access   protected
1068
-     * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1069
-     * @param string   $dt_frmt      valid datetime format used for date
1070
-     *                               (if '' then we just use the default on the field,
1071
-     *                               if NULL we use the last-used format)
1072
-     * @param string   $tm_frmt      Same as above except this is for time format
1073
-     * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1074
-     * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1075
-     * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1076
-     *                               if field is not a valid dtt field, or void if echoing
1077
-     * @throws \EE_Error
1078
-     */
1079
-    protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1080
-    {
1081
-        $in_dt_frmt = $dt_frmt === '' ? $this->_dt_frmt : $dt_frmt;
1082
-        $in_tm_frmt = $tm_frmt === '' ? $this->_tm_frmt : $tm_frmt;
1083
-        //validate field for datetime and returns field settings if valid.
1084
-        $field = $this->_get_dtt_field_settings($field_name);
1085
-        //clear cached property if either formats are not null.
1086
-        if ($dt_frmt !== null || $tm_frmt !== null) {
1087
-            $this->_clear_cached_property($field_name);
1088
-            //reset format properties because they are used in get()
1089
-            $this->_dt_frmt = $in_dt_frmt;
1090
-            $this->_tm_frmt = $in_tm_frmt;
1091
-        }
1092
-        if ($echo) {
1093
-            $field->set_pretty_date_format($in_dt_frmt);
1094
-        } else {
1095
-            $field->set_date_format($in_dt_frmt);
1096
-        }
1097
-        if ($echo) {
1098
-            $field->set_pretty_time_format($in_tm_frmt);
1099
-        } else {
1100
-            $field->set_time_format($in_tm_frmt);
1101
-        }
1102
-        //set timezone in field object
1103
-        $field->set_timezone($this->_timezone);
1104
-        //set the output returned
1105
-        switch ($date_or_time) {
1106
-            case 'D' :
1107
-                $field->set_date_time_output('date');
1108
-                break;
1109
-            case 'T' :
1110
-                $field->set_date_time_output('time');
1111
-                break;
1112
-            default :
1113
-                $field->set_date_time_output();
1114
-        }
1115
-        if ($echo) {
1116
-            $this->e($field_name, $date_or_time);
1117
-            return '';
1118
-        }
1119
-        return $this->get($field_name, $date_or_time);
1120
-    }
1121
-
1122
-
1123
-
1124
-    /**
1125
-     * 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
1126
-     * the pretty value for dtt)
1127
-     *
1128
-     * @param  string $field_name name of model object datetime field holding the value
1129
-     * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1130
-     * @return string            datetime value formatted
1131
-     * @throws \EE_Error
1132
-     */
1133
-    public function get_date($field_name, $format = '')
1134
-    {
1135
-        return $this->_get_datetime($field_name, $format, null, 'D');
1136
-    }
1137
-
1138
-
1139
-
1140
-    /**
1141
-     * @param      $field_name
1142
-     * @param string $format
1143
-     * @throws \EE_Error
1144
-     */
1145
-    public function e_date($field_name, $format = '')
1146
-    {
1147
-        $this->_get_datetime($field_name, $format, null, 'D', true);
1148
-    }
1149
-
1150
-
1151
-
1152
-    /**
1153
-     * 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
1154
-     * the pretty value for dtt)
1155
-     *
1156
-     * @param  string $field_name name of model object datetime field holding the value
1157
-     * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1158
-     * @return string             datetime value formatted
1159
-     * @throws \EE_Error
1160
-     */
1161
-    public function get_time($field_name, $format = '')
1162
-    {
1163
-        return $this->_get_datetime($field_name, null, $format, 'T');
1164
-    }
1165
-
1166
-
1167
-
1168
-    /**
1169
-     * @param      $field_name
1170
-     * @param string $format
1171
-     * @throws \EE_Error
1172
-     */
1173
-    public function e_time($field_name, $format = '')
1174
-    {
1175
-        $this->_get_datetime($field_name, null, $format, 'T', true);
1176
-    }
1177
-
1178
-
1179
-
1180
-    /**
1181
-     * 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
1182
-     * echoes the pretty value for dtt)
1183
-     *
1184
-     * @param  string $field_name name of model object datetime field holding the value
1185
-     * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1186
-     * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1187
-     * @return string             datetime value formatted
1188
-     * @throws \EE_Error
1189
-     */
1190
-    public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1191
-    {
1192
-        return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1193
-    }
1194
-
1195
-
1196
-
1197
-    /**
1198
-     * @param string $field_name
1199
-     * @param string $dt_frmt
1200
-     * @param string $tm_frmt
1201
-     * @throws \EE_Error
1202
-     */
1203
-    public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1204
-    {
1205
-        $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1206
-    }
1207
-
1208
-
1209
-
1210
-    /**
1211
-     * Get the i8ln value for a date using the WordPress @see date_i18n function.
1212
-     *
1213
-     * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1214
-     * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format on the object will be used.
1215
-     * @return string Date and time string in set locale or false if no field exists for the given
1216
-     * @throws \EE_Error
1217
-     *                           field name.
1218
-     */
1219
-    public function get_i18n_datetime($field_name, $format = '')
1220
-    {
1221
-        $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1222
-        return date_i18n(
1223
-            $format,
1224
-            EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1225
-        );
1226
-    }
1227
-
1228
-
1229
-
1230
-    /**
1231
-     * 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.
1232
-     *
1233
-     * @param  string $field_name The field name being checked
1234
-     * @throws EE_Error
1235
-     * @return EE_Datetime_Field
1236
-     */
1237
-    protected function _get_dtt_field_settings($field_name)
1238
-    {
1239
-        $field = $this->get_model()->field_settings_for($field_name);
1240
-        //check if field is dtt
1241
-        if ($field instanceof EE_Datetime_Field) {
1242
-            return $field;
1243
-        } else {
1244
-            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',
1245
-                'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1246
-        }
1247
-    }
1248
-
1249
-
1250
-
1251
-
1252
-    /**
1253
-     * NOTE ABOUT BELOW:
1254
-     * 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).
1255
-     * 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.
1256
-     */
1257
-    /**
1258
-     * sets the time on a datetime property
1259
-     *
1260
-     * @access protected
1261
-     * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1262
-     * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1263
-     * @throws \EE_Error
1264
-     */
1265
-    protected function _set_time_for($time, $fieldname)
1266
-    {
1267
-        $this->_set_date_time('T', $time, $fieldname);
1268
-    }
1269
-
1270
-
1271
-
1272
-    /**
1273
-     * sets the date on a datetime property
1274
-     *
1275
-     * @access protected
1276
-     * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1277
-     * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1278
-     * @throws \EE_Error
1279
-     */
1280
-    protected function _set_date_for($date, $fieldname)
1281
-    {
1282
-        $this->_set_date_time('D', $date, $fieldname);
1283
-    }
1284
-
1285
-
1286
-
1287
-    /**
1288
-     * 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
1289
-     *
1290
-     * @access protected
1291
-     * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1292
-     * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1293
-     * @param string          $fieldname      the name of the field the date OR time is being set on (must match a EE_Datetime_Field property)
1294
-     * @throws \EE_Error
1295
-     */
1296
-    protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1297
-    {
1298
-        $field = $this->_get_dtt_field_settings($fieldname);
1299
-        $field->set_timezone($this->_timezone);
1300
-        $field->set_date_format($this->_dt_frmt);
1301
-        $field->set_time_format($this->_tm_frmt);
1302
-        switch ($what) {
1303
-            case 'T' :
1304
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1305
-                    $datetime_value,
1306
-                    $this->_fields[$fieldname]
1307
-                );
1308
-                break;
1309
-            case 'D' :
1310
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1311
-                    $datetime_value,
1312
-                    $this->_fields[$fieldname]
1313
-                );
1314
-                break;
1315
-            case 'B' :
1316
-                $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1317
-                break;
1318
-        }
1319
-        $this->_clear_cached_property($fieldname);
1320
-    }
1321
-
1322
-
1323
-
1324
-    /**
1325
-     * 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.
1326
-     * 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!
1327
-     *
1328
-     * @access public
1329
-     * @param string               $field_name This is the name of the field on the object that contains the date/time value being returned.
1330
-     * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1331
-     * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1332
-     * @param string               $prepend    You can include something to prepend on the timestamp
1333
-     * @param string               $append     You can include something to append on the timestamp
1334
-     * @throws EE_Error
1335
-     * @return string timestamp
1336
-     */
1337
-    public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = null, $prepend = '', $append = '')
1338
-    {
1339
-        $timezone = EEH_DTT_Helper::get_timezone();
1340
-        if ($timezone === $this->_timezone) {
1341
-            return '';
1342
-        }
1343
-        $original_timezone = $this->_timezone;
1344
-        $this->set_timezone($timezone);
1345
-        $fn = (array)$field_name;
1346
-        $args = array_merge($fn, (array)$args);
1347
-        if ( ! method_exists($this, $callback)) {
1348
-            throw new EE_Error(
1349
-                sprintf(
1350
-                    __(
1351
-                        'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1352
-                        'event_espresso'
1353
-                    ),
1354
-                    $callback
1355
-                )
1356
-            );
1357
-        }
1358
-        $args = (array)$args;
1359
-        $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1360
-        $this->set_timezone($original_timezone);
1361
-        return $return;
1362
-    }
1363
-
1364
-
1365
-
1366
-    /**
1367
-     * Deletes this model object.
1368
-     * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should override
1369
-     * `EE_Base_Class::_delete` NOT this class.
1370
-     *
1371
-     * @return boolean | int
1372
-     * @throws \EE_Error
1373
-     */
1374
-    public function delete()
1375
-    {
1376
-        /**
1377
-         * Called just before the `EE_Base_Class::_delete` method call.
1378
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1379
-         * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1380
-         * soft deletes (trash) the object and does not permanently delete it.
1381
-         *
1382
-         * @param EE_Base_Class $model_object about to be 'deleted'
1383
-         */
1384
-        do_action('AHEE__EE_Base_Class__delete__before', $this);
1385
-        $result = $this->_delete();
1386
-        /**
1387
-         * Called just after the `EE_Base_Class::_delete` method call.
1388
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1389
-         * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1390
-         * soft deletes (trash) the object and does not permanently delete it.
1391
-         *
1392
-         * @param EE_Base_Class $model_object that was just 'deleted'
1393
-         * @param boolean       $result
1394
-         */
1395
-        do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1396
-        return $result;
1397
-    }
1398
-
1399
-
1400
-
1401
-    /**
1402
-     * Calls the specific delete method for the instantiated class.
1403
-     * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override default
1404
-     * functionality for "delete" (which is to call `permanently_delete`) should override this method NOT `EE_Base_Class::delete`
1405
-     *
1406
-     * @return bool|int
1407
-     * @throws \EE_Error
1408
-     */
1409
-    protected function _delete()
1410
-    {
1411
-        return $this->delete_permanently();
1412
-    }
1413
-
1414
-
1415
-
1416
-    /**
1417
-     * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error)
1418
-     *
1419
-     * @return bool | int
1420
-     * @throws \EE_Error
1421
-     */
1422
-    public function delete_permanently()
1423
-    {
1424
-        /**
1425
-         * Called just before HARD deleting a model object
1426
-         *
1427
-         * @param EE_Base_Class $model_object about to be 'deleted'
1428
-         */
1429
-        do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1430
-        $model = $this->get_model();
1431
-        $result = $model->delete_permanently_by_ID($this->ID());
1432
-        $this->refresh_cache_of_related_objects();
1433
-        /**
1434
-         * Called just after HARD deleting a model object
1435
-         *
1436
-         * @param EE_Base_Class $model_object that was just 'deleted'
1437
-         * @param boolean       $result
1438
-         */
1439
-        do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1440
-        return $result;
1441
-    }
1442
-
1443
-
1444
-
1445
-    /**
1446
-     * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1447
-     * related model objects
1448
-     *
1449
-     * @throws \EE_Error
1450
-     */
1451
-    public function refresh_cache_of_related_objects()
1452
-    {
1453
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1454
-            if ( ! empty($this->_model_relations[$relation_name])) {
1455
-                $related_objects = $this->_model_relations[$relation_name];
1456
-                if ($relation_obj instanceof EE_Belongs_To_Relation) {
1457
-                    //this relation only stores a single model object, not an array
1458
-                    //but let's make it consistent
1459
-                    $related_objects = array($related_objects);
1460
-                }
1461
-                foreach ($related_objects as $related_object) {
1462
-                    //only refresh their cache if they're in memory
1463
-                    if ($related_object instanceof EE_Base_Class) {
1464
-                        $related_object->clear_cache($this->get_model()->get_this_model_name(), $this);
1465
-                    }
1466
-                }
1467
-            }
1468
-        }
1469
-    }
1470
-
1471
-
1472
-
1473
-    /**
1474
-     *        Saves this object to the database. An array may be supplied to set some values on this
1475
-     * object just before saving.
1476
-     *
1477
-     * @access public
1478
-     * @param array $set_cols_n_values keys are field names, values are their new values,
1479
-     *                                 if provided during the save() method (often client code will change the fields' values before calling save)
1480
-     * @throws \EE_Error
1481
-     * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1482
-     *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1483
-     */
1484
-    public function save($set_cols_n_values = array())
1485
-    {
1486
-        /**
1487
-         * Filters the fields we're about to save on the model object
1488
-         *
1489
-         * @param array         $set_cols_n_values
1490
-         * @param EE_Base_Class $model_object
1491
-         */
1492
-        $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this);
1493
-        //set attributes as provided in $set_cols_n_values
1494
-        foreach ($set_cols_n_values as $column => $value) {
1495
-            $this->set($column, $value);
1496
-        }
1497
-        /**
1498
-         * Saving a model object.
1499
-         * Before we perform a save, this action is fired.
1500
-         *
1501
-         * @param EE_Base_Class $model_object the model object about to be saved.
1502
-         */
1503
-        do_action('AHEE__EE_Base_Class__save__begin', $this);
1504
-        if ( ! $this->allow_persist()) {
1505
-            return 0;
1506
-        }
1507
-        //now get current attribute values
1508
-        $save_cols_n_values = $this->_fields;
1509
-        //if the object already has an ID, update it. Otherwise, insert it
1510
-        //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1511
-        $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object();
1512
-        $this->get_model()->assume_values_already_prepared_by_model_object(true);
1513
-        //does this model have an autoincrement PK?
1514
-        if ($this->get_model()->has_primary_key_field()) {
1515
-            if ($this->get_model()->get_primary_key_field()->is_auto_increment()) {
1516
-                //ok check if it's set, if so: update; if not, insert
1517
-                if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) {
1518
-                    $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1519
-                } else {
1520
-                    unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]);
1521
-                    $results = $this->get_model()->insert($save_cols_n_values);
1522
-                    if ($results) {
1523
-                        //if successful, set the primary key
1524
-                        //but don't use the normal SET method, because it will check if
1525
-                        //an item with the same ID exists in the mapper & db, then
1526
-                        //will find it in the db (because we just added it) and THAT object
1527
-                        //will get added to the mapper before we can add this one!
1528
-                        //but if we just avoid using the SET method, all that headache can be avoided
1529
-                        $pk_field_name = self::_get_primary_key_name(get_class($this));
1530
-                        $this->_fields[$pk_field_name] = $results;
1531
-                        $this->_clear_cached_property($pk_field_name);
1532
-                        $this->get_model()->add_to_entity_map($this);
1533
-                        $this->_update_cached_related_model_objs_fks();
1534
-                    }
1535
-                }
1536
-            } else {//PK is NOT auto-increment
1537
-                //so check if one like it already exists in the db
1538
-                if ($this->get_model()->exists_by_ID($this->ID())) {
1539
-                    if (WP_DEBUG && ! $this->in_entity_map()) {
1540
-                        throw new EE_Error(
1541
-                            sprintf(
1542
-                                __('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',
1543
-                                    'event_espresso'),
1544
-                                get_class($this),
1545
-                                get_class($this->get_model()) . '::instance()->add_to_entity_map()',
1546
-                                get_class($this->get_model()) . '::instance()->get_one_by_ID()',
1547
-                                '<br />'
1548
-                            )
1549
-                        );
1550
-                    }
1551
-                    $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1552
-                } else {
1553
-                    $results = $this->get_model()->insert($save_cols_n_values);
1554
-                    $this->_update_cached_related_model_objs_fks();
1555
-                }
1556
-            }
1557
-        } else {//there is NO primary key
1558
-            $already_in_db = false;
1559
-            foreach ($this->get_model()->unique_indexes() as $index) {
1560
-                $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1561
-                if ($this->get_model()->exists(array($uniqueness_where_params))) {
1562
-                    $already_in_db = true;
1563
-                }
1564
-            }
1565
-            if ($already_in_db) {
1566
-                $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields());
1567
-                $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values);
1568
-            } else {
1569
-                $results = $this->get_model()->insert($save_cols_n_values);
1570
-            }
1571
-        }
1572
-        //restore the old assumption about values being prepared by the model object
1573
-        $this->get_model()->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1574
-        /**
1575
-         * After saving the model object this action is called
1576
-         *
1577
-         * @param EE_Base_Class $model_object which was just saved
1578
-         * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1579
-         *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1580
-         */
1581
-        do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1582
-        return $results;
1583
-    }
1584
-
1585
-
1586
-
1587
-    /**
1588
-     * Updates the foreign key on related models objects pointing to this to have this model object's ID
1589
-     * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB is consistent)
1590
-     * Especially useful in case we JUST added this model object ot the database
1591
-     * 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
1592
-     * 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)
1593
-     *
1594
-     * @return void
1595
-     * @throws \EE_Error
1596
-     */
1597
-    protected function _update_cached_related_model_objs_fks()
1598
-    {
1599
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1600
-            if ($relation_obj instanceof EE_Has_Many_Relation) {
1601
-                foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1602
-                    $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1603
-                        $this->get_model()->get_this_model_name()
1604
-                    );
1605
-                    $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1606
-                    if ($related_model_obj_in_cache->ID()) {
1607
-                        $related_model_obj_in_cache->save();
1608
-                    }
1609
-                }
1610
-            }
1611
-        }
1612
-    }
1613
-
1614
-
1615
-
1616
-    /**
1617
-     * Saves this model object and its NEW cached relations to the database.
1618
-     * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1619
-     * In order for that to work, we would need to mark model objects as dirty/clean...
1620
-     * because otherwise, there's a potential for infinite looping of saving
1621
-     * Saves the cached related model objects, and ensures the relation between them
1622
-     * and this object and properly setup
1623
-     *
1624
-     * @return int ID of new model object on save; 0 on failure+
1625
-     * @throws \EE_Error
1626
-     */
1627
-    public function save_new_cached_related_model_objs()
1628
-    {
1629
-        //make sure this has been saved
1630
-        if ( ! $this->ID()) {
1631
-            $id = $this->save();
1632
-        } else {
1633
-            $id = $this->ID();
1634
-        }
1635
-        //now save all the NEW cached model objects  (ie they don't exist in the DB)
1636
-        foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1637
-            if ($this->_model_relations[$relationName]) {
1638
-                //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1639
-                //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1640
-                if ($relationObj instanceof EE_Belongs_To_Relation) {
1641
-                    //add a relation to that relation type (which saves the appropriate thing in the process)
1642
-                    //but ONLY if it DOES NOT exist in the DB
1643
-                    /* @var $related_model_obj EE_Base_Class */
1644
-                    $related_model_obj = $this->_model_relations[$relationName];
1645
-                    //					if( ! $related_model_obj->ID()){
1646
-                    $this->_add_relation_to($related_model_obj, $relationName);
1647
-                    $related_model_obj->save_new_cached_related_model_objs();
1648
-                    //					}
1649
-                } else {
1650
-                    foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1651
-                        //add a relation to that relation type (which saves the appropriate thing in the process)
1652
-                        //but ONLY if it DOES NOT exist in the DB
1653
-                        //						if( ! $related_model_obj->ID()){
1654
-                        $this->_add_relation_to($related_model_obj, $relationName);
1655
-                        $related_model_obj->save_new_cached_related_model_objs();
1656
-                        //						}
1657
-                    }
1658
-                }
1659
-            }
1660
-        }
1661
-        return $id;
1662
-    }
1663
-
1664
-
1665
-
1666
-    /**
1667
-     * for getting a model while instantiated.
1668
-     *
1669
-     * @return \EEM_Base | \EEM_CPT_Base
1670
-     */
1671
-    public function get_model()
1672
-    {
1673
-        $modelName = self::_get_model_classname(get_class($this));
1674
-        return self::_get_model_instance_with_name($modelName, $this->_timezone);
1675
-    }
1676
-
1677
-
1678
-
1679
-    /**
1680
-     * @param $props_n_values
1681
-     * @param $classname
1682
-     * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1683
-     * @throws \EE_Error
1684
-     */
1685
-    protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1686
-    {
1687
-        //TODO: will not work for Term_Relationships because they have no PK!
1688
-        $primary_id_ref = self::_get_primary_key_name($classname);
1689
-        if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1690
-            $id = $props_n_values[$primary_id_ref];
1691
-            return self::_get_model($classname)->get_from_entity_map($id);
1692
-        }
1693
-        return false;
1694
-    }
1695
-
1696
-
1697
-
1698
-    /**
1699
-     * 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).
1700
-     * 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.
1701
-     *
1702
-     * @param  array  $props_n_values   incoming array of properties and their values
1703
-     * @param  string $classname        the classname of the child class
1704
-     * @param null    $timezone
1705
-     * @param array   $date_formats     incoming date_formats in an array where the first value is the
1706
-     *                                  date_format and the second value is the time format
1707
-     * @return mixed (EE_Base_Class|bool)
1708
-     * @throws \EE_Error
1709
-     */
1710
-    protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1711
-    {
1712
-        $existing = null;
1713
-        if (self::_get_model($classname)->has_primary_key_field()) {
1714
-            $primary_id_ref = self::_get_primary_key_name($classname);
1715
-            if (array_key_exists($primary_id_ref, $props_n_values)
1716
-                && ! empty($props_n_values[$primary_id_ref])
1717
-            ) {
1718
-                $existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1719
-                    $props_n_values[$primary_id_ref]
1720
-                );
1721
-            }
1722
-        } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) {
1723
-            //no primary key on this model, but there's still a matching item in the DB
1724
-            $existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1725
-                self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1726
-            );
1727
-        }
1728
-        if ($existing) {
1729
-            //set date formats if present before setting values
1730
-            if ( ! empty($date_formats) && is_array($date_formats)) {
1731
-                $existing->set_date_format($date_formats[0]);
1732
-                $existing->set_time_format($date_formats[1]);
1733
-            } else {
1734
-                //set default formats for date and time
1735
-                $existing->set_date_format(get_option('date_format'));
1736
-                $existing->set_time_format(get_option('time_format'));
1737
-            }
1738
-            foreach ($props_n_values as $property => $field_value) {
1739
-                $existing->set($property, $field_value);
1740
-            }
1741
-            return $existing;
1742
-        } else {
1743
-            return false;
1744
-        }
1745
-    }
1746
-
1747
-
1748
-
1749
-    /**
1750
-     * Gets the EEM_*_Model for this class
1751
-     *
1752
-     * @access public now, as this is more convenient
1753
-     * @param      $classname
1754
-     * @param null $timezone
1755
-     * @throws EE_Error
1756
-     * @return EEM_Base
1757
-     */
1758
-    protected static function _get_model($classname, $timezone = null)
1759
-    {
1760
-        //find model for this class
1761
-        if ( ! $classname) {
1762
-            throw new EE_Error(
1763
-                sprintf(
1764
-                    __(
1765
-                        "What were you thinking calling _get_model(%s)?? You need to specify the class name",
1766
-                        "event_espresso"
1767
-                    ),
1768
-                    $classname
1769
-                )
1770
-            );
1771
-        }
1772
-        $modelName = self::_get_model_classname($classname);
1773
-        return self::_get_model_instance_with_name($modelName, $timezone);
1774
-    }
1775
-
1776
-
1777
-
1778
-    /**
1779
-     * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1780
-     *
1781
-     * @param string $model_classname
1782
-     * @param null   $timezone
1783
-     * @return EEM_Base
1784
-     */
1785
-    protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1786
-    {
1787
-        $model_classname = str_replace('EEM_', '', $model_classname);
1788
-        $model = EE_Registry::instance()->load_model($model_classname);
1789
-        $model->set_timezone($timezone);
1790
-        return $model;
1791
-    }
1792
-
1793
-
1794
-
1795
-    /**
1796
-     * If a model name is provided (eg Registration), gets the model classname for that model.
1797
-     * Also works if a model class's classname is provided (eg EE_Registration).
1798
-     *
1799
-     * @param null $model_name
1800
-     * @return string like EEM_Attendee
1801
-     */
1802
-    private static function _get_model_classname($model_name = null)
1803
-    {
1804
-        if (strpos($model_name, "EE_") === 0) {
1805
-            $model_classname = str_replace("EE_", "EEM_", $model_name);
1806
-        } else {
1807
-            $model_classname = "EEM_" . $model_name;
1808
-        }
1809
-        return $model_classname;
1810
-    }
1811
-
1812
-
1813
-
1814
-    /**
1815
-     * returns the name of the primary key attribute
1816
-     *
1817
-     * @param null $classname
1818
-     * @throws EE_Error
1819
-     * @return string
1820
-     */
1821
-    protected static function _get_primary_key_name($classname = null)
1822
-    {
1823
-        if ( ! $classname) {
1824
-            throw new EE_Error(
1825
-                sprintf(
1826
-                    __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1827
-                    $classname
1828
-                )
1829
-            );
1830
-        }
1831
-        return self::_get_model($classname)->get_primary_key_field()->get_name();
1832
-    }
1833
-
1834
-
1835
-
1836
-    /**
1837
-     * Gets the value of the primary key.
1838
-     * If the object hasn't yet been saved, it should be whatever the model field's default was
1839
-     * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value is.
1840
-     * Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1841
-     *
1842
-     * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1843
-     * @throws \EE_Error
1844
-     */
1845
-    public function ID()
1846
-    {
1847
-        //now that we know the name of the variable, use a variable variable to get its value and return its
1848
-        if ($this->get_model()->has_primary_key_field()) {
1849
-            return $this->_fields[self::_get_primary_key_name(get_class($this))];
1850
-        } else {
1851
-            return $this->get_model()->get_index_primary_key_string($this->_fields);
1852
-        }
1853
-    }
1854
-
1855
-
1856
-
1857
-    /**
1858
-     * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current model is related
1859
-     * to a group of events, the $relationName should be 'Event', and should be a key in the EE Model's $_model_relations array.
1860
-     * If this model object doesn't exist in the DB, just caches the related thing
1861
-     *
1862
-     * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1863
-     * @param string $relationName                     eg 'Events','Question',etc.
1864
-     *                                                 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')
1865
-     * @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
1866
-     *                                                 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,
1867
-     *                                                 then a NEW row is created in the join table.
1868
-     * @param null   $cache_id
1869
-     * @throws EE_Error
1870
-     * @return EE_Base_Class the object the relation was added to
1871
-     */
1872
-    public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = null)
1873
-    {
1874
-        //if this thing exists in the DB, save the relation to the DB
1875
-        if ($this->ID()) {
1876
-            $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values);
1877
-            //clear cache so future get_many_related and get_first_related() return new results.
1878
-            $this->clear_cache($relationName, $otherObject, true);
1879
-            if ($otherObject instanceof EE_Base_Class) {
1880
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1881
-            }
1882
-        } else {
1883
-            //this thing doesn't exist in the DB,  so just cache it
1884
-            if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
1885
-                throw new EE_Error(sprintf(
1886
-                    __('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'),
1887
-                    $otherObjectModelObjectOrID,
1888
-                    get_class($this)
1889
-                ));
1890
-            } else {
1891
-                $otherObject = $otherObjectModelObjectOrID;
1892
-            }
1893
-            $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
1894
-        }
1895
-        if ($otherObject instanceof EE_Base_Class) {
1896
-            //fix the reciprocal relation too
1897
-            if ($otherObject->ID()) {
1898
-                //its saved so assumed relations exist in the DB, so we can just
1899
-                //clear the cache so future queries use the updated info in the DB
1900
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true);
1901
-            } else {
1902
-                //it's not saved, so it caches relations like this
1903
-                $otherObject->cache($this->get_model()->get_this_model_name(), $this);
1904
-            }
1905
-        }
1906
-        return $otherObject;
1907
-    }
1908
-
1909
-
1910
-
1911
-    /**
1912
-     * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current model is related
1913
-     * to a group of events, the $relationName should be 'Events', and should be a key in the EE Model's $_model_relations array.
1914
-     * If this model object doesn't exist in the DB, just removes the related thing from the cache
1915
-     *
1916
-     * @param mixed  $otherObjectModelObjectOrID
1917
-     *                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
1918
-     * @param string $relationName
1919
-     * @param array  $where_query
1920
-     *                You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added.
1921
-     *                However, keep in mind that the columns (keys) given must match a column on the JOIN table
1922
-     *                and currently only the HABTM models accept these additional conditions.
1923
-     *                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.
1924
-     * @return EE_Base_Class the relation was removed from
1925
-     * @throws \EE_Error
1926
-     */
1927
-    public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
1928
-    {
1929
-        if ($this->ID()) {
1930
-            //if this exists in the DB, save the relation change to the DB too
1931
-            $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query);
1932
-            $this->clear_cache($relationName, $otherObject);
1933
-        } else {
1934
-            //this doesn't exist in the DB, just remove it from the cache
1935
-            $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
1936
-        }
1937
-        if ($otherObject instanceof EE_Base_Class) {
1938
-            $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1939
-        }
1940
-        return $otherObject;
1941
-    }
1942
-
1943
-
1944
-
1945
-    /**
1946
-     * Removes ALL the related things for the $relationName.
1947
-     *
1948
-     * @param string $relationName
1949
-     * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
1950
-     * @return EE_Base_Class
1951
-     * @throws \EE_Error
1952
-     */
1953
-    public function _remove_relations($relationName, $where_query_params = array())
1954
-    {
1955
-        if ($this->ID()) {
1956
-            //if this exists in the DB, save the relation change to the DB too
1957
-            $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
1958
-            $this->clear_cache($relationName, null, true);
1959
-        } else {
1960
-            //this doesn't exist in the DB, just remove it from the cache
1961
-            $otherObjects = $this->clear_cache($relationName, null, true);
1962
-        }
1963
-        if (is_array($otherObjects)) {
1964
-            foreach ($otherObjects as $otherObject) {
1965
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1966
-            }
1967
-        }
1968
-        return $otherObjects;
1969
-    }
1970
-
1971
-
1972
-
1973
-    /**
1974
-     * Gets all the related model objects of the specified type. Eg, if the current class if
1975
-     * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
1976
-     * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
1977
-     * because we want to get even deleted items etc.
1978
-     *
1979
-     * @param string $relationName key in the model's _model_relations array
1980
-     * @param array  $query_params like EEM_Base::get_all
1981
-     * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
1982
-     * @throws \EE_Error
1983
-     *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs
1984
-     */
1985
-    public function get_many_related($relationName, $query_params = array())
1986
-    {
1987
-        if ($this->ID()) {
1988
-            //this exists in the DB, so get the related things from either the cache or the DB
1989
-            //if there are query parameters, forget about caching the related model objects.
1990
-            if ($query_params) {
1991
-                $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1992
-            } else {
1993
-                //did we already cache the result of this query?
1994
-                $cached_results = $this->get_all_from_cache($relationName);
1995
-                if ( ! $cached_results) {
1996
-                    $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1997
-                    //if no query parameters were passed, then we got all the related model objects
1998
-                    //for that relation. We can cache them then.
1999
-                    foreach ($related_model_objects as $related_model_object) {
2000
-                        $this->cache($relationName, $related_model_object);
2001
-                    }
2002
-                } else {
2003
-                    $related_model_objects = $cached_results;
2004
-                }
2005
-            }
2006
-        } else {
2007
-            //this doesn't exist in the DB, so just get the related things from the cache
2008
-            $related_model_objects = $this->get_all_from_cache($relationName);
2009
-        }
2010
-        return $related_model_objects;
2011
-    }
2012
-
2013
-
2014
-
2015
-    /**
2016
-     * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2017
-     * unless otherwise specified in the $query_params
2018
-     *
2019
-     * @param string $relation_name  model_name like 'Event', or 'Registration'
2020
-     * @param array  $query_params   like EEM_Base::get_all's
2021
-     * @param string $field_to_count name of field to count by. By default, uses primary key
2022
-     * @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;
2023
-     * @return int
2024
-     */
2025
-    public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2026
-    {
2027
-        return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2028
-    }
2029
-
2030
-
2031
-
2032
-    /**
2033
-     * Instead of getting the related model objects, simply sums up the values of the specified field.
2034
-     * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2035
-     *
2036
-     * @param string $relation_name model_name like 'Event', or 'Registration'
2037
-     * @param array  $query_params  like EEM_Base::get_all's
2038
-     * @param string $field_to_sum  name of field to count by.
2039
-     *                              By default, uses primary key (which doesn't make much sense, so you should probably change it)
2040
-     * @return int
2041
-     */
2042
-    public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2043
-    {
2044
-        return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2045
-    }
2046
-
2047
-
2048
-
2049
-    /**
2050
-     * Gets the first (ie, one) related model object of the specified type.
2051
-     *
2052
-     * @param string $relationName key in the model's _model_relations array
2053
-     * @param array  $query_params like EEM_Base::get_all
2054
-     * @return EE_Base_Class (not an array, a single object)
2055
-     * @throws \EE_Error
2056
-     */
2057
-    public function get_first_related($relationName, $query_params = array())
2058
-    {
2059
-        if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2060
-            //if they've provided some query parameters, don't bother trying to cache the result
2061
-            //also make sure we're not caching the result of get_first_related
2062
-            //on a relation which should have an array of objects (because the cache might have an array of objects)
2063
-            if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2064
-                $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2065
-            } else {
2066
-                //first, check if we've already cached the result of this query
2067
-                $cached_result = $this->get_one_from_cache($relationName);
2068
-                if ( ! $cached_result) {
2069
-                    $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2070
-                    $this->cache($relationName, $related_model_object);
2071
-                } else {
2072
-                    $related_model_object = $cached_result;
2073
-                }
2074
-            }
2075
-        } else {
2076
-            $related_model_object = null;
2077
-            //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2078
-            if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2079
-                $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2080
-            }
2081
-            //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
2082
-            if ( ! $related_model_object) {
2083
-                $related_model_object = $this->get_one_from_cache($relationName);
2084
-            }
2085
-        }
2086
-        return $related_model_object;
2087
-    }
2088
-
2089
-
2090
-
2091
-    /**
2092
-     * Does a delete on all related objects of type $relationName and removes
2093
-     * the current model object's relation to them. If they can't be deleted (because
2094
-     * of blocking related model objects) does nothing. If the related model objects are
2095
-     * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2096
-     * If this model object doesn't exist yet in the DB, just removes its related things
2097
-     *
2098
-     * @param string $relationName
2099
-     * @param array  $query_params like EEM_Base::get_all's
2100
-     * @return int how many deleted
2101
-     * @throws \EE_Error
2102
-     */
2103
-    public function delete_related($relationName, $query_params = array())
2104
-    {
2105
-        if ($this->ID()) {
2106
-            $count = $this->get_model()->delete_related($this, $relationName, $query_params);
2107
-        } else {
2108
-            $count = count($this->get_all_from_cache($relationName));
2109
-            $this->clear_cache($relationName, null, true);
2110
-        }
2111
-        return $count;
2112
-    }
2113
-
2114
-
2115
-
2116
-    /**
2117
-     * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2118
-     * the current model object's relation to them. If they can't be deleted (because
2119
-     * of blocking related model objects) just does a soft delete on it instead, if possible.
2120
-     * If the related thing isn't a soft-deletable model object, this function is identical
2121
-     * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2122
-     *
2123
-     * @param string $relationName
2124
-     * @param array  $query_params like EEM_Base::get_all's
2125
-     * @return int how many deleted (including those soft deleted)
2126
-     * @throws \EE_Error
2127
-     */
2128
-    public function delete_related_permanently($relationName, $query_params = array())
2129
-    {
2130
-        if ($this->ID()) {
2131
-            $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2132
-        } else {
2133
-            $count = count($this->get_all_from_cache($relationName));
2134
-        }
2135
-        $this->clear_cache($relationName, null, true);
2136
-        return $count;
2137
-    }
2138
-
2139
-
2140
-
2141
-    /**
2142
-     * is_set
2143
-     * Just a simple utility function children can use for checking if property exists
2144
-     *
2145
-     * @access  public
2146
-     * @param  string $field_name property to check
2147
-     * @return bool                              TRUE if existing,FALSE if not.
2148
-     */
2149
-    public function is_set($field_name)
2150
-    {
2151
-        return isset($this->_fields[$field_name]);
2152
-    }
2153
-
2154
-
2155
-
2156
-    /**
2157
-     * 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
2158
-     *
2159
-     * @param  mixed (string|array) $properties properties to check
2160
-     * @throws EE_Error
2161
-     * @return bool                              TRUE if existing, throw EE_Error if not.
2162
-     */
2163
-    protected function _property_exists($properties)
2164
-    {
2165
-        foreach ((array)$properties as $property_name) {
2166
-            //first make sure this property exists
2167
-            if ( ! $this->_fields[$property_name]) {
2168
-                throw new EE_Error(
2169
-                    sprintf(
2170
-                        __(
2171
-                            'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2172
-                            'event_espresso'
2173
-                        ),
2174
-                        $property_name
2175
-                    )
2176
-                );
2177
-            }
2178
-        }
2179
-        return true;
2180
-    }
2181
-
2182
-
2183
-
2184
-    /**
2185
-     * This simply returns an array of model fields for this object
2186
-     *
2187
-     * @return array
2188
-     * @throws \EE_Error
2189
-     */
2190
-    public function model_field_array()
2191
-    {
2192
-        $fields = $this->get_model()->field_settings(false);
2193
-        $properties = array();
2194
-        //remove prepended underscore
2195
-        foreach ($fields as $field_name => $settings) {
2196
-            $properties[$field_name] = $this->get($field_name);
2197
-        }
2198
-        return $properties;
2199
-    }
2200
-
2201
-
2202
-
2203
-    /**
2204
-     * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2205
-     * 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)
2206
-     * and passed the method's name and arguments.
2207
-     * 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?)
2208
-     * they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, filters_hook_espresso__EE_Answer__my_great_function)
2209
-     * 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.
2210
-     * Example: in functions.php (or in a plugin):
2211
-     * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3);
2212
-     * function my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2213
-     * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2214
-     *        return $previousReturnValue.$returnString;
2215
-     * }
2216
-     * require('EE_Answer.class.php');
2217
-     * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2218
-     * echo $answer->my_callback('monkeys',100);
2219
-     * //will output "you called my_callback! and passed args:monkeys,100"
2220
-     *
2221
-     * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2222
-     * @param array  $args       array of original arguments passed to the function
2223
-     * @throws EE_Error
2224
-     * @return mixed whatever the plugin which calls add_filter decides
2225
-     */
2226
-    public function __call($methodName, $args)
2227
-    {
2228
-        $className = get_class($this);
2229
-        $tagName = "FHEE__{$className}__{$methodName}";
2230
-        if ( ! has_filter($tagName)) {
2231
-            throw new EE_Error(
2232
-                sprintf(
2233
-                    __(
2234
-                        "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;}",
2235
-                        "event_espresso"
2236
-                    ),
2237
-                    $methodName,
2238
-                    $className,
2239
-                    $tagName
2240
-                )
2241
-            );
2242
-        }
2243
-        return apply_filters($tagName, null, $this, $args);
2244
-    }
2245
-
2246
-
2247
-
2248
-    /**
2249
-     * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2250
-     * A $previous_value can be specified in case there are many meta rows with the same key
2251
-     *
2252
-     * @param string $meta_key
2253
-     * @param string $meta_value
2254
-     * @param string $previous_value
2255
-     * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2256
-     * @throws \EE_Error
2257
-     * NOTE: if the values haven't changed, returns 0
2258
-     */
2259
-    public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2260
-    {
2261
-        $query_params = array(
2262
-            array(
2263
-                'EXM_key'  => $meta_key,
2264
-                'OBJ_ID'   => $this->ID(),
2265
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2266
-            ),
2267
-        );
2268
-        if ($previous_value !== null) {
2269
-            $query_params[0]['EXM_value'] = $meta_value;
2270
-        }
2271
-        $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2272
-        if ( ! $existing_rows_like_that) {
2273
-            return $this->add_extra_meta($meta_key, $meta_value);
2274
-        } else {
2275
-            foreach ($existing_rows_like_that as $existing_row) {
2276
-                $existing_row->save(array('EXM_value' => $meta_value));
2277
-            }
2278
-            return count($existing_rows_like_that);
2279
-        }
2280
-    }
2281
-
2282
-
2283
-
2284
-    /**
2285
-     * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2286
-     * no other extra meta for this model object have the same key. Returns TRUE if the
2287
-     * extra meta row was entered, false if not
2288
-     *
2289
-     * @param string  $meta_key
2290
-     * @param string  $meta_value
2291
-     * @param boolean $unique
2292
-     * @return boolean
2293
-     * @throws \EE_Error
2294
-     */
2295
-    public function add_extra_meta($meta_key, $meta_value, $unique = false)
2296
-    {
2297
-        if ($unique) {
2298
-            $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2299
-                array(
2300
-                    array(
2301
-                        'EXM_key'  => $meta_key,
2302
-                        'OBJ_ID'   => $this->ID(),
2303
-                        'EXM_type' => $this->get_model()->get_this_model_name(),
2304
-                    ),
2305
-                )
2306
-            );
2307
-            if ($existing_extra_meta) {
2308
-                return false;
2309
-            }
2310
-        }
2311
-        $new_extra_meta = EE_Extra_Meta::new_instance(
2312
-            array(
2313
-                'EXM_key'   => $meta_key,
2314
-                'EXM_value' => $meta_value,
2315
-                'OBJ_ID'    => $this->ID(),
2316
-                'EXM_type'  => $this->get_model()->get_this_model_name(),
2317
-            )
2318
-        );
2319
-        $new_extra_meta->save();
2320
-        return true;
2321
-    }
2322
-
2323
-
2324
-
2325
-    /**
2326
-     * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2327
-     * is specified, only deletes extra meta records with that value.
2328
-     *
2329
-     * @param string $meta_key
2330
-     * @param string $meta_value
2331
-     * @return int number of extra meta rows deleted
2332
-     * @throws \EE_Error
2333
-     */
2334
-    public function delete_extra_meta($meta_key, $meta_value = null)
2335
-    {
2336
-        $query_params = array(
2337
-            array(
2338
-                'EXM_key'  => $meta_key,
2339
-                'OBJ_ID'   => $this->ID(),
2340
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2341
-            ),
2342
-        );
2343
-        if ($meta_value !== null) {
2344
-            $query_params[0]['EXM_value'] = $meta_value;
2345
-        }
2346
-        return EEM_Extra_Meta::instance()->delete($query_params);
2347
-    }
2348
-
2349
-
2350
-
2351
-    /**
2352
-     * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2353
-     * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2354
-     * You can specify $default is case you haven't found the extra meta
2355
-     *
2356
-     * @param string  $meta_key
2357
-     * @param boolean $single
2358
-     * @param mixed   $default if we don't find anything, what should we return?
2359
-     * @return mixed single value if $single; array if ! $single
2360
-     * @throws \EE_Error
2361
-     */
2362
-    public function get_extra_meta($meta_key, $single = false, $default = null)
2363
-    {
2364
-        if ($single) {
2365
-            $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2366
-            if ($result instanceof EE_Extra_Meta) {
2367
-                return $result->value();
2368
-            } else {
2369
-                return $default;
2370
-            }
2371
-        } else {
2372
-            $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2373
-            if ($results) {
2374
-                $values = array();
2375
-                foreach ($results as $result) {
2376
-                    if ($result instanceof EE_Extra_Meta) {
2377
-                        $values[$result->ID()] = $result->value();
2378
-                    }
2379
-                }
2380
-                return $values;
2381
-            } else {
2382
-                return $default;
2383
-            }
2384
-        }
2385
-    }
2386
-
2387
-
2388
-
2389
-    /**
2390
-     * Returns a simple array of all the extra meta associated with this model object.
2391
-     * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2392
-     * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2393
-     * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2394
-     * If $one_of_each_key is false, it will return an array with the top-level keys being
2395
-     * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2396
-     * finally the extra meta's value as each sub-value. (eg array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2397
-     *
2398
-     * @param boolean $one_of_each_key
2399
-     * @return array
2400
-     * @throws \EE_Error
2401
-     */
2402
-    public function all_extra_meta_array($one_of_each_key = true)
2403
-    {
2404
-        $return_array = array();
2405
-        if ($one_of_each_key) {
2406
-            $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2407
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2408
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2409
-                    $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2410
-                }
2411
-            }
2412
-        } else {
2413
-            $extra_meta_objs = $this->get_many_related('Extra_Meta');
2414
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2415
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2416
-                    if ( ! isset($return_array[$extra_meta_obj->key()])) {
2417
-                        $return_array[$extra_meta_obj->key()] = array();
2418
-                    }
2419
-                    $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2420
-                }
2421
-            }
2422
-        }
2423
-        return $return_array;
2424
-    }
2425
-
2426
-
2427
-
2428
-    /**
2429
-     * Gets a pretty nice displayable nice for this model object. Often overridden
2430
-     *
2431
-     * @return string
2432
-     * @throws \EE_Error
2433
-     */
2434
-    public function name()
2435
-    {
2436
-        //find a field that's not a text field
2437
-        $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2438
-        if ($field_we_can_use) {
2439
-            return $this->get($field_we_can_use->get_name());
2440
-        } else {
2441
-            $first_few_properties = $this->model_field_array();
2442
-            $first_few_properties = array_slice($first_few_properties, 0, 3);
2443
-            $name_parts = array();
2444
-            foreach ($first_few_properties as $name => $value) {
2445
-                $name_parts[] = "$name:$value";
2446
-            }
2447
-            return implode(",", $name_parts);
2448
-        }
2449
-    }
2450
-
2451
-
2452
-
2453
-    /**
2454
-     * in_entity_map
2455
-     * Checks if this model object has been proven to already be in the entity map
2456
-     *
2457
-     * @return boolean
2458
-     * @throws \EE_Error
2459
-     */
2460
-    public function in_entity_map()
2461
-    {
2462
-        if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2463
-            //well, if we looked, did we find it in the entity map?
2464
-            return true;
2465
-        } else {
2466
-            return false;
2467
-        }
2468
-    }
2469
-
2470
-
2471
-
2472
-    /**
2473
-     * refresh_from_db
2474
-     * Makes sure the fields and values on this model object are in-sync with what's in the database.
2475
-     *
2476
-     * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2477
-     * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2478
-     */
2479
-    public function refresh_from_db()
2480
-    {
2481
-        if ($this->ID() && $this->in_entity_map()) {
2482
-            $this->get_model()->refresh_entity_map_from_db($this->ID());
2483
-        } else {
2484
-            //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2485
-            //if it has an ID but it's not in the map, and you're asking me to refresh it
2486
-            //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2487
-            //absolutely nothing in it for this ID
2488
-            if (WP_DEBUG) {
2489
-                throw new EE_Error(
2490
-                    sprintf(
2491
-                        __('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.',
2492
-                            'event_espresso'),
2493
-                        $this->ID(),
2494
-                        get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2495
-                        get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2496
-                    )
2497
-                );
2498
-            }
2499
-        }
2500
-    }
2501
-
2502
-
2503
-
2504
-    /**
2505
-     * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2506
-     * (probably a bad assumption they have made, oh well)
2507
-     *
2508
-     * @return string
2509
-     */
2510
-    public function __toString()
2511
-    {
2512
-        try {
2513
-            return sprintf('%s (%s)', $this->name(), $this->ID());
2514
-        } catch (Exception $e) {
2515
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2516
-            return '';
2517
-        }
2518
-    }
2519
-
2520
-
2521
-
2522
-    /**
2523
-     * Clear related model objects if they're already in the DB, because otherwise when we
2524
-     * UN-serialize this model object we'll need to be careful to add them to the entity map.
2525
-     * This means if we have made changes to those related model objects, and want to unserialize
2526
-     * the this model object on a subsequent request, changes to those related model objects will be lost.
2527
-     * Instead, those related model objects should be directly serialized and stored.
2528
-     * Eg, the following won't work:
2529
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2530
-     * $att = $reg->attendee();
2531
-     * $att->set( 'ATT_fname', 'Dirk' );
2532
-     * update_option( 'my_option', serialize( $reg ) );
2533
-     * //END REQUEST
2534
-     * //START NEXT REQUEST
2535
-     * $reg = get_option( 'my_option' );
2536
-     * $reg->attendee()->save();
2537
-     * And would need to be replace with:
2538
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2539
-     * $att = $reg->attendee();
2540
-     * $att->set( 'ATT_fname', 'Dirk' );
2541
-     * update_option( 'my_option', serialize( $reg ) );
2542
-     * //END REQUEST
2543
-     * //START NEXT REQUEST
2544
-     * $att = get_option( 'my_option' );
2545
-     * $att->save();
2546
-     *
2547
-     * @return array
2548
-     * @throws \EE_Error
2549
-     */
2550
-    public function __sleep()
2551
-    {
2552
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2553
-            if ($relation_obj instanceof EE_Belongs_To_Relation) {
2554
-                $classname = 'EE_' . $this->get_model()->get_this_model_name();
2555
-                if (
2556
-                    $this->get_one_from_cache($relation_name) instanceof $classname
2557
-                    && $this->get_one_from_cache($relation_name)->ID()
2558
-                ) {
2559
-                    $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2560
-                }
2561
-            }
2562
-        }
2563
-        $this->_props_n_values_provided_in_constructor = array();
2564
-        return array_keys(get_object_vars($this));
2565
-    }
2566
-
2567
-
2568
-
2569
-    /**
2570
-     * restore _props_n_values_provided_in_constructor
2571
-     * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2572
-     * and therefore should NOT be used to determine if state change has occurred since initial construction.
2573
-     * At best, you would only be able to detect if state change has occurred during THIS request.
2574
-     */
2575
-    public function __wakeup()
2576
-    {
2577
-        $this->_props_n_values_provided_in_constructor = $this->_fields;
2578
-    }
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
+			/**
555
+			 * maybe this is EE_Datetime_Field.  If so we need to make sure timezone and
556
+			 * formats are correct.
557
+			 */
558
+			if ($field_obj instanceof EE_Datetime_Field) {
559
+				$field_obj->set_timezone($this->_timezone);
560
+				$field_obj->set_date_format($this->_dt_frmt, $pretty);
561
+				$field_obj->set_time_format($this->_tm_frmt, $pretty);
562
+			}
563
+			if ( ! isset($this->_fields[$fieldname])) {
564
+				$this->_fields[$fieldname] = null;
565
+			}
566
+			$value = $pretty
567
+				? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
568
+				: $field_obj->prepare_for_get($this->_fields[$fieldname]);
569
+			$this->_set_cached_property($fieldname, $value, $cache_type);
570
+			return $value;
571
+		}
572
+		return null;
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * This just takes care of clearing out the cached_properties
579
+	 *
580
+	 * @return void
581
+	 */
582
+	protected function _clear_cached_properties()
583
+	{
584
+		$this->_cached_properties = array();
585
+	}
586
+
587
+
588
+
589
+	/**
590
+	 * This just clears out ONE property if it exists in the cache
591
+	 *
592
+	 * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
593
+	 * @return void
594
+	 */
595
+	protected function _clear_cached_property($property_name)
596
+	{
597
+		if (isset($this->_cached_properties[$property_name])) {
598
+			unset($this->_cached_properties[$property_name]);
599
+		}
600
+	}
601
+
602
+
603
+
604
+	/**
605
+	 * Ensures that this related thing is a model object.
606
+	 *
607
+	 * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
608
+	 * @param string $model_name   name of the related thing, eg 'Attendee',
609
+	 * @return EE_Base_Class
610
+	 * @throws \EE_Error
611
+	 */
612
+	protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
613
+	{
614
+		$other_model_instance = self::_get_model_instance_with_name(
615
+			self::_get_model_classname($model_name),
616
+			$this->_timezone
617
+		);
618
+		return $other_model_instance->ensure_is_obj($object_or_id);
619
+	}
620
+
621
+
622
+
623
+	/**
624
+	 * Forgets the cached model of the given relation Name. So the next time we request it,
625
+	 * we will fetch it again from the database. (Handy if you know it's changed somehow).
626
+	 * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
627
+	 * then only remove that one object from our cached array. Otherwise, clear the entire list
628
+	 *
629
+	 * @param string $relationName                         one of the keys in the _model_relations array on the model. Eg 'Registration'
630
+	 * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
631
+	 *                                                     if you intend to use $clear_all = TRUE, or the relation only has 1 object anyways (ie, it's a BelongsToRelation)
632
+	 * @param bool   $clear_all                            This flags clearing the entire cache relation property if this is HasMany or HABTM.
633
+	 * @throws EE_Error
634
+	 * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all
635
+	 */
636
+	public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
637
+	{
638
+		$relationship_to_model = $this->get_model()->related_settings_for($relationName);
639
+		$index_in_cache = '';
640
+		if ( ! $relationship_to_model) {
641
+			throw new EE_Error(
642
+				sprintf(
643
+					__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
644
+					$relationName,
645
+					get_class($this)
646
+				)
647
+			);
648
+		}
649
+		if ($clear_all) {
650
+			$obj_removed = true;
651
+			$this->_model_relations[$relationName] = null;
652
+		} elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
653
+			$obj_removed = $this->_model_relations[$relationName];
654
+			$this->_model_relations[$relationName] = null;
655
+		} else {
656
+			if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) {
657
+				$index_in_cache = $object_to_remove_or_index_into_array->ID();
658
+				if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) {
659
+					$index_found_at = null;
660
+					//find this object in the array even though it has a different key
661
+					foreach ($this->_model_relations[$relationName] as $index => $obj) {
662
+						if (
663
+							$obj instanceof EE_Base_Class
664
+							&& (
665
+								$obj == $object_to_remove_or_index_into_array
666
+								|| $obj->ID() === $object_to_remove_or_index_into_array->ID()
667
+							)
668
+						) {
669
+							$index_found_at = $index;
670
+							break;
671
+						}
672
+					}
673
+					if ($index_found_at) {
674
+						$index_in_cache = $index_found_at;
675
+					} else {
676
+						//it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
677
+						//if it wasn't in it to begin with. So we're done
678
+						return $object_to_remove_or_index_into_array;
679
+					}
680
+				}
681
+			} elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
682
+				//so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
683
+				foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
684
+					if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
685
+						$index_in_cache = $index;
686
+					}
687
+				}
688
+			} else {
689
+				$index_in_cache = $object_to_remove_or_index_into_array;
690
+			}
691
+			//supposedly we've found it. But it could just be that the client code
692
+			//provided a bad index/object
693
+			if (
694
+			isset(
695
+				$this->_model_relations[$relationName],
696
+				$this->_model_relations[$relationName][$index_in_cache]
697
+			)
698
+			) {
699
+				$obj_removed = $this->_model_relations[$relationName][$index_in_cache];
700
+				unset($this->_model_relations[$relationName][$index_in_cache]);
701
+			} else {
702
+				//that thing was never cached anyways.
703
+				$obj_removed = null;
704
+			}
705
+		}
706
+		return $obj_removed;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * update_cache_after_object_save
713
+	 * 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
714
+	 *
715
+	 * @param string         $relationName       - the type of object that is cached
716
+	 * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
717
+	 * @param string         $current_cache_id   - the ID that was used when originally caching the object
718
+	 * @return boolean TRUE on success, FALSE on fail
719
+	 * @throws \EE_Error
720
+	 */
721
+	public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '')
722
+	{
723
+		// verify that incoming object is of the correct type
724
+		$obj_class = 'EE_' . $relationName;
725
+		if ($newly_saved_object instanceof $obj_class) {
726
+			/* @type EE_Base_Class $newly_saved_object */
727
+			// now get the type of relation
728
+			$relationship_to_model = $this->get_model()->related_settings_for($relationName);
729
+			// if this is a 1:1 relationship
730
+			if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
731
+				// then just replace the cached object with the newly saved object
732
+				$this->_model_relations[$relationName] = $newly_saved_object;
733
+				return true;
734
+				// or if it's some kind of sordid feral polyamorous relationship...
735
+			} elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) {
736
+				// then remove the current cached item
737
+				unset($this->_model_relations[$relationName][$current_cache_id]);
738
+				// and cache the newly saved object using it's new ID
739
+				$this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
740
+				return true;
741
+			}
742
+		}
743
+		return false;
744
+	}
745
+
746
+
747
+
748
+	/**
749
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
750
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
751
+	 *
752
+	 * @param string $relationName
753
+	 * @return EE_Base_Class
754
+	 */
755
+	public function get_one_from_cache($relationName)
756
+	{
757
+		$cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null;
758
+		if (is_array($cached_array_or_object)) {
759
+			return array_shift($cached_array_or_object);
760
+		} else {
761
+			return $cached_array_or_object;
762
+		}
763
+	}
764
+
765
+
766
+
767
+	/**
768
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
769
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
770
+	 *
771
+	 * @param string $relationName
772
+	 * @throws \EE_Error
773
+	 * @return EE_Base_Class[] NOT necessarily indexed by primary keys
774
+	 */
775
+	public function get_all_from_cache($relationName)
776
+	{
777
+		$objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
778
+		// if the result is not an array, but exists, make it an array
779
+		$objects = is_array($objects) ? $objects : array($objects);
780
+		//bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
781
+		//basically, if this model object was stored in the session, and these cached model objects
782
+		//already have IDs, let's make sure they're in their model's entity mapper
783
+		//otherwise we will have duplicates next time we call
784
+		// EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
785
+		$model = EE_Registry::instance()->load_model($relationName);
786
+		foreach ($objects as $model_object) {
787
+			if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
788
+				//ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
789
+				if ($model_object->ID()) {
790
+					$model->add_to_entity_map($model_object);
791
+				}
792
+			} else {
793
+				throw new EE_Error(
794
+					sprintf(
795
+						__(
796
+							'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
797
+							'event_espresso'
798
+						),
799
+						$relationName,
800
+						gettype($model_object)
801
+					)
802
+				);
803
+			}
804
+		}
805
+		return $objects;
806
+	}
807
+
808
+
809
+
810
+	/**
811
+	 * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
812
+	 * matching the given query conditions.
813
+	 *
814
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
815
+	 * @param int   $limit              How many objects to return.
816
+	 * @param array $query_params       Any additional conditions on the query.
817
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
818
+	 *                                  you can indicate just the columns you want returned
819
+	 * @return array|EE_Base_Class[]
820
+	 * @throws \EE_Error
821
+	 */
822
+	public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
823
+	{
824
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
825
+			? $this->get_model()->get_primary_key_field()->get_name()
826
+			: $field_to_order_by;
827
+		$current_value = ! empty($field) ? $this->get($field) : null;
828
+		if (empty($field) || empty($current_value)) {
829
+			return array();
830
+		}
831
+		return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
832
+	}
833
+
834
+
835
+
836
+	/**
837
+	 * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
838
+	 * matching the given query conditions.
839
+	 *
840
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
841
+	 * @param int   $limit              How many objects to return.
842
+	 * @param array $query_params       Any additional conditions on the query.
843
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
844
+	 *                                  you can indicate just the columns you want returned
845
+	 * @return array|EE_Base_Class[]
846
+	 * @throws \EE_Error
847
+	 */
848
+	public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
849
+	{
850
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
851
+			? $this->get_model()->get_primary_key_field()->get_name()
852
+			: $field_to_order_by;
853
+		$current_value = ! empty($field) ? $this->get($field) : null;
854
+		if (empty($field) || empty($current_value)) {
855
+			return array();
856
+		}
857
+		return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
858
+	}
859
+
860
+
861
+
862
+	/**
863
+	 * Returns the next EE_Base_Class object in sequence from this object as found in the database
864
+	 * matching the given query conditions.
865
+	 *
866
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
867
+	 * @param array $query_params       Any additional conditions on the query.
868
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
869
+	 *                                  you can indicate just the columns you want returned
870
+	 * @return array|EE_Base_Class
871
+	 * @throws \EE_Error
872
+	 */
873
+	public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
874
+	{
875
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
876
+			? $this->get_model()->get_primary_key_field()->get_name()
877
+			: $field_to_order_by;
878
+		$current_value = ! empty($field) ? $this->get($field) : null;
879
+		if (empty($field) || empty($current_value)) {
880
+			return array();
881
+		}
882
+		return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select);
883
+	}
884
+
885
+
886
+
887
+	/**
888
+	 * Returns the previous EE_Base_Class object in sequence from this object as found in the database
889
+	 * matching the given query conditions.
890
+	 *
891
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
892
+	 * @param array $query_params       Any additional conditions on the query.
893
+	 * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
894
+	 *                                  you can indicate just the column you want returned
895
+	 * @return array|EE_Base_Class
896
+	 * @throws \EE_Error
897
+	 */
898
+	public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
899
+	{
900
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
901
+			? $this->get_model()->get_primary_key_field()->get_name()
902
+			: $field_to_order_by;
903
+		$current_value = ! empty($field) ? $this->get($field) : null;
904
+		if (empty($field) || empty($current_value)) {
905
+			return array();
906
+		}
907
+		return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select);
908
+	}
909
+
910
+
911
+
912
+	/**
913
+	 * Overrides parent because parent expects old models.
914
+	 * This also doesn't do any validation, and won't work for serialized arrays
915
+	 *
916
+	 * @param string $field_name
917
+	 * @param mixed  $field_value_from_db
918
+	 * @throws \EE_Error
919
+	 */
920
+	public function set_from_db($field_name, $field_value_from_db)
921
+	{
922
+		$field_obj = $this->get_model()->field_settings_for($field_name);
923
+		if ($field_obj instanceof EE_Model_Field_Base) {
924
+			//you would think the DB has no NULLs for non-null label fields right? wrong!
925
+			//eg, a CPT model object could have an entry in the posts table, but no
926
+			//entry in the meta table. Meaning that all its columns in the meta table
927
+			//are null! yikes! so when we find one like that, use defaults for its meta columns
928
+			if ($field_value_from_db === null) {
929
+				if ($field_obj->is_nullable()) {
930
+					//if the field allows nulls, then let it be null
931
+					$field_value = null;
932
+				} else {
933
+					$field_value = $field_obj->get_default_value();
934
+				}
935
+			} else {
936
+				$field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
937
+			}
938
+			$this->_fields[$field_name] = $field_value;
939
+			$this->_clear_cached_property($field_name);
940
+		}
941
+	}
942
+
943
+
944
+
945
+	/**
946
+	 * verifies that the specified field is of the correct type
947
+	 *
948
+	 * @param string $field_name
949
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
950
+	 *                                (in cases where the same property may be used for different outputs
951
+	 *                                - i.e. datetime, money etc.)
952
+	 * @return mixed
953
+	 * @throws \EE_Error
954
+	 */
955
+	public function get($field_name, $extra_cache_ref = null)
956
+	{
957
+		return $this->_get_cached_property($field_name, false, $extra_cache_ref);
958
+	}
959
+
960
+
961
+
962
+	/**
963
+	 * This method simply returns the RAW unprocessed value for the given property in this class
964
+	 *
965
+	 * @param  string $field_name A valid fieldname
966
+	 * @return mixed              Whatever the raw value stored on the property is.
967
+	 * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
968
+	 */
969
+	public function get_raw($field_name)
970
+	{
971
+		$field_settings = $this->get_model()->field_settings_for($field_name);
972
+		return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
973
+			? $this->_fields[$field_name]->format('U')
974
+			: $this->_fields[$field_name];
975
+	}
976
+
977
+
978
+
979
+	/**
980
+	 * This is used to return the internal DateTime object used for a field that is a
981
+	 * EE_Datetime_Field.
982
+	 *
983
+	 * @param string $field_name               The field name retrieving the DateTime object.
984
+	 * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
985
+	 * @throws \EE_Error
986
+	 *                                         an error is set and false returned.  If the field IS an
987
+	 *                                         EE_Datetime_Field and but the field value is null, then
988
+	 *                                         just null is returned (because that indicates that likely
989
+	 *                                         this field is nullable).
990
+	 */
991
+	public function get_DateTime_object($field_name)
992
+	{
993
+		$field_settings = $this->get_model()->field_settings_for($field_name);
994
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
995
+			EE_Error::add_error(
996
+				sprintf(
997
+					__(
998
+						'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
999
+						'event_espresso'
1000
+					),
1001
+					$field_name
1002
+				),
1003
+				__FILE__,
1004
+				__FUNCTION__,
1005
+				__LINE__
1006
+			);
1007
+			return false;
1008
+		}
1009
+		return $this->_fields[$field_name];
1010
+	}
1011
+
1012
+
1013
+
1014
+	/**
1015
+	 * To be used in template to immediately echo out the value, and format it for output.
1016
+	 * Eg, should call stripslashes and whatnot before echoing
1017
+	 *
1018
+	 * @param string $field_name      the name of the field as it appears in the DB
1019
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1020
+	 *                                (in cases where the same property may be used for different outputs
1021
+	 *                                - i.e. datetime, money etc.)
1022
+	 * @return void
1023
+	 * @throws \EE_Error
1024
+	 */
1025
+	public function e($field_name, $extra_cache_ref = null)
1026
+	{
1027
+		echo $this->get_pretty($field_name, $extra_cache_ref);
1028
+	}
1029
+
1030
+
1031
+
1032
+	/**
1033
+	 * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1034
+	 * can be easily used as the value of form input.
1035
+	 *
1036
+	 * @param string $field_name
1037
+	 * @return void
1038
+	 * @throws \EE_Error
1039
+	 */
1040
+	public function f($field_name)
1041
+	{
1042
+		$this->e($field_name, 'form_input');
1043
+	}
1044
+
1045
+
1046
+
1047
+	/**
1048
+	 * @param string $field_name
1049
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1050
+	 *                                (in cases where the same property may be used for different outputs
1051
+	 *                                - i.e. datetime, money etc.)
1052
+	 * @return mixed
1053
+	 * @throws \EE_Error
1054
+	 */
1055
+	public function get_pretty($field_name, $extra_cache_ref = null)
1056
+	{
1057
+		return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1058
+	}
1059
+
1060
+
1061
+
1062
+	/**
1063
+	 * This simply returns the datetime for the given field name
1064
+	 * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1065
+	 * (and the equivalent e_date, e_time, e_datetime).
1066
+	 *
1067
+	 * @access   protected
1068
+	 * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1069
+	 * @param string   $dt_frmt      valid datetime format used for date
1070
+	 *                               (if '' then we just use the default on the field,
1071
+	 *                               if NULL we use the last-used format)
1072
+	 * @param string   $tm_frmt      Same as above except this is for time format
1073
+	 * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1074
+	 * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1075
+	 * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1076
+	 *                               if field is not a valid dtt field, or void if echoing
1077
+	 * @throws \EE_Error
1078
+	 */
1079
+	protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1080
+	{
1081
+		$in_dt_frmt = $dt_frmt === '' ? $this->_dt_frmt : $dt_frmt;
1082
+		$in_tm_frmt = $tm_frmt === '' ? $this->_tm_frmt : $tm_frmt;
1083
+		//validate field for datetime and returns field settings if valid.
1084
+		$field = $this->_get_dtt_field_settings($field_name);
1085
+		//clear cached property if either formats are not null.
1086
+		if ($dt_frmt !== null || $tm_frmt !== null) {
1087
+			$this->_clear_cached_property($field_name);
1088
+			//reset format properties because they are used in get()
1089
+			$this->_dt_frmt = $in_dt_frmt;
1090
+			$this->_tm_frmt = $in_tm_frmt;
1091
+		}
1092
+		if ($echo) {
1093
+			$field->set_pretty_date_format($in_dt_frmt);
1094
+		} else {
1095
+			$field->set_date_format($in_dt_frmt);
1096
+		}
1097
+		if ($echo) {
1098
+			$field->set_pretty_time_format($in_tm_frmt);
1099
+		} else {
1100
+			$field->set_time_format($in_tm_frmt);
1101
+		}
1102
+		//set timezone in field object
1103
+		$field->set_timezone($this->_timezone);
1104
+		//set the output returned
1105
+		switch ($date_or_time) {
1106
+			case 'D' :
1107
+				$field->set_date_time_output('date');
1108
+				break;
1109
+			case 'T' :
1110
+				$field->set_date_time_output('time');
1111
+				break;
1112
+			default :
1113
+				$field->set_date_time_output();
1114
+		}
1115
+		if ($echo) {
1116
+			$this->e($field_name, $date_or_time);
1117
+			return '';
1118
+		}
1119
+		return $this->get($field_name, $date_or_time);
1120
+	}
1121
+
1122
+
1123
+
1124
+	/**
1125
+	 * 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
1126
+	 * the pretty value for dtt)
1127
+	 *
1128
+	 * @param  string $field_name name of model object datetime field holding the value
1129
+	 * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1130
+	 * @return string            datetime value formatted
1131
+	 * @throws \EE_Error
1132
+	 */
1133
+	public function get_date($field_name, $format = '')
1134
+	{
1135
+		return $this->_get_datetime($field_name, $format, null, 'D');
1136
+	}
1137
+
1138
+
1139
+
1140
+	/**
1141
+	 * @param      $field_name
1142
+	 * @param string $format
1143
+	 * @throws \EE_Error
1144
+	 */
1145
+	public function e_date($field_name, $format = '')
1146
+	{
1147
+		$this->_get_datetime($field_name, $format, null, 'D', true);
1148
+	}
1149
+
1150
+
1151
+
1152
+	/**
1153
+	 * 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
1154
+	 * the pretty value for dtt)
1155
+	 *
1156
+	 * @param  string $field_name name of model object datetime field holding the value
1157
+	 * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1158
+	 * @return string             datetime value formatted
1159
+	 * @throws \EE_Error
1160
+	 */
1161
+	public function get_time($field_name, $format = '')
1162
+	{
1163
+		return $this->_get_datetime($field_name, null, $format, 'T');
1164
+	}
1165
+
1166
+
1167
+
1168
+	/**
1169
+	 * @param      $field_name
1170
+	 * @param string $format
1171
+	 * @throws \EE_Error
1172
+	 */
1173
+	public function e_time($field_name, $format = '')
1174
+	{
1175
+		$this->_get_datetime($field_name, null, $format, 'T', true);
1176
+	}
1177
+
1178
+
1179
+
1180
+	/**
1181
+	 * 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
1182
+	 * echoes the pretty value for dtt)
1183
+	 *
1184
+	 * @param  string $field_name name of model object datetime field holding the value
1185
+	 * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1186
+	 * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1187
+	 * @return string             datetime value formatted
1188
+	 * @throws \EE_Error
1189
+	 */
1190
+	public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1191
+	{
1192
+		return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1193
+	}
1194
+
1195
+
1196
+
1197
+	/**
1198
+	 * @param string $field_name
1199
+	 * @param string $dt_frmt
1200
+	 * @param string $tm_frmt
1201
+	 * @throws \EE_Error
1202
+	 */
1203
+	public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1204
+	{
1205
+		$this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1206
+	}
1207
+
1208
+
1209
+
1210
+	/**
1211
+	 * Get the i8ln value for a date using the WordPress @see date_i18n function.
1212
+	 *
1213
+	 * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1214
+	 * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format on the object will be used.
1215
+	 * @return string Date and time string in set locale or false if no field exists for the given
1216
+	 * @throws \EE_Error
1217
+	 *                           field name.
1218
+	 */
1219
+	public function get_i18n_datetime($field_name, $format = '')
1220
+	{
1221
+		$format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1222
+		return date_i18n(
1223
+			$format,
1224
+			EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1225
+		);
1226
+	}
1227
+
1228
+
1229
+
1230
+	/**
1231
+	 * 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.
1232
+	 *
1233
+	 * @param  string $field_name The field name being checked
1234
+	 * @throws EE_Error
1235
+	 * @return EE_Datetime_Field
1236
+	 */
1237
+	protected function _get_dtt_field_settings($field_name)
1238
+	{
1239
+		$field = $this->get_model()->field_settings_for($field_name);
1240
+		//check if field is dtt
1241
+		if ($field instanceof EE_Datetime_Field) {
1242
+			return $field;
1243
+		} else {
1244
+			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',
1245
+				'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1246
+		}
1247
+	}
1248
+
1249
+
1250
+
1251
+
1252
+	/**
1253
+	 * NOTE ABOUT BELOW:
1254
+	 * 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).
1255
+	 * 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.
1256
+	 */
1257
+	/**
1258
+	 * sets the time on a datetime property
1259
+	 *
1260
+	 * @access protected
1261
+	 * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1262
+	 * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1263
+	 * @throws \EE_Error
1264
+	 */
1265
+	protected function _set_time_for($time, $fieldname)
1266
+	{
1267
+		$this->_set_date_time('T', $time, $fieldname);
1268
+	}
1269
+
1270
+
1271
+
1272
+	/**
1273
+	 * sets the date on a datetime property
1274
+	 *
1275
+	 * @access protected
1276
+	 * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1277
+	 * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1278
+	 * @throws \EE_Error
1279
+	 */
1280
+	protected function _set_date_for($date, $fieldname)
1281
+	{
1282
+		$this->_set_date_time('D', $date, $fieldname);
1283
+	}
1284
+
1285
+
1286
+
1287
+	/**
1288
+	 * 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
1289
+	 *
1290
+	 * @access protected
1291
+	 * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1292
+	 * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1293
+	 * @param string          $fieldname      the name of the field the date OR time is being set on (must match a EE_Datetime_Field property)
1294
+	 * @throws \EE_Error
1295
+	 */
1296
+	protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1297
+	{
1298
+		$field = $this->_get_dtt_field_settings($fieldname);
1299
+		$field->set_timezone($this->_timezone);
1300
+		$field->set_date_format($this->_dt_frmt);
1301
+		$field->set_time_format($this->_tm_frmt);
1302
+		switch ($what) {
1303
+			case 'T' :
1304
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1305
+					$datetime_value,
1306
+					$this->_fields[$fieldname]
1307
+				);
1308
+				break;
1309
+			case 'D' :
1310
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1311
+					$datetime_value,
1312
+					$this->_fields[$fieldname]
1313
+				);
1314
+				break;
1315
+			case 'B' :
1316
+				$this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1317
+				break;
1318
+		}
1319
+		$this->_clear_cached_property($fieldname);
1320
+	}
1321
+
1322
+
1323
+
1324
+	/**
1325
+	 * 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.
1326
+	 * 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!
1327
+	 *
1328
+	 * @access public
1329
+	 * @param string               $field_name This is the name of the field on the object that contains the date/time value being returned.
1330
+	 * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1331
+	 * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1332
+	 * @param string               $prepend    You can include something to prepend on the timestamp
1333
+	 * @param string               $append     You can include something to append on the timestamp
1334
+	 * @throws EE_Error
1335
+	 * @return string timestamp
1336
+	 */
1337
+	public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = null, $prepend = '', $append = '')
1338
+	{
1339
+		$timezone = EEH_DTT_Helper::get_timezone();
1340
+		if ($timezone === $this->_timezone) {
1341
+			return '';
1342
+		}
1343
+		$original_timezone = $this->_timezone;
1344
+		$this->set_timezone($timezone);
1345
+		$fn = (array)$field_name;
1346
+		$args = array_merge($fn, (array)$args);
1347
+		if ( ! method_exists($this, $callback)) {
1348
+			throw new EE_Error(
1349
+				sprintf(
1350
+					__(
1351
+						'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1352
+						'event_espresso'
1353
+					),
1354
+					$callback
1355
+				)
1356
+			);
1357
+		}
1358
+		$args = (array)$args;
1359
+		$return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1360
+		$this->set_timezone($original_timezone);
1361
+		return $return;
1362
+	}
1363
+
1364
+
1365
+
1366
+	/**
1367
+	 * Deletes this model object.
1368
+	 * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should override
1369
+	 * `EE_Base_Class::_delete` NOT this class.
1370
+	 *
1371
+	 * @return boolean | int
1372
+	 * @throws \EE_Error
1373
+	 */
1374
+	public function delete()
1375
+	{
1376
+		/**
1377
+		 * Called just before the `EE_Base_Class::_delete` method call.
1378
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1379
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1380
+		 * soft deletes (trash) the object and does not permanently delete it.
1381
+		 *
1382
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1383
+		 */
1384
+		do_action('AHEE__EE_Base_Class__delete__before', $this);
1385
+		$result = $this->_delete();
1386
+		/**
1387
+		 * Called just after the `EE_Base_Class::_delete` method call.
1388
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1389
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1390
+		 * soft deletes (trash) the object and does not permanently delete it.
1391
+		 *
1392
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1393
+		 * @param boolean       $result
1394
+		 */
1395
+		do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1396
+		return $result;
1397
+	}
1398
+
1399
+
1400
+
1401
+	/**
1402
+	 * Calls the specific delete method for the instantiated class.
1403
+	 * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override default
1404
+	 * functionality for "delete" (which is to call `permanently_delete`) should override this method NOT `EE_Base_Class::delete`
1405
+	 *
1406
+	 * @return bool|int
1407
+	 * @throws \EE_Error
1408
+	 */
1409
+	protected function _delete()
1410
+	{
1411
+		return $this->delete_permanently();
1412
+	}
1413
+
1414
+
1415
+
1416
+	/**
1417
+	 * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error)
1418
+	 *
1419
+	 * @return bool | int
1420
+	 * @throws \EE_Error
1421
+	 */
1422
+	public function delete_permanently()
1423
+	{
1424
+		/**
1425
+		 * Called just before HARD deleting a model object
1426
+		 *
1427
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1428
+		 */
1429
+		do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1430
+		$model = $this->get_model();
1431
+		$result = $model->delete_permanently_by_ID($this->ID());
1432
+		$this->refresh_cache_of_related_objects();
1433
+		/**
1434
+		 * Called just after HARD deleting a model object
1435
+		 *
1436
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1437
+		 * @param boolean       $result
1438
+		 */
1439
+		do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1440
+		return $result;
1441
+	}
1442
+
1443
+
1444
+
1445
+	/**
1446
+	 * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1447
+	 * related model objects
1448
+	 *
1449
+	 * @throws \EE_Error
1450
+	 */
1451
+	public function refresh_cache_of_related_objects()
1452
+	{
1453
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1454
+			if ( ! empty($this->_model_relations[$relation_name])) {
1455
+				$related_objects = $this->_model_relations[$relation_name];
1456
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
1457
+					//this relation only stores a single model object, not an array
1458
+					//but let's make it consistent
1459
+					$related_objects = array($related_objects);
1460
+				}
1461
+				foreach ($related_objects as $related_object) {
1462
+					//only refresh their cache if they're in memory
1463
+					if ($related_object instanceof EE_Base_Class) {
1464
+						$related_object->clear_cache($this->get_model()->get_this_model_name(), $this);
1465
+					}
1466
+				}
1467
+			}
1468
+		}
1469
+	}
1470
+
1471
+
1472
+
1473
+	/**
1474
+	 *        Saves this object to the database. An array may be supplied to set some values on this
1475
+	 * object just before saving.
1476
+	 *
1477
+	 * @access public
1478
+	 * @param array $set_cols_n_values keys are field names, values are their new values,
1479
+	 *                                 if provided during the save() method (often client code will change the fields' values before calling save)
1480
+	 * @throws \EE_Error
1481
+	 * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1482
+	 *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1483
+	 */
1484
+	public function save($set_cols_n_values = array())
1485
+	{
1486
+		/**
1487
+		 * Filters the fields we're about to save on the model object
1488
+		 *
1489
+		 * @param array         $set_cols_n_values
1490
+		 * @param EE_Base_Class $model_object
1491
+		 */
1492
+		$set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this);
1493
+		//set attributes as provided in $set_cols_n_values
1494
+		foreach ($set_cols_n_values as $column => $value) {
1495
+			$this->set($column, $value);
1496
+		}
1497
+		/**
1498
+		 * Saving a model object.
1499
+		 * Before we perform a save, this action is fired.
1500
+		 *
1501
+		 * @param EE_Base_Class $model_object the model object about to be saved.
1502
+		 */
1503
+		do_action('AHEE__EE_Base_Class__save__begin', $this);
1504
+		if ( ! $this->allow_persist()) {
1505
+			return 0;
1506
+		}
1507
+		//now get current attribute values
1508
+		$save_cols_n_values = $this->_fields;
1509
+		//if the object already has an ID, update it. Otherwise, insert it
1510
+		//also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1511
+		$old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object();
1512
+		$this->get_model()->assume_values_already_prepared_by_model_object(true);
1513
+		//does this model have an autoincrement PK?
1514
+		if ($this->get_model()->has_primary_key_field()) {
1515
+			if ($this->get_model()->get_primary_key_field()->is_auto_increment()) {
1516
+				//ok check if it's set, if so: update; if not, insert
1517
+				if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) {
1518
+					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1519
+				} else {
1520
+					unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]);
1521
+					$results = $this->get_model()->insert($save_cols_n_values);
1522
+					if ($results) {
1523
+						//if successful, set the primary key
1524
+						//but don't use the normal SET method, because it will check if
1525
+						//an item with the same ID exists in the mapper & db, then
1526
+						//will find it in the db (because we just added it) and THAT object
1527
+						//will get added to the mapper before we can add this one!
1528
+						//but if we just avoid using the SET method, all that headache can be avoided
1529
+						$pk_field_name = self::_get_primary_key_name(get_class($this));
1530
+						$this->_fields[$pk_field_name] = $results;
1531
+						$this->_clear_cached_property($pk_field_name);
1532
+						$this->get_model()->add_to_entity_map($this);
1533
+						$this->_update_cached_related_model_objs_fks();
1534
+					}
1535
+				}
1536
+			} else {//PK is NOT auto-increment
1537
+				//so check if one like it already exists in the db
1538
+				if ($this->get_model()->exists_by_ID($this->ID())) {
1539
+					if (WP_DEBUG && ! $this->in_entity_map()) {
1540
+						throw new EE_Error(
1541
+							sprintf(
1542
+								__('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',
1543
+									'event_espresso'),
1544
+								get_class($this),
1545
+								get_class($this->get_model()) . '::instance()->add_to_entity_map()',
1546
+								get_class($this->get_model()) . '::instance()->get_one_by_ID()',
1547
+								'<br />'
1548
+							)
1549
+						);
1550
+					}
1551
+					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1552
+				} else {
1553
+					$results = $this->get_model()->insert($save_cols_n_values);
1554
+					$this->_update_cached_related_model_objs_fks();
1555
+				}
1556
+			}
1557
+		} else {//there is NO primary key
1558
+			$already_in_db = false;
1559
+			foreach ($this->get_model()->unique_indexes() as $index) {
1560
+				$uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1561
+				if ($this->get_model()->exists(array($uniqueness_where_params))) {
1562
+					$already_in_db = true;
1563
+				}
1564
+			}
1565
+			if ($already_in_db) {
1566
+				$combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields());
1567
+				$results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values);
1568
+			} else {
1569
+				$results = $this->get_model()->insert($save_cols_n_values);
1570
+			}
1571
+		}
1572
+		//restore the old assumption about values being prepared by the model object
1573
+		$this->get_model()->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1574
+		/**
1575
+		 * After saving the model object this action is called
1576
+		 *
1577
+		 * @param EE_Base_Class $model_object which was just saved
1578
+		 * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1579
+		 *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1580
+		 */
1581
+		do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1582
+		return $results;
1583
+	}
1584
+
1585
+
1586
+
1587
+	/**
1588
+	 * Updates the foreign key on related models objects pointing to this to have this model object's ID
1589
+	 * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB is consistent)
1590
+	 * Especially useful in case we JUST added this model object ot the database
1591
+	 * 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
1592
+	 * 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)
1593
+	 *
1594
+	 * @return void
1595
+	 * @throws \EE_Error
1596
+	 */
1597
+	protected function _update_cached_related_model_objs_fks()
1598
+	{
1599
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1600
+			if ($relation_obj instanceof EE_Has_Many_Relation) {
1601
+				foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1602
+					$fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1603
+						$this->get_model()->get_this_model_name()
1604
+					);
1605
+					$related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1606
+					if ($related_model_obj_in_cache->ID()) {
1607
+						$related_model_obj_in_cache->save();
1608
+					}
1609
+				}
1610
+			}
1611
+		}
1612
+	}
1613
+
1614
+
1615
+
1616
+	/**
1617
+	 * Saves this model object and its NEW cached relations to the database.
1618
+	 * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1619
+	 * In order for that to work, we would need to mark model objects as dirty/clean...
1620
+	 * because otherwise, there's a potential for infinite looping of saving
1621
+	 * Saves the cached related model objects, and ensures the relation between them
1622
+	 * and this object and properly setup
1623
+	 *
1624
+	 * @return int ID of new model object on save; 0 on failure+
1625
+	 * @throws \EE_Error
1626
+	 */
1627
+	public function save_new_cached_related_model_objs()
1628
+	{
1629
+		//make sure this has been saved
1630
+		if ( ! $this->ID()) {
1631
+			$id = $this->save();
1632
+		} else {
1633
+			$id = $this->ID();
1634
+		}
1635
+		//now save all the NEW cached model objects  (ie they don't exist in the DB)
1636
+		foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1637
+			if ($this->_model_relations[$relationName]) {
1638
+				//is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1639
+				//or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1640
+				if ($relationObj instanceof EE_Belongs_To_Relation) {
1641
+					//add a relation to that relation type (which saves the appropriate thing in the process)
1642
+					//but ONLY if it DOES NOT exist in the DB
1643
+					/* @var $related_model_obj EE_Base_Class */
1644
+					$related_model_obj = $this->_model_relations[$relationName];
1645
+					//					if( ! $related_model_obj->ID()){
1646
+					$this->_add_relation_to($related_model_obj, $relationName);
1647
+					$related_model_obj->save_new_cached_related_model_objs();
1648
+					//					}
1649
+				} else {
1650
+					foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1651
+						//add a relation to that relation type (which saves the appropriate thing in the process)
1652
+						//but ONLY if it DOES NOT exist in the DB
1653
+						//						if( ! $related_model_obj->ID()){
1654
+						$this->_add_relation_to($related_model_obj, $relationName);
1655
+						$related_model_obj->save_new_cached_related_model_objs();
1656
+						//						}
1657
+					}
1658
+				}
1659
+			}
1660
+		}
1661
+		return $id;
1662
+	}
1663
+
1664
+
1665
+
1666
+	/**
1667
+	 * for getting a model while instantiated.
1668
+	 *
1669
+	 * @return \EEM_Base | \EEM_CPT_Base
1670
+	 */
1671
+	public function get_model()
1672
+	{
1673
+		$modelName = self::_get_model_classname(get_class($this));
1674
+		return self::_get_model_instance_with_name($modelName, $this->_timezone);
1675
+	}
1676
+
1677
+
1678
+
1679
+	/**
1680
+	 * @param $props_n_values
1681
+	 * @param $classname
1682
+	 * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1683
+	 * @throws \EE_Error
1684
+	 */
1685
+	protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1686
+	{
1687
+		//TODO: will not work for Term_Relationships because they have no PK!
1688
+		$primary_id_ref = self::_get_primary_key_name($classname);
1689
+		if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1690
+			$id = $props_n_values[$primary_id_ref];
1691
+			return self::_get_model($classname)->get_from_entity_map($id);
1692
+		}
1693
+		return false;
1694
+	}
1695
+
1696
+
1697
+
1698
+	/**
1699
+	 * 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).
1700
+	 * 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.
1701
+	 *
1702
+	 * @param  array  $props_n_values   incoming array of properties and their values
1703
+	 * @param  string $classname        the classname of the child class
1704
+	 * @param null    $timezone
1705
+	 * @param array   $date_formats     incoming date_formats in an array where the first value is the
1706
+	 *                                  date_format and the second value is the time format
1707
+	 * @return mixed (EE_Base_Class|bool)
1708
+	 * @throws \EE_Error
1709
+	 */
1710
+	protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1711
+	{
1712
+		$existing = null;
1713
+		if (self::_get_model($classname)->has_primary_key_field()) {
1714
+			$primary_id_ref = self::_get_primary_key_name($classname);
1715
+			if (array_key_exists($primary_id_ref, $props_n_values)
1716
+				&& ! empty($props_n_values[$primary_id_ref])
1717
+			) {
1718
+				$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1719
+					$props_n_values[$primary_id_ref]
1720
+				);
1721
+			}
1722
+		} elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) {
1723
+			//no primary key on this model, but there's still a matching item in the DB
1724
+			$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1725
+				self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1726
+			);
1727
+		}
1728
+		if ($existing) {
1729
+			//set date formats if present before setting values
1730
+			if ( ! empty($date_formats) && is_array($date_formats)) {
1731
+				$existing->set_date_format($date_formats[0]);
1732
+				$existing->set_time_format($date_formats[1]);
1733
+			} else {
1734
+				//set default formats for date and time
1735
+				$existing->set_date_format(get_option('date_format'));
1736
+				$existing->set_time_format(get_option('time_format'));
1737
+			}
1738
+			foreach ($props_n_values as $property => $field_value) {
1739
+				$existing->set($property, $field_value);
1740
+			}
1741
+			return $existing;
1742
+		} else {
1743
+			return false;
1744
+		}
1745
+	}
1746
+
1747
+
1748
+
1749
+	/**
1750
+	 * Gets the EEM_*_Model for this class
1751
+	 *
1752
+	 * @access public now, as this is more convenient
1753
+	 * @param      $classname
1754
+	 * @param null $timezone
1755
+	 * @throws EE_Error
1756
+	 * @return EEM_Base
1757
+	 */
1758
+	protected static function _get_model($classname, $timezone = null)
1759
+	{
1760
+		//find model for this class
1761
+		if ( ! $classname) {
1762
+			throw new EE_Error(
1763
+				sprintf(
1764
+					__(
1765
+						"What were you thinking calling _get_model(%s)?? You need to specify the class name",
1766
+						"event_espresso"
1767
+					),
1768
+					$classname
1769
+				)
1770
+			);
1771
+		}
1772
+		$modelName = self::_get_model_classname($classname);
1773
+		return self::_get_model_instance_with_name($modelName, $timezone);
1774
+	}
1775
+
1776
+
1777
+
1778
+	/**
1779
+	 * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1780
+	 *
1781
+	 * @param string $model_classname
1782
+	 * @param null   $timezone
1783
+	 * @return EEM_Base
1784
+	 */
1785
+	protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1786
+	{
1787
+		$model_classname = str_replace('EEM_', '', $model_classname);
1788
+		$model = EE_Registry::instance()->load_model($model_classname);
1789
+		$model->set_timezone($timezone);
1790
+		return $model;
1791
+	}
1792
+
1793
+
1794
+
1795
+	/**
1796
+	 * If a model name is provided (eg Registration), gets the model classname for that model.
1797
+	 * Also works if a model class's classname is provided (eg EE_Registration).
1798
+	 *
1799
+	 * @param null $model_name
1800
+	 * @return string like EEM_Attendee
1801
+	 */
1802
+	private static function _get_model_classname($model_name = null)
1803
+	{
1804
+		if (strpos($model_name, "EE_") === 0) {
1805
+			$model_classname = str_replace("EE_", "EEM_", $model_name);
1806
+		} else {
1807
+			$model_classname = "EEM_" . $model_name;
1808
+		}
1809
+		return $model_classname;
1810
+	}
1811
+
1812
+
1813
+
1814
+	/**
1815
+	 * returns the name of the primary key attribute
1816
+	 *
1817
+	 * @param null $classname
1818
+	 * @throws EE_Error
1819
+	 * @return string
1820
+	 */
1821
+	protected static function _get_primary_key_name($classname = null)
1822
+	{
1823
+		if ( ! $classname) {
1824
+			throw new EE_Error(
1825
+				sprintf(
1826
+					__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1827
+					$classname
1828
+				)
1829
+			);
1830
+		}
1831
+		return self::_get_model($classname)->get_primary_key_field()->get_name();
1832
+	}
1833
+
1834
+
1835
+
1836
+	/**
1837
+	 * Gets the value of the primary key.
1838
+	 * If the object hasn't yet been saved, it should be whatever the model field's default was
1839
+	 * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value is.
1840
+	 * Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1841
+	 *
1842
+	 * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1843
+	 * @throws \EE_Error
1844
+	 */
1845
+	public function ID()
1846
+	{
1847
+		//now that we know the name of the variable, use a variable variable to get its value and return its
1848
+		if ($this->get_model()->has_primary_key_field()) {
1849
+			return $this->_fields[self::_get_primary_key_name(get_class($this))];
1850
+		} else {
1851
+			return $this->get_model()->get_index_primary_key_string($this->_fields);
1852
+		}
1853
+	}
1854
+
1855
+
1856
+
1857
+	/**
1858
+	 * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current model is related
1859
+	 * to a group of events, the $relationName should be 'Event', and should be a key in the EE Model's $_model_relations array.
1860
+	 * If this model object doesn't exist in the DB, just caches the related thing
1861
+	 *
1862
+	 * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1863
+	 * @param string $relationName                     eg 'Events','Question',etc.
1864
+	 *                                                 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')
1865
+	 * @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
1866
+	 *                                                 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,
1867
+	 *                                                 then a NEW row is created in the join table.
1868
+	 * @param null   $cache_id
1869
+	 * @throws EE_Error
1870
+	 * @return EE_Base_Class the object the relation was added to
1871
+	 */
1872
+	public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = null)
1873
+	{
1874
+		//if this thing exists in the DB, save the relation to the DB
1875
+		if ($this->ID()) {
1876
+			$otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values);
1877
+			//clear cache so future get_many_related and get_first_related() return new results.
1878
+			$this->clear_cache($relationName, $otherObject, true);
1879
+			if ($otherObject instanceof EE_Base_Class) {
1880
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1881
+			}
1882
+		} else {
1883
+			//this thing doesn't exist in the DB,  so just cache it
1884
+			if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
1885
+				throw new EE_Error(sprintf(
1886
+					__('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'),
1887
+					$otherObjectModelObjectOrID,
1888
+					get_class($this)
1889
+				));
1890
+			} else {
1891
+				$otherObject = $otherObjectModelObjectOrID;
1892
+			}
1893
+			$this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
1894
+		}
1895
+		if ($otherObject instanceof EE_Base_Class) {
1896
+			//fix the reciprocal relation too
1897
+			if ($otherObject->ID()) {
1898
+				//its saved so assumed relations exist in the DB, so we can just
1899
+				//clear the cache so future queries use the updated info in the DB
1900
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true);
1901
+			} else {
1902
+				//it's not saved, so it caches relations like this
1903
+				$otherObject->cache($this->get_model()->get_this_model_name(), $this);
1904
+			}
1905
+		}
1906
+		return $otherObject;
1907
+	}
1908
+
1909
+
1910
+
1911
+	/**
1912
+	 * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current model is related
1913
+	 * to a group of events, the $relationName should be 'Events', and should be a key in the EE Model's $_model_relations array.
1914
+	 * If this model object doesn't exist in the DB, just removes the related thing from the cache
1915
+	 *
1916
+	 * @param mixed  $otherObjectModelObjectOrID
1917
+	 *                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
1918
+	 * @param string $relationName
1919
+	 * @param array  $where_query
1920
+	 *                You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added.
1921
+	 *                However, keep in mind that the columns (keys) given must match a column on the JOIN table
1922
+	 *                and currently only the HABTM models accept these additional conditions.
1923
+	 *                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.
1924
+	 * @return EE_Base_Class the relation was removed from
1925
+	 * @throws \EE_Error
1926
+	 */
1927
+	public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
1928
+	{
1929
+		if ($this->ID()) {
1930
+			//if this exists in the DB, save the relation change to the DB too
1931
+			$otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query);
1932
+			$this->clear_cache($relationName, $otherObject);
1933
+		} else {
1934
+			//this doesn't exist in the DB, just remove it from the cache
1935
+			$otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
1936
+		}
1937
+		if ($otherObject instanceof EE_Base_Class) {
1938
+			$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1939
+		}
1940
+		return $otherObject;
1941
+	}
1942
+
1943
+
1944
+
1945
+	/**
1946
+	 * Removes ALL the related things for the $relationName.
1947
+	 *
1948
+	 * @param string $relationName
1949
+	 * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
1950
+	 * @return EE_Base_Class
1951
+	 * @throws \EE_Error
1952
+	 */
1953
+	public function _remove_relations($relationName, $where_query_params = array())
1954
+	{
1955
+		if ($this->ID()) {
1956
+			//if this exists in the DB, save the relation change to the DB too
1957
+			$otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
1958
+			$this->clear_cache($relationName, null, true);
1959
+		} else {
1960
+			//this doesn't exist in the DB, just remove it from the cache
1961
+			$otherObjects = $this->clear_cache($relationName, null, true);
1962
+		}
1963
+		if (is_array($otherObjects)) {
1964
+			foreach ($otherObjects as $otherObject) {
1965
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1966
+			}
1967
+		}
1968
+		return $otherObjects;
1969
+	}
1970
+
1971
+
1972
+
1973
+	/**
1974
+	 * Gets all the related model objects of the specified type. Eg, if the current class if
1975
+	 * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
1976
+	 * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
1977
+	 * because we want to get even deleted items etc.
1978
+	 *
1979
+	 * @param string $relationName key in the model's _model_relations array
1980
+	 * @param array  $query_params like EEM_Base::get_all
1981
+	 * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
1982
+	 * @throws \EE_Error
1983
+	 *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs
1984
+	 */
1985
+	public function get_many_related($relationName, $query_params = array())
1986
+	{
1987
+		if ($this->ID()) {
1988
+			//this exists in the DB, so get the related things from either the cache or the DB
1989
+			//if there are query parameters, forget about caching the related model objects.
1990
+			if ($query_params) {
1991
+				$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1992
+			} else {
1993
+				//did we already cache the result of this query?
1994
+				$cached_results = $this->get_all_from_cache($relationName);
1995
+				if ( ! $cached_results) {
1996
+					$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
1997
+					//if no query parameters were passed, then we got all the related model objects
1998
+					//for that relation. We can cache them then.
1999
+					foreach ($related_model_objects as $related_model_object) {
2000
+						$this->cache($relationName, $related_model_object);
2001
+					}
2002
+				} else {
2003
+					$related_model_objects = $cached_results;
2004
+				}
2005
+			}
2006
+		} else {
2007
+			//this doesn't exist in the DB, so just get the related things from the cache
2008
+			$related_model_objects = $this->get_all_from_cache($relationName);
2009
+		}
2010
+		return $related_model_objects;
2011
+	}
2012
+
2013
+
2014
+
2015
+	/**
2016
+	 * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2017
+	 * unless otherwise specified in the $query_params
2018
+	 *
2019
+	 * @param string $relation_name  model_name like 'Event', or 'Registration'
2020
+	 * @param array  $query_params   like EEM_Base::get_all's
2021
+	 * @param string $field_to_count name of field to count by. By default, uses primary key
2022
+	 * @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;
2023
+	 * @return int
2024
+	 */
2025
+	public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2026
+	{
2027
+		return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2028
+	}
2029
+
2030
+
2031
+
2032
+	/**
2033
+	 * Instead of getting the related model objects, simply sums up the values of the specified field.
2034
+	 * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2035
+	 *
2036
+	 * @param string $relation_name model_name like 'Event', or 'Registration'
2037
+	 * @param array  $query_params  like EEM_Base::get_all's
2038
+	 * @param string $field_to_sum  name of field to count by.
2039
+	 *                              By default, uses primary key (which doesn't make much sense, so you should probably change it)
2040
+	 * @return int
2041
+	 */
2042
+	public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2043
+	{
2044
+		return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2045
+	}
2046
+
2047
+
2048
+
2049
+	/**
2050
+	 * Gets the first (ie, one) related model object of the specified type.
2051
+	 *
2052
+	 * @param string $relationName key in the model's _model_relations array
2053
+	 * @param array  $query_params like EEM_Base::get_all
2054
+	 * @return EE_Base_Class (not an array, a single object)
2055
+	 * @throws \EE_Error
2056
+	 */
2057
+	public function get_first_related($relationName, $query_params = array())
2058
+	{
2059
+		if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2060
+			//if they've provided some query parameters, don't bother trying to cache the result
2061
+			//also make sure we're not caching the result of get_first_related
2062
+			//on a relation which should have an array of objects (because the cache might have an array of objects)
2063
+			if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2064
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2065
+			} else {
2066
+				//first, check if we've already cached the result of this query
2067
+				$cached_result = $this->get_one_from_cache($relationName);
2068
+				if ( ! $cached_result) {
2069
+					$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2070
+					$this->cache($relationName, $related_model_object);
2071
+				} else {
2072
+					$related_model_object = $cached_result;
2073
+				}
2074
+			}
2075
+		} else {
2076
+			$related_model_object = null;
2077
+			//this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2078
+			if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2079
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2080
+			}
2081
+			//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
2082
+			if ( ! $related_model_object) {
2083
+				$related_model_object = $this->get_one_from_cache($relationName);
2084
+			}
2085
+		}
2086
+		return $related_model_object;
2087
+	}
2088
+
2089
+
2090
+
2091
+	/**
2092
+	 * Does a delete on all related objects of type $relationName and removes
2093
+	 * the current model object's relation to them. If they can't be deleted (because
2094
+	 * of blocking related model objects) does nothing. If the related model objects are
2095
+	 * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2096
+	 * If this model object doesn't exist yet in the DB, just removes its related things
2097
+	 *
2098
+	 * @param string $relationName
2099
+	 * @param array  $query_params like EEM_Base::get_all's
2100
+	 * @return int how many deleted
2101
+	 * @throws \EE_Error
2102
+	 */
2103
+	public function delete_related($relationName, $query_params = array())
2104
+	{
2105
+		if ($this->ID()) {
2106
+			$count = $this->get_model()->delete_related($this, $relationName, $query_params);
2107
+		} else {
2108
+			$count = count($this->get_all_from_cache($relationName));
2109
+			$this->clear_cache($relationName, null, true);
2110
+		}
2111
+		return $count;
2112
+	}
2113
+
2114
+
2115
+
2116
+	/**
2117
+	 * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2118
+	 * the current model object's relation to them. If they can't be deleted (because
2119
+	 * of blocking related model objects) just does a soft delete on it instead, if possible.
2120
+	 * If the related thing isn't a soft-deletable model object, this function is identical
2121
+	 * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2122
+	 *
2123
+	 * @param string $relationName
2124
+	 * @param array  $query_params like EEM_Base::get_all's
2125
+	 * @return int how many deleted (including those soft deleted)
2126
+	 * @throws \EE_Error
2127
+	 */
2128
+	public function delete_related_permanently($relationName, $query_params = array())
2129
+	{
2130
+		if ($this->ID()) {
2131
+			$count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2132
+		} else {
2133
+			$count = count($this->get_all_from_cache($relationName));
2134
+		}
2135
+		$this->clear_cache($relationName, null, true);
2136
+		return $count;
2137
+	}
2138
+
2139
+
2140
+
2141
+	/**
2142
+	 * is_set
2143
+	 * Just a simple utility function children can use for checking if property exists
2144
+	 *
2145
+	 * @access  public
2146
+	 * @param  string $field_name property to check
2147
+	 * @return bool                              TRUE if existing,FALSE if not.
2148
+	 */
2149
+	public function is_set($field_name)
2150
+	{
2151
+		return isset($this->_fields[$field_name]);
2152
+	}
2153
+
2154
+
2155
+
2156
+	/**
2157
+	 * 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
2158
+	 *
2159
+	 * @param  mixed (string|array) $properties properties to check
2160
+	 * @throws EE_Error
2161
+	 * @return bool                              TRUE if existing, throw EE_Error if not.
2162
+	 */
2163
+	protected function _property_exists($properties)
2164
+	{
2165
+		foreach ((array)$properties as $property_name) {
2166
+			//first make sure this property exists
2167
+			if ( ! $this->_fields[$property_name]) {
2168
+				throw new EE_Error(
2169
+					sprintf(
2170
+						__(
2171
+							'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2172
+							'event_espresso'
2173
+						),
2174
+						$property_name
2175
+					)
2176
+				);
2177
+			}
2178
+		}
2179
+		return true;
2180
+	}
2181
+
2182
+
2183
+
2184
+	/**
2185
+	 * This simply returns an array of model fields for this object
2186
+	 *
2187
+	 * @return array
2188
+	 * @throws \EE_Error
2189
+	 */
2190
+	public function model_field_array()
2191
+	{
2192
+		$fields = $this->get_model()->field_settings(false);
2193
+		$properties = array();
2194
+		//remove prepended underscore
2195
+		foreach ($fields as $field_name => $settings) {
2196
+			$properties[$field_name] = $this->get($field_name);
2197
+		}
2198
+		return $properties;
2199
+	}
2200
+
2201
+
2202
+
2203
+	/**
2204
+	 * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2205
+	 * 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)
2206
+	 * and passed the method's name and arguments.
2207
+	 * 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?)
2208
+	 * they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, filters_hook_espresso__EE_Answer__my_great_function)
2209
+	 * 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.
2210
+	 * Example: in functions.php (or in a plugin):
2211
+	 * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3);
2212
+	 * function my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2213
+	 * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2214
+	 *        return $previousReturnValue.$returnString;
2215
+	 * }
2216
+	 * require('EE_Answer.class.php');
2217
+	 * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2218
+	 * echo $answer->my_callback('monkeys',100);
2219
+	 * //will output "you called my_callback! and passed args:monkeys,100"
2220
+	 *
2221
+	 * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2222
+	 * @param array  $args       array of original arguments passed to the function
2223
+	 * @throws EE_Error
2224
+	 * @return mixed whatever the plugin which calls add_filter decides
2225
+	 */
2226
+	public function __call($methodName, $args)
2227
+	{
2228
+		$className = get_class($this);
2229
+		$tagName = "FHEE__{$className}__{$methodName}";
2230
+		if ( ! has_filter($tagName)) {
2231
+			throw new EE_Error(
2232
+				sprintf(
2233
+					__(
2234
+						"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;}",
2235
+						"event_espresso"
2236
+					),
2237
+					$methodName,
2238
+					$className,
2239
+					$tagName
2240
+				)
2241
+			);
2242
+		}
2243
+		return apply_filters($tagName, null, $this, $args);
2244
+	}
2245
+
2246
+
2247
+
2248
+	/**
2249
+	 * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2250
+	 * A $previous_value can be specified in case there are many meta rows with the same key
2251
+	 *
2252
+	 * @param string $meta_key
2253
+	 * @param string $meta_value
2254
+	 * @param string $previous_value
2255
+	 * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2256
+	 * @throws \EE_Error
2257
+	 * NOTE: if the values haven't changed, returns 0
2258
+	 */
2259
+	public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2260
+	{
2261
+		$query_params = array(
2262
+			array(
2263
+				'EXM_key'  => $meta_key,
2264
+				'OBJ_ID'   => $this->ID(),
2265
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2266
+			),
2267
+		);
2268
+		if ($previous_value !== null) {
2269
+			$query_params[0]['EXM_value'] = $meta_value;
2270
+		}
2271
+		$existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2272
+		if ( ! $existing_rows_like_that) {
2273
+			return $this->add_extra_meta($meta_key, $meta_value);
2274
+		} else {
2275
+			foreach ($existing_rows_like_that as $existing_row) {
2276
+				$existing_row->save(array('EXM_value' => $meta_value));
2277
+			}
2278
+			return count($existing_rows_like_that);
2279
+		}
2280
+	}
2281
+
2282
+
2283
+
2284
+	/**
2285
+	 * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2286
+	 * no other extra meta for this model object have the same key. Returns TRUE if the
2287
+	 * extra meta row was entered, false if not
2288
+	 *
2289
+	 * @param string  $meta_key
2290
+	 * @param string  $meta_value
2291
+	 * @param boolean $unique
2292
+	 * @return boolean
2293
+	 * @throws \EE_Error
2294
+	 */
2295
+	public function add_extra_meta($meta_key, $meta_value, $unique = false)
2296
+	{
2297
+		if ($unique) {
2298
+			$existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2299
+				array(
2300
+					array(
2301
+						'EXM_key'  => $meta_key,
2302
+						'OBJ_ID'   => $this->ID(),
2303
+						'EXM_type' => $this->get_model()->get_this_model_name(),
2304
+					),
2305
+				)
2306
+			);
2307
+			if ($existing_extra_meta) {
2308
+				return false;
2309
+			}
2310
+		}
2311
+		$new_extra_meta = EE_Extra_Meta::new_instance(
2312
+			array(
2313
+				'EXM_key'   => $meta_key,
2314
+				'EXM_value' => $meta_value,
2315
+				'OBJ_ID'    => $this->ID(),
2316
+				'EXM_type'  => $this->get_model()->get_this_model_name(),
2317
+			)
2318
+		);
2319
+		$new_extra_meta->save();
2320
+		return true;
2321
+	}
2322
+
2323
+
2324
+
2325
+	/**
2326
+	 * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2327
+	 * is specified, only deletes extra meta records with that value.
2328
+	 *
2329
+	 * @param string $meta_key
2330
+	 * @param string $meta_value
2331
+	 * @return int number of extra meta rows deleted
2332
+	 * @throws \EE_Error
2333
+	 */
2334
+	public function delete_extra_meta($meta_key, $meta_value = null)
2335
+	{
2336
+		$query_params = array(
2337
+			array(
2338
+				'EXM_key'  => $meta_key,
2339
+				'OBJ_ID'   => $this->ID(),
2340
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2341
+			),
2342
+		);
2343
+		if ($meta_value !== null) {
2344
+			$query_params[0]['EXM_value'] = $meta_value;
2345
+		}
2346
+		return EEM_Extra_Meta::instance()->delete($query_params);
2347
+	}
2348
+
2349
+
2350
+
2351
+	/**
2352
+	 * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2353
+	 * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2354
+	 * You can specify $default is case you haven't found the extra meta
2355
+	 *
2356
+	 * @param string  $meta_key
2357
+	 * @param boolean $single
2358
+	 * @param mixed   $default if we don't find anything, what should we return?
2359
+	 * @return mixed single value if $single; array if ! $single
2360
+	 * @throws \EE_Error
2361
+	 */
2362
+	public function get_extra_meta($meta_key, $single = false, $default = null)
2363
+	{
2364
+		if ($single) {
2365
+			$result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2366
+			if ($result instanceof EE_Extra_Meta) {
2367
+				return $result->value();
2368
+			} else {
2369
+				return $default;
2370
+			}
2371
+		} else {
2372
+			$results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2373
+			if ($results) {
2374
+				$values = array();
2375
+				foreach ($results as $result) {
2376
+					if ($result instanceof EE_Extra_Meta) {
2377
+						$values[$result->ID()] = $result->value();
2378
+					}
2379
+				}
2380
+				return $values;
2381
+			} else {
2382
+				return $default;
2383
+			}
2384
+		}
2385
+	}
2386
+
2387
+
2388
+
2389
+	/**
2390
+	 * Returns a simple array of all the extra meta associated with this model object.
2391
+	 * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2392
+	 * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2393
+	 * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2394
+	 * If $one_of_each_key is false, it will return an array with the top-level keys being
2395
+	 * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2396
+	 * finally the extra meta's value as each sub-value. (eg array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2397
+	 *
2398
+	 * @param boolean $one_of_each_key
2399
+	 * @return array
2400
+	 * @throws \EE_Error
2401
+	 */
2402
+	public function all_extra_meta_array($one_of_each_key = true)
2403
+	{
2404
+		$return_array = array();
2405
+		if ($one_of_each_key) {
2406
+			$extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2407
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2408
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2409
+					$return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2410
+				}
2411
+			}
2412
+		} else {
2413
+			$extra_meta_objs = $this->get_many_related('Extra_Meta');
2414
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2415
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2416
+					if ( ! isset($return_array[$extra_meta_obj->key()])) {
2417
+						$return_array[$extra_meta_obj->key()] = array();
2418
+					}
2419
+					$return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2420
+				}
2421
+			}
2422
+		}
2423
+		return $return_array;
2424
+	}
2425
+
2426
+
2427
+
2428
+	/**
2429
+	 * Gets a pretty nice displayable nice for this model object. Often overridden
2430
+	 *
2431
+	 * @return string
2432
+	 * @throws \EE_Error
2433
+	 */
2434
+	public function name()
2435
+	{
2436
+		//find a field that's not a text field
2437
+		$field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2438
+		if ($field_we_can_use) {
2439
+			return $this->get($field_we_can_use->get_name());
2440
+		} else {
2441
+			$first_few_properties = $this->model_field_array();
2442
+			$first_few_properties = array_slice($first_few_properties, 0, 3);
2443
+			$name_parts = array();
2444
+			foreach ($first_few_properties as $name => $value) {
2445
+				$name_parts[] = "$name:$value";
2446
+			}
2447
+			return implode(",", $name_parts);
2448
+		}
2449
+	}
2450
+
2451
+
2452
+
2453
+	/**
2454
+	 * in_entity_map
2455
+	 * Checks if this model object has been proven to already be in the entity map
2456
+	 *
2457
+	 * @return boolean
2458
+	 * @throws \EE_Error
2459
+	 */
2460
+	public function in_entity_map()
2461
+	{
2462
+		if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2463
+			//well, if we looked, did we find it in the entity map?
2464
+			return true;
2465
+		} else {
2466
+			return false;
2467
+		}
2468
+	}
2469
+
2470
+
2471
+
2472
+	/**
2473
+	 * refresh_from_db
2474
+	 * Makes sure the fields and values on this model object are in-sync with what's in the database.
2475
+	 *
2476
+	 * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2477
+	 * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2478
+	 */
2479
+	public function refresh_from_db()
2480
+	{
2481
+		if ($this->ID() && $this->in_entity_map()) {
2482
+			$this->get_model()->refresh_entity_map_from_db($this->ID());
2483
+		} else {
2484
+			//if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2485
+			//if it has an ID but it's not in the map, and you're asking me to refresh it
2486
+			//that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2487
+			//absolutely nothing in it for this ID
2488
+			if (WP_DEBUG) {
2489
+				throw new EE_Error(
2490
+					sprintf(
2491
+						__('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.',
2492
+							'event_espresso'),
2493
+						$this->ID(),
2494
+						get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2495
+						get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2496
+					)
2497
+				);
2498
+			}
2499
+		}
2500
+	}
2501
+
2502
+
2503
+
2504
+	/**
2505
+	 * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2506
+	 * (probably a bad assumption they have made, oh well)
2507
+	 *
2508
+	 * @return string
2509
+	 */
2510
+	public function __toString()
2511
+	{
2512
+		try {
2513
+			return sprintf('%s (%s)', $this->name(), $this->ID());
2514
+		} catch (Exception $e) {
2515
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2516
+			return '';
2517
+		}
2518
+	}
2519
+
2520
+
2521
+
2522
+	/**
2523
+	 * Clear related model objects if they're already in the DB, because otherwise when we
2524
+	 * UN-serialize this model object we'll need to be careful to add them to the entity map.
2525
+	 * This means if we have made changes to those related model objects, and want to unserialize
2526
+	 * the this model object on a subsequent request, changes to those related model objects will be lost.
2527
+	 * Instead, those related model objects should be directly serialized and stored.
2528
+	 * Eg, the following won't work:
2529
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2530
+	 * $att = $reg->attendee();
2531
+	 * $att->set( 'ATT_fname', 'Dirk' );
2532
+	 * update_option( 'my_option', serialize( $reg ) );
2533
+	 * //END REQUEST
2534
+	 * //START NEXT REQUEST
2535
+	 * $reg = get_option( 'my_option' );
2536
+	 * $reg->attendee()->save();
2537
+	 * And would need to be replace with:
2538
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2539
+	 * $att = $reg->attendee();
2540
+	 * $att->set( 'ATT_fname', 'Dirk' );
2541
+	 * update_option( 'my_option', serialize( $reg ) );
2542
+	 * //END REQUEST
2543
+	 * //START NEXT REQUEST
2544
+	 * $att = get_option( 'my_option' );
2545
+	 * $att->save();
2546
+	 *
2547
+	 * @return array
2548
+	 * @throws \EE_Error
2549
+	 */
2550
+	public function __sleep()
2551
+	{
2552
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2553
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
2554
+				$classname = 'EE_' . $this->get_model()->get_this_model_name();
2555
+				if (
2556
+					$this->get_one_from_cache($relation_name) instanceof $classname
2557
+					&& $this->get_one_from_cache($relation_name)->ID()
2558
+				) {
2559
+					$this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2560
+				}
2561
+			}
2562
+		}
2563
+		$this->_props_n_values_provided_in_constructor = array();
2564
+		return array_keys(get_object_vars($this));
2565
+	}
2566
+
2567
+
2568
+
2569
+	/**
2570
+	 * restore _props_n_values_provided_in_constructor
2571
+	 * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2572
+	 * and therefore should NOT be used to determine if state change has occurred since initial construction.
2573
+	 * At best, you would only be able to detect if state change has occurred during THIS request.
2574
+	 */
2575
+	public function __wakeup()
2576
+	{
2577
+		$this->_props_n_values_provided_in_constructor = $this->_fields;
2578
+	}
2579 2579
 
2580 2580
 
2581 2581
 
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
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -17,60 +17,60 @@  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
-        );
40
-        $template_args['event_permalink'] = $event->get_permalink();
41
-        $template_args['event_name'] = $event->name();
42
-        $template_args['event_description'] = $event->description();
43
-        $template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM);
44
-        $template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM);
45
-        $template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
46
-        foreach ($event->tickets() as $ticket) {
47
-            $ID = $ticket->ID();
48
-            $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
49
-            $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
50
-            $template_args['event_tickets'][$ID]['price'] = number_format(
51
-                $ticket->price(),
52
-                EE_Registry::instance()->CFG->currency->dec_plc,
53
-                EE_Registry::instance()->CFG->currency->dec_mrk,
54
-                EE_Registry::instance()->CFG->currency->thsnds
55
-            );
56
-        }
57
-        $VNU_ID = espresso_venue_id();
58
-        if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
59
-            $venue = EEH_Venue_View::get_venue($VNU_ID);
60
-            $template_args['venue_name'] = get_the_title($VNU_ID);
61
-            $template_args['venue_url'] = get_permalink($VNU_ID);
62
-            $template_args['venue_locality'] = $venue->city();
63
-            $template_args['venue_region'] = $venue->state_name();
64
-        }
65
-        $template_args = apply_filters(
66
-            'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
67
-            $template_args,
68
-            $event,
69
-            $VNU_ID
70
-        );
71
-        extract($template_args, EXTR_OVERWRITE);
72
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
73
-    }
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
+		);
40
+		$template_args['event_permalink'] = $event->get_permalink();
41
+		$template_args['event_name'] = $event->name();
42
+		$template_args['event_description'] = $event->description();
43
+		$template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM);
44
+		$template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM);
45
+		$template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
46
+		foreach ($event->tickets() as $ticket) {
47
+			$ID = $ticket->ID();
48
+			$template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
49
+			$template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
50
+			$template_args['event_tickets'][$ID]['price'] = number_format(
51
+				$ticket->price(),
52
+				EE_Registry::instance()->CFG->currency->dec_plc,
53
+				EE_Registry::instance()->CFG->currency->dec_mrk,
54
+				EE_Registry::instance()->CFG->currency->thsnds
55
+			);
56
+		}
57
+		$VNU_ID = espresso_venue_id();
58
+		if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
59
+			$venue = EEH_Venue_View::get_venue($VNU_ID);
60
+			$template_args['venue_name'] = get_the_title($VNU_ID);
61
+			$template_args['venue_url'] = get_permalink($VNU_ID);
62
+			$template_args['venue_locality'] = $venue->city();
63
+			$template_args['venue_region'] = $venue->state_name();
64
+		}
65
+		$template_args = apply_filters(
66
+			'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
67
+			$template_args,
68
+			$event,
69
+			$VNU_ID
70
+		);
71
+		extract($template_args, EXTR_OVERWRITE);
72
+		include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
73
+	}
74 74
 
75 75
 
76 76
 	/**
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	public static function location( $location = null ) {
86 86
 		return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
87
-		                              . $location
88
-		                              . '</div>' : '';
87
+									  . $location
88
+									  . '</div>' : '';
89 89
 	}
90 90
 
91 91
 
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 	 */
206 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
-		                                                                              . $obj_with_address->zip()
209
-		                                                                              . '</span>' : '';
208
+																					  . $obj_with_address->zip()
209
+																					  . '</span>' : '';
210 210
 	}
211 211
 
212 212
 
Please login to merge, or discard this patch.
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.
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.