@@ -555,10 +555,10 @@ |
||
555 | 555 | $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
556 | 556 | $status_array = array(); |
557 | 557 | foreach ( $stati as $status ) { |
558 | - $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
559 | - } |
|
560 | - return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
|
561 | - } |
|
558 | + $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
559 | + } |
|
560 | + return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
|
561 | + } |
|
562 | 562 | |
563 | 563 | |
564 | 564 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @since EE4 |
24 | 24 | * |
25 | 25 | */ |
26 | -abstract class EEM_Base extends EE_Base{ |
|
26 | +abstract class EEM_Base extends EE_Base { |
|
27 | 27 | |
28 | 28 | //admin posty |
29 | 29 | //basic -> grants access to mine -> if they don't have it, select none |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * Flag indicating whether this model has a primary key or not |
236 | 236 | * @var boolean |
237 | 237 | */ |
238 | - protected $_has_primary_key_field=null; |
|
238 | + protected $_has_primary_key_field = null; |
|
239 | 239 | |
240 | 240 | /** |
241 | 241 | * Whether or not this model is based off a table in WP core only (CPTs should set |
@@ -297,19 +297,19 @@ discard block |
||
297 | 297 | * operators that work like 'BETWEEN'. Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'" |
298 | 298 | * @var array |
299 | 299 | */ |
300 | - protected $_between_style_operators = array( 'BETWEEN' ); |
|
300 | + protected $_between_style_operators = array('BETWEEN'); |
|
301 | 301 | |
302 | 302 | /** |
303 | 303 | * operators that are used for handling NUll and !NULL queries. Typically used for when checking if a row exists on a join table. |
304 | 304 | * @var array |
305 | 305 | */ |
306 | - protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL'); |
|
306 | + protected $_null_style_operators = array('IS NOT NULL', 'IS NULL'); |
|
307 | 307 | |
308 | 308 | /** |
309 | 309 | * Allowed values for $query_params['order'] for ordering in queries |
310 | 310 | * @var array |
311 | 311 | */ |
312 | - protected $_allowed_order_values = array('asc','desc','ASC','DESC'); |
|
312 | + protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC'); |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * When these are keys in a WHERE or HAVING clause, they are handled much differently |
@@ -323,13 +323,13 @@ discard block |
||
323 | 323 | * 'where', but 'where' clauses are so common that we thought we'd omit it |
324 | 324 | * @var array |
325 | 325 | */ |
326 | - private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps'); |
|
326 | + private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps'); |
|
327 | 327 | |
328 | 328 | /** |
329 | 329 | * All the data types that can be used in $wpdb->prepare statements. |
330 | 330 | * @var array |
331 | 331 | */ |
332 | - private $_valid_wpdb_data_types = array('%d','%s','%f'); |
|
332 | + private $_valid_wpdb_data_types = array('%d', '%s', '%f'); |
|
333 | 333 | |
334 | 334 | /** |
335 | 335 | * EE_Registry Object |
@@ -362,17 +362,17 @@ discard block |
||
362 | 362 | /** |
363 | 363 | * constant used to show EEM_Base has not yet verified the db on this http request |
364 | 364 | */ |
365 | - const db_verified_none = 0; |
|
365 | + const db_verified_none = 0; |
|
366 | 366 | /** |
367 | 367 | * constant used to show EEM_Base has verified the EE core db on this http request, |
368 | 368 | * but not the addons' dbs |
369 | 369 | */ |
370 | - const db_verified_core = 1; |
|
370 | + const db_verified_core = 1; |
|
371 | 371 | /** |
372 | 372 | * constant used to show EEM_Base has verified the addons' dbs (and implicitly |
373 | 373 | * the EE core db too) |
374 | 374 | */ |
375 | - const db_verified_addons = 2; |
|
375 | + const db_verified_addons = 2; |
|
376 | 376 | |
377 | 377 | /** |
378 | 378 | * indicates whether an EEM_Base child has already re-verified the DB |
@@ -403,13 +403,13 @@ discard block |
||
403 | 403 | * @param null $timezone |
404 | 404 | * @throws \EE_Error |
405 | 405 | */ |
406 | - protected function __construct( $timezone = NULL ){ |
|
406 | + protected function __construct($timezone = NULL) { |
|
407 | 407 | // check that the model has not been loaded too soon |
408 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) { |
|
409 | - throw new EE_Error ( |
|
408 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons')) { |
|
409 | + throw new EE_Error( |
|
410 | 410 | sprintf( |
411 | - __( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ), |
|
412 | - get_class( $this ) |
|
411 | + __('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'), |
|
412 | + get_class($this) |
|
413 | 413 | ) |
414 | 414 | ); |
415 | 415 | } |
@@ -419,11 +419,11 @@ discard block |
||
419 | 419 | * just use EE_Register_Model_Extension |
420 | 420 | * @var EE_Table_Base[] $_tables |
421 | 421 | */ |
422 | - $this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables ); |
|
423 | - foreach($this->_tables as $table_alias => $table_obj){ |
|
422 | + $this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables); |
|
423 | + foreach ($this->_tables as $table_alias => $table_obj) { |
|
424 | 424 | /** @var $table_obj EE_Table_Base */ |
425 | 425 | $table_obj->_construct_finalize_with_alias($table_alias); |
426 | - if( $table_obj instanceof EE_Secondary_Table ){ |
|
426 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
427 | 427 | /** @var $table_obj EE_Secondary_Table */ |
428 | 428 | $table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table()); |
429 | 429 | } |
@@ -433,54 +433,54 @@ discard block |
||
433 | 433 | * EE_Register_Model_Extension |
434 | 434 | * @param EE_Model_Field_Base[] $_fields |
435 | 435 | */ |
436 | - $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields); |
|
436 | + $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields); |
|
437 | 437 | $this->_invalidate_field_caches(); |
438 | - foreach($this->_fields as $table_alias => $fields_for_table){ |
|
439 | - if ( ! array_key_exists( $table_alias, $this->_tables )){ |
|
440 | - throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields))); |
|
438 | + foreach ($this->_fields as $table_alias => $fields_for_table) { |
|
439 | + if ( ! array_key_exists($table_alias, $this->_tables)) { |
|
440 | + throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields))); |
|
441 | 441 | } |
442 | - foreach($fields_for_table as $field_name => $field_obj){ |
|
442 | + foreach ($fields_for_table as $field_name => $field_obj) { |
|
443 | 443 | /** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */ |
444 | 444 | //primary key field base has a slightly different _construct_finalize |
445 | 445 | /** @var $field_obj EE_Model_Field_Base */ |
446 | - $field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() ); |
|
446 | + $field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name()); |
|
447 | 447 | } |
448 | 448 | } |
449 | 449 | |
450 | 450 | // everything is related to Extra_Meta |
451 | - if( get_class($this) != 'EEM_Extra_Meta'){ |
|
451 | + if (get_class($this) != 'EEM_Extra_Meta') { |
|
452 | 452 | //make extra meta related to everything, but don't block deleting things just |
453 | 453 | //because they have related extra meta info. For now just orphan those extra meta |
454 | 454 | //in the future we should automatically delete them |
455 | - $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE ); |
|
455 | + $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE); |
|
456 | 456 | } |
457 | 457 | //and change logs |
458 | - if( get_class( $this) != 'EEM_Change_Log' ) { |
|
459 | - $this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE ); |
|
458 | + if (get_class($this) != 'EEM_Change_Log') { |
|
459 | + $this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE); |
|
460 | 460 | } |
461 | 461 | /** |
462 | 462 | * Filters the list of relations on a model. It is best to NOT use this directly and instead just use |
463 | 463 | * EE_Register_Model_Extension |
464 | 464 | * @param EE_Model_Relation_Base[] $_model_relations |
465 | 465 | */ |
466 | - $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations); |
|
467 | - foreach($this->_model_relations as $model_name => $relation_obj){ |
|
466 | + $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations); |
|
467 | + foreach ($this->_model_relations as $model_name => $relation_obj) { |
|
468 | 468 | /** @var $relation_obj EE_Model_Relation_Base */ |
469 | 469 | $relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name); |
470 | 470 | } |
471 | - foreach($this->_indexes as $index_name => $index_obj){ |
|
471 | + foreach ($this->_indexes as $index_name => $index_obj) { |
|
472 | 472 | /** @var $index_obj EE_Index */ |
473 | 473 | $index_obj->_construct_finalize($index_name, $this->get_this_model_name()); |
474 | 474 | } |
475 | 475 | |
476 | 476 | $this->set_timezone($timezone); |
477 | 477 | //finalize default where condition strategy, or set default |
478 | - if( ! $this->_default_where_conditions_strategy){ |
|
478 | + if ( ! $this->_default_where_conditions_strategy) { |
|
479 | 479 | //nothing was set during child constructor, so set default |
480 | 480 | $this->_default_where_conditions_strategy = new EE_Default_Where_Conditions(); |
481 | 481 | } |
482 | 482 | $this->_default_where_conditions_strategy->_finalize_construct($this); |
483 | - if( ! $this->_minimum_where_conditions_strategy){ |
|
483 | + if ( ! $this->_minimum_where_conditions_strategy) { |
|
484 | 484 | //nothing was set during child constructor, so set default |
485 | 485 | $this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions(); |
486 | 486 | } |
@@ -488,15 +488,15 @@ discard block |
||
488 | 488 | |
489 | 489 | //if the cap slug hasn't been set, and we haven't set it to false on purpose |
490 | 490 | //to indicate to NOT set it, set it to the logical default |
491 | - if( $this->_caps_slug === null ) { |
|
492 | - EE_Registry::instance()->load_helper( 'Inflector' ); |
|
493 | - $this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() ); |
|
491 | + if ($this->_caps_slug === null) { |
|
492 | + EE_Registry::instance()->load_helper('Inflector'); |
|
493 | + $this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name()); |
|
494 | 494 | } |
495 | 495 | //initialize the standard cap restriction generators if none were specified by the child constructor |
496 | - if( $this->_cap_restriction_generators !== false ){ |
|
497 | - foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){ |
|
498 | - if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) { |
|
499 | - $this->_cap_restriction_generators[ $cap_context ] = apply_filters( |
|
496 | + if ($this->_cap_restriction_generators !== false) { |
|
497 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
498 | + if ( ! isset($this->_cap_restriction_generators[$cap_context])) { |
|
499 | + $this->_cap_restriction_generators[$cap_context] = apply_filters( |
|
500 | 500 | 'FHEE__EEM_Base___construct__standard_cap_restriction_generator', |
501 | 501 | new EE_Restriction_Generator_Protected(), |
502 | 502 | $cap_context, |
@@ -506,23 +506,23 @@ discard block |
||
506 | 506 | } |
507 | 507 | } |
508 | 508 | //if there are cap restriction generators, use them to make the default cap restrictions |
509 | - if( $this->_cap_restriction_generators !== false ){ |
|
510 | - foreach( $this->_cap_restriction_generators as $context => $generator_object ) { |
|
511 | - if( ! $generator_object ){ |
|
509 | + if ($this->_cap_restriction_generators !== false) { |
|
510 | + foreach ($this->_cap_restriction_generators as $context => $generator_object) { |
|
511 | + if ( ! $generator_object) { |
|
512 | 512 | continue; |
513 | 513 | } |
514 | - if( ! $generator_object instanceof EE_Restriction_Generator_Base ){ |
|
514 | + if ( ! $generator_object instanceof EE_Restriction_Generator_Base) { |
|
515 | 515 | throw new EE_Error( |
516 | 516 | sprintf( |
517 | - __( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ), |
|
517 | + __('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'), |
|
518 | 518 | $context, |
519 | 519 | $this->get_this_model_name() |
520 | 520 | ) |
521 | 521 | ); |
522 | 522 | } |
523 | - $action = $this->cap_action_for_context( $context ); |
|
524 | - if( ! $generator_object->construction_finalized() ){ |
|
525 | - $generator_object->_construct_finalize( $this, $action ); |
|
523 | + $action = $this->cap_action_for_context($context); |
|
524 | + if ( ! $generator_object->construction_finalized()) { |
|
525 | + $generator_object->_construct_finalize($this, $action); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | } |
@@ -536,11 +536,11 @@ discard block |
||
536 | 536 | * @param string $context one of EEM_Base::valid_cap_contexts() |
537 | 537 | * @return EE_Default_Where_Conditions[] |
538 | 538 | */ |
539 | - protected function _generate_cap_restrictions( $context ){ |
|
540 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
541 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
|
542 | - return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
|
543 | - }else{ |
|
539 | + protected function _generate_cap_restrictions($context) { |
|
540 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
541 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) { |
|
542 | + return $this->_cap_restriction_generators[$context]->generate_restrictions(); |
|
543 | + } else { |
|
544 | 544 | return array(); |
545 | 545 | } |
546 | 546 | } |
@@ -553,16 +553,16 @@ discard block |
||
553 | 553 | * @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) |
554 | 554 | * @return static (as in the concrete child class) |
555 | 555 | */ |
556 | - public static function instance( $timezone = NULL ){ |
|
556 | + public static function instance($timezone = NULL) { |
|
557 | 557 | |
558 | 558 | // check if instance of Espresso_model already exists |
559 | 559 | if ( ! static::$_instance instanceof static) { |
560 | 560 | // instantiate Espresso_model |
561 | - static::$_instance = new static( $timezone ); |
|
561 | + static::$_instance = new static($timezone); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | //we might have a timezone set, let set_timezone decide what to do with it |
565 | - static::$_instance->set_timezone( $timezone ); |
|
565 | + static::$_instance->set_timezone($timezone); |
|
566 | 566 | |
567 | 567 | // Espresso_model object |
568 | 568 | return static::$_instance; |
@@ -575,11 +575,11 @@ discard block |
||
575 | 575 | * @param null | string $timezone |
576 | 576 | * @return static |
577 | 577 | */ |
578 | - public static function reset( $timezone = NULL ){ |
|
579 | - if ( ! is_null( static::$_instance ) ) { |
|
578 | + public static function reset($timezone = NULL) { |
|
579 | + if ( ! is_null(static::$_instance)) { |
|
580 | 580 | static::$_instance = null; |
581 | 581 | |
582 | - return self::instance( $timezone ); |
|
582 | + return self::instance($timezone); |
|
583 | 583 | } |
584 | 584 | return null; |
585 | 585 | } |
@@ -590,15 +590,15 @@ discard block |
||
590 | 590 | * @param boolean $translated return localized strings or JUST the array. |
591 | 591 | * @return array |
592 | 592 | */ |
593 | - public function status_array( $translated = FALSE ) { |
|
594 | - if ( !array_key_exists('Status', $this->_model_relations ) ) |
|
593 | + public function status_array($translated = FALSE) { |
|
594 | + if ( ! array_key_exists('Status', $this->_model_relations)) |
|
595 | 595 | return array(); |
596 | 596 | $model_name = $this->get_this_model_name(); |
597 | - $status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) ); |
|
598 | - $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
|
597 | + $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name))); |
|
598 | + $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type))); |
|
599 | 599 | $status_array = array(); |
600 | - foreach ( $stati as $status ) { |
|
601 | - $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
600 | + foreach ($stati as $status) { |
|
601 | + $status_array[$status->ID()] = $status->get('STS_code'); |
|
602 | 602 | } |
603 | 603 | return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
604 | 604 | } |
@@ -740,10 +740,10 @@ discard block |
||
740 | 740 | * 'order_by'=>array('ANS_value'=>'ASC') |
741 | 741 | * )); |
742 | 742 | */ |
743 | - function get_all($query_params = array()){ |
|
744 | - if( isset( $query_params[ 'limit' ] ) |
|
745 | - && ! isset( $query_params[ 'group_by' ] ) ) { |
|
746 | - $query_params[ 'group_by' ] = array_keys( $this->get_combined_primary_key_fields() ); |
|
743 | + function get_all($query_params = array()) { |
|
744 | + if (isset($query_params['limit']) |
|
745 | + && ! isset($query_params['group_by'])) { |
|
746 | + $query_params['group_by'] = array_keys($this->get_combined_primary_key_fields()); |
|
747 | 747 | } |
748 | 748 | return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL)); |
749 | 749 | } |
@@ -754,10 +754,10 @@ discard block |
||
754 | 754 | * @param array $query_params @see EEM_Base::get_all() |
755 | 755 | * @return array like EEM_Base::get_all |
756 | 756 | */ |
757 | - function alter_query_params_to_only_include_mine( $query_params = array() ) { |
|
757 | + function alter_query_params_to_only_include_mine($query_params = array()) { |
|
758 | 758 | $wp_user_field_name = $this->wp_user_field_name(); |
759 | - if( $wp_user_field_name ){ |
|
760 | - $query_params[0][ $wp_user_field_name ] = get_current_user_id(); |
|
759 | + if ($wp_user_field_name) { |
|
760 | + $query_params[0][$wp_user_field_name] = get_current_user_id(); |
|
761 | 761 | } |
762 | 762 | return $query_params; |
763 | 763 | } |
@@ -770,19 +770,19 @@ discard block |
||
770 | 770 | * foreign key to the WP_User table |
771 | 771 | */ |
772 | 772 | function wp_user_field_name() { |
773 | - try{ |
|
774 | - if( ! empty( $this->_model_chain_to_wp_user ) ) { |
|
775 | - $models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user ); |
|
776 | - $last_model_name = end( $models_to_follow_to_wp_users ); |
|
777 | - $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
|
778 | - $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
|
779 | - }else{ |
|
773 | + try { |
|
774 | + if ( ! empty($this->_model_chain_to_wp_user)) { |
|
775 | + $models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user); |
|
776 | + $last_model_name = end($models_to_follow_to_wp_users); |
|
777 | + $model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name); |
|
778 | + $model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.'; |
|
779 | + } else { |
|
780 | 780 | $model_with_fk_to_wp_users = $this; |
781 | 781 | $model_chain_to_wp_user = ''; |
782 | 782 | } |
783 | - $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
|
784 | - return $model_chain_to_wp_user . $wp_user_field->get_name(); |
|
785 | - }catch( EE_Error $e ) { |
|
783 | + $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User'); |
|
784 | + return $model_chain_to_wp_user.$wp_user_field->get_name(); |
|
785 | + } catch (EE_Error $e) { |
|
786 | 786 | return false; |
787 | 787 | } |
788 | 788 | } |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | * (or transiently-related model) |
797 | 797 | * @return string |
798 | 798 | */ |
799 | - public function model_chain_to_wp_user(){ |
|
799 | + public function model_chain_to_wp_user() { |
|
800 | 800 | return $this->_model_chain_to_wp_user; |
801 | 801 | } |
802 | 802 | |
@@ -808,13 +808,13 @@ discard block |
||
808 | 808 | * @return boolean |
809 | 809 | */ |
810 | 810 | public function is_owned() { |
811 | - if( $this->model_chain_to_wp_user() ){ |
|
811 | + if ($this->model_chain_to_wp_user()) { |
|
812 | 812 | return true; |
813 | - }else{ |
|
814 | - try{ |
|
815 | - $this->get_foreign_key_to( 'WP_User' ); |
|
813 | + } else { |
|
814 | + try { |
|
815 | + $this->get_foreign_key_to('WP_User'); |
|
816 | 816 | return true; |
817 | - }catch( EE_Error $e ){ |
|
817 | + } catch (EE_Error $e) { |
|
818 | 818 | return false; |
819 | 819 | } |
820 | 820 | } |
@@ -833,21 +833,21 @@ discard block |
||
833 | 833 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
834 | 834 | * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
835 | 835 | */ |
836 | - protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
836 | + protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
837 | 837 | //remember the custom selections, if any |
838 | - if(is_array($columns_to_select)){ |
|
838 | + if (is_array($columns_to_select)) { |
|
839 | 839 | $this->_custom_selections = $columns_to_select; |
840 | - }elseif(is_string($columns_to_select)){ |
|
840 | + }elseif (is_string($columns_to_select)) { |
|
841 | 841 | $this->_custom_selections = array($this->_custom_selections); |
842 | - }else{ |
|
842 | + } else { |
|
843 | 843 | $this->_custom_selections = array(); |
844 | 844 | } |
845 | 845 | |
846 | 846 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
847 | 847 | $select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info); |
848 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
848 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
849 | 849 | // echo "sql:$SQL"; |
850 | - $results = $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output); |
|
850 | + $results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output); |
|
851 | 851 | return $results; |
852 | 852 | } |
853 | 853 | |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
866 | 866 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
867 | 867 | */ |
868 | - public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
868 | + public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
869 | 869 | return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select); |
870 | 870 | } |
871 | 871 | |
@@ -877,12 +877,12 @@ discard block |
||
877 | 877 | * @throws EE_Error |
878 | 878 | * @return string |
879 | 879 | */ |
880 | - private function _construct_select_from_input($columns_to_select){ |
|
881 | - if(is_array($columns_to_select)){ |
|
880 | + private function _construct_select_from_input($columns_to_select) { |
|
881 | + if (is_array($columns_to_select)) { |
|
882 | 882 | $select_sql_array = array(); |
883 | 883 | |
884 | - foreach($columns_to_select as $alias => $selection_and_datatype){ |
|
885 | - if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){ |
|
884 | + foreach ($columns_to_select as $alias => $selection_and_datatype) { |
|
885 | + if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) { |
|
886 | 886 | throw new EE_Error( |
887 | 887 | sprintf( |
888 | 888 | __( |
@@ -894,24 +894,24 @@ discard block |
||
894 | 894 | ) |
895 | 895 | ); |
896 | 896 | } |
897 | - if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){ |
|
897 | + if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) { |
|
898 | 898 | throw new EE_Error( |
899 | 899 | sprintf( |
900 | 900 | __( |
901 | 901 | "Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", |
902 | 902 | "event_espresso" |
903 | 903 | ), |
904 | - $selection_and_datatype[ 1 ], |
|
905 | - $selection_and_datatype[ 0 ], |
|
904 | + $selection_and_datatype[1], |
|
905 | + $selection_and_datatype[0], |
|
906 | 906 | $alias, |
907 | - implode( ",", $this->_valid_wpdb_data_types ) |
|
907 | + implode(",", $this->_valid_wpdb_data_types) |
|
908 | 908 | ) |
909 | 909 | ); |
910 | 910 | } |
911 | 911 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
912 | 912 | } |
913 | - $columns_to_select_string = implode(", ",$select_sql_array); |
|
914 | - }else{ |
|
913 | + $columns_to_select_string = implode(", ", $select_sql_array); |
|
914 | + } else { |
|
915 | 915 | $columns_to_select_string = $columns_to_select; |
916 | 916 | } |
917 | 917 | return $columns_to_select_string; |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID' |
925 | 925 | * @return string |
926 | 926 | */ |
927 | - function primary_key_name(){ |
|
927 | + function primary_key_name() { |
|
928 | 928 | return $this->get_primary_key_field()->get_name(); |
929 | 929 | } |
930 | 930 | |
@@ -936,14 +936,14 @@ discard block |
||
936 | 936 | * @param mixed $id int or string, depending on the type of the model's primary key |
937 | 937 | * @return EE_Base_Class |
938 | 938 | */ |
939 | - function get_one_by_ID($id){ |
|
940 | - if( $this->get_from_entity_map( $id ) ){ |
|
941 | - return $this->get_from_entity_map( $id ); |
|
939 | + function get_one_by_ID($id) { |
|
940 | + if ($this->get_from_entity_map($id)) { |
|
941 | + return $this->get_from_entity_map($id); |
|
942 | 942 | } |
943 | 943 | return $this->get_one( |
944 | 944 | $this->alter_query_params_to_restrict_by_ID( |
945 | 945 | $id, |
946 | - array( 'default_where_conditions' => 'minimum' ) |
|
946 | + array('default_where_conditions' => 'minimum') |
|
947 | 947 | ) |
948 | 948 | ); |
949 | 949 | } |
@@ -955,15 +955,15 @@ discard block |
||
955 | 955 | * @param array $query_params |
956 | 956 | * @return array of normal query params, @see EEM_Base::get_all |
957 | 957 | */ |
958 | - public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) { |
|
959 | - if( ! isset( $query_params[ 0 ] ) ) { |
|
960 | - $query_params[ 0 ] = array(); |
|
958 | + public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) { |
|
959 | + if ( ! isset($query_params[0])) { |
|
960 | + $query_params[0] = array(); |
|
961 | 961 | } |
962 | - if( $this->has_primary_key_field ( ) ) { |
|
963 | - $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
|
964 | - }else{ |
|
962 | + if ($this->has_primary_key_field( )) { |
|
963 | + $query_params[0][$this->primary_key_name()] = $id; |
|
964 | + } else { |
|
965 | 965 | //no primary key, so the $id must be from the get_index_primary_key_string() |
966 | - $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
|
966 | + $query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id)); |
|
967 | 967 | } |
968 | 968 | return $query_params; |
969 | 969 | } |
@@ -975,16 +975,16 @@ discard block |
||
975 | 975 | * @param array $query_params like EEM_Base's $query_params variable. |
976 | 976 | * @return EE_Base_Class | NULL |
977 | 977 | */ |
978 | - function get_one($query_params = array()){ |
|
979 | - if( ! is_array( $query_params ) ){ |
|
980 | - EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
978 | + function get_one($query_params = array()) { |
|
979 | + if ( ! is_array($query_params)) { |
|
980 | + EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
981 | 981 | $query_params = array(); |
982 | 982 | } |
983 | 983 | $query_params['limit'] = 1; |
984 | 984 | $items = $this->get_all($query_params); |
985 | - if(empty($items)){ |
|
985 | + if (empty($items)) { |
|
986 | 986 | return null; |
987 | - }else{ |
|
987 | + } else { |
|
988 | 988 | return array_shift($items); |
989 | 989 | } |
990 | 990 | } |
@@ -1008,8 +1008,8 @@ discard block |
||
1008 | 1008 | * |
1009 | 1009 | * @return EE_Base_Class[]|array |
1010 | 1010 | */ |
1011 | - public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1012 | - return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1011 | + public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1012 | + return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | |
@@ -1032,8 +1032,8 @@ discard block |
||
1032 | 1032 | * |
1033 | 1033 | * @return EE_Base_Class[]|array |
1034 | 1034 | */ |
1035 | - public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1036 | - return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1035 | + public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1036 | + return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | |
@@ -1055,9 +1055,9 @@ discard block |
||
1055 | 1055 | * |
1056 | 1056 | * @return EE_Base_Class|null|array() |
1057 | 1057 | */ |
1058 | - public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1059 | - $results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1060 | - return empty( $results ) ? null : reset( $results ); |
|
1058 | + public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1059 | + $results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1060 | + return empty($results) ? null : reset($results); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | |
@@ -1079,9 +1079,9 @@ discard block |
||
1079 | 1079 | * |
1080 | 1080 | * @return EE_Base_Class|null|array() |
1081 | 1081 | */ |
1082 | - public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1083 | - $results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1084 | - return empty( $results ) ? null : reset( $results ); |
|
1082 | + public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1083 | + $results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1084 | + return empty($results) ? null : reset($results); |
|
1085 | 1085 | } |
1086 | 1086 | |
1087 | 1087 | |
@@ -1107,40 +1107,40 @@ discard block |
||
1107 | 1107 | * @return EE_Base_Class[]|array |
1108 | 1108 | * @throws EE_Error |
1109 | 1109 | */ |
1110 | - protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1110 | + protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1111 | 1111 | //if $field_to_order_by is empty then let's assume we're ordering by the primary key. |
1112 | - if ( empty( $field_to_order_by ) ) { |
|
1113 | - if ( $this->has_primary_key_field() ) { |
|
1112 | + if (empty($field_to_order_by)) { |
|
1113 | + if ($this->has_primary_key_field()) { |
|
1114 | 1114 | $field_to_order_by = $this->get_primary_key_field()->get_name(); |
1115 | 1115 | } else { |
1116 | 1116 | |
1117 | - if ( WP_DEBUG ) { |
|
1118 | - throw new EE_Error( __( 'EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso' ) ); |
|
1117 | + if (WP_DEBUG) { |
|
1118 | + throw new EE_Error(__('EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso')); |
|
1119 | 1119 | } |
1120 | - EE_Error::add_error( __('There was an error with the query.', 'event_espresso') ); |
|
1120 | + EE_Error::add_error(__('There was an error with the query.', 'event_espresso')); |
|
1121 | 1121 | return array(); |
1122 | 1122 | } |
1123 | 1123 | } |
1124 | 1124 | |
1125 | - if( ! is_array( $query_params ) ){ |
|
1126 | - EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1125 | + if ( ! is_array($query_params)) { |
|
1126 | + EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1127 | 1127 | $query_params = array(); |
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | //let's add the where query param for consecutive look up. |
1131 | - $query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value ); |
|
1131 | + $query_params[0][$field_to_order_by] = array($operand, $current_field_value); |
|
1132 | 1132 | $query_params['limit'] = $limit; |
1133 | 1133 | |
1134 | 1134 | //set direction |
1135 | - $incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array(); |
|
1136 | - $query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby; |
|
1135 | + $incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array(); |
|
1136 | + $query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby; |
|
1137 | 1137 | |
1138 | 1138 | //if $columns_to_select is empty then that means we're returning EE_Base_Class objects |
1139 | - if ( empty( $columns_to_select ) ) { |
|
1140 | - return $this->get_all( $query_params ); |
|
1139 | + if (empty($columns_to_select)) { |
|
1140 | + return $this->get_all($query_params); |
|
1141 | 1141 | } else { |
1142 | 1142 | //getting just the fields |
1143 | - return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select ); |
|
1143 | + return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select); |
|
1144 | 1144 | } |
1145 | 1145 | } |
1146 | 1146 | |
@@ -1151,18 +1151,18 @@ discard block |
||
1151 | 1151 | * This sets the _timezone property after model object has been instantiated. |
1152 | 1152 | * @param null | string $timezone valid PHP DateTimeZone timezone string |
1153 | 1153 | */ |
1154 | - public function set_timezone( $timezone ) { |
|
1155 | - if ( $timezone !== null ) { |
|
1154 | + public function set_timezone($timezone) { |
|
1155 | + if ($timezone !== null) { |
|
1156 | 1156 | $this->_timezone = $timezone; |
1157 | 1157 | } |
1158 | 1158 | //note we need to loop through relations and set the timezone on those objects as well. |
1159 | - foreach ( $this->_model_relations as $relation ) { |
|
1160 | - $relation->set_timezone( $timezone ); |
|
1159 | + foreach ($this->_model_relations as $relation) { |
|
1160 | + $relation->set_timezone($timezone); |
|
1161 | 1161 | } |
1162 | 1162 | //and finally we do the same for any datetime fields |
1163 | - foreach ( $this->_fields as $field ) { |
|
1164 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1165 | - $field->set_timezone( $timezone ); |
|
1163 | + foreach ($this->_fields as $field) { |
|
1164 | + if ($field instanceof EE_Datetime_Field) { |
|
1165 | + $field->set_timezone($timezone); |
|
1166 | 1166 | } |
1167 | 1167 | } |
1168 | 1168 | } |
@@ -1177,9 +1177,9 @@ discard block |
||
1177 | 1177 | */ |
1178 | 1178 | public function get_timezone() { |
1179 | 1179 | //first validate if timezone is set. If not, then let's set it be whatever is set on the model fields. |
1180 | - if ( empty( $this->_timezone ) ) { |
|
1181 | - foreach( $this->_fields as $field ) { |
|
1182 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1180 | + if (empty($this->_timezone)) { |
|
1181 | + foreach ($this->_fields as $field) { |
|
1182 | + if ($field instanceof EE_Datetime_Field) { |
|
1183 | 1183 | $this->set_timezone($field->get_timezone()); |
1184 | 1184 | break; |
1185 | 1185 | } |
@@ -1187,9 +1187,9 @@ discard block |
||
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | //if timezone STILL empty then return the default timezone for the site. |
1190 | - if ( empty( $this->_timezone ) ) { |
|
1191 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1192 | - $this->set_timezone( EEH_DTT_Helper::get_timezone() ); |
|
1190 | + if (empty($this->_timezone)) { |
|
1191 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1192 | + $this->set_timezone(EEH_DTT_Helper::get_timezone()); |
|
1193 | 1193 | } |
1194 | 1194 | return $this->_timezone; |
1195 | 1195 | } |
@@ -1207,19 +1207,19 @@ discard block |
||
1207 | 1207 | * |
1208 | 1208 | * @return array formats in an array with the date format first, and the time format last. |
1209 | 1209 | */ |
1210 | - public function get_formats_for( $field_name, $pretty = false ) { |
|
1211 | - $field_settings = $this->field_settings_for( $field_name ); |
|
1210 | + public function get_formats_for($field_name, $pretty = false) { |
|
1211 | + $field_settings = $this->field_settings_for($field_name); |
|
1212 | 1212 | |
1213 | 1213 | //if not a valid EE_Datetime_Field then throw error |
1214 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
1215 | - throw new EE_Error( sprintf( __('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso' ), $field_name ) ); |
|
1214 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1215 | + throw new EE_Error(sprintf(__('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso'), $field_name)); |
|
1216 | 1216 | } |
1217 | 1217 | |
1218 | 1218 | //while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on |
1219 | 1219 | //the field. |
1220 | 1220 | $this->_timezone = $field_settings->get_timezone(); |
1221 | 1221 | |
1222 | - return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) ); |
|
1222 | + return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty)); |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | 1225 | |
@@ -1243,25 +1243,25 @@ discard block |
||
1243 | 1243 | * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
1244 | 1244 | * exception is triggered. |
1245 | 1245 | */ |
1246 | - public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
|
1247 | - $formats = $this->get_formats_for( $field_name ); |
|
1246 | + public function current_time_for_query($field_name, $timestamp = false, $what = 'both') { |
|
1247 | + $formats = $this->get_formats_for($field_name); |
|
1248 | 1248 | |
1249 | - $DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) ); |
|
1249 | + $DateTime = new DateTime("now", new DateTimeZone($this->_timezone)); |
|
1250 | 1250 | |
1251 | - if ( $timestamp ) { |
|
1252 | - return $DateTime->format( 'U' ); |
|
1251 | + if ($timestamp) { |
|
1252 | + return $DateTime->format('U'); |
|
1253 | 1253 | } |
1254 | 1254 | |
1255 | 1255 | //not returning timestamp, so return formatted string in timezone. |
1256 | - switch( $what ) { |
|
1256 | + switch ($what) { |
|
1257 | 1257 | case 'time' : |
1258 | - return $DateTime->format( $formats[1] ); |
|
1258 | + return $DateTime->format($formats[1]); |
|
1259 | 1259 | break; |
1260 | 1260 | case 'date' : |
1261 | - return $DateTime->format( $formats[0] ); |
|
1261 | + return $DateTime->format($formats[0]); |
|
1262 | 1262 | break; |
1263 | 1263 | default : |
1264 | - return $DateTime->format( implode( ' ', $formats ) ); |
|
1264 | + return $DateTime->format(implode(' ', $formats)); |
|
1265 | 1265 | break; |
1266 | 1266 | } |
1267 | 1267 | } |
@@ -1285,18 +1285,18 @@ discard block |
||
1285 | 1285 | * 'U', this is ignored. |
1286 | 1286 | * @return DateTime |
1287 | 1287 | */ |
1288 | - public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) { |
|
1288 | + public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') { |
|
1289 | 1289 | |
1290 | 1290 | //just using this to ensure the timezone is set correctly internally |
1291 | - $this->get_formats_for( $field_name ); |
|
1291 | + $this->get_formats_for($field_name); |
|
1292 | 1292 | |
1293 | 1293 | //load EEH_DTT_Helper |
1294 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1295 | - $set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1294 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1295 | + $set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1296 | 1296 | |
1297 | - $incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) ); |
|
1297 | + $incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone)); |
|
1298 | 1298 | |
1299 | - return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) ); |
|
1299 | + return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone)); |
|
1300 | 1300 | } |
1301 | 1301 | |
1302 | 1302 | |
@@ -1306,7 +1306,7 @@ discard block |
||
1306 | 1306 | * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects |
1307 | 1307 | * @return EE_Table_Base[] |
1308 | 1308 | */ |
1309 | - function get_tables(){ |
|
1309 | + function get_tables() { |
|
1310 | 1310 | return $this->_tables; |
1311 | 1311 | } |
1312 | 1312 | |
@@ -1340,9 +1340,9 @@ discard block |
||
1340 | 1340 | * be aware that model objects being used could get out-of-sync with the database |
1341 | 1341 | * @return int how many rows got updated or FALSE if something went wrong with the query (wp returns FALSE or num rows affected which *could* include 0 which DOES NOT mean the query was bad) |
1342 | 1342 | */ |
1343 | - function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){ |
|
1344 | - if( ! is_array( $query_params ) ){ |
|
1345 | - EE_Error::doing_it_wrong('EEM_Base::update', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1343 | + function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
1344 | + if ( ! is_array($query_params)) { |
|
1345 | + EE_Error::doing_it_wrong('EEM_Base::update', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1346 | 1346 | $query_params = array(); |
1347 | 1347 | } |
1348 | 1348 | /** |
@@ -1352,7 +1352,7 @@ discard block |
||
1352 | 1352 | * @param array $fields_n_values the updated fields and their new values |
1353 | 1353 | * @param array $query_params @see EEM_Base::get_all() |
1354 | 1354 | */ |
1355 | - do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params ); |
|
1355 | + do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params); |
|
1356 | 1356 | /** |
1357 | 1357 | * Filters the fields about to be updated given the query parameters. You can provide the |
1358 | 1358 | * $query_params to $this->get_all() to find exactly which records will be updated |
@@ -1360,10 +1360,10 @@ discard block |
||
1360 | 1360 | * @param EEM_Base $model the model being queried |
1361 | 1361 | * @param array $query_params see EEM_Base::get_all() |
1362 | 1362 | */ |
1363 | - $fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params ); |
|
1363 | + $fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params); |
|
1364 | 1364 | //need to verify that, for any entry we want to update, there are entries in each secondary table. |
1365 | 1365 | //to do that, for each table, verify that it's PK isn't null. |
1366 | - $tables= $this->get_tables(); |
|
1366 | + $tables = $this->get_tables(); |
|
1367 | 1367 | |
1368 | 1368 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1369 | 1369 | //NOTE: we should make this code more efficient by NOT querying twice |
@@ -1373,29 +1373,29 @@ discard block |
||
1373 | 1373 | //we want to make sure the default_where strategy is ignored |
1374 | 1374 | $this->_ignore_where_strategy = TRUE; |
1375 | 1375 | $wpdb_select_results = $this->_get_all_wpdb_results($query_params); |
1376 | - foreach( $wpdb_select_results as $wpdb_result ){ |
|
1376 | + foreach ($wpdb_select_results as $wpdb_result) { |
|
1377 | 1377 | // type cast stdClass as array |
1378 | - $wpdb_result = (array)$wpdb_result; |
|
1378 | + $wpdb_result = (array) $wpdb_result; |
|
1379 | 1379 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1380 | - if( $this->has_primary_key_field() ){ |
|
1381 | - $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1382 | - }else{ |
|
1380 | + if ($this->has_primary_key_field()) { |
|
1381 | + $main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()]; |
|
1382 | + } else { |
|
1383 | 1383 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work) |
1384 | 1384 | $main_table_pk_value = null; |
1385 | 1385 | } |
1386 | 1386 | //if there are more than 1 tables, we'll want to verify that each table for this model has an entry in the other tables |
1387 | 1387 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1388 | - if(count($tables) > 1){ |
|
1388 | + if (count($tables) > 1) { |
|
1389 | 1389 | //foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry |
1390 | 1390 | //in that table, and so we'll want to insert one |
1391 | - foreach($tables as $table_obj){ |
|
1391 | + foreach ($tables as $table_obj) { |
|
1392 | 1392 | $this_table_pk_column = $table_obj->get_fully_qualified_pk_column(); |
1393 | 1393 | //if there is no private key for this table on the results, it means there's no entry |
1394 | 1394 | //in this table, right? so insert a row in the current table, using any fields available |
1395 | - if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){ |
|
1395 | + if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) { |
|
1396 | 1396 | $success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value); |
1397 | 1397 | //if we died here, report the error |
1398 | - if( ! $success ) { |
|
1398 | + if ( ! $success) { |
|
1399 | 1399 | return false; |
1400 | 1400 | } |
1401 | 1401 | } |
@@ -1415,44 +1415,44 @@ discard block |
||
1415 | 1415 | //if this wasn't called from a model object (to update itself) |
1416 | 1416 | //then we want to make sure we keep all the existing |
1417 | 1417 | //model objects in sync with the db |
1418 | - if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
|
1419 | - if( $this->has_primary_key_field() ){ |
|
1420 | - $model_objs_affected_ids = $this->get_col( $query_params ); |
|
1421 | - }else{ |
|
1418 | + if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) { |
|
1419 | + if ($this->has_primary_key_field()) { |
|
1420 | + $model_objs_affected_ids = $this->get_col($query_params); |
|
1421 | + } else { |
|
1422 | 1422 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1423 | - $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
|
1423 | + $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A); |
|
1424 | 1424 | $model_objs_affected_ids = array(); |
1425 | - foreach( $models_affected_key_columns as $row ){ |
|
1426 | - $combined_index_key = $this->get_index_primary_key_string( $row ); |
|
1427 | - $model_objs_affected_ids[ $combined_index_key ] = $combined_index_key; |
|
1425 | + foreach ($models_affected_key_columns as $row) { |
|
1426 | + $combined_index_key = $this->get_index_primary_key_string($row); |
|
1427 | + $model_objs_affected_ids[$combined_index_key] = $combined_index_key; |
|
1428 | 1428 | } |
1429 | 1429 | |
1430 | 1430 | } |
1431 | 1431 | |
1432 | - if( ! $model_objs_affected_ids ){ |
|
1432 | + if ( ! $model_objs_affected_ids) { |
|
1433 | 1433 | //wait wait wait- if nothing was affected let's stop here |
1434 | 1434 | return 0; |
1435 | 1435 | } |
1436 | - foreach( $model_objs_affected_ids as $id ){ |
|
1437 | - $model_obj_in_entity_map = $this->get_from_entity_map( $id ); |
|
1438 | - if( $model_obj_in_entity_map ){ |
|
1439 | - foreach( $fields_n_values as $field => $new_value ){ |
|
1440 | - $model_obj_in_entity_map->set( $field, $new_value ); |
|
1436 | + foreach ($model_objs_affected_ids as $id) { |
|
1437 | + $model_obj_in_entity_map = $this->get_from_entity_map($id); |
|
1438 | + if ($model_obj_in_entity_map) { |
|
1439 | + foreach ($fields_n_values as $field => $new_value) { |
|
1440 | + $model_obj_in_entity_map->set($field, $new_value); |
|
1441 | 1441 | } |
1442 | 1442 | } |
1443 | 1443 | } |
1444 | 1444 | //if there is a primary key on this model, we can now do a slight optimization |
1445 | - if( $this->has_primary_key_field() ){ |
|
1445 | + if ($this->has_primary_key_field()) { |
|
1446 | 1446 | //we already know what we want to update. So let's make the query simpler so it's a little more efficient |
1447 | 1447 | $query_params = array( |
1448 | - array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ), |
|
1449 | - 'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' ); |
|
1448 | + array($this->primary_key_name() => array('IN', $model_objs_affected_ids)), |
|
1449 | + 'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' ); |
|
1450 | 1450 | } |
1451 | 1451 | } |
1452 | 1452 | |
1453 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
1454 | - $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql();//note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1455 | - $rows_affected = $this->_do_wpdb_query('query', array( $SQL ) ); |
|
1453 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
1454 | + $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql(); //note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1455 | + $rows_affected = $this->_do_wpdb_query('query', array($SQL)); |
|
1456 | 1456 | /** |
1457 | 1457 | * Action called after a model update call has been made. |
1458 | 1458 | * |
@@ -1461,8 +1461,8 @@ discard block |
||
1461 | 1461 | * @param array $query_params @see EEM_Base::get_all() |
1462 | 1462 | * @param int $rows_affected |
1463 | 1463 | */ |
1464 | - do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected ); |
|
1465 | - return $rows_affected;//how many supposedly got updated |
|
1464 | + do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected); |
|
1465 | + return $rows_affected; //how many supposedly got updated |
|
1466 | 1466 | } |
1467 | 1467 | |
1468 | 1468 | /** |
@@ -1474,22 +1474,22 @@ discard block |
||
1474 | 1474 | * @param string $field_to_select |
1475 | 1475 | * @return array just like $wpdb->get_col() |
1476 | 1476 | */ |
1477 | - public function get_col( $query_params = array(), $field_to_select = NULL ){ |
|
1477 | + public function get_col($query_params = array(), $field_to_select = NULL) { |
|
1478 | 1478 | |
1479 | - if( $field_to_select ){ |
|
1480 | - $field = $this->field_settings_for( $field_to_select ); |
|
1481 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1479 | + if ($field_to_select) { |
|
1480 | + $field = $this->field_settings_for($field_to_select); |
|
1481 | + }elseif ($this->has_primary_key_field( )) { |
|
1482 | 1482 | $field = $this->get_primary_key_field(); |
1483 | - }else{ |
|
1483 | + } else { |
|
1484 | 1484 | //no primary key, just grab the first column |
1485 | - $field = reset( $this->field_settings()); |
|
1485 | + $field = reset($this->field_settings()); |
|
1486 | 1486 | } |
1487 | 1487 | |
1488 | 1488 | |
1489 | 1489 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1490 | 1490 | $select_expressions = $field->get_qualified_column(); |
1491 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1492 | - $results = $this->_do_wpdb_query('get_col', array( $SQL ) ); |
|
1491 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1492 | + $results = $this->_do_wpdb_query('get_col', array($SQL)); |
|
1493 | 1493 | return $results; |
1494 | 1494 | } |
1495 | 1495 | |
@@ -1499,12 +1499,12 @@ discard block |
||
1499 | 1499 | * @param string $field_to_select @see EEM_Base::get_col() |
1500 | 1500 | * @return string |
1501 | 1501 | */ |
1502 | - public function get_var( $query_params = array(), $field_to_select = NULL ) { |
|
1503 | - $query_params[ 'limit' ] = 1; |
|
1504 | - $col = $this->get_col( $query_params, $field_to_select ); |
|
1505 | - if( ! empty( $col ) ) { |
|
1506 | - return reset( $col ); |
|
1507 | - }else{ |
|
1502 | + public function get_var($query_params = array(), $field_to_select = NULL) { |
|
1503 | + $query_params['limit'] = 1; |
|
1504 | + $col = $this->get_col($query_params, $field_to_select); |
|
1505 | + if ( ! empty($col)) { |
|
1506 | + return reset($col); |
|
1507 | + } else { |
|
1508 | 1508 | return NULL; |
1509 | 1509 | } |
1510 | 1510 | } |
@@ -1518,19 +1518,19 @@ discard block |
||
1518 | 1518 | * @param array $fields_n_values array keys are field names on this model, and values are what those fields should be updated to in the DB |
1519 | 1519 | * @return string of SQL |
1520 | 1520 | */ |
1521 | - function _construct_update_sql($fields_n_values){ |
|
1521 | + function _construct_update_sql($fields_n_values) { |
|
1522 | 1522 | /** @type WPDB $wpdb */ |
1523 | 1523 | global $wpdb; |
1524 | 1524 | $cols_n_values = array(); |
1525 | - foreach($fields_n_values as $field_name => $value){ |
|
1525 | + foreach ($fields_n_values as $field_name => $value) { |
|
1526 | 1526 | $field_obj = $this->field_settings_for($field_name); |
1527 | 1527 | //if the value is NULL, we want to assign the value to that. |
1528 | 1528 | //wpdb->prepare doesn't really handle that properly |
1529 | - $prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values ); |
|
1530 | - $value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value ); |
|
1529 | + $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
|
1530 | + $value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value); |
|
1531 | 1531 | $cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql; |
1532 | 1532 | } |
1533 | - return implode(",",$cols_n_values); |
|
1533 | + return implode(",", $cols_n_values); |
|
1534 | 1534 | |
1535 | 1535 | } |
1536 | 1536 | |
@@ -1542,10 +1542,10 @@ discard block |
||
1542 | 1542 | * @param mixed $id |
1543 | 1543 | * @return boolean whether the row got deleted or not |
1544 | 1544 | */ |
1545 | - public function delete_permanently_by_ID( $id ) { |
|
1545 | + public function delete_permanently_by_ID($id) { |
|
1546 | 1546 | return $this->delete_permanently( |
1547 | 1547 | array( |
1548 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1548 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1549 | 1549 | 'limit' => 1 |
1550 | 1550 | ) |
1551 | 1551 | ); |
@@ -1559,10 +1559,10 @@ discard block |
||
1559 | 1559 | * @param mixed $id |
1560 | 1560 | * @return boolean whether the row got deleted or not |
1561 | 1561 | */ |
1562 | - public function delete_by_ID( $id ){ |
|
1562 | + public function delete_by_ID($id) { |
|
1563 | 1563 | return $this->delete( |
1564 | 1564 | array( |
1565 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1565 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1566 | 1566 | 'limit' => 1 |
1567 | 1567 | ) |
1568 | 1568 | ); |
@@ -1576,7 +1576,7 @@ discard block |
||
1576 | 1576 | * @param boolean $allow_blocking |
1577 | 1577 | * @return int |
1578 | 1578 | */ |
1579 | - function delete($query_params,$allow_blocking = true){ |
|
1579 | + function delete($query_params, $allow_blocking = true) { |
|
1580 | 1580 | return $this->delete_permanently($query_params, $allow_blocking); |
1581 | 1581 | } |
1582 | 1582 | |
@@ -1592,7 +1592,7 @@ discard block |
||
1592 | 1592 | * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
1593 | 1593 | * @return int how many rows got deleted |
1594 | 1594 | */ |
1595 | - function delete_permanently($query_params,$allow_blocking = true){ |
|
1595 | + function delete_permanently($query_params, $allow_blocking = true) { |
|
1596 | 1596 | /** |
1597 | 1597 | * Action called just before performing a real deletion query. You can use the |
1598 | 1598 | * model and its $query_params to find exactly which items will be deleted |
@@ -1601,34 +1601,34 @@ discard block |
||
1601 | 1601 | * @param boolean $allow_blocking whether or not to allow related model objects |
1602 | 1602 | * to block (prevent) this deletion |
1603 | 1603 | */ |
1604 | - do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking ); |
|
1604 | + do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking); |
|
1605 | 1605 | //some MySQL databases may be running safe mode, which may restrict |
1606 | 1606 | //deletion if there is no KEY column used in the WHERE statement of a deletion. |
1607 | 1607 | //to get around this, we first do a SELECT, get all the IDs, and then run another query |
1608 | 1608 | //to delete them |
1609 | 1609 | $items_for_deletion = $this->_get_all_wpdb_results($query_params); |
1610 | - $deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking); |
|
1611 | - if($deletion_where){ |
|
1610 | + $deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking); |
|
1611 | + if ($deletion_where) { |
|
1612 | 1612 | //echo "objects for deletion:";var_dump($objects_for_deletion); |
1613 | 1613 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1614 | 1614 | $table_aliases = array(); |
1615 | - foreach(array_keys($this->_tables) as $table_alias){ |
|
1615 | + foreach (array_keys($this->_tables) as $table_alias) { |
|
1616 | 1616 | $table_aliases[] = $table_alias; |
1617 | 1617 | } |
1618 | - $SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1618 | + $SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1619 | 1619 | |
1620 | 1620 | // /echo "delete sql:$SQL"; |
1621 | - $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
|
1622 | - }else{ |
|
1621 | + $rows_deleted = $this->_do_wpdb_query('query', array($SQL)); |
|
1622 | + } else { |
|
1623 | 1623 | $rows_deleted = 0; |
1624 | 1624 | } |
1625 | 1625 | |
1626 | 1626 | //and lastly make sure those items are removed from the entity map; if they could be put into it at all |
1627 | - if( $this->has_primary_key_field() ){ |
|
1628 | - foreach($items_for_deletion as $item_for_deletion_row ){ |
|
1629 | - $pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1630 | - if( isset( $this->_entity_map[ $pk_value ] ) ){ |
|
1631 | - unset( $this->_entity_map[ $pk_value ] ); |
|
1627 | + if ($this->has_primary_key_field()) { |
|
1628 | + foreach ($items_for_deletion as $item_for_deletion_row) { |
|
1629 | + $pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()]; |
|
1630 | + if (isset($this->_entity_map[$pk_value])) { |
|
1631 | + unset($this->_entity_map[$pk_value]); |
|
1632 | 1632 | } |
1633 | 1633 | } |
1634 | 1634 | } |
@@ -1640,8 +1640,8 @@ discard block |
||
1640 | 1640 | * @param array $query_params @see EEM_Base::get_all() |
1641 | 1641 | * @param int $rows_deleted |
1642 | 1642 | */ |
1643 | - do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted ); |
|
1644 | - return $rows_deleted;//how many supposedly got deleted |
|
1643 | + do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted); |
|
1644 | + return $rows_deleted; //how many supposedly got deleted |
|
1645 | 1645 | } |
1646 | 1646 | |
1647 | 1647 | |
@@ -1657,28 +1657,28 @@ discard block |
||
1657 | 1657 | * blocking its deletion before removing the relation between A and B |
1658 | 1658 | * @return boolean |
1659 | 1659 | */ |
1660 | - public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){ |
|
1660 | + public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) { |
|
1661 | 1661 | //first, if $ignore_this_model_obj was supplied, get its model |
1662 | - if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
|
1662 | + if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) { |
|
1663 | 1663 | $ignored_model = $ignore_this_model_obj->get_model(); |
1664 | - }else{ |
|
1664 | + } else { |
|
1665 | 1665 | $ignored_model = null; |
1666 | 1666 | } |
1667 | 1667 | //now check all the relations of $this_model_obj_or_id and see if there |
1668 | 1668 | //are any related model objects blocking it? |
1669 | 1669 | $is_blocked = false; |
1670 | - foreach($this->_model_relations as $relation_name => $relation_obj){ |
|
1671 | - if( $relation_obj->block_delete_if_related_models_exist()){ |
|
1670 | + foreach ($this->_model_relations as $relation_name => $relation_obj) { |
|
1671 | + if ($relation_obj->block_delete_if_related_models_exist()) { |
|
1672 | 1672 | //if $ignore_this_model_obj was supplied, then for the query |
1673 | 1673 | //on that model needs to be told to ignore $ignore_this_model_obj |
1674 | - if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){ |
|
1675 | - $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
|
1676 | - array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
|
1677 | - }else{ |
|
1674 | + if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) { |
|
1675 | + $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array( |
|
1676 | + array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID())))); |
|
1677 | + } else { |
|
1678 | 1678 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1679 | 1679 | } |
1680 | 1680 | |
1681 | - if($related_model_objects){ |
|
1681 | + if ($related_model_objects) { |
|
1682 | 1682 | EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__); |
1683 | 1683 | $is_blocked = true; |
1684 | 1684 | } |
@@ -1698,65 +1698,65 @@ discard block |
||
1698 | 1698 | * @throws EE_Error |
1699 | 1699 | * @return string everything that comes after the WHERE statement. |
1700 | 1700 | */ |
1701 | - protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) { |
|
1702 | - if($this->has_primary_key_field()){ |
|
1701 | + protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) { |
|
1702 | + if ($this->has_primary_key_field()) { |
|
1703 | 1703 | $primary_table = $this->_get_main_table(); |
1704 | 1704 | $other_tables = $this->_get_other_tables(); |
1705 | 1705 | $deletes = $query = array(); |
1706 | - foreach ( $objects_for_deletion as $delete_object ) { |
|
1706 | + foreach ($objects_for_deletion as $delete_object) { |
|
1707 | 1707 | //before we mark this object for deletion, |
1708 | 1708 | //make sure there's no related objects blocking its deletion (if we're checking) |
1709 | - if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){ |
|
1709 | + if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) { |
|
1710 | 1710 | continue; |
1711 | 1711 | } |
1712 | 1712 | |
1713 | 1713 | //primary table deletes |
1714 | - if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) |
|
1714 | + if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) |
|
1715 | 1715 | $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
1716 | 1716 | |
1717 | 1717 | //other tables |
1718 | - if ( !empty( $other_tables ) ) { |
|
1719 | - foreach ( $other_tables as $ot ) { |
|
1718 | + if ( ! empty($other_tables)) { |
|
1719 | + foreach ($other_tables as $ot) { |
|
1720 | 1720 | |
1721 | 1721 | //first check if we've got the foreign key column here. |
1722 | - if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) |
|
1722 | + if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) |
|
1723 | 1723 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
1724 | 1724 | |
1725 | 1725 | //wait! it's entirely possible that we'll have a the primary key for this table in here if it's a foreign key for one of the other secondary tables |
1726 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) |
|
1726 | + if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) |
|
1727 | 1727 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1728 | 1728 | |
1729 | 1729 | //finally, it is possible that the fk for this table is found in the fully qualified pk column for the fk table, so let's see if that's there! |
1730 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) |
|
1730 | + if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) |
|
1731 | 1731 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1732 | 1732 | } |
1733 | 1733 | } |
1734 | 1734 | } |
1735 | 1735 | |
1736 | 1736 | //we should have deletes now, so let's just go through and setup the where statement |
1737 | - foreach ( $deletes as $column => $values ) { |
|
1737 | + foreach ($deletes as $column => $values) { |
|
1738 | 1738 | //make sure we have unique $values; |
1739 | 1739 | $values = array_unique($values); |
1740 | - $query[] = $column . ' IN(' . implode(",",$values) . ')'; |
|
1740 | + $query[] = $column.' IN('.implode(",", $values).')'; |
|
1741 | 1741 | } |
1742 | 1742 | |
1743 | - return !empty($query) ? implode(' AND ', $query ) : ''; |
|
1744 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1743 | + return ! empty($query) ? implode(' AND ', $query) : ''; |
|
1744 | + }elseif (count($this->get_combined_primary_key_fields()) > 1) { |
|
1745 | 1745 | $ways_to_identify_a_row = array(); |
1746 | 1746 | $fields = $this->get_combined_primary_key_fields(); |
1747 | 1747 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
1748 | - foreach($objects_for_deletion as $delete_object){ |
|
1748 | + foreach ($objects_for_deletion as $delete_object) { |
|
1749 | 1749 | $values_for_each_cpk_for_a_row = array(); |
1750 | - foreach($fields as $cpk_field){ |
|
1750 | + foreach ($fields as $cpk_field) { |
|
1751 | 1751 | $values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()]; |
1752 | 1752 | } |
1753 | - $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
|
1753 | + $ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")"; |
|
1754 | 1754 | } |
1755 | - return implode(" OR ",$ways_to_identify_a_row); |
|
1756 | - }else{ |
|
1755 | + return implode(" OR ", $ways_to_identify_a_row); |
|
1756 | + } else { |
|
1757 | 1757 | //so there's no primary key and no combined key... |
1758 | 1758 | //sorry, can't help you |
1759 | - throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this))); |
|
1759 | + throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"), get_class($this))); |
|
1760 | 1760 | } |
1761 | 1761 | } |
1762 | 1762 | |
@@ -1770,21 +1770,21 @@ discard block |
||
1770 | 1770 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
1771 | 1771 | * @return int |
1772 | 1772 | */ |
1773 | - function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1773 | + function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1774 | 1774 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1775 | - if($field_to_count){ |
|
1775 | + if ($field_to_count) { |
|
1776 | 1776 | $field_obj = $this->field_settings_for($field_to_count); |
1777 | 1777 | $column_to_count = $field_obj->get_qualified_column(); |
1778 | - }elseif($this->has_primary_key_field ()){ |
|
1778 | + }elseif ($this->has_primary_key_field()) { |
|
1779 | 1779 | $pk_field_obj = $this->get_primary_key_field(); |
1780 | 1780 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1781 | - }else{//there's no primary key |
|
1781 | + } else {//there's no primary key |
|
1782 | 1782 | $column_to_count = '*'; |
1783 | 1783 | } |
1784 | 1784 | |
1785 | - $column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count; |
|
1786 | - $SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1787 | - return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) ); |
|
1785 | + $column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count; |
|
1786 | + $SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1787 | + return (int) $this->_do_wpdb_query('get_var', array($SQL)); |
|
1788 | 1788 | } |
1789 | 1789 | |
1790 | 1790 | /** |
@@ -1794,23 +1794,23 @@ discard block |
||
1794 | 1794 | * @param string $field_to_sum name of field (array key in $_fields array) |
1795 | 1795 | * @return float |
1796 | 1796 | */ |
1797 | - function sum($query_params, $field_to_sum = NULL){ |
|
1797 | + function sum($query_params, $field_to_sum = NULL) { |
|
1798 | 1798 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1799 | 1799 | |
1800 | - if($field_to_sum){ |
|
1800 | + if ($field_to_sum) { |
|
1801 | 1801 | $field_obj = $this->field_settings_for($field_to_sum); |
1802 | 1802 | |
1803 | - }else{ |
|
1803 | + } else { |
|
1804 | 1804 | $field_obj = $this->get_primary_key_field(); |
1805 | 1805 | } |
1806 | 1806 | $column_to_count = $field_obj->get_qualified_column(); |
1807 | 1807 | |
1808 | - $SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1809 | - $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
|
1810 | - if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){ |
|
1811 | - return (float)$return_value; |
|
1812 | - }else{//must be %f |
|
1813 | - return (float)$return_value; |
|
1808 | + $SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1809 | + $return_value = $this->_do_wpdb_query('get_var', array($SQL)); |
|
1810 | + if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') { |
|
1811 | + return (float) $return_value; |
|
1812 | + } else {//must be %f |
|
1813 | + return (float) $return_value; |
|
1814 | 1814 | } |
1815 | 1815 | } |
1816 | 1816 | |
@@ -1825,33 +1825,33 @@ discard block |
||
1825 | 1825 | * @global wpdb $wpdb |
1826 | 1826 | * @return mixed |
1827 | 1827 | */ |
1828 | - protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){ |
|
1828 | + protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1829 | 1829 | //if we're in maintenance mode level 2, DON'T run any queries |
1830 | 1830 | //because level 2 indicates the database needs updating and |
1831 | 1831 | //is probably out of sync with the code |
1832 | - if( ! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
1832 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
1833 | 1833 | throw new EE_Error(sprintf(__("Event Espresso Level 2 Maintenance mode is active. That means EE can not run ANY database queries until the necessary migration scripts have run which will take EE out of maintenance mode level 2. Please inform support of this error.", "event_espresso"))); |
1834 | 1834 | } |
1835 | 1835 | /** @type WPDB $wpdb */ |
1836 | 1836 | global $wpdb; |
1837 | - if( ! method_exists( $wpdb, $wpdb_method ) ){ |
|
1838 | - throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) ); |
|
1837 | + if ( ! method_exists($wpdb, $wpdb_method)) { |
|
1838 | + throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method)); |
|
1839 | 1839 | } |
1840 | - if( WP_DEBUG ){ |
|
1840 | + if (WP_DEBUG) { |
|
1841 | 1841 | $old_show_errors_value = $wpdb->show_errors; |
1842 | - $wpdb->show_errors( FALSE ); |
|
1843 | - } |
|
1844 | - $result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1845 | - $this->show_db_query_if_previously_requested( $wpdb->last_query ); |
|
1846 | - if( WP_DEBUG ){ |
|
1847 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1848 | - if( ! empty( $wpdb->last_error ) ){ |
|
1849 | - throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
|
1850 | - }elseif( $result === false ){ |
|
1851 | - throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) ); |
|
1842 | + $wpdb->show_errors(FALSE); |
|
1843 | + } |
|
1844 | + $result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1845 | + $this->show_db_query_if_previously_requested($wpdb->last_query); |
|
1846 | + if (WP_DEBUG) { |
|
1847 | + $wpdb->show_errors($old_show_errors_value); |
|
1848 | + if ( ! empty($wpdb->last_error)) { |
|
1849 | + throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error)); |
|
1850 | + }elseif ($result === false) { |
|
1851 | + throw new EE_Error(sprintf(__('WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso'), $wpdb_method, var_export($arguments_to_provide, true))); |
|
1852 | 1852 | } |
1853 | - }elseif( $result === false ) { |
|
1854 | - EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
|
1853 | + }elseif ($result === false) { |
|
1854 | + EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__); |
|
1855 | 1855 | } |
1856 | 1856 | return $result; |
1857 | 1857 | } |
@@ -1867,26 +1867,26 @@ discard block |
||
1867 | 1867 | * @param array $arguments_to_provide |
1868 | 1868 | * @return mixed |
1869 | 1869 | */ |
1870 | - private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) { |
|
1870 | + private function _process_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1871 | 1871 | /** @type WPDB $wpdb */ |
1872 | 1872 | global $wpdb; |
1873 | 1873 | $wpdb->last_error = null; |
1874 | - $result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide ); |
|
1874 | + $result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide); |
|
1875 | 1875 | // was there an error running the query? but we don't care on new activations |
1876 | 1876 | // (we're going to setup the DB anyway on new activations) |
1877 | - if ( ( $result === false || ! empty( $wpdb->last_error ) ) |
|
1877 | + if (($result === false || ! empty($wpdb->last_error)) |
|
1878 | 1878 | && EE_System::instance()->detect_req_type() != EE_System::req_type_new_activation |
1879 | 1879 | ) { |
1880 | - switch ( EEM_Base::$_db_verification_level ) { |
|
1880 | + switch (EEM_Base::$_db_verification_level) { |
|
1881 | 1881 | |
1882 | 1882 | case EEM_Base::db_verified_none : |
1883 | 1883 | // let's double-check core's DB |
1884 | - $error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide ); |
|
1884 | + $error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide); |
|
1885 | 1885 | break; |
1886 | 1886 | |
1887 | 1887 | case EEM_Base::db_verified_core : |
1888 | 1888 | // STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed |
1889 | - $error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide ); |
|
1889 | + $error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide); |
|
1890 | 1890 | break; |
1891 | 1891 | |
1892 | 1892 | case EEM_Base::db_verified_addons : |
@@ -1894,11 +1894,11 @@ discard block |
||
1894 | 1894 | return $result; |
1895 | 1895 | break; |
1896 | 1896 | } |
1897 | - if ( ! empty( $error_message ) ) { |
|
1898 | - EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' ); |
|
1899 | - trigger_error( $error_message ); |
|
1897 | + if ( ! empty($error_message)) { |
|
1898 | + EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error'); |
|
1899 | + trigger_error($error_message); |
|
1900 | 1900 | } |
1901 | - return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1901 | + return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1902 | 1902 | |
1903 | 1903 | } |
1904 | 1904 | |
@@ -1914,18 +1914,18 @@ discard block |
||
1914 | 1914 | * @param array $arguments_to_provide |
1915 | 1915 | * @return string |
1916 | 1916 | */ |
1917 | - private function _verify_core_db( $wpdb_method, $arguments_to_provide ){ |
|
1917 | + private function _verify_core_db($wpdb_method, $arguments_to_provide) { |
|
1918 | 1918 | /** @type WPDB $wpdb */ |
1919 | 1919 | global $wpdb; |
1920 | 1920 | //ok remember that we've already attempted fixing the core db, in case the problem persists |
1921 | 1921 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_core; |
1922 | 1922 | $error_message = sprintf( |
1923 | - __( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ), |
|
1923 | + __('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'), |
|
1924 | 1924 | $wpdb->last_error, |
1925 | 1925 | $wpdb_method, |
1926 | - json_encode( $arguments_to_provide ) |
|
1926 | + json_encode($arguments_to_provide) |
|
1927 | 1927 | ); |
1928 | - EE_System::instance()->initialize_db_if_no_migrations_required( false, true ); |
|
1928 | + EE_System::instance()->initialize_db_if_no_migrations_required(false, true); |
|
1929 | 1929 | return $error_message; |
1930 | 1930 | } |
1931 | 1931 | |
@@ -1938,16 +1938,16 @@ discard block |
||
1938 | 1938 | * @param $arguments_to_provide |
1939 | 1939 | * @return string |
1940 | 1940 | */ |
1941 | - private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) { |
|
1941 | + private function _verify_addons_db($wpdb_method, $arguments_to_provide) { |
|
1942 | 1942 | /** @type WPDB $wpdb */ |
1943 | 1943 | global $wpdb; |
1944 | 1944 | //ok remember that we've already attempted fixing the addons dbs, in case the problem persists |
1945 | 1945 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons; |
1946 | 1946 | $error_message = sprintf( |
1947 | - __( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ), |
|
1947 | + __('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'), |
|
1948 | 1948 | $wpdb->last_error, |
1949 | 1949 | $wpdb_method, |
1950 | - json_encode( $arguments_to_provide ) |
|
1950 | + json_encode($arguments_to_provide) |
|
1951 | 1951 | ); |
1952 | 1952 | EE_System::instance()->initialize_addons(); |
1953 | 1953 | return $error_message; |
@@ -1962,7 +1962,7 @@ discard block |
||
1962 | 1962 | * @param EE_Model_Query_Info_Carrier $model_query_info |
1963 | 1963 | * @return string |
1964 | 1964 | */ |
1965 | - private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){ |
|
1965 | + private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) { |
|
1966 | 1966 | return " FROM ".$model_query_info->get_full_join_sql(). |
1967 | 1967 | $model_query_info->get_where_sql(). |
1968 | 1968 | $model_query_info->get_group_by_sql(). |
@@ -1975,7 +1975,7 @@ discard block |
||
1975 | 1975 | * Set to easily debug the next X queries ran from this model. |
1976 | 1976 | * @param int $count |
1977 | 1977 | */ |
1978 | - function show_next_x_db_queries($count = 1){ |
|
1978 | + function show_next_x_db_queries($count = 1) { |
|
1979 | 1979 | $this->_show_next_x_db_queries = $count; |
1980 | 1980 | } |
1981 | 1981 | |
@@ -1984,8 +1984,8 @@ discard block |
||
1984 | 1984 | /** |
1985 | 1985 | * @param $sql_query |
1986 | 1986 | */ |
1987 | - function show_db_query_if_previously_requested($sql_query){ |
|
1988 | - if($this->_show_next_x_db_queries > 0){ |
|
1987 | + function show_db_query_if_previously_requested($sql_query) { |
|
1988 | + if ($this->_show_next_x_db_queries > 0) { |
|
1989 | 1989 | echo $sql_query; |
1990 | 1990 | $this->_show_next_x_db_queries--; |
1991 | 1991 | } |
@@ -2009,9 +2009,9 @@ discard block |
||
2009 | 2009 | * @param array $extra_join_model_fields_n_values This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
2010 | 2010 | * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj |
2011 | 2011 | */ |
2012 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){ |
|
2012 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) { |
|
2013 | 2013 | $relation_obj = $this->related_settings_for($relationName); |
2014 | - return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2014 | + return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2015 | 2015 | } |
2016 | 2016 | |
2017 | 2017 | /** |
@@ -2030,9 +2030,9 @@ discard block |
||
2030 | 2030 | * @return boolean of success |
2031 | 2031 | * @param array $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
2032 | 2032 | */ |
2033 | - public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
|
2033 | + public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
2034 | 2034 | $relation_obj = $this->related_settings_for($relationName); |
2035 | - return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query ); |
|
2035 | + return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query); |
|
2036 | 2036 | } |
2037 | 2037 | |
2038 | 2038 | |
@@ -2045,9 +2045,9 @@ discard block |
||
2045 | 2045 | * @param EE_Base_Class[] objects to which relations were removed |
2046 | 2046 | * @return \EE_Base_Class[] |
2047 | 2047 | */ |
2048 | - public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){ |
|
2048 | + public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) { |
|
2049 | 2049 | $relation_obj = $this->related_settings_for($relationName); |
2050 | - return $relation_obj->remove_relations($id_or_obj, $where_query_params ); |
|
2050 | + return $relation_obj->remove_relations($id_or_obj, $where_query_params); |
|
2051 | 2051 | } |
2052 | 2052 | |
2053 | 2053 | |
@@ -2060,10 +2060,10 @@ discard block |
||
2060 | 2060 | * @param array $query_params like EEM_Base::get_all |
2061 | 2061 | * @return EE_Base_Class[] |
2062 | 2062 | */ |
2063 | - function get_all_related($id_or_obj, $model_name, $query_params = null){ |
|
2063 | + function get_all_related($id_or_obj, $model_name, $query_params = null) { |
|
2064 | 2064 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2065 | 2065 | $relation_settings = $this->related_settings_for($model_name); |
2066 | - return $relation_settings->get_all_related($model_obj,$query_params); |
|
2066 | + return $relation_settings->get_all_related($model_obj, $query_params); |
|
2067 | 2067 | } |
2068 | 2068 | |
2069 | 2069 | /** |
@@ -2076,10 +2076,10 @@ discard block |
||
2076 | 2076 | * @param array $query_params |
2077 | 2077 | * @return int how many deleted |
2078 | 2078 | */ |
2079 | - public function delete_related($id_or_obj,$model_name, $query_params = array()){ |
|
2079 | + public function delete_related($id_or_obj, $model_name, $query_params = array()) { |
|
2080 | 2080 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2081 | 2081 | $relation_settings = $this->related_settings_for($model_name); |
2082 | - return $relation_settings->delete_all_related($model_obj,$query_params); |
|
2082 | + return $relation_settings->delete_all_related($model_obj, $query_params); |
|
2083 | 2083 | } |
2084 | 2084 | |
2085 | 2085 | /** |
@@ -2092,10 +2092,10 @@ discard block |
||
2092 | 2092 | * @param array $query_params |
2093 | 2093 | * @return int how many deleted |
2094 | 2094 | */ |
2095 | - public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){ |
|
2095 | + public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) { |
|
2096 | 2096 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2097 | 2097 | $relation_settings = $this->related_settings_for($model_name); |
2098 | - return $relation_settings->delete_related_permanently($model_obj,$query_params); |
|
2098 | + return $relation_settings->delete_related_permanently($model_obj, $query_params); |
|
2099 | 2099 | } |
2100 | 2100 | |
2101 | 2101 | /** |
@@ -2108,17 +2108,17 @@ discard block |
||
2108 | 2108 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
2109 | 2109 | * @return int |
2110 | 2110 | */ |
2111 | - function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){ |
|
2111 | + function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) { |
|
2112 | 2112 | $related_model = $this->get_related_model_obj($model_name); |
2113 | 2113 | //we're just going to use the query params on the related model's normal get_all query, |
2114 | 2114 | //except add a condition to say to match the current mod |
2115 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2116 | - $query_params['default_where_conditions']='none'; |
|
2115 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2116 | + $query_params['default_where_conditions'] = 'none'; |
|
2117 | 2117 | } |
2118 | 2118 | $this_model_name = $this->get_this_model_name(); |
2119 | 2119 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2120 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2121 | - return $related_model->count($query_params,$field_to_count,$distinct); |
|
2120 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2121 | + return $related_model->count($query_params, $field_to_count, $distinct); |
|
2122 | 2122 | } |
2123 | 2123 | |
2124 | 2124 | |
@@ -2132,21 +2132,21 @@ discard block |
||
2132 | 2132 | * @param string $field_to_sum name of field to count by. By default, uses primary key |
2133 | 2133 | * @return float |
2134 | 2134 | */ |
2135 | - function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){ |
|
2135 | + function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) { |
|
2136 | 2136 | $related_model = $this->get_related_model_obj($model_name); |
2137 | - if( ! is_array( $query_params ) ){ |
|
2138 | - EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
2137 | + if ( ! is_array($query_params)) { |
|
2138 | + EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
2139 | 2139 | $query_params = array(); |
2140 | 2140 | } |
2141 | 2141 | //we're just going to use the query params on the related model's normal get_all query, |
2142 | 2142 | //except add a condition to say to match the current mod |
2143 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2144 | - $query_params['default_where_conditions']='none'; |
|
2143 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2144 | + $query_params['default_where_conditions'] = 'none'; |
|
2145 | 2145 | } |
2146 | 2146 | $this_model_name = $this->get_this_model_name(); |
2147 | 2147 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2148 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2149 | - return $related_model->sum($query_params,$field_to_sum); |
|
2148 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2149 | + return $related_model->sum($query_params, $field_to_sum); |
|
2150 | 2150 | } |
2151 | 2151 | |
2152 | 2152 | |
@@ -2158,12 +2158,12 @@ discard block |
||
2158 | 2158 | * @param array $query_params like EEM_Base::get_all's |
2159 | 2159 | * @return EE_Base_Class |
2160 | 2160 | */ |
2161 | - public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){ |
|
2162 | - $query_params['limit']=1; |
|
2163 | - $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
|
2164 | - if( $results ){ |
|
2161 | + public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) { |
|
2162 | + $query_params['limit'] = 1; |
|
2163 | + $results = $this->get_all_related($id_or_obj, $other_model_name, $query_params); |
|
2164 | + if ($results) { |
|
2165 | 2165 | return array_shift($results); |
2166 | - }else{ |
|
2166 | + } else { |
|
2167 | 2167 | return null; |
2168 | 2168 | } |
2169 | 2169 | |
@@ -2173,8 +2173,8 @@ discard block |
||
2173 | 2173 | * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event |
2174 | 2174 | * @return string |
2175 | 2175 | */ |
2176 | - function get_this_model_name(){ |
|
2177 | - return str_replace("EEM_","",get_class($this)); |
|
2176 | + function get_this_model_name() { |
|
2177 | + return str_replace("EEM_", "", get_class($this)); |
|
2178 | 2178 | } |
2179 | 2179 | |
2180 | 2180 | /** |
@@ -2182,14 +2182,14 @@ discard block |
||
2182 | 2182 | * @return EE_Any_Foreign_Model_Name_Field |
2183 | 2183 | * @throws EE_Error |
2184 | 2184 | */ |
2185 | - public function get_field_containing_related_model_name(){ |
|
2186 | - foreach($this->field_settings(true) as $field){ |
|
2187 | - if($field instanceof EE_Any_Foreign_Model_Name_Field){ |
|
2185 | + public function get_field_containing_related_model_name() { |
|
2186 | + foreach ($this->field_settings(true) as $field) { |
|
2187 | + if ($field instanceof EE_Any_Foreign_Model_Name_Field) { |
|
2188 | 2188 | $field_with_model_name = $field; |
2189 | 2189 | } |
2190 | 2190 | } |
2191 | - if( !isset($field_with_model_name) || !$field_with_model_name ){ |
|
2192 | - throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() )); |
|
2191 | + if ( ! isset($field_with_model_name) || ! $field_with_model_name) { |
|
2192 | + throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name())); |
|
2193 | 2193 | } |
2194 | 2194 | return $field_with_model_name; |
2195 | 2195 | } |
@@ -2210,19 +2210,19 @@ discard block |
||
2210 | 2210 | * @return int new primary key on main table that got inserted |
2211 | 2211 | * @throws EE_Error |
2212 | 2212 | */ |
2213 | - function insert($field_n_values){ |
|
2213 | + function insert($field_n_values) { |
|
2214 | 2214 | /** |
2215 | 2215 | * Filters the fields and their values before inserting an item using the models |
2216 | 2216 | * @param array $fields_n_values keys are the fields and values are their new values |
2217 | 2217 | * @param EEM_Base $model the model used |
2218 | 2218 | */ |
2219 | - $field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this ); |
|
2220 | - if($this->_satisfies_unique_indexes($field_n_values)){ |
|
2219 | + $field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this); |
|
2220 | + if ($this->_satisfies_unique_indexes($field_n_values)) { |
|
2221 | 2221 | $main_table = $this->_get_main_table(); |
2222 | 2222 | $new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false); |
2223 | - if( $new_id !== false ) { |
|
2224 | - foreach($this->_get_other_tables() as $other_table){ |
|
2225 | - $this->_insert_into_specific_table($other_table, $field_n_values,$new_id); |
|
2223 | + if ($new_id !== false) { |
|
2224 | + foreach ($this->_get_other_tables() as $other_table) { |
|
2225 | + $this->_insert_into_specific_table($other_table, $field_n_values, $new_id); |
|
2226 | 2226 | } |
2227 | 2227 | } |
2228 | 2228 | /** |
@@ -2232,9 +2232,9 @@ discard block |
||
2232 | 2232 | * @param array $fields_n_values fields and their values |
2233 | 2233 | * @param int|string the ID of the newly-inserted model object |
2234 | 2234 | */ |
2235 | - do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
|
2235 | + do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id); |
|
2236 | 2236 | return $new_id; |
2237 | - }else{ |
|
2237 | + } else { |
|
2238 | 2238 | return FALSE; |
2239 | 2239 | } |
2240 | 2240 | } |
@@ -2247,11 +2247,11 @@ discard block |
||
2247 | 2247 | * @param string $action |
2248 | 2248 | * @return boolean |
2249 | 2249 | */ |
2250 | - protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){ |
|
2251 | - foreach($this->unique_indexes() as $index_name => $index){ |
|
2250 | + protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') { |
|
2251 | + foreach ($this->unique_indexes() as $index_name => $index) { |
|
2252 | 2252 | $uniqueness_where_params = array_intersect_key($field_n_values, $index->fields()); |
2253 | - if($this->exists(array($uniqueness_where_params))){ |
|
2254 | - EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"),$action,$this->_get_class_name(),$index_name,implode(",",$index->field_names()),http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__ ); |
|
2253 | + if ($this->exists(array($uniqueness_where_params))) { |
|
2254 | + EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"), $action, $this->_get_class_name(), $index_name, implode(",", $index->field_names()), http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__); |
|
2255 | 2255 | return false; |
2256 | 2256 | } |
2257 | 2257 | } |
@@ -2272,28 +2272,28 @@ discard block |
||
2272 | 2272 | * @throws EE_Error |
2273 | 2273 | * @return EE_Base_Class |
2274 | 2274 | */ |
2275 | - public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
|
2276 | - if($obj_or_fields_array instanceof EE_Base_Class){ |
|
2275 | + public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) { |
|
2276 | + if ($obj_or_fields_array instanceof EE_Base_Class) { |
|
2277 | 2277 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2278 | - }elseif( is_array($obj_or_fields_array)){ |
|
2278 | + }elseif (is_array($obj_or_fields_array)) { |
|
2279 | 2279 | $fields_n_values = $obj_or_fields_array; |
2280 | - }else{ |
|
2281 | - throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array)); |
|
2280 | + } else { |
|
2281 | + throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"), get_class($this), $obj_or_fields_array)); |
|
2282 | 2282 | } |
2283 | 2283 | $query_params = array(); |
2284 | - if( $this->has_primary_key_field() && |
|
2285 | - ( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2286 | - isset($fields_n_values[$this->primary_key_name()])){ |
|
2284 | + if ($this->has_primary_key_field() && |
|
2285 | + ($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2286 | + isset($fields_n_values[$this->primary_key_name()])) { |
|
2287 | 2287 | $query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()]; |
2288 | 2288 | } |
2289 | - foreach($this->unique_indexes() as $unique_index_name=>$unique_index){ |
|
2289 | + foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) { |
|
2290 | 2290 | $uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields()); |
2291 | 2291 | $query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params; |
2292 | 2292 | } |
2293 | 2293 | //if there is nothing to base this search on, then we shouldn't find anything |
2294 | - if( empty( $query_params ) ){ |
|
2294 | + if (empty($query_params)) { |
|
2295 | 2295 | return array(); |
2296 | - }else{ |
|
2296 | + } else { |
|
2297 | 2297 | return $this->get_one($query_params); |
2298 | 2298 | } |
2299 | 2299 | } |
@@ -2303,7 +2303,7 @@ discard block |
||
2303 | 2303 | * @param array $query_params |
2304 | 2304 | * @return boolean |
2305 | 2305 | */ |
2306 | - function exists($query_params){ |
|
2306 | + function exists($query_params) { |
|
2307 | 2307 | $query_params['limit'] = 1; |
2308 | 2308 | return $this->count($query_params) > 0; |
2309 | 2309 | } |
@@ -2313,7 +2313,7 @@ discard block |
||
2313 | 2313 | * @param int|string $id |
2314 | 2314 | * @return boolean |
2315 | 2315 | */ |
2316 | - function exists_by_ID($id){ |
|
2316 | + function exists_by_ID($id) { |
|
2317 | 2317 | return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id))); |
2318 | 2318 | } |
2319 | 2319 | |
@@ -2333,45 +2333,45 @@ discard block |
||
2333 | 2333 | * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert |
2334 | 2334 | * @return int ID of new row inserted, or FALSE on failure |
2335 | 2335 | */ |
2336 | - protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){ |
|
2336 | + protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) { |
|
2337 | 2337 | global $wpdb; |
2338 | 2338 | $insertion_col_n_values = array(); |
2339 | 2339 | $format_for_insertion = array(); |
2340 | 2340 | $fields_on_table = $this->_get_fields_for_table($table->get_table_alias()); |
2341 | - foreach($fields_on_table as $field_name => $field_obj){ |
|
2341 | + foreach ($fields_on_table as $field_name => $field_obj) { |
|
2342 | 2342 | //check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing |
2343 | - if($field_obj->is_auto_increment()){ |
|
2343 | + if ($field_obj->is_auto_increment()) { |
|
2344 | 2344 | continue; |
2345 | 2345 | } |
2346 | 2346 | $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
2347 | 2347 | //if the value we want to assign it to is NULL, just don't mention it for the insertion |
2348 | - if( $prepared_value !== NULL ){ |
|
2349 | - $insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value; |
|
2348 | + if ($prepared_value !== NULL) { |
|
2349 | + $insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value; |
|
2350 | 2350 | $format_for_insertion[] = $field_obj->get_wpdb_data_type(); |
2351 | 2351 | } |
2352 | 2352 | } |
2353 | 2353 | |
2354 | - if($table instanceof EE_Secondary_Table && $new_id){ |
|
2354 | + if ($table instanceof EE_Secondary_Table && $new_id) { |
|
2355 | 2355 | //its not the main table, so we should have already saved the main table's PK which we just inserted |
2356 | 2356 | //so add the fk to the main table as a column |
2357 | 2357 | $insertion_col_n_values[$table->get_fk_on_table()] = $new_id; |
2358 | - $format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs |
|
2358 | + $format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs |
|
2359 | 2359 | } |
2360 | 2360 | //insert the new entry |
2361 | - $result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) ); |
|
2362 | - if( $result === false ) { |
|
2361 | + $result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion)); |
|
2362 | + if ($result === false) { |
|
2363 | 2363 | return false; |
2364 | 2364 | } |
2365 | 2365 | //ok, now what do we return for the ID of the newly-inserted thing? |
2366 | - if($this->has_primary_key_field()){ |
|
2367 | - if($this->get_primary_key_field()->is_auto_increment()){ |
|
2366 | + if ($this->has_primary_key_field()) { |
|
2367 | + if ($this->get_primary_key_field()->is_auto_increment()) { |
|
2368 | 2368 | return $wpdb->insert_id; |
2369 | - }else{ |
|
2369 | + } else { |
|
2370 | 2370 | //it's not an auto-increment primary key, so |
2371 | 2371 | //it must have been supplied |
2372 | 2372 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2373 | 2373 | } |
2374 | - }else{ |
|
2374 | + } else { |
|
2375 | 2375 | //we can't return a primary key because there is none. instead return |
2376 | 2376 | //a unique string indicating this model |
2377 | 2377 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2386,15 +2386,15 @@ discard block |
||
2386 | 2386 | * @param array $fields_n_values |
2387 | 2387 | * @return mixed string|int|float depending on what the table column will be expecting |
2388 | 2388 | */ |
2389 | - protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){ |
|
2389 | + protected function _prepare_value_or_use_default($field_obj, $fields_n_values) { |
|
2390 | 2390 | //if this field doesn't allow nullable, don't allow it |
2391 | - if( ! $field_obj->is_nullable() && ( |
|
2392 | - ! isset( $fields_n_values[ $field_obj->get_name() ] ) || |
|
2393 | - $fields_n_values[ $field_obj->get_name() ] === NULL ) ){ |
|
2394 | - $fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value(); |
|
2391 | + if ( ! $field_obj->is_nullable() && ( |
|
2392 | + ! isset($fields_n_values[$field_obj->get_name()]) || |
|
2393 | + $fields_n_values[$field_obj->get_name()] === NULL )) { |
|
2394 | + $fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value(); |
|
2395 | 2395 | } |
2396 | - $unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL; |
|
2397 | - return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj); |
|
2396 | + $unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL; |
|
2397 | + return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj); |
|
2398 | 2398 | } |
2399 | 2399 | |
2400 | 2400 | |
@@ -2406,9 +2406,9 @@ discard block |
||
2406 | 2406 | * @param EE_Model_Field_Base $field field which will be doing the preparing of the value. If null, we assume $value is a custom selection |
2407 | 2407 | * @return mixed a value ready for use in the database for insertions, updating, or in a where clause |
2408 | 2408 | */ |
2409 | - private function _prepare_value_for_use_in_db($value, $field){ |
|
2410 | - if($field && $field instanceof EE_Model_Field_Base){ |
|
2411 | - switch( $this->_values_already_prepared_by_model_object ){ |
|
2409 | + private function _prepare_value_for_use_in_db($value, $field) { |
|
2410 | + if ($field && $field instanceof EE_Model_Field_Base) { |
|
2411 | + switch ($this->_values_already_prepared_by_model_object) { |
|
2412 | 2412 | /** @noinspection PhpMissingBreakStatementInspection */ |
2413 | 2413 | case self::not_prepared_by_model_object: |
2414 | 2414 | $value = $field->prepare_for_set($value); |
@@ -2419,7 +2419,7 @@ discard block |
||
2419 | 2419 | //leave the value alone |
2420 | 2420 | } |
2421 | 2421 | return $value; |
2422 | - }else{ |
|
2422 | + } else { |
|
2423 | 2423 | return $value; |
2424 | 2424 | } |
2425 | 2425 | } |
@@ -2429,13 +2429,13 @@ discard block |
||
2429 | 2429 | * @return EE_Primary_Table |
2430 | 2430 | * @throws EE_Error |
2431 | 2431 | */ |
2432 | - protected function _get_main_table(){ |
|
2433 | - foreach($this->_tables as $table){ |
|
2434 | - if($table instanceof EE_Primary_Table){ |
|
2432 | + protected function _get_main_table() { |
|
2433 | + foreach ($this->_tables as $table) { |
|
2434 | + if ($table instanceof EE_Primary_Table) { |
|
2435 | 2435 | return $table; |
2436 | 2436 | } |
2437 | 2437 | } |
2438 | - throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor','event_espresso'),get_class($this))); |
|
2438 | + throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor', 'event_espresso'), get_class($this))); |
|
2439 | 2439 | } |
2440 | 2440 | |
2441 | 2441 | /** |
@@ -2454,7 +2454,7 @@ discard block |
||
2454 | 2454 | */ |
2455 | 2455 | public function second_table() { |
2456 | 2456 | // grab second table from tables array |
2457 | - $second_table = end( $this->_tables ); |
|
2457 | + $second_table = end($this->_tables); |
|
2458 | 2458 | return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL; |
2459 | 2459 | } |
2460 | 2460 | |
@@ -2467,8 +2467,8 @@ discard block |
||
2467 | 2467 | * @param string $table_alias |
2468 | 2468 | * @return EE_Primary_Table | EE_Secondary_Table |
2469 | 2469 | */ |
2470 | - public function get_table_obj_by_alias( $table_alias = '' ) { |
|
2471 | - return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL; |
|
2470 | + public function get_table_obj_by_alias($table_alias = '') { |
|
2471 | + return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL; |
|
2472 | 2472 | } |
2473 | 2473 | |
2474 | 2474 | |
@@ -2477,10 +2477,10 @@ discard block |
||
2477 | 2477 | * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables |
2478 | 2478 | * @return EE_Secondary_Table[] |
2479 | 2479 | */ |
2480 | - protected function _get_other_tables(){ |
|
2481 | - $other_tables =array(); |
|
2482 | - foreach($this->_tables as $table_alias => $table){ |
|
2483 | - if($table instanceof EE_Secondary_Table){ |
|
2480 | + protected function _get_other_tables() { |
|
2481 | + $other_tables = array(); |
|
2482 | + foreach ($this->_tables as $table_alias => $table) { |
|
2483 | + if ($table instanceof EE_Secondary_Table) { |
|
2484 | 2484 | $other_tables[$table_alias] = $table; |
2485 | 2485 | } |
2486 | 2486 | } |
@@ -2492,7 +2492,7 @@ discard block |
||
2492 | 2492 | * @param string $table_alias, array key in EEM_Base::_tables |
2493 | 2493 | * @return EE_Model_Field_Base[] |
2494 | 2494 | */ |
2495 | - function _get_fields_for_table($table_alias){ |
|
2495 | + function _get_fields_for_table($table_alias) { |
|
2496 | 2496 | return $this->_fields[$table_alias]; |
2497 | 2497 | } |
2498 | 2498 | |
@@ -2504,29 +2504,29 @@ discard block |
||
2504 | 2504 | * @param array $query_params like EEM_Base::get_all's $query_parameters['where'] |
2505 | 2505 | * @return EE_Model_Query_Info_Carrier |
2506 | 2506 | */ |
2507 | - function _extract_related_models_from_query($query_params){ |
|
2507 | + function _extract_related_models_from_query($query_params) { |
|
2508 | 2508 | $query_info_carrier = new EE_Model_Query_Info_Carrier(); |
2509 | - if(array_key_exists(0,$query_params)){ |
|
2510 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0); |
|
2511 | - } |
|
2512 | - if(array_key_exists('group_by', $query_params)){ |
|
2513 | - if(is_array($query_params['group_by'])){ |
|
2514 | - $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by'); |
|
2515 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2516 | - $this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by'); |
|
2509 | + if (array_key_exists(0, $query_params)) { |
|
2510 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0); |
|
2511 | + } |
|
2512 | + if (array_key_exists('group_by', $query_params)) { |
|
2513 | + if (is_array($query_params['group_by'])) { |
|
2514 | + $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2515 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2516 | + $this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2517 | 2517 | } |
2518 | 2518 | } |
2519 | - if(array_key_exists('having',$query_params)){ |
|
2520 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having'); |
|
2519 | + if (array_key_exists('having', $query_params)) { |
|
2520 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having'); |
|
2521 | 2521 | } |
2522 | - if(array_key_exists('order_by', $query_params)){ |
|
2523 | - if ( is_array( $query_params['order_by'] ) ) |
|
2524 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2525 | - elseif( ! empty( $query_params['order_by'] )) |
|
2526 | - $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2522 | + if (array_key_exists('order_by', $query_params)) { |
|
2523 | + if (is_array($query_params['order_by'])) |
|
2524 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2525 | + elseif ( ! empty($query_params['order_by'])) |
|
2526 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2527 | 2527 | } |
2528 | - if(array_key_exists('force_join', $query_params)){ |
|
2529 | - $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join'); |
|
2528 | + if (array_key_exists('force_join', $query_params)) { |
|
2529 | + $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join'); |
|
2530 | 2530 | } |
2531 | 2531 | return $query_info_carrier; |
2532 | 2532 | } |
@@ -2539,34 +2539,34 @@ discard block |
||
2539 | 2539 | * @throws EE_Error |
2540 | 2540 | * @return \EE_Model_Query_Info_Carrier |
2541 | 2541 | */ |
2542 | - private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2543 | - if (!empty($sub_query_params)){ |
|
2542 | + private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2543 | + if ( ! empty($sub_query_params)) { |
|
2544 | 2544 | $sub_query_params = (array) $sub_query_params; |
2545 | - foreach($sub_query_params as $param => $possibly_array_of_params){ |
|
2545 | + foreach ($sub_query_params as $param => $possibly_array_of_params) { |
|
2546 | 2546 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2547 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type); |
|
2547 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2548 | 2548 | |
2549 | 2549 | //if $possibly_array_of_params is an array, try recursing into it, searching for keys which |
2550 | 2550 | //indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried |
2551 | 2551 | //extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value |
2552 | 2552 | //of array('Registration.TXN_ID'=>23) |
2553 | 2553 | $query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param); |
2554 | - if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){ |
|
2555 | - if (! is_array($possibly_array_of_params)){ |
|
2554 | + if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) { |
|
2555 | + if ( ! is_array($possibly_array_of_params)) { |
|
2556 | 2556 | throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"), |
2557 | - $param,$possibly_array_of_params)); |
|
2558 | - }else{ |
|
2559 | - $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
|
2557 | + $param, $possibly_array_of_params)); |
|
2558 | + } else { |
|
2559 | + $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type); |
|
2560 | 2560 | } |
2561 | - }elseif($query_param_type === 0 //ie WHERE |
|
2561 | + }elseif ($query_param_type === 0 //ie WHERE |
|
2562 | 2562 | && is_array($possibly_array_of_params) |
2563 | 2563 | && isset($possibly_array_of_params[2]) |
2564 | - && $possibly_array_of_params[2] == true){ |
|
2564 | + && $possibly_array_of_params[2] == true) { |
|
2565 | 2565 | //then $possible_array_of_params looks something like array('<','DTT_sold',true) |
2566 | 2566 | //indicating that $possible_array_of_params[1] is actually a field name, |
2567 | 2567 | //from which we should extract query parameters! |
2568 | - if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){ |
|
2569 | - throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"),$query_param_type,implode(",",$possibly_array_of_params))); |
|
2568 | + if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) { |
|
2569 | + throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"), $query_param_type, implode(",", $possibly_array_of_params))); |
|
2570 | 2570 | } |
2571 | 2571 | $this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type); |
2572 | 2572 | } |
@@ -2585,14 +2585,14 @@ discard block |
||
2585 | 2585 | * @throws EE_Error |
2586 | 2586 | * @return \EE_Model_Query_Info_Carrier |
2587 | 2587 | */ |
2588 | - private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2589 | - if (!empty($sub_query_params)){ |
|
2590 | - if(!is_array($sub_query_params)){ |
|
2591 | - throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params)); |
|
2588 | + private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2589 | + if ( ! empty($sub_query_params)) { |
|
2590 | + if ( ! is_array($sub_query_params)) { |
|
2591 | + throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params)); |
|
2592 | 2592 | } |
2593 | - foreach($sub_query_params as $param){ |
|
2593 | + foreach ($sub_query_params as $param) { |
|
2594 | 2594 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2595 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type); |
|
2595 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2596 | 2596 | } |
2597 | 2597 | } |
2598 | 2598 | return $model_query_info_carrier; |
@@ -2611,81 +2611,81 @@ discard block |
||
2611 | 2611 | * @throws EE_Error |
2612 | 2612 | * @return EE_Model_Query_Info_Carrier |
2613 | 2613 | */ |
2614 | - function _create_model_query_info_carrier($query_params){ |
|
2615 | - if( ! is_array( $query_params ) ){ |
|
2616 | - EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
2614 | + function _create_model_query_info_carrier($query_params) { |
|
2615 | + if ( ! is_array($query_params)) { |
|
2616 | + EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
2617 | 2617 | $query_params = array(); |
2618 | 2618 | } |
2619 | - if( isset( $query_params[0] ) ) { |
|
2619 | + if (isset($query_params[0])) { |
|
2620 | 2620 | $where_query_params = $query_params[0]; |
2621 | - }else{ |
|
2621 | + } else { |
|
2622 | 2622 | $where_query_params = array(); |
2623 | 2623 | } |
2624 | 2624 | //first check if we should alter the query to account for caps or not |
2625 | 2625 | //because the caps might require us to do extra joins |
2626 | - if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) { |
|
2627 | - $query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) ); |
|
2626 | + if (isset($query_params['caps']) && $query_params['caps'] != 'none') { |
|
2627 | + $query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps'])); |
|
2628 | 2628 | } |
2629 | 2629 | $query_object = $this->_extract_related_models_from_query($query_params); |
2630 | 2630 | |
2631 | 2631 | //verify where_query_params has NO numeric indexes.... that's simply not how you use it! |
2632 | - foreach($where_query_params as $key => $value){ |
|
2633 | - if(is_int($key)){ |
|
2634 | - throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"),$key, var_export( $value, true ), var_export( $query_params, true ), get_class($this))); |
|
2632 | + foreach ($where_query_params as $key => $value) { |
|
2633 | + if (is_int($key)) { |
|
2634 | + throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"), $key, var_export($value, true), var_export($query_params, true), get_class($this))); |
|
2635 | 2635 | } |
2636 | 2636 | } |
2637 | - if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){ |
|
2637 | + if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) { |
|
2638 | 2638 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2639 | - }else{ |
|
2639 | + } else { |
|
2640 | 2640 | $use_default_where_conditions = 'all'; |
2641 | 2641 | } |
2642 | - $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object,$use_default_where_conditions,$where_query_params), $where_query_params ); |
|
2643 | - $query_object->set_where_sql( $this->_construct_where_clause($where_query_params)); |
|
2642 | + $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object, $use_default_where_conditions, $where_query_params), $where_query_params); |
|
2643 | + $query_object->set_where_sql($this->_construct_where_clause($where_query_params)); |
|
2644 | 2644 | |
2645 | 2645 | |
2646 | 2646 | //if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join. So we need to setup a subquery and use that for the main join. Note for now this only works on the primary table for the model. So for instance, you could set the limit array like this: |
2647 | 2647 | //array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) ) |
2648 | - if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) { |
|
2649 | - $query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) ); |
|
2648 | + if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) { |
|
2649 | + $query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1])); |
|
2650 | 2650 | } |
2651 | 2651 | |
2652 | 2652 | |
2653 | 2653 | //set limit |
2654 | - if(array_key_exists('limit',$query_params)){ |
|
2655 | - if(is_array($query_params['limit'])){ |
|
2656 | - if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){ |
|
2657 | - $e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit'])); |
|
2654 | + if (array_key_exists('limit', $query_params)) { |
|
2655 | + if (is_array($query_params['limit'])) { |
|
2656 | + if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) { |
|
2657 | + $e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit'])); |
|
2658 | 2658 | throw new EE_Error($e."|".$e); |
2659 | 2659 | } |
2660 | 2660 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2661 | 2661 | $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
2662 | - }elseif( ! empty ( $query_params['limit'] )){ |
|
2662 | + }elseif ( ! empty ($query_params['limit'])) { |
|
2663 | 2663 | $query_object->set_limit_sql((" LIMIT ".$query_params['limit'])); |
2664 | 2664 | } |
2665 | 2665 | } |
2666 | 2666 | //set order by |
2667 | - if(array_key_exists('order_by',$query_params)){ |
|
2668 | - if(is_array($query_params['order_by'])){ |
|
2667 | + if (array_key_exists('order_by', $query_params)) { |
|
2668 | + if (is_array($query_params['order_by'])) { |
|
2669 | 2669 | //if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must |
2670 | 2670 | //specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So |
2671 | 2671 | //including 'order' wouldn't make any sense if 'order_by' has already specified which way to order! |
2672 | - if(array_key_exists('order', $query_params)){ |
|
2672 | + if (array_key_exists('order', $query_params)) { |
|
2673 | 2673 | throw new EE_Error(sprintf(__("In querying %s, we are using query parameter 'order_by' as an array (keys:%s,values:%s), and so we can't use query parameter 'order' (value %s). You should just use the 'order_by' parameter ", "event_espresso"), |
2674 | - get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order'])); |
|
2674 | + get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order'])); |
|
2675 | 2675 | } |
2676 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by'); |
|
2676 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by'); |
|
2677 | 2677 | //assume it's an array of fields to order by |
2678 | 2678 | $order_array = array(); |
2679 | - foreach($query_params['order_by'] as $field_name_to_order_by => $order){ |
|
2679 | + foreach ($query_params['order_by'] as $field_name_to_order_by => $order) { |
|
2680 | 2680 | $order = $this->_extract_order($order); |
2681 | 2681 | $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
2682 | 2682 | } |
2683 | - $query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array)); |
|
2684 | - }elseif( ! empty ( $query_params['order_by'] )){ |
|
2685 | - $this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']); |
|
2686 | - if(isset($query_params['order'])){ |
|
2683 | + $query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array)); |
|
2684 | + }elseif ( ! empty ($query_params['order_by'])) { |
|
2685 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']); |
|
2686 | + if (isset($query_params['order'])) { |
|
2687 | 2687 | $order = $this->_extract_order($query_params['order']); |
2688 | - }else{ |
|
2688 | + } else { |
|
2689 | 2689 | $order = 'DESC'; |
2690 | 2690 | } |
2691 | 2691 | $query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order); |
@@ -2693,46 +2693,46 @@ discard block |
||
2693 | 2693 | } |
2694 | 2694 | |
2695 | 2695 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2696 | - if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){ |
|
2696 | + if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) { |
|
2697 | 2697 | $pk_field = $this->get_primary_key_field(); |
2698 | 2698 | $order = $this->_extract_order($query_params['order']); |
2699 | 2699 | $query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order); |
2700 | 2700 | } |
2701 | 2701 | |
2702 | 2702 | //set group by |
2703 | - if(array_key_exists('group_by',$query_params)){ |
|
2704 | - if(is_array($query_params['group_by'])){ |
|
2703 | + if (array_key_exists('group_by', $query_params)) { |
|
2704 | + if (is_array($query_params['group_by'])) { |
|
2705 | 2705 | //it's an array, so assume we'll be grouping by a bunch of stuff |
2706 | 2706 | $group_by_array = array(); |
2707 | - foreach($query_params['group_by'] as $field_name_to_group_by){ |
|
2707 | + foreach ($query_params['group_by'] as $field_name_to_group_by) { |
|
2708 | 2708 | $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
2709 | 2709 | } |
2710 | - $query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array)); |
|
2711 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2710 | + $query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array)); |
|
2711 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2712 | 2712 | $query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])); |
2713 | 2713 | } |
2714 | 2714 | } |
2715 | 2715 | //set having |
2716 | - if(array_key_exists('having',$query_params) && $query_params['having']){ |
|
2717 | - $query_object->set_having_sql( $this->_construct_having_clause($query_params['having'])); |
|
2716 | + if (array_key_exists('having', $query_params) && $query_params['having']) { |
|
2717 | + $query_object->set_having_sql($this->_construct_having_clause($query_params['having'])); |
|
2718 | 2718 | } |
2719 | 2719 | |
2720 | 2720 | //now, just verify they didn't pass anything wack |
2721 | - foreach($query_params as $query_key => $query_value){ |
|
2722 | - if( ! in_array($query_key,$this->_allowed_query_params,true)){ |
|
2721 | + foreach ($query_params as $query_key => $query_value) { |
|
2722 | + if ( ! in_array($query_key, $this->_allowed_query_params, true)) { |
|
2723 | 2723 | throw new EE_Error( |
2724 | 2724 | sprintf( |
2725 | - __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'), |
|
2725 | + __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'), |
|
2726 | 2726 | $query_key, |
2727 | 2727 | get_class($this), |
2728 | 2728 | // print_r( $this->_allowed_query_params, TRUE ) |
2729 | - implode( ',', $this->_allowed_query_params ) |
|
2729 | + implode(',', $this->_allowed_query_params) |
|
2730 | 2730 | ) |
2731 | 2731 | ); |
2732 | 2732 | } |
2733 | 2733 | } |
2734 | 2734 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2735 | - if ( empty( $main_model_join_sql ) ) |
|
2735 | + if (empty($main_model_join_sql)) |
|
2736 | 2736 | $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
2737 | 2737 | return $query_object; |
2738 | 2738 | } |
@@ -2743,17 +2743,17 @@ discard block |
||
2743 | 2743 | * @param string $context one of EEM_Base::valid_cap_contexts() |
2744 | 2744 | * @return array like EEM_Base::get_all() 's $query_params[0] |
2745 | 2745 | */ |
2746 | - public function caps_where_conditions( $context = self::caps_read ) { |
|
2747 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
2746 | + public function caps_where_conditions($context = self::caps_read) { |
|
2747 | + EEM_Base::verify_is_valid_cap_context($context); |
|
2748 | 2748 | $cap_where_conditions = array(); |
2749 | - $cap_restrictions = $this->caps_missing( $context ); |
|
2749 | + $cap_restrictions = $this->caps_missing($context); |
|
2750 | 2750 | /** |
2751 | 2751 | * @var $cap_restrictions EE_Default_Where_Conditions[] |
2752 | 2752 | */ |
2753 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
2754 | - $cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() ); |
|
2753 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
2754 | + $cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions()); |
|
2755 | 2755 | } |
2756 | - return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions ); |
|
2756 | + return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions); |
|
2757 | 2757 | } |
2758 | 2758 | |
2759 | 2759 | /** |
@@ -2763,11 +2763,11 @@ discard block |
||
2763 | 2763 | * @return string either ASC, asc, DESC or desc |
2764 | 2764 | * @throws EE_Error |
2765 | 2765 | */ |
2766 | - private function _extract_order($should_be_order_string){ |
|
2767 | - if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
|
2766 | + private function _extract_order($should_be_order_string) { |
|
2767 | + if (in_array($should_be_order_string, $this->_allowed_order_values)) { |
|
2768 | 2768 | return $should_be_order_string; |
2769 | - }else{ |
|
2770 | - throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string)); |
|
2769 | + } else { |
|
2770 | + throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"), get_class($this), $should_be_order_string)); |
|
2771 | 2771 | } |
2772 | 2772 | } |
2773 | 2773 | |
@@ -2785,7 +2785,7 @@ discard block |
||
2785 | 2785 | * @throws EE_Error |
2786 | 2786 | * @return array like $query_params[0], see EEM_Base::get_all for documentation |
2787 | 2787 | */ |
2788 | - private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier,$use_default_where_conditions = 'all',$where_query_params = array()){ |
|
2788 | + private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier, $use_default_where_conditions = 'all', $where_query_params = array()) { |
|
2789 | 2789 | $allowed_used_default_where_conditions_values = array( |
2790 | 2790 | 'all', |
2791 | 2791 | 'this_model_only', |
@@ -2793,19 +2793,19 @@ discard block |
||
2793 | 2793 | 'minimum', |
2794 | 2794 | 'none' |
2795 | 2795 | ); |
2796 | - if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){ |
|
2797 | - throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"),$use_default_where_conditions,implode(", ",$allowed_used_default_where_conditions_values))); |
|
2796 | + if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) { |
|
2797 | + throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"), $use_default_where_conditions, implode(", ", $allowed_used_default_where_conditions_values))); |
|
2798 | 2798 | } |
2799 | - if( in_array($use_default_where_conditions, array('all','this_model_only')) ){ |
|
2799 | + if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) { |
|
2800 | 2800 | $universal_query_params = $this->_get_default_where_conditions(); |
2801 | - }elseif( in_array( $use_default_where_conditions, array( 'minimum' ) ) ) { |
|
2801 | + }elseif (in_array($use_default_where_conditions, array('minimum'))) { |
|
2802 | 2802 | $universal_query_params = $this->_get_minimum_where_conditions(); |
2803 | - }else{ |
|
2803 | + } else { |
|
2804 | 2804 | $universal_query_params = array(); |
2805 | 2805 | } |
2806 | 2806 | |
2807 | - if(in_array($use_default_where_conditions,array('all','other_models_only'))){ |
|
2808 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
2807 | + if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) { |
|
2808 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
2809 | 2809 | $related_model = $this->get_related_model_obj($model_name); |
2810 | 2810 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
2811 | 2811 | |
@@ -2832,22 +2832,22 @@ discard block |
||
2832 | 2832 | * @param string $model_relation_path like 'Transaction.Payment.' |
2833 | 2833 | * @return array like EEM_Base::get_all's $query_params[0] |
2834 | 2834 | */ |
2835 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
2835 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
2836 | 2836 | $null_friendly_where_conditions = array(); |
2837 | 2837 | $none_overridden = true; |
2838 | 2838 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
2839 | 2839 | |
2840 | - foreach($default_where_conditions as $key => $val){ |
|
2841 | - if( isset($provided_where_conditions[$key])){ |
|
2840 | + foreach ($default_where_conditions as $key => $val) { |
|
2841 | + if (isset($provided_where_conditions[$key])) { |
|
2842 | 2842 | $none_overridden = false; |
2843 | - }else{ |
|
2843 | + } else { |
|
2844 | 2844 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
2845 | 2845 | } |
2846 | 2846 | } |
2847 | - if( $none_overridden && $default_where_conditions){ |
|
2848 | - if($model->has_primary_key_field()){ |
|
2847 | + if ($none_overridden && $default_where_conditions) { |
|
2848 | + if ($model->has_primary_key_field()) { |
|
2849 | 2849 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
2850 | - }else{ |
|
2850 | + } else { |
|
2851 | 2851 | //@todo NO PK, use other defaults |
2852 | 2852 | } |
2853 | 2853 | } |
@@ -2862,8 +2862,8 @@ discard block |
||
2862 | 2862 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
2863 | 2863 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2864 | 2864 | */ |
2865 | - private function _get_default_where_conditions($model_relation_path = null){ |
|
2866 | - if ( $this->_ignore_where_strategy ) |
|
2865 | + private function _get_default_where_conditions($model_relation_path = null) { |
|
2866 | + if ($this->_ignore_where_strategy) |
|
2867 | 2867 | return array(); |
2868 | 2868 | |
2869 | 2869 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -2877,8 +2877,8 @@ discard block |
||
2877 | 2877 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
2878 | 2878 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2879 | 2879 | */ |
2880 | - protected function _get_minimum_where_conditions($model_relation_path = null){ |
|
2881 | - if ( $this->_ignore_where_strategy ) |
|
2880 | + protected function _get_minimum_where_conditions($model_relation_path = null) { |
|
2881 | + if ($this->_ignore_where_strategy) |
|
2882 | 2882 | return array(); |
2883 | 2883 | |
2884 | 2884 | return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -2889,13 +2889,13 @@ discard block |
||
2889 | 2889 | * @param EE_Model_Query_Info_Carrier $model_query_info |
2890 | 2890 | * @return string |
2891 | 2891 | */ |
2892 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
2892 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
2893 | 2893 | $selects = $this->_get_columns_to_select_for_this_model(); |
2894 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
2894 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
2895 | 2895 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
2896 | 2896 | $selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain)); |
2897 | 2897 | } |
2898 | - return implode(", ",$selects); |
|
2898 | + return implode(", ", $selects); |
|
2899 | 2899 | } |
2900 | 2900 | |
2901 | 2901 | /** |
@@ -2904,19 +2904,19 @@ discard block |
||
2904 | 2904 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
2905 | 2905 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
2906 | 2906 | */ |
2907 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
2907 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
2908 | 2908 | $fields = $this->field_settings(); |
2909 | 2909 | $selects = array(); |
2910 | 2910 | $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model_name()); |
2911 | - foreach($fields as $field_obj){ |
|
2912 | - $selects[] = $table_alias_with_model_relation_chain_prefix . $field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
2911 | + foreach ($fields as $field_obj) { |
|
2912 | + $selects[] = $table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
2913 | 2913 | } |
2914 | 2914 | //make sure we are also getting the PKs of each table |
2915 | 2915 | $tables = $this->get_tables(); |
2916 | - if(count($tables) > 1){ |
|
2917 | - foreach($tables as $table_obj){ |
|
2918 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
2919 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
2916 | + if (count($tables) > 1) { |
|
2917 | + foreach ($tables as $table_obj) { |
|
2918 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
2919 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
2920 | 2920 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
2921 | 2921 | } |
2922 | 2922 | } |
@@ -2940,66 +2940,66 @@ discard block |
||
2940 | 2940 | * @throws EE_Error |
2941 | 2941 | * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it |
2942 | 2942 | */ |
2943 | - private function _extract_related_model_info_from_query_param( $query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL ){ |
|
2944 | - if($original_query_param == NULL){ |
|
2943 | + private function _extract_related_model_info_from_query_param($query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL) { |
|
2944 | + if ($original_query_param == NULL) { |
|
2945 | 2945 | $original_query_param = $query_param; |
2946 | 2946 | } |
2947 | 2947 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
2948 | 2948 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
2949 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
2950 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
2949 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
2950 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
2951 | 2951 | //check to see if we have a field on this model |
2952 | 2952 | $this_model_fields = $this->field_settings(true); |
2953 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
2954 | - if($allow_fields){ |
|
2953 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
2954 | + if ($allow_fields) { |
|
2955 | 2955 | return; |
2956 | - }else{ |
|
2956 | + } else { |
|
2957 | 2957 | throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"), |
2958 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
2958 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
2959 | 2959 | } |
2960 | 2960 | } |
2961 | 2961 | //check if this is a special logic query param |
2962 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
2963 | - if($allow_logic_query_params){ |
|
2962 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
2963 | + if ($allow_logic_query_params) { |
|
2964 | 2964 | return; |
2965 | - }else{ |
|
2965 | + } else { |
|
2966 | 2966 | throw new EE_Error( |
2967 | 2967 | sprintf( |
2968 | - __( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ), |
|
2969 | - implode( '", "', $this->_logic_query_param_keys ), |
|
2970 | - $query_param , |
|
2971 | - get_class( $this ), |
|
2968 | + __('Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso'), |
|
2969 | + implode('", "', $this->_logic_query_param_keys), |
|
2970 | + $query_param, |
|
2971 | + get_class($this), |
|
2972 | 2972 | '<br />', |
2973 | - "\t" . ' $passed_in_query_info = <pre>' . print_r( $passed_in_query_info, TRUE ) . '</pre>' . "\n\t" . ' $query_param_type = ' . $query_param_type . "\n\t" . ' $original_query_param = ' . $original_query_param |
|
2973 | + "\t".' $passed_in_query_info = <pre>'.print_r($passed_in_query_info, TRUE).'</pre>'."\n\t".' $query_param_type = '.$query_param_type."\n\t".' $original_query_param = '.$original_query_param |
|
2974 | 2974 | ) |
2975 | 2975 | ); |
2976 | 2976 | } |
2977 | 2977 | } |
2978 | 2978 | |
2979 | 2979 | //check if it's a custom selection |
2980 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
2980 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
2981 | 2981 | return; |
2982 | 2982 | } |
2983 | 2983 | |
2984 | 2984 | //check if has a model name at the beginning |
2985 | 2985 | //and |
2986 | 2986 | //check if it's a field on a related model |
2987 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
2988 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
2989 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
2987 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
2988 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
2989 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
2990 | 2990 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
2991 | - if($query_param == ''){ |
|
2991 | + if ($query_param == '') { |
|
2992 | 2992 | //nothing left to $query_param |
2993 | 2993 | //we should actually end in a field name, not a model like this! |
2994 | 2994 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
2995 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
2996 | - }else{ |
|
2995 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
2996 | + } else { |
|
2997 | 2997 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
2998 | 2998 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
2999 | 2999 | return; |
3000 | 3000 | } |
3001 | - }elseif($query_param == $valid_related_model_name){ |
|
3002 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3001 | + }elseif ($query_param == $valid_related_model_name) { |
|
3002 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3003 | 3003 | return; |
3004 | 3004 | } |
3005 | 3005 | } |
@@ -3009,7 +3009,7 @@ discard block |
||
3009 | 3009 | //and we previously confirmed it wasn't a logic query param or field on the current model |
3010 | 3010 | //it's wack, that's what it is |
3011 | 3011 | throw new EE_Error(sprintf(__("There is no model named '%s' related to %s. Query param type is %s and original query param is %s", "event_espresso"), |
3012 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3012 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3013 | 3013 | |
3014 | 3014 | } |
3015 | 3015 | |
@@ -3026,26 +3026,26 @@ discard block |
||
3026 | 3026 | * what models to prepend onto its default query params or in case it wants to rename tables (in case there are multiple joins to the same table) |
3027 | 3027 | * @return void |
3028 | 3028 | */ |
3029 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
3029 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
3030 | 3030 | $relation_obj = $this->related_settings_for($model_name); |
3031 | 3031 | |
3032 | 3032 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
3033 | 3033 | //check if the relation is HABTM, because then we're essentially doing two joins |
3034 | 3034 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
3035 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
3035 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
3036 | 3036 | $join_model_obj = $relation_obj->get_join_model(); |
3037 | 3037 | //replace the model specified with the join model for this relation chain, whi |
3038 | 3038 | $relation_chain_to_join_model = EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_obj->get_this_model_name(), $model_relation_chain); |
3039 | 3039 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3040 | 3040 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
3041 | 3041 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
3042 | - $passed_in_query_info->merge( $new_query_info ); |
|
3042 | + $passed_in_query_info->merge($new_query_info); |
|
3043 | 3043 | } |
3044 | 3044 | //now just join to the other table pointed to by the relation object, and add its data types |
3045 | 3045 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3046 | 3046 | array($model_relation_chain=>$model_name), |
3047 | 3047 | $relation_obj->get_join_statement($model_relation_chain)); |
3048 | - $passed_in_query_info->merge( $new_query_info ); |
|
3048 | + $passed_in_query_info->merge($new_query_info); |
|
3049 | 3049 | } |
3050 | 3050 | |
3051 | 3051 | |
@@ -3054,11 +3054,11 @@ discard block |
||
3054 | 3054 | * @param array $where_params like EEM_Base::get_all |
3055 | 3055 | * @return string of SQL |
3056 | 3056 | */ |
3057 | - private function _construct_where_clause($where_params){ |
|
3057 | + private function _construct_where_clause($where_params) { |
|
3058 | 3058 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3059 | - if($SQL){ |
|
3060 | - return " WHERE ". $SQL; |
|
3061 | - }else{ |
|
3059 | + if ($SQL) { |
|
3060 | + return " WHERE ".$SQL; |
|
3061 | + } else { |
|
3062 | 3062 | return ''; |
3063 | 3063 | } |
3064 | 3064 | } |
@@ -3069,11 +3069,11 @@ discard block |
||
3069 | 3069 | * @param array $having_params |
3070 | 3070 | * @return string |
3071 | 3071 | */ |
3072 | - private function _construct_having_clause($having_params){ |
|
3072 | + private function _construct_having_clause($having_params) { |
|
3073 | 3073 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3074 | - if($SQL){ |
|
3075 | - return " HAVING ". $SQL; |
|
3076 | - }else{ |
|
3074 | + if ($SQL) { |
|
3075 | + return " HAVING ".$SQL; |
|
3076 | + } else { |
|
3077 | 3077 | return ''; |
3078 | 3078 | } |
3079 | 3079 | |
@@ -3087,17 +3087,17 @@ discard block |
||
3087 | 3087 | * @return EE_Model_Field_Base |
3088 | 3088 | * @throws EE_Error |
3089 | 3089 | */ |
3090 | - protected function _get_field_on_model($field_name,$model_name){ |
|
3090 | + protected function _get_field_on_model($field_name, $model_name) { |
|
3091 | 3091 | $model_class = 'EEM_'.$model_name; |
3092 | 3092 | $model_filepath = $model_class.".model.php"; |
3093 | - EE_Registry::instance()->load_helper( 'File' ); |
|
3094 | - if ( is_readable($model_filepath)){ |
|
3093 | + EE_Registry::instance()->load_helper('File'); |
|
3094 | + if (is_readable($model_filepath)) { |
|
3095 | 3095 | require_once($model_filepath); |
3096 | - $model_instance=call_user_func($model_name."::instance"); |
|
3096 | + $model_instance = call_user_func($model_name."::instance"); |
|
3097 | 3097 | /* @var $model_instance EEM_Base */ |
3098 | 3098 | return $model_instance->field_settings_for($field_name); |
3099 | - }else{ |
|
3100 | - throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
|
3099 | + } else { |
|
3100 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
3101 | 3101 | } |
3102 | 3102 | } |
3103 | 3103 | |
@@ -3110,43 +3110,43 @@ discard block |
||
3110 | 3110 | * @throws EE_Error |
3111 | 3111 | * @return string of SQL |
3112 | 3112 | */ |
3113 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
3114 | - $where_clauses=array(); |
|
3115 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
3116 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
3117 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
3118 | - switch($query_param){ |
|
3113 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
3114 | + $where_clauses = array(); |
|
3115 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
3116 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
3117 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
3118 | + switch ($query_param) { |
|
3119 | 3119 | case 'not': |
3120 | 3120 | case 'NOT': |
3121 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3121 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3122 | 3122 | break; |
3123 | 3123 | case 'and': |
3124 | 3124 | case 'AND': |
3125 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
3125 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
3126 | 3126 | break; |
3127 | 3127 | case 'or': |
3128 | 3128 | case 'OR': |
3129 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
3129 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
3130 | 3130 | break; |
3131 | 3131 | } |
3132 | - }else{ |
|
3132 | + } else { |
|
3133 | 3133 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3134 | 3134 | |
3135 | 3135 | //if it's not a normal field, maybe it's a custom selection? |
3136 | - if( ! $field_obj){ |
|
3137 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
3136 | + if ( ! $field_obj) { |
|
3137 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
3138 | 3138 | $field_obj = $this->_custom_selections[$query_param][1]; |
3139 | - }else{ |
|
3140 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
3139 | + } else { |
|
3140 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
3141 | 3141 | } |
3142 | 3142 | } |
3143 | 3143 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
3144 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3144 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3145 | 3145 | } |
3146 | 3146 | } |
3147 | - if($where_clauses){ |
|
3148 | - $SQL = implode($glue,$where_clauses); |
|
3149 | - }else{ |
|
3147 | + if ($where_clauses) { |
|
3148 | + $SQL = implode($glue, $where_clauses); |
|
3149 | + } else { |
|
3150 | 3150 | $SQL = ''; |
3151 | 3151 | } |
3152 | 3152 | return $SQL; |
@@ -3160,18 +3160,18 @@ discard block |
||
3160 | 3160 | * @throws EE_Error |
3161 | 3161 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
3162 | 3162 | */ |
3163 | - private function _deduce_column_name_from_query_param($query_param){ |
|
3163 | + private function _deduce_column_name_from_query_param($query_param) { |
|
3164 | 3164 | $field = $this->_deduce_field_from_query_param($query_param); |
3165 | 3165 | |
3166 | - if( $field ){ |
|
3167 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
3168 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
3169 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3166 | + if ($field) { |
|
3167 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
3168 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
3169 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3170 | 3170 | //maybe it's custom selection item? |
3171 | 3171 | //if so, just use it as the "column name" |
3172 | 3172 | return $query_param; |
3173 | - }else{ |
|
3174 | - throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections))); |
|
3173 | + } else { |
|
3174 | + throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"), $query_param, implode(",", $this->_custom_selections))); |
|
3175 | 3175 | } |
3176 | 3176 | } |
3177 | 3177 | |
@@ -3183,11 +3183,11 @@ discard block |
||
3183 | 3183 | * @param string $condition_query_param_key |
3184 | 3184 | * @return string |
3185 | 3185 | */ |
3186 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
3186 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
3187 | 3187 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3188 | - if($pos_of_star === FALSE){ |
|
3188 | + if ($pos_of_star === FALSE) { |
|
3189 | 3189 | return $condition_query_param_key; |
3190 | - }else{ |
|
3190 | + } else { |
|
3191 | 3191 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3192 | 3192 | return $condition_query_param_sans_star; |
3193 | 3193 | } |
@@ -3202,54 +3202,54 @@ discard block |
||
3202 | 3202 | * @throws EE_Error |
3203 | 3203 | * @return string |
3204 | 3204 | */ |
3205 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
3206 | - if(is_array( $op_and_value )){ |
|
3205 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
3206 | + if (is_array($op_and_value)) { |
|
3207 | 3207 | $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
3208 | - if( ! $operator){ |
|
3208 | + if ( ! $operator) { |
|
3209 | 3209 | $php_array_like_string = array(); |
3210 | - foreach($op_and_value as $key => $value){ |
|
3210 | + foreach ($op_and_value as $key => $value) { |
|
3211 | 3211 | $php_array_like_string[] = "$key=>$value"; |
3212 | 3212 | } |
3213 | - throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",",$php_array_like_string))); |
|
3213 | + throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",", $php_array_like_string))); |
|
3214 | 3214 | } |
3215 | 3215 | $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
3216 | - }else{ |
|
3216 | + } else { |
|
3217 | 3217 | $operator = '='; |
3218 | 3218 | $value = $op_and_value; |
3219 | 3219 | } |
3220 | 3220 | |
3221 | 3221 | //check to see if the value is actually another field |
3222 | - if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){ |
|
3222 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
3223 | 3223 | return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
3224 | - }elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3224 | + }elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3225 | 3225 | //in this case, the value should be an array, or at least a comma-separated list |
3226 | 3226 | //it will need to handle a little differently |
3227 | 3227 | $cleaned_value = $this->_construct_in_value($value, $field_obj); |
3228 | 3228 | //note: $cleaned_value has already been run through $wpdb->prepare() |
3229 | 3229 | return $operator.SP.$cleaned_value; |
3230 | - } elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
3230 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
3231 | 3231 | //the value should be an array with count of two. |
3232 | - if ( count($value) !== 2 ) |
|
3233 | - throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) ); |
|
3234 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
3232 | + if (count($value) !== 2) |
|
3233 | + throw new EE_Error(sprintf(__("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN")); |
|
3234 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
3235 | 3235 | return $operator.SP.$cleaned_value; |
3236 | - } elseif( in_array( $operator, $this->_null_style_operators ) ) { |
|
3237 | - if($value != NULL){ |
|
3238 | - throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"),$value,$operator)); |
|
3236 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
3237 | + if ($value != NULL) { |
|
3238 | + throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"), $value, $operator)); |
|
3239 | 3239 | } |
3240 | 3240 | return $operator; |
3241 | - }elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3241 | + }elseif ($operator == 'LIKE' && ! is_array($value)) { |
|
3242 | 3242 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3243 | 3243 | //remove other junk. So just treat it as a string. |
3244 | 3244 | return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
3245 | - }elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3246 | - return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj); |
|
3247 | - }elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3248 | - throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))",'event_espresso'),$operator, $operator)); |
|
3249 | - }elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3250 | - throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))",'event_espresso'),$operator,$operator)); |
|
3251 | - }else{ |
|
3252 | - throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
|
3245 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3246 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3247 | + }elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3248 | + throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))", 'event_espresso'), $operator, $operator)); |
|
3249 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3250 | + throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))", 'event_espresso'), $operator, $operator)); |
|
3251 | + } else { |
|
3252 | + throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
|
3253 | 3253 | } |
3254 | 3254 | } |
3255 | 3255 | |
@@ -3261,12 +3261,12 @@ discard block |
||
3261 | 3261 | * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s' |
3262 | 3262 | * @return string |
3263 | 3263 | */ |
3264 | - function _construct_between_value( $values, $field_obj ) { |
|
3264 | + function _construct_between_value($values, $field_obj) { |
|
3265 | 3265 | $cleaned_values = array(); |
3266 | - foreach ( $values as $value ) { |
|
3267 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3266 | + foreach ($values as $value) { |
|
3267 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3268 | 3268 | } |
3269 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3269 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3270 | 3270 | } |
3271 | 3271 | |
3272 | 3272 | |
@@ -3282,26 +3282,26 @@ discard block |
||
3282 | 3282 | * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d' |
3283 | 3283 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3284 | 3284 | */ |
3285 | - function _construct_in_value($values, $field_obj){ |
|
3285 | + function _construct_in_value($values, $field_obj) { |
|
3286 | 3286 | //check if the value is a CSV list |
3287 | - if(is_string($values)){ |
|
3287 | + if (is_string($values)) { |
|
3288 | 3288 | //in which case, turn it into an array |
3289 | - $values = explode(",",$values); |
|
3289 | + $values = explode(",", $values); |
|
3290 | 3290 | } |
3291 | 3291 | $cleaned_values = array(); |
3292 | - foreach($values as $value){ |
|
3293 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3292 | + foreach ($values as $value) { |
|
3293 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3294 | 3294 | } |
3295 | 3295 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3296 | 3296 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3297 | 3297 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3298 | - if(empty($cleaned_values)){ |
|
3298 | + if (empty($cleaned_values)) { |
|
3299 | 3299 | $all_fields = $this->field_settings(); |
3300 | 3300 | $a_field = array_shift($all_fields); |
3301 | 3301 | $main_table = $this->_get_main_table(); |
3302 | 3302 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3303 | 3303 | } |
3304 | - return "(".implode(",",$cleaned_values).")"; |
|
3304 | + return "(".implode(",", $cleaned_values).")"; |
|
3305 | 3305 | } |
3306 | 3306 | |
3307 | 3307 | |
@@ -3313,16 +3313,16 @@ discard block |
||
3313 | 3313 | * @throws EE_Error |
3314 | 3314 | * @return false|null|string |
3315 | 3315 | */ |
3316 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3316 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3317 | 3317 | /** @type WPDB $wpdb */ |
3318 | 3318 | global $wpdb; |
3319 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3320 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3321 | - }else{//$field_obj should really just be a data type |
|
3322 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3323 | - throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types))); |
|
3319 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3320 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3321 | + } else {//$field_obj should really just be a data type |
|
3322 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3323 | + throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"), $field_obj, implode(",", $this->_valid_wpdb_data_types))); |
|
3324 | 3324 | } |
3325 | - return $wpdb->prepare($field_obj,$value); |
|
3325 | + return $wpdb->prepare($field_obj, $value); |
|
3326 | 3326 | } |
3327 | 3327 | } |
3328 | 3328 | |
@@ -3334,27 +3334,27 @@ discard block |
||
3334 | 3334 | * @throws EE_Error |
3335 | 3335 | * @return EE_Model_Field_Base |
3336 | 3336 | */ |
3337 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3337 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3338 | 3338 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3339 | 3339 | //which will help us find the database table and column |
3340 | 3340 | |
3341 | - $query_param_parts = explode(".",$query_param_name); |
|
3342 | - if(empty($query_param_parts)){ |
|
3343 | - throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
3341 | + $query_param_parts = explode(".", $query_param_name); |
|
3342 | + if (empty($query_param_parts)) { |
|
3343 | + throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
3344 | 3344 | } |
3345 | 3345 | $number_of_parts = count($query_param_parts); |
3346 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3347 | - if($number_of_parts == 1){ |
|
3346 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3347 | + if ($number_of_parts == 1) { |
|
3348 | 3348 | $field_name = $last_query_param_part; |
3349 | 3349 | $model_obj = $this; |
3350 | - }else{// $number_of_parts >= 2 |
|
3350 | + } else {// $number_of_parts >= 2 |
|
3351 | 3351 | //the last part is the column name, and there are only 2parts. therefore... |
3352 | 3352 | $field_name = $last_query_param_part; |
3353 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3353 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3354 | 3354 | } |
3355 | - try{ |
|
3355 | + try { |
|
3356 | 3356 | return $model_obj->field_settings_for($field_name); |
3357 | - }catch(EE_Error $e){ |
|
3357 | + } catch (EE_Error $e) { |
|
3358 | 3358 | return null; |
3359 | 3359 | } |
3360 | 3360 | } |
@@ -3368,13 +3368,13 @@ discard block |
||
3368 | 3368 | * @throws EE_Error |
3369 | 3369 | * @return string |
3370 | 3370 | */ |
3371 | - function _get_qualified_column_for_field($field_name){ |
|
3371 | + function _get_qualified_column_for_field($field_name) { |
|
3372 | 3372 | $all_fields = $this->field_settings(); |
3373 | 3373 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3374 | - if($field){ |
|
3374 | + if ($field) { |
|
3375 | 3375 | return $field->get_qualified_column(); |
3376 | - }else{ |
|
3377 | - throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this))); |
|
3376 | + } else { |
|
3377 | + throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.", 'event_espresso'), $field_name, get_class($this))); |
|
3378 | 3378 | } |
3379 | 3379 | } |
3380 | 3380 | |
@@ -3388,14 +3388,14 @@ discard block |
||
3388 | 3388 | * @param mixed|string $limit The limit for this select |
3389 | 3389 | * @return string The final select join element for the query. |
3390 | 3390 | */ |
3391 | - function _construct_limit_join_select( $table_alias, $limit ) { |
|
3391 | + function _construct_limit_join_select($table_alias, $limit) { |
|
3392 | 3392 | $SQL = ''; |
3393 | 3393 | |
3394 | - foreach ( $this->_tables as $table_obj ) { |
|
3395 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3396 | - $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit( $limit ) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3397 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3398 | - $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP . $table_obj->get_join_sql( $table_alias ).SP; |
|
3394 | + foreach ($this->_tables as $table_obj) { |
|
3395 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3396 | + $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit($limit) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3397 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3398 | + $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP.$table_obj->get_join_sql($table_alias).SP; |
|
3399 | 3399 | } |
3400 | 3400 | } |
3401 | 3401 | return $SQL; |
@@ -3408,7 +3408,7 @@ discard block |
||
3408 | 3408 | * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id" |
3409 | 3409 | * @return string SQL |
3410 | 3410 | */ |
3411 | - function _construct_internal_join(){ |
|
3411 | + function _construct_internal_join() { |
|
3412 | 3412 | $SQL = $this->_get_main_table()->get_table_sql(); |
3413 | 3413 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3414 | 3414 | return $SQL; |
@@ -3429,17 +3429,17 @@ discard block |
||
3429 | 3429 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3430 | 3430 | * @return string |
3431 | 3431 | */ |
3432 | - function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3432 | + function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3433 | 3433 | $SQL = ''; |
3434 | 3434 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3435 | - foreach($this->_tables as $table_obj){ |
|
3436 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3437 | - if($alias_sans_prefix == $table_obj->get_table_alias()){ |
|
3435 | + foreach ($this->_tables as $table_obj) { |
|
3436 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3437 | + if ($alias_sans_prefix == $table_obj->get_table_alias()) { |
|
3438 | 3438 | //so we're joining to this table, meaning the table is already in |
3439 | 3439 | //the FROM statement, BUT the primary table isn't. So we want |
3440 | 3440 | //to add the inverse join sql |
3441 | 3441 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3442 | - }else{ |
|
3442 | + } else { |
|
3443 | 3443 | //just add a regular JOIN to this table from the primary table |
3444 | 3444 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3445 | 3445 | } |
@@ -3453,9 +3453,9 @@ discard block |
||
3453 | 3453 | * This should be a growing array of keys being table-columns (eg 'EVT_ID' and 'Event.EVT_ID'), and values being their data type (eg, '%s', '%d', etc) |
3454 | 3454 | * @return array |
3455 | 3455 | */ |
3456 | - function _get_data_types(){ |
|
3456 | + function _get_data_types() { |
|
3457 | 3457 | $data_types = array(); |
3458 | - foreach(array_values($this->field_settings()) as $field_obj){ |
|
3458 | + foreach (array_values($this->field_settings()) as $field_obj) { |
|
3459 | 3459 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3460 | 3460 | /** @var $field_obj EE_Model_Field_Base */ |
3461 | 3461 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3471,11 +3471,11 @@ discard block |
||
3471 | 3471 | * @throws EE_Error |
3472 | 3472 | * @return EEM_Base |
3473 | 3473 | */ |
3474 | - function get_related_model_obj($model_name){ |
|
3474 | + function get_related_model_obj($model_name) { |
|
3475 | 3475 | |
3476 | 3476 | $model_classname = "EEM_".$model_name; |
3477 | - if(!class_exists($model_classname)){ |
|
3478 | - throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s",'event_espresso'),$model_name,$model_classname)); |
|
3477 | + if ( ! class_exists($model_classname)) { |
|
3478 | + throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s", 'event_espresso'), $model_name, $model_classname)); |
|
3479 | 3479 | } |
3480 | 3480 | $model_obj = call_user_func($model_classname."::instance"); |
3481 | 3481 | return $model_obj; |
@@ -3486,7 +3486,7 @@ discard block |
||
3486 | 3486 | * Returns the array of EE_ModelRelations for this model. |
3487 | 3487 | * @return EE_Model_Relation_Base[] |
3488 | 3488 | */ |
3489 | - public function relation_settings(){ |
|
3489 | + public function relation_settings() { |
|
3490 | 3490 | return $this->_model_relations; |
3491 | 3491 | } |
3492 | 3492 | |
@@ -3496,10 +3496,10 @@ discard block |
||
3496 | 3496 | * (Eg, without an event, datetimes have little purpose.) |
3497 | 3497 | * @return EE_Belongs_To_Relation[] |
3498 | 3498 | */ |
3499 | - public function belongs_to_relations(){ |
|
3499 | + public function belongs_to_relations() { |
|
3500 | 3500 | $belongs_to_relations = array(); |
3501 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3502 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3501 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3502 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3503 | 3503 | $belongs_to_relations[$model_name] = $relation_obj; |
3504 | 3504 | } |
3505 | 3505 | } |
@@ -3514,15 +3514,15 @@ discard block |
||
3514 | 3514 | * @throws EE_Error |
3515 | 3515 | * @return EE_Model_Relation_Base |
3516 | 3516 | */ |
3517 | - public function related_settings_for($relation_name){ |
|
3518 | - $relatedModels=$this->relation_settings(); |
|
3519 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3517 | + public function related_settings_for($relation_name) { |
|
3518 | + $relatedModels = $this->relation_settings(); |
|
3519 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3520 | 3520 | throw new EE_Error( |
3521 | 3521 | sprintf( |
3522 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3522 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3523 | 3523 | $relation_name, |
3524 | 3524 | $this->_get_class_name(), |
3525 | - implode( ', ', array_keys( $relatedModels )) |
|
3525 | + implode(', ', array_keys($relatedModels)) |
|
3526 | 3526 | ) |
3527 | 3527 | ); |
3528 | 3528 | } |
@@ -3537,10 +3537,10 @@ discard block |
||
3537 | 3537 | * @throws EE_Error |
3538 | 3538 | * @return EE_Model_Field_Base |
3539 | 3539 | */ |
3540 | - public function field_settings_for($fieldName){ |
|
3541 | - $fieldSettings=$this->field_settings(true); |
|
3542 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3543 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3540 | + public function field_settings_for($fieldName) { |
|
3541 | + $fieldSettings = $this->field_settings(true); |
|
3542 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3543 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3544 | 3544 | } |
3545 | 3545 | return $fieldSettings[$fieldName]; |
3546 | 3546 | } |
@@ -3550,11 +3550,11 @@ discard block |
||
3550 | 3550 | * @param string $fieldName a key in the model's _field_settings array |
3551 | 3551 | * @return boolean |
3552 | 3552 | */ |
3553 | - public function has_field($fieldName){ |
|
3553 | + public function has_field($fieldName) { |
|
3554 | 3554 | $fieldSettings = $this->field_settings(true); |
3555 | - if( isset($fieldSettings[$fieldName])){ |
|
3555 | + if (isset($fieldSettings[$fieldName])) { |
|
3556 | 3556 | return true; |
3557 | - }else{ |
|
3557 | + } else { |
|
3558 | 3558 | return false; |
3559 | 3559 | } |
3560 | 3560 | } |
@@ -3564,11 +3564,11 @@ discard block |
||
3564 | 3564 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3565 | 3565 | * @return boolean |
3566 | 3566 | */ |
3567 | - public function has_relation($relation_name){ |
|
3567 | + public function has_relation($relation_name) { |
|
3568 | 3568 | $relations = $this->relation_settings(); |
3569 | - if(isset($relations[$relation_name])){ |
|
3569 | + if (isset($relations[$relation_name])) { |
|
3570 | 3570 | return true; |
3571 | - }else{ |
|
3571 | + } else { |
|
3572 | 3572 | return false; |
3573 | 3573 | } |
3574 | 3574 | } |
@@ -3580,7 +3580,7 @@ discard block |
||
3580 | 3580 | * @param $field_obj |
3581 | 3581 | * @return EE_Model_Field_Base |
3582 | 3582 | */ |
3583 | - public function is_primary_key_field( $field_obj ){ |
|
3583 | + public function is_primary_key_field($field_obj) { |
|
3584 | 3584 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3585 | 3585 | } |
3586 | 3586 | |
@@ -3592,16 +3592,16 @@ discard block |
||
3592 | 3592 | * @return EE_Model_Field_Base |
3593 | 3593 | * @throws EE_Error |
3594 | 3594 | */ |
3595 | - public function get_primary_key_field(){ |
|
3596 | - if( $this->_primary_key_field === NULL ){ |
|
3597 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3598 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3595 | + public function get_primary_key_field() { |
|
3596 | + if ($this->_primary_key_field === NULL) { |
|
3597 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3598 | + if ($this->is_primary_key_field($field_obj)) { |
|
3599 | 3599 | $this->_primary_key_field = $field_obj; |
3600 | 3600 | break; |
3601 | 3601 | } |
3602 | 3602 | } |
3603 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3604 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3603 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3604 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3605 | 3605 | } |
3606 | 3606 | } |
3607 | 3607 | return $this->_primary_key_field; |
@@ -3614,12 +3614,12 @@ discard block |
||
3614 | 3614 | * Internally does some caching. |
3615 | 3615 | * @return boolean |
3616 | 3616 | */ |
3617 | - public function has_primary_key_field(){ |
|
3618 | - if($this->_has_primary_key_field === null){ |
|
3619 | - try{ |
|
3617 | + public function has_primary_key_field() { |
|
3618 | + if ($this->_has_primary_key_field === null) { |
|
3619 | + try { |
|
3620 | 3620 | $this->get_primary_key_field(); |
3621 | 3621 | $this->_has_primary_key_field = true; |
3622 | - }catch(EE_Error $e){ |
|
3622 | + } catch (EE_Error $e) { |
|
3623 | 3623 | $this->_has_primary_key_field = false; |
3624 | 3624 | } |
3625 | 3625 | } |
@@ -3633,9 +3633,9 @@ discard block |
||
3633 | 3633 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3634 | 3634 | * @return EE_Model_Field_Base or null if none is found |
3635 | 3635 | */ |
3636 | - public function get_a_field_of_type($field_class_name){ |
|
3637 | - foreach($this->field_settings() as $field){ |
|
3638 | - if( $field instanceof $field_class_name ){ |
|
3636 | + public function get_a_field_of_type($field_class_name) { |
|
3637 | + foreach ($this->field_settings() as $field) { |
|
3638 | + if ($field instanceof $field_class_name) { |
|
3639 | 3639 | return $field; |
3640 | 3640 | } |
3641 | 3641 | } |
@@ -3649,21 +3649,21 @@ discard block |
||
3649 | 3649 | * @return EE_Foreign_Key_Field_Base |
3650 | 3650 | * @throws EE_Error |
3651 | 3651 | */ |
3652 | - public function get_foreign_key_to($model_name){ |
|
3653 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3654 | - foreach($this->field_settings() as $field){ |
|
3655 | - if( $field instanceof EE_Foreign_Key_Field_Base ){ |
|
3656 | - if (in_array($model_name,$field->get_model_names_pointed_to() ) ) { |
|
3657 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
3652 | + public function get_foreign_key_to($model_name) { |
|
3653 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3654 | + foreach ($this->field_settings() as $field) { |
|
3655 | + if ($field instanceof EE_Foreign_Key_Field_Base) { |
|
3656 | + if (in_array($model_name, $field->get_model_names_pointed_to())) { |
|
3657 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
3658 | 3658 | break; |
3659 | 3659 | } |
3660 | 3660 | } |
3661 | 3661 | } |
3662 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3663 | - throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s",'event_espresso'),$model_name,get_class($this))); |
|
3662 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3663 | + throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s", 'event_espresso'), $model_name, get_class($this))); |
|
3664 | 3664 | } |
3665 | 3665 | } |
3666 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
3666 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
3667 | 3667 | } |
3668 | 3668 | |
3669 | 3669 | |
@@ -3674,7 +3674,7 @@ discard block |
||
3674 | 3674 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3675 | 3675 | * @return EE_Table_Base |
3676 | 3676 | */ |
3677 | - function get_table_for_alias($table_alias){ |
|
3677 | + function get_table_for_alias($table_alias) { |
|
3678 | 3678 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
3679 | 3679 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
3680 | 3680 | } |
@@ -3687,25 +3687,25 @@ discard block |
||
3687 | 3687 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
3688 | 3688 | * @return EE_Model_Field_Base[] where the keys are the field's name |
3689 | 3689 | */ |
3690 | - public function field_settings($include_db_only_fields = false){ |
|
3691 | - if( $include_db_only_fields ){ |
|
3692 | - if( $this->_cached_fields === NULL ){ |
|
3690 | + public function field_settings($include_db_only_fields = false) { |
|
3691 | + if ($include_db_only_fields) { |
|
3692 | + if ($this->_cached_fields === NULL) { |
|
3693 | 3693 | $this->_cached_fields = array(); |
3694 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3695 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3696 | - $this->_cached_fields[$field_name]=$field_obj; |
|
3694 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3695 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3696 | + $this->_cached_fields[$field_name] = $field_obj; |
|
3697 | 3697 | } |
3698 | 3698 | } |
3699 | 3699 | } |
3700 | 3700 | return $this->_cached_fields; |
3701 | - }else{ |
|
3702 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
3701 | + } else { |
|
3702 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
3703 | 3703 | $this->_cached_fields_non_db_only = array(); |
3704 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3705 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3704 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3705 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3706 | 3706 | /** @var $field_obj EE_Model_Field_Base */ |
3707 | - if( ! $field_obj->is_db_only_field() ){ |
|
3708 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
3707 | + if ( ! $field_obj->is_db_only_field()) { |
|
3708 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
3709 | 3709 | } |
3710 | 3710 | } |
3711 | 3711 | } |
@@ -3724,67 +3724,67 @@ discard block |
||
3724 | 3724 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
3725 | 3725 | * @throws \EE_Error |
3726 | 3726 | */ |
3727 | - protected function _create_objects( $rows = array() ) { |
|
3728 | - $array_of_objects=array(); |
|
3729 | - if(empty($rows)){ |
|
3727 | + protected function _create_objects($rows = array()) { |
|
3728 | + $array_of_objects = array(); |
|
3729 | + if (empty($rows)) { |
|
3730 | 3730 | return array(); |
3731 | 3731 | } |
3732 | 3732 | $count_if_model_has_no_primary_key = 0; |
3733 | 3733 | $has_primary_key = $this->has_primary_key_field(); |
3734 | - if( $has_primary_key ) { |
|
3734 | + if ($has_primary_key) { |
|
3735 | 3735 | $primary_key_field = $this->get_primary_key_field(); |
3736 | 3736 | } else { |
3737 | 3737 | $primary_key_field = null; |
3738 | 3738 | } |
3739 | - foreach ( $rows as $row ) { |
|
3740 | - if(empty($row)){ |
|
3739 | + foreach ($rows as $row) { |
|
3740 | + if (empty($row)) { |
|
3741 | 3741 | //wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
3742 | 3742 | return array(); |
3743 | 3743 | } |
3744 | 3744 | //check if we've already set this object in the results array, |
3745 | 3745 | //in which case there's no need to process it further (again) |
3746 | - if( $has_primary_key ) { |
|
3746 | + if ($has_primary_key) { |
|
3747 | 3747 | $table_pk_value = $this->_get_column_value_with_table_alias_or_not( |
3748 | 3748 | $row, |
3749 | 3749 | $primary_key_field->get_qualified_column(), |
3750 | 3750 | $primary_key_field->get_table_column() |
3751 | 3751 | ); |
3752 | - if( $table_pk_value && |
|
3753 | - isset( $array_of_objects[ $table_pk_value ] ) ) { |
|
3752 | + if ($table_pk_value && |
|
3753 | + isset($array_of_objects[$table_pk_value])) { |
|
3754 | 3754 | continue; |
3755 | 3755 | } |
3756 | 3756 | } |
3757 | - $classInstance=$this->instantiate_class_from_array_or_object($row); |
|
3758 | - if( ! $classInstance ) { |
|
3757 | + $classInstance = $this->instantiate_class_from_array_or_object($row); |
|
3758 | + if ( ! $classInstance) { |
|
3759 | 3759 | throw new EE_Error( |
3760 | 3760 | sprintf( |
3761 | - __( 'Could not create instance of class %s from row %s', 'event_espresso' ), |
|
3761 | + __('Could not create instance of class %s from row %s', 'event_espresso'), |
|
3762 | 3762 | $this->get_this_model_name(), |
3763 | - http_build_query( $row ) |
|
3763 | + http_build_query($row) |
|
3764 | 3764 | ) |
3765 | 3765 | ); |
3766 | 3766 | } |
3767 | 3767 | //set the timezone on the instantiated objects |
3768 | - $classInstance->set_timezone( $this->_timezone ); |
|
3768 | + $classInstance->set_timezone($this->_timezone); |
|
3769 | 3769 | //make sure if there is any timezone setting present that we set the timezone for the object |
3770 | 3770 | $key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++; |
3771 | - $array_of_objects[ $key ] = $classInstance; |
|
3771 | + $array_of_objects[$key] = $classInstance; |
|
3772 | 3772 | //also, for all the relations of type BelongsTo, see if we can cache |
3773 | 3773 | //those related models |
3774 | 3774 | //(we could do this for other relations too, but if there are conditions |
3775 | 3775 | //that filtered out some fo the results, then we'd be caching an incomplete set |
3776 | 3776 | //so it requires a little more thought than just caching them immediately...) |
3777 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
3778 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
3777 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
3778 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3779 | 3779 | //check if this model's INFO is present. If so, cache it on the model |
3780 | 3780 | $other_model = $relation_obj->get_other_model(); |
3781 | 3781 | |
3782 | 3782 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
3783 | 3783 | |
3784 | 3784 | //if we managed to make a model object from the results, cache it on the main model object |
3785 | - if( $other_model_obj_maybe ){ |
|
3785 | + if ($other_model_obj_maybe) { |
|
3786 | 3786 | //set timezone on these other model objects if they are present |
3787 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
3787 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
3788 | 3788 | $classInstance->cache($modelName, $other_model_obj_maybe); |
3789 | 3789 | } |
3790 | 3790 | } |
@@ -3805,12 +3805,12 @@ discard block |
||
3805 | 3805 | |
3806 | 3806 | $this_model_fields_and_values = array(); |
3807 | 3807 | //setup the row using default values; |
3808 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
3808 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
3809 | 3809 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
3810 | 3810 | } |
3811 | 3811 | |
3812 | 3812 | $className = $this->_get_class_name(); |
3813 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
3813 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
3814 | 3814 | |
3815 | 3815 | return $classInstance; |
3816 | 3816 | } |
@@ -3823,45 +3823,45 @@ discard block |
||
3823 | 3823 | * or an stdClass where each property is the name of a column, |
3824 | 3824 | * @return EE_Base_Class |
3825 | 3825 | */ |
3826 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
3827 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
3828 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
3826 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
3827 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
3828 | + $cols_n_values = get_object_vars($cols_n_values); |
|
3829 | 3829 | } |
3830 | 3830 | $primary_key = NULL; |
3831 | 3831 | //make sure the array only has keys that are fields/columns on this model |
3832 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3833 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
3834 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
3832 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3833 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3834 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
3835 | 3835 | } |
3836 | - $className=$this->_get_class_name(); |
|
3836 | + $className = $this->_get_class_name(); |
|
3837 | 3837 | |
3838 | 3838 | //check we actually found results that we can use to build our model object |
3839 | 3839 | //if not, return null |
3840 | - if( $this->has_primary_key_field()){ |
|
3841 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
3840 | + if ($this->has_primary_key_field()) { |
|
3841 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3842 | 3842 | return NULL; |
3843 | 3843 | } |
3844 | - }else if($this->unique_indexes()){ |
|
3844 | + } else if ($this->unique_indexes()) { |
|
3845 | 3845 | $first_column = reset($this_model_fields_n_values); |
3846 | - if(empty($first_column)){ |
|
3846 | + if (empty($first_column)) { |
|
3847 | 3847 | return NULL; |
3848 | 3848 | } |
3849 | 3849 | } |
3850 | 3850 | |
3851 | 3851 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
3852 | - if ( $primary_key){ |
|
3853 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
3854 | - if( ! $classInstance) { |
|
3855 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3852 | + if ($primary_key) { |
|
3853 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
3854 | + if ( ! $classInstance) { |
|
3855 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3856 | 3856 | // add this new object to the entity map |
3857 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
3857 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
3858 | 3858 | } |
3859 | - }else{ |
|
3860 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3859 | + } else { |
|
3860 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3861 | 3861 | } |
3862 | 3862 | |
3863 | 3863 | //it is entirely possible that the instantiated class object has a set timezone_string db field and has set it's internal _timezone property accordingly (see new_instance_from_db in model objects particularly EE_Event for example). In this case, we want to make sure the model object doesn't have its timezone string overwritten by any timezone property currently set here on the model so, we intentionally override the model _timezone property with the model_object timezone property. |
3864 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
3864 | + $this->set_timezone($classInstance->get_timezone()); |
|
3865 | 3865 | return $classInstance; |
3866 | 3866 | } |
3867 | 3867 | /** |
@@ -3869,8 +3869,8 @@ discard block |
||
3869 | 3869 | * @param int|string $id the ID of the model object |
3870 | 3870 | * @return EE_Base_Class |
3871 | 3871 | */ |
3872 | - public function get_from_entity_map( $id ){ |
|
3873 | - return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL; |
|
3872 | + public function get_from_entity_map($id) { |
|
3873 | + return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL; |
|
3874 | 3874 | } |
3875 | 3875 | |
3876 | 3876 | |
@@ -3889,21 +3889,21 @@ discard block |
||
3889 | 3889 | * @throws EE_Error |
3890 | 3890 | * @return \EE_Base_Class |
3891 | 3891 | */ |
3892 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
3892 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
3893 | 3893 | $className = $this->_get_class_name(); |
3894 | - if( ! $object instanceof $className ){ |
|
3895 | - throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"),is_object( $object ) ? get_class( $object ) : $object, $className ) ); |
|
3894 | + if ( ! $object instanceof $className) { |
|
3895 | + throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"), is_object($object) ? get_class($object) : $object, $className)); |
|
3896 | 3896 | } |
3897 | 3897 | /** @var $object EE_Base_Class */ |
3898 | - if ( ! $object->ID() ){ |
|
3899 | - throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this))); |
|
3898 | + if ( ! $object->ID()) { |
|
3899 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
3900 | 3900 | } |
3901 | 3901 | // double check it's not already there |
3902 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
3903 | - if ( $classInstance ) { |
|
3902 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
3903 | + if ($classInstance) { |
|
3904 | 3904 | return $classInstance; |
3905 | 3905 | } else { |
3906 | - $this->_entity_map[ $object->ID() ] = $object; |
|
3906 | + $this->_entity_map[$object->ID()] = $object; |
|
3907 | 3907 | return $object; |
3908 | 3908 | } |
3909 | 3909 | } |
@@ -3916,8 +3916,8 @@ discard block |
||
3916 | 3916 | * @param array $cols_n_values |
3917 | 3917 | * @return array |
3918 | 3918 | */ |
3919 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
3920 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3919 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3920 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3921 | 3921 | } |
3922 | 3922 | |
3923 | 3923 | |
@@ -3930,40 +3930,40 @@ discard block |
||
3930 | 3930 | * @param string $cols_n_values |
3931 | 3931 | * @return array |
3932 | 3932 | */ |
3933 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
3933 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3934 | 3934 | $this_model_fields_n_values = array(); |
3935 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
3936 | - $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column() ); |
|
3935 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
3936 | + $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column()); |
|
3937 | 3937 | //there is a primary key on this table and its not set. Use defaults for all its columns |
3938 | - if( $table_obj->get_pk_column() && $table_pk_value === NULL ){ |
|
3939 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
3940 | - if( ! $field_obj->is_db_only_field() ){ |
|
3938 | + if ($table_obj->get_pk_column() && $table_pk_value === NULL) { |
|
3939 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
3940 | + if ( ! $field_obj->is_db_only_field()) { |
|
3941 | 3941 | //prepare field as if its coming from db |
3942 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
3943 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
3942 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
3943 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
3944 | 3944 | } |
3945 | 3945 | } |
3946 | - }else{ |
|
3946 | + } else { |
|
3947 | 3947 | //the table's rows existed. Use their values |
3948 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
3949 | - if( ! $field_obj->is_db_only_field() ) |
|
3950 | - $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() ); |
|
3948 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
3949 | + if ( ! $field_obj->is_db_only_field()) |
|
3950 | + $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column()); |
|
3951 | 3951 | } |
3952 | 3952 | } |
3953 | 3953 | } |
3954 | 3954 | return $this_model_fields_n_values; |
3955 | 3955 | } |
3956 | 3956 | |
3957 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
3957 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
3958 | 3958 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
3959 | 3959 | //does the field on the model relate to this column retrieved from the db? |
3960 | 3960 | //or is it a db-only field? (not relating to the model) |
3961 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
3962 | - $value = $cols_n_values[ $qualified_column ]; |
|
3961 | + if (isset($cols_n_values[$qualified_column])) { |
|
3962 | + $value = $cols_n_values[$qualified_column]; |
|
3963 | 3963 | |
3964 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
3965 | - $value = $cols_n_values[ $regular_column ]; |
|
3966 | - }else{ |
|
3964 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
3965 | + $value = $cols_n_values[$regular_column]; |
|
3966 | + } else { |
|
3967 | 3967 | $value = NULL; |
3968 | 3968 | } |
3969 | 3969 | |
@@ -3981,23 +3981,23 @@ discard block |
||
3981 | 3981 | * @param int|string $id |
3982 | 3982 | * @return EE_Base_Class |
3983 | 3983 | */ |
3984 | - public function refresh_entity_map_from_db( $id ){ |
|
3985 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
3986 | - if( $obj_in_map ){ |
|
3987 | - $wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) ); |
|
3988 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
3989 | - $one_row = reset( $wpdb_results ); |
|
3990 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
3991 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
3984 | + public function refresh_entity_map_from_db($id) { |
|
3985 | + $obj_in_map = $this->get_from_entity_map($id); |
|
3986 | + if ($obj_in_map) { |
|
3987 | + $wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1)); |
|
3988 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
3989 | + $one_row = reset($wpdb_results); |
|
3990 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
3991 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
3992 | 3992 | } |
3993 | 3993 | //clear the cache of related model objects |
3994 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
3995 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
3994 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
3995 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
3996 | 3996 | } |
3997 | 3997 | } |
3998 | 3998 | return $obj_in_map; |
3999 | - }else{ |
|
4000 | - return $this->get_one_by_ID( $id ); |
|
3999 | + } else { |
|
4000 | + return $this->get_one_by_ID($id); |
|
4001 | 4001 | } |
4002 | 4002 | } |
4003 | 4003 | |
@@ -4015,24 +4015,24 @@ discard block |
||
4015 | 4015 | * @param EE_Base_Class $replacing_model_obj |
4016 | 4016 | * @return \EE_Base_Class |
4017 | 4017 | */ |
4018 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
4019 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4020 | - if( $obj_in_map ){ |
|
4021 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
4022 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
4023 | - $obj_in_map->set( $field_name, $value ); |
|
4018 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
4019 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4020 | + if ($obj_in_map) { |
|
4021 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
4022 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
4023 | + $obj_in_map->set($field_name, $value); |
|
4024 | 4024 | } |
4025 | 4025 | //make the model object in the entity map's cache match the $replacing_model_obj |
4026 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4027 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4028 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
4029 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
4026 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4027 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4028 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
4029 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
4030 | 4030 | } |
4031 | 4031 | } |
4032 | 4032 | } |
4033 | 4033 | return $obj_in_map; |
4034 | - }else{ |
|
4035 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
4034 | + } else { |
|
4035 | + $this->add_to_entity_map($replacing_model_obj); |
|
4036 | 4036 | return $replacing_model_obj; |
4037 | 4037 | } |
4038 | 4038 | } |
@@ -4045,7 +4045,7 @@ discard block |
||
4045 | 4045 | * require_once($this->_getClassName().".class.php"); |
4046 | 4046 | * @return string |
4047 | 4047 | */ |
4048 | - private function _get_class_name(){ |
|
4048 | + private function _get_class_name() { |
|
4049 | 4049 | return "EE_".$this->get_this_model_name(); |
4050 | 4050 | } |
4051 | 4051 | |
@@ -4058,10 +4058,10 @@ discard block |
||
4058 | 4058 | * @param int $quantity |
4059 | 4059 | * @return string |
4060 | 4060 | */ |
4061 | - public function item_name($quantity = 1){ |
|
4062 | - if($quantity == 1){ |
|
4061 | + public function item_name($quantity = 1) { |
|
4062 | + if ($quantity == 1) { |
|
4063 | 4063 | return $this->singular_item; |
4064 | - }else{ |
|
4064 | + } else { |
|
4065 | 4065 | return $this->plural_item; |
4066 | 4066 | } |
4067 | 4067 | } |
@@ -4090,13 +4090,13 @@ discard block |
||
4090 | 4090 | * @throws EE_Error |
4091 | 4091 | * @return mixed whatever the plugin which calls add_filter decides |
4092 | 4092 | */ |
4093 | - public function __call($methodName,$args){ |
|
4094 | - $className=get_class($this); |
|
4095 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
4096 | - if(!has_filter($tagName)){ |
|
4093 | + public function __call($methodName, $args) { |
|
4094 | + $className = get_class($this); |
|
4095 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
4096 | + if ( ! has_filter($tagName)) { |
|
4097 | 4097 | throw new EE_Error( |
4098 | 4098 | sprintf( |
4099 | - __( 'Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso' ), |
|
4099 | + __('Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso'), |
|
4100 | 4100 | $methodName, |
4101 | 4101 | $className, |
4102 | 4102 | $tagName, |
@@ -4105,7 +4105,7 @@ discard block |
||
4105 | 4105 | ); |
4106 | 4106 | } |
4107 | 4107 | |
4108 | - return apply_filters($tagName,null,$this,$args); |
|
4108 | + return apply_filters($tagName, null, $this, $args); |
|
4109 | 4109 | } |
4110 | 4110 | |
4111 | 4111 | |
@@ -4118,22 +4118,22 @@ discard block |
||
4118 | 4118 | * @throws EE_Error |
4119 | 4119 | * @return EE_Base_Class |
4120 | 4120 | */ |
4121 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
4121 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
4122 | 4122 | $className = $this->_get_class_name(); |
4123 | 4123 | $primary_key_field = $this->get_primary_key_field(); |
4124 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4124 | + if ($base_class_obj_or_id instanceof $className) { |
|
4125 | 4125 | $model_object = $base_class_obj_or_id; |
4126 | - }elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
4127 | - is_int( $base_class_obj_or_id ) || |
|
4128 | - is_string( $base_class_obj_or_id ) )){//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
|
4126 | + }elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
4127 | + is_int($base_class_obj_or_id) || |
|
4128 | + is_string($base_class_obj_or_id) )) {//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
|
4129 | 4129 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4130 | - }elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
4130 | + }elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) { |
|
4131 | 4131 | //assume its a string representation of the object |
4132 | 4132 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4133 | - }else{ |
|
4134 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
4133 | + } else { |
|
4134 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
4135 | 4135 | } |
4136 | - if( $model_object->ID() == NULL && $ensure_is_in_db){ |
|
4136 | + if ($model_object->ID() == NULL && $ensure_is_in_db) { |
|
4137 | 4137 | $model_object->save(); |
4138 | 4138 | } |
4139 | 4139 | return $model_object; |
@@ -4149,19 +4149,19 @@ discard block |
||
4149 | 4149 | * @return int|string depending on the type of this model object's ID |
4150 | 4150 | * @throws EE_Error |
4151 | 4151 | */ |
4152 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
4152 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
4153 | 4153 | $className = $this->_get_class_name(); |
4154 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4154 | + if ($base_class_obj_or_id instanceof $className) { |
|
4155 | 4155 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4156 | 4156 | $id = $base_class_obj_or_id->ID(); |
4157 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4157 | + }elseif (is_int($base_class_obj_or_id)) { |
|
4158 | 4158 | //assume it's an ID |
4159 | 4159 | $id = $base_class_obj_or_id; |
4160 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4160 | + }elseif (is_string($base_class_obj_or_id)) { |
|
4161 | 4161 | //assume its a string representation of the object |
4162 | 4162 | $id = $base_class_obj_or_id; |
4163 | - }else{ |
|
4164 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
4163 | + } else { |
|
4164 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
4165 | 4165 | } |
4166 | 4166 | return $id; |
4167 | 4167 | } |
@@ -4184,14 +4184,14 @@ discard block |
||
4184 | 4184 | * @param int $values_already_prepared like one of the constants on EEM_Base |
4185 | 4185 | * @return void |
4186 | 4186 | */ |
4187 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
4187 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
4188 | 4188 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
4189 | 4189 | } |
4190 | 4190 | /** |
4191 | 4191 | * Read comments for assume_values_already_prepared_by_model_object() |
4192 | 4192 | * @return int |
4193 | 4193 | */ |
4194 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
4194 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
4195 | 4195 | return $this->_values_already_prepared_by_model_object; |
4196 | 4196 | } |
4197 | 4197 | |
@@ -4199,17 +4199,17 @@ discard block |
||
4199 | 4199 | * Gets all the indexes on this model |
4200 | 4200 | * @return EE_Index[] |
4201 | 4201 | */ |
4202 | - public function indexes(){ |
|
4202 | + public function indexes() { |
|
4203 | 4203 | return $this->_indexes; |
4204 | 4204 | } |
4205 | 4205 | /** |
4206 | 4206 | * Gets all the Unique Indexes on this model |
4207 | 4207 | * @return EE_Unique_Index[] |
4208 | 4208 | */ |
4209 | - public function unique_indexes(){ |
|
4209 | + public function unique_indexes() { |
|
4210 | 4210 | $unique_indexes = array(); |
4211 | - foreach($this->_indexes as $name => $index){ |
|
4212 | - if($index instanceof EE_Unique_Index){ |
|
4211 | + foreach ($this->_indexes as $name => $index) { |
|
4212 | + if ($index instanceof EE_Unique_Index) { |
|
4213 | 4213 | $unique_indexes [$name] = $index; |
4214 | 4214 | } |
4215 | 4215 | } |
@@ -4222,13 +4222,13 @@ discard block |
||
4222 | 4222 | * on a primary index |
4223 | 4223 | * @return EE_Model_Field_Base[] indexed by the field's name |
4224 | 4224 | */ |
4225 | - public function get_combined_primary_key_fields(){ |
|
4226 | - foreach($this->indexes() as $index){ |
|
4227 | - if($index instanceof EE_Primary_Key_Index){ |
|
4225 | + public function get_combined_primary_key_fields() { |
|
4226 | + foreach ($this->indexes() as $index) { |
|
4227 | + if ($index instanceof EE_Primary_Key_Index) { |
|
4228 | 4228 | return $index->fields(); |
4229 | 4229 | } |
4230 | 4230 | } |
4231 | - return array( $this->primary_key_name() => $this->get_primary_key_field()); |
|
4231 | + return array($this->primary_key_name() => $this->get_primary_key_field()); |
|
4232 | 4232 | } |
4233 | 4233 | |
4234 | 4234 | |
@@ -4238,7 +4238,7 @@ discard block |
||
4238 | 4238 | * @param array $cols_n_values keys are field names, values are their values |
4239 | 4239 | * @return string |
4240 | 4240 | */ |
4241 | - public function get_index_primary_key_string($cols_n_values){ |
|
4241 | + public function get_index_primary_key_string($cols_n_values) { |
|
4242 | 4242 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
4243 | 4243 | return http_build_query($cols_n_values_for_primary_key_index); |
4244 | 4244 | } |
@@ -4250,13 +4250,13 @@ discard block |
||
4250 | 4250 | * @param string $index_primary_key_string |
4251 | 4251 | * @return null|array |
4252 | 4252 | */ |
4253 | - function parse_index_primary_key_string( $index_primary_key_string) { |
|
4253 | + function parse_index_primary_key_string($index_primary_key_string) { |
|
4254 | 4254 | $key_fields = $this->get_combined_primary_key_fields(); |
4255 | 4255 | //check all of them are in the $id |
4256 | 4256 | $key_vals_in_combined_pk = array(); |
4257 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
4258 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
4259 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
4257 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
4258 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
4259 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
4260 | 4260 | return NULL; |
4261 | 4261 | } |
4262 | 4262 | } |
@@ -4269,10 +4269,10 @@ discard block |
||
4269 | 4269 | * @param array $key_vals |
4270 | 4270 | * @return boolean |
4271 | 4271 | */ |
4272 | - function has_all_combined_primary_key_fields( $key_vals ) { |
|
4273 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4274 | - foreach( $keys_it_should_have as $key ){ |
|
4275 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4272 | + function has_all_combined_primary_key_fields($key_vals) { |
|
4273 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4274 | + foreach ($keys_it_should_have as $key) { |
|
4275 | + if ( ! isset($key_vals[$key])) { |
|
4276 | 4276 | return false; |
4277 | 4277 | } |
4278 | 4278 | } |
@@ -4288,23 +4288,23 @@ discard block |
||
4288 | 4288 | * @throws EE_Error |
4289 | 4289 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4290 | 4290 | */ |
4291 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4291 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4292 | 4292 | |
4293 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4293 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4294 | 4294 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4295 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4295 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4296 | 4296 | $attributes_array = $model_object_or_attributes_array; |
4297 | - }else{ |
|
4298 | - throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array)); |
|
4297 | + } else { |
|
4298 | + throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"), $model_object_or_attributes_array)); |
|
4299 | 4299 | } |
4300 | 4300 | //even copies obviously won't have the same ID, so remove the primary key |
4301 | 4301 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4302 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4302 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4303 | 4303 | unset($attributes_array[$this->primary_key_name()]); |
4304 | 4304 | } |
4305 | - if(isset($query_params[0])){ |
|
4306 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4307 | - }else{ |
|
4305 | + if (isset($query_params[0])) { |
|
4306 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4307 | + } else { |
|
4308 | 4308 | $query_params[0] = $attributes_array; |
4309 | 4309 | } |
4310 | 4310 | return $this->get_all($query_params); |
@@ -4318,16 +4318,16 @@ discard block |
||
4318 | 4318 | * @param array $query_params |
4319 | 4319 | * @return EE_Base_Class |
4320 | 4320 | */ |
4321 | - function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4322 | - if( ! is_array( $query_params ) ){ |
|
4323 | - EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
4321 | + function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4322 | + if ( ! is_array($query_params)) { |
|
4323 | + EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
4324 | 4324 | $query_params = array(); |
4325 | 4325 | } |
4326 | 4326 | $query_params['limit'] = 1; |
4327 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4328 | - if(is_array($copies)){ |
|
4327 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4328 | + if (is_array($copies)) { |
|
4329 | 4329 | return array_shift($copies); |
4330 | - }else{ |
|
4330 | + } else { |
|
4331 | 4331 | return null; |
4332 | 4332 | } |
4333 | 4333 | } |
@@ -4341,10 +4341,10 @@ discard block |
||
4341 | 4341 | * @param int|string $id the value of the primary key to update |
4342 | 4342 | * @return int number of rows updated |
4343 | 4343 | */ |
4344 | - public function update_by_ID($fields_n_values,$id){ |
|
4344 | + public function update_by_ID($fields_n_values, $id) { |
|
4345 | 4345 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4346 | 4346 | 'default_where_conditions'=>'other_models_only',); |
4347 | - return $this->update($fields_n_values,$query_params); |
|
4347 | + return $this->update($fields_n_values, $query_params); |
|
4348 | 4348 | } |
4349 | 4349 | |
4350 | 4350 | |
@@ -4355,12 +4355,12 @@ discard block |
||
4355 | 4355 | * @return string an operator which can be used in SQL |
4356 | 4356 | * @throws EE_Error |
4357 | 4357 | */ |
4358 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4358 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4359 | 4359 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4360 | - if($sql_operator){ |
|
4360 | + if ($sql_operator) { |
|
4361 | 4361 | return $sql_operator; |
4362 | - }else{ |
|
4363 | - throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators)))); |
|
4362 | + } else { |
|
4363 | + throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"), $operator_supplied, implode(",", array_keys($this->_valid_operators)))); |
|
4364 | 4364 | } |
4365 | 4365 | } |
4366 | 4366 | |
@@ -4370,10 +4370,10 @@ discard block |
||
4370 | 4370 | * @param array $query_params like get_all's |
4371 | 4371 | * @return string[] |
4372 | 4372 | */ |
4373 | - public function get_all_names($query_params = array()){ |
|
4373 | + public function get_all_names($query_params = array()) { |
|
4374 | 4374 | $objs = $this->get_all($query_params); |
4375 | 4375 | $names = array(); |
4376 | - foreach($objs as $obj){ |
|
4376 | + foreach ($objs as $obj) { |
|
4377 | 4377 | $names[$obj->ID()] = $obj->name(); |
4378 | 4378 | } |
4379 | 4379 | return $names; |
@@ -4388,22 +4388,22 @@ discard block |
||
4388 | 4388 | * @param boolean $filter_out_empty_ids if a model object has an ID of '' or 0, don't bother including it in the returned array |
4389 | 4389 | * @return array |
4390 | 4390 | */ |
4391 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4392 | - if( ! $this->has_primary_key_field() ) { |
|
4393 | - if( WP_DEBUG ) { |
|
4394 | - EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
4391 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4392 | + if ( ! $this->has_primary_key_field()) { |
|
4393 | + if (WP_DEBUG) { |
|
4394 | + EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
4395 | 4395 | return array(); |
4396 | 4396 | } |
4397 | 4397 | } |
4398 | 4398 | $IDs = array(); |
4399 | - foreach( $model_objects as $model_object ) { |
|
4399 | + foreach ($model_objects as $model_object) { |
|
4400 | 4400 | $id = $model_object->ID(); |
4401 | - if( ! $id ) { |
|
4402 | - if( $filter_out_empty_ids ) { |
|
4401 | + if ( ! $id) { |
|
4402 | + if ($filter_out_empty_ids) { |
|
4403 | 4403 | continue; |
4404 | 4404 | } |
4405 | - if( WP_DEBUG ) { |
|
4406 | - EE_Error::add_error(__( 'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
4405 | + if (WP_DEBUG) { |
|
4406 | + EE_Error::add_error(__('Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
4407 | 4407 | } |
4408 | 4408 | } |
4409 | 4409 | $IDs[] = $id; |
@@ -4416,8 +4416,8 @@ discard block |
||
4416 | 4416 | * are no capabilities that relate to this model returns false |
4417 | 4417 | * @return string|false |
4418 | 4418 | */ |
4419 | - public function cap_slug(){ |
|
4420 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4419 | + public function cap_slug() { |
|
4420 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4421 | 4421 | } |
4422 | 4422 | |
4423 | 4423 | /** |
@@ -4429,27 +4429,27 @@ discard block |
||
4429 | 4429 | * @param string $context |
4430 | 4430 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4431 | 4431 | */ |
4432 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4433 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4432 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4433 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4434 | 4434 | //check if we ought to run the restriction generator first |
4435 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
4436 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base && |
|
4437 | - ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) { |
|
4438 | - $this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ], $this->_cap_restriction_generators[ $context ]->generate_restrictions() ); |
|
4435 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
4436 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base && |
|
4437 | + ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) { |
|
4438 | + $this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions()); |
|
4439 | 4439 | } |
4440 | 4440 | //and make sure we've finalized the construction of each restriction |
4441 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4442 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4441 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4442 | + $where_conditions_obj->_finalize_construct($this); |
|
4443 | 4443 | } |
4444 | 4444 | |
4445 | - return $this->_cap_restrictions[ $context ]; |
|
4445 | + return $this->_cap_restrictions[$context]; |
|
4446 | 4446 | } |
4447 | 4447 | |
4448 | 4448 | /** |
4449 | 4449 | * Indicating whether or not this model thinks its a wp core model |
4450 | 4450 | * @return boolean |
4451 | 4451 | */ |
4452 | - public function is_wp_core_model(){ |
|
4452 | + public function is_wp_core_model() { |
|
4453 | 4453 | return $this->_wp_core_model; |
4454 | 4454 | } |
4455 | 4455 | |
@@ -4459,12 +4459,12 @@ discard block |
||
4459 | 4459 | * @param string $context one of EEM_Base::caps_ constants |
4460 | 4460 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4461 | 4461 | */ |
4462 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4462 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4463 | 4463 | $missing_caps = array(); |
4464 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4465 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4466 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4467 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4464 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4465 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4466 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4467 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4468 | 4468 | } |
4469 | 4469 | } |
4470 | 4470 | return $missing_caps; |
@@ -4476,7 +4476,7 @@ discard block |
||
4476 | 4476 | * one of 'read', 'edit', or 'delete' |
4477 | 4477 | */ |
4478 | 4478 | public function cap_contexts_to_cap_action_map() { |
4479 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4479 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4480 | 4480 | } |
4481 | 4481 | |
4482 | 4482 | |
@@ -4487,19 +4487,19 @@ discard block |
||
4487 | 4487 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4488 | 4488 | * @throws \EE_Error |
4489 | 4489 | */ |
4490 | - public function cap_action_for_context( $context ) { |
|
4490 | + public function cap_action_for_context($context) { |
|
4491 | 4491 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4492 | - if( isset( $mapping[ $context ] ) ) { |
|
4493 | - return $mapping[ $context ]; |
|
4492 | + if (isset($mapping[$context])) { |
|
4493 | + return $mapping[$context]; |
|
4494 | 4494 | } |
4495 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4495 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4496 | 4496 | return $action; |
4497 | 4497 | } |
4498 | 4498 | throw new EE_Error( |
4499 | 4499 | sprintf( |
4500 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4500 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4501 | 4501 | $context, |
4502 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4502 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4503 | 4503 | ) |
4504 | 4504 | ); |
4505 | 4505 | |
@@ -4510,7 +4510,7 @@ discard block |
||
4510 | 4510 | * @return array |
4511 | 4511 | */ |
4512 | 4512 | static public function valid_cap_contexts() { |
4513 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4513 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4514 | 4514 | self::caps_read, |
4515 | 4515 | self::caps_read_admin, |
4516 | 4516 | self::caps_edit, |
@@ -4526,17 +4526,17 @@ discard block |
||
4526 | 4526 | * @return bool |
4527 | 4527 | * @throws \EE_Error |
4528 | 4528 | */ |
4529 | - static public function verify_is_valid_cap_context( $context ) { |
|
4529 | + static public function verify_is_valid_cap_context($context) { |
|
4530 | 4530 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4531 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4531 | + if (in_array($context, $valid_cap_contexts)) { |
|
4532 | 4532 | return true; |
4533 | - }else{ |
|
4533 | + } else { |
|
4534 | 4534 | throw new EE_Error( |
4535 | 4535 | sprintf( |
4536 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4536 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4537 | 4537 | $context, |
4538 | - 'EEM_Base' , |
|
4539 | - implode(',', $valid_cap_contexts ) |
|
4538 | + 'EEM_Base', |
|
4539 | + implode(',', $valid_cap_contexts) |
|
4540 | 4540 | ) |
4541 | 4541 | ); |
4542 | 4542 | } |
@@ -1,24 +1,24 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | /** |
4 | - * |
|
5 | - * Class Model_Data_Translator |
|
6 | - * |
|
7 | - * Class for translating data between the EE4 models and JSON. |
|
8 | - * Some of this class needs to interpret an incoming array of query params from |
|
9 | - * the REST API and prepare it for use by the models. Some of this code seems duplicated |
|
10 | - * fromt he models but it's anticipated to diverge (because providing parameters |
|
11 | - * in the REST API is sometimes more difficult than in PHP directly. Eg, providing an array like |
|
12 | - * array( 'where' => array( 'EVT_ID' => array( '<', 100 ) ) ) in PHP is easy, but in a querystring it needs to look like |
|
13 | - * "where[EVT_ID][]=<&where[EVT_ID][]=100" is less intuitive, so we may want |
|
14 | - * to allow REST API query parameters to diverge from the format accepted by models) |
|
15 | - * |
|
16 | - * @package Event Espresso |
|
17 | - * @subpackage |
|
18 | - * @author Mike Nelson |
|
19 | - * @since 4.8.36 |
|
20 | - * |
|
21 | - */ |
|
4 | + * |
|
5 | + * Class Model_Data_Translator |
|
6 | + * |
|
7 | + * Class for translating data between the EE4 models and JSON. |
|
8 | + * Some of this class needs to interpret an incoming array of query params from |
|
9 | + * the REST API and prepare it for use by the models. Some of this code seems duplicated |
|
10 | + * fromt he models but it's anticipated to diverge (because providing parameters |
|
11 | + * in the REST API is sometimes more difficult than in PHP directly. Eg, providing an array like |
|
12 | + * array( 'where' => array( 'EVT_ID' => array( '<', 100 ) ) ) in PHP is easy, but in a querystring it needs to look like |
|
13 | + * "where[EVT_ID][]=<&where[EVT_ID][]=100" is less intuitive, so we may want |
|
14 | + * to allow REST API query parameters to diverge from the format accepted by models) |
|
15 | + * |
|
16 | + * @package Event Espresso |
|
17 | + * @subpackage |
|
18 | + * @author Mike Nelson |
|
19 | + * @since 4.8.36 |
|
20 | + * |
|
21 | + */ |
|
22 | 22 | |
23 | 23 | |
24 | 24 | if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | - * Prepares a field's value for display in the API |
|
78 | - * @param \EE_Model_Field_Base $field_obj |
|
79 | - * @param mixed $original_value |
|
80 | - * @return mixed |
|
81 | - */ |
|
77 | + * Prepares a field's value for display in the API |
|
78 | + * @param \EE_Model_Field_Base $field_obj |
|
79 | + * @param mixed $original_value |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | 82 | public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) { |
83 | 83 | if( $original_value === EE_INF ) { |
84 | 84 | $new_value = self::ee_inf_in_rest; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $original_value, |
96 | 96 | $requested_version |
97 | 97 | ); |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Prepares condition-query-parameters (like what's in where and having) from |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | |
24 | -if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
25 | - exit( 'No direct script access allowed' ); |
|
24 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
25 | + exit('No direct script access allowed'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | class Model_Data_Translator { |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | * @param string $requested_version |
41 | 41 | * @return mixed |
42 | 42 | */ |
43 | - public static function prepare_field_values_from_json( $field_obj, $original_value_maybe_array, $requested_version ) { |
|
44 | - if( is_array( $original_value_maybe_array ) ) { |
|
43 | + public static function prepare_field_values_from_json($field_obj, $original_value_maybe_array, $requested_version) { |
|
44 | + if (is_array($original_value_maybe_array)) { |
|
45 | 45 | $new_value_maybe_array = array(); |
46 | - foreach( $original_value_maybe_array as $array_key => $array_item ) { |
|
47 | - $new_value_maybe_array[ $array_key ] = self::prepare_field_value_from_json( $field_obj, $array_item, $requested_version ); |
|
46 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
47 | + $new_value_maybe_array[$array_key] = self::prepare_field_value_from_json($field_obj, $array_item, $requested_version); |
|
48 | 48 | } |
49 | 49 | } else { |
50 | - $new_value_maybe_array = self::prepare_field_value_from_json( $field_obj, $original_value_maybe_array, $requested_version ); |
|
50 | + $new_value_maybe_array = self::prepare_field_value_from_json($field_obj, $original_value_maybe_array, $requested_version); |
|
51 | 51 | } |
52 | 52 | return $new_value_maybe_array; |
53 | 53 | } |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | * @param string $requested_version |
61 | 61 | * @return mixed |
62 | 62 | */ |
63 | - public static function prepare_field_value_from_json( $field_obj, $original_value, $requested_version ) { |
|
63 | + public static function prepare_field_value_from_json($field_obj, $original_value, $requested_version) { |
|
64 | 64 | $new_value = null; |
65 | - if( $field_obj instanceof \EE_Infinite_Integer_Field |
|
66 | - && in_array( $original_value, array( null, '' ), true ) ) { |
|
65 | + if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
66 | + && in_array($original_value, array(null, ''), true)) { |
|
67 | 67 | $new_value = EE_INF; |
68 | - } elseif( $field_obj instanceof \EE_Datetime_Field ) { |
|
69 | - $new_value = rest_parse_date( $original_value ); |
|
68 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
69 | + $new_value = rest_parse_date($original_value); |
|
70 | 70 | } else { |
71 | 71 | $new_value = $original_value; |
72 | 72 | } |
@@ -79,17 +79,17 @@ discard block |
||
79 | 79 | * @param mixed $original_value |
80 | 80 | * @return mixed |
81 | 81 | */ |
82 | - public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) { |
|
83 | - if( $original_value === EE_INF ) { |
|
82 | + public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) { |
|
83 | + if ($original_value === EE_INF) { |
|
84 | 84 | $new_value = self::ee_inf_in_rest; |
85 | - } elseif( $field_obj instanceof \EE_Datetime_Field && |
|
86 | - $original_value instanceof \DateTime ) { |
|
87 | - $new_value = $original_value->format( 'c' ); |
|
88 | - $new_value = mysql_to_rfc3339( $new_value ); |
|
85 | + } elseif ($field_obj instanceof \EE_Datetime_Field && |
|
86 | + $original_value instanceof \DateTime) { |
|
87 | + $new_value = $original_value->format('c'); |
|
88 | + $new_value = mysql_to_rfc3339($new_value); |
|
89 | 89 | } else { |
90 | 90 | $new_value = $original_value; |
91 | 91 | } |
92 | - return apply_filters( 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
92 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
93 | 93 | $new_value, |
94 | 94 | $field_obj, |
95 | 95 | $original_value, |
@@ -105,39 +105,39 @@ discard block |
||
105 | 105 | * @param string $requested_version |
106 | 106 | * @return array |
107 | 107 | */ |
108 | - public static function prepare_conditions_query_params_for_models( $inputted_query_params_of_this_type, \EEM_Base $model, $requested_version ) { |
|
108 | + public static function prepare_conditions_query_params_for_models($inputted_query_params_of_this_type, \EEM_Base $model, $requested_version) { |
|
109 | 109 | $query_param_for_models = array(); |
110 | - foreach( $inputted_query_params_of_this_type as $query_param_key => $query_param_value ) { |
|
110 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
111 | 111 | $field = self::deduce_field_from_query_param( |
112 | - self::remove_stars_and_anything_after_from_condition_query_param_key( $query_param_key ), |
|
112 | + self::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
113 | 113 | $model |
114 | 114 | ); |
115 | - if( $field instanceof \EE_Model_Field_Base ) { |
|
115 | + if ($field instanceof \EE_Model_Field_Base) { |
|
116 | 116 | //did they specify an operator? |
117 | - if( is_array( $query_param_value ) ) { |
|
118 | - $op = $query_param_value[ 0 ]; |
|
119 | - $translated_value = array( $op ); |
|
120 | - if( isset( $query_param_value[ 1 ] ) ) { |
|
121 | - $value = $query_param_value[ 1 ]; |
|
122 | - $translated_value[1] = self::prepare_field_values_from_json( $field, $value, $requested_version ); |
|
117 | + if (is_array($query_param_value)) { |
|
118 | + $op = $query_param_value[0]; |
|
119 | + $translated_value = array($op); |
|
120 | + if (isset($query_param_value[1])) { |
|
121 | + $value = $query_param_value[1]; |
|
122 | + $translated_value[1] = self::prepare_field_values_from_json($field, $value, $requested_version); |
|
123 | 123 | } |
124 | 124 | } else { |
125 | - $translated_value = self::prepare_field_value_from_json( $field, $query_param_value, $requested_version ); |
|
125 | + $translated_value = self::prepare_field_value_from_json($field, $query_param_value, $requested_version); |
|
126 | 126 | } |
127 | - $query_param_for_models[ $query_param_key ] = $translated_value; |
|
127 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
128 | 128 | } else { |
129 | 129 | //so it's not for a field, assume it's a logic query param key |
130 | - $query_param_for_models[ $query_param_key ] = self::prepare_conditions_query_params_for_models( $query_param_value, $model, $requested_version ); |
|
130 | + $query_param_for_models[$query_param_key] = self::prepare_conditions_query_params_for_models($query_param_value, $model, $requested_version); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | return $query_param_for_models; |
134 | 134 | } |
135 | 135 | |
136 | - public static function remove_stars_and_anything_after_from_condition_query_param_key( $condition_query_param_key ) { |
|
136 | + public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
137 | 137 | $pos_of_star = strpos($condition_query_param_key, '*'); |
138 | - if($pos_of_star === FALSE){ |
|
138 | + if ($pos_of_star === FALSE) { |
|
139 | 139 | return $condition_query_param_key; |
140 | - }else{ |
|
140 | + } else { |
|
141 | 141 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
142 | 142 | return $condition_query_param_sans_star; |
143 | 143 | } |
@@ -149,26 +149,26 @@ discard block |
||
149 | 149 | * @throws EE_Error |
150 | 150 | * @return EE_Model_Field_Base |
151 | 151 | */ |
152 | - public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model){ |
|
152 | + public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) { |
|
153 | 153 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
154 | 154 | //which will help us find the database table and column |
155 | 155 | |
156 | - $query_param_parts = explode(".",$query_param_name); |
|
157 | - if(empty($query_param_parts)){ |
|
158 | - throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
156 | + $query_param_parts = explode(".", $query_param_name); |
|
157 | + if (empty($query_param_parts)) { |
|
158 | + throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
159 | 159 | } |
160 | 160 | $number_of_parts = count($query_param_parts); |
161 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
162 | - if($number_of_parts == 1){ |
|
161 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
162 | + if ($number_of_parts == 1) { |
|
163 | 163 | $field_name = $last_query_param_part; |
164 | - }else{// $number_of_parts >= 2 |
|
164 | + } else {// $number_of_parts >= 2 |
|
165 | 165 | //the last part is the column name, and there are only 2parts. therefore... |
166 | 166 | $field_name = $last_query_param_part; |
167 | - $model = \EE_Registry::instance()->load_model( $query_param_parts[ $number_of_parts - 2 ]); |
|
167 | + $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
168 | 168 | } |
169 | - try{ |
|
169 | + try { |
|
170 | 170 | return $model->field_settings_for($field_name); |
171 | - }catch(\EE_Error $e){ |
|
171 | + } catch (\EE_Error $e) { |
|
172 | 172 | return null; |
173 | 173 | } |
174 | 174 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -54,23 +54,23 @@ discard block |
||
54 | 54 | $this->_name = 'pricing'; |
55 | 55 | |
56 | 56 | //capability check |
57 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_default_prices', 'advanced_ticket_datetime_metabox' ) ) { |
|
57 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices', 'advanced_ticket_datetime_metabox')) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
61 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
61 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
62 | 62 | |
63 | 63 | //if we were going to add our own metaboxes we'd use the below. |
64 | 64 | $this->_metaboxes = array( |
65 | 65 | 0 => array( |
66 | - 'page_route' => array('edit','create_new'), |
|
66 | + 'page_route' => array('edit', 'create_new'), |
|
67 | 67 | 'func' => 'pricing_metabox', |
68 | 68 | 'label' => __('Event Tickets & Datetimes', 'event_espresso'), |
69 | 69 | 'priority' => 'high', |
70 | 70 | 'context' => 'normal' |
71 | 71 | ), |
72 | 72 | |
73 | - );/**/ |
|
73 | + ); /**/ |
|
74 | 74 | |
75 | 75 | $this->_remove_metaboxes = array( |
76 | 76 | 0 => array( |
@@ -89,24 +89,24 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @var array Expected an array returned with 'date' and 'time' keys. |
91 | 91 | */ |
92 | - $this->_date_format_strings = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', array( |
|
92 | + $this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', array( |
|
93 | 93 | 'date' => 'Y-m-d', |
94 | 94 | 'time' => 'h:i a' |
95 | 95 | )); |
96 | 96 | |
97 | 97 | //validate |
98 | - $this->_date_format_strings['date'] = isset( $this->_date_format_strings['date'] ) ? $this->_date_format_strings['date'] : null; |
|
99 | - $this->_date_format_strings['time'] = isset( $this->_date_format_strings['time'] ) ? $this->_date_format_strings['time'] : null; |
|
98 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null; |
|
99 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null; |
|
100 | 100 | |
101 | 101 | //validate format strings |
102 | - $format_validation = EEH_DTT_Helper::validate_format_string( $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] ); |
|
103 | - if ( is_array( $format_validation ) ) { |
|
104 | - $msg = '<p>' . sprintf( __( 'The format "%s" was likely added via a filter and is invalid for the following reasons:', 'event_espresso' ), $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] ) . '</p><ul>'; |
|
105 | - foreach ( $format_validation as $error ) { |
|
106 | - $msg .= '<li>' . $error . '</li>'; |
|
102 | + $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'].' '.$this->_date_format_strings['time']); |
|
103 | + if (is_array($format_validation)) { |
|
104 | + $msg = '<p>'.sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:', 'event_espresso'), $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']).'</p><ul>'; |
|
105 | + foreach ($format_validation as $error) { |
|
106 | + $msg .= '<li>'.$error.'</li>'; |
|
107 | 107 | } |
108 | - $msg .= '</ul></p><p>' . sprintf( __( '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', 'event_espresso' ), '<span style="color:#D54E21;">', '</span>' ) . '</p>'; |
|
109 | - EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
108 | + $msg .= '</ul></p><p>'.sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', 'event_espresso'), '<span style="color:#D54E21;">', '</span>').'</p>'; |
|
109 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
110 | 110 | $this->_date_format_strings = array( |
111 | 111 | 'date' => 'Y-m-d', |
112 | 112 | 'time' => 'h:i a' |
@@ -117,60 +117,60 @@ discard block |
||
117 | 117 | $this->_scripts_styles = array( |
118 | 118 | 'registers' => array( |
119 | 119 | 'ee-tickets-datetimes-css' => array( |
120 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
120 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
121 | 121 | 'type' => 'css' |
122 | 122 | ), |
123 | 123 | 'ee-dtt-ticket-metabox' => array( |
124 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
124 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
125 | 125 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore') |
126 | 126 | ) |
127 | 127 | ), |
128 | 128 | 'deregisters' => array( |
129 | - 'event-editor-css' => array('type' => 'css' ), |
|
129 | + 'event-editor-css' => array('type' => 'css'), |
|
130 | 130 | 'event-datetime-metabox' => array('type' => 'js') |
131 | 131 | ), |
132 | 132 | 'enqueues' => array( |
133 | - 'ee-tickets-datetimes-css' => array( 'edit', 'create_new' ), |
|
134 | - 'ee-dtt-ticket-metabox' => array( 'edit', 'create_new' ) |
|
133 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
134 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new') |
|
135 | 135 | ), |
136 | 136 | 'localize' => array( |
137 | 137 | 'ee-dtt-ticket-metabox' => array( |
138 | 138 | 'DTT_TRASH_BLOCK' => array( |
139 | 139 | 'main_warning' => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', 'event_espresso'), |
140 | 140 | 'after_warning' => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', 'event_espresso'), |
141 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' . __('Cancel', 'event_espresso') . '</button>', |
|
141 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">'.__('Cancel', 'event_espresso').'</button>', |
|
142 | 142 | 'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', 'event_espresso'), |
143 | 143 | 'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', 'event_espresso'), |
144 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss', 'event_espresso') . '</button>' |
|
144 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">'.__('Dismiss', 'event_espresso').'</button>' |
|
145 | 145 | ), |
146 | 146 | 'DTT_ERROR_MSG' => array( |
147 | 147 | 'no_ticket_name' => __('General Admission', 'event_espresso'), |
148 | - 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss', 'event_espresso') . '</button></div>' |
|
148 | + 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">'.__('Dismiss', 'event_espresso').'</button></div>' |
|
149 | 149 | ), |
150 | 150 | 'DTT_OVERSELL_WARNING' => array( |
151 | 151 | 'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', 'event_espresso'), |
152 | 152 | 'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', 'event_espresso') |
153 | 153 | ), |
154 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( $this->_date_format_strings['date'], $this->_date_format_strings['time'] ), |
|
155 | - 'DTT_START_OF_WEEK' => array( 'dayValue' => (int) get_option( 'start_of_week' ) ) |
|
154 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
155 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')) |
|
156 | 156 | ) |
157 | 157 | ) |
158 | 158 | ); |
159 | 159 | |
160 | 160 | |
161 | - add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', array( $this, 'autosave_handling' ), 10 ); |
|
162 | - add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', array( $this, 'caf_updates' ), 10 ); |
|
161 | + add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', array($this, 'autosave_handling'), 10); |
|
162 | + add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', array($this, 'caf_updates'), 10); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
166 | 166 | |
167 | - public function caf_updates( $update_callbacks ) { |
|
168 | - foreach ( $update_callbacks as $key => $callback ) { |
|
169 | - if ( $callback[1] == '_default_tickets_update' ) |
|
170 | - unset( $update_callbacks[$key] ); |
|
167 | + public function caf_updates($update_callbacks) { |
|
168 | + foreach ($update_callbacks as $key => $callback) { |
|
169 | + if ($callback[1] == '_default_tickets_update') |
|
170 | + unset($update_callbacks[$key]); |
|
171 | 171 | } |
172 | 172 | |
173 | - $update_callbacks[] = array( $this, 'dtt_and_tickets_caf_update' ); |
|
173 | + $update_callbacks[] = array($this, 'dtt_and_tickets_caf_update'); |
|
174 | 174 | return $update_callbacks; |
175 | 175 | } |
176 | 176 | |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | * @param array $data The request data from the form |
184 | 184 | * @return bool success or fail |
185 | 185 | */ |
186 | - public function dtt_and_tickets_caf_update( $evtobj, $data ) { |
|
186 | + public function dtt_and_tickets_caf_update($evtobj, $data) { |
|
187 | 187 | //first we need to start with datetimes cause they are the "root" items attached to events. |
188 | - $saved_dtts = $this->_update_dtts( $evtobj, $data ); |
|
188 | + $saved_dtts = $this->_update_dtts($evtobj, $data); |
|
189 | 189 | //next tackle the tickets (and prices?) |
190 | - $this->_update_tkts( $evtobj, $saved_dtts, $data ); |
|
190 | + $this->_update_tkts($evtobj, $saved_dtts, $data); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -198,41 +198,41 @@ discard block |
||
198 | 198 | * @param array $data the request data from the form |
199 | 199 | * @return EE_Datetime[] |
200 | 200 | */ |
201 | - protected function _update_dtts( $evt_obj, $data ) { |
|
202 | - $timezone = isset( $data['timezone_string'] ) ? $data['timezone_string'] : NULL; |
|
201 | + protected function _update_dtts($evt_obj, $data) { |
|
202 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : NULL; |
|
203 | 203 | $saved_dtt_ids = array(); |
204 | 204 | $saved_dtt_objs = array(); |
205 | 205 | |
206 | - foreach ( $data['edit_event_datetimes'] as $row => $dtt ) { |
|
206 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
207 | 207 | //trim all values to ensure any excess whitespace is removed. |
208 | 208 | $dtt = array_map( |
209 | - function( $datetime_data ) { |
|
210 | - return is_array( $datetime_data ) ? $datetime_data : trim( $datetime_data ); |
|
209 | + function($datetime_data) { |
|
210 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
211 | 211 | }, |
212 | 212 | $dtt |
213 | 213 | ); |
214 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty( $dtt['DTT_EVT_end'] ) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start']; |
|
214 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start']; |
|
215 | 215 | $datetime_values = array( |
216 | - 'DTT_ID' => ! empty( $dtt['DTT_ID'] ) ? $dtt['DTT_ID'] : NULL, |
|
217 | - 'DTT_name' => ! empty( $dtt['DTT_name'] ) ? $dtt['DTT_name'] : '', |
|
218 | - 'DTT_description' => ! empty( $dtt['DTT_description'] ) ? $dtt['DTT_description'] : '', |
|
216 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : NULL, |
|
217 | + 'DTT_name' => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '', |
|
218 | + 'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '', |
|
219 | 219 | 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
220 | 220 | 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
221 | - 'DTT_reg_limit' => empty( $dtt['DTT_reg_limit'] ) ? EE_INF : $dtt[ 'DTT_reg_limit' ], |
|
222 | - 'DTT_order' => ! isset( $dtt['DTT_order'] ) ? $row : $dtt['DTT_order'], |
|
221 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
222 | + 'DTT_order' => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'], |
|
223 | 223 | ); |
224 | 224 | |
225 | 225 | //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
226 | 226 | |
227 | - if ( !empty( $dtt['DTT_ID'] ) ) { |
|
228 | - $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone) )->get_one_by_ID($dtt['DTT_ID'] ); |
|
227 | + if ( ! empty($dtt['DTT_ID'])) { |
|
228 | + $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']); |
|
229 | 229 | |
230 | 230 | //set date and time format according to what is set in this class. |
231 | - $DTM->set_date_format( $this->_date_format_strings['date'] ); |
|
232 | - $DTM->set_time_format( $this->_date_format_strings['time'] ); |
|
231 | + $DTM->set_date_format($this->_date_format_strings['date']); |
|
232 | + $DTM->set_time_format($this->_date_format_strings['time']); |
|
233 | 233 | |
234 | - foreach ( $datetime_values as $field => $value ) { |
|
235 | - $DTM->set( $field, $value ); |
|
234 | + foreach ($datetime_values as $field => $value) { |
|
235 | + $DTM->set($field, $value); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. |
@@ -240,24 +240,24 @@ discard block |
||
240 | 240 | $saved_dtt_ids[$DTM->ID()] = $DTM->ID(); |
241 | 241 | |
242 | 242 | } else { |
243 | - $DTM = EE_Registry::instance()->load_class('Datetime', array( $datetime_values, $timezone ), FALSE, FALSE ); |
|
243 | + $DTM = EE_Registry::instance()->load_class('Datetime', array($datetime_values, $timezone), FALSE, FALSE); |
|
244 | 244 | |
245 | 245 | //reset date and times to match the format |
246 | - $DTM->set_date_format( $this->_date_format_strings['date'] ); |
|
247 | - $DTM->set_time_format( $this->_date_format_strings['time'] ); |
|
248 | - foreach( $datetime_values as $field => $value ) { |
|
249 | - $DTM->set( $field, $value ); |
|
246 | + $DTM->set_date_format($this->_date_format_strings['date']); |
|
247 | + $DTM->set_time_format($this->_date_format_strings['time']); |
|
248 | + foreach ($datetime_values as $field => $value) { |
|
249 | + $DTM->set($field, $value); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
253 | 253 | |
254 | 254 | $DTM->save(); |
255 | - $DTM = $evt_obj->_add_relation_to( $DTM, 'Datetime' ); |
|
255 | + $DTM = $evt_obj->_add_relation_to($DTM, 'Datetime'); |
|
256 | 256 | $evt_obj->save(); |
257 | 257 | |
258 | 258 | //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
259 | - if( $DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end') ) { |
|
260 | - $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start') ); |
|
259 | + if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) { |
|
260 | + $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start')); |
|
261 | 261 | EE_Registry::instance()->load_helper('DTT_Helper'); |
262 | 262 | $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days'); |
263 | 263 | $DTM->save(); |
@@ -273,25 +273,25 @@ discard block |
||
273 | 273 | } |
274 | 274 | |
275 | 275 | //now we need to REMOVE any dtts that got deleted. Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point. |
276 | - $old_datetimes = explode(',', $data['datetime_IDs'] ); |
|
276 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
277 | 277 | $old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes; |
278 | 278 | |
279 | - if ( is_array( $old_datetimes ) ) { |
|
280 | - $dtts_to_delete = array_diff( $old_datetimes, $saved_dtt_ids ); |
|
281 | - foreach ( $dtts_to_delete as $id ) { |
|
282 | - $id = absint( $id ); |
|
283 | - if ( empty( $id ) ) |
|
279 | + if (is_array($old_datetimes)) { |
|
280 | + $dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
281 | + foreach ($dtts_to_delete as $id) { |
|
282 | + $id = absint($id); |
|
283 | + if (empty($id)) |
|
284 | 284 | continue; |
285 | 285 | |
286 | 286 | $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
287 | 287 | |
288 | 288 | //remove tkt relationships. |
289 | 289 | $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
290 | - foreach ( $related_tickets as $tkt ) { |
|
290 | + foreach ($related_tickets as $tkt) { |
|
291 | 291 | $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
292 | 292 | } |
293 | 293 | |
294 | - $evt_obj->_remove_relation_to( $id, 'Datetime' ); |
|
294 | + $evt_obj->_remove_relation_to($id, 'Datetime'); |
|
295 | 295 | $dtt_to_remove->refresh_cache_of_related_objects(); |
296 | 296 | |
297 | 297 | } |
@@ -312,86 +312,86 @@ discard block |
||
312 | 312 | * @param array $data incoming request data |
313 | 313 | * @return EE_Ticket[] |
314 | 314 | */ |
315 | - protected function _update_tkts( $evtobj, $saved_dtts, $data ) { |
|
315 | + protected function _update_tkts($evtobj, $saved_dtts, $data) { |
|
316 | 316 | |
317 | 317 | $new_tkt = null; |
318 | 318 | $new_default = null; |
319 | 319 | //stripslashes because WP filtered the $_POST ($data) array to add slashes |
320 | 320 | $data = stripslashes_deep($data); |
321 | - $timezone = isset( $data['timezone_string'] ) ? $data['timezone_string'] : NULL; |
|
321 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : NULL; |
|
322 | 322 | $saved_tickets = $dtts_on_existing = array(); |
323 | - $old_tickets = isset( $data['ticket_IDs'] ) ? explode(',', $data['ticket_IDs'] ) : array(); |
|
323 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
324 | 324 | |
325 | 325 | //load money helper |
326 | - EE_Registry::instance()->load_helper( 'Money' ); |
|
326 | + EE_Registry::instance()->load_helper('Money'); |
|
327 | 327 | |
328 | - foreach ( $data['edit_tickets'] as $row => $tkt ) { |
|
328 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
329 | 329 | |
330 | 330 | $update_prices = $create_new_TKT = FALSE; |
331 | 331 | |
332 | 332 | //figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session. |
333 | 333 | |
334 | - $starting_tkt_dtt_rows = explode(',',$data['starting_ticket_datetime_rows'][$row]); |
|
335 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row] ); |
|
334 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
335 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
336 | 336 | $dtts_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
337 | 337 | $dtts_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
338 | 338 | |
339 | 339 | // trim inputs to ensure any excess whitespace is removed. |
340 | 340 | $tkt = array_map( |
341 | - function( $ticket_data ) { |
|
342 | - return is_array( $ticket_data ) ? $ticket_data : trim( $ticket_data ); |
|
341 | + function($ticket_data) { |
|
342 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
343 | 343 | }, |
344 | 344 | $tkt |
345 | 345 | ); |
346 | 346 | |
347 | 347 | //note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models. |
348 | 348 | //note incoming ['TKT_price'] value is already in standard notation (via js). |
349 | - $ticket_price = isset( $tkt['TKT_price'] ) ? round ( (float) $tkt['TKT_price'], 3 ) : 0; |
|
349 | + $ticket_price = isset($tkt['TKT_price']) ? round((float) $tkt['TKT_price'], 3) : 0; |
|
350 | 350 | |
351 | 351 | //note incoming base price needs converted from localized value. |
352 | - $base_price = isset( $tkt['TKT_base_price'] ) ? EEH_Money::convert_to_float_from_localized_money( $tkt['TKT_base_price'] ) : 0; |
|
352 | + $base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0; |
|
353 | 353 | //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
354 | 354 | $ticket_price = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price; |
355 | - $base_price_id = isset( $tkt['TKT_base_price_ID'] ) ? $tkt['TKT_base_price_ID'] : 0; |
|
355 | + $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0; |
|
356 | 356 | |
357 | 357 | $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array(); |
358 | 358 | |
359 | 359 | $now = null; |
360 | - if ( empty( $tkt['TKT_start_date'] ) ) { |
|
360 | + if (empty($tkt['TKT_start_date'])) { |
|
361 | 361 | //lets' use now in the set timezone. |
362 | - $now = new DateTime( 'now', new DateTimeZone( $evtobj->get_timezone() ) ); |
|
363 | - $tkt['TKT_start_date'] = $now->format( $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] ); |
|
362 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
363 | + $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'].' '.$this->_date_format_strings['time']); |
|
364 | 364 | } |
365 | 365 | |
366 | - if ( empty( $tkt['TKT_end_date'] ) ) { |
|
366 | + if (empty($tkt['TKT_end_date'])) { |
|
367 | 367 | /** |
368 | 368 | * set the TKT_end_date to the first datetime attached to the ticket. |
369 | 369 | */ |
370 | - $first_dtt = $saved_dtts[reset( $tkt_dtt_rows )]; |
|
371 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time( $this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time'] ); |
|
370 | + $first_dtt = $saved_dtts[reset($tkt_dtt_rows)]; |
|
371 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'].' '.$this->_date_format_string['time']); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | $TKT_values = array( |
375 | - 'TKT_ID' => ! empty( $tkt['TKT_ID'] ) ? $tkt['TKT_ID'] : NULL, |
|
376 | - 'TTM_ID' => ! empty( $tkt['TTM_ID'] ) ? $tkt['TTM_ID'] : 0, |
|
377 | - 'TKT_name' => ! empty( $tkt['TKT_name'] ) ? $tkt['TKT_name'] : '', |
|
378 | - 'TKT_description' => ! empty( $tkt['TKT_description'] ) && $tkt['TKT_description'] != __('You can modify this description', 'event_espresso') ? $tkt['TKT_description'] : '', |
|
375 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : NULL, |
|
376 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
377 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
378 | + 'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description', 'event_espresso') ? $tkt['TKT_description'] : '', |
|
379 | 379 | 'TKT_start_date' => $tkt['TKT_start_date'], |
380 | 380 | 'TKT_end_date' => $tkt['TKT_end_date'], |
381 | - 'TKT_qty' => ! isset( $tkt[ 'TKT_qty' ] ) || $tkt[ 'TKT_qty' ] === '' ? EE_INF : $tkt[ 'TKT_qty' ], |
|
382 | - 'TKT_uses' => ! isset( $tkt[ 'TKT_uses' ] ) || $tkt[ 'TKT_uses' ] === '' ? EE_INF : $tkt['TKT_uses'], |
|
383 | - 'TKT_min' => empty( $tkt['TKT_min'] ) ? 0 : $tkt['TKT_min'], |
|
384 | - 'TKT_max' => empty( $tkt['TKT_max'] ) ? EE_INF : $tkt['TKT_max'], |
|
381 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
382 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
383 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
384 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
385 | 385 | 'TKT_row' => $row, |
386 | - 'TKT_order' => isset( $tkt['TKT_order'] ) ? $tkt['TKT_order'] : 0, |
|
387 | - 'TKT_taxable' => ! empty( $tkt['TKT_taxable'] ) ? 1 : 0, |
|
388 | - 'TKT_required' => ! empty( $tkt['TKT_required'] ) ? 1 : 0, |
|
386 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
387 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
388 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
389 | 389 | 'TKT_price' => $ticket_price |
390 | 390 | ); |
391 | 391 | |
392 | 392 | |
393 | 393 | //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
394 | - if ( isset( $tkt['TKT_is_default'] ) && $tkt['TKT_is_default'] ) { |
|
394 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
395 | 395 | $TKT_values['TKT_ID'] = 0; |
396 | 396 | $TKT_values['TKT_is_default'] = 0; |
397 | 397 | $update_prices = TRUE; |
@@ -403,21 +403,21 @@ discard block |
||
403 | 403 | // but DID have it's items modified. |
404 | 404 | // keep in mind that if the TKT has been sold (and we have changed pricing information), |
405 | 405 | // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
406 | - if ( absint( $TKT_values['TKT_ID'] ) ) { |
|
407 | - $TKT = EE_Registry::instance()->load_model( 'Ticket', array( $timezone ) )->get_one_by_ID( $tkt['TKT_ID'] ); |
|
408 | - if ( $TKT instanceof EE_Ticket ) { |
|
406 | + if (absint($TKT_values['TKT_ID'])) { |
|
407 | + $TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']); |
|
408 | + if ($TKT instanceof EE_Ticket) { |
|
409 | 409 | |
410 | - $TKT = $this->_update_ticket_datetimes( $TKT, $saved_dtts, $dtts_added, $dtts_removed ); |
|
410 | + $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
411 | 411 | // are there any registrations using this ticket ? |
412 | 412 | $tickets_sold = $TKT->count_related( |
413 | 413 | 'Registration', |
414 | - array( array( |
|
415 | - 'STS_ID' => array( 'NOT IN', array( EEM_Registration::status_id_incomplete ) ) |
|
416 | - ) ) |
|
414 | + array(array( |
|
415 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)) |
|
416 | + )) |
|
417 | 417 | ); |
418 | 418 | //set ticket formats |
419 | - $TKT->set_date_format( $this->_date_format_strings['date'] ); |
|
420 | - $TKT->set_time_format( $this->_date_format_strings['time'] ); |
|
419 | + $TKT->set_date_format($this->_date_format_strings['date']); |
|
420 | + $TKT->set_time_format($this->_date_format_strings['time']); |
|
421 | 421 | |
422 | 422 | // let's just check the total price for the existing ticket |
423 | 423 | // and determine if it matches the new total price. |
@@ -427,17 +427,17 @@ discard block |
||
427 | 427 | ? TRUE : FALSE; |
428 | 428 | |
429 | 429 | //set new values |
430 | - foreach ( $TKT_values as $field => $value ) { |
|
431 | - if ( $field === 'TKT_qty' ) { |
|
432 | - $TKT->set_qty( $value ); |
|
430 | + foreach ($TKT_values as $field => $value) { |
|
431 | + if ($field === 'TKT_qty') { |
|
432 | + $TKT->set_qty($value); |
|
433 | 433 | } else { |
434 | - $TKT->set( $field, $value ); |
|
434 | + $TKT->set($field, $value); |
|
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
438 | 438 | //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
439 | - if ( $create_new_TKT ) { |
|
440 | - $new_tkt = $this->_duplicate_ticket( $TKT, $price_rows, $ticket_price, $base_price, $base_price_id ); |
|
439 | + if ($create_new_TKT) { |
|
440 | + $new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price, $base_price_id); |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
@@ -446,12 +446,12 @@ discard block |
||
446 | 446 | $TKT = EE_Ticket::new_instance( |
447 | 447 | $TKT_values, |
448 | 448 | $timezone, |
449 | - array( $this->_date_format_strings[ 'date' ], $this->_date_format_strings[ 'time' ] ) |
|
449 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
450 | 450 | ); |
451 | - if ( $TKT instanceof EE_Ticket ) { |
|
451 | + if ($TKT instanceof EE_Ticket) { |
|
452 | 452 | // make sure ticket has an ID of setting relations won't work |
453 | 453 | $TKT->save(); |
454 | - $TKT = $this->_update_ticket_datetimes( $TKT, $saved_dtts, $dtts_added, $dtts_removed ); |
|
454 | + $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
455 | 455 | $update_prices = TRUE; |
456 | 456 | } |
457 | 457 | } |
@@ -459,38 +459,38 @@ discard block |
||
459 | 459 | //$TKT->save(); |
460 | 460 | |
461 | 461 | //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
462 | - if( $TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date') ) { |
|
463 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date') ); |
|
462 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
463 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
464 | 464 | EE_Registry::instance()->load_helper('DTT_Helper'); |
465 | 465 | $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
466 | 466 | } |
467 | 467 | |
468 | 468 | //let's make sure the base price is handled |
469 | - $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket( array(), $TKT, $update_prices, $base_price, $base_price_id ) : $TKT; |
|
469 | + $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price, $base_price_id) : $TKT; |
|
470 | 470 | |
471 | 471 | //add/update price_modifiers |
472 | - $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket( $price_rows, $TKT, $update_prices ) : $TKT; |
|
472 | + $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT; |
|
473 | 473 | |
474 | 474 | //need to make sue that the TKT_price is accurate after saving the prices. |
475 | 475 | $TKT->ensure_TKT_Price_correct(); |
476 | 476 | |
477 | 477 | //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
478 | - if ( ! defined('DOING_AUTOSAVE' ) ) { |
|
479 | - if ( !empty($tkt['TKT_is_default_selector'] ) ) { |
|
478 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
479 | + if ( ! empty($tkt['TKT_is_default_selector'])) { |
|
480 | 480 | $update_prices = TRUE; |
481 | 481 | $new_default = clone $TKT; |
482 | - $new_default->set( 'TKT_ID', 0 ); |
|
483 | - $new_default->set( 'TKT_is_default', 1 ); |
|
484 | - $new_default->set( 'TKT_row', 1 ); |
|
485 | - $new_default->set( 'TKT_price', $ticket_price ); |
|
482 | + $new_default->set('TKT_ID', 0); |
|
483 | + $new_default->set('TKT_is_default', 1); |
|
484 | + $new_default->set('TKT_row', 1); |
|
485 | + $new_default->set('TKT_price', $ticket_price); |
|
486 | 486 | //remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object) |
487 | 487 | $new_default->_remove_relations('Datetime'); |
488 | 488 | //todo we need to add the current attached prices as new prices to the new default ticket. |
489 | - $new_default = $this->_add_prices_to_ticket( $price_rows, $new_default, $update_prices ); |
|
489 | + $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
490 | 490 | //don't forget the base price! |
491 | - $new_default = $this->_add_prices_to_ticket( array(), $new_default, $update_prices, $base_price, $base_price_id ); |
|
491 | + $new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price, $base_price_id); |
|
492 | 492 | $new_default->save(); |
493 | - do_action( 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default, $row, $TKT, $data ); |
|
493 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default, $row, $TKT, $data); |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
@@ -501,19 +501,19 @@ discard block |
||
501 | 501 | //let's assign any tickets that have been setup to the saved_tickets tracker |
502 | 502 | //save existing TKT |
503 | 503 | $TKT->save(); |
504 | - if ( $create_new_TKT && $new_tkt instanceof EE_Ticket ) { |
|
504 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
505 | 505 | //save new TKT |
506 | 506 | $new_tkt->save(); |
507 | 507 | //add new ticket to array |
508 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
508 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
509 | 509 | |
510 | - do_action( 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data ); |
|
510 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data); |
|
511 | 511 | |
512 | 512 | } else { |
513 | 513 | //add tkt to saved tkts |
514 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
514 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
515 | 515 | |
516 | - do_action( 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data ); |
|
516 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | } |
@@ -523,22 +523,22 @@ discard block |
||
523 | 523 | // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
524 | 524 | // Or a draft event was saved and in the process of editing a ticket is trashed. |
525 | 525 | // No sense in keeping all the related data in the db! |
526 | - $old_tickets = isset( $old_tickets[0] ) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
527 | - $tickets_removed = array_diff( $old_tickets, array_keys($saved_tickets) ); |
|
526 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
527 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
528 | 528 | |
529 | - foreach ( $tickets_removed as $id ) { |
|
530 | - $id = absint( $id ); |
|
529 | + foreach ($tickets_removed as $id) { |
|
530 | + $id = absint($id); |
|
531 | 531 | |
532 | 532 | //get the ticket for this id |
533 | 533 | $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
534 | 534 | |
535 | 535 | //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
536 | - if ( $tkt_to_remove->get('TKT_is_default') ) |
|
536 | + if ($tkt_to_remove->get('TKT_is_default')) |
|
537 | 537 | continue; |
538 | 538 | |
539 | 539 | // if this tkt has any registrations attached so then we just ARCHIVE |
540 | 540 | // because we don't actually permanently delete these tickets. |
541 | - if ( $tkt_to_remove->count_related('Registration') > 0 ) { |
|
541 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
542 | 542 | $tkt_to_remove->delete(); |
543 | 543 | continue; |
544 | 544 | } |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | // (remember this process can ONLY kick off if there are NO tkts_sold) |
548 | 548 | $dtts = $tkt_to_remove->get_many_related('Datetime'); |
549 | 549 | |
550 | - foreach( $dtts as $dtt ) { |
|
550 | + foreach ($dtts as $dtt) { |
|
551 | 551 | $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
552 | 552 | } |
553 | 553 | |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
556 | 556 | $tkt_to_remove->delete_related_permanently('Price'); |
557 | 557 | |
558 | - do_action( 'AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove ); |
|
558 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
559 | 559 | |
560 | 560 | // finally let's delete this ticket |
561 | 561 | // (which should not be blocked at this point b/c we've removed all our relationships) |
@@ -587,39 +587,39 @@ discard block |
||
587 | 587 | // and removing the ticket from datetimes it got removed from. |
588 | 588 | |
589 | 589 | // first let's add datetimes |
590 | - if ( ! empty( $added_datetimes ) && is_array( $added_datetimes ) ) { |
|
591 | - foreach ( $added_datetimes as $row_id ) { |
|
590 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
591 | + foreach ($added_datetimes as $row_id) { |
|
592 | 592 | $row_id = (int) $row_id; |
593 | - if ( isset( $saved_datetimes[ $row_id ] ) && $saved_datetimes[ $row_id ] instanceof EE_Datetime ) { |
|
594 | - $ticket->_add_relation_to( $saved_datetimes[ $row_id ], 'Datetime' ); |
|
593 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
594 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
595 | 595 | // Is this an existing ticket (has an ID) and does it have any sold? |
596 | 596 | // If so, then we need to add that to the DTT sold because this DTT is getting added. |
597 | - if ( $ticket->ID() && $ticket->sold() > 0 ) { |
|
598 | - $saved_datetimes[ $row_id ]->increase_sold( $ticket->sold() ); |
|
599 | - $saved_datetimes[ $row_id ]->save(); |
|
597 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
598 | + $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
599 | + $saved_datetimes[$row_id]->save(); |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | } |
603 | 603 | } |
604 | 604 | // then remove datetimes |
605 | - if ( ! empty( $removed_datetimes ) && is_array( $removed_datetimes ) ) { |
|
606 | - foreach ( $removed_datetimes as $row_id ) { |
|
607 | - $row_id = (int)$row_id; |
|
605 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
606 | + foreach ($removed_datetimes as $row_id) { |
|
607 | + $row_id = (int) $row_id; |
|
608 | 608 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
609 | 609 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
610 | - if ( isset( $saved_datetimes[ $row_id ] ) && $saved_datetimes[ $row_id ] instanceof EE_Datetime ) { |
|
611 | - $ticket->_remove_relation_to( $saved_datetimes[ $row_id ], 'Datetime' ); |
|
610 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
611 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
612 | 612 | // Is this an existing ticket (has an ID) and does it have any sold? |
613 | 613 | // If so, then we need to remove it's sold from the DTT_sold. |
614 | - if ( $ticket->ID() && $ticket->sold() > 0 ) { |
|
615 | - $saved_datetimes[ $row_id ]->decrease_sold( $ticket->sold() ); |
|
616 | - $saved_datetimes[ $row_id ]->save(); |
|
614 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
615 | + $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
616 | + $saved_datetimes[$row_id]->save(); |
|
617 | 617 | } |
618 | 618 | } |
619 | 619 | } |
620 | 620 | } |
621 | 621 | // cap ticket qty by datetime reg limits |
622 | - $ticket->set_qty( min( $ticket->qty(), $ticket->qty( 'reg_limit' ) ) ); |
|
622 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
623 | 623 | return $ticket; |
624 | 624 | } |
625 | 625 | |
@@ -640,39 +640,39 @@ discard block |
||
640 | 640 | EE_Ticket $ticket, |
641 | 641 | $price_rows = array(), |
642 | 642 | $ticket_price = 0, |
643 | - $base_price = 0 , |
|
643 | + $base_price = 0, |
|
644 | 644 | $base_price_id = 0 |
645 | 645 | ) { |
646 | 646 | |
647 | 647 | // create new ticket that's a copy of the existing |
648 | 648 | // except a new id of course (and not archived) |
649 | 649 | // AND has the new TKT_price associated with it. |
650 | - $new_ticket = clone( $ticket ); |
|
651 | - $new_ticket->set( 'TKT_ID', 0 ); |
|
652 | - $new_ticket->set( 'TKT_deleted', 0 ); |
|
653 | - $new_ticket->set( 'TKT_price', $ticket_price ); |
|
654 | - $new_ticket->set( 'TKT_sold', 0 ); |
|
650 | + $new_ticket = clone($ticket); |
|
651 | + $new_ticket->set('TKT_ID', 0); |
|
652 | + $new_ticket->set('TKT_deleted', 0); |
|
653 | + $new_ticket->set('TKT_price', $ticket_price); |
|
654 | + $new_ticket->set('TKT_sold', 0); |
|
655 | 655 | // let's get a new ID for this ticket |
656 | 656 | $new_ticket->save(); |
657 | 657 | // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
658 | - $datetimes_on_existing = $ticket->get_many_related( 'Datetime' ); |
|
658 | + $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
659 | 659 | $new_ticket = $this->_update_ticket_datetimes( |
660 | 660 | $new_ticket, |
661 | 661 | $datetimes_on_existing, |
662 | - array_keys( $datetimes_on_existing ) |
|
662 | + array_keys($datetimes_on_existing) |
|
663 | 663 | ); |
664 | 664 | |
665 | 665 | // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
666 | 666 | // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
667 | 667 | // available. |
668 | - if ( $ticket->sold() > 0 ) { |
|
668 | + if ($ticket->sold() > 0) { |
|
669 | 669 | $new_qty = $ticket->qty() - $ticket->sold(); |
670 | - $new_ticket->set_qty( $new_qty ); |
|
670 | + $new_ticket->set_qty($new_qty); |
|
671 | 671 | } |
672 | 672 | //now we update the prices just for this ticket |
673 | - $new_ticket = $this->_add_prices_to_ticket( $price_rows, $new_ticket, true ); |
|
673 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
674 | 674 | //and we update the base price |
675 | - $new_ticket = $this->_add_prices_to_ticket( array(), $new_ticket, true, $base_price, $base_price_id ); |
|
675 | + $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
676 | 676 | return $new_ticket; |
677 | 677 | } |
678 | 678 | |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
693 | 693 | * @return EE_Ticket |
694 | 694 | */ |
695 | - protected function _add_prices_to_ticket( $prices = array(), EE_Ticket $ticket, $new_prices = FALSE, $base_price = FALSE, $base_price_id = FALSE ) { |
|
695 | + protected function _add_prices_to_ticket($prices = array(), EE_Ticket $ticket, $new_prices = FALSE, $base_price = FALSE, $base_price_id = FALSE) { |
|
696 | 696 | |
697 | 697 | //let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session. |
698 | 698 | $current_prices_on_ticket = $base_price !== FALSE ? $ticket->base_price(TRUE) : $ticket->price_modifiers(); |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | $updated_prices = array(); |
701 | 701 | |
702 | 702 | // if $base_price ! FALSE then updating a base price. |
703 | - if ( $base_price !== FALSE ) { |
|
703 | + if ($base_price !== FALSE) { |
|
704 | 704 | $prices[1] = array( |
705 | 705 | 'PRC_ID' => $new_prices || $base_price_id === 1 ? NULL : $base_price_id, |
706 | 706 | 'PRT_ID' => 1, |
@@ -711,47 +711,47 @@ discard block |
||
711 | 711 | } |
712 | 712 | |
713 | 713 | //possibly need to save tkt |
714 | - if ( ! $ticket->ID() ) |
|
714 | + if ( ! $ticket->ID()) |
|
715 | 715 | $ticket->save(); |
716 | 716 | |
717 | - foreach ( $prices as $row => $prc ) { |
|
718 | - $prt_id = !empty( $prc['PRT_ID'] ) ? $prc['PRT_ID'] : NULL; |
|
719 | - if ( empty($prt_id) ) |
|
717 | + foreach ($prices as $row => $prc) { |
|
718 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : NULL; |
|
719 | + if (empty($prt_id)) |
|
720 | 720 | continue; //prices MUST have a price type id. |
721 | 721 | $PRC_values = array( |
722 | - 'PRC_ID' => !empty( $prc['PRC_ID'] ) ? $prc['PRC_ID'] : NULL, |
|
722 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : NULL, |
|
723 | 723 | 'PRT_ID' => $prt_id, |
724 | - 'PRC_amount' => !empty( $prc['PRC_amount'] ) ? $prc['PRC_amount'] : 0, |
|
725 | - 'PRC_name' => !empty( $prc['PRC_name'] ) ? $prc['PRC_name'] : '', |
|
726 | - 'PRC_desc' => !empty( $prc['PRC_desc'] ) ? $prc['PRC_desc'] : '', |
|
724 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
725 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
726 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
727 | 727 | 'PRC_is_default' => false, //make sure we set PRC_is_default to false for all ticket saves from event_editor |
728 | 728 | 'PRC_order' => $row |
729 | 729 | ); |
730 | - if ( $new_prices || empty( $PRC_values['PRC_ID'] ) ) { |
|
730 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
731 | 731 | $PRC_values['PRC_ID'] = 0; |
732 | - $PRC = EE_Registry::instance()->load_class('Price', array( $PRC_values ), FALSE, FALSE); |
|
732 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), FALSE, FALSE); |
|
733 | 733 | } else { |
734 | - $PRC = EE_Registry::instance()->load_model( 'Price' )->get_one_by_ID( $prc['PRC_ID'] ); |
|
734 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
735 | 735 | //update this price with new values |
736 | - foreach ( $PRC_values as $field => $newprc ) { |
|
737 | - $PRC->set( $field, $newprc ); |
|
736 | + foreach ($PRC_values as $field => $newprc) { |
|
737 | + $PRC->set($field, $newprc); |
|
738 | 738 | } |
739 | 739 | } |
740 | 740 | $PRC->save(); |
741 | 741 | $prcid = $PRC->ID(); |
742 | 742 | $updated_prices[$prcid] = $PRC; |
743 | - $ticket->_add_relation_to( $PRC, 'Price' ); |
|
743 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | //now let's remove any prices that got removed from the ticket |
747 | - if ( !empty ( $current_prices_on_ticket ) ) { |
|
747 | + if ( ! empty ($current_prices_on_ticket)) { |
|
748 | 748 | $current = array_keys($current_prices_on_ticket); |
749 | 749 | $updated = array_keys($updated_prices); |
750 | 750 | $prices_to_remove = array_diff($current, $updated); |
751 | - if ( !empty( $prices_to_remove ) ) { |
|
752 | - foreach ( $prices_to_remove as $prc_id ) { |
|
751 | + if ( ! empty($prices_to_remove)) { |
|
752 | + foreach ($prices_to_remove as $prc_id) { |
|
753 | 753 | $p = $current_prices_on_ticket[$prc_id]; |
754 | - $ticket->_remove_relation_to( $p, 'Price' ); |
|
754 | + $ticket->_remove_relation_to($p, 'Price'); |
|
755 | 755 | |
756 | 756 | //delete permanently the price |
757 | 757 | $p->delete_permanently(); |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | |
765 | 765 | |
766 | 766 | |
767 | - public function autosave_handling( $event_admin_obj ) { |
|
767 | + public function autosave_handling($event_admin_obj) { |
|
768 | 768 | return $event_admin_obj; //doing nothing for the moment. |
769 | 769 | //todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method) |
770 | 770 | |
@@ -798,12 +798,12 @@ discard block |
||
798 | 798 | |
799 | 799 | //default main template args |
800 | 800 | $main_template_args = array( |
801 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab', $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), FALSE, FALSE ), //todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help |
|
801 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab', $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), FALSE, FALSE), //todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help |
|
802 | 802 | 'existing_datetime_ids' => '', |
803 | 803 | 'total_dtt_rows' => 1, |
804 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link('add_new_dtt_info', $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), FALSE, FALSE ), //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
804 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link('add_new_dtt_info', $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), FALSE, FALSE), //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
805 | 805 | 'datetime_rows' => '', |
806 | - 'show_tickets_container' => '',//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
806 | + 'show_tickets_container' => '', //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
807 | 807 | 'ticket_rows' => '', |
808 | 808 | 'existing_ticket_ids' => '', |
809 | 809 | 'total_ticket_rows' => 1, |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | |
814 | 814 | $timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : NULL; |
815 | 815 | |
816 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
816 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
817 | 817 | |
818 | 818 | /** |
819 | 819 | * 1. Start with retrieving Datetimes |
@@ -821,8 +821,8 @@ discard block |
||
821 | 821 | * 3. For each ticket get related prices |
822 | 822 | */ |
823 | 823 | |
824 | - $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone) ); |
|
825 | - $times = $DTM->get_all_event_dates( $evtID ); |
|
824 | + $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
825 | + $times = $DTM->get_all_event_dates($evtID); |
|
826 | 826 | |
827 | 827 | |
828 | 828 | |
@@ -830,31 +830,31 @@ discard block |
||
830 | 830 | |
831 | 831 | /** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */ |
832 | 832 | $dttrow = 1; |
833 | - foreach ( $times as $time ) { |
|
833 | + foreach ($times as $time) { |
|
834 | 834 | $dttid = $time->get('DTT_ID'); |
835 | - $time->set( 'DTT_order', $dttrow ); |
|
835 | + $time->set('DTT_order', $dttrow); |
|
836 | 836 | $existing_datetime_ids[] = $dttid; |
837 | 837 | |
838 | 838 | //tickets attached |
839 | - $related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array( array( 'OR' => array( 'TKT_deleted' => 1, 'TKT_deleted*' => 0 ) ), 'default_where_conditions' => 'none', 'order_by' => array('TKT_order' => 'ASC' ) ) ) : array(); |
|
839 | + $related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array(array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), 'default_where_conditions' => 'none', 'order_by' => array('TKT_order' => 'ASC'))) : array(); |
|
840 | 840 | |
841 | 841 | //if there are no related tickets this is likely a new event OR autodraft |
842 | 842 | // event so we need to generate the default tickets because dtts |
843 | 843 | // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
844 | 844 | // datetime on the event. |
845 | - if ( empty ( $related_tickets ) && count( $times ) < 2 ) { |
|
845 | + if (empty ($related_tickets) && count($times) < 2) { |
|
846 | 846 | $related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
847 | 847 | |
848 | 848 | //this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
849 | 849 | $default_prices = EEM_Price::instance()->get_all_default_prices(); |
850 | 850 | |
851 | - $main_default_ticket = reset( $related_tickets ); |
|
852 | - if ( $main_default_ticket instanceof EE_Ticket ) { |
|
853 | - foreach ( $default_prices as $default_price ) { |
|
854 | - if ( $default_price->is_base_price() ) { |
|
851 | + $main_default_ticket = reset($related_tickets); |
|
852 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
853 | + foreach ($default_prices as $default_price) { |
|
854 | + if ($default_price->is_base_price()) { |
|
855 | 855 | continue; |
856 | 856 | } |
857 | - $main_default_ticket->cache( 'Price', $default_price ); |
|
857 | + $main_default_ticket->cache('Price', $default_price); |
|
858 | 858 | } |
859 | 859 | } |
860 | 860 | } |
@@ -863,11 +863,11 @@ discard block |
||
863 | 863 | //we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information. |
864 | 864 | |
865 | 865 | //loop through and setup the ticket rows and make sure the order is set. |
866 | - foreach ( $related_tickets as $ticket ) { |
|
866 | + foreach ($related_tickets as $ticket) { |
|
867 | 867 | $tktid = $ticket->get('TKT_ID'); |
868 | 868 | $tktrow = $ticket->get('TKT_row'); |
869 | 869 | //we only want unique tickets in our final display!! |
870 | - if ( !in_array( $tktid, $existing_ticket_ids ) ) { |
|
870 | + if ( ! in_array($tktid, $existing_ticket_ids)) { |
|
871 | 871 | $existing_ticket_ids[] = $tktid; |
872 | 872 | $all_tickets[] = $ticket; |
873 | 873 | } |
@@ -876,57 +876,57 @@ discard block |
||
876 | 876 | $datetime_tickets[$dttid][] = $tktrow; |
877 | 877 | |
878 | 878 | //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
879 | - if ( !isset( $ticket_datetimes[$tktid] ) || ! in_array( $dttrow, $ticket_datetimes[$tktid] ) ) |
|
879 | + if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) |
|
880 | 880 | $ticket_datetimes[$tktid][] = $dttrow; |
881 | 881 | } |
882 | 882 | $dttrow++; |
883 | 883 | } |
884 | 884 | |
885 | - $main_template_args['total_ticket_rows'] = count( $existing_ticket_ids ); |
|
886 | - $main_template_args['existing_ticket_ids'] = implode( ',', $existing_ticket_ids ); |
|
887 | - $main_template_args['existing_datetime_ids'] = implode( ',', $existing_datetime_ids ); |
|
885 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
886 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
887 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
888 | 888 | |
889 | 889 | //sort $all_tickets by order |
890 | - usort( $all_tickets, function( $a, $b ) { |
|
890 | + usort($all_tickets, function($a, $b) { |
|
891 | 891 | $a_order = (int) $a->get('TKT_order'); |
892 | 892 | $b_order = (int) $b->get('TKT_order'); |
893 | - if ( $a_order == $b_order ) { |
|
893 | + if ($a_order == $b_order) { |
|
894 | 894 | return 0; |
895 | 895 | } |
896 | - return ( $a_order < $b_order ) ? -1 : 1; |
|
896 | + return ($a_order < $b_order) ? -1 : 1; |
|
897 | 897 | }); |
898 | 898 | |
899 | 899 | //k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again. |
900 | 900 | $dttrow = 1; |
901 | - foreach ( $times as $time ) { |
|
902 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( $dttrow, $time, $datetime_tickets, $all_tickets, FALSE, $times ); |
|
901 | + foreach ($times as $time) { |
|
902 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets, $all_tickets, FALSE, $times); |
|
903 | 903 | $dttrow++; |
904 | 904 | } |
905 | 905 | |
906 | 906 | //then loop through all tickets for the ticket rows. |
907 | 907 | $tktrow = 1; |
908 | - foreach ( $all_tickets as $ticket ) { |
|
909 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( $tktrow, $ticket, $ticket_datetimes, $times, FALSE, $all_tickets ); |
|
908 | + foreach ($all_tickets as $ticket) { |
|
909 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times, FALSE, $all_tickets); |
|
910 | 910 | $tktrow++; |
911 | 911 | } |
912 | 912 | |
913 | 913 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets); |
914 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'; |
|
915 | - EEH_Template::display_template( $template, $main_template_args ); |
|
914 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'; |
|
915 | + EEH_Template::display_template($template, $main_template_args); |
|
916 | 916 | return; |
917 | 917 | } |
918 | 918 | |
919 | 919 | |
920 | 920 | |
921 | - protected function _get_datetime_row( $dttrow, EE_Datetime $dtt, $datetime_tickets, $all_tickets, $default = FALSE, $all_dtts = array() ) { |
|
921 | + protected function _get_datetime_row($dttrow, EE_Datetime $dtt, $datetime_tickets, $all_tickets, $default = FALSE, $all_dtts = array()) { |
|
922 | 922 | |
923 | 923 | $dtt_display_template_args = array( |
924 | - 'dtt_edit_row' => $this->_get_dtt_edit_row( $dttrow, $dtt, $default, $all_dtts ), |
|
925 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( $dttrow, $dtt, $datetime_tickets, $all_tickets, $default ), |
|
924 | + 'dtt_edit_row' => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts), |
|
925 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default), |
|
926 | 926 | 'dtt_row' => $default ? 'DTTNUM' : $dttrow |
927 | 927 | ); |
928 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php'; |
|
929 | - return EEH_Template::display_template( $template, $dtt_display_template_args, TRUE); |
|
928 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php'; |
|
929 | + return EEH_Template::display_template($template, $dtt_display_template_args, TRUE); |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | |
@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | * |
945 | 945 | * @return string Generated edit row. |
946 | 946 | */ |
947 | - protected function _get_dtt_edit_row( $dttrow, $dtt, $default, $all_dtts ) { |
|
947 | + protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts) { |
|
948 | 948 | |
949 | 949 | // if the incomign $dtt object is NOT an instance of EE_Datetime then force default to true. |
950 | 950 | $default = ! $dtt instanceof EE_Datetime ? true : false; |
@@ -952,30 +952,30 @@ discard block |
||
952 | 952 | $template_args = array( |
953 | 953 | 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
954 | 954 | 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
955 | - 'edit_dtt_expanded' => '',//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing', |
|
955 | + 'edit_dtt_expanded' => '', //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing', |
|
956 | 956 | 'DTT_ID' => $default ? '' : $dtt->ID(), |
957 | 957 | 'DTT_name' => $default ? '' : $dtt->name(), |
958 | 958 | 'DTT_description' => $default ? '' : $dtt->description(), |
959 | - 'DTT_EVT_start' => $default ? '' : $dtt->start_date( $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] ), |
|
960 | - 'DTT_EVT_end' => $default ? '' : $dtt->end_date( $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] ), |
|
961 | - 'DTT_reg_limit' => $default ? '' : $dtt->get_pretty('DTT_reg_limit','input'), |
|
959 | + 'DTT_EVT_start' => $default ? '' : $dtt->start_date($this->_date_format_strings['date'].' '.$this->_date_format_strings['time']), |
|
960 | + 'DTT_EVT_end' => $default ? '' : $dtt->end_date($this->_date_format_strings['date'].' '.$this->_date_format_strings['time']), |
|
961 | + 'DTT_reg_limit' => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'), |
|
962 | 962 | 'DTT_order' => $default ? 'DTTNUM' : $dttrow, |
963 | 963 | 'dtt_sold' => $default ? '0' : $dtt->get('DTT_sold'), |
964 | - 'clone_icon' => !empty( $dtt ) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable', |
|
965 | - 'trash_icon' => !empty( $dtt ) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable' |
|
964 | + 'clone_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable', |
|
965 | + 'trash_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable' |
|
966 | 966 | ); |
967 | 967 | |
968 | - $template_args['show_trash'] = count( $all_dtts ) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
968 | + $template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
969 | 969 | |
970 | 970 | //allow filtering of template args at this point. |
971 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event ); |
|
971 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event); |
|
972 | 972 | |
973 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php'; |
|
974 | - return EEH_Template::display_template( $template, $template_args, TRUE ); |
|
973 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php'; |
|
974 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
975 | 975 | } |
976 | 976 | |
977 | 977 | |
978 | - protected function _get_dtt_attached_tickets_row( $dttrow, $dtt, $datetime_tickets, $all_tickets, $default ) { |
|
978 | + protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default) { |
|
979 | 979 | |
980 | 980 | $template_args = array( |
981 | 981 | 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
@@ -983,47 +983,47 @@ discard block |
||
983 | 983 | 'DTT_description' => $default ? '' : $dtt->description(), |
984 | 984 | 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
985 | 985 | 'show_tickets_row' => ' style="display:none;"', //$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '', |
986 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime', $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), FALSE, FALSE ), //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
986 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime', $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), FALSE, FALSE), //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
987 | 987 | 'DTT_ID' => $default ? '' : $dtt->ID() |
988 | 988 | ); |
989 | 989 | |
990 | 990 | //need to setup the list items (but only if this isnt' a default skeleton setup) |
991 | - if ( !$default ) { |
|
991 | + if ( ! $default) { |
|
992 | 992 | $tktrow = 1; |
993 | - foreach ( $all_tickets as $ticket ) { |
|
994 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default ); |
|
993 | + foreach ($all_tickets as $ticket) { |
|
994 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default); |
|
995 | 995 | $tktrow++; |
996 | 996 | } |
997 | 997 | } |
998 | 998 | |
999 | 999 | //filter template args at this point |
1000 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event ); |
|
1000 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event); |
|
1001 | 1001 | |
1002 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php'; |
|
1003 | - return EEH_Template::display_template( $template, $template_args, TRUE ); |
|
1002 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php'; |
|
1003 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | |
1007 | 1007 | |
1008 | - protected function _get_datetime_tickets_list_item( $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default ) { |
|
1009 | - $tktid = !empty( $ticket ) ? $ticket->ID() : 0; |
|
1010 | - $dtt_tkts = $dtt instanceof EE_Datetime && isset( $datetime_tickets[$dtt->ID()] ) ? $datetime_tickets[$dtt->ID()] : array(); |
|
1008 | + protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default) { |
|
1009 | + $tktid = ! empty($ticket) ? $ticket->ID() : 0; |
|
1010 | + $dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array(); |
|
1011 | 1011 | |
1012 | - $displayrow = !empty( $ticket ) ? $ticket->get('TKT_row') : 0; |
|
1012 | + $displayrow = ! empty($ticket) ? $ticket->get('TKT_row') : 0; |
|
1013 | 1013 | $template_args = array( |
1014 | 1014 | 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
1015 | - 'tkt_row' => $default && empty( $ticket ) ? 'TICKETNUM' : $tktrow, |
|
1015 | + 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
|
1016 | 1016 | 'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '', |
1017 | 1017 | 'ticket_selected' => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '', |
1018 | - 'TKT_name' => $default && empty( $ticket ) ? 'TKTNAME' : $ticket->get('TKT_name'), |
|
1019 | - 'tkt_status_class' => ( $default && empty( $ticket ) ) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(), |
|
1018 | + 'TKT_name' => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'), |
|
1019 | + 'tkt_status_class' => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-'.EE_Ticket::onsale : ' tkt-status-'.$ticket->ticket_status(), |
|
1020 | 1020 | ); |
1021 | 1021 | |
1022 | 1022 | //filter template args |
1023 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event ); |
|
1023 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event); |
|
1024 | 1024 | |
1025 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php'; |
|
1026 | - return EEH_Template::display_template( $template, $template_args, TRUE ); |
|
1025 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php'; |
|
1026 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | |
@@ -1045,37 +1045,37 @@ discard block |
||
1045 | 1045 | * |
1046 | 1046 | * @return [type] [description] |
1047 | 1047 | */ |
1048 | - protected function _get_ticket_row( $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default = FALSE, $all_tickets = array() ) { |
|
1048 | + protected function _get_ticket_row($tktrow, $ticket, $ticket_datetimes, $all_dtts, $default = FALSE, $all_tickets = array()) { |
|
1049 | 1049 | |
1050 | 1050 | //if $ticket is not an instance of EE_Ticket then force default to true. |
1051 | - $default = ! $ticket instanceof EE_Ticket ? true : false; |
|
1051 | + $default = ! $ticket instanceof EE_Ticket ? true : false; |
|
1052 | 1052 | |
1053 | - $prices = ! empty( $ticket ) && ! $default ? $ticket->get_many_related('Price', array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC') ) ) : array(); |
|
1053 | + $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
1054 | 1054 | |
1055 | 1055 | //if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on |
1056 | 1056 | //the object. This is done by not including any query_params. |
1057 | - if ( $ticket instanceof EE_Ticket && $ticket->is_default() && ( count( $prices ) === 1 || empty( $prices ) ) ) { |
|
1058 | - $prices = $ticket->get_many_related( 'Price' ); |
|
1057 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1058 | + $prices = $ticket->get_many_related('Price'); |
|
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | // check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket). This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
1062 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default') ) ? TRUE : FALSE; |
|
1062 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? TRUE : FALSE; |
|
1063 | 1063 | |
1064 | - $tkt_dtts = $ticket instanceof EE_Ticket && isset( $ticket_datetimes[$ticket->ID()] ) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
1064 | + $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
1065 | 1065 | |
1066 | 1066 | $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
1067 | - $base_price = $default ? NULL : $ticket->base_price(); |
|
1067 | + $base_price = $default ? NULL : $ticket->base_price(); |
|
1068 | 1068 | $count_price_mods = EEM_Price::instance()->get_all_default_prices(TRUE); |
1069 | 1069 | |
1070 | 1070 | //breaking out complicated condition for ticket_status |
1071 | - if ( $default ) { |
|
1072 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1071 | + if ($default) { |
|
1072 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
1073 | 1073 | } else { |
1074 | - $ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(); |
|
1074 | + $ticket_status_class = $ticket->is_default() ? ' tkt-status-'.EE_Ticket::onsale : ' tkt-status-'.$ticket->ticket_status(); |
|
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | //breaking out complicated condition for TKT_taxable |
1078 | - if ( $default ) { |
|
1078 | + if ($default) { |
|
1079 | 1079 | $TKT_taxable = ''; |
1080 | 1080 | } else { |
1081 | 1081 | $TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : ''; |
@@ -1090,19 +1090,19 @@ discard block |
||
1090 | 1090 | 'edit_tkt_expanded' => '', |
1091 | 1091 | 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
1092 | 1092 | 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
1093 | - 'TKT_start_date' => $default ? '' : $ticket->get_date('TKT_start_date', $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] ), |
|
1094 | - 'TKT_end_date' => $default ? '' : $ticket->get_date('TKT_end_date', $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] ), |
|
1095 | - 'TKT_status' => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : $ticket->is_default() ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence') : $ticket->ticket_status(TRUE), |
|
1093 | + 'TKT_start_date' => $default ? '' : $ticket->get_date('TKT_start_date', $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']), |
|
1094 | + 'TKT_end_date' => $default ? '' : $ticket->get_date('TKT_end_date', $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']), |
|
1095 | + 'TKT_status' => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : $ticket->ticket_status(TRUE), |
|
1096 | 1096 | 'TKT_price' => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(), FALSE, FALSE), |
1097 | 1097 | 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
1098 | 1098 | 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
1099 | - 'TKT_qty' => $default ? '' : $ticket->get_pretty('TKT_qty','symbol'), |
|
1100 | - 'TKT_qty_for_input'=> $default ? '' : $ticket->get_pretty('TKT_qty','input'), |
|
1101 | - 'TKT_uses' => $default ? '' : $ticket->get_pretty('TKT_uses','input'), |
|
1102 | - 'TKT_min' => $default ? '' : ( $ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min') ), |
|
1103 | - 'TKT_max' => $default ? '' : $ticket->get_pretty('TKT_max','input'), |
|
1099 | + 'TKT_qty' => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1100 | + 'TKT_qty_for_input'=> $default ? '' : $ticket->get_pretty('TKT_qty', 'input'), |
|
1101 | + 'TKT_uses' => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'), |
|
1102 | + 'TKT_min' => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')), |
|
1103 | + 'TKT_max' => $default ? '' : $ticket->get_pretty('TKT_max', 'input'), |
|
1104 | 1104 | 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
1105 | - 'TKT_registrations' => $default ? 0 : $ticket->count_registrations( array( array( 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) ) ) ), |
|
1105 | + 'TKT_registrations' => $default ? 0 : $ticket->count_registrations(array(array('STS_ID' => array('!=', EEM_Registration::status_id_incomplete)))), |
|
1106 | 1106 | 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
1107 | 1107 | 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
1108 | 1108 | 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
@@ -1111,99 +1111,99 @@ discard block |
||
1111 | 1111 | 'ticket_price_rows' => '', |
1112 | 1112 | 'TKT_base_price' => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount', 'localized_float'), |
1113 | 1113 | 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
1114 | - 'show_price_modifier' => count($prices) > 1 || ( $default && $count_price_mods > 0 ) ? '' : ' style="display:none;"', |
|
1115 | - 'show_price_mod_button' => count($prices) > 1 || ( $default && $count_price_mods > 0 ) || ( !$default && $ticket->get('TKT_deleted') ) ? ' style="display:none;"' : '', |
|
1114 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"', |
|
1115 | + 'show_price_mod_button' => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '', |
|
1116 | 1116 | 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
1117 | 1117 | 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
1118 | 1118 | 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts), |
1119 | 1119 | 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_dtts), |
1120 | - 'existing_ticket_price_ids' => $default, '', implode(',', array_keys( $prices) ), |
|
1120 | + 'existing_ticket_price_ids' => $default, '', implode(',', array_keys($prices)), |
|
1121 | 1121 | 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
1122 | 1122 | 'TKT_taxable' => $TKT_taxable, |
1123 | 1123 | 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"', |
1124 | 1124 | 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
1125 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency($ticket_subtotal, FALSE, FALSE ), |
|
1125 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency($ticket_subtotal, FALSE, FALSE), |
|
1126 | 1126 | 'TKT_subtotal_amount' => $ticket_subtotal, |
1127 | - 'tax_rows' => $this->_get_tax_rows( $tktrow, $ticket ), |
|
1128 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? TRUE: FALSE, |
|
1127 | + 'tax_rows' => $this->_get_tax_rows($tktrow, $ticket), |
|
1128 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? TRUE : FALSE, |
|
1129 | 1129 | 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '', |
1130 | 1130 | 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable', |
1131 | 1131 | 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable' |
1132 | 1132 | ); |
1133 | 1133 | |
1134 | - $template_args['trash_hidden'] = count( $all_tickets ) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
1134 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
1135 | 1135 | |
1136 | 1136 | //handle rows that should NOT be empty |
1137 | - if ( empty( $template_args['TKT_start_date'] ) ) { |
|
1137 | + if (empty($template_args['TKT_start_date'])) { |
|
1138 | 1138 | //if empty then the start date will be now. |
1139 | - $template_args['TKT_start_date'] = date( $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] , current_time('timestamp')); |
|
1140 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1139 | + $template_args['TKT_start_date'] = date($this->_date_format_strings['date'].' '.$this->_date_format_strings['time'], current_time('timestamp')); |
|
1140 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | - if ( empty( $template_args['TKT_end_date'] ) ) { |
|
1143 | + if (empty($template_args['TKT_end_date'])) { |
|
1144 | 1144 | |
1145 | 1145 | //get the earliest datetime (if present); |
1146 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime', array('order_by'=> array('DTT_EVT_start' => 'ASC' ) ) ) : NULL; |
|
1146 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime', array('order_by'=> array('DTT_EVT_start' => 'ASC'))) : NULL; |
|
1147 | 1147 | |
1148 | - if ( !empty( $earliest_dtt ) ) { |
|
1149 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] ); |
|
1148 | + if ( ! empty($earliest_dtt)) { |
|
1149 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']); |
|
1150 | 1150 | } else { |
1151 | 1151 | //default so let's just use what's been set for the default date-time which is 30 days from now. |
1152 | - $template_args['TKT_end_date'] = date( $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'] , mktime(24, 0, 0, date("m"), date("d") + 29, date("Y") ) ); |
|
1152 | + $template_args['TKT_end_date'] = date($this->_date_format_strings['date'].' '.$this->_date_format_strings['time'], mktime(24, 0, 0, date("m"), date("d") + 29, date("Y"))); |
|
1153 | 1153 | } |
1154 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1154 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1155 | 1155 | } |
1156 | 1156 | |
1157 | 1157 | //generate ticket_datetime items |
1158 | - if ( ! $default ) { |
|
1158 | + if ( ! $default) { |
|
1159 | 1159 | $dttrow = 1; |
1160 | - foreach ( $all_dtts as $dtt ) { |
|
1161 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default ); |
|
1160 | + foreach ($all_dtts as $dtt) { |
|
1161 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default); |
|
1162 | 1162 | $dttrow++; |
1163 | 1163 | } |
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | $prcrow = 1; |
1167 | - foreach ( $prices as $price ) { |
|
1168 | - if ( $price->is_base_price() ) { |
|
1167 | + foreach ($prices as $price) { |
|
1168 | + if ($price->is_base_price()) { |
|
1169 | 1169 | $prcrow++; |
1170 | 1170 | continue; |
1171 | 1171 | } |
1172 | - $show_trash = ( count( $prices ) > 1 && $prcrow === 1 ) || count( $prices ) === 1 ? FALSE : TRUE; |
|
1173 | - $show_create = count( $prices ) > 1 && count( $prices ) !== $prcrow ? FALSE : TRUE; |
|
1174 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create ); |
|
1172 | + $show_trash = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? FALSE : TRUE; |
|
1173 | + $show_create = count($prices) > 1 && count($prices) !== $prcrow ? FALSE : TRUE; |
|
1174 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create); |
|
1175 | 1175 | $prcrow++; |
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | //filter $template_args |
1179 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets, $this->_is_creating_event ); |
|
1179 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets, $this->_is_creating_event); |
|
1180 | 1180 | |
1181 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php'; |
|
1182 | - return EEH_Template::display_template( $template, $template_args, TRUE ); |
|
1181 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php'; |
|
1182 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1183 | 1183 | } |
1184 | 1184 | |
1185 | 1185 | |
1186 | 1186 | |
1187 | 1187 | |
1188 | 1188 | |
1189 | - protected function _get_tax_rows( $tktrow, $ticket ) { |
|
1189 | + protected function _get_tax_rows($tktrow, $ticket) { |
|
1190 | 1190 | $tax_rows = ''; |
1191 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php'; |
|
1191 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php'; |
|
1192 | 1192 | $template_args = array(); |
1193 | - $taxes = empty( $ticket ) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1194 | - foreach ( $taxes as $tax ) { |
|
1195 | - $tax_added = $this->_get_tax_added( $tax, $ticket ); |
|
1193 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1194 | + foreach ($taxes as $tax) { |
|
1195 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1196 | 1196 | $template_args = array( |
1197 | - 'display_tax' => !empty( $ticket ) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"', |
|
1197 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"', |
|
1198 | 1198 | 'tax_id' => $tax->ID(), |
1199 | 1199 | 'tkt_row' => $tktrow, |
1200 | 1200 | 'tax_label' => $tax->get('PRC_name'), |
1201 | 1201 | 'tax_added' => $tax_added, |
1202 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, FALSE, FALSE ), |
|
1202 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, FALSE, FALSE), |
|
1203 | 1203 | 'tax_amount' => $tax->get('PRC_amount') |
1204 | 1204 | ); |
1205 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', $template_args, $tktrow, $ticket, $this->_is_creating_event ); |
|
1206 | - $tax_rows .= EEH_Template::display_template( $template, $template_args, TRUE ); |
|
1205 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', $template_args, $tktrow, $ticket, $this->_is_creating_event); |
|
1206 | + $tax_rows .= EEH_Template::display_template($template, $template_args, TRUE); |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | |
@@ -1211,81 +1211,81 @@ discard block |
||
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | |
1214 | - protected function _get_tax_added( EE_Price $tax, $ticket ) { |
|
1215 | - $subtotal = empty( $ticket ) ? 0 : $ticket->get_ticket_subtotal(); |
|
1214 | + protected function _get_tax_added(EE_Price $tax, $ticket) { |
|
1215 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1216 | 1216 | return $subtotal * $tax->get('PRC_amount') / 100; |
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | |
1220 | 1220 | |
1221 | 1221 | |
1222 | - protected function _get_ticket_price_row( $tktrow, $prcrow, $price, $default, $ticket, $show_trash = TRUE, $show_create = TRUE ) { |
|
1223 | - $send_disabled = !empty( $ticket ) && $ticket->get('TKT_deleted') ? TRUE : FALSE; |
|
1222 | + protected function _get_ticket_price_row($tktrow, $prcrow, $price, $default, $ticket, $show_trash = TRUE, $show_create = TRUE) { |
|
1223 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? TRUE : FALSE; |
|
1224 | 1224 | $template_args = array( |
1225 | 1225 | 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
1226 | 1226 | 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
1227 | 1227 | 'edit_prices_name' => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices', |
1228 | - 'price_type_selector' => $default && empty( $price ) ? $this->_get_base_price_template( $tktrow, $prcrow, $price, $default ) : $this->_get_price_type_selector( $tktrow, $prcrow, $price, $default, $send_disabled ), |
|
1228 | + 'price_type_selector' => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow, $price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled), |
|
1229 | 1229 | 'PRC_ID' => $default && empty($price) ? 0 : $price->ID(), |
1230 | 1230 | 'PRC_is_default' => $default && empty($price) ? 0 : $price->get('PRC_is_default'), |
1231 | 1231 | 'PRC_name' => $default && empty($price) ? '' : $price->get('PRC_name'), |
1232 | 1232 | 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
1233 | 1233 | 'show_plus_or_minus' => $default && empty($price) ? '' : ' style="display:none;"', |
1234 | - 'show_plus' => $default && empty( $price ) ? ' style="display:none;"' : ( $price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''), |
|
1235 | - 'show_minus' => $default && empty( $price ) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'), |
|
1236 | - 'show_currency_symbol' => $default && empty( $price ) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : '' ), |
|
1237 | - 'PRC_amount' => $default && empty( $price ) ? 0 : $price->get_pretty('PRC_amount', 'localized_float'), |
|
1238 | - 'show_percentage' => $default && empty( $price ) ? ' style="display:none;"' : ( $price->is_percent() ? '' : ' style="display:none;"' ), |
|
1234 | + 'show_plus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''), |
|
1235 | + 'show_minus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'), |
|
1236 | + 'show_currency_symbol' => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''), |
|
1237 | + 'PRC_amount' => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount', 'localized_float'), |
|
1238 | + 'show_percentage' => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'), |
|
1239 | 1239 | 'show_trash_icon' => $show_trash ? '' : ' style="display:none;"', |
1240 | 1240 | 'show_create_button' => $show_create ? '' : ' style="display:none;"', |
1241 | - 'PRC_desc' => $default && empty( $price ) ? '' : $price->get('PRC_desc'), |
|
1242 | - 'disabled' => !empty( $ticket ) && $ticket->get('TKT_deleted') ? TRUE : FALSE |
|
1241 | + 'PRC_desc' => $default && empty($price) ? '' : $price->get('PRC_desc'), |
|
1242 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted') ? TRUE : FALSE |
|
1243 | 1243 | ); |
1244 | 1244 | |
1245 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create, $this->_is_creating_event ); |
|
1245 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create, $this->_is_creating_event); |
|
1246 | 1246 | |
1247 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php'; |
|
1248 | - return EEH_Template::display_template( $template, $template_args, TRUE ); |
|
1247 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php'; |
|
1248 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1249 | 1249 | } |
1250 | 1250 | |
1251 | 1251 | |
1252 | - protected function _get_price_type_selector( $tktrow, $prcrow, $price, $default, $disabled = FALSE ) { |
|
1253 | - if ( $price->is_base_price() ) { |
|
1254 | - return $this->_get_base_price_template( $tktrow, $prcrow, $price, $default ); |
|
1252 | + protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = FALSE) { |
|
1253 | + if ($price->is_base_price()) { |
|
1254 | + return $this->_get_base_price_template($tktrow, $prcrow, $price, $default); |
|
1255 | 1255 | } else { |
1256 | - return $this->_get_price_modifier_template( $tktrow, $prcrow, $price, $default, $disabled ); |
|
1256 | + return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled); |
|
1257 | 1257 | } |
1258 | 1258 | |
1259 | 1259 | } |
1260 | 1260 | |
1261 | 1261 | |
1262 | - protected function _get_base_price_template( $tktrow, $prcrow, $price, $default ) { |
|
1262 | + protected function _get_base_price_template($tktrow, $prcrow, $price, $default) { |
|
1263 | 1263 | $template_args = array( |
1264 | 1264 | 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
1265 | - 'PRC_order' => $default && empty( $price ) ? 'PRICENUM' : $prcrow, |
|
1266 | - 'PRT_ID' => $default && empty( $price ) ? 1 : $price->get('PRT_ID'), |
|
1265 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
1266 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1267 | 1267 | 'PRT_name' => __('Price', 'event_espresso'), |
1268 | 1268 | 'price_selected_operator' => '+', |
1269 | 1269 | 'price_selected_is_percent' => 0 |
1270 | 1270 | ); |
1271 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php'; |
|
1271 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php'; |
|
1272 | 1272 | |
1273 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event ); |
|
1273 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event); |
|
1274 | 1274 | |
1275 | - return EEH_Template::display_template( $template, $template_args, TRUE ); |
|
1275 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1276 | 1276 | } |
1277 | 1277 | |
1278 | 1278 | |
1279 | 1279 | |
1280 | - protected function _get_price_modifier_template( $tktrow, $prcrow, $price, $default, $disabled = FALSE ) { |
|
1281 | - $select_name = $default && empty( $price ) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]'; |
|
1282 | - $price_types = EE_Registry::instance()->load_model('Price_Type')->get_all(array( array('OR' => array('PBT_ID' => '2', 'PBT_ID*' => '3' ) ) ) ); |
|
1283 | - $price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php'; |
|
1284 | - $all_price_types = $default && empty( $price ) ? array(array('id' => 0, 'text' => __('Select Modifier', 'event_espresso')) ) : array(); |
|
1285 | - $selected_price_type_id = $default && empty( $price ) ? 0 : $price->type(); |
|
1280 | + protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = FALSE) { |
|
1281 | + $select_name = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices['.$tktrow.']['.$prcrow.'][PRT_ID]'; |
|
1282 | + $price_types = EE_Registry::instance()->load_model('Price_Type')->get_all(array(array('OR' => array('PBT_ID' => '2', 'PBT_ID*' => '3')))); |
|
1283 | + $price_option_span_template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php'; |
|
1284 | + $all_price_types = $default && empty($price) ? array(array('id' => 0, 'text' => __('Select Modifier', 'event_espresso'))) : array(); |
|
1285 | + $selected_price_type_id = $default && empty($price) ? 0 : $price->type(); |
|
1286 | 1286 | $price_option_spans = ''; |
1287 | 1287 | //setup pricetypes for selector |
1288 | - foreach ( $price_types as $price_type ) { |
|
1288 | + foreach ($price_types as $price_type) { |
|
1289 | 1289 | $all_price_types[] = array( |
1290 | 1290 | 'id' => $price_type->ID(), |
1291 | 1291 | 'text' => $price_type->get('PRT_name'), |
@@ -1297,50 +1297,50 @@ discard block |
||
1297 | 1297 | 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
1298 | 1298 | 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0 |
1299 | 1299 | ); |
1300 | - $price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, TRUE ); |
|
1300 | + $price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, TRUE); |
|
1301 | 1301 | } |
1302 | 1302 | |
1303 | - $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"'; |
|
1303 | + $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"'; |
|
1304 | 1304 | $main_name = $select_name; |
1305 | - $select_name = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name; |
|
1305 | + $select_name = $disabled ? 'archive_price['.$tktrow.']['.$prcrow.'][PRT_ID]' : $main_name; |
|
1306 | 1306 | |
1307 | 1307 | $template_args = array( |
1308 | 1308 | 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
1309 | - 'PRC_order' => $default && empty( $price ) ? 'PRICENUM' : $prcrow, |
|
1310 | - 'price_modifier_selector' => EEH_Form_Fields::select_input( $select_name, $all_price_types, $selected_price_type_id, $select_params, 'edit-price-PRT_ID' ), |
|
1309 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
1310 | + 'price_modifier_selector' => EEH_Form_Fields::select_input($select_name, $all_price_types, $selected_price_type_id, $select_params, 'edit-price-PRT_ID'), |
|
1311 | 1311 | 'main_name' => $main_name, |
1312 | 1312 | 'selected_price_type_id' => $selected_price_type_id, |
1313 | 1313 | 'price_option_spans' => $price_option_spans, |
1314 | - 'price_selected_operator' => $default && empty( $price ) ? '' : ( $price->is_discount() ? '-' : '+' ), |
|
1315 | - 'price_selected_is_percent' => $default && empty( $price ) ? '' : ( $price->is_percent() ? 1 : 0 ), |
|
1314 | + 'price_selected_operator' => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'), |
|
1315 | + 'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0), |
|
1316 | 1316 | 'disabled' => $disabled |
1317 | 1317 | ); |
1318 | 1318 | |
1319 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event ); |
|
1319 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event); |
|
1320 | 1320 | |
1321 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php'; |
|
1321 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php'; |
|
1322 | 1322 | |
1323 | - return EEH_Template::display_template( $template, $template_args, TRUE ); |
|
1323 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | |
1327 | 1327 | |
1328 | - protected function _get_ticket_datetime_list_item( $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default ) { |
|
1329 | - $dttid = !empty($dtt) ? $dtt->ID() : 0; |
|
1330 | - $displayrow = !empty($dtt) ? $dtt->get('DTT_order') : 0; |
|
1331 | - $tkt_dtts = $ticket instanceof EE_Ticket && isset( $ticket_datetimes[$ticket->ID()] ) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
1328 | + protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default) { |
|
1329 | + $dttid = ! empty($dtt) ? $dtt->ID() : 0; |
|
1330 | + $displayrow = ! empty($dtt) ? $dtt->get('DTT_order') : 0; |
|
1331 | + $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
1332 | 1332 | $template_args = array( |
1333 | - 'dtt_row' => $default && empty( $dtt ) ? 'DTTNUM' : $dttrow, |
|
1333 | + 'dtt_row' => $default && empty($dtt) ? 'DTTNUM' : $dttrow, |
|
1334 | 1334 | 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
1335 | - 'ticket_datetime_selected' => in_array( $displayrow, $tkt_dtts ) ? ' ticket-selected' : '', |
|
1336 | - 'ticket_datetime_checked' => in_array( $displayrow, $tkt_dtts ) ? ' checked="checked"' : '', |
|
1337 | - 'DTT_name' => $default && empty( $dtt ) ? 'DTTNAME' : $dtt->get_dtt_display_name( TRUE ), |
|
1335 | + 'ticket_datetime_selected' => in_array($displayrow, $tkt_dtts) ? ' ticket-selected' : '', |
|
1336 | + 'ticket_datetime_checked' => in_array($displayrow, $tkt_dtts) ? ' checked="checked"' : '', |
|
1337 | + 'DTT_name' => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(TRUE), |
|
1338 | 1338 | 'tkt_status_class' => '', |
1339 | 1339 | ); |
1340 | 1340 | |
1341 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event ); |
|
1342 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php'; |
|
1343 | - return EEH_Template::display_template( $template, $template_args, TRUE ); |
|
1341 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event); |
|
1342 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php'; |
|
1343 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1344 | 1344 | } |
1345 | 1345 | |
1346 | 1346 | |
@@ -1348,53 +1348,53 @@ discard block |
||
1348 | 1348 | protected function _get_ticket_js_structure($all_dtts, $all_tickets) { |
1349 | 1349 | $template_args = array( |
1350 | 1350 | 'default_datetime_edit_row' => $this->_get_dtt_edit_row('DTTNUM', NULL, TRUE, $all_dtts), |
1351 | - 'default_ticket_row' => $this->_get_ticket_row( 'TICKETNUM', NULL, array(), array(), TRUE), |
|
1352 | - 'default_price_row' => $this->_get_ticket_price_row( 'TICKETNUM', 'PRICENUM', NULL, TRUE, NULL ), |
|
1351 | + 'default_ticket_row' => $this->_get_ticket_row('TICKETNUM', NULL, array(), array(), TRUE), |
|
1352 | + 'default_price_row' => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', NULL, TRUE, NULL), |
|
1353 | 1353 | 'default_price_rows' => '', |
1354 | 1354 | 'default_base_price_amount' => 0, |
1355 | 1355 | 'default_base_price_name' => '', |
1356 | 1356 | 'default_base_price_description' => '', |
1357 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( 'TICKETNUM', 'PRICENUM', NULL, TRUE ), |
|
1358 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( 'DTTNUM', NULL, array(), array(), TRUE ), |
|
1357 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM', NULL, TRUE), |
|
1358 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row('DTTNUM', NULL, array(), array(), TRUE), |
|
1359 | 1359 | 'existing_available_datetime_tickets_list' => '', |
1360 | 1360 | 'existing_available_ticket_datetimes_list' => '', |
1361 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( 'DTTNUM', 'TICKETNUM', NULL, NULL, array(), TRUE ), |
|
1362 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( 'DTTNUM', 'TICKETNUM', NULL, NULL, array(), TRUE ) |
|
1361 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM', NULL, NULL, array(), TRUE), |
|
1362 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM', NULL, NULL, array(), TRUE) |
|
1363 | 1363 | ); |
1364 | 1364 | |
1365 | 1365 | $tktrow = 1; |
1366 | - foreach ( $all_tickets as $ticket ) { |
|
1367 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( 'DTTNUM', $tktrow, NULL, $ticket, array(), TRUE ); |
|
1366 | + foreach ($all_tickets as $ticket) { |
|
1367 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM', $tktrow, NULL, $ticket, array(), TRUE); |
|
1368 | 1368 | $tktrow++; |
1369 | 1369 | } |
1370 | 1370 | |
1371 | 1371 | |
1372 | 1372 | $dttrow = 1; |
1373 | - foreach ( $all_dtts as $dtt ) { |
|
1374 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( $dttrow, 'TICKETNUM', $dtt, NULL, array(), TRUE ); |
|
1373 | + foreach ($all_dtts as $dtt) { |
|
1374 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, 'TICKETNUM', $dtt, NULL, array(), TRUE); |
|
1375 | 1375 | $dttrow++; |
1376 | 1376 | } |
1377 | 1377 | |
1378 | 1378 | $default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices(); |
1379 | 1379 | $prcrow = 1; |
1380 | - foreach ( $default_prices as $price ) { |
|
1381 | - if ( $price->is_base_price() ) { |
|
1380 | + foreach ($default_prices as $price) { |
|
1381 | + if ($price->is_base_price()) { |
|
1382 | 1382 | $template_args['default_base_price_amount'] = $price->get_pretty('PRC_amount', 'localized_float'); |
1383 | 1383 | $template_args['default_base_price_name'] = $price->get('PRC_name'); |
1384 | 1384 | $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
1385 | 1385 | $prcrow++; |
1386 | 1386 | continue; |
1387 | 1387 | } |
1388 | - $show_trash = ( count( $default_prices ) > 1 && $prcrow === 1 ) || count( $default_prices ) === 1 ? FALSE : TRUE; |
|
1389 | - $show_create = count( $default_prices ) > 1 && count( $default_prices ) !== $prcrow ? FALSE : TRUE; |
|
1390 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( 'TICKETNUM', $prcrow, $price, TRUE, NULL, $show_trash, $show_create ); |
|
1388 | + $show_trash = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? FALSE : TRUE; |
|
1389 | + $show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? FALSE : TRUE; |
|
1390 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, TRUE, NULL, $show_trash, $show_create); |
|
1391 | 1391 | $prcrow++; |
1392 | 1392 | } |
1393 | 1393 | |
1394 | - $template_args = apply_filters( 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', $template_args, $all_dtts, $all_tickets, $this->_is_creating_event ); |
|
1394 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', $template_args, $all_dtts, $all_tickets, $this->_is_creating_event); |
|
1395 | 1395 | |
1396 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php'; |
|
1397 | - return EEH_Template::display_template( $template, $template_args, TRUE ); |
|
1396 | + $template = PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php'; |
|
1397 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1398 | 1398 | } |
1399 | 1399 | |
1400 | 1400 |
@@ -3,13 +3,13 @@ discard block |
||
3 | 3 | /** @var boolean $revisit */ |
4 | 4 | /** @var string $order_conf_desc */ |
5 | 5 | |
6 | -do_action( 'AHEE__thank_you_page_overview_template__top', $transaction ); |
|
6 | +do_action('AHEE__thank_you_page_overview_template__top', $transaction); |
|
7 | 7 | |
8 | 8 | ?> |
9 | 9 | |
10 | 10 | <div id="espresso-thank-you-page-overview-dv" class="width-100" > |
11 | 11 | |
12 | - <?php if ( ! $revisit ) : ?> |
|
12 | + <?php if ( ! $revisit) : ?> |
|
13 | 13 | <div class="ee-attention"> |
14 | 14 | <div class="extra-padding-sides"> |
15 | 15 | <?php echo apply_filters( |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | '<br />' |
22 | 22 | ) |
23 | 23 | ); |
24 | - if ( ! empty( $TXN_receipt_url )) : ?> |
|
24 | + if ( ! empty($TXN_receipt_url)) : ?> |
|
25 | 25 | <br/> |
26 | 26 | <div class="jst-rght"> |
27 | - <a class="ee-button ee-roundish indented-text big-text" href="<?php echo $TXN_receipt_url;?>"><span class="ee-icon ee-icon-PDF-file-type"></span><?php echo apply_filters( 'FHEE__thank_you_page_overview_template__order_conf_button_text', __( 'View Full Order Confirmation Receipt', 'event_espresso' )); ?></a> |
|
27 | + <a class="ee-button ee-roundish indented-text big-text" href="<?php echo $TXN_receipt_url; ?>"><span class="ee-icon ee-icon-PDF-file-type"></span><?php echo apply_filters('FHEE__thank_you_page_overview_template__order_conf_button_text', __('View Full Order Confirmation Receipt', 'event_espresso')); ?></a> |
|
28 | 28 | </div> |
29 | 29 | <?php endif; ?> |
30 | 30 | </div> |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | <?php endif; ?> |
34 | 34 | <br/> |
35 | 35 | |
36 | - <?php do_action( 'AHEE__thank_you_page_overview_template__content', $transaction ); ?> |
|
36 | + <?php do_action('AHEE__thank_you_page_overview_template__content', $transaction); ?> |
|
37 | 37 | |
38 | 38 | </div> |
39 | 39 | <!-- end of espresso-thank-you-page-overview-dv --> |
40 | 40 | |
41 | -<?php do_action( 'AHEE__thank_you_page_overview_template__bottom', $transaction ); ?> |
|
41 | +<?php do_action('AHEE__thank_you_page_overview_template__bottom', $transaction); ?> |
@@ -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 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return void |
92 | 92 | */ |
93 | 93 | public static function set_hooks() { |
94 | - add_action( 'wp_loaded', array( 'EES_Espresso_Thank_You', 'set_definitions' ), 2 ); |
|
94 | + add_action('wp_loaded', array('EES_Espresso_Thank_You', 'set_definitions'), 2); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | |
@@ -104,22 +104,22 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public static function set_hooks_admin() { |
106 | 106 | // AJAX for IPN monitoring |
107 | - add_filter( 'heartbeat_received', array( 'EES_Espresso_Thank_You', 'thank_you_page_IPN_monitor' ), 10, 3 ); |
|
107 | + add_filter('heartbeat_received', array('EES_Espresso_Thank_You', 'thank_you_page_IPN_monitor'), 10, 3); |
|
108 | 108 | add_filter( |
109 | 109 | 'heartbeat_nopriv_received', |
110 | - array( 'EES_Espresso_Thank_You', 'thank_you_page_IPN_monitor' ), |
|
110 | + array('EES_Espresso_Thank_You', 'thank_you_page_IPN_monitor'), |
|
111 | 111 | 10, |
112 | 112 | 3 |
113 | 113 | ); |
114 | 114 | add_action( |
115 | 115 | 'wp_ajax_espresso_resend_reg_confirmation_email', |
116 | - array( 'EES_Espresso_Thank_You', 'resend_reg_confirmation_email' ), |
|
116 | + array('EES_Espresso_Thank_You', 'resend_reg_confirmation_email'), |
|
117 | 117 | 10, |
118 | 118 | 2 |
119 | 119 | ); |
120 | 120 | add_action( |
121 | 121 | 'wp_ajax_nopriv_espresso_resend_reg_confirmation_email', |
122 | - array( 'EES_Espresso_Thank_You', 'resend_reg_confirmation_email' ), |
|
122 | + array('EES_Espresso_Thank_You', 'resend_reg_confirmation_email'), |
|
123 | 123 | 10, |
124 | 124 | 2 |
125 | 125 | ); |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @return void |
135 | 135 | */ |
136 | 136 | public static function set_definitions() { |
137 | - define( 'THANK_YOU_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
|
138 | - define( 'THANK_YOU_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ ) ) . 'templates' . DS ); |
|
137 | + define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
138 | + define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | * @return EE_Transaction |
148 | 148 | */ |
149 | 149 | public function get_txn() { |
150 | - if ( $this->_current_txn instanceof EE_Transaction ) { |
|
150 | + if ($this->_current_txn instanceof EE_Transaction) { |
|
151 | 151 | return $this->_current_txn; |
152 | 152 | } |
153 | - $TXN_model = EE_Registry::instance()->load_model( 'Transaction' ); |
|
154 | - if ( ! $TXN_model instanceof EEM_Transaction ) { |
|
153 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
154 | + if ( ! $TXN_model instanceof EEM_Transaction) { |
|
155 | 155 | EE_Error::add_error( |
156 | - __( 'The transaction model could not be established.', 'event_espresso' ), |
|
156 | + __('The transaction model could not be established.', 'event_espresso'), |
|
157 | 157 | __FILE__, |
158 | 158 | __FUNCTION__, |
159 | 159 | __LINE__ |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | return null; |
162 | 162 | } |
163 | 163 | //get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request |
164 | - $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link( $this->_reg_url_link ); |
|
164 | + $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link); |
|
165 | 165 | // verify TXN |
166 | - if ( WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction ) { |
|
166 | + if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) { |
|
167 | 167 | EE_Error::add_error( |
168 | 168 | __( |
169 | 169 | 'No transaction information could be retrieved or the transaction data is not of the correct type.', |
@@ -187,16 +187,16 @@ discard block |
||
187 | 187 | * @param int $since |
188 | 188 | * @return mixed array of EE_Payment || FALSE |
189 | 189 | */ |
190 | - public function get_txn_payments( $since = 0 ) { |
|
191 | - if ( ! $this->get_txn() ) { |
|
190 | + public function get_txn_payments($since = 0) { |
|
191 | + if ( ! $this->get_txn()) { |
|
192 | 192 | return false; |
193 | 193 | } |
194 | - $args = array( 'order_by' => array( 'PAY_timestamp' => 'ASC' ) ); |
|
195 | - if ( $since > 0 ) { |
|
196 | - $args[0] = array( 'PAY_timestamp' => array( '>', $since ) ); |
|
194 | + $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
|
195 | + if ($since > 0) { |
|
196 | + $args[0] = array('PAY_timestamp' => array('>', $since)); |
|
197 | 197 | } |
198 | 198 | // get array of payments with most recent first |
199 | - return $this->_current_txn->payments( $args ); |
|
199 | + return $this->_current_txn->payments($args); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -208,11 +208,11 @@ discard block |
||
208 | 208 | * @return void |
209 | 209 | */ |
210 | 210 | private function _get_reg_url_link() { |
211 | - if ( ! empty( $this->_reg_url_link ) ) { |
|
211 | + if ( ! empty($this->_reg_url_link)) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | 214 | // only do thank you page stuff if we have a REG_url_link in the url |
215 | - if ( WP_DEBUG && ! EE_Registry::instance()->REQ->is_set( 'e_reg_url_link' ) ) { |
|
215 | + if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) { |
|
216 | 216 | EE_Error::add_error( |
217 | 217 | __( |
218 | 218 | 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | return; |
226 | 226 | } |
227 | 227 | // check for reg_url_link |
228 | - $this->_reg_url_link = EE_Registry::instance()->REQ->get( 'e_reg_url_link' ); |
|
228 | + $this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link'); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | * @param string $reg_url_link |
238 | 238 | * @return string |
239 | 239 | */ |
240 | - public function set_reg_url_link( $reg_url_link = null ) { |
|
241 | - $this->_reg_url_link = ! empty( $reg_url_link ) ? $reg_url_link : $this->_reg_url_link; |
|
240 | + public function set_reg_url_link($reg_url_link = null) { |
|
241 | + $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | |
@@ -251,28 +251,28 @@ discard block |
||
251 | 251 | * @param WP $WP |
252 | 252 | * @return void |
253 | 253 | */ |
254 | - public function run( WP $WP ) { |
|
254 | + public function run(WP $WP) { |
|
255 | 255 | // remove site_url() from thank you page URL |
256 | - $thank_you_page_URL = substr( EE_Registry::instance()->CFG->core->thank_you_page_url(), strlen( home_url() ) ); |
|
256 | + $thank_you_page_URL = substr(EE_Registry::instance()->CFG->core->thank_you_page_url(), strlen(home_url())); |
|
257 | 257 | // remove other non-essential details from URL |
258 | - $thank_you_page_URL = trim( parse_url( $thank_you_page_URL, PHP_URL_PATH ), '/' ); |
|
258 | + $thank_you_page_URL = trim(parse_url($thank_you_page_URL, PHP_URL_PATH), '/'); |
|
259 | 259 | // ensure this shortcode doesn't trigger on anything BUT the thank you page |
260 | - if ( isset( $WP->request ) && trim( $WP->request, '/' ) !== $thank_you_page_URL ) { |
|
260 | + if (isset($WP->request) && trim($WP->request, '/') !== $thank_you_page_URL) { |
|
261 | 261 | return; |
262 | 262 | } else if ( |
263 | - isset( $WP->query_vars['page_id'] ) |
|
264 | - && (int)$WP->query_vars['page_id'] !== (int)EE_Registry::instance()->CFG->core->thank_you_page_id |
|
263 | + isset($WP->query_vars['page_id']) |
|
264 | + && (int) $WP->query_vars['page_id'] !== (int) EE_Registry::instance()->CFG->core->thank_you_page_id |
|
265 | 265 | ) { |
266 | 266 | return; |
267 | 267 | } |
268 | 268 | $this->_get_reg_url_link(); |
269 | 269 | // resend_reg_confirmation_email ? |
270 | - if ( EE_Registry::instance()->REQ->is_set( 'resend' ) ) { |
|
270 | + if (EE_Registry::instance()->REQ->is_set('resend')) { |
|
271 | 271 | EES_Espresso_Thank_You::resend_reg_confirmation_email(); |
272 | 272 | } |
273 | 273 | // load assets |
274 | - add_action( 'wp_enqueue_scripts', array( $this, 'load_js' ), 10 ); |
|
275 | - EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ ); |
|
274 | + add_action('wp_enqueue_scripts', array($this, 'load_js'), 10); |
|
275 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
276 | 276 | $this->_translate_strings(); |
277 | 277 | } |
278 | 278 | |
@@ -326,12 +326,12 @@ discard block |
||
326 | 326 | public function load_js() { |
327 | 327 | wp_register_script( |
328 | 328 | 'thank_you_page', |
329 | - THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
330 | - array( 'espresso_core', 'heartbeat' ), |
|
329 | + THANK_YOU_ASSETS_URL.'thank_you_page.js', |
|
330 | + array('espresso_core', 'heartbeat'), |
|
331 | 331 | EVENT_ESPRESSO_VERSION, |
332 | 332 | true |
333 | 333 | ); |
334 | - wp_enqueue_script( 'thank_you_page' ); |
|
334 | + wp_enqueue_script('thank_you_page'); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | |
@@ -345,10 +345,10 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function init() { |
347 | 347 | $this->_get_reg_url_link(); |
348 | - if ( ! $this->get_txn() ) { |
|
349 | - EE_Registry::instance()->load_helper( 'HTML' ); |
|
348 | + if ( ! $this->get_txn()) { |
|
349 | + EE_Registry::instance()->load_helper('HTML'); |
|
350 | 350 | echo EEH_HTML::div( |
351 | - EEH_HTML::h4( __( 'We\'re sorry...', 'event_espresso' ), '', '' ) . |
|
351 | + EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', ''). |
|
352 | 352 | sprintf( |
353 | 353 | __( |
354 | 354 | 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
@@ -362,8 +362,8 @@ discard block |
||
362 | 362 | return null; |
363 | 363 | } |
364 | 364 | // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete" |
365 | - if ( $this->_current_txn->status_ID() === EEM_Transaction::failed_status_code ) { |
|
366 | - $this->_current_txn->set_status( EEM_Transaction::incomplete_status_code ); |
|
365 | + if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) { |
|
366 | + $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code); |
|
367 | 367 | $this->_current_txn->save(); |
368 | 368 | } |
369 | 369 | $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration |
@@ -376,15 +376,15 @@ discard block |
||
376 | 376 | ); |
377 | 377 | $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
378 | 378 | // txn status ? |
379 | - if ( $this->_current_txn->is_completed() ) { |
|
379 | + if ($this->_current_txn->is_completed()) { |
|
380 | 380 | $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
381 | 381 | } else if ( |
382 | 382 | $this->_current_txn->is_incomplete() |
383 | - && ( $this->_primary_registrant->is_approved() |
|
384 | - || $this->_primary_registrant->is_pending_payment() ) |
|
383 | + && ($this->_primary_registrant->is_approved() |
|
384 | + || $this->_primary_registrant->is_pending_payment()) |
|
385 | 385 | ) { |
386 | 386 | $this->_show_try_pay_again_link = true; |
387 | - } else if ( $this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment() ) { |
|
387 | + } else if ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) { |
|
388 | 388 | // its pending |
389 | 389 | $this->_show_try_pay_again_link = isset( |
390 | 390 | EE_Registry::instance()->CFG->registration->show_pending_payment_options |
@@ -410,23 +410,23 @@ discard block |
||
410 | 410 | } |
411 | 411 | // link to SPCO |
412 | 412 | $revisit_spco_url = add_query_arg( |
413 | - array( 'ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link ), |
|
413 | + array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link), |
|
414 | 414 | EE_Registry::instance()->CFG->core->reg_page_url() |
415 | 415 | ); |
416 | 416 | // link to SPCO payment_options |
417 | 417 | $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration |
418 | 418 | ? $this->_primary_registrant->payment_overview_url() |
419 | 419 | : add_query_arg( |
420 | - array( 'step' => 'payment_options' ), |
|
420 | + array('step' => 'payment_options'), |
|
421 | 421 | $revisit_spco_url |
422 | 422 | ); |
423 | 423 | // link to SPCO attendee_information |
424 | 424 | $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration |
425 | 425 | ? $this->_primary_registrant->edit_attendee_information_url() |
426 | 426 | : false; |
427 | - EE_Registry::instance()->load_helper( 'Template' ); |
|
428 | - EE_Registry::instance()->load_helper( 'Template_Validator' ); |
|
429 | - do_action( 'AHEE__EES_Espresso_Thank_You__init_end', $this->_current_txn ); |
|
427 | + EE_Registry::instance()->load_helper('Template'); |
|
428 | + EE_Registry::instance()->load_helper('Template_Validator'); |
|
429 | + do_action('AHEE__EES_Espresso_Thank_You__init_end', $this->_current_txn); |
|
430 | 430 | // set no cache headers and constants |
431 | 431 | EE_System::do_not_cache(); |
432 | 432 | } |
@@ -441,16 +441,16 @@ discard block |
||
441 | 441 | * @return string |
442 | 442 | * @throws \EE_Error |
443 | 443 | */ |
444 | - public function process_shortcode( $attributes = array() ) { |
|
444 | + public function process_shortcode($attributes = array()) { |
|
445 | 445 | $this->init(); |
446 | - if ( ! $this->_current_txn instanceof EE_Transaction ) { |
|
446 | + if ( ! $this->_current_txn instanceof EE_Transaction) { |
|
447 | 447 | return EE_Error::get_notices(); |
448 | 448 | } |
449 | 449 | //EE_Registry::instance()->load_helper( 'Debug_Tools' ); |
450 | 450 | //EEH_Debug_Tools::log( __CLASS__, __FUNCTION__, __LINE__, array( $this->_current_txn ), true, 'EE_Transaction: ' . $this->_current_txn->ID() ); |
451 | 451 | // link to receipt |
452 | - $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url( 'html' ); |
|
453 | - if ( ! empty( $template_args['TXN_receipt_url'] ) ) { |
|
452 | + $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html'); |
|
453 | + if ( ! empty($template_args['TXN_receipt_url'])) { |
|
454 | 454 | $template_args['order_conf_desc'] = __( |
455 | 455 | '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
456 | 456 | 'event_espresso' |
@@ -462,13 +462,13 @@ discard block |
||
462 | 462 | ); |
463 | 463 | } |
464 | 464 | $template_args['transaction'] = $this->_current_txn; |
465 | - $template_args['revisit'] = EE_Registry::instance()->REQ->get( 'revisit', false ); |
|
466 | - add_action( 'AHEE__thank_you_page_overview_template__content', array( $this, 'get_registration_details' ) ); |
|
467 | - if ( $this->_is_primary && ! $this->_current_txn->is_free() ) { |
|
468 | - add_action( 'AHEE__thank_you_page_overview_template__content', array( $this, 'get_ajax_content' ) ); |
|
465 | + $template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false); |
|
466 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details')); |
|
467 | + if ($this->_is_primary && ! $this->_current_txn->is_free()) { |
|
468 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
|
469 | 469 | } |
470 | 470 | return EEH_Template::locate_template( |
471 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
471 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-overview.template.php', |
|
472 | 472 | $template_args, |
473 | 473 | true, |
474 | 474 | true |
@@ -489,15 +489,15 @@ discard block |
||
489 | 489 | * @return array |
490 | 490 | * @throws \EE_Error |
491 | 491 | */ |
492 | - public static function thank_you_page_IPN_monitor( $response = array(), $data = array() ) { |
|
492 | + public static function thank_you_page_IPN_monitor($response = array(), $data = array()) { |
|
493 | 493 | // does this heartbeat contain our data ? |
494 | - if ( ! isset( $data['espresso_thank_you_page'] ) ) { |
|
494 | + if ( ! isset($data['espresso_thank_you_page'])) { |
|
495 | 495 | return $response; |
496 | 496 | } |
497 | 497 | // check for reg_url_link in the incoming heartbeat data |
498 | - if ( ! isset( $data['espresso_thank_you_page']['e_reg_url_link'] ) ) { |
|
498 | + if ( ! isset($data['espresso_thank_you_page']['e_reg_url_link'])) { |
|
499 | 499 | $response['espresso_thank_you_page'] = array( |
500 | - 'errors' => ! empty( $notices['errors'] ) |
|
500 | + 'errors' => ! empty($notices['errors']) |
|
501 | 501 | ? $notices['errors'] |
502 | 502 | : __( |
503 | 503 | 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
@@ -512,15 +512,15 @@ discard block |
||
512 | 512 | EES_Espresso_Thank_You::set_definitions(); |
513 | 513 | /** @var $espresso_thank_you_page EES_Espresso_Thank_You */ |
514 | 514 | $espresso_thank_you_page = EES_Espresso_Thank_You::instance(); |
515 | - $espresso_thank_you_page->set_reg_url_link( $data['espresso_thank_you_page']['e_reg_url_link'] ); |
|
515 | + $espresso_thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']); |
|
516 | 516 | $espresso_thank_you_page->init(); |
517 | 517 | //get TXN |
518 | 518 | $TXN = $espresso_thank_you_page->get_txn(); |
519 | 519 | // no TXN? then get out |
520 | - if ( ! $TXN instanceof EE_Transaction ) { |
|
520 | + if ( ! $TXN instanceof EE_Transaction) { |
|
521 | 521 | $notices = EE_Error::get_notices(); |
522 | 522 | $response['espresso_thank_you_page'] = array( |
523 | - 'errors' => ! empty( $notices['errors'] ) |
|
523 | + 'errors' => ! empty($notices['errors']) |
|
524 | 524 | ? $notices['errors'] |
525 | 525 | : sprintf( |
526 | 526 | __( |
@@ -533,13 +533,13 @@ discard block |
||
533 | 533 | return $response; |
534 | 534 | } |
535 | 535 | // grab transient of TXN's status |
536 | - $txn_status = isset( $data['espresso_thank_you_page']['txn_status'] ) |
|
536 | + $txn_status = isset($data['espresso_thank_you_page']['txn_status']) |
|
537 | 537 | ? $data['espresso_thank_you_page']['txn_status'] |
538 | 538 | : null; |
539 | 539 | // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
540 | - if ( $txn_status !== $TXN->status_ID() ) { |
|
540 | + if ($txn_status !== $TXN->status_ID()) { |
|
541 | 541 | // switch between two possible basic outcomes |
542 | - switch ( $TXN->status_ID() ) { |
|
542 | + switch ($TXN->status_ID()) { |
|
543 | 543 | // TXN has been updated in some way |
544 | 544 | case EEM_Transaction::overpaid_status_code: |
545 | 545 | case EEM_Transaction::complete_status_code: |
@@ -554,25 +554,25 @@ discard block |
||
554 | 554 | case EEM_Transaction::failed_status_code: |
555 | 555 | default: |
556 | 556 | // keep on waiting... |
557 | - return $espresso_thank_you_page->_update_server_wait_time( $data['espresso_thank_you_page'] ); |
|
557 | + return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']); |
|
558 | 558 | } |
559 | 559 | // or is the TXN still failed (never been updated) ??? |
560 | - } else if ( $TXN->failed() ) { |
|
560 | + } else if ($TXN->failed()) { |
|
561 | 561 | // keep on waiting... |
562 | - return $espresso_thank_you_page->_update_server_wait_time( $data['espresso_thank_you_page'] ); |
|
562 | + return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']); |
|
563 | 563 | } |
564 | 564 | // TXN is happening so let's get the payments now |
565 | 565 | // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
566 | - $since = isset( $data['espresso_thank_you_page']['get_payments_since'] ) |
|
566 | + $since = isset($data['espresso_thank_you_page']['get_payments_since']) |
|
567 | 567 | ? $data['espresso_thank_you_page']['get_payments_since'] |
568 | 568 | : 0; |
569 | 569 | // then check for payments |
570 | - $payments = $espresso_thank_you_page->get_txn_payments( $since ); |
|
570 | + $payments = $espresso_thank_you_page->get_txn_payments($since); |
|
571 | 571 | // has a payment been processed ? |
572 | - if ( ! empty( $payments ) || $espresso_thank_you_page->_is_offline_payment_method ) { |
|
573 | - if ( $since ) { |
|
572 | + if ( ! empty($payments) || $espresso_thank_you_page->_is_offline_payment_method) { |
|
573 | + if ($since) { |
|
574 | 574 | $response['espresso_thank_you_page'] = array( |
575 | - 'new_payments' => $espresso_thank_you_page->get_new_payments( $payments ), |
|
575 | + 'new_payments' => $espresso_thank_you_page->get_new_payments($payments), |
|
576 | 576 | 'transaction_details' => $espresso_thank_you_page->get_transaction_details(), |
577 | 577 | 'txn_status' => $TXN->status_ID() |
578 | 578 | ); |
@@ -598,9 +598,9 @@ discard block |
||
598 | 598 | * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data |
599 | 599 | * @return array |
600 | 600 | */ |
601 | - private function _update_server_wait_time( $thank_you_page_data = array() ) { |
|
601 | + private function _update_server_wait_time($thank_you_page_data = array()) { |
|
602 | 602 | $response['espresso_thank_you_page'] = array( |
603 | - 'still_waiting' => isset( $thank_you_page_data['initial_access'] ) |
|
603 | + 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
604 | 604 | ? time() - $thank_you_page_data['initial_access'] |
605 | 605 | : 0, |
606 | 606 | 'txn_status' => $this->_current_txn->status_ID() |
@@ -625,17 +625,17 @@ discard block |
||
625 | 625 | $template_args['is_primary'] = $this->_is_primary; |
626 | 626 | $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url; |
627 | 627 | $template_args['resend_reg_confirmation_url'] = add_query_arg( |
628 | - array( 'token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true' ), |
|
628 | + array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'), |
|
629 | 629 | EE_Registry::instance()->CFG->core->thank_you_page_url() |
630 | 630 | ); |
631 | 631 | // verify template arguments |
632 | - EEH_Template_Validator::verify_instanceof( $template_args['transaction'], '$transaction', 'EE_Transaction' ); |
|
632 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
633 | 633 | EEH_Template_Validator::verify_isnt_null( |
634 | 634 | $template_args['SPCO_attendee_information_url'], |
635 | 635 | '$SPCO_attendee_information_url' |
636 | 636 | ); |
637 | 637 | echo EEH_Template::locate_template( |
638 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
638 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-registration-details.template.php', |
|
639 | 639 | $template_args, |
640 | 640 | true, |
641 | 641 | true |
@@ -648,16 +648,16 @@ discard block |
||
648 | 648 | * resend_reg_confirmation_email |
649 | 649 | */ |
650 | 650 | public static function resend_reg_confirmation_email() { |
651 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
652 | - $reg_url_link = EE_Registry::instance()->REQ->get( 'token' ); |
|
651 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
652 | + $reg_url_link = EE_Registry::instance()->REQ->get('token'); |
|
653 | 653 | // was a REG_ID passed ? |
654 | - if ( $reg_url_link ) { |
|
655 | - $registration = EE_Registry::instance()->load_model( 'Registration' )->get_one( |
|
656 | - array( array( 'REG_url_link' => $reg_url_link ) ) |
|
654 | + if ($reg_url_link) { |
|
655 | + $registration = EE_Registry::instance()->load_model('Registration')->get_one( |
|
656 | + array(array('REG_url_link' => $reg_url_link)) |
|
657 | 657 | ); |
658 | - if ( $registration instanceof EE_Registration ) { |
|
658 | + if ($registration instanceof EE_Registration) { |
|
659 | 659 | // resend email |
660 | - EED_Messages::process_resend( array( '_REG_ID' => $registration->ID() ) ); |
|
660 | + EED_Messages::process_resend(array('_REG_ID' => $registration->ID())); |
|
661 | 661 | } else { |
662 | 662 | EE_Error::add_error( |
663 | 663 | __( |
@@ -681,16 +681,16 @@ discard block |
||
681 | 681 | ); |
682 | 682 | } |
683 | 683 | // request sent via AJAX ? |
684 | - if ( EE_FRONT_AJAX ) { |
|
685 | - echo json_encode( EE_Error::get_notices( false ) ); |
|
684 | + if (EE_FRONT_AJAX) { |
|
685 | + echo json_encode(EE_Error::get_notices(false)); |
|
686 | 686 | die(); |
687 | 687 | // or was JS disabled ? |
688 | 688 | } else { |
689 | 689 | // save errors so that they get picked up on the next request |
690 | - EE_Error::get_notices( true, true ); |
|
690 | + EE_Error::get_notices(true, true); |
|
691 | 691 | wp_safe_redirect( |
692 | 692 | add_query_arg( |
693 | - array( 'e_reg_url_link' => $reg_url_link ), |
|
693 | + array('e_reg_url_link' => $reg_url_link), |
|
694 | 694 | EE_Registry::instance()->CFG->core->thank_you_page_url() |
695 | 695 | ) |
696 | 696 | ); |
@@ -706,26 +706,26 @@ discard block |
||
706 | 706 | * @return void |
707 | 707 | */ |
708 | 708 | public function get_ajax_content() { |
709 | - if ( ! $this->get_txn() ) { |
|
709 | + if ( ! $this->get_txn()) { |
|
710 | 710 | return; |
711 | 711 | } |
712 | 712 | // first determine which event(s) require pre-approval or not |
713 | 713 | $events = array(); |
714 | 714 | $events_requiring_pre_approval = array(); |
715 | - foreach ( $this->_current_txn->registrations() as $registration ) { |
|
716 | - if ( $registration instanceof EE_Registration ) { |
|
715 | + foreach ($this->_current_txn->registrations() as $registration) { |
|
716 | + if ($registration instanceof EE_Registration) { |
|
717 | 717 | $event = $registration->event(); |
718 | - if ( $event instanceof EE_Event ) { |
|
719 | - if ( $registration->is_not_approved() && $registration->event() instanceof EE_Event ) { |
|
720 | - $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
718 | + if ($event instanceof EE_Event) { |
|
719 | + if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
|
720 | + $events_requiring_pre_approval[$event->ID()] = $event; |
|
721 | 721 | } else { |
722 | - $events[ $event->ID() ] = $event; |
|
722 | + $events[$event->ID()] = $event; |
|
723 | 723 | } |
724 | 724 | } |
725 | 725 | } |
726 | 726 | } |
727 | - $this->display_details_for_events_requiring_pre_approval( $events_requiring_pre_approval ); |
|
728 | - $this->display_details_for_events( $events ); |
|
727 | + $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval); |
|
728 | + $this->display_details_for_events($events); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | |
@@ -737,8 +737,8 @@ discard block |
||
737 | 737 | * @param EE_Event[] $events |
738 | 738 | * @return string |
739 | 739 | */ |
740 | - public function display_details_for_events( $events = array() ) { |
|
741 | - if ( ! empty( $events ) ) { |
|
740 | + public function display_details_for_events($events = array()) { |
|
741 | + if ( ! empty($events)) { |
|
742 | 742 | ?> |
743 | 743 | <div id="espresso-thank-you-page-ajax-content-dv"> |
744 | 744 | <div id="espresso-thank-you-page-ajax-transaction-dv"></div> |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | 'event_espresso' |
751 | 751 | ); ?></span> |
752 | 752 | </div> |
753 | - <?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed ) : ?> |
|
753 | + <?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
|
754 | 754 | <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear"> |
755 | 755 | <?php echo apply_filters( |
756 | 756 | 'EES_Espresso_Thank_You__get_ajax_content__waiting_for_IPN_msg', |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | ); ?> |
762 | 762 | <br/> |
763 | 763 | <span class="jst-rght ee-block small-text lt-grey-text"> |
764 | - <?php _e( 'current wait time ', 'event_espresso' ); ?> |
|
764 | + <?php _e('current wait time ', 'event_espresso'); ?> |
|
765 | 765 | <span id="espresso-thank-you-page-ajax-time-dv">00:00:00</span></span> |
766 | 766 | </p> |
767 | 767 | <?php endif; ?> |
@@ -781,11 +781,11 @@ discard block |
||
781 | 781 | * @param EE_Event[] $events |
782 | 782 | * @return string |
783 | 783 | */ |
784 | - public function display_details_for_events_requiring_pre_approval( $events = array() ) { |
|
785 | - if ( ! empty( $events ) ) { |
|
784 | + public function display_details_for_events_requiring_pre_approval($events = array()) { |
|
785 | + if ( ! empty($events)) { |
|
786 | 786 | ?> |
787 | 787 | <div id="espresso-thank-you-page-not-approved-message-dv"> |
788 | - <h4 class="orange-text"><?php _e( 'Important Notice:', 'event_espresso' ); ?></h4> |
|
788 | + <h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4> |
|
789 | 789 | <p id="events-requiring-pre-approval-pg" class="small-text"> |
790 | 790 | <?php echo apply_filters( |
791 | 791 | 'AHEE__EES_Espresso_Thank_You__get_ajax_content__not_approved_message', |
@@ -796,8 +796,8 @@ discard block |
||
796 | 796 | ); ?> |
797 | 797 | </p> |
798 | 798 | <ul class="events-requiring-pre-approval-ul"> |
799 | - <?php foreach ( $events as $event ) { |
|
800 | - if ( $event instanceof EE_Event ) { |
|
799 | + <?php foreach ($events as $event) { |
|
800 | + if ($event instanceof EE_Event) { |
|
801 | 801 | echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>', |
802 | 802 | $event->name(), |
803 | 803 | '</li>'; |
@@ -824,12 +824,12 @@ discard block |
||
824 | 824 | $template_args = array(); |
825 | 825 | $template_args['transaction'] = $this->_current_txn; |
826 | 826 | $template_args['reg_url_link'] = $this->_reg_url_link; |
827 | - $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name( true ); |
|
827 | + $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true); |
|
828 | 828 | // link to SPCO payment_options |
829 | 829 | $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
830 | 830 | $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
831 | 831 | // verify template arguments |
832 | - EEH_Template_Validator::verify_instanceof( $template_args['transaction'], '$transaction', 'EE_Transaction' ); |
|
832 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
833 | 833 | EEH_Template_Validator::verify_isnt_null( |
834 | 834 | $template_args['show_try_pay_again_link'], |
835 | 835 | '$show_try_pay_again_link' |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | '$SPCO_payment_options_url' |
840 | 840 | ); |
841 | 841 | return EEH_Template::locate_template( |
842 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
842 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-transaction-details.template.php', |
|
843 | 843 | $template_args, |
844 | 844 | true, |
845 | 845 | true |
@@ -856,9 +856,9 @@ discard block |
||
856 | 856 | * @return string |
857 | 857 | * @throws \EE_Error |
858 | 858 | */ |
859 | - public function get_payment_row_html( $payment = null ) { |
|
859 | + public function get_payment_row_html($payment = null) { |
|
860 | 860 | $html = ''; |
861 | - if ( $payment instanceof EE_Payment ) { |
|
861 | + if ($payment instanceof EE_Payment) { |
|
862 | 862 | if ( |
863 | 863 | $payment->payment_method() instanceof EE_Payment_Method |
864 | 864 | && $payment->status() === EEM_Payment::status_id_failed |
@@ -867,31 +867,31 @@ discard block |
||
867 | 867 | // considering the registrant has made it to the Thank You page, |
868 | 868 | // any failed payments may actually be pending and the IPN is just slow |
869 | 869 | // so let's |
870 | - $payment->set_status( EEM_Payment::status_id_pending ); |
|
870 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
871 | 871 | } |
872 | 872 | $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
873 | - ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>' |
|
873 | + ? '<br /><span class="small-text">'.$payment->gateway_response().'</span>' |
|
874 | 874 | : ''; |
875 | 875 | $html .= ' |
876 | 876 | <tr> |
877 | 877 | <td> |
878 | - ' . $payment->timestamp() . ' |
|
878 | + ' . $payment->timestamp().' |
|
879 | 879 | </td> |
880 | 880 | <td> |
881 | 881 | ' . ( |
882 | 882 | $payment->payment_method() instanceof EE_Payment_Method |
883 | 883 | ? $payment->payment_method()->name() |
884 | - : __( 'Unknown', 'event_espresso' ) |
|
885 | - ) . ' |
|
884 | + : __('Unknown', 'event_espresso') |
|
885 | + ).' |
|
886 | 886 | </td> |
887 | 887 | <td class="jst-rght"> |
888 | - ' . EEH_Template::format_currency( $payment->amount() ) . ' |
|
888 | + ' . EEH_Template::format_currency($payment->amount()).' |
|
889 | 889 | </td> |
890 | 890 | <td class="jst-rght" style="line-height:1;"> |
891 | - ' . $payment->pretty_status( true ) . $payment_declined_msg . ' |
|
891 | + ' . $payment->pretty_status(true).$payment_declined_msg.' |
|
892 | 892 | </td> |
893 | 893 | </tr>'; |
894 | - do_action( 'AHEE__thank_you_page_payment_details_template__after_each_payment', $payment ); |
|
894 | + do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
|
895 | 895 | } |
896 | 896 | return $html; |
897 | 897 | } |
@@ -906,14 +906,14 @@ discard block |
||
906 | 906 | * @return string |
907 | 907 | * @throws \EE_Error |
908 | 908 | */ |
909 | - public function get_payment_details( $payments = array() ) { |
|
909 | + public function get_payment_details($payments = array()) { |
|
910 | 910 | //prepare variables for displaying |
911 | 911 | $template_args = array(); |
912 | 912 | $template_args['transaction'] = $this->_current_txn; |
913 | 913 | $template_args['reg_url_link'] = $this->_reg_url_link; |
914 | 914 | $template_args['payments'] = array(); |
915 | - foreach ( $payments as $payment ) { |
|
916 | - $template_args['payments'][] = $this->get_payment_row_html( $payment ); |
|
915 | + foreach ($payments as $payment) { |
|
916 | + $template_args['payments'][] = $this->get_payment_row_html($payment); |
|
917 | 917 | } |
918 | 918 | //create a hacky payment object, but dont save it |
919 | 919 | $payment = EE_Payment::new_instance( |
@@ -926,8 +926,8 @@ discard block |
||
926 | 926 | ) |
927 | 927 | ); |
928 | 928 | $payment_method = $this->_current_txn->payment_method(); |
929 | - if ( $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base ) { |
|
930 | - $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content( $payment ); |
|
929 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
930 | + $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment); |
|
931 | 931 | } else { |
932 | 932 | $template_args['gateway_content'] = ''; |
933 | 933 | } |
@@ -935,19 +935,19 @@ discard block |
||
935 | 935 | $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
936 | 936 | $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
937 | 937 | // verify template arguments |
938 | - EEH_Template_Validator::verify_instanceof( $template_args['transaction'], '$transaction', 'EE_Transaction' ); |
|
939 | - EEH_Template_Validator::verify_isnt_null( $template_args['payments'], '$payments' ); |
|
938 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
939 | + EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments'); |
|
940 | 940 | EEH_Template_Validator::verify_isnt_null( |
941 | 941 | $template_args['show_try_pay_again_link'], |
942 | 942 | '$show_try_pay_again_link' |
943 | 943 | ); |
944 | - EEH_Template_Validator::verify_isnt_null( $template_args['gateway_content'], '$gateway_content' ); |
|
944 | + EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content'); |
|
945 | 945 | EEH_Template_Validator::verify_isnt_null( |
946 | 946 | $template_args['SPCO_payment_options_url'], |
947 | 947 | '$SPCO_payment_options_url' |
948 | 948 | ); |
949 | 949 | return EEH_Template::locate_template( |
950 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
950 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-payment-details.template.php', |
|
951 | 951 | $template_args, |
952 | 952 | true, |
953 | 953 | true |
@@ -964,11 +964,11 @@ discard block |
||
964 | 964 | * @return string |
965 | 965 | * @throws \EE_Error |
966 | 966 | */ |
967 | - public function get_new_payments( $payments = array() ) { |
|
967 | + public function get_new_payments($payments = array()) { |
|
968 | 968 | $payments_html = ''; |
969 | 969 | //prepare variables for displaying |
970 | - foreach ( $payments as $payment ) { |
|
971 | - $payments_html .= $this->get_payment_row_html( $payment ); |
|
970 | + foreach ($payments as $payment) { |
|
971 | + $payments_html .= $this->get_payment_row_html($payment); |
|
972 | 972 | } |
973 | 973 | return $payments_html; |
974 | 974 | } |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | use EventEspresso\core\libraries\rest_api\Rest_Exception; |
7 | 7 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
8 | 8 | |
9 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
10 | - exit( 'No direct script access allowed' ); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | - \EE_Registry::instance()->load_helper( 'Inflector' ); |
|
41 | + \EE_Registry::instance()->load_helper('Inflector'); |
|
42 | 42 | $this->_fields_calculator = new Calculated_Model_Fields(); |
43 | 43 | } |
44 | 44 | |
@@ -47,22 +47,22 @@ discard block |
||
47 | 47 | * @param \WP_REST_Request $request |
48 | 48 | * @return \WP_REST_Response|\WP_Error |
49 | 49 | */ |
50 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
50 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
51 | 51 | $controller = new Read(); |
52 | - try{ |
|
52 | + try { |
|
53 | 53 | $matches = $controller->parse_route( |
54 | 54 | $request->get_route(), |
55 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
56 | - array( 'version', 'model' ) |
|
55 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
56 | + array('version', 'model') |
|
57 | 57 | ); |
58 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
59 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
60 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
58 | + $controller->set_requested_version($matches['version']); |
|
59 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
60 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
61 | 61 | return $controller->send_response( |
62 | 62 | new \WP_Error( |
63 | 63 | 'endpoint_parsing_error', |
64 | 64 | sprintf( |
65 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
65 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
66 | 66 | $model_name_singular |
67 | 67 | ) |
68 | 68 | ) |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | } |
71 | 71 | return $controller->send_response( |
72 | 72 | $controller->get_entities_from_model( |
73 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
73 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
74 | 74 | $request |
75 | 75 | ) |
76 | 76 | ); |
77 | - } catch( \Exception $e ) { |
|
78 | - return $controller->send_response( $e ); |
|
77 | + } catch (\Exception $e) { |
|
78 | + return $controller->send_response($e); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
@@ -85,21 +85,21 @@ discard block |
||
85 | 85 | * @param \WP_REST_Request $request |
86 | 86 | * @return \WP_REST_Response|\WP_Error |
87 | 87 | */ |
88 | - public static function handle_request_get_one( \WP_REST_Request $request ) { |
|
88 | + public static function handle_request_get_one(\WP_REST_Request $request) { |
|
89 | 89 | $controller = new Read(); |
90 | - try{ |
|
90 | + try { |
|
91 | 91 | $matches = $controller->parse_route( |
92 | 92 | $request->get_route(), |
93 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
94 | - array( 'version', 'model', 'id' ) ); |
|
95 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
96 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
97 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
93 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
94 | + array('version', 'model', 'id') ); |
|
95 | + $controller->set_requested_version($matches['version']); |
|
96 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
97 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
98 | 98 | return $controller->send_response( |
99 | 99 | new \WP_Error( |
100 | 100 | 'endpoint_parsing_error', |
101 | 101 | sprintf( |
102 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
102 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
103 | 103 | $model_name_singular |
104 | 104 | ) |
105 | 105 | ) |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | } |
108 | 108 | return $controller->send_response( |
109 | 109 | $controller->get_entity_from_model( |
110 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
110 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
111 | 111 | $request |
112 | 112 | ) |
113 | 113 | ); |
114 | - } catch( \Exception $e ) { |
|
115 | - return $controller->send_response( $e ); |
|
114 | + } catch (\Exception $e) { |
|
115 | + return $controller->send_response($e); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -124,40 +124,40 @@ discard block |
||
124 | 124 | * @param \WP_REST_Request $request |
125 | 125 | * @return \WP_REST_Response|\WP_Error |
126 | 126 | */ |
127 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
127 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
128 | 128 | $controller = new Read(); |
129 | - try{ |
|
129 | + try { |
|
130 | 130 | $matches = $controller->parse_route( |
131 | 131 | $request->get_route(), |
132 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
133 | - array( 'version', 'model', 'id', 'related_model' ) |
|
132 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
133 | + array('version', 'model', 'id', 'related_model') |
|
134 | 134 | ); |
135 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
136 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
137 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
135 | + $controller->set_requested_version($matches['version']); |
|
136 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
137 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
138 | 138 | return $controller->send_response( |
139 | 139 | new \WP_Error( |
140 | 140 | 'endpoint_parsing_error', |
141 | 141 | sprintf( |
142 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
142 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
143 | 143 | $main_model_name_singular |
144 | 144 | ) |
145 | 145 | ) |
146 | 146 | ); |
147 | 147 | } |
148 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
148 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
149 | 149 | //assume the related model name is plural and try to find the model's name |
150 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
151 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
150 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
151 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
152 | 152 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
153 | - $related_model_name_singular = \EEH_Inflector::humanize( $matches[ 'related_model' ] ); |
|
153 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
154 | 154 | } |
155 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
155 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
156 | 156 | return $controller->send_response( |
157 | 157 | new \WP_Error( |
158 | 158 | 'endpoint_parsing_error', |
159 | 159 | sprintf( |
160 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
160 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
161 | 161 | $related_model_name_singular |
162 | 162 | ) |
163 | 163 | ) |
@@ -166,13 +166,13 @@ discard block |
||
166 | 166 | |
167 | 167 | return $controller->send_response( |
168 | 168 | $controller->get_entities_from_relation( |
169 | - $request->get_param( 'id' ), |
|
170 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
169 | + $request->get_param('id'), |
|
170 | + $main_model->related_settings_for($related_model_name_singular), |
|
171 | 171 | $request |
172 | 172 | ) |
173 | 173 | ); |
174 | - } catch( \Exception $e ) { |
|
175 | - return $controller->send_response( $e ); |
|
174 | + } catch (\Exception $e) { |
|
175 | + return $controller->send_response($e); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -185,28 +185,28 @@ discard block |
||
185 | 185 | * @param \WP_REST_Request $request |
186 | 186 | * @return array |
187 | 187 | */ |
188 | - public function get_entities_from_model( $model, $request) { |
|
189 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
190 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
191 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
188 | + public function get_entities_from_model($model, $request) { |
|
189 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
190 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
191 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
192 | 192 | return new \WP_Error( |
193 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
193 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
194 | 194 | sprintf( |
195 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
195 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
196 | 196 | $model_name_plural, |
197 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
197 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
198 | 198 | ), |
199 | - array( 'status' => 403 ) |
|
199 | + array('status' => 403) |
|
200 | 200 | ); |
201 | 201 | } |
202 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
203 | - $this->_set_headers_from_query_params( $model, $query_params ); |
|
202 | + if ( ! $request->get_header('no_rest_headers')) { |
|
203 | + $this->_set_headers_from_query_params($model, $query_params); |
|
204 | 204 | } |
205 | 205 | /** @type array $results */ |
206 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
206 | + $results = $model->get_all_wpdb_results($query_params); |
|
207 | 207 | $nice_results = array( ); |
208 | - foreach ( $results as $result ) { |
|
209 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
208 | + foreach ($results as $result) { |
|
209 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
210 | 210 | $model, |
211 | 211 | $result, |
212 | 212 | $request |
@@ -227,64 +227,64 @@ discard block |
||
227 | 227 | * @param \WP_REST_Request $request |
228 | 228 | * @return array |
229 | 229 | */ |
230 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
231 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
230 | + public function get_entities_from_relation($id, $relation, $request) { |
|
231 | + $context = $this->validate_context($request->get_param('caps')); |
|
232 | 232 | $model = $relation->get_this_model(); |
233 | 233 | $related_model = $relation->get_other_model(); |
234 | 234 | //check if they can access the 1st model object |
235 | - $query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 ); |
|
236 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
235 | + $query_params = array(array($model->primary_key_name() => $id), 'limit' => 1); |
|
236 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
237 | 237 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
238 | 238 | } |
239 | 239 | $restricted_query_params = $query_params; |
240 | - $restricted_query_params[ 'caps' ] = $context; |
|
241 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
242 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
240 | + $restricted_query_params['caps'] = $context; |
|
241 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
242 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
243 | 243 | |
244 | - if( |
|
244 | + if ( |
|
245 | 245 | ! ( |
246 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
247 | - && $model->exists( $restricted_query_params ) |
|
246 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
247 | + && $model->exists($restricted_query_params) |
|
248 | 248 | ) |
249 | - ){ |
|
250 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
251 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
252 | - }else{ |
|
253 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
249 | + ) { |
|
250 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
251 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
252 | + } else { |
|
253 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
254 | 254 | } |
255 | 255 | return new \WP_Error( |
256 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
256 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
257 | 257 | sprintf( |
258 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
258 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
259 | 259 | $related_model_name_maybe_plural, |
260 | 260 | $relation->get_this_model()->get_this_model_name(), |
261 | 261 | implode( |
262 | 262 | ',', |
263 | 263 | array_keys( |
264 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
264 | + Capabilities::get_missing_permissions($related_model, $context) |
|
265 | 265 | ) |
266 | 266 | ) |
267 | 267 | ), |
268 | - array( 'status' => 403 ) |
|
268 | + array('status' => 403) |
|
269 | 269 | ); |
270 | 270 | } |
271 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
272 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id; |
|
273 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
274 | - $query_params[ 'caps' ] = $context; |
|
275 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
276 | - $this->_set_headers_from_query_params( $relation->get_other_model(), $query_params ); |
|
271 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
272 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id; |
|
273 | + $query_params['default_where_conditions'] = 'none'; |
|
274 | + $query_params['caps'] = $context; |
|
275 | + if ( ! $request->get_header('no_rest_headers')) { |
|
276 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
277 | 277 | } |
278 | 278 | /** @type array $results */ |
279 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
279 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
280 | 280 | $nice_results = array(); |
281 | - foreach( $results as $result ) { |
|
281 | + foreach ($results as $result) { |
|
282 | 282 | $nice_result = $this->create_entity_from_wpdb_result( |
283 | 283 | $relation->get_other_model(), |
284 | 284 | $result, |
285 | 285 | $request |
286 | 286 | ); |
287 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
287 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
288 | 288 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
289 | 289 | //if there are conflicts we prefer the properties from the main model |
290 | 290 | $join_model_result = $this->create_entity_from_wpdb_result( |
@@ -292,18 +292,18 @@ discard block |
||
292 | 292 | $result, |
293 | 293 | $request |
294 | 294 | ); |
295 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
295 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
296 | 296 | //but keep the meta stuff from the main model |
297 | - if( isset( $nice_result['meta'] ) ){ |
|
297 | + if (isset($nice_result['meta'])) { |
|
298 | 298 | $joined_result['meta'] = $nice_result['meta']; |
299 | 299 | } |
300 | 300 | $nice_result = $joined_result; |
301 | 301 | } |
302 | 302 | $nice_results[] = $nice_result; |
303 | 303 | } |
304 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
305 | - return array_shift( $nice_results ); |
|
306 | - }else{ |
|
304 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
305 | + return array_shift($nice_results); |
|
306 | + } else { |
|
307 | 307 | return $nice_results; |
308 | 308 | } |
309 | 309 | } |
@@ -316,30 +316,30 @@ discard block |
||
316 | 316 | * @param array $query_params |
317 | 317 | * @return void |
318 | 318 | */ |
319 | - protected function _set_headers_from_query_params( $model, $query_params ) { |
|
320 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
321 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) ); |
|
319 | + protected function _set_headers_from_query_params($model, $query_params) { |
|
320 | + $this->_set_debug_info('model query params', $query_params); |
|
321 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
322 | 322 | //normally the limit to a 2-part array, where the 2nd item is the limit |
323 | - if( ! isset( $query_params[ 'limit' ] ) ) { |
|
324 | - $query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
323 | + if ( ! isset($query_params['limit'])) { |
|
324 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
325 | 325 | } |
326 | - if( is_array( $query_params[ 'limit' ] ) ) { |
|
327 | - $limit_parts = $query_params[ 'limit' ]; |
|
326 | + if (is_array($query_params['limit'])) { |
|
327 | + $limit_parts = $query_params['limit']; |
|
328 | 328 | } else { |
329 | - $limit_parts = explode(',', $query_params[ 'limit' ] ); |
|
330 | - if( count( $limit_parts ) == 1 ){ |
|
331 | - $limit_parts = array(0, $limit_parts[ 0 ] ); |
|
329 | + $limit_parts = explode(',', $query_params['limit']); |
|
330 | + if (count($limit_parts) == 1) { |
|
331 | + $limit_parts = array(0, $limit_parts[0]); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | //remove the group by and having parts of the query, as those will |
335 | 335 | //make the sql query return an array of values, instead of just a single value |
336 | - unset( $query_params[ 'group_by' ], $query_params[ 'having' ], $query_params[ 'limit' ] ); |
|
337 | - $count = $model->count( $query_params, null, true ); |
|
336 | + unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
337 | + $count = $model->count($query_params, null, true); |
|
338 | 338 | |
339 | - $pages = $count / $limit_parts[ 1 ]; |
|
340 | - $this->_set_response_header( 'Total', $count, false ); |
|
341 | - $this->_set_response_header( 'PageSize', $limit_parts[ 1 ], false ); |
|
342 | - $this->_set_response_header( 'TotalPages', ceil( $pages ), false ); |
|
339 | + $pages = $count / $limit_parts[1]; |
|
340 | + $this->_set_response_header('Total', $count, false); |
|
341 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
342 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | |
@@ -352,47 +352,47 @@ discard block |
||
352 | 352 | * @param string $deprecated no longer used |
353 | 353 | * @return array ready for being converted into json for sending to client |
354 | 354 | */ |
355 | - public function create_entity_from_wpdb_result( $model, $db_row, $rest_request, $deprecated = null ) { |
|
356 | - if( ! $rest_request instanceof \WP_REST_Request ) { |
|
355 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) { |
|
356 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
357 | 357 | //ok so this was called in the old style, where the 3rd arg was |
358 | 358 | //$include, and the 4th arg was $context |
359 | 359 | //now setup the request just to avoid fatal errors, although we won't be able |
360 | 360 | //to truly make use of it because it's kinda devoid of info |
361 | 361 | $rest_request = new \WP_REST_Request(); |
362 | - $rest_request->set_param( 'include', $rest_request ); |
|
363 | - $rest_request->set_param( 'caps', $deprecated ); |
|
362 | + $rest_request->set_param('include', $rest_request); |
|
363 | + $rest_request->set_param('caps', $deprecated); |
|
364 | 364 | } |
365 | - if( $rest_request->get_param( 'caps' ) == null ) { |
|
366 | - $rest_request->set_param( 'caps', \EEM_Base::caps_read ); |
|
365 | + if ($rest_request->get_param('caps') == null) { |
|
366 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
367 | 367 | } |
368 | - $entity_array = $this->_create_bare_entity_from_wpdb_results( $model, $db_row ); |
|
369 | - $entity_array = $this->_add_extra_fields( $model, $db_row, $entity_array ); |
|
370 | - $entity_array[ '_links' ] = $this->_get_entity_links( $model, $db_row, $entity_array ); |
|
371 | - $entity_array[ '_calculated_fields'] = $this->_get_entity_calculations( $model, $db_row, $rest_request ); |
|
372 | - $entity_array = $this->_include_requested_models( $model, $rest_request, $entity_array ); |
|
368 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
369 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
370 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
371 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
372 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array); |
|
373 | 373 | $entity_array = apply_filters( |
374 | 374 | 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
375 | 375 | $entity_array, |
376 | 376 | $model, |
377 | - $rest_request->get_param( 'caps' ), |
|
377 | + $rest_request->get_param('caps'), |
|
378 | 378 | $rest_request, |
379 | 379 | $this |
380 | 380 | ); |
381 | 381 | $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
382 | 382 | $entity_array, |
383 | 383 | $model, |
384 | - $rest_request->get_param( 'caps' ), |
|
384 | + $rest_request->get_param('caps'), |
|
385 | 385 | $this->get_model_version_info() |
386 | 386 | ); |
387 | 387 | $this->_set_debug_info( |
388 | 388 | 'inaccessible fields', |
389 | - array_keys( array_diff_key( $entity_array, $result_without_inaccessible_fields ) ) |
|
389 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
390 | 390 | ); |
391 | 391 | return apply_filters( |
392 | 392 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
393 | 393 | $result_without_inaccessible_fields, |
394 | 394 | $model, |
395 | - $rest_request->get_param( 'caps' ) |
|
395 | + $rest_request->get_param('caps') |
|
396 | 396 | ); |
397 | 397 | } |
398 | 398 | |
@@ -404,38 +404,38 @@ discard block |
||
404 | 404 | * @param array $db_row |
405 | 405 | * @return array entity mostly ready for converting to JSON and sending in the response |
406 | 406 | */ |
407 | - protected function _create_bare_entity_from_wpdb_results( \EEM_Base $model, $db_row ) { |
|
408 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
409 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
410 | - foreach( $result as $field_name => $raw_field_value ) { |
|
407 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) { |
|
408 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
409 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
410 | + foreach ($result as $field_name => $raw_field_value) { |
|
411 | 411 | $field_obj = $model->field_settings_for($field_name); |
412 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
413 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
414 | - unset( $result[ $field_name ] ); |
|
415 | - }elseif( |
|
416 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
417 | - ){ |
|
418 | - $result[ $field_name ] = array( |
|
419 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
420 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
412 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
413 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
414 | + unset($result[$field_name]); |
|
415 | + }elseif ( |
|
416 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
417 | + ) { |
|
418 | + $result[$field_name] = array( |
|
419 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
420 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
421 | 421 | ); |
422 | - }elseif( |
|
423 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
424 | - ){ |
|
425 | - $result[ $field_name ] = array( |
|
426 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
427 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
422 | + }elseif ( |
|
423 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
424 | + ) { |
|
425 | + $result[$field_name] = array( |
|
426 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
427 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
428 | 428 | ); |
429 | - } elseif ( $field_obj instanceof \EE_Datetime_Field ) { |
|
430 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
429 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
430 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
431 | 431 | $field_obj, |
432 | 432 | $field_value, |
433 | 433 | $this->get_model_version_info()->requested_version() |
434 | 434 | ); |
435 | 435 | } else { |
436 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
436 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
437 | 437 | $field_obj, |
438 | - $field_obj->prepare_for_get( $field_value ), |
|
438 | + $field_obj->prepare_for_get($field_value), |
|
439 | 439 | $this->get_model_version_info()->requested_version() |
440 | 440 | ); |
441 | 441 | } |
@@ -450,9 +450,9 @@ discard block |
||
450 | 450 | * @param array $entity_array |
451 | 451 | * @return array modified entity |
452 | 452 | */ |
453 | - protected function _add_extra_fields( \EEM_Base $model, $db_row, $entity_array ) { |
|
454 | - if( $model instanceof \EEM_CPT_Base ) { |
|
455 | - $entity_array[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
453 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) { |
|
454 | + if ($model instanceof \EEM_CPT_Base) { |
|
455 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
456 | 456 | } |
457 | 457 | return $entity_array; |
458 | 458 | } |
@@ -466,20 +466,20 @@ discard block |
||
466 | 466 | * @param array $entity_array |
467 | 467 | * @return array the _links item in the entity |
468 | 468 | */ |
469 | - protected function _get_entity_links( $model, $db_row, $entity_array ) { |
|
469 | + protected function _get_entity_links($model, $db_row, $entity_array) { |
|
470 | 470 | //add basic links |
471 | 471 | $links = array( |
472 | 472 | 'self' => array( |
473 | 473 | array( |
474 | 474 | 'href' => $this->get_versioned_link_to( |
475 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] |
|
475 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()] |
|
476 | 476 | ) |
477 | 477 | ) |
478 | 478 | ), |
479 | 479 | 'collection' => array( |
480 | 480 | array( |
481 | 481 | 'href' => $this->get_versioned_link_to( |
482 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
482 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
483 | 483 | ) |
484 | 484 | ) |
485 | 485 | ), |
@@ -487,24 +487,24 @@ discard block |
||
487 | 487 | |
488 | 488 | //add link to the wp core endpoint, if wp api is active |
489 | 489 | global $wp_rest_server; |
490 | - if( $model instanceof \EEM_CPT_Base && |
|
490 | + if ($model instanceof \EEM_CPT_Base && |
|
491 | 491 | $wp_rest_server instanceof \WP_REST_Server && |
492 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) ) { |
|
493 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post' ] = array( |
|
492 | + $wp_rest_server->get_route_options('/wp/v2/posts')) { |
|
493 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.'self_wp_post'] = array( |
|
494 | 494 | array( |
495 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
495 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
496 | 496 | 'single' => true |
497 | 497 | ) |
498 | 498 | ); |
499 | 499 | } |
500 | 500 | |
501 | 501 | //add links to related models |
502 | - foreach( $this->get_model_version_info()->relation_settings( $model ) as $relation_name => $relation_obj ) { |
|
503 | - $related_model_part = Read::get_related_entity_name( $relation_name, $relation_obj ); |
|
504 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array( |
|
502 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
503 | + $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
504 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
505 | 505 | array( |
506 | 506 | 'href' => $this->get_versioned_link_to( |
507 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] . '/' . $related_model_part |
|
507 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()].'/'.$related_model_part |
|
508 | 508 | ), |
509 | 509 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
510 | 510 | ) |
@@ -520,51 +520,51 @@ discard block |
||
520 | 520 | * @param array $entity_array |
521 | 521 | * @return array the modified entity |
522 | 522 | */ |
523 | - protected function _include_requested_models( \EEM_Base $model, \WP_REST_Request $rest_request, $entity_array ) { |
|
524 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'include' ), '' ); |
|
525 | - $includes_for_this_model = $this->_remove_model_names_from_array( $includes_for_this_model ); |
|
523 | + protected function _include_requested_models(\EEM_Base $model, \WP_REST_Request $rest_request, $entity_array) { |
|
524 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
525 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
526 | 526 | //if they passed in * or didn't specify any includes, return everything |
527 | - if( ! in_array( '*', $includes_for_this_model ) |
|
528 | - && ! empty( $includes_for_this_model ) ) { |
|
529 | - if( $model->has_primary_key_field() ) { |
|
527 | + if ( ! in_array('*', $includes_for_this_model) |
|
528 | + && ! empty($includes_for_this_model)) { |
|
529 | + if ($model->has_primary_key_field()) { |
|
530 | 530 | //always include the primary key. ya just gotta know that at least |
531 | 531 | $includes_for_this_model[] = $model->primary_key_name(); |
532 | 532 | } |
533 | - if( $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'calculate' ), '' ) ) { |
|
533 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
534 | 534 | $includes_for_this_model[] = '_calculated_fields'; |
535 | 535 | } |
536 | - $entity_array = array_intersect_key( $entity_array, array_flip( $includes_for_this_model ) ); |
|
536 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
537 | 537 | } |
538 | - $relation_settings = $this->get_model_version_info()->relation_settings( $model ); |
|
539 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
538 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
539 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
540 | 540 | $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
541 | - $rest_request->get_param( 'include' ), |
|
541 | + $rest_request->get_param('include'), |
|
542 | 542 | $relation_name |
543 | 543 | ); |
544 | 544 | $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
545 | - $rest_request->get_param( 'calculate' ), |
|
545 | + $rest_request->get_param('calculate'), |
|
546 | 546 | $relation_name |
547 | 547 | ); |
548 | 548 | //did they specify they wanted to include a related model, or |
549 | 549 | //specific fields from a related model? |
550 | 550 | //or did they specify to calculate a field from a related model? |
551 | - if( $related_fields_to_include || $related_fields_to_calculate ) { |
|
551 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
552 | 552 | //if so, we should include at least some part of the related model |
553 | 553 | $pretend_related_request = new \WP_REST_Request(); |
554 | 554 | $pretend_related_request->set_query_params( |
555 | 555 | array( |
556 | - 'caps' => $rest_request->get_param( 'caps' ), |
|
556 | + 'caps' => $rest_request->get_param('caps'), |
|
557 | 557 | 'include' => $related_fields_to_include, |
558 | 558 | 'calculate' => $related_fields_to_calculate, |
559 | 559 | ) |
560 | 560 | ); |
561 | - $pretend_related_request->add_header( 'no_rest_headers', true ); |
|
561 | + $pretend_related_request->add_header('no_rest_headers', true); |
|
562 | 562 | $related_results = $this->get_entities_from_relation( |
563 | - $entity_array[ $model->primary_key_name() ], |
|
563 | + $entity_array[$model->primary_key_name()], |
|
564 | 564 | $relation_obj, |
565 | 565 | $pretend_related_request |
566 | 566 | ); |
567 | - $entity_array[ Read::get_related_entity_name( $relation_name, $relation_obj ) ] = $related_results instanceof \WP_Error |
|
567 | + $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results instanceof \WP_Error |
|
568 | 568 | ? null |
569 | 569 | : $related_results; |
570 | 570 | } |
@@ -578,8 +578,8 @@ discard block |
||
578 | 578 | * @param array $arr |
579 | 579 | * @return array |
580 | 580 | */ |
581 | - private function _remove_model_names_from_array( $arr ) { |
|
582 | - return array_diff( $arr, array_keys( \EE_Registry::instance()->non_abstract_db_models ) ); |
|
581 | + private function _remove_model_names_from_array($arr) { |
|
582 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
583 | 583 | } |
584 | 584 | /** |
585 | 585 | * Gets the calculated fields for the response |
@@ -589,15 +589,15 @@ discard block |
||
589 | 589 | * @param \WP_REST_Request $rest_request |
590 | 590 | * @return array the _calculations item in the entity |
591 | 591 | */ |
592 | - protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
|
592 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) { |
|
593 | 593 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
594 | - $rest_request->get_param( 'calculate' ), |
|
594 | + $rest_request->get_param('calculate'), |
|
595 | 595 | '' |
596 | 596 | ); |
597 | 597 | //note: setting calculate=* doesn't do anything |
598 | 598 | $calculated_fields_to_return = new \stdClass(); |
599 | - foreach( $calculated_fields as $field_to_calculate ) { |
|
600 | - try{ |
|
599 | + foreach ($calculated_fields as $field_to_calculate) { |
|
600 | + try { |
|
601 | 601 | $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
602 | 602 | null, |
603 | 603 | $this->_fields_calculator->retrieve_calculated_field_value( |
@@ -609,10 +609,10 @@ discard block |
||
609 | 609 | ), |
610 | 610 | $this->get_model_version_info()->requested_version() |
611 | 611 | ); |
612 | - } catch( Rest_Exception $e ) { |
|
612 | + } catch (Rest_Exception $e) { |
|
613 | 613 | //if we don't have permission to read it, just leave it out. but let devs know about the problem |
614 | 614 | $this->_set_response_header( |
615 | - 'Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']', |
|
615 | + 'Notices-Field-Calculation-Errors['.$e->get_string_code().']['.$model->get_this_model_name().']['.$field_to_calculate.']', |
|
616 | 616 | $e->getMessage(), |
617 | 617 | true |
618 | 618 | ); |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
627 | 627 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
628 | 628 | */ |
629 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
629 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
630 | 630 | return rest_url( |
631 | 631 | \EED_Core_Rest_Api::ee_api_namespace |
632 | 632 | . $this->get_model_version_info()->requested_version() |
@@ -642,11 +642,11 @@ discard block |
||
642 | 642 | * @param \EE_Model_Relation_Base $relation_obj |
643 | 643 | * @return string |
644 | 644 | */ |
645 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
646 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
647 | - return strtolower( $relation_name ); |
|
648 | - }else{ |
|
649 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
645 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
646 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
647 | + return strtolower($relation_name); |
|
648 | + } else { |
|
649 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
650 | 650 | } |
651 | 651 | } |
652 | 652 | |
@@ -659,43 +659,43 @@ discard block |
||
659 | 659 | * @param \WP_REST_Request $request |
660 | 660 | * @return array |
661 | 661 | */ |
662 | - public function get_entity_from_model( $model, $request ) { |
|
663 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
664 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
662 | + public function get_entity_from_model($model, $request) { |
|
663 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
664 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
665 | 665 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
666 | 666 | } |
667 | 667 | $restricted_query_params = $query_params; |
668 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
669 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
670 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
671 | - if ( ! empty ( $model_rows ) ) { |
|
668 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
669 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
670 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
671 | + if ( ! empty ($model_rows)) { |
|
672 | 672 | return $this->create_entity_from_wpdb_result( |
673 | 673 | $model, |
674 | - array_shift( $model_rows ), |
|
674 | + array_shift($model_rows), |
|
675 | 675 | $request ); |
676 | 676 | } else { |
677 | 677 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
678 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
679 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
680 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
678 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
679 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
680 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
681 | 681 | //you got shafted- it existed but we didn't want to tell you! |
682 | 682 | return new \WP_Error( |
683 | 683 | 'rest_user_cannot_read', |
684 | 684 | sprintf( |
685 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
686 | - strtolower( $model->get_this_model_name() ), |
|
685 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
686 | + strtolower($model->get_this_model_name()), |
|
687 | 687 | Capabilities::get_missing_permissions_string( |
688 | 688 | $model, |
689 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
689 | + $this->validate_context($request->get_param('caps')) ) |
|
690 | 690 | ), |
691 | - array( 'status' => 403 ) |
|
691 | + array('status' => 403) |
|
692 | 692 | ); |
693 | 693 | } else { |
694 | 694 | //it's not you. It just doesn't exist |
695 | 695 | return new \WP_Error( |
696 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
697 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
698 | - array( 'status' => 404 ) |
|
696 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
697 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
698 | + array('status' => 404) |
|
699 | 699 | ); |
700 | 700 | } |
701 | 701 | } |
@@ -708,14 +708,14 @@ discard block |
||
708 | 708 | * @param string $context |
709 | 709 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
710 | 710 | */ |
711 | - public function validate_context( $context ) { |
|
712 | - if( ! $context ) { |
|
711 | + public function validate_context($context) { |
|
712 | + if ( ! $context) { |
|
713 | 713 | $context = \EEM_Base::caps_read; |
714 | 714 | } |
715 | 715 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
716 | - if( in_array( $context, $valid_contexts ) ){ |
|
716 | + if (in_array($context, $valid_contexts)) { |
|
717 | 717 | return $context; |
718 | - }else{ |
|
718 | + } else { |
|
719 | 719 | return \EEM_Base::caps_read; |
720 | 720 | } |
721 | 721 | } |
@@ -734,77 +734,77 @@ discard block |
||
734 | 734 | * that absolutely no results should be returned |
735 | 735 | * @throws \EE_Error |
736 | 736 | */ |
737 | - public function create_model_query_params( $model, $query_parameters ) { |
|
737 | + public function create_model_query_params($model, $query_parameters) { |
|
738 | 738 | $model_query_params = array( ); |
739 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
740 | - $model_query_params[ 0 ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
741 | - $query_parameters[ 'where' ], |
|
739 | + if (isset($query_parameters['where'])) { |
|
740 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
741 | + $query_parameters['where'], |
|
742 | 742 | $model, |
743 | 743 | $this->get_model_version_info()->requested_version() |
744 | 744 | ); |
745 | 745 | } |
746 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
747 | - $order_by = $query_parameters[ 'order_by' ]; |
|
748 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
749 | - $order_by = $query_parameters[ 'orderby' ]; |
|
750 | - }else{ |
|
746 | + if (isset($query_parameters['order_by'])) { |
|
747 | + $order_by = $query_parameters['order_by']; |
|
748 | + } elseif (isset($query_parameters['orderby'])) { |
|
749 | + $order_by = $query_parameters['orderby']; |
|
750 | + } else { |
|
751 | 751 | $order_by = null; |
752 | 752 | } |
753 | - if( $order_by !== null ){ |
|
754 | - $model_query_params[ 'order_by' ] = $order_by; |
|
753 | + if ($order_by !== null) { |
|
754 | + $model_query_params['order_by'] = $order_by; |
|
755 | 755 | } |
756 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
757 | - $group_by = $query_parameters[ 'group_by' ]; |
|
758 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
759 | - $group_by = $query_parameters[ 'groupby' ]; |
|
760 | - }else{ |
|
761 | - $group_by = array_keys( $model->get_combined_primary_key_fields() ); |
|
756 | + if (isset($query_parameters['group_by'])) { |
|
757 | + $group_by = $query_parameters['group_by']; |
|
758 | + } elseif (isset($query_parameters['groupby'])) { |
|
759 | + $group_by = $query_parameters['groupby']; |
|
760 | + } else { |
|
761 | + $group_by = array_keys($model->get_combined_primary_key_fields()); |
|
762 | 762 | } |
763 | - if( $group_by !== null ){ |
|
764 | - $model_query_params[ 'group_by' ] = $group_by; |
|
763 | + if ($group_by !== null) { |
|
764 | + $model_query_params['group_by'] = $group_by; |
|
765 | 765 | } |
766 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
767 | - $model_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
768 | - $query_parameters[ 'having' ], |
|
766 | + if (isset($query_parameters['having'])) { |
|
767 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
768 | + $query_parameters['having'], |
|
769 | 769 | $model, |
770 | 770 | $this->get_model_version_info()->requested_version() |
771 | 771 | ); |
772 | 772 | } |
773 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
774 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
773 | + if (isset($query_parameters['order'])) { |
|
774 | + $model_query_params['order'] = $query_parameters['order']; |
|
775 | 775 | } |
776 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
777 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
776 | + if (isset($query_parameters['mine'])) { |
|
777 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
778 | 778 | } |
779 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
779 | + if (isset($query_parameters['limit'])) { |
|
780 | 780 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
781 | - if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
|
782 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
783 | - }else { |
|
784 | - $limit_array = $query_parameters[ 'limit' ]; |
|
781 | + if ( ! is_array($query_parameters['limit'])) { |
|
782 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
783 | + } else { |
|
784 | + $limit_array = $query_parameters['limit']; |
|
785 | 785 | } |
786 | 786 | $sanitized_limit = array(); |
787 | - foreach( $limit_array as $key => $limit_part ) { |
|
788 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
787 | + foreach ($limit_array as $key => $limit_part) { |
|
788 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
789 | 789 | throw new \EE_Error( |
790 | 790 | sprintf( |
791 | - __( 'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso' ), |
|
792 | - json_encode( $query_parameters[ 'limit' ] ) |
|
791 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso'), |
|
792 | + json_encode($query_parameters['limit']) |
|
793 | 793 | ) |
794 | 794 | ); |
795 | 795 | } |
796 | - $sanitized_limit[] = (int)$limit_part; |
|
796 | + $sanitized_limit[] = (int) $limit_part; |
|
797 | 797 | } |
798 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
799 | - }else{ |
|
800 | - $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
798 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
799 | + } else { |
|
800 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
801 | 801 | } |
802 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
803 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
804 | - }else{ |
|
805 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
802 | + if (isset($query_parameters['caps'])) { |
|
803 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
804 | + } else { |
|
805 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
806 | 806 | } |
807 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
807 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | |
@@ -816,13 +816,13 @@ discard block |
||
816 | 816 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
817 | 817 | * @return array |
818 | 818 | */ |
819 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
819 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
820 | 820 | $model_ready_query_params = array(); |
821 | - foreach( $query_params as $key => $value ) { |
|
822 | - if( is_array( $value ) ) { |
|
823 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
824 | - }else{ |
|
825 | - $model_ready_query_params[ $key ] = $value; |
|
821 | + foreach ($query_params as $key => $value) { |
|
822 | + if (is_array($value)) { |
|
823 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
824 | + } else { |
|
825 | + $model_ready_query_params[$key] = $value; |
|
826 | 826 | } |
827 | 827 | } |
828 | 828 | return $model_ready_query_params; |
@@ -836,13 +836,13 @@ discard block |
||
836 | 836 | * @param $query_params |
837 | 837 | * @return array |
838 | 838 | */ |
839 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
839 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
840 | 840 | $model_ready_query_params = array(); |
841 | - foreach( $query_params as $key => $value ) { |
|
842 | - if( is_array( $value ) ) { |
|
843 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
841 | + foreach ($query_params as $key => $value) { |
|
842 | + if (is_array($value)) { |
|
843 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
844 | 844 | } else { |
845 | - $model_ready_query_params[ $key ] = $value; |
|
845 | + $model_ready_query_params[$key] = $value; |
|
846 | 846 | } |
847 | 847 | } |
848 | 848 | return $model_ready_query_params; |
@@ -857,33 +857,33 @@ discard block |
||
857 | 857 | * we only return strings starting with that and a period; if no prefix was specified |
858 | 858 | * we return all items containing NO periods |
859 | 859 | */ |
860 | - public function explode_and_get_items_prefixed_with( $string_to_explode, $prefix ) { |
|
861 | - if( is_string( $string_to_explode ) ) { |
|
862 | - $exploded_contents = explode( ',', $string_to_explode ); |
|
863 | - } else if( is_array( $string_to_explode ) ) { |
|
860 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) { |
|
861 | + if (is_string($string_to_explode)) { |
|
862 | + $exploded_contents = explode(',', $string_to_explode); |
|
863 | + } else if (is_array($string_to_explode)) { |
|
864 | 864 | $exploded_contents = $string_to_explode; |
865 | 865 | } else { |
866 | 866 | $exploded_contents = array(); |
867 | 867 | } |
868 | 868 | //if the string was empty, we want an empty array |
869 | - $exploded_contents = array_filter( $exploded_contents ); |
|
869 | + $exploded_contents = array_filter($exploded_contents); |
|
870 | 870 | $contents_with_prefix = array(); |
871 | - foreach( $exploded_contents as $item ) { |
|
872 | - $item = trim( $item ); |
|
871 | + foreach ($exploded_contents as $item) { |
|
872 | + $item = trim($item); |
|
873 | 873 | //if no prefix was provided, so we look for items with no "." in them |
874 | - if( ! $prefix ) { |
|
874 | + if ( ! $prefix) { |
|
875 | 875 | //does this item have a period? |
876 | - if( strpos( $item, '.' ) === false ) { |
|
876 | + if (strpos($item, '.') === false) { |
|
877 | 877 | //if not, then its what we're looking for |
878 | 878 | $contents_with_prefix[] = $item; |
879 | 879 | } |
880 | - } else if( strpos( $item, $prefix . '.' ) === 0 ) { |
|
880 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
881 | 881 | //this item has the prefix and a period, grab it |
882 | 882 | $contents_with_prefix[] = substr( |
883 | 883 | $item, |
884 | - strpos( $item, $prefix . '.' ) + strlen( $prefix . '.' ) |
|
884 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
885 | 885 | ); |
886 | - } else if( $item === $prefix ) { |
|
886 | + } else if ($item === $prefix) { |
|
887 | 887 | //this item is JUST the prefix |
888 | 888 | //so let's grab everything after, which is a blank string |
889 | 889 | $contents_with_prefix[] = ''; |
@@ -906,33 +906,33 @@ discard block |
||
906 | 906 | * the fields for that model, with the model's name removed from each. |
907 | 907 | * If $include_string was blank or '*' returns an empty array |
908 | 908 | */ |
909 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
910 | - if( is_array( $include_string ) ) { |
|
911 | - $include_string = implode( ',', $include_string ); |
|
909 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
910 | + if (is_array($include_string)) { |
|
911 | + $include_string = implode(',', $include_string); |
|
912 | 912 | } |
913 | - if( $include_string === '*' || $include_string === '' ) { |
|
913 | + if ($include_string === '*' || $include_string === '') { |
|
914 | 914 | return array(); |
915 | 915 | } |
916 | - $includes = explode( ',', $include_string ); |
|
916 | + $includes = explode(',', $include_string); |
|
917 | 917 | $extracted_fields_to_include = array(); |
918 | - if( $model_name ){ |
|
919 | - foreach( $includes as $field_to_include ) { |
|
920 | - $field_to_include = trim( $field_to_include ); |
|
921 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
918 | + if ($model_name) { |
|
919 | + foreach ($includes as $field_to_include) { |
|
920 | + $field_to_include = trim($field_to_include); |
|
921 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
922 | 922 | //found the model name at the exact start |
923 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
923 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
924 | 924 | $extracted_fields_to_include[] = $field_sans_model_name; |
925 | - }elseif( $field_to_include == $model_name ){ |
|
925 | + }elseif ($field_to_include == $model_name) { |
|
926 | 926 | $extracted_fields_to_include[] = '*'; |
927 | 927 | } |
928 | 928 | } |
929 | - }else{ |
|
929 | + } else { |
|
930 | 930 | //look for ones with no period |
931 | - foreach( $includes as $field_to_include ) { |
|
932 | - $field_to_include = trim( $field_to_include ); |
|
931 | + foreach ($includes as $field_to_include) { |
|
932 | + $field_to_include = trim($field_to_include); |
|
933 | 933 | if ( |
934 | - strpos( $field_to_include, '.' ) === false |
|
935 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
934 | + strpos($field_to_include, '.') === false |
|
935 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
936 | 936 | ) { |
937 | 937 | $extracted_fields_to_include[] = $field_to_include; |
938 | 938 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -69,58 +69,58 @@ discard block |
||
69 | 69 | /** |
70 | 70 | * @throws \EE_Error |
71 | 71 | */ |
72 | - public function __construct(){ |
|
73 | - if( ! $this->_model_name_extended){ |
|
72 | + public function __construct() { |
|
73 | + if ( ! $this->_model_name_extended) { |
|
74 | 74 | throw new EE_Error(sprintf(__("When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", "event_espresso"))); |
75 | 75 | } |
76 | 76 | $construct_end_action = 'AHEE__EEM_'.$this->_model_name_extended.'__construct__end'; |
77 | - if ( did_action( $construct_end_action )) { |
|
77 | + if (did_action($construct_end_action)) { |
|
78 | 78 | throw new EE_Error( |
79 | 79 | sprintf( |
80 | - __( "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", "event_espresso"), |
|
80 | + __("Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", "event_espresso"), |
|
81 | 81 | get_class($this), |
82 | 82 | $this->_model_name_extended, |
83 | 83 | $construct_end_action |
84 | 84 | ) |
85 | 85 | ); |
86 | 86 | } |
87 | - add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__tables',array($this,'add_extra_tables_on_filter')); |
|
88 | - add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__fields',array($this,'add_extra_fields_on_filter')); |
|
89 | - add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations',array($this,'add_extra_relations_on_filter')); |
|
87 | + add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__tables', array($this, 'add_extra_tables_on_filter')); |
|
88 | + add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__fields', array($this, 'add_extra_fields_on_filter')); |
|
89 | + add_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations', array($this, 'add_extra_relations_on_filter')); |
|
90 | 90 | $this->_register_extending_methods(); |
91 | 91 | } |
92 | 92 | |
93 | - public function add_extra_tables_on_filter( $existing_tables ){ |
|
94 | - $tables = array_merge( $existing_tables, $this->_extra_tables ); |
|
93 | + public function add_extra_tables_on_filter($existing_tables) { |
|
94 | + $tables = array_merge($existing_tables, $this->_extra_tables); |
|
95 | 95 | return $tables; |
96 | 96 | } |
97 | - public function add_extra_fields_on_filter($existing_fields){ |
|
98 | - if( $this->_extra_fields){ |
|
99 | - foreach($this->_extra_fields as $table_alias => $fields){ |
|
100 | - if( ! isset( $existing_fields[ $table_alias ] ) ){ |
|
101 | - $existing_fields[ $table_alias ] = array(); |
|
97 | + public function add_extra_fields_on_filter($existing_fields) { |
|
98 | + if ($this->_extra_fields) { |
|
99 | + foreach ($this->_extra_fields as $table_alias => $fields) { |
|
100 | + if ( ! isset($existing_fields[$table_alias])) { |
|
101 | + $existing_fields[$table_alias] = array(); |
|
102 | 102 | } |
103 | - $existing_fields[$table_alias] = array_merge($existing_fields[$table_alias],$this->_extra_fields[$table_alias]); |
|
103 | + $existing_fields[$table_alias] = array_merge($existing_fields[$table_alias], $this->_extra_fields[$table_alias]); |
|
104 | 104 | |
105 | 105 | } |
106 | 106 | } |
107 | 107 | return $existing_fields; |
108 | 108 | } |
109 | - public function add_extra_relations_on_filter($existing_relations){ |
|
110 | - $relations = array_merge($existing_relations,$this->_extra_relations); |
|
109 | + public function add_extra_relations_on_filter($existing_relations) { |
|
110 | + $relations = array_merge($existing_relations, $this->_extra_relations); |
|
111 | 111 | return $relations; |
112 | 112 | } |
113 | 113 | /** |
114 | 114 | * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
115 | 115 | * model extended. (Internally uses filters, and the __call magic method) |
116 | 116 | */ |
117 | - protected function _register_extending_methods(){ |
|
117 | + protected function _register_extending_methods() { |
|
118 | 118 | $all_methods = get_class_methods(get_class($this)); |
119 | - foreach($all_methods as $method_name){ |
|
120 | - if(strpos($method_name, self::extending_method_prefix) === 0){ |
|
119 | + foreach ($all_methods as $method_name) { |
|
120 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
121 | 121 | $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
122 | 122 | $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
123 | - add_filter($callback_name,array($this,self::dynamic_callback_method_prefix.$method_name_on_model),10,10); |
|
123 | + add_filter($callback_name, array($this, self::dynamic_callback_method_prefix.$method_name_on_model), 10, 10); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | } |
@@ -129,27 +129,27 @@ discard block |
||
129 | 129 | * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
130 | 130 | * model extended. (Internally uses filters, and the __call magic method) |
131 | 131 | */ |
132 | - public function deregister(){ |
|
133 | - remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__tables',array($this,'add_extra_tables_on_filter')); |
|
134 | - remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__fields',array($this,'add_extra_fields_on_filter')); |
|
135 | - remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations',array($this,'add_extra_relations_on_filter')); |
|
132 | + public function deregister() { |
|
133 | + remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__tables', array($this, 'add_extra_tables_on_filter')); |
|
134 | + remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__fields', array($this, 'add_extra_fields_on_filter')); |
|
135 | + remove_filter('FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations', array($this, 'add_extra_relations_on_filter')); |
|
136 | 136 | $all_methods = get_class_methods(get_class($this)); |
137 | - foreach($all_methods as $method_name){ |
|
138 | - if(strpos($method_name, self::extending_method_prefix) === 0){ |
|
137 | + foreach ($all_methods as $method_name) { |
|
138 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
139 | 139 | $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
140 | 140 | $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
141 | - remove_filter($callback_name,array($this,self::dynamic_callback_method_prefix.$method_name_on_model),10); |
|
141 | + remove_filter($callback_name, array($this, self::dynamic_callback_method_prefix.$method_name_on_model), 10); |
|
142 | 142 | } |
143 | 143 | } |
144 | - $model_to_reset = 'EEM_' . $this->_model_name_extended; |
|
145 | - if ( class_exists( $model_to_reset ) ) { |
|
144 | + $model_to_reset = 'EEM_'.$this->_model_name_extended; |
|
145 | + if (class_exists($model_to_reset)) { |
|
146 | 146 | $model_to_reset::reset(); |
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | 150 | |
151 | - public function __call($callback_method_name,$args){ |
|
152 | - if(strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0){ |
|
151 | + public function __call($callback_method_name, $args) { |
|
152 | + if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
153 | 153 | //it's a dynamic callback for a method name |
154 | 154 | $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
155 | 155 | $original_return_val = $args[0]; |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | $this->_ = $model_called; |
158 | 158 | $args_provided_to_method_on_model = $args[2]; |
159 | 159 | $extending_method = self::extending_method_prefix.$method_called_on_model; |
160 | - if(method_exists($this, $extending_method)){ |
|
161 | - return call_user_func_array(array($this,$extending_method), $args_provided_to_method_on_model); |
|
162 | - }else{ |
|
163 | - throw new EE_Error(sprintf(__("An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", "event_espresso"),$this->_model_name_extended,get_class($this),$extending_method,$extending_method)); |
|
160 | + if (method_exists($this, $extending_method)) { |
|
161 | + return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
|
162 | + } else { |
|
163 | + throw new EE_Error(sprintf(__("An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", "event_espresso"), $this->_model_name_extended, get_class($this), $extending_method, $extending_method)); |
|
164 | 164 | } |
165 | 165 | |
166 | - }else{ |
|
167 | - throw new EE_Error(sprintf(__("There is no method named '%s' on '%s'", "event_espresso"),$callback_method_name,get_class($this))); |
|
166 | + } else { |
|
167 | + throw new EE_Error(sprintf(__("There is no method named '%s' on '%s'", "event_espresso"), $callback_method_name, get_class($this))); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 |