Completed
Branch BUG-8698-ticket-sellouts (195489)
by
unknown
117:04 queued 99:55
created
core/db_classes/EE_Datetime.class.php 1 patch
Spacing   +137 added lines, -137 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
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @access        public
120 120
 	 * @param        string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
121 121
 	 */
122
-	public function set_start_date( $date ) {
123
-		$this->_set_date_for( $date, 'DTT_EVT_start' );
122
+	public function set_start_date($date) {
123
+		$this->_set_date_for($date, 'DTT_EVT_start');
124 124
 	}
125 125
 
126 126
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 	 * @access        public
134 134
 	 * @param        string $time a string representation of the event time ex:  9am  or  7:30 PM
135 135
 	 */
136
-	public function set_start_time( $time ) {
137
-		$this->_set_time_for( $time, 'DTT_EVT_start' );
136
+	public function set_start_time($time) {
137
+		$this->_set_time_for($time, 'DTT_EVT_start');
138 138
 	}
139 139
 
140 140
 
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 	 * @access        public
148 148
 	 * @param        string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
149 149
 	 */
150
-	public function set_end_date( $date ) {
151
-		$this->_set_date_for( $date, 'DTT_EVT_end' );
150
+	public function set_end_date($date) {
151
+		$this->_set_date_for($date, 'DTT_EVT_end');
152 152
 	}
153 153
 
154 154
 
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 	 * @access        public
162 162
 	 * @param        string $time a string representation of the event time ex:  9am  or  7:30 PM
163 163
 	 */
164
-	public function set_end_time( $time ) {
165
-		$this->_set_time_for( $time, 'DTT_EVT_end' );
164
+	public function set_end_time($time) {
165
+		$this->_set_time_for($time, 'DTT_EVT_end');
166 166
 	}
167 167
 
168 168
 
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 	 * @access        public
176 176
 	 * @param        int $reg_limit
177 177
 	 */
178
-	public function set_reg_limit( $reg_limit ) {
179
-		$this->set( 'DTT_reg_limit', $reg_limit );
178
+	public function set_reg_limit($reg_limit) {
179
+		$this->set('DTT_reg_limit', $reg_limit);
180 180
 	}
181 181
 
182 182
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @return        mixed        int on success, FALSE on fail
189 189
 	 */
190 190
 	public function sold() {
191
-		return $this->get_raw( 'DTT_sold' );
191
+		return $this->get_raw('DTT_sold');
192 192
 	}
193 193
 
194 194
 
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 	 * @access        public
200 200
 	 * @param        int $sold
201 201
 	 */
202
-	public function set_sold( $sold ) {
202
+	public function set_sold($sold) {
203 203
 		// sold can not go below zero
204
-		$sold = max( 0, $sold );
205
-		$this->set( 'DTT_sold', $sold );
204
+		$sold = max(0, $sold);
205
+		$this->set('DTT_sold', $sold);
206 206
 	}
207 207
 
208 208
 
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
 	 * increments sold by amount passed by $qty
212 212
 	 * @param int $qty
213 213
 	 */
214
-	function increase_sold( $qty = 1 ) {
214
+	function increase_sold($qty = 1) {
215 215
 		$sold = $this->sold() + $qty;
216 216
 		// remove ticket reservation
217
-		$this->decrease_reserved( $qty );
218
-		$this->set_sold( $sold );
217
+		$this->decrease_reserved($qty);
218
+		$this->set_sold($sold);
219 219
 	}
220 220
 
221 221
 
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
 	 * decrements (subtracts) sold amount passed by $qty
225 225
 	 * @param int $qty
226 226
 	 */
227
-	function decrease_sold( $qty = 1 ) {
227
+	function decrease_sold($qty = 1) {
228 228
 		$sold = $this->sold() - $qty;
229
-		$this->set_sold( $sold );
229
+		$this->set_sold($sold);
230 230
 	}
231 231
 
232 232
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	 * @return int
238 238
 	 */
239 239
 	function reserved() {
240
-		return $this->get_raw( 'DTT_reserved' );
240
+		return $this->get_raw('DTT_reserved');
241 241
 	}
242 242
 
243 243
 
@@ -248,10 +248,10 @@  discard block
 block discarded – undo
248 248
 	 * @param int $reserved
249 249
 	 * @return boolean
250 250
 	 */
251
-	function set_reserved( $reserved ) {
251
+	function set_reserved($reserved) {
252 252
 		// reserved can not go below zero
253
-		$reserved = max( 0, intval( $reserved ) );
254
-		$this->set( 'DTT_reserved', $reserved );
253
+		$reserved = max(0, intval($reserved));
254
+		$this->set('DTT_reserved', $reserved);
255 255
 	}
256 256
 
257 257
 
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 	 * @param int $qty
263 263
 	 * @return boolean
264 264
 	 */
265
-	function increase_reserved( $qty = 1 ) {
266
-		$reserved = $this->reserved() + absint( $qty );
267
-		return $this->set_reserved( $reserved );
265
+	function increase_reserved($qty = 1) {
266
+		$reserved = $this->reserved() + absint($qty);
267
+		return $this->set_reserved($reserved);
268 268
 	}
269 269
 
270 270
 
@@ -275,9 +275,9 @@  discard block
 block discarded – undo
275 275
 	 * @param int $qty
276 276
 	 * @return boolean
277 277
 	 */
278
-	function decrease_reserved( $qty = 1 ) {
279
-		$reserved = $this->reserved() - absint( $qty );
280
-		return $this->set_reserved( $reserved );
278
+	function decrease_reserved($qty = 1) {
279
+		$reserved = $this->reserved() - absint($qty);
280
+		return $this->set_reserved($reserved);
281 281
 	}
282 282
 
283 283
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	 * @return string
299 299
 	 */
300 300
 	public function name() {
301
-		return $this->get( 'DTT_name' );
301
+		return $this->get('DTT_name');
302 302
 	}
303 303
 
304 304
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	 * @return string
309 309
 	 */
310 310
 	public function description() {
311
-		return $this->get( 'DTT_description' );
311
+		return $this->get('DTT_description');
312 312
 	}
313 313
 
314 314
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 	 * @return boolean          TRUE if is primary, FALSE if not.
319 319
 	 */
320 320
 	public function is_primary() {
321
-		return $this->get( 'DTT_is_primary' );
321
+		return $this->get('DTT_is_primary');
322 322
 	}
323 323
 
324 324
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 	 * @return int         The order of the datetime for this event.
329 329
 	 */
330 330
 	public function order() {
331
-		return $this->get( 'DTT_order' );
331
+		return $this->get('DTT_order');
332 332
 	}
333 333
 
334 334
 
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 	 * @return int
339 339
 	 */
340 340
 	public function parent() {
341
-		return $this->get( 'DTT_parent' );
341
+		return $this->get('DTT_parent');
342 342
 	}
343 343
 
344 344
 
@@ -354,10 +354,10 @@  discard block
 block discarded – undo
354 354
 	 * @param    bool   $echo         - whether we echo or return (note echoing uses "pretty" formats, otherwise we use the standard formats)
355 355
 	 * @return    string|bool|void  string on success, FALSE on fail
356 356
 	 */
357
-	private function _show_datetime( $date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE ) {
357
+	private function _show_datetime($date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE) {
358 358
 		$field_name = "DTT_EVT_{$start_or_end}";
359
-		$dtt = $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo );
360
-		if ( ! $echo ) {
359
+		$dtt = $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo);
360
+		if ( ! $echo) {
361 361
 			return $dtt;
362 362
 		}
363 363
 		return '';
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 	 * @param null $dt_frmt - string representation of date format defaults to 'F j, Y'
374 374
 	 * @return        mixed        string on success, FALSE on fail
375 375
 	 */
376
-	public function start_date( $dt_frmt = NULL ) {
377
-		return $this->_show_datetime( 'D', 'start', $dt_frmt );
376
+	public function start_date($dt_frmt = NULL) {
377
+		return $this->_show_datetime('D', 'start', $dt_frmt);
378 378
 	}
379 379
 
380 380
 
@@ -383,8 +383,8 @@  discard block
 block discarded – undo
383 383
 	 * Echoes start_date()
384 384
 	 * @param string $dt_frmt
385 385
 	 */
386
-	public function e_start_date( $dt_frmt = NULL ) {
387
-		$this->_show_datetime( 'D', 'start', $dt_frmt, NULL, TRUE );
386
+	public function e_start_date($dt_frmt = NULL) {
387
+		$this->_show_datetime('D', 'start', $dt_frmt, NULL, TRUE);
388 388
 	}
389 389
 
390 390
 
@@ -397,8 +397,8 @@  discard block
 block discarded – undo
397 397
 	 * @param null $dt_frmt - string representation of date format defaults to 'F j, Y'
398 398
 	 * @return        mixed        string on success, FALSE on fail
399 399
 	 */
400
-	public function end_date( $dt_frmt = NULL ) {
401
-		return $this->_show_datetime( 'D', 'end', $dt_frmt );
400
+	public function end_date($dt_frmt = NULL) {
401
+		return $this->_show_datetime('D', 'end', $dt_frmt);
402 402
 	}
403 403
 
404 404
 
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
 	 * Echoes the end date. See end_date()
408 408
 	 * @param string $dt_frmt
409 409
 	 */
410
-	public function e_end_date( $dt_frmt = NULL ) {
411
-		$this->_show_datetime( 'D', 'end', $dt_frmt, NULL, TRUE );
410
+	public function e_end_date($dt_frmt = NULL) {
411
+		$this->_show_datetime('D', 'end', $dt_frmt, NULL, TRUE);
412 412
 	}
413 413
 
414 414
 
@@ -421,11 +421,11 @@  discard block
 block discarded – undo
421 421
 	 * @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
422 422
 	 * @return        mixed        string on success, FALSE on fail
423 423
 	 */
424
-	public function date_range( $dt_frmt = NULL, $conjunction = ' - ' ) {
425
-		$dt_frmt = ! empty( $dt_frmt ) ? $dt_frmt : $this->_dt_frmt;
426
-		$start = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_start', $dt_frmt ) );
427
-		$end = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_end', $dt_frmt ) );
428
-		return $start != $end ? $start . $conjunction . $end : $start;
424
+	public function date_range($dt_frmt = NULL, $conjunction = ' - ') {
425
+		$dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt;
426
+		$start = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt));
427
+		$end = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt));
428
+		return $start != $end ? $start.$conjunction.$end : $start;
429 429
 	}
430 430
 
431 431
 
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
 	 * @param null   $dt_frmt
435 435
 	 * @param string $conjunction
436 436
 	 */
437
-	public function e_date_range( $dt_frmt = NULL, $conjunction = ' - ' ) {
438
-		echo $this->date_range( $dt_frmt, $conjunction );
437
+	public function e_date_range($dt_frmt = NULL, $conjunction = ' - ') {
438
+		echo $this->date_range($dt_frmt, $conjunction);
439 439
 	}
440 440
 
441 441
 
@@ -447,8 +447,8 @@  discard block
 block discarded – undo
447 447
 	 * @param        string $tm_format - string representation of time format defaults to 'g:i a'
448 448
 	 * @return        mixed        string on success, FALSE on fail
449 449
 	 */
450
-	public function start_time( $tm_format = NULL ) {
451
-		return $this->_show_datetime( 'T', 'start', NULL, $tm_format );
450
+	public function start_time($tm_format = NULL) {
451
+		return $this->_show_datetime('T', 'start', NULL, $tm_format);
452 452
 	}
453 453
 
454 454
 
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
 	/**
457 457
 	 * @param null $tm_format
458 458
 	 */
459
-	public function e_start_time( $tm_format = NULL ) {
460
-		$this->_show_datetime( 'T', 'start', NULL, $tm_format, TRUE );
459
+	public function e_start_time($tm_format = NULL) {
460
+		$this->_show_datetime('T', 'start', NULL, $tm_format, TRUE);
461 461
 	}
462 462
 
463 463
 
@@ -469,8 +469,8 @@  discard block
 block discarded – undo
469 469
 	 * @param        string $tm_format - string representation of time format defaults to 'g:i a'
470 470
 	 * @return        mixed        string on success, FALSE on fail
471 471
 	 */
472
-	public function end_time( $tm_format = NULL ) {
473
-		return $this->_show_datetime( 'T', 'end', NULL, $tm_format );
472
+	public function end_time($tm_format = NULL) {
473
+		return $this->_show_datetime('T', 'end', NULL, $tm_format);
474 474
 	}
475 475
 
476 476
 
@@ -478,8 +478,8 @@  discard block
 block discarded – undo
478 478
 	/**
479 479
 	 * @param null $tm_format
480 480
 	 */
481
-	public function e_end_time( $tm_format = NULL ) {
482
-		$this->_show_datetime( 'T', 'end', NULL, $tm_format, TRUE );
481
+	public function e_end_time($tm_format = NULL) {
482
+		$this->_show_datetime('T', 'end', NULL, $tm_format, TRUE);
483 483
 	}
484 484
 
485 485
 
@@ -492,12 +492,12 @@  discard block
 block discarded – undo
492 492
 	 * @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
493 493
 	 * @return        mixed        string on success, FALSE on fail
494 494
 	 */
495
-	public function time_range( $tm_format = NULL, $conjunction = ' - ' ) {
496
-		$tm_format = !empty( $tm_format ) ? $tm_format : $this->_tm_frmt;
495
+	public function time_range($tm_format = NULL, $conjunction = ' - ') {
496
+		$tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt;
497 497
 
498
-		$start = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_start', $tm_format ) );
499
-		$end = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_end',  $tm_format ) );
500
-		return $start != $end ? $start . $conjunction . $end : $start;
498
+		$start = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_start', $tm_format));
499
+		$end = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_end', $tm_format));
500
+		return $start != $end ? $start.$conjunction.$end : $start;
501 501
 	}
502 502
 
503 503
 
@@ -506,8 +506,8 @@  discard block
 block discarded – undo
506 506
 	 * @param null   $tm_format
507 507
 	 * @param string $conjunction
508 508
 	 */
509
-	public function e_time_range( $tm_format = NULL, $conjunction = ' - ' ) {
510
-		echo $this->time_range( $tm_format, $conjunction );
509
+	public function e_time_range($tm_format = NULL, $conjunction = ' - ') {
510
+		echo $this->time_range($tm_format, $conjunction);
511 511
 	}
512 512
 
513 513
 
@@ -520,8 +520,8 @@  discard block
 block discarded – undo
520 520
 	 * @param 	string 	$tm_format - string representation of time format defaults to 'g:i a'
521 521
 	 * @return 	mixed 	string on success, FALSE on fail
522 522
 	 */
523
-	public function start_date_and_time( $dt_format = NULL, $tm_format = NULL ) {
524
-		return $this->_show_datetime( '', 'start', $dt_format, $tm_format );
523
+	public function start_date_and_time($dt_format = NULL, $tm_format = NULL) {
524
+		return $this->_show_datetime('', 'start', $dt_format, $tm_format);
525 525
 	}
526 526
 
527 527
 
@@ -530,8 +530,8 @@  discard block
 block discarded – undo
530 530
 	 * @param null $dt_frmt
531 531
 	 * @param null $tm_format
532 532
 	 */
533
-	public function e_start_date_and_time( $dt_frmt = NULL, $tm_format = NULL ) {
534
-		$this->_show_datetime( '', 'start', $dt_frmt, $tm_format, TRUE );
533
+	public function e_start_date_and_time($dt_frmt = NULL, $tm_format = NULL) {
534
+		$this->_show_datetime('', 'start', $dt_frmt, $tm_format, TRUE);
535 535
 	}
536 536
 
537 537
 
@@ -545,11 +545,11 @@  discard block
 block discarded – undo
545 545
 	 * @param bool   $round_up
546 546
 	 * @return float|int|mixed
547 547
 	 */
548
-	public function length( $units = 'seconds', $round_up = FALSE ) {
549
-		$start = $this->get_raw( 'DTT_EVT_start' );
550
-		$end = $this->get_raw( 'DTT_EVT_end' );
548
+	public function length($units = 'seconds', $round_up = FALSE) {
549
+		$start = $this->get_raw('DTT_EVT_start');
550
+		$end = $this->get_raw('DTT_EVT_end');
551 551
 		$length_in_units = $end - $start;
552
-		switch ( $units ) {
552
+		switch ($units) {
553 553
 			//NOTE: We purposefully don't use "break;" in order to chain the divisions
554 554
 			/** @noinspection PhpMissingBreakStatementInspection */
555 555
 			case 'days':
@@ -562,10 +562,10 @@  discard block
 block discarded – undo
562 562
 				$length_in_units /= 60;
563 563
 			case 'seconds':
564 564
 			default:
565
-				$length_in_units = ceil( $length_in_units );
565
+				$length_in_units = ceil($length_in_units);
566 566
 		}
567
-		if ( $round_up ) {
568
-			$length_in_units = max( $length_in_units, 1 );
567
+		if ($round_up) {
568
+			$length_in_units = max($length_in_units, 1);
569 569
 		}
570 570
 		return $length_in_units;
571 571
 	}
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	 * @param bool | string 	$tm_format - string representation of time format defaults to 'g:i a'
581 581
 	 * @return 	mixed        		string on success, FALSE on fail
582 582
 	 */
583
-	public function end_date_and_time( $dt_frmt = FALSE, $tm_format = FALSE ) {
584
-		return $this->_show_datetime( '', 'end', $dt_frmt, $tm_format );
583
+	public function end_date_and_time($dt_frmt = FALSE, $tm_format = FALSE) {
584
+		return $this->_show_datetime('', 'end', $dt_frmt, $tm_format);
585 585
 	}
586 586
 
587 587
 
@@ -590,8 +590,8 @@  discard block
 block discarded – undo
590 590
 	 * @param bool $dt_frmt
591 591
 	 * @param bool $tm_format
592 592
 	 */
593
-	public function e_end_date_and_time( $dt_frmt = FALSE, $tm_format = FALSE ) {
594
-		$this->_show_datetime( '', 'end', $dt_frmt, $tm_format, TRUE );
593
+	public function e_end_date_and_time($dt_frmt = FALSE, $tm_format = FALSE) {
594
+		$this->_show_datetime('', 'end', $dt_frmt, $tm_format, TRUE);
595 595
 	}
596 596
 
597 597
 
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 	 * @return        int
604 604
 	 */
605 605
 	public function start() {
606
-		return $this->get_raw( 'DTT_EVT_start' );
606
+		return $this->get_raw('DTT_EVT_start');
607 607
 	}
608 608
 
609 609
 
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 	 * @return        int
616 616
 	 */
617 617
 	public function end() {
618
-		return $this->get_raw( 'DTT_EVT_end' );
618
+		return $this->get_raw('DTT_EVT_end');
619 619
 	}
620 620
 
621 621
 
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 	 * @return        mixed        int on success, FALSE on fail
628 628
 	 */
629 629
 	public function reg_limit() {
630
-		return $this->get_raw( 'DTT_reg_limit' );
630
+		return $this->get_raw('DTT_reg_limit');
631 631
 	}
632 632
 
633 633
 
@@ -656,15 +656,15 @@  discard block
 block discarded – undo
656 656
 	 * 																	the spaces remaining for this particular datetime, hence the flag.
657 657
 	 * @return 	int
658 658
 	 */
659
-	public function spaces_remaining( $consider_tickets = FALSE ) {
659
+	public function spaces_remaining($consider_tickets = FALSE) {
660 660
 		// tickets remaining available for purchase
661 661
 		//no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF
662 662
 		$dtt_remaining = $this->reg_limit() - $this->sold();
663
-		if ( ! $consider_tickets ) {
663
+		if ( ! $consider_tickets) {
664 664
 			return $dtt_remaining;
665 665
 		}
666 666
 		$tickets_remaining = $this->tickets_remaining();
667
-		return min( $dtt_remaining, $tickets_remaining );
667
+		return min($dtt_remaining, $tickets_remaining);
668 668
 	}
669 669
 
670 670
 
@@ -675,19 +675,19 @@  discard block
 block discarded – undo
675 675
 	 * @param array $query_params like EEM_Base::get_all's
676 676
 	 * @return int
677 677
 	 */
678
-	public function tickets_remaining( $query_params = array() ) {
678
+	public function tickets_remaining($query_params = array()) {
679 679
 		$sum = 0;
680
-		$tickets = $this->tickets( $query_params );
681
-		if ( ! empty( $tickets ) ) {
682
-			foreach ( $tickets as $ticket ) {
683
-				if ( $ticket instanceof EE_Ticket ) {
680
+		$tickets = $this->tickets($query_params);
681
+		if ( ! empty($tickets)) {
682
+			foreach ($tickets as $ticket) {
683
+				if ($ticket instanceof EE_Ticket) {
684 684
 					// get the actual amount of tickets that can be sold
685
-					$qty = $ticket->qty( 'saleable' );
686
-					if ( $qty === EE_INF ) {
685
+					$qty = $ticket->qty('saleable');
686
+					if ($qty === EE_INF) {
687 687
 						return EE_INF;
688 688
 					}
689 689
 					// no negative ticket quantities plz
690
-					if ( $qty > 0 ) {
690
+					if ($qty > 0) {
691 691
 						$sum += $qty;
692 692
 					}
693 693
 				}
@@ -704,8 +704,8 @@  discard block
 block discarded – undo
704 704
 	 * @param array $query_params like EEM_Base::get_all's
705 705
 	 * @return int
706 706
 	 */
707
-	public function sum_tickets_initially_available( $query_params = array() ) {
708
-		return $this->sum_related( 'Ticket', $query_params, 'TKT_qty' );
707
+	public function sum_tickets_initially_available($query_params = array()) {
708
+		return $this->sum_related('Ticket', $query_params, 'TKT_qty');
709 709
 	}
710 710
 
711 711
 
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
 	 * @return int
718 718
 	 */
719 719
 	public function total_tickets_available_at_this_datetime() {
720
-		return $this->spaces_remaining( true );
720
+		return $this->spaces_remaining(true);
721 721
 	}
722 722
 
723 723
 
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 	 * @return boolean
729 729
 	 */
730 730
 	public function is_upcoming() {
731
-		return ( $this->get_raw( 'DTT_EVT_start' ) > time() );
731
+		return ($this->get_raw('DTT_EVT_start') > time());
732 732
 	}
733 733
 
734 734
 
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 	 * @return boolean
739 739
 	 */
740 740
 	public function is_active() {
741
-		return ( $this->get_raw( 'DTT_EVT_start' ) < time() && $this->get_raw( 'DTT_EVT_end' ) > time() );
741
+		return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time());
742 742
 	}
743 743
 
744 744
 
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 	 * @return boolean
749 749
 	 */
750 750
 	public function is_expired() {
751
-		return ( $this->get_raw( 'DTT_EVT_end' ) < time() );
751
+		return ($this->get_raw('DTT_EVT_end') < time());
752 752
 	}
753 753
 
754 754
 
@@ -759,16 +759,16 @@  discard block
 block discarded – undo
759 759
 	 */
760 760
 	public function get_active_status() {
761 761
 		$total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime();
762
-		if ( $total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1 ) {
762
+		if ($total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1) {
763 763
 			return EE_Datetime::sold_out;
764 764
 		}
765
-		if ( $this->is_expired() ) {
765
+		if ($this->is_expired()) {
766 766
 			return EE_Datetime::expired;
767 767
 		}
768
-		if ( $this->is_upcoming() ) {
768
+		if ($this->is_upcoming()) {
769 769
 			return EE_Datetime::upcoming;
770 770
 		}
771
-		if ( $this->is_active() ) {
771
+		if ($this->is_active()) {
772 772
 			return EE_Datetime::active;
773 773
 		}
774 774
 		return NULL;
@@ -782,24 +782,24 @@  discard block
 block discarded – undo
782 782
 	 * @param  boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty.
783 783
 	 * @return string
784 784
 	 */
785
-	public function get_dtt_display_name( $use_dtt_name = FALSE ) {
786
-		if ( $use_dtt_name ) {
785
+	public function get_dtt_display_name($use_dtt_name = FALSE) {
786
+		if ($use_dtt_name) {
787 787
 			$dtt_name = $this->name();
788
-			if ( !empty( $dtt_name ) ) {
788
+			if ( ! empty($dtt_name)) {
789 789
 				return $dtt_name;
790 790
 			}
791 791
 		}
792 792
 		//first condition is to see if the months are different
793
-		if ( date( 'm', $this->get_raw( 'DTT_EVT_start' ) ) != date( 'm', $this->get_raw( 'DTT_EVT_end' ) ) ) {
794
-			$display_date = $this->start_date( 'M j\, Y g:i a' ) . ' - ' . $this->end_date( 'M j\, Y g:i a' );
793
+		if (date('m', $this->get_raw('DTT_EVT_start')) != date('m', $this->get_raw('DTT_EVT_end'))) {
794
+			$display_date = $this->start_date('M j\, Y g:i a').' - '.$this->end_date('M j\, Y g:i a');
795 795
 			//next condition is if its the same month but different day
796 796
 		}
797 797
 		else {
798
-			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' ) ) ) {
799
-				$display_date = $this->start_date( 'M j\, g:i a' ) . ' - ' . $this->end_date( 'M j\, g:i a Y' );
798
+			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'))) {
799
+				$display_date = $this->start_date('M j\, g:i a').' - '.$this->end_date('M j\, g:i a Y');
800 800
 			}
801 801
 			else {
802
-				$display_date = $this->start_date( 'F j\, Y' ) . ' @ ' . $this->start_date( 'g:i a' ) . ' - ' . $this->end_date( 'g:i a' );
802
+				$display_date = $this->start_date('F j\, Y').' @ '.$this->start_date('g:i a').' - '.$this->end_date('g:i a');
803 803
 			}
804 804
 		}
805 805
 		return $display_date;
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
 *@param array $query_params see EEM_Base::get_all()
814 814
 	 * @return EE_Ticket[]
815 815
 	 */
816
-	public function tickets( $query_params = array() ) {
817
-		return $this->get_many_related( 'Ticket', $query_params );
816
+	public function tickets($query_params = array()) {
817
+		return $this->get_many_related('Ticket', $query_params);
818 818
 	}
819 819
 
820 820
 
@@ -824,21 +824,21 @@  discard block
 block discarded – undo
824 824
 	 * @param array $query_params like EEM_Base::get_all's
825 825
 	 * @return EE_Ticket[]
826 826
 	 */
827
-	public function ticket_types_available_for_purchase( $query_params = array() ) {
827
+	public function ticket_types_available_for_purchase($query_params = array()) {
828 828
 		// first check if datetime is valid
829
-		if ( ! ( $this->is_upcoming() || $this->is_active() ) || $this->sold_out() ) {
829
+		if ( ! ($this->is_upcoming() || $this->is_active()) || $this->sold_out()) {
830 830
 			return array();
831 831
 		}
832
-		if ( empty( $query_params ) ) {
832
+		if (empty($query_params)) {
833 833
 			$query_params = array(
834 834
 				array(
835
-					'TKT_start_date' => array( '<=', EEM_Ticket::instance()->current_time_for_query( 'TKT_start_date' ) ),
836
-					'TKT_end_date'   => array( '>=', EEM_Ticket::instance()->current_time_for_query( 'TKT_end_date' ) ),
835
+					'TKT_start_date' => array('<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')),
836
+					'TKT_end_date'   => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
837 837
 					'TKT_deleted'    => false
838 838
 				)
839 839
 			);
840 840
 		}
841
-		return $this->tickets( $query_params );
841
+		return $this->tickets($query_params);
842 842
 	}
843 843
 
844 844
 
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	 * @return EE_Event
849 849
 	 */
850 850
 	public function event() {
851
-		return $this->get_first_related( 'Event' );
851
+		return $this->get_first_related('Event');
852 852
 	}
853 853
 
854 854
 
@@ -860,13 +860,13 @@  discard block
 block discarded – undo
860 860
 	 */
861 861
 	public function update_sold() {
862 862
 		$count_regs_for_this_datetime = EEM_Registration::instance()->count(
863
-			array( array(
863
+			array(array(
864 864
 				'STS_ID' 					=> EEM_Registration::status_id_approved,
865 865
 				'REG_deleted' 				=> 0,
866 866
 				'Ticket.Datetime.DTT_ID' 	=> $this->ID(),
867
-			) )
867
+			))
868 868
 		);
869
-		$this->set( 'DTT_sold', $count_regs_for_this_datetime );
869
+		$this->set('DTT_sold', $count_regs_for_this_datetime);
870 870
 		$this->save();
871 871
 		return $count_regs_for_this_datetime;
872 872
 	}
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 1 patch
Spacing   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
  *
22 22
  * ------------------------------------------------------------------------
23 23
  */
24
-require_once ( EE_MODELS . 'EEM_Soft_Delete_Base.model.php' );
25
-require_once ( EE_CLASSES . 'EE_Datetime.class.php' );
24
+require_once (EE_MODELS.'EEM_Soft_Delete_Base.model.php');
25
+require_once (EE_CLASSES.'EE_Datetime.class.php');
26 26
 
27 27
 class EEM_Datetime extends EEM_Soft_Delete_Base {
28 28
 
@@ -35,28 +35,28 @@  discard block
 block discarded – undo
35 35
 	 *		@access private
36 36
 	 *		@param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
37 37
 	 */
38
-	protected function __construct( $timezone ) {
39
-		$this->singular_item = __('Datetime','event_espresso');
40
-		$this->plural_item = __('Datetimes','event_espresso');
38
+	protected function __construct($timezone) {
39
+		$this->singular_item = __('Datetime', 'event_espresso');
40
+		$this->plural_item = __('Datetimes', 'event_espresso');
41 41
 
42 42
 		$this->_tables = array(
43 43
 			'Datetime'=> new EE_Primary_Table('esp_datetime', 'DTT_ID')
44 44
 		);
45 45
 		$this->_fields = array(
46 46
 			'Datetime'=>array(
47
-				'DTT_ID'=> new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID','event_espresso')),
48
-				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID','event_espresso'), false, 0, 'Event'),
47
+				'DTT_ID'=> new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
48
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
49 49
 				'DTT_name' => new EE_Plain_Text_Field('DTT_name', __('Datetime Name', 'event_espresso'), false, ''),
50 50
 				'DTT_description' => new EE_Full_HTML_Field('DTT_description', __('Description for Datetime', 'event_espresso'), false, ''),
51
-				'DTT_EVT_start'=>new EE_Datetime_Field('DTT_EVT_start', __('Start time/date of Event','event_espresso'), false, time(), $timezone ),
52
-				'DTT_EVT_end'=>new EE_Datetime_Field('DTT_EVT_end', __('End time/date of Event','event_espresso'), false, time(), $timezone ),
53
-				'DTT_reg_limit'=>new EE_Infinite_Integer_Field('DTT_reg_limit', __('Registration Limit for this time','event_espresso'), true, EE_INF),
54
-				'DTT_sold'=>new EE_Integer_Field('DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0 ),
55
-				'DTT_reserved' => new EE_Integer_Field('DTT_reserved',__('Quantity of tickets that are reserved, but not yet fully purchased','event_espresso'),false,0),
56
-				'DTT_is_primary'=>new EE_Boolean_Field('DTT_is_primary', __("Flag indicating datetime is primary one for event", "event_espresso"), false,false),
51
+				'DTT_EVT_start'=>new EE_Datetime_Field('DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, time(), $timezone),
52
+				'DTT_EVT_end'=>new EE_Datetime_Field('DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, time(), $timezone),
53
+				'DTT_reg_limit'=>new EE_Infinite_Integer_Field('DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
54
+				'DTT_sold'=>new EE_Integer_Field('DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0),
55
+				'DTT_reserved' => new EE_Integer_Field('DTT_reserved', __('Quantity of tickets that are reserved, but not yet fully purchased', 'event_espresso'), false, 0),
56
+				'DTT_is_primary'=>new EE_Boolean_Field('DTT_is_primary', __("Flag indicating datetime is primary one for event", "event_espresso"), false, false),
57 57
 				'DTT_order' => new EE_Integer_Field('DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0),
58
-				'DTT_parent' => new EE_Integer_Field('DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0 ),
59
-				'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false ),
58
+				'DTT_parent' => new EE_Integer_Field('DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0),
59
+				'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false),
60 60
 			));
61 61
 		$this->_model_relations = array(
62 62
 			'Ticket'=>new EE_HABTM_Relation('Datetime_Ticket'),
@@ -65,11 +65,11 @@  discard block
 block discarded – undo
65 65
 		);
66 66
 		$this->_model_chain_to_wp_user = 'Event';
67 67
 		//this model is generally available for reading
68
-		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( 'Event' );
69
-		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event' );
70
-		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event' );
71
-		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event', EEM_Base::caps_edit );
72
-		parent::__construct( $timezone );
68
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
69
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
70
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
71
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event', EEM_Base::caps_edit);
72
+		parent::__construct($timezone);
73 73
 	}
74 74
 
75 75
 
@@ -84,16 +84,16 @@  discard block
 block discarded – undo
84 84
 	public function create_new_blank_datetime() {
85 85
 		$blank_datetime = EE_Datetime::new_instance(
86 86
 			array(
87
-				'DTT_EVT_start' => $this->current_time_for_query( 'DTT_EVT_start', true ) + (60 * 60 * 24 * 30),
88
-				'DTT_EVT_end' => $this->current_time_for_query( 'DTT_EVT_end', true ) + (60 * 60 * 24 * 30),
87
+				'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + (60 * 60 * 24 * 30),
88
+				'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + (60 * 60 * 24 * 30),
89 89
 				'DTT_order' => 1,
90 90
 				'DTT_reg_limit' => EE_INF
91 91
 			),
92 92
 			$this->_timezone
93 93
 		);
94
-		$blank_datetime->set_start_time( $this->convert_datetime_for_query( 'DTT_EVT_start', '8am', 'ga', $this->_timezone ) );
95
-		$blank_datetime->set_end_time( $this->convert_datetime_for_query( 'DTT_EVT_end', '5pm', 'ga', $this->_timezone ) );
96
-		return array( $blank_datetime );
94
+		$blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga', $this->_timezone));
95
+		$blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $this->_timezone));
96
+		return array($blank_datetime);
97 97
 	}
98 98
 
99 99
 
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
 	* 		@param		int 			$EVT_ID
108 108
 	*		@return 		EE_Datetime[]		array on success, FALSE on fail
109 109
 	*/
110
-	public function get_all_event_dates( $EVT_ID = 0 ) {
111
-		if ( ! $EVT_ID ) { // on add_new_event event_id gets set to 0
110
+	public function get_all_event_dates($EVT_ID = 0) {
111
+		if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
112 112
 			return $this->create_new_blank_datetime();
113 113
 		}
114
-		$results =  $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
114
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
115 115
 
116
-		if ( empty( $results ) ) {
116
+		if (empty($results)) {
117 117
 			return $this->create_new_blank_datetime();
118 118
 		}
119 119
 
@@ -134,26 +134,26 @@  discard block
 block discarded – undo
134 134
 	 *                        	the given number
135 135
 	 * @return EE_Datetime[]
136 136
 	 */
137
-	public function get_datetimes_for_event_ordered_by_DTT_order( $EVT_ID, $include_expired = TRUE, $include_deleted= TRUE, $limit = NULL  ) {
137
+	public function get_datetimes_for_event_ordered_by_DTT_order($EVT_ID, $include_expired = TRUE, $include_deleted = TRUE, $limit = NULL) {
138 138
 
139 139
 		//sanitize EVT_ID
140
-		$EVT_ID = intval( $EVT_ID );
140
+		$EVT_ID = intval($EVT_ID);
141 141
 
142 142
 		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
143
-		$this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db );
144
-		$where_params = array( 'Event.EVT_ID' => $EVT_ID );
143
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
144
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
145 145
 
146
-		$query_params = ! empty( $limit ) ? array( $where_params, 'limit' => $limit, 'order_by' => array( 'DTT_order' => 'ASC' ), 'default_where_conditions' => 'none' ) : array( $where_params, 'order_by' => array( 'DTT_order' => 'ASC' ), 'default_where_conditions' => 'none' );
146
+		$query_params = ! empty($limit) ? array($where_params, 'limit' => $limit, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none') : array($where_params, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none');
147 147
 
148
-		if( ! $include_expired){
149
-			$query_params[0]['DTT_EVT_end'] = array( '>=', current_time( 'mysql', TRUE ) );
148
+		if ( ! $include_expired) {
149
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE));
150 150
 		}
151
-		if( $include_deleted){
152
-			$query_params[0]['DTT_deleted'] = array( 'IN', array( TRUE, FALSE ));
151
+		if ($include_deleted) {
152
+			$query_params[0]['DTT_deleted'] = array('IN', array(TRUE, FALSE));
153 153
 		}
154 154
 
155
-		$result = $this->get_all( $query_params );
156
-		$this->assume_values_already_prepared_by_model_object( $old_assumption );
155
+		$result = $this->get_all($query_params);
156
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
157 157
 		return $result;
158 158
 	}
159 159
 
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 	 * @param int $limit
169 169
 	 * @return EE_Datetime[]
170 170
 	 */
171
-	public function get_datetimes_for_event_ordered_by_importance( $EVT_ID = 0, $limit = NULL){
172
-		return $this->get_all( array(array('Event.EVT_ID'=>$EVT_ID),
171
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = NULL) {
172
+		return $this->get_all(array(array('Event.EVT_ID'=>$EVT_ID),
173 173
 			'limit'=>$limit,
174 174
 			'order_by'=>array('DTT_EVT_start'=>'ASC'),
175 175
 			'default_where_conditions' => 'none'));
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
 	 * @param boolean $include_deleted
185 185
 	 * @return EE_Datetime
186 186
 	 */
187
-	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false,$include_deleted = false){
188
-		$results =  $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
189
-		if($results){
187
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) {
188
+		$results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
189
+		if ($results) {
190 190
 			return array_shift($results);
191
-		}else{
191
+		} else {
192 192
 			return NULL;
193 193
 		}
194 194
 	}
@@ -202,16 +202,16 @@  discard block
 block discarded – undo
202 202
 	 * @param bool $try_to_exclude_deleted
203 203
 	 * @return \EE_Datetime
204 204
 	 */
205
-	public function get_primary_datetime_for_event($EVT_ID,$try_to_exclude_expired = true, $try_to_exclude_deleted = true){
206
-		if($try_to_exclude_expired){
207
-			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false,false);
208
-			if($non_expired){
205
+	public function get_primary_datetime_for_event($EVT_ID, $try_to_exclude_expired = true, $try_to_exclude_deleted = true) {
206
+		if ($try_to_exclude_expired) {
207
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
208
+			if ($non_expired) {
209 209
 				return $non_expired;
210 210
 			}
211 211
 		}
212
-		if($try_to_exclude_deleted){
212
+		if ($try_to_exclude_deleted) {
213 213
 			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
214
-			if($expired_even){
214
+			if ($expired_even) {
215 215
 				return $expired_even;
216 216
 			}
217 217
 		}
@@ -230,23 +230,23 @@  discard block
 block discarded – undo
230 230
 	 * @param int $limit
231 231
 	 * @return EE_Datetime[]
232 232
 	 */
233
-	public function get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired = true, $include_deleted= true, $limit = NULL ){
233
+	public function get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) {
234 234
 		//sanitize EVT_ID
235
-		$EVT_ID = intval( $EVT_ID );
235
+		$EVT_ID = intval($EVT_ID);
236 236
 		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
237
-		$this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db );
238
-		$query_params =array(array('Event.EVT_ID'=>$EVT_ID),'order_by'=>array('DTT_EVT_start'=>'asc'));
239
-		if( ! $include_expired){
240
-			$query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE));
237
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
238
+		$query_params = array(array('Event.EVT_ID'=>$EVT_ID), 'order_by'=>array('DTT_EVT_start'=>'asc'));
239
+		if ( ! $include_expired) {
240
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE));
241 241
 		}
242
-		if( $include_deleted){
243
-			$query_params[0]['DTT_deleted'] = array('IN',array(true,false));
242
+		if ($include_deleted) {
243
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
244 244
 		}
245
-		if($limit){
245
+		if ($limit) {
246 246
 			$query_params['limit'] = $limit;
247 247
 		}
248
-		$result = $this->get_all( $query_params );
249
-		$this->assume_values_already_prepared_by_model_object( $old_assumption );
248
+		$result = $this->get_all($query_params);
249
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
250 250
 		return $result;
251 251
 	}
252 252
 
@@ -259,23 +259,23 @@  discard block
 block discarded – undo
259 259
 	 * @param int $limit
260 260
 	 * @return EE_Datetime[]
261 261
 	 */
262
-	public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted= true, $limit = NULL){
262
+	public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) {
263 263
 		//sanitize TKT_ID
264
-		$TKT_ID =  intval( $TKT_ID );
264
+		$TKT_ID = intval($TKT_ID);
265 265
 		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
266
-		$this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db );
267
-		$query_params =array(array('Ticket.TKT_ID'=>$TKT_ID),'order_by'=>array('DTT_EVT_start'=>'asc'));
268
-		if( ! $include_expired){
269
-			$query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE));
266
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
267
+		$query_params = array(array('Ticket.TKT_ID'=>$TKT_ID), 'order_by'=>array('DTT_EVT_start'=>'asc'));
268
+		if ( ! $include_expired) {
269
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE));
270 270
 		}
271
-		if( $include_deleted){
272
-			$query_params[0]['DTT_deleted'] = array('IN',array(true,false));
271
+		if ($include_deleted) {
272
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
273 273
 		}
274
-		if($limit){
274
+		if ($limit) {
275 275
 			$query_params['limit'] = $limit;
276 276
 		}
277
-		$result = $this->get_all( $query_params );
278
-		$this->assume_values_already_prepared_by_model_object( $old_assumption );
277
+		$result = $this->get_all($query_params);
278
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
279 279
 		return $result;
280 280
 	}
281 281
 
@@ -291,24 +291,24 @@  discard block
 block discarded – undo
291 291
 	 *                                  that number
292 292
 	 * @return EE_Datetime[]
293 293
 	 */
294
-	public function get_datetimes_for_ticket_ordered_by_DTT_order( $TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL ) {
294
+	public function get_datetimes_for_ticket_ordered_by_DTT_order($TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) {
295 295
 		//sanitize id.
296
-		$TKT_ID =  intval( $TKT_ID );
296
+		$TKT_ID = intval($TKT_ID);
297 297
 		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
298
-		$this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db );
299
-		$where_params = array( 'Ticket.TKT_ID' => $TKT_ID );
300
-		$query_params = array( $where_params, 'order_by' => array( 'DTT_order' => 'ASC' ) );
301
-		if( ! $include_expired){
302
-			$query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE));
298
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
299
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
300
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
301
+		if ( ! $include_expired) {
302
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE));
303 303
 		}
304
-		if( $include_deleted){
305
-			$query_params[0]['DTT_deleted'] = array('IN',array(true,false));
304
+		if ($include_deleted) {
305
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
306 306
 		}
307
-		if($limit){
307
+		if ($limit) {
308 308
 			$query_params['limit'] = $limit;
309 309
 		}
310
-		$result = $this->get_all( $query_params );
311
-		$this->assume_values_already_prepared_by_model_object( $old_assumption );
310
+		$result = $this->get_all($query_params);
311
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
312 312
 		return $result;
313 313
 	}
314 314
 
@@ -319,11 +319,11 @@  discard block
 block discarded – undo
319 319
 	 * @param int $EVT_ID
320 320
 	 * @return EE_Datetime
321 321
 	 */
322
-	public function get_most_important_datetime_for_event($EVT_ID){
322
+	public function get_most_important_datetime_for_event($EVT_ID) {
323 323
 		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
324
-		if($results){
324
+		if ($results) {
325 325
 			return array_shift($results);
326
-		}else{
326
+		} else {
327 327
 			return null;
328 328
 		}
329 329
 	}
@@ -342,78 +342,78 @@  discard block
 block discarded – undo
342 342
 	 * 			- inactive = Events that are either not published.
343 343
 	 * @return wpdb results array
344 344
 	 */
345
-	public function get_dtt_months_and_years( $where_params, $evt_active_status = '' ) {
346
-		$current_time_for_DTT_EVT_start = $this->current_time_for_query( 'DTT_EVT_start' );
347
-		$current_time_for_DTT_EVT_end = $this->current_time_for_query( 'DTT_EVT_end' );
345
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '') {
346
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
347
+		$current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
348 348
 
349
-		switch ( $evt_active_status ) {
349
+		switch ($evt_active_status) {
350 350
 			case 'upcoming' :
351 351
 					$where_params['Event.status'] = 'publish';
352 352
 					//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
353
-					if ( isset( $where_params['DTT_EVT_start'] ) ) {
353
+					if (isset($where_params['DTT_EVT_start'])) {
354 354
 						$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
355 355
 					}
356
-					$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start );
356
+					$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
357 357
 					break;
358 358
 
359 359
 			case 'expired' :
360
-				if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] );
360
+				if (isset($where_params['Event.status'])) unset($where_params['Event.status']);
361 361
 				//get events to exclude
362
-				$exclude_query[0] = array_merge( $where_params, array( 'DTT_EVT_end' => array( '>', $current_time_for_DTT_EVT_end ) ) );
362
+				$exclude_query[0] = array_merge($where_params, array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
363 363
 				//first get all events that have datetimes where its not expired.
364
-				$event_ids = $this->_get_all_wpdb_results( $exclude_query, OBJECT_K, 'Datetime.EVT_ID' );
365
-				$event_ids = array_keys( $event_ids );
364
+				$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
365
+				$event_ids = array_keys($event_ids);
366 366
 
367
-				if ( isset( $where_params['DTT_EVT_end'] ) ) {
367
+				if (isset($where_params['DTT_EVT_end'])) {
368 368
 					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
369 369
 				}
370
-				$where_params['DTT_EVT_end'] = array( '<', $current_time_for_DTT_EVT_end );
371
-				$where_params['Event.EVT_ID'] = array( 'NOT IN', $event_ids );
370
+				$where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
371
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
372 372
 				break;
373 373
 
374 374
 			case 'active' :
375 375
 				$where_params['Event.status'] = 'publish';
376
-				if ( isset( $where_params['DTT_EVT_start'] ) ) {
376
+				if (isset($where_params['DTT_EVT_start'])) {
377 377
 					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
378 378
 				}
379
-				if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) {
379
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
380 380
 					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
381 381
 				}
382
-				$where_params['DTT_EVT_start'] = array('<',  $current_time_for_DTT_EVT_start );
383
-				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end );
382
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
383
+				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
384 384
 				break;
385 385
 
386 386
 			case 'inactive' :
387
-				if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] );
388
-				if ( isset( $where_params['OR'] ) ) {
387
+				if (isset($where_params['Event.status'])) unset($where_params['Event.status']);
388
+				if (isset($where_params['OR'])) {
389 389
 					$where_params['AND']['OR'] = $where_params['OR'];
390 390
 				}
391
-				if ( isset( $where_params['DTT_EVT_end'] ) ) {
391
+				if (isset($where_params['DTT_EVT_end'])) {
392 392
 					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
393
-					unset( $where_params['DTT_EVT_end'] );
393
+					unset($where_params['DTT_EVT_end']);
394 394
 				}
395 395
 
396
-				if ( isset( $where_params['DTT_EVT_start'] ) ) {
396
+				if (isset($where_params['DTT_EVT_start'])) {
397 397
 					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
398
-					unset( $where_params['DTT_EVT_start'] );
398
+					unset($where_params['DTT_EVT_start']);
399 399
 				}
400
-				$where_params['AND']['Event.status'] = array( '!=', 'publish' );
400
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
401 401
 				break;
402 402
 		}
403 403
 
404 404
 		$query_params[0] = $where_params;
405 405
 		$query_params['group_by'] = array('dtt_year', 'dtt_month');
406
-		$query_params['order_by'] = array( 'DTT_EVT_start' => 'DESC' );
406
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
407 407
 
408
-		EE_Registry::instance()->load_helper( 'DTT_Helper' );
409
-		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'DTT_EVT_start' );
408
+		EE_Registry::instance()->load_helper('DTT_Helper');
409
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
410 410
 
411 411
 		$columns_to_select = array(
412
-			'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'),
413
-			'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'),
414
-			'dtt_month_num' => array('MONTH(' . $query_interval .')', '%s')
412
+			'dtt_year' => array('YEAR('.$query_interval.')', '%s'),
413
+			'dtt_month' => array('MONTHNAME('.$query_interval.')', '%s'),
414
+			'dtt_month_num' => array('MONTH('.$query_interval.')', '%s')
415 415
 			);
416
-		return $this->_get_all_wpdb_results( $query_params, OBJECT, $columns_to_select );
416
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
417 417
 	}
418 418
 
419 419
 	/**
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
 	 * for the tickets for each datetime)
422 422
 	 * @param EE_Datetime[] $datetimes
423 423
 	 */
424
-	public function update_sold($datetimes){
425
-		foreach($datetimes as $datetime){
424
+	public function update_sold($datetimes) {
425
+		foreach ($datetimes as $datetime) {
426 426
 			$datetime->update_sold();
427 427
 		}
428 428
 	}
@@ -437,10 +437,10 @@  discard block
 block discarded – undo
437 437
 	 * @param array $query_params
438 438
 	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO tickets attached to datetime then FALSE is returned.
439 439
 	 */
440
-	public function sum_tickets_currently_available_at_datetime( $DTT_ID, $query_params = array() ) {
441
-		$datetime = $this->get_one_by_ID( $DTT_ID );
442
-		if ( $datetime instanceof EE_Datetime ) {
443
-			return $datetime->tickets_remaining( $query_params );
440
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) {
441
+		$datetime = $this->get_one_by_ID($DTT_ID);
442
+		if ($datetime instanceof EE_Datetime) {
443
+			return $datetime->tickets_remaining($query_params);
444 444
 		}
445 445
 		return 0;
446 446
 	}
@@ -462,36 +462,36 @@  discard block
 block discarded – undo
462 462
 	 *                EE_Datetime::upcoming
463 463
 	 *                EE_Datetime::expired
464 464
 	 */
465
-	public function get_datetime_counts_by_status( $stati_to_include = array(), $query_params = array() ) {
465
+	public function get_datetime_counts_by_status($stati_to_include = array(), $query_params = array()) {
466 466
 		//only accept where conditions for this query.
467
-		$_where = isset( $query_params[0] ) ? $query_params[0] : array();
467
+		$_where = isset($query_params[0]) ? $query_params[0] : array();
468 468
 		$status_query_args = array(
469 469
 				EE_Datetime::active => array_merge(
470 470
 						$_where,
471
-						array( 'DTT_EVT_start' => array( '<', time() ), 'DTT_EVT_end' => array( '>', time() ) )
471
+						array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
472 472
 				),
473 473
 				EE_Datetime::upcoming => array_merge(
474 474
 						$_where,
475
-						array( 'DTT_EVT_start' => array( '>', time() ) )
475
+						array('DTT_EVT_start' => array('>', time()))
476 476
 				),
477 477
 				EE_Datetime::expired => array_merge(
478 478
 						$_where,
479
-						array( 'DTT_EVT_end' => array('<', time() ) )
479
+						array('DTT_EVT_end' => array('<', time()))
480 480
 				)
481 481
 		);
482 482
 
483
-		if ( ! empty( $stati_to_include ) ) {
484
-			foreach( array_keys( $status_query_args ) as $status ) {
485
-				if ( ! in_array( $status, $stati_to_include ) ) {
486
-					unset( $status_query_args[$status] );
483
+		if ( ! empty($stati_to_include)) {
484
+			foreach (array_keys($status_query_args) as $status) {
485
+				if ( ! in_array($status, $stati_to_include)) {
486
+					unset($status_query_args[$status]);
487 487
 				}
488 488
 			}
489 489
 		}
490 490
 
491 491
 		//loop through and query counts for each stati.
492 492
 		$status_query_results = array();
493
-		foreach( $status_query_args as $status => $status_where_conditions ) {
494
-			$status_query_results[ $status ] = EEM_Datetime::count( array( $status_where_conditions ), 'DTT_ID', true );
493
+		foreach ($status_query_args as $status => $status_where_conditions) {
494
+			$status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
495 495
 		}
496 496
 
497 497
 		return $status_query_results;
@@ -505,9 +505,9 @@  discard block
 block discarded – undo
505 505
 	 * @param array $query_params
506 506
 	 * @return int
507 507
 	 */
508
-	public function get_datetime_count_for_status( $status = EE_Datetime::active, $query_params = array() ) {
509
-		$count = $this->get_datetime_counts_by_status( array( $status ), $query_params );
510
-		return ! empty( $count[$status] ) ? $count[$status] : 0;
508
+	public function get_datetime_count_for_status($status = EE_Datetime::active, $query_params = array()) {
509
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
510
+		return ! empty($count[$status]) ? $count[$status] : 0;
511 511
 	}
512 512
 
513 513
 
Please login to merge, or discard this patch.