@@ -503,7 +503,7 @@ |
||
503 | 503 | * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
504 | 504 | * allowed) |
505 | 505 | * @param string $datetime_string mysql timestamp in UTC |
506 | - * @return mixed null | DateTime |
|
506 | + * @return null|DateTime null | DateTime |
|
507 | 507 | */ |
508 | 508 | public function prepare_for_set_from_db( $datetime_string ) { |
509 | 509 | //if $datetime_value is empty, and ! $this->_nullable, just use time() |
@@ -2,14 +2,14 @@ |
||
2 | 2 | exit( 'No direct script access allowed' ); |
3 | 3 | } |
4 | 4 | /** |
5 | - * EE_Datetime_Field |
|
6 | - * |
|
7 | - * Text_Fields is a base class for any fields which are have integer value. (Exception: foreign and private key fields. Wish PHP had multiple-inheritance for this...) |
|
8 | - * |
|
9 | - * @package Event Espresso |
|
10 | - * @subpackage /core/db_models/fields/EE_Datetime_Field.php |
|
11 | - * @author Darren Ethier |
|
12 | - */ |
|
5 | + * EE_Datetime_Field |
|
6 | + * |
|
7 | + * Text_Fields is a base class for any fields which are have integer value. (Exception: foreign and private key fields. Wish PHP had multiple-inheritance for this...) |
|
8 | + * |
|
9 | + * @package Event Espresso |
|
10 | + * @subpackage /core/db_models/fields/EE_Datetime_Field.php |
|
11 | + * @author Darren Ethier |
|
12 | + */ |
|
13 | 13 | class EE_Datetime_Field extends EE_Model_Field_Base { |
14 | 14 | |
15 | 15 | /** |
@@ -459,7 +459,7 @@ |
||
459 | 459 | //must be explicit because schema could equal true. |
460 | 460 | if( $schema === 'no_html' ){ |
461 | 461 | $timezone_string = ' (' . $DateTime->format( 'T' ) . ')'; |
462 | - }else{ |
|
462 | + } else{ |
|
463 | 463 | $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format( 'T' ) . ')</span>'; |
464 | 464 | } |
465 | 465 | } else { |
@@ -1,5 +1,5 @@ discard block |
||
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 | * EE_Datetime_Field |
@@ -111,16 +111,16 @@ discard block |
||
111 | 111 | * @param string $pretty_date_format |
112 | 112 | * @param string $pretty_time_format |
113 | 113 | */ |
114 | - public function __construct( $table_column, $nice_name, $nullable, $default_value, $timezone_string = '', $date_format = '', $time_format = '', $pretty_date_format = '', $pretty_time_format = '' ){ |
|
114 | + public function __construct($table_column, $nice_name, $nullable, $default_value, $timezone_string = '', $date_format = '', $time_format = '', $pretty_date_format = '', $pretty_time_format = '') { |
|
115 | 115 | |
116 | - $this->_date_format = ! empty( $date_format ) ? $date_format : get_option('date_format'); |
|
117 | - $this->_time_format = ! empty( $time_format ) ? $time_format : get_option('time_format'); |
|
118 | - $this->_pretty_date_format = ! empty( $pretty_date_format ) ? $pretty_date_format : get_option('date_format'); |
|
119 | - $this->_pretty_time_format = ! empty( $pretty_time_format ) ? $pretty_time_format : get_option('time_format'); |
|
116 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
117 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
118 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
119 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
120 | 120 | |
121 | - parent::__construct( $table_column, $nice_name, $nullable, $default_value ); |
|
121 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
122 | 122 | EE_Registry::instance()->load_helper('DTT_Helper'); |
123 | - $this->set_timezone( $timezone_string ); |
|
123 | + $this->set_timezone($timezone_string); |
|
124 | 124 | |
125 | 125 | } |
126 | 126 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @return DateTimeZone |
140 | 140 | */ |
141 | 141 | public function get_UTC_DateTimeZone() { |
142 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone ? $this->_UTC_DateTimeZone : $this->_create_timezone_object_from_timezone_string( 'UTC' ); |
|
142 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone ? $this->_UTC_DateTimeZone : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @return DateTimeZone |
149 | 149 | */ |
150 | 150 | public function get_blog_DateTimeZone() { |
151 | - return $this->_blog_DateTimeZone instanceof DateTimeZone ? $this->_blog_DateTimeZone : $this->_create_timezone_object_from_timezone_string( '' ); |
|
151 | + return $this->_blog_DateTimeZone instanceof DateTimeZone ? $this->_blog_DateTimeZone : $this->_create_timezone_object_from_timezone_string(''); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix timestamp |
159 | 159 | * @return DateTime |
160 | 160 | */ |
161 | - public function prepare_for_set( $value_inputted_for_field_on_model_object ) { |
|
162 | - return $this->_get_date_object( $value_inputted_for_field_on_model_object ); |
|
161 | + public function prepare_for_set($value_inputted_for_field_on_model_object) { |
|
162 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * @param bool $pretty If we're returning the pretty formats or standard format string. |
176 | 176 | * @return string The final assembled format string. |
177 | 177 | */ |
178 | - protected function _get_date_time_output( $pretty = FALSE ) { |
|
178 | + protected function _get_date_time_output($pretty = FALSE) { |
|
179 | 179 | |
180 | - switch ( $this->_date_time_output ) { |
|
180 | + switch ($this->_date_time_output) { |
|
181 | 181 | case 'time' : |
182 | 182 | return $pretty ? $this->_pretty_time_format : $this->_time_format; |
183 | 183 | break; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | break; |
188 | 188 | |
189 | 189 | default : |
190 | - return $pretty ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format : $this->_date_format . ' ' . $this->_time_format; |
|
190 | + return $pretty ? $this->_pretty_date_format.' '.$this->_pretty_time_format : $this->_date_format.' '.$this->_time_format; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @param string $what acceptable values are 'time' or 'date'. Any other value will be set but will always result in both 'date' and 'time' being returned. |
202 | 202 | * @return void |
203 | 203 | */ |
204 | - public function set_date_time_output( $what = NULL ) { |
|
204 | + public function set_date_time_output($what = NULL) { |
|
205 | 205 | $this->_date_time_output = $what; |
206 | 206 | } |
207 | 207 | |
@@ -217,15 +217,15 @@ discard block |
||
217 | 217 | * @param string $timezone_string A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
218 | 218 | * @return void |
219 | 219 | */ |
220 | - public function set_timezone( $timezone_string ) { |
|
221 | - if( empty( $timezone_string ) && $this->_timezone_string != NULL ){ |
|
220 | + public function set_timezone($timezone_string) { |
|
221 | + if (empty($timezone_string) && $this->_timezone_string != NULL) { |
|
222 | 222 | // leave the timezone AS-IS if we already have one and |
223 | 223 | // the function arg didn't provide one |
224 | 224 | return; |
225 | 225 | } |
226 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string( $timezone_string ); |
|
227 | - $this->_timezone_string = ! empty( $timezone_string ) ? $timezone_string : 'UTC'; |
|
228 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string( $this->_timezone_string ); |
|
226 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
227 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
228 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | * @param string $timezone_string |
238 | 238 | * @return \DateTimeZone |
239 | 239 | */ |
240 | - protected function _create_timezone_object_from_timezone_string( $timezone_string = '' ) { |
|
241 | - return new DateTimeZone( EEH_DTT_Helper::get_valid_timezone_string( $timezone_string ) ); |
|
240 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') { |
|
241 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | * @param bool $pretty Whether to set pretty format or not. |
264 | 264 | * @return void |
265 | 265 | */ |
266 | - public function set_date_format( $format, $pretty = false ) { |
|
267 | - if ( $pretty ) { |
|
266 | + public function set_date_format($format, $pretty = false) { |
|
267 | + if ($pretty) { |
|
268 | 268 | $this->_pretty_date_format = $format; |
269 | 269 | } else { |
270 | 270 | $this->_date_format = $format; |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | * @param bool $pretty Whether to get pretty format or not. |
280 | 280 | * @return string |
281 | 281 | */ |
282 | - public function get_date_format( $pretty = false ) { |
|
282 | + public function get_date_format($pretty = false) { |
|
283 | 283 | return $pretty ? $this->_pretty_date_format : $this->_date_format; |
284 | 284 | } |
285 | 285 | |
@@ -294,8 +294,8 @@ discard block |
||
294 | 294 | * @param bool $pretty Whether to set pretty format or not. |
295 | 295 | * @return void |
296 | 296 | */ |
297 | - public function set_time_format( $format, $pretty = false ) { |
|
298 | - if ( $pretty ) { |
|
297 | + public function set_time_format($format, $pretty = false) { |
|
298 | + if ($pretty) { |
|
299 | 299 | $this->_pretty_time_format = $format; |
300 | 300 | } else { |
301 | 301 | $this->_time_format = $format; |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @param bool $pretty Whether to get pretty format or not. |
311 | 311 | * @return string |
312 | 312 | */ |
313 | - public function get_time_format( $pretty = false ) { |
|
313 | + public function get_time_format($pretty = false) { |
|
314 | 314 | return $pretty ? $this->_pretty_time_format : $this->_time_format; |
315 | 315 | } |
316 | 316 | |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
326 | 326 | * @return void |
327 | 327 | */ |
328 | - public function set_pretty_date_format( $format ) { |
|
328 | + public function set_pretty_date_format($format) { |
|
329 | 329 | $this->_pretty_date_format = $format; |
330 | 330 | } |
331 | 331 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
343 | 343 | * @return void |
344 | 344 | */ |
345 | - public function set_pretty_time_format( $format ) { |
|
345 | + public function set_pretty_time_format($format) { |
|
346 | 346 | $this->_pretty_time_format = $format; |
347 | 347 | } |
348 | 348 | |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | * @param DateTime $current current DateTime object for the datetime field |
355 | 355 | * @return DateTime |
356 | 356 | */ |
357 | - public function prepare_for_set_with_new_time( $time_to_set_string, DateTime $current ){ |
|
357 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) { |
|
358 | 358 | //if $time_to_set_string is datetime object, then let's use it to set the parse array. Otherwise parse the string. |
359 | - if ( $time_to_set_string instanceof DateTime ) { |
|
359 | + if ($time_to_set_string instanceof DateTime) { |
|
360 | 360 | $parsed = array( |
361 | 361 | 'hour' => $time_to_set_string->format('H'), |
362 | 362 | 'minute' => $time_to_set_string->format('i'), |
@@ -364,12 +364,12 @@ discard block |
||
364 | 364 | ); |
365 | 365 | } else { |
366 | 366 | //parse incoming string |
367 | - $parsed = date_parse_from_format( $this->_time_format, $time_to_set_string ); |
|
367 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | //make sure $current is in the correct timezone. |
371 | - $current->setTimezone( $this->_DateTimeZone ); |
|
372 | - return $current->setTime( $parsed['hour'], $parsed['minute'], $parsed['second'] ); |
|
371 | + $current->setTimezone($this->_DateTimeZone); |
|
372 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -380,9 +380,9 @@ discard block |
||
380 | 380 | * @param DateTime $current current DateTime object for the datetime field |
381 | 381 | * @return DateTime |
382 | 382 | */ |
383 | - public function prepare_for_set_with_new_date( $date_to_set_string, DateTime $current ){ |
|
383 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) { |
|
384 | 384 | //if $time_to_set_string is datetime object, then let's use it to set the parse array. Otherwise parse the string. |
385 | - if ( $date_to_set_string instanceof DateTime ) { |
|
385 | + if ($date_to_set_string instanceof DateTime) { |
|
386 | 386 | $parsed = array( |
387 | 387 | 'year' => $date_to_set_string->format('Y'), |
388 | 388 | 'month' => $date_to_set_string->format('m'), |
@@ -390,12 +390,12 @@ discard block |
||
390 | 390 | ); |
391 | 391 | } else { |
392 | 392 | //parse incoming string |
393 | - $parsed = date_parse_from_format( $this->_date_format, $date_to_set_string ); |
|
393 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | //make sure $current is in the correct timezone |
397 | - $current->setTimezone( $this->_DateTimeZone ); |
|
398 | - return $current->setDate( $parsed['year'], $parsed['month'], $parsed['day'] ); |
|
397 | + $current->setTimezone($this->_DateTimeZone); |
|
398 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | * @param DateTime $DateTime |
408 | 408 | * @return string formatted date time for given timezone |
409 | 409 | */ |
410 | - public function prepare_for_get( $DateTime ) { |
|
411 | - return $this->_prepare_for_display( $DateTime ); |
|
410 | + public function prepare_for_get($DateTime) { |
|
411 | + return $this->_prepare_for_display($DateTime); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | |
@@ -423,8 +423,8 @@ discard block |
||
423 | 423 | * @param null $schema |
424 | 424 | * @return string |
425 | 425 | */ |
426 | - public function prepare_for_pretty_echoing( $DateTime, $schema = null ) { |
|
427 | - return $this->_prepare_for_display( $DateTime, $schema ? $schema : true ); |
|
426 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) { |
|
427 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | |
@@ -438,36 +438,36 @@ discard block |
||
438 | 438 | * @return string |
439 | 439 | * @throws \EE_Error |
440 | 440 | */ |
441 | - protected function _prepare_for_display( $DateTime, $schema = false ) { |
|
442 | - if ( ! $DateTime instanceof DateTime ) { |
|
443 | - if ( $this->_nullable ) { |
|
441 | + protected function _prepare_for_display($DateTime, $schema = false) { |
|
442 | + if ( ! $DateTime instanceof DateTime) { |
|
443 | + if ($this->_nullable) { |
|
444 | 444 | return ''; |
445 | 445 | } else { |
446 | - if ( WP_DEBUG ) { |
|
447 | - throw new EE_Error( sprintf( __('EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', 'event_espresso' ), $this->_nicename ) ); |
|
446 | + if (WP_DEBUG) { |
|
447 | + throw new EE_Error(sprintf(__('EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', 'event_espresso'), $this->_nicename)); |
|
448 | 448 | } else { |
449 | - $DateTime = new DateTime( "now" ); |
|
450 | - EE_Error::add_error( sprintf( __('EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', 'event_espresso' ), $this->_nicename ) ); |
|
449 | + $DateTime = new DateTime("now"); |
|
450 | + EE_Error::add_error(sprintf(__('EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', 'event_espresso'), $this->_nicename)); |
|
451 | 451 | } |
452 | 452 | } |
453 | 453 | } |
454 | - $format_string = $this->_get_date_time_output( $schema ); |
|
454 | + $format_string = $this->_get_date_time_output($schema); |
|
455 | 455 | //make sure datetime_value is in the correct timezone (in case that's been updated). |
456 | - $DateTime->setTimezone( $this->_DateTimeZone ); |
|
457 | - if ( $schema ) { |
|
458 | - if( $this->_display_timezone() ) { |
|
456 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
457 | + if ($schema) { |
|
458 | + if ($this->_display_timezone()) { |
|
459 | 459 | //must be explicit because schema could equal true. |
460 | - if( $schema === 'no_html' ){ |
|
461 | - $timezone_string = ' (' . $DateTime->format( 'T' ) . ')'; |
|
462 | - }else{ |
|
463 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format( 'T' ) . ')</span>'; |
|
460 | + if ($schema === 'no_html') { |
|
461 | + $timezone_string = ' ('.$DateTime->format('T').')'; |
|
462 | + } else { |
|
463 | + $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>'; |
|
464 | 464 | } |
465 | 465 | } else { |
466 | 466 | $timezone_string = ''; |
467 | 467 | } |
468 | - return $DateTime->format( $format_string ) . $timezone_string; |
|
468 | + return $DateTime->format($format_string).$timezone_string; |
|
469 | 469 | } else { |
470 | - return $DateTime->format( $format_string ); |
|
470 | + return $DateTime->format($format_string); |
|
471 | 471 | } |
472 | 472 | } |
473 | 473 | |
@@ -481,18 +481,18 @@ discard block |
||
481 | 481 | * @return string mysql timestamp in UTC |
482 | 482 | * @throws \EE_Error |
483 | 483 | */ |
484 | - public function prepare_for_use_in_db( $datetime_value ) { |
|
484 | + public function prepare_for_use_in_db($datetime_value) { |
|
485 | 485 | //we allow an empty value or DateTime object, but nothing else. |
486 | - if ( ! empty( $datetime_value ) && ! $datetime_value instanceof DateTime ) { |
|
487 | - throw new EE_Error( __('The incoming value being prepared for setting in the database must either be empty or a php DateTime object', 'event_espresso' ) ); |
|
486 | + if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
487 | + throw new EE_Error(__('The incoming value being prepared for setting in the database must either be empty or a php DateTime object', 'event_espresso')); |
|
488 | 488 | } |
489 | 489 | |
490 | - if ( $datetime_value instanceof DateTime ) { |
|
491 | - return $datetime_value->setTimezone( $this->get_UTC_DateTimeZone() )->format( EE_Datetime_Field::mysql_timestamp_format ); |
|
490 | + if ($datetime_value instanceof DateTime) { |
|
491 | + return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(EE_Datetime_Field::mysql_timestamp_format); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
495 | - return ! $this->_nullable && empty( $datetime_value ) ? current_time( 'mysql', true ) : null; |
|
495 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | |
@@ -505,20 +505,20 @@ discard block |
||
505 | 505 | * @param string $datetime_string mysql timestamp in UTC |
506 | 506 | * @return mixed null | DateTime |
507 | 507 | */ |
508 | - public function prepare_for_set_from_db( $datetime_string ) { |
|
508 | + public function prepare_for_set_from_db($datetime_string) { |
|
509 | 509 | //if $datetime_value is empty, and ! $this->_nullable, just use time() |
510 | - if ( empty( $datetime_string) && $this->_nullable ) { |
|
510 | + if (empty($datetime_string) && $this->_nullable) { |
|
511 | 511 | return null; |
512 | 512 | } |
513 | 513 | // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
514 | - $DateTime = empty( $datetime_string ) ? new DateTime( 'now', $this->get_UTC_DateTimeZone() ) : DateTime::createFromFormat( EE_Datetime_Field::mysql_timestamp_format, $datetime_string, $this->get_UTC_DateTimeZone() ); |
|
514 | + $DateTime = empty($datetime_string) ? new DateTime('now', $this->get_UTC_DateTimeZone()) : DateTime::createFromFormat(EE_Datetime_Field::mysql_timestamp_format, $datetime_string, $this->get_UTC_DateTimeZone()); |
|
515 | 515 | |
516 | - if ( ! $DateTime instanceof DateTime ) { |
|
516 | + if ( ! $DateTime instanceof DateTime) { |
|
517 | 517 | //if still no datetime object, then let's just use now |
518 | - $DateTime = new DateTime( 'now', $this->get_UTC_DateTimeZone() ); |
|
518 | + $DateTime = new DateTime('now', $this->get_UTC_DateTimeZone()); |
|
519 | 519 | } |
520 | 520 | // THEN apply the field's set DateTimeZone |
521 | - $DateTime->setTimezone( $this->_DateTimeZone ); |
|
521 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
522 | 522 | return $DateTime; |
523 | 523 | } |
524 | 524 | |
@@ -535,15 +535,15 @@ discard block |
||
535 | 535 | protected function _display_timezone() { |
536 | 536 | |
537 | 537 | // first let's do a comparison of timezone strings. If they match then we can get out without any further calculations |
538 | - $blog_string = get_option( 'timezone_string' ); |
|
539 | - if ( $blog_string == $this->_timezone_string ) { |
|
538 | + $blog_string = get_option('timezone_string'); |
|
539 | + if ($blog_string == $this->_timezone_string) { |
|
540 | 540 | return FALSE; |
541 | 541 | } |
542 | 542 | // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
543 | - $this_offset = $this->get_timezone_offset( $this->_DateTimeZone ); |
|
544 | - $blog_offset = $this->get_timezone_offset( $this->get_blog_DateTimeZone() ); |
|
543 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
544 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
545 | 545 | // now compare |
546 | - if ( $blog_offset === $this_offset ) { |
|
546 | + if ($blog_offset === $this_offset) { |
|
547 | 547 | return FALSE; |
548 | 548 | } |
549 | 549 | return TRUE; |
@@ -561,24 +561,24 @@ discard block |
||
561 | 561 | * |
562 | 562 | * @return DateTime |
563 | 563 | */ |
564 | - protected function _get_date_object( $date_string ) { |
|
564 | + protected function _get_date_object($date_string) { |
|
565 | 565 | //first if this is an empty date_string and nullable is allowed, just return null. |
566 | - if ( $this->_nullable && empty( $date_string ) ) { |
|
566 | + if ($this->_nullable && empty($date_string)) { |
|
567 | 567 | return null; |
568 | 568 | } |
569 | 569 | |
570 | 570 | // if incoming date |
571 | - if ( $date_string instanceof DateTime ) { |
|
572 | - $date_string->setTimezone( $this->_DateTimeZone ); |
|
571 | + if ($date_string instanceof DateTime) { |
|
572 | + $date_string->setTimezone($this->_DateTimeZone); |
|
573 | 573 | return $date_string; |
574 | 574 | } |
575 | 575 | // if empty date_string and made it here. |
576 | 576 | // Return a datetime object for now in the given timezone. |
577 | - if ( empty( $date_string ) ) { |
|
578 | - return new DateTime( "now", $this->_DateTimeZone ); |
|
577 | + if (empty($date_string)) { |
|
578 | + return new DateTime("now", $this->_DateTimeZone); |
|
579 | 579 | } |
580 | 580 | // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
581 | - if ( preg_match( EE_Datetime_Field::unix_timestamp_regex, $date_string ) ) { |
|
581 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
582 | 582 | try { |
583 | 583 | /** |
584 | 584 | * This is operating under the assumption that the incoming Unix timestamp is |
@@ -586,29 +586,29 @@ discard block |
||
586 | 586 | * current_time('timestamp'); |
587 | 587 | * |
588 | 588 | */ |
589 | - $DateTime = new DateTime( "now", $this->_DateTimeZone ); |
|
590 | - return $DateTime->setTimestamp( $date_string ); |
|
591 | - } catch ( Exception $e ) { |
|
589 | + $DateTime = new DateTime("now", $this->_DateTimeZone); |
|
590 | + return $DateTime->setTimestamp($date_string); |
|
591 | + } catch (Exception $e) { |
|
592 | 592 | // should be rare, but if things got fooled then let's just continue |
593 | 593 | } |
594 | 594 | } |
595 | 595 | //not a unix timestamp. So we will use the set format on this object and set timezone to |
596 | 596 | //create the DateTime object. |
597 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
597 | + $format = $this->_date_format.' '.$this->_time_format; |
|
598 | 598 | try { |
599 | - $DateTime = DateTime::createFromFormat( $format, $date_string, $this->_DateTimeZone ); |
|
600 | - if ( ! $DateTime instanceof DateTime ) { |
|
599 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
600 | + if ( ! $DateTime instanceof DateTime) { |
|
601 | 601 | throw new EE_Error( |
602 | 602 | sprintf( |
603 | - __( '"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso' ), |
|
603 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
604 | 604 | $date_string, |
605 | 605 | $format |
606 | 606 | ) |
607 | 607 | ); |
608 | 608 | } |
609 | - } catch ( Exception $e ) { |
|
609 | + } catch (Exception $e) { |
|
610 | 610 | // if we made it here then likely then something went really wrong. Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
611 | - $DateTime = new DateTime( "now", $this->_DateTimeZone ); |
|
611 | + $DateTime = new DateTime("now", $this->_DateTimeZone); |
|
612 | 612 | } |
613 | 613 | return $DateTime; |
614 | 614 | } |
@@ -622,9 +622,9 @@ discard block |
||
622 | 622 | * @param null $time |
623 | 623 | * @return mixed |
624 | 624 | */ |
625 | - public function get_timezone_offset( DateTimeZone $DateTimeZone, $time = null ) { |
|
626 | - $time = preg_match( EE_Datetime_Field::unix_timestamp_regex, $time ) ? $time : time(); |
|
627 | - $transitions = $DateTimeZone->getTransitions( $time ); |
|
625 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) { |
|
626 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
627 | + $transitions = $DateTimeZone->getTransitions($time); |
|
628 | 628 | return $transitions[0]['offset']; |
629 | 629 | } |
630 | 630 | |
@@ -636,10 +636,10 @@ discard block |
||
636 | 636 | * @param string $timezone_string |
637 | 637 | * @return string abbreviation |
638 | 638 | */ |
639 | - public function get_timezone_abbrev( $timezone_string ) { |
|
640 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string( $timezone_string ); |
|
641 | - $dateTime = new DateTime( 'now', new DateTimeZone( $timezone_string ) ); |
|
642 | - return $dateTime->format( 'T' ); |
|
639 | + public function get_timezone_abbrev($timezone_string) { |
|
640 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
641 | + $dateTime = new DateTime('now', new DateTimeZone($timezone_string)); |
|
642 | + return $dateTime->format('T'); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 |
@@ -27,7 +27,7 @@ |
||
27 | 27 | /** |
28 | 28 | * Returns the name of the model(s) pointed to |
29 | 29 | * @deprecated since version 4.6.7 |
30 | - * @return mixed string or array of strings |
|
30 | + * @return string string or array of strings |
|
31 | 31 | */ |
32 | 32 | function get_model_name_pointed_to(){ |
33 | 33 | EE_Error::doing_it_wrong( 'get_model_name_pointed_to', __( 'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', 'event_espresso' ), '4.6.7' ); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * with the EE_Foreign_Key_Field to create a relation between any two models) |
6 | 6 | * also required basically the exact same functionality, except NOT be a foreign key. |
7 | 7 | */ |
8 | -abstract class EE_Field_With_Model_Name extends EE_Model_Field_Base{ |
|
8 | +abstract class EE_Field_With_Model_Name extends EE_Model_Field_Base { |
|
9 | 9 | /** |
10 | 10 | * Usually the name of a single model. However, as in the case for custom post types, |
11 | 11 | * it can actually be an array of models |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul dbe a string |
21 | 21 | * @param string $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the "EEM_" |
22 | 22 | */ |
23 | - function __construct($table_column, $nicename, $nullable, $default_value,$model_name){ |
|
23 | + function __construct($table_column, $nicename, $nullable, $default_value, $model_name) { |
|
24 | 24 | $this->_model_name_pointed_to = $model_name; |
25 | 25 | parent::__construct($table_column, $nicename, $nullable, $default_value); |
26 | 26 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | * @deprecated since version 4.6.7 |
30 | 30 | * @return mixed string or array of strings |
31 | 31 | */ |
32 | - function get_model_name_pointed_to(){ |
|
33 | - EE_Error::doing_it_wrong( 'get_model_name_pointed_to', __( 'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', 'event_espresso' ), '4.6.7' ); |
|
32 | + function get_model_name_pointed_to() { |
|
33 | + EE_Error::doing_it_wrong('get_model_name_pointed_to', __('This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', 'event_espresso'), '4.6.7'); |
|
34 | 34 | return $this->_model_name_pointed_to; |
35 | 35 | } |
36 | 36 | /** |
@@ -39,31 +39,31 @@ discard block |
||
39 | 39 | * @return array of model names pointed to by this field |
40 | 40 | */ |
41 | 41 | function get_model_names_pointed_to() { |
42 | - if( is_array( $this->_model_name_pointed_to ) ) { |
|
42 | + if (is_array($this->_model_name_pointed_to)) { |
|
43 | 43 | return $this->_model_name_pointed_to; |
44 | - }else{ |
|
45 | - return array( $this->_model_name_pointed_to ); |
|
44 | + } else { |
|
45 | + return array($this->_model_name_pointed_to); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | /** |
49 | 49 | * Returns the model's classname (eg EE_Event instead of just Event) |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - function get_model_class_names_pointed_to(){ |
|
52 | + function get_model_class_names_pointed_to() { |
|
53 | 53 | $model_names = array(); |
54 | - if(is_array($this->_model_name_pointed_to)){ |
|
55 | - foreach($this->_model_name_pointed_to as $model_name){ |
|
54 | + if (is_array($this->_model_name_pointed_to)) { |
|
55 | + foreach ($this->_model_name_pointed_to as $model_name) { |
|
56 | 56 | $model_names[] = "EE_".$model_name; |
57 | 57 | } |
58 | - }else{ |
|
58 | + } else { |
|
59 | 59 | $model_names = array("EE_".$this->_model_name_pointed_to); |
60 | 60 | } |
61 | 61 | return $model_names; |
62 | 62 | } |
63 | 63 | |
64 | - function is_model_obj_of_type_pointed_to($model_obj_or_ID){ |
|
65 | - foreach($this->get_model_class_names_pointed_to() as $model_obj_classname){ |
|
66 | - if($model_obj_or_ID instanceof $model_obj_classname){ |
|
64 | + function is_model_obj_of_type_pointed_to($model_obj_or_ID) { |
|
65 | + foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) { |
|
66 | + if ($model_obj_or_ID instanceof $model_obj_classname) { |
|
67 | 67 | return true; |
68 | 68 | } |
69 | 69 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
43 | 43 | } |
44 | 44 | throw new EE_Validation_Error( $validation_error_message, 'float_only' ); |
45 | - }else{ |
|
45 | + } else{ |
|
46 | 46 | return floatval($normalized_value); |
47 | 47 | } |
48 | 48 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function unnormalize($normalized_value) { |
56 | 56 | if( empty( $normalized_value ) ){ |
57 | 57 | return '0.00'; |
58 | - }else{ |
|
58 | + } else{ |
|
59 | 59 | return "$normalized_value"; |
60 | 60 | } |
61 | 61 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | protected $_model_name; |
30 | 30 | |
31 | 31 | /** |
32 | - * @param $table_column |
|
32 | + * @param string $table_column |
|
33 | 33 | * @param $nicename |
34 | - * @param $nullable |
|
34 | + * @param boolean $nullable |
|
35 | 35 | * @param null $default_value |
36 | 36 | */ |
37 | 37 | function __construct($table_column, $nicename, $nullable, $default_value = null){ |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default, |
118 | 118 | * we simply return it. |
119 | 119 | * @param mixed $value_of_field_on_model_object |
120 | - * @return mixed |
|
120 | + * @return double |
|
121 | 121 | */ |
122 | 122 | function prepare_for_get($value_of_field_on_model_object){ |
123 | 123 | return $value_of_field_on_model_object; |
@@ -2,22 +2,22 @@ |
||
2 | 2 | exit( 'No direct script access allowed' ); |
3 | 3 | } |
4 | 4 | /** |
5 | - * |
|
6 | - * EE_Model_Field_Base class |
|
7 | - * |
|
8 | - * Base class for all EE_*_Field classes. These classes are for providing information and functions specific to each |
|
9 | - * field. They define the field's data type for insertion into the db (eg, if the value should be treated as an int, float, or string), |
|
10 | - * what values for the field are acceptable (eg, if setting EVT_ID to a float is acceptable), and generally any functionality within |
|
11 | - * EEM_Base or EE_Base_Class which depend on the field's type. (ie, you shouldn't need any logic within your model |
|
12 | - * or model object which are dependent on the field's type, ideally). For example, EE_Serialized_Text_Field, specifies that any fields of this type |
|
13 | - * should be serialized before insertion into the db (prepare_for_insertion_into_db()), |
|
14 | - * should be considered a string when inserting, updating, or using in a where clause for any queries (get_wpdb_data_type()), |
|
15 | - * should be unserialized when being retrieved from the db (prepare_for_set_from_db()), and whatever else. |
|
16 | - * |
|
17 | - * @package Event Espresso |
|
18 | - * @subpackage /core/db_models/fields/EE_Model_Field_Base.php |
|
19 | - * @author Michael Nelson |
|
20 | - */ |
|
5 | + * |
|
6 | + * EE_Model_Field_Base class |
|
7 | + * |
|
8 | + * Base class for all EE_*_Field classes. These classes are for providing information and functions specific to each |
|
9 | + * field. They define the field's data type for insertion into the db (eg, if the value should be treated as an int, float, or string), |
|
10 | + * what values for the field are acceptable (eg, if setting EVT_ID to a float is acceptable), and generally any functionality within |
|
11 | + * EEM_Base or EE_Base_Class which depend on the field's type. (ie, you shouldn't need any logic within your model |
|
12 | + * or model object which are dependent on the field's type, ideally). For example, EE_Serialized_Text_Field, specifies that any fields of this type |
|
13 | + * should be serialized before insertion into the db (prepare_for_insertion_into_db()), |
|
14 | + * should be considered a string when inserting, updating, or using in a where clause for any queries (get_wpdb_data_type()), |
|
15 | + * should be unserialized when being retrieved from the db (prepare_for_set_from_db()), and whatever else. |
|
16 | + * |
|
17 | + * @package Event Espresso |
|
18 | + * @subpackage /core/db_models/fields/EE_Model_Field_Base.php |
|
19 | + * @author Michael Nelson |
|
20 | + */ |
|
21 | 21 | abstract class EE_Model_Field_Base{ |
22 | 22 | var $_table_alias; |
23 | 23 | var $_table_column; |
@@ -1,5 +1,5 @@ discard block |
||
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 | * |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @subpackage /core/db_models/fields/EE_Model_Field_Base.php |
19 | 19 | * @author Michael Nelson |
20 | 20 | */ |
21 | -abstract class EE_Model_Field_Base{ |
|
21 | +abstract class EE_Model_Field_Base { |
|
22 | 22 | var $_table_alias; |
23 | 23 | var $_table_column; |
24 | 24 | var $_name; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param $nullable |
35 | 35 | * @param null $default_value |
36 | 36 | */ |
37 | - function __construct($table_column, $nicename, $nullable, $default_value = null){ |
|
37 | + function __construct($table_column, $nicename, $nullable, $default_value = null) { |
|
38 | 38 | $this->_table_column = $table_column; |
39 | 39 | $this->_nicename = $nicename; |
40 | 40 | $this->_nullable = $nullable; |
@@ -48,22 +48,22 @@ discard block |
||
48 | 48 | * @param $name |
49 | 49 | * @param $model_name |
50 | 50 | */ |
51 | - function _construct_finalize($table_alias, $name, $model_name){ |
|
51 | + function _construct_finalize($table_alias, $name, $model_name) { |
|
52 | 52 | $this->_table_alias = $table_alias; |
53 | 53 | $this->_name = $name; |
54 | 54 | $this->_model_name = $model_name; |
55 | 55 | } |
56 | - function get_table_alias(){ |
|
56 | + function get_table_alias() { |
|
57 | 57 | return $this->_table_alias; |
58 | 58 | } |
59 | - function get_table_column(){ |
|
59 | + function get_table_column() { |
|
60 | 60 | return $this->_table_column; |
61 | 61 | } |
62 | 62 | /** |
63 | 63 | * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime' |
64 | 64 | * @return string |
65 | 65 | */ |
66 | - function get_model_name(){ |
|
66 | + function get_model_name() { |
|
67 | 67 | return $this->_model_name; |
68 | 68 | } |
69 | 69 | |
@@ -71,17 +71,17 @@ discard block |
||
71 | 71 | * @throws \EE_Error |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - function get_name(){ |
|
75 | - if($this->_name){ |
|
74 | + function get_name() { |
|
75 | + if ($this->_name) { |
|
76 | 76 | return $this->_name; |
77 | - }else{ |
|
78 | - throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?", "event_espresso"),get_class($this))); |
|
77 | + } else { |
|
78 | + throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?", "event_espresso"), get_class($this))); |
|
79 | 79 | } |
80 | 80 | } |
81 | - function get_nicename(){ |
|
81 | + function get_nicename() { |
|
82 | 82 | return $this->_nicename; |
83 | 83 | } |
84 | - function is_nullable(){ |
|
84 | + function is_nullable() { |
|
85 | 85 | return $this->_nullable; |
86 | 86 | } |
87 | 87 | /** |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * on insertion it can be null. However, on updates it must be present. |
90 | 90 | * @return boolean |
91 | 91 | */ |
92 | - function is_auto_increment(){ |
|
92 | + function is_auto_increment() { |
|
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * value domains at the top of EEM_Base |
98 | 98 | * @return mixed |
99 | 99 | */ |
100 | - function get_default_value(){ |
|
100 | + function get_default_value() { |
|
101 | 101 | return $this->_default_value; |
102 | 102 | } |
103 | 103 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * in the current query |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - function get_qualified_column(){ |
|
111 | + function get_qualified_column() { |
|
112 | 112 | return $this->get_table_alias().".".$this->get_table_column(); |
113 | 113 | } |
114 | 114 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param mixed $value_of_field_on_model_object |
120 | 120 | * @return mixed |
121 | 121 | */ |
122 | - function prepare_for_get($value_of_field_on_model_object){ |
|
122 | + function prepare_for_get($value_of_field_on_model_object) { |
|
123 | 123 | return $value_of_field_on_model_object; |
124 | 124 | } |
125 | 125 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param mixed $value_of_field_on_model_object |
130 | 130 | * @return mixed |
131 | 131 | */ |
132 | - function prepare_for_use_in_db($value_of_field_on_model_object){ |
|
132 | + function prepare_for_use_in_db($value_of_field_on_model_object) { |
|
133 | 133 | return $value_of_field_on_model_object; |
134 | 134 | } |
135 | 135 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param mixed $value_inputted_for_field_on_model_object |
141 | 141 | * @return mixed |
142 | 142 | */ |
143 | - function prepare_for_set($value_inputted_for_field_on_model_object){ |
|
143 | + function prepare_for_set($value_inputted_for_field_on_model_object) { |
|
144 | 144 | return $value_inputted_for_field_on_model_object; |
145 | 145 | } |
146 | 146 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param mixed $value_found_in_db_for_model_object |
152 | 152 | * @return mixed |
153 | 153 | */ |
154 | - function prepare_for_set_from_db($value_found_in_db_for_model_object){ |
|
154 | + function prepare_for_set_from_db($value_found_in_db_for_model_object) { |
|
155 | 155 | return $this->prepare_for_set($value_found_in_db_for_model_object); |
156 | 156 | } |
157 | 157 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param mixed $value_on_field_to_be_outputted |
163 | 163 | * @return mixed |
164 | 164 | */ |
165 | - function prepare_for_pretty_echoing( $value_on_field_to_be_outputted ){ |
|
165 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted) { |
|
166 | 166 | return $value_on_field_to_be_outputted; |
167 | 167 | } |
168 | 168 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * By default, all fields aren't db-only. |
178 | 178 | * @return boolean |
179 | 179 | */ |
180 | - function is_db_only_field(){ |
|
180 | + function is_db_only_field() { |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | } |
184 | 184 | \ No newline at end of file |
@@ -90,7 +90,7 @@ |
||
90 | 90 | //so in case teh IPN is arriving later, let's try to process an IPN! |
91 | 91 | if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
92 | 92 | return $this->handle_ipn($_POST, $transaction ); |
93 | - }else{ |
|
93 | + } else{ |
|
94 | 94 | return parent::finalize_payment_for( $transaction ); |
95 | 95 | } |
96 | 96 | } |
@@ -4,6 +4,7 @@ |
||
4 | 4 | * Overrides parent so it doesn't need to provide so many non-applicable fields |
5 | 5 | * @param string $table_column |
6 | 6 | * @param string $nicename |
7 | + * @param integer|null $default |
|
7 | 8 | */ |
8 | 9 | public function __construct($table_column, $nicename,$default) { |
9 | 10 | parent::__construct($table_column, $nicename, false, $default, null); |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | -abstract class EE_Primary_Key_Field_Base extends EE_Field_With_Model_Name{ |
|
2 | +abstract class EE_Primary_Key_Field_Base extends EE_Field_With_Model_Name { |
|
3 | 3 | /** |
4 | 4 | * Overrides parent so it doesn't need to provide so many non-applicable fields |
5 | 5 | * @param string $table_column |
6 | 6 | * @param string $nicename |
7 | 7 | */ |
8 | - public function __construct($table_column, $nicename,$default) { |
|
8 | + public function __construct($table_column, $nicename, $default) { |
|
9 | 9 | parent::__construct($table_column, $nicename, false, $default, null); |
10 | 10 | } |
11 | 11 | /** |
12 | 12 | * @param $table_alias |
13 | 13 | * @param $name |
14 | 14 | */ |
15 | - function _construct_finalize($table_alias, $name, $model_name){ |
|
15 | + function _construct_finalize($table_alias, $name, $model_name) { |
|
16 | 16 | $this->_model_name_pointed_to = $model_name; |
17 | 17 | parent::_construct_finalize($table_alias, $name, $model_name); |
18 | 18 | } |
@@ -4,6 +4,10 @@ |
||
4 | 4 | function get_wpdb_data_type(){ |
5 | 5 | return '%s'; |
6 | 6 | } |
7 | + |
|
8 | + /** |
|
9 | + * @param string $table_column |
|
10 | + */ |
|
7 | 11 | public function __construct($table_column, $nicename) { |
8 | 12 | parent::__construct($table_column, $nicename, NULL); |
9 | 13 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | require_once('EE_Primary_Key_Field_Base.php'); |
3 | -class EE_Primary_Key_String_Field extends EE_Primary_Key_Field_Base{ |
|
4 | - function get_wpdb_data_type(){ |
|
3 | +class EE_Primary_Key_String_Field extends EE_Primary_Key_Field_Base { |
|
4 | + function get_wpdb_data_type() { |
|
5 | 5 | return '%s'; |
6 | 6 | } |
7 | 7 | public function __construct($table_column, $nicename) { |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @return string |
14 | 14 | */ |
15 | 15 | function prepare_for_set($value_inputted_for_field_on_model_object) { |
16 | - if($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)){ |
|
16 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
17 | 17 | $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
18 | 18 | } |
19 | 19 | return wp_strip_all_tags($value_inputted_for_field_on_model_object); |
@@ -26,7 +26,6 @@ |
||
26 | 26 | * ) |
27 | 27 | * ) |
28 | 28 | * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
29 | - * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is set to true, it will be stored as an INT |
|
30 | 29 | */ |
31 | 30 | function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()){ |
32 | 31 | $this->_register_new_stati( $new_stati ); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once( EE_MODELS . 'fields/EE_Enum_Text_Field.php' ); |
|
3 | -class EE_WP_Post_Status_Field extends EE_Enum_Text_Field{ |
|
2 | +require_once(EE_MODELS.'fields/EE_Enum_Text_Field.php'); |
|
3 | +class EE_WP_Post_Status_Field extends EE_Enum_Text_Field { |
|
4 | 4 | |
5 | 5 | protected $_wp_post_stati; |
6 | 6 | |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
29 | 29 | * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is set to true, it will be stored as an INT |
30 | 30 | */ |
31 | - function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()){ |
|
32 | - $this->_register_new_stati( $new_stati ); |
|
31 | + function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) { |
|
32 | + $this->_register_new_stati($new_stati); |
|
33 | 33 | $this->_set_allowed_enum_values(); |
34 | 34 | parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values); |
35 | 35 | } |
@@ -46,18 +46,18 @@ discard block |
||
46 | 46 | * @param array $new_stati statuses |
47 | 47 | * @return void |
48 | 48 | */ |
49 | - protected function _register_new_stati( $new_stati ) { |
|
49 | + protected function _register_new_stati($new_stati) { |
|
50 | 50 | |
51 | - foreach ( (array) $new_stati as $status_key => $status_args ) { |
|
51 | + foreach ((array) $new_stati as $status_key => $status_args) { |
|
52 | 52 | $args = array( |
53 | - 'label' => isset( $status_args['label'] ) ? $status_args['label'] : $status_key, |
|
54 | - 'public' => isset( $status_args['public'] ) && is_bool( $status_args['public'] ) ? $status_args['public'] : TRUE, |
|
55 | - 'exclude_from_search' => isset( $status_args['exclude_from_search'] ) && is_bool($status_args['exclude_from_search'] ) ? $status_args['exclude_from_search'] : FALSE, |
|
56 | - 'show_in_admin_all_list' => isset( $status_args['show_in_admin_all_list'] ) && is_bool( $status_args['show_in_admin_all_list'] ) ? $status_args['show_in_admin_all_list'] : FALSE, |
|
57 | - 'show_in_admin_status_list' => isset( $status_args['show_in_admin_status_list'] ) && is_bool( $status_args['show_in_admin_status_list'] ) ? $status_args['show_in_admin_status_list'] : TRUE, |
|
58 | - 'label_count' => isset( $status_args['label_count'] ) ? $status_args['label_count'] : '' |
|
53 | + 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
|
54 | + 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : TRUE, |
|
55 | + 'exclude_from_search' => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : FALSE, |
|
56 | + 'show_in_admin_all_list' => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : FALSE, |
|
57 | + 'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : TRUE, |
|
58 | + 'label_count' => isset($status_args['label_count']) ? $status_args['label_count'] : '' |
|
59 | 59 | ); |
60 | - register_post_status( $status_key, $status_args ); |
|
60 | + register_post_status($status_key, $status_args); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | global $wp_post_statuses; |
79 | 79 | $this->_wp_post_stati = $wp_post_statuses; |
80 | 80 | |
81 | - foreach( $this->_wp_post_stati as $post_status => $args_object ) { |
|
81 | + foreach ($this->_wp_post_stati as $post_status => $args_object) { |
|
82 | 82 | $this->_allowed_enum_values[$post_status] = $args_object->label; |
83 | 83 | } |
84 | 84 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @param string $status What status object you want |
109 | 109 | * @return std_object the status object or FALSE if it doesn't exist. |
110 | 110 | */ |
111 | - public function get_status_object( $status ) { |
|
112 | - return isset( $this->_wp_post_stati[$status] ) ? $this->_wp_post_stati[$status] : FALSE; |
|
111 | + public function get_status_object($status) { |
|
112 | + return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : FALSE; |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | \ No newline at end of file |
@@ -43,16 +43,30 @@ discard block |
||
43 | 43 | |
44 | 44 | private $_group_by_sql; |
45 | 45 | |
46 | + /** |
|
47 | + * @param string $limit_sql |
|
48 | + */ |
|
46 | 49 | function set_limit_sql($limit_sql){ |
47 | 50 | $this->_limit_sql = $limit_sql; |
48 | 51 | } |
49 | 52 | |
53 | + /** |
|
54 | + * @param string $order_by_sql |
|
55 | + */ |
|
50 | 56 | function set_order_by_sql($order_by_sql){ |
51 | 57 | $this->_order_by_sql = $order_by_sql; |
52 | 58 | } |
59 | + |
|
60 | + /** |
|
61 | + * @param string $group_by_sql |
|
62 | + */ |
|
53 | 63 | function set_group_by_sql($group_by_sql){ |
54 | 64 | $this->_group_by_sql = $group_by_sql; |
55 | 65 | } |
66 | + |
|
67 | + /** |
|
68 | + * @param string $having_sql |
|
69 | + */ |
|
56 | 70 | function set_having_sql($having_sql){ |
57 | 71 | $this->_having_sql = $having_sql; |
58 | 72 | } |
@@ -72,7 +86,6 @@ discard block |
||
72 | 86 | * |
73 | 87 | * @param type $model_included_name |
74 | 88 | * @param type $join_sql |
75 | - * @param type $data_types |
|
76 | 89 | */ |
77 | 90 | public function __construct($model_included_name= array(), $join_sql = ''){ |
78 | 91 | $this->_models_included = $model_included_name; |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class EE_Model_Query_Info_Carrier extends EE_Base{ |
13 | 13 | /** |
14 | - * @var string SQL for performing joins (Eg, "INNER JOIN blah ON blah=blah INNER JOIN FOO ON foo=foo...") |
|
15 | - */ |
|
14 | + * @var string SQL for performing joins (Eg, "INNER JOIN blah ON blah=blah INNER JOIN FOO ON foo=foo...") |
|
15 | + */ |
|
16 | 16 | private $_join_sql; |
17 | 17 | /** |
18 | 18 | * |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @return string |
133 | 133 | */ |
134 | 134 | public function get_main_model_join_sql() { |
135 | - return $this->_main_join_sql; |
|
135 | + return $this->_main_join_sql; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * We could have returned an array |
10 | 10 | * with two keys 'join_sql' and 'data_types', but this better-defines the data being passed around |
11 | 11 | */ |
12 | -class EE_Model_Query_Info_Carrier extends EE_Base{ |
|
12 | +class EE_Model_Query_Info_Carrier extends EE_Base { |
|
13 | 13 | /** |
14 | 14 | * @var string SQL for performing joins (Eg, "INNER JOIN blah ON blah=blah INNER JOIN FOO ON foo=foo...") |
15 | 15 | */ |
@@ -43,29 +43,29 @@ discard block |
||
43 | 43 | |
44 | 44 | private $_group_by_sql; |
45 | 45 | |
46 | - function set_limit_sql($limit_sql){ |
|
46 | + function set_limit_sql($limit_sql) { |
|
47 | 47 | $this->_limit_sql = $limit_sql; |
48 | 48 | } |
49 | 49 | |
50 | - function set_order_by_sql($order_by_sql){ |
|
50 | + function set_order_by_sql($order_by_sql) { |
|
51 | 51 | $this->_order_by_sql = $order_by_sql; |
52 | 52 | } |
53 | - function set_group_by_sql($group_by_sql){ |
|
53 | + function set_group_by_sql($group_by_sql) { |
|
54 | 54 | $this->_group_by_sql = $group_by_sql; |
55 | 55 | } |
56 | - function set_having_sql($having_sql){ |
|
56 | + function set_having_sql($having_sql) { |
|
57 | 57 | $this->_having_sql = $having_sql; |
58 | 58 | } |
59 | - function get_limit_sql(){ |
|
59 | + function get_limit_sql() { |
|
60 | 60 | return $this->_limit_sql; |
61 | 61 | } |
62 | - function get_order_by_sql(){ |
|
62 | + function get_order_by_sql() { |
|
63 | 63 | return $this->_order_by_sql; |
64 | 64 | } |
65 | - function get_group_by_sql(){ |
|
65 | + function get_group_by_sql() { |
|
66 | 66 | return $this->_group_by_sql; |
67 | 67 | } |
68 | - function get_having_sql(){ |
|
68 | + function get_having_sql() { |
|
69 | 69 | return $this->_having_sql; |
70 | 70 | } |
71 | 71 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param type $join_sql |
75 | 75 | * @param type $data_types |
76 | 76 | */ |
77 | - public function __construct($model_included_name= array(), $join_sql = ''){ |
|
77 | + public function __construct($model_included_name = array(), $join_sql = '') { |
|
78 | 78 | $this->_models_included = $model_included_name; |
79 | 79 | $this->_join_sql = $join_sql; |
80 | 80 | } |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | * Merges info from the other EEM_Related_Model_Info_Carrier into this one. |
84 | 84 | * @param EE_Model_Query_Info_Carrier $other_model_query_info_carrier |
85 | 85 | */ |
86 | - public function merge( $other_model_query_info_carrier ){ |
|
87 | - if( $other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())){ |
|
88 | - $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included(); |
|
89 | - $this->_models_included = array_merge( $this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier ); |
|
86 | + public function merge($other_model_query_info_carrier) { |
|
87 | + if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) { |
|
88 | + $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included(); |
|
89 | + $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier); |
|
90 | 90 | $this->_join_sql .= $other_model_query_info_carrier->_join_sql; |
91 | 91 | } |
92 | 92 | //otherwise don't merge our data. |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param array $model_names just like EE_MOdel_QUery_Info_Carrier::_models_included: keys are model chain paths, values are the model names only |
101 | 101 | * @return boolean |
102 | 102 | */ |
103 | - protected function _have_already_included_one_of_these_models($model_names){ |
|
104 | - foreach($this->_models_included as $model_relation_path=>$model_included){ |
|
105 | - if(array_key_exists($model_relation_path, $model_names)){ |
|
103 | + protected function _have_already_included_one_of_these_models($model_names) { |
|
104 | + foreach ($this->_models_included as $model_relation_path=>$model_included) { |
|
105 | + if (array_key_exists($model_relation_path, $model_names)) { |
|
106 | 106 | return true; |
107 | 107 | } |
108 | 108 | } |
@@ -112,17 +112,17 @@ discard block |
||
112 | 112 | * Array keys are model names, values are "model relation paths". See EE_Model_Query_Info_Carrier::_models_included for details |
113 | 113 | * @return array like EE_Model_Query_Info_Carrier::_models_included |
114 | 114 | */ |
115 | - public function get_model_names_included(){ |
|
115 | + public function get_model_names_included() { |
|
116 | 116 | return $this->_models_included; |
117 | 117 | } |
118 | 118 | /** |
119 | 119 | * sets the $where_sql for later use from client code |
120 | 120 | * @param string $where_sql |
121 | 121 | */ |
122 | - public function set_where_sql($where_sql){ |
|
122 | + public function set_where_sql($where_sql) { |
|
123 | 123 | $this->_where_sql = $where_sql; |
124 | 124 | } |
125 | - public function get_where_sql(){ |
|
125 | + public function get_where_sql() { |
|
126 | 126 | return $this->_where_sql; |
127 | 127 | } |
128 | 128 | |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | * after the FROM and before the WHERE.) |
144 | 144 | * @param string $join_sql |
145 | 145 | */ |
146 | - public function set_main_model_join_sql($join_sql){ |
|
146 | + public function set_main_model_join_sql($join_sql) { |
|
147 | 147 | $this->_main_join_sql = $join_sql; |
148 | 148 | } |
149 | - public function get_full_join_sql(){ |
|
150 | - return $this->_main_join_sql . $this->_join_sql; |
|
149 | + public function get_full_join_sql() { |
|
150 | + return $this->_main_join_sql.$this->_join_sql; |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | \ No newline at end of file |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * creates join statement FROM primary table |
50 | 50 | * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk |
51 | 51 | * |
52 | - * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery) |
|
52 | + * @param string $primary_table_alias_with_model_chain_prefix |
|
53 | 53 | * @return string of SQL |
54 | 54 | */ |
55 | 55 | function get_join_sql( $primary_table_alias_with_model_chain_prefix ){ |
@@ -72,6 +72,7 @@ discard block |
||
72 | 72 | * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns |
73 | 73 | * " LEFT JOIN primary_table AS Primary ON ...". |
74 | 74 | * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. |
75 | + * @param string $secondary_table_alias_with_model_chain_prefix |
|
75 | 76 | * @return string |
76 | 77 | */ |
77 | 78 | function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix){ |
@@ -5,8 +5,8 @@ discard block |
||
5 | 5 | * table's rows. Ie, it can't have many rows in the secondary table that point to |
6 | 6 | * a single row in the primary table |
7 | 7 | */ |
8 | -require_once( EE_MODELS . 'helpers/EE_Table_Base.php'); |
|
9 | -class EE_Secondary_Table extends EE_Table_Base{ |
|
8 | +require_once(EE_MODELS.'helpers/EE_Table_Base.php'); |
|
9 | +class EE_Secondary_Table extends EE_Table_Base { |
|
10 | 10 | protected $_extra_join_conditions; |
11 | 11 | |
12 | 12 | /** |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
20 | 20 | * or whether each site on a multisite install has a copy of this table |
21 | 21 | */ |
22 | - function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false ){ |
|
22 | + function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false) { |
|
23 | 23 | $this->_fk_on_table = $fk_column; |
24 | 24 | $this->_extra_join_conditions = $extra_join_conditions; |
25 | - parent::__construct( $table_name, $pk_column, $global ); |
|
25 | + parent::__construct($table_name, $pk_column, $global); |
|
26 | 26 | } |
27 | - function get_fk_on_table(){ |
|
27 | + function get_fk_on_table() { |
|
28 | 28 | return $this->_fk_on_table; |
29 | 29 | } |
30 | - function _construct_finalize_set_table_to_join_with(EE_Table_Base $table){ |
|
30 | + function _construct_finalize_set_table_to_join_with(EE_Table_Base $table) { |
|
31 | 31 | $this->_table_to_join_with = $table; |
32 | 32 | } |
33 | 33 | /** |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | * @return string of sql like "Event.post_type = 'event'", which gets added to |
36 | 36 | * the end of the join statement with the primary table |
37 | 37 | */ |
38 | - function get_extra_join_conditions(){ |
|
38 | + function get_extra_join_conditions() { |
|
39 | 39 | return $this->_extra_join_conditions; |
40 | 40 | } |
41 | 41 | /** |
42 | 42 | * |
43 | 43 | * @return EE_Primary_Table |
44 | 44 | */ |
45 | - function get_table_to_join_with(){ |
|
45 | + function get_table_to_join_with() { |
|
46 | 46 | return $this->_table_to_join_with; |
47 | 47 | } |
48 | 48 | /** |
@@ -52,15 +52,15 @@ discard block |
||
52 | 52 | * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery) |
53 | 53 | * @return string of SQL |
54 | 54 | */ |
55 | - function get_join_sql( $primary_table_alias_with_model_chain_prefix ){ |
|
55 | + function get_join_sql($primary_table_alias_with_model_chain_prefix) { |
|
56 | 56 | |
57 | 57 | $table_name = $this->get_table_name(); |
58 | - $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
58 | + $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix).$this->get_table_alias(); |
|
59 | 59 | $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
60 | 60 | $fk = $this->get_fk_on_table(); |
61 | 61 | $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
62 | - if($this->get_extra_join_conditions()){ |
|
63 | - $join_sql.="AND ".$this->get_extra_join_conditions(); |
|
62 | + if ($this->get_extra_join_conditions()) { |
|
63 | + $join_sql .= "AND ".$this->get_extra_join_conditions(); |
|
64 | 64 | } |
65 | 65 | return $join_sql; |
66 | 66 | } |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. |
75 | 75 | * @return string |
76 | 76 | */ |
77 | - function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix){ |
|
78 | - $primary_table_name =$this->get_table_to_join_with()->get_table_name(); |
|
79 | - $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
80 | - $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();//$this->get_pk_column(); |
|
77 | + function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) { |
|
78 | + $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
|
79 | + $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix).$this->get_table_to_join_with()->get_table_alias(); |
|
80 | + $primary_table_pk = $this->get_table_to_join_with()->get_pk_column(); //$this->get_pk_column(); |
|
81 | 81 | $fk = $this->get_fk_on_table(); |
82 | 82 | $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
83 | - if($this->get_extra_join_conditions()){ |
|
84 | - $join_sql.="AND ".$this->get_extra_join_conditions(); |
|
83 | + if ($this->get_extra_join_conditions()) { |
|
84 | + $join_sql .= "AND ".$this->get_extra_join_conditions(); |
|
85 | 85 | } |
86 | 86 | return $join_sql; |
87 | 87 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | public function get_select_join_limit_join($limit) { |
95 | 95 | //first get the select |
96 | 96 | $select = $this->get_select_join_limit($limit); |
97 | - $join_sql = $this->get_join_sql( $select ); |
|
97 | + $join_sql = $this->get_join_sql($select); |
|
98 | 98 | return $join_sql; |
99 | 99 | } |
100 | 100 | |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | function get_fully_qualified_fk_column() { |
104 | 104 | $table_alias = $this->get_table_alias(); |
105 | 105 | $fk = $this->get_fk_on_table(); |
106 | - return $table_alias . '.' . $fk; |
|
106 | + return $table_alias.'.'.$fk; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | function get_fully_qualified_pk_on_fk_table() { |
110 | 110 | $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
111 | 111 | $pk = $this->get_table_to_join_with()->get_pk_column(); |
112 | - return $table_alias . '.' . $pk; |
|
112 | + return $table_alias.'.'.$pk; |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | \ No newline at end of file |
@@ -17,6 +17,7 @@ discard block |
||
17 | 17 | * get related models across the relation, and add-and-remove the relationships. |
18 | 18 | * @param boolean $block_deletes for this type of relation, we block by default for now. if there are related models across this relation, block (prevent and add an error) the deletion of this model |
19 | 19 | * @param type $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
20 | + * @param string $joining_model_name |
|
20 | 21 | */ |
21 | 22 | function __construct($joining_model_name,$block_deletes = true, $blocking_delete_error_message =''){ |
22 | 23 | $this->_joining_model_name = $joining_model_name; |
@@ -24,7 +25,7 @@ discard block |
||
24 | 25 | } |
25 | 26 | /** |
26 | 27 | * Gets the joining model's object |
27 | - * @return EEM_Base |
|
28 | + * @return boolean |
|
28 | 29 | */ |
29 | 30 | function get_join_model(){ |
30 | 31 | return $this->_get_model($this->_joining_model_name); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once( EE_MODELS . 'relations/EE_Model_Relation_Base.php'); |
|
4 | -class EE_HABTM_Relation extends EE_Model_Relation_Base{ |
|
3 | +require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php'); |
|
4 | +class EE_HABTM_Relation extends EE_Model_Relation_Base { |
|
5 | 5 | /** |
6 | 6 | * Model whicih defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
7 | 7 | * which joins EE_Event and EE_Question_Group |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param boolean $block_deletes for this type of relation, we block by default for now. if there are related models across this relation, block (prevent and add an error) the deletion of this model |
19 | 19 | * @param type $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
20 | 20 | */ |
21 | - function __construct($joining_model_name,$block_deletes = true, $blocking_delete_error_message =''){ |
|
21 | + function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') { |
|
22 | 22 | $this->_joining_model_name = $joining_model_name; |
23 | 23 | parent::__construct($block_deletes, $blocking_delete_error_message); |
24 | 24 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * Gets the joining model's object |
27 | 27 | * @return EEM_Base |
28 | 28 | */ |
29 | - function get_join_model(){ |
|
29 | + function get_join_model() { |
|
30 | 30 | return $this->_get_model($this->_joining_model_name); |
31 | 31 | } |
32 | 32 | /** |
@@ -34,21 +34,21 @@ discard block |
||
34 | 34 | * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
35 | 35 | * @return string of SQL |
36 | 36 | */ |
37 | - function get_join_to_intermediate_model_statement($model_relation_chain){ |
|
37 | + function get_join_to_intermediate_model_statement($model_relation_chain) { |
|
38 | 38 | //create sql like |
39 | 39 | //LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
40 | 40 | //LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
41 | 41 | //remember the model relation chain to the JOIN model, because we'll |
42 | 42 | //need it for get_join_statement() |
43 | 43 | $this->_model_relation_chain_to_join_model = $model_relation_chain; |
44 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();//get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
44 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); //get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
45 | 45 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
46 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
46 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
47 | 47 | |
48 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
48 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
49 | 49 | $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
50 | 50 | //phew! ok, we have all the info we need, now we can create the SQL join string |
51 | - $SQL = $this->_left_join($join_table, $join_table_alias, $join_table_fk_field_to_this_table->get_table_column(), $this_table_alias, $this_table_pk_field->get_table_column()) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
51 | + $SQL = $this->_left_join($join_table, $join_table_alias, $join_table_fk_field_to_this_table->get_table_column(), $this_table_alias, $this_table_pk_field->get_table_column()).$this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
52 | 52 | |
53 | 53 | return $SQL; |
54 | 54 | } |
@@ -60,18 +60,18 @@ discard block |
||
60 | 60 | * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
61 | 61 | * @return string of SQL |
62 | 62 | */ |
63 | - function get_join_statement($model_relation_chain){ |
|
64 | - if( $this->_model_relation_chain_to_join_model === NULL ){ |
|
65 | - throw new EE_Error( sprintf( __( 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso' ))); |
|
63 | + function get_join_statement($model_relation_chain) { |
|
64 | + if ($this->_model_relation_chain_to_join_model === NULL) { |
|
65 | + throw new EE_Error(sprintf(__('When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso'))); |
|
66 | 66 | } |
67 | 67 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
68 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
68 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
69 | 69 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
70 | 70 | $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
71 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias(); |
|
71 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias(); |
|
72 | 72 | $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
73 | 73 | |
74 | - $SQL = $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(), $join_table_alias, $join_table_fk_field_to_other_table->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
74 | + $SQL = $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(), $join_table_alias, $join_table_fk_field_to_other_table->get_table_column()).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
75 | 75 | return $SQL; |
76 | 76 | } |
77 | 77 | |
@@ -84,36 +84,36 @@ discard block |
||
84 | 84 | * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for checking existing values and for setting new rows if no exact matches. |
85 | 85 | * @return EE_Base_Class |
86 | 86 | */ |
87 | - function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
87 | + function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
88 | 88 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
89 | 89 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
90 | 90 | //check if such a relationship already exists |
91 | 91 | $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
92 | 92 | $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
93 | 93 | |
94 | - $cols_n_values = array( |
|
94 | + $cols_n_values = array( |
|
95 | 95 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
96 | 96 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID()); |
97 | 97 | |
98 | 98 | //if $where_query exists lets add them to the query_params. |
99 | - if ( !empty( $extra_join_model_fields_n_values ) ) { |
|
99 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
100 | 100 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
101 | 101 | //make sure we strip THIS models name from the query param |
102 | - foreach ( $extra_join_model_fields_n_values as $query_param => $val ) { |
|
103 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
102 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
103 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
104 | 104 | $parsed_query[$query_param] = $val; |
105 | 105 | } |
106 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
106 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
107 | 107 | } |
108 | 108 | |
109 | - $query_params = array( $cols_n_values ); |
|
109 | + $query_params = array($cols_n_values); |
|
110 | 110 | |
111 | 111 | |
112 | 112 | $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
113 | 113 | //if there is already an entry in the join table, indicating a relationship, we're done |
114 | 114 | //again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
115 | 115 | //the other tables, use the joining model directly! |
116 | - if( ! $existing_entry_in_join_table ){ |
|
116 | + if ( ! $existing_entry_in_join_table) { |
|
117 | 117 | $this->get_join_model()->insert($cols_n_values); |
118 | 118 | } |
119 | 119 | return $other_model_obj; |
@@ -125,29 +125,29 @@ discard block |
||
125 | 125 | * * @param array $where_query col=>val pairs that are used as extra conditions for checking existing values and for removing existing rows if exact matches exist. |
126 | 126 | * @return EE_Base_Class |
127 | 127 | */ |
128 | - function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array() ){ |
|
128 | + function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
129 | 129 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
130 | 130 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
131 | 131 | //check if such a relationship already exists |
132 | 132 | $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
133 | 133 | $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
134 | 134 | |
135 | - $cols_n_values = array( |
|
135 | + $cols_n_values = array( |
|
136 | 136 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
137 | 137 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID()); |
138 | 138 | |
139 | 139 | //if $where_query exists lets add them to the query_params. |
140 | - if ( !empty( $where_query ) ) { |
|
140 | + if ( ! empty($where_query)) { |
|
141 | 141 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
142 | 142 | //make sure we strip THIS models name from the query param |
143 | - foreach ( $where_query as $query_param => $val ) { |
|
144 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
143 | + foreach ($where_query as $query_param => $val) { |
|
144 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
145 | 145 | $parsed_query[$query_param] = $val; |
146 | 146 | } |
147 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
147 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
148 | 148 | } |
149 | 149 | |
150 | - $existing_entry_in_join_table = $this->get_join_model()->delete( array($cols_n_values) ); |
|
150 | + $existing_entry_in_join_table = $this->get_join_model()->delete(array($cols_n_values)); |
|
151 | 151 | return $other_model_obj; |
152 | 152 | } |
153 | 153 | } |