@@ -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 |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | * Returns the name of the field's name that points to the WP_User table |
742 | 742 | * on this model (or follows the _model_chain_to_wp_user and uses that model's |
743 | 743 | * foreign key to the WP_User table) |
744 | - * @return string|boolean string on success, boolean false when there is no |
|
744 | + * @return string|false string on success, boolean false when there is no |
|
745 | 745 | * foreign key to the WP_User table |
746 | 746 | */ |
747 | 747 | function wp_user_field_name() { |
@@ -837,6 +837,7 @@ discard block |
||
837 | 837 | * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array. |
838 | 838 | * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection |
839 | 839 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
840 | + * @param string $columns_to_select |
|
840 | 841 | * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
841 | 842 | */ |
842 | 843 | public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
@@ -1139,7 +1140,7 @@ discard block |
||
1139 | 1140 | * @param bool $pretty Whether to return the pretty formats (true) or not (false). |
1140 | 1141 | * @throws EE_Error If the given field_name is not of the EE_Datetime_Field type. |
1141 | 1142 | * |
1142 | - * @return array formats in an array with the date format first, and the time format last. |
|
1143 | + * @return string[] formats in an array with the date format first, and the time format last. |
|
1143 | 1144 | */ |
1144 | 1145 | public function get_formats_for( $field_name, $pretty = false ) { |
1145 | 1146 | $field_settings = $this->field_settings_for( $field_name ); |
@@ -1174,7 +1175,7 @@ discard block |
||
1174 | 1175 | * |
1175 | 1176 | * @throws EE_Error If the given field_name is not of the EE_Datetime_Field type. |
1176 | 1177 | * |
1177 | - * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
|
1178 | + * @return string|null If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
|
1178 | 1179 | * exception is triggered. |
1179 | 1180 | */ |
1180 | 1181 | public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
@@ -1474,7 +1475,7 @@ discard block |
||
1474 | 1475 | * Deletes a single row from the DB given the model object's primary key value. (eg, EE_Attendee->ID()'s value). |
1475 | 1476 | * Wrapper for EEM_Base::delete() |
1476 | 1477 | * @param mixed $id |
1477 | - * @return boolean whether the row got deleted or not |
|
1478 | + * @return integer whether the row got deleted or not |
|
1478 | 1479 | */ |
1479 | 1480 | public function delete_by_ID( $id ){ |
1480 | 1481 | return $this->delete( array( |
@@ -1834,7 +1835,7 @@ discard block |
||
1834 | 1835 | /** |
1835 | 1836 | * Verifies the EE addons' database is up-to-date and records that we've done it on |
1836 | 1837 | * EEM_Base::$_db_verification_level |
1837 | - * @param $wpdb_method |
|
1838 | + * @param string $wpdb_method |
|
1838 | 1839 | * @param $arguments_to_provide |
1839 | 1840 | * @return string |
1840 | 1841 | */ |
@@ -1902,7 +1903,6 @@ discard block |
||
1902 | 1903 | * 'hasAndBelongsToMany' relationships: checks that there isn't already an entry in the join table, and adds one. |
1903 | 1904 | * If one of the model Objects has not yet been saved to the database, it is saved before adding the entry in the join table |
1904 | 1905 | * |
1905 | - * @param EE_Base_Class/int $thisModelObject |
|
1906 | 1906 | * @param EE_Base_Class/int $id_or_obj EE_base_Class or ID of other Model Object |
1907 | 1907 | * @param string $relationName, key in EEM_Base::_relations |
1908 | 1908 | * an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id') |
@@ -1924,8 +1924,8 @@ discard block |
||
1924 | 1924 | * |
1925 | 1925 | * 'hasAndBelongsToMany' relationships:removes any existing entry in the join table between the two models. |
1926 | 1926 | * |
1927 | - * @param EE_Base_Class/int $id_or_obj |
|
1928 | - * @param EE_Base_Class/int $other_model_id_or_obj EE_Base_Class or ID of other Model Object |
|
1927 | + * @param EE_CPT_Base $id_or_obj |
|
1928 | + * @param EE_Term_Taxonomy $other_model_id_or_obj EE_Base_Class or ID of other Model Object |
|
1929 | 1929 | * @param string $relationName key in EEM_Base::_relations |
1930 | 1930 | * @return boolean of success |
1931 | 1931 | * @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. |
@@ -2001,7 +2001,7 @@ discard block |
||
2001 | 2001 | /** |
2002 | 2002 | * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
2003 | 2003 | * unless otherwise specified in the $query_params |
2004 | - * @param int/EE_Base_Class $id_or_obj |
|
2004 | + * @param EE_Event $id_or_obj |
|
2005 | 2005 | * @param string $model_name like 'Event', or 'Registration' |
2006 | 2006 | * @param array $query_params like EEM_Base::get_all's |
2007 | 2007 | * @param string $field_to_count name of field to count by. By default, uses primary key |
@@ -2390,7 +2390,7 @@ discard block |
||
2390 | 2390 | /** |
2391 | 2391 | * Finds all the fields that correspond to the given table |
2392 | 2392 | * @param string $table_alias, array key in EEM_Base::_tables |
2393 | - * @return EE_Model_Field_Base[] |
|
2393 | + * @return EE_Model_Field_Base |
|
2394 | 2394 | */ |
2395 | 2395 | function _get_fields_for_table($table_alias){ |
2396 | 2396 | return $this->_fields[$table_alias]; |
@@ -3454,8 +3454,8 @@ discard block |
||
3454 | 3454 | /** |
3455 | 3455 | * gets the field object of type 'primary_key' from the fieldsSettings attribute. |
3456 | 3456 | * Eg, on EE_Answer that would be ANS_ID field object |
3457 | - * @param $field_obj |
|
3458 | - * @return EE_Model_Field_Base |
|
3457 | + * @param EE_Model_Field_Base $field_obj |
|
3458 | + * @return boolean |
|
3459 | 3459 | */ |
3460 | 3460 | public function is_primary_key_field( $field_obj ){ |
3461 | 3461 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
@@ -3549,7 +3549,7 @@ discard block |
||
3549 | 3549 | * Gets the actual table for the table alias |
3550 | 3550 | * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe |
3551 | 3551 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3552 | - * @return EE_Table_Base |
|
3552 | + * @return string |
|
3553 | 3553 | */ |
3554 | 3554 | function get_table_for_alias($table_alias){ |
3555 | 3555 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
@@ -3676,7 +3676,7 @@ discard block |
||
3676 | 3676 | * The purpose of this method is to allow us to create a model object that is not in the db that holds default values. |
3677 | 3677 | * A typical example of where this is used is when creating a new item and the initial load of a form. We dont' necessarily want to test for if the object is present but just assume it is BUT load the defaults from the object (as set in the model_field!). |
3678 | 3678 | * |
3679 | - * @return EE_Base_Class single EE_Base_Class object with default values for the properties. |
|
3679 | + * @return boolean single EE_Base_Class object with default values for the properties. |
|
3680 | 3680 | */ |
3681 | 3681 | public function create_default_object() { |
3682 | 3682 | |
@@ -3800,7 +3800,7 @@ discard block |
||
3800 | 3800 | * returns an array of their corresponding field names and database values |
3801 | 3801 | * |
3802 | 3802 | * @param string $cols_n_values |
3803 | - * @return array |
|
3803 | + * @return string |
|
3804 | 3804 | */ |
3805 | 3805 | protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
3806 | 3806 | $this_model_fields_n_values = array(); |
@@ -4061,7 +4061,7 @@ discard block |
||
4061 | 4061 | } |
4062 | 4062 | /** |
4063 | 4063 | * Read comments for assume_values_already_prepared_by_model_object() |
4064 | - * @return int |
|
4064 | + * @return boolean |
|
4065 | 4065 | */ |
4066 | 4066 | public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
4067 | 4067 | return $this->_values_already_prepared_by_model_object; |
@@ -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 |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * Flag indicating whether this model has a primary key or not |
229 | 229 | * @var boolean |
230 | 230 | */ |
231 | - protected $_has_primary_key_field=null; |
|
231 | + protected $_has_primary_key_field = null; |
|
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Whether or not this model is based off a table in WP core only (CPTs should set |
@@ -283,19 +283,19 @@ discard block |
||
283 | 283 | * operators that work like 'BETWEEN'. Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'" |
284 | 284 | * @var array |
285 | 285 | */ |
286 | - protected $_between_style_operators = array( 'BETWEEN' ); |
|
286 | + protected $_between_style_operators = array('BETWEEN'); |
|
287 | 287 | |
288 | 288 | /** |
289 | 289 | * operators that are used for handling NUll and !NULL queries. Typically used for when checking if a row exists on a join table. |
290 | 290 | * @var array |
291 | 291 | */ |
292 | - protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL'); |
|
292 | + protected $_null_style_operators = array('IS NOT NULL', 'IS NULL'); |
|
293 | 293 | |
294 | 294 | /** |
295 | 295 | * Allowed values for $query_params['order'] for ordering in queries |
296 | 296 | * @var array |
297 | 297 | */ |
298 | - protected $_allowed_order_values = array('asc','desc','ASC','DESC'); |
|
298 | + protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC'); |
|
299 | 299 | |
300 | 300 | /** |
301 | 301 | * When these are keys in a WHERE or HAVING clause, they are handled much differently |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | * 'where', but 'where' clauses are so common that we thought we'd omit it |
310 | 310 | * @var array |
311 | 311 | */ |
312 | - private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps'); |
|
312 | + private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps'); |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * All the data types that can be used in $wpdb->prepare statements. |
316 | 316 | * @var array |
317 | 317 | */ |
318 | - private $_valid_wpdb_data_types = array('%d','%s','%f'); |
|
318 | + private $_valid_wpdb_data_types = array('%d', '%s', '%f'); |
|
319 | 319 | |
320 | 320 | /** |
321 | 321 | * EE_Registry Object |
@@ -348,17 +348,17 @@ discard block |
||
348 | 348 | /** |
349 | 349 | * constant used to show EEM_Base has not yet verified the db on this http request |
350 | 350 | */ |
351 | - const db_verified_none = 0; |
|
351 | + const db_verified_none = 0; |
|
352 | 352 | /** |
353 | 353 | * constant used to show EEM_Base has verified the EE core db on this http request, |
354 | 354 | * but not the addons' dbs |
355 | 355 | */ |
356 | - const db_verified_core = 1; |
|
356 | + const db_verified_core = 1; |
|
357 | 357 | /** |
358 | 358 | * constant used to show EEM_Base has verified the addons' dbs (and implicitly |
359 | 359 | * the EE core db too) |
360 | 360 | */ |
361 | - const db_verified_addons = 2; |
|
361 | + const db_verified_addons = 2; |
|
362 | 362 | |
363 | 363 | /** |
364 | 364 | * indicates whether an EEM_Base child has already re-verified the DB |
@@ -389,13 +389,13 @@ discard block |
||
389 | 389 | * @param null $timezone |
390 | 390 | * @throws \EE_Error |
391 | 391 | */ |
392 | - protected function __construct( $timezone = NULL ){ |
|
392 | + protected function __construct($timezone = NULL) { |
|
393 | 393 | // check that the model has not been loaded too soon |
394 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) { |
|
395 | - throw new EE_Error ( |
|
394 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons')) { |
|
395 | + throw new EE_Error( |
|
396 | 396 | sprintf( |
397 | - __( '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' ), |
|
398 | - get_class( $this ) |
|
397 | + __('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'), |
|
398 | + get_class($this) |
|
399 | 399 | ) |
400 | 400 | ); |
401 | 401 | } |
@@ -405,11 +405,11 @@ discard block |
||
405 | 405 | * just use EE_Register_Model_Extension |
406 | 406 | * @var EE_Table_Base[] $_tables |
407 | 407 | */ |
408 | - $this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables ); |
|
409 | - foreach($this->_tables as $table_alias => $table_obj){ |
|
408 | + $this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables); |
|
409 | + foreach ($this->_tables as $table_alias => $table_obj) { |
|
410 | 410 | /** @var $table_obj EE_Table_Base */ |
411 | 411 | $table_obj->_construct_finalize_with_alias($table_alias); |
412 | - if( $table_obj instanceof EE_Secondary_Table ){ |
|
412 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
413 | 413 | /** @var $table_obj EE_Secondary_Table */ |
414 | 414 | $table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table()); |
415 | 415 | } |
@@ -419,48 +419,48 @@ discard block |
||
419 | 419 | * EE_Register_Model_Extension |
420 | 420 | * @param EE_Model_Field_Base[] $_fields |
421 | 421 | */ |
422 | - $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields); |
|
423 | - foreach($this->_fields as $table_alias => $fields_for_table){ |
|
424 | - if ( ! array_key_exists( $table_alias, $this->_tables )){ |
|
425 | - 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))); |
|
422 | + $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields); |
|
423 | + foreach ($this->_fields as $table_alias => $fields_for_table) { |
|
424 | + if ( ! array_key_exists($table_alias, $this->_tables)) { |
|
425 | + 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))); |
|
426 | 426 | } |
427 | - foreach($fields_for_table as $field_name => $field_obj){ |
|
427 | + foreach ($fields_for_table as $field_name => $field_obj) { |
|
428 | 428 | /** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */ |
429 | 429 | //primary key field base has a slightly different _construct_finalize |
430 | 430 | /** @var $field_obj EE_Model_Field_Base */ |
431 | - $field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() ); |
|
431 | + $field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name()); |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | |
435 | 435 | // everything is related to Extra_Meta |
436 | - if( get_class($this) != 'EEM_Extra_Meta'){ |
|
436 | + if (get_class($this) != 'EEM_Extra_Meta') { |
|
437 | 437 | //make extra meta related to everything, but don't block deleting things just |
438 | 438 | //because they have related extra meta info. For now just orphan those extra meta |
439 | 439 | //in the future we should automatically delete them |
440 | - $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE ); |
|
440 | + $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE); |
|
441 | 441 | } |
442 | 442 | //and change logs |
443 | - if( get_class( $this) != 'EEM_Change_Log' ) { |
|
444 | - $this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE ); |
|
443 | + if (get_class($this) != 'EEM_Change_Log') { |
|
444 | + $this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE); |
|
445 | 445 | } |
446 | 446 | /** |
447 | 447 | * Filters the list of relations on a model. It is best to NOT use this directly and instead just use |
448 | 448 | * EE_Register_Model_Extension |
449 | 449 | * @param EE_Model_Relation_Base[] $_model_relations |
450 | 450 | */ |
451 | - $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations); |
|
452 | - foreach($this->_model_relations as $model_name => $relation_obj){ |
|
451 | + $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations); |
|
452 | + foreach ($this->_model_relations as $model_name => $relation_obj) { |
|
453 | 453 | /** @var $relation_obj EE_Model_Relation_Base */ |
454 | 454 | $relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name); |
455 | 455 | } |
456 | - foreach($this->_indexes as $index_name => $index_obj){ |
|
456 | + foreach ($this->_indexes as $index_name => $index_obj) { |
|
457 | 457 | /** @var $index_obj EE_Index */ |
458 | 458 | $index_obj->_construct_finalize($index_name, $this->get_this_model_name()); |
459 | 459 | } |
460 | 460 | |
461 | 461 | $this->set_timezone($timezone); |
462 | 462 | //finalize default where condition strategy, or set default |
463 | - if( ! $this->_default_where_conditions_strategy){ |
|
463 | + if ( ! $this->_default_where_conditions_strategy) { |
|
464 | 464 | //nothing was set during child constructor, so set default |
465 | 465 | $this->_default_where_conditions_strategy = new EE_Default_Where_Conditions(); |
466 | 466 | } |
@@ -468,15 +468,15 @@ discard block |
||
468 | 468 | |
469 | 469 | //if the cap slug hasn't been set, and we haven't set it to false on purpose |
470 | 470 | //to indicate to NOT set it, set it to the logical default |
471 | - if( $this->_caps_slug === null ) { |
|
472 | - EE_Registry::instance()->load_helper( 'Inflector' ); |
|
473 | - $this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() ); |
|
471 | + if ($this->_caps_slug === null) { |
|
472 | + EE_Registry::instance()->load_helper('Inflector'); |
|
473 | + $this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name()); |
|
474 | 474 | } |
475 | 475 | //initialize the standard cap restriction generators if none were specified by the child constructor |
476 | - if( $this->_cap_restriction_generators !== false ){ |
|
477 | - foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){ |
|
478 | - if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) { |
|
479 | - $this->_cap_restriction_generators[ $cap_context ] = apply_filters( |
|
476 | + if ($this->_cap_restriction_generators !== false) { |
|
477 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
478 | + if ( ! isset($this->_cap_restriction_generators[$cap_context])) { |
|
479 | + $this->_cap_restriction_generators[$cap_context] = apply_filters( |
|
480 | 480 | 'FHEE__EEM_Base___construct__standard_cap_restriction_generator', |
481 | 481 | new EE_Restriction_Generator_Protected(), |
482 | 482 | $cap_context, |
@@ -486,23 +486,23 @@ discard block |
||
486 | 486 | } |
487 | 487 | } |
488 | 488 | //if there are cap restriction generators, use them to make the default cap restrictions |
489 | - if( $this->_cap_restriction_generators !== false ){ |
|
490 | - foreach( $this->_cap_restriction_generators as $context => $generator_object ) { |
|
491 | - if( ! $generator_object ){ |
|
489 | + if ($this->_cap_restriction_generators !== false) { |
|
490 | + foreach ($this->_cap_restriction_generators as $context => $generator_object) { |
|
491 | + if ( ! $generator_object) { |
|
492 | 492 | continue; |
493 | 493 | } |
494 | - if( ! $generator_object instanceof EE_Restriction_Generator_Base ){ |
|
494 | + if ( ! $generator_object instanceof EE_Restriction_Generator_Base) { |
|
495 | 495 | throw new EE_Error( |
496 | 496 | sprintf( |
497 | - __( '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' ), |
|
497 | + __('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'), |
|
498 | 498 | $context, |
499 | 499 | $this->get_this_model_name() |
500 | 500 | ) |
501 | 501 | ); |
502 | 502 | } |
503 | - $action = $this->cap_action_for_context( $context ); |
|
504 | - if( ! $generator_object->construction_finalized() ){ |
|
505 | - $generator_object->_construct_finalize( $this, $action ); |
|
503 | + $action = $this->cap_action_for_context($context); |
|
504 | + if ( ! $generator_object->construction_finalized()) { |
|
505 | + $generator_object->_construct_finalize($this, $action); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | } |
@@ -516,11 +516,11 @@ discard block |
||
516 | 516 | * @param string $context one of EEM_Base::valid_cap_contexts() |
517 | 517 | * @return EE_Default_Where_Conditions[] |
518 | 518 | */ |
519 | - protected function _generate_cap_restrictions( $context ){ |
|
520 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
521 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
|
522 | - return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
|
523 | - }else{ |
|
519 | + protected function _generate_cap_restrictions($context) { |
|
520 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
521 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) { |
|
522 | + return $this->_cap_restriction_generators[$context]->generate_restrictions(); |
|
523 | + } else { |
|
524 | 524 | return array(); |
525 | 525 | } |
526 | 526 | } |
@@ -533,16 +533,16 @@ discard block |
||
533 | 533 | * @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) |
534 | 534 | * @return static (as in the concrete child class) |
535 | 535 | */ |
536 | - public static function instance( $timezone = NULL ){ |
|
536 | + public static function instance($timezone = NULL) { |
|
537 | 537 | |
538 | 538 | // check if instance of Espresso_model already exists |
539 | 539 | if ( ! static::$_instance instanceof static) { |
540 | 540 | // instantiate Espresso_model |
541 | - static::$_instance = new static( $timezone ); |
|
541 | + static::$_instance = new static($timezone); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | //we might have a timezone set, let set_timezone decide what to do with it |
545 | - static::$_instance->set_timezone( $timezone ); |
|
545 | + static::$_instance->set_timezone($timezone); |
|
546 | 546 | |
547 | 547 | // Espresso_model object |
548 | 548 | return static::$_instance; |
@@ -555,11 +555,11 @@ discard block |
||
555 | 555 | * @param null | string $timezone |
556 | 556 | * @return static |
557 | 557 | */ |
558 | - public static function reset( $timezone = NULL ){ |
|
559 | - if ( ! is_null( static::$_instance ) ) { |
|
558 | + public static function reset($timezone = NULL) { |
|
559 | + if ( ! is_null(static::$_instance)) { |
|
560 | 560 | static::$_instance = null; |
561 | 561 | |
562 | - return self::instance( $timezone ); |
|
562 | + return self::instance($timezone); |
|
563 | 563 | } |
564 | 564 | return null; |
565 | 565 | } |
@@ -570,15 +570,15 @@ discard block |
||
570 | 570 | * @param boolean $translated return localized strings or JUST the array. |
571 | 571 | * @return array |
572 | 572 | */ |
573 | - public function status_array( $translated = FALSE ) { |
|
574 | - if ( !array_key_exists('Status', $this->_model_relations ) ) |
|
573 | + public function status_array($translated = FALSE) { |
|
574 | + if ( ! array_key_exists('Status', $this->_model_relations)) |
|
575 | 575 | return array(); |
576 | 576 | $model_name = $this->get_this_model_name(); |
577 | - $status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) ); |
|
578 | - $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
|
577 | + $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name))); |
|
578 | + $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type))); |
|
579 | 579 | $status_array = array(); |
580 | - foreach ( $stati as $status ) { |
|
581 | - $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
580 | + foreach ($stati as $status) { |
|
581 | + $status_array[$status->ID()] = $status->get('STS_code'); |
|
582 | 582 | } |
583 | 583 | return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
584 | 584 | } |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | * 'order_by'=>array('ANS_value'=>'ASC') |
720 | 720 | * )); |
721 | 721 | */ |
722 | - function get_all($query_params = array()){ |
|
722 | + function get_all($query_params = array()) { |
|
723 | 723 | return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL)); |
724 | 724 | } |
725 | 725 | |
@@ -729,10 +729,10 @@ discard block |
||
729 | 729 | * @param array $query_params @see EEM_Base::get_all() |
730 | 730 | * @return array like EEM_Base::get_all |
731 | 731 | */ |
732 | - function alter_query_params_to_only_include_mine( $query_params = array() ) { |
|
732 | + function alter_query_params_to_only_include_mine($query_params = array()) { |
|
733 | 733 | $wp_user_field_name = $this->wp_user_field_name(); |
734 | - if( $wp_user_field_name ){ |
|
735 | - $query_params[0][ $wp_user_field_name ] = get_current_user_id(); |
|
734 | + if ($wp_user_field_name) { |
|
735 | + $query_params[0][$wp_user_field_name] = get_current_user_id(); |
|
736 | 736 | } |
737 | 737 | return $query_params; |
738 | 738 | } |
@@ -745,19 +745,19 @@ discard block |
||
745 | 745 | * foreign key to the WP_User table |
746 | 746 | */ |
747 | 747 | function wp_user_field_name() { |
748 | - try{ |
|
749 | - if( ! empty( $this->_model_chain_to_wp_user ) ) { |
|
750 | - $models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user ); |
|
751 | - $last_model_name = end( $models_to_follow_to_wp_users ); |
|
752 | - $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
|
753 | - $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
|
754 | - }else{ |
|
748 | + try { |
|
749 | + if ( ! empty($this->_model_chain_to_wp_user)) { |
|
750 | + $models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user); |
|
751 | + $last_model_name = end($models_to_follow_to_wp_users); |
|
752 | + $model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name); |
|
753 | + $model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.'; |
|
754 | + } else { |
|
755 | 755 | $model_with_fk_to_wp_users = $this; |
756 | 756 | $model_chain_to_wp_user = ''; |
757 | 757 | } |
758 | - $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
|
759 | - return $model_chain_to_wp_user . $wp_user_field->get_name(); |
|
760 | - }catch( EE_Error $e ) { |
|
758 | + $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User'); |
|
759 | + return $model_chain_to_wp_user.$wp_user_field->get_name(); |
|
760 | + } catch (EE_Error $e) { |
|
761 | 761 | return false; |
762 | 762 | } |
763 | 763 | } |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | * (or transiently-related model) |
772 | 772 | * @return string |
773 | 773 | */ |
774 | - public function model_chain_to_wp_user(){ |
|
774 | + public function model_chain_to_wp_user() { |
|
775 | 775 | return $this->_model_chain_to_wp_user; |
776 | 776 | } |
777 | 777 | |
@@ -783,13 +783,13 @@ discard block |
||
783 | 783 | * @return boolean |
784 | 784 | */ |
785 | 785 | public function is_owned() { |
786 | - if( $this->model_chain_to_wp_user() ){ |
|
786 | + if ($this->model_chain_to_wp_user()) { |
|
787 | 787 | return true; |
788 | - }else{ |
|
789 | - try{ |
|
790 | - $this->get_foreign_key_to( 'WP_User' ); |
|
788 | + } else { |
|
789 | + try { |
|
790 | + $this->get_foreign_key_to('WP_User'); |
|
791 | 791 | return true; |
792 | - }catch( EE_Error $e ){ |
|
792 | + } catch (EE_Error $e) { |
|
793 | 793 | return false; |
794 | 794 | } |
795 | 795 | } |
@@ -808,21 +808,21 @@ discard block |
||
808 | 808 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
809 | 809 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
810 | 810 | */ |
811 | - protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
811 | + protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
812 | 812 | //remember the custom selections, if any |
813 | - if(is_array($columns_to_select)){ |
|
813 | + if (is_array($columns_to_select)) { |
|
814 | 814 | $this->_custom_selections = $columns_to_select; |
815 | - }elseif(is_string($columns_to_select)){ |
|
815 | + }elseif (is_string($columns_to_select)) { |
|
816 | 816 | $this->_custom_selections = array($this->_custom_selections); |
817 | - }else{ |
|
817 | + } else { |
|
818 | 818 | $this->_custom_selections = array(); |
819 | 819 | } |
820 | 820 | |
821 | 821 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
822 | 822 | $select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info); |
823 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
823 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
824 | 824 | // echo "sql:$SQL"; |
825 | - $results = $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output); |
|
825 | + $results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output); |
|
826 | 826 | return $results; |
827 | 827 | } |
828 | 828 | |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
840 | 840 | * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
841 | 841 | */ |
842 | - public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
842 | + public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
843 | 843 | return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select); |
844 | 844 | } |
845 | 845 | |
@@ -851,21 +851,21 @@ discard block |
||
851 | 851 | * @throws EE_Error |
852 | 852 | * @return string |
853 | 853 | */ |
854 | - private function _construct_select_from_input($columns_to_select){ |
|
855 | - if(is_array($columns_to_select)){ |
|
854 | + private function _construct_select_from_input($columns_to_select) { |
|
855 | + if (is_array($columns_to_select)) { |
|
856 | 856 | $select_sql_array = array(); |
857 | 857 | |
858 | - foreach($columns_to_select as $alias => $selection_and_datatype){ |
|
859 | - if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){ |
|
860 | - throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"),$selection_and_datatype,$alias)); |
|
858 | + foreach ($columns_to_select as $alias => $selection_and_datatype) { |
|
859 | + if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) { |
|
860 | + throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"), $selection_and_datatype, $alias)); |
|
861 | 861 | } |
862 | - if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){ |
|
863 | - throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"),$selection_and_datatype[1],$selection_and_datatype[0],$alias,implode(",",$this->_valid_wpdb_data_types))); |
|
862 | + if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) { |
|
863 | + throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"), $selection_and_datatype[1], $selection_and_datatype[0], $alias, implode(",", $this->_valid_wpdb_data_types))); |
|
864 | 864 | } |
865 | 865 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
866 | 866 | } |
867 | - $columns_to_select_string = implode(", ",$select_sql_array); |
|
868 | - }else{ |
|
867 | + $columns_to_select_string = implode(", ", $select_sql_array); |
|
868 | + } else { |
|
869 | 869 | $columns_to_select_string = $columns_to_select; |
870 | 870 | } |
871 | 871 | return $columns_to_select_string; |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID' |
879 | 879 | * @return string |
880 | 880 | */ |
881 | - function primary_key_name(){ |
|
881 | + function primary_key_name() { |
|
882 | 882 | return $this->get_primary_key_field()->get_name(); |
883 | 883 | } |
884 | 884 | |
@@ -890,15 +890,15 @@ discard block |
||
890 | 890 | * @param mixed $id int or string, depending on the type of the model's primary key |
891 | 891 | * @return EE_Base_Class |
892 | 892 | */ |
893 | - function get_one_by_ID($id){ |
|
894 | - if( $this->get_from_entity_map( $id ) ){ |
|
895 | - return $this->get_from_entity_map( $id ); |
|
896 | - }elseif( $this->has_primary_key_field ( ) ) { |
|
893 | + function get_one_by_ID($id) { |
|
894 | + if ($this->get_from_entity_map($id)) { |
|
895 | + return $this->get_from_entity_map($id); |
|
896 | + }elseif ($this->has_primary_key_field( )) { |
|
897 | 897 | $primary_key_name = $this->get_primary_key_field()->get_name(); |
898 | 898 | return $this->get_one(array(array($primary_key_name => $id))); |
899 | - }else{ |
|
899 | + } else { |
|
900 | 900 | //no primary key, so the $id must be from the get_index_primary_key_string() |
901 | - return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) ); |
|
901 | + return $this->get_one(array($this->parse_index_primary_key_string($id))); |
|
902 | 902 | } |
903 | 903 | } |
904 | 904 | |
@@ -909,16 +909,16 @@ discard block |
||
909 | 909 | * @param array $query_params like EEM_Base's $query_params variable. |
910 | 910 | * @return EE_Base_Class | NULL |
911 | 911 | */ |
912 | - function get_one($query_params = array()){ |
|
913 | - if( ! is_array( $query_params ) ){ |
|
914 | - 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' ); |
|
912 | + function get_one($query_params = array()) { |
|
913 | + if ( ! is_array($query_params)) { |
|
914 | + 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'); |
|
915 | 915 | $query_params = array(); |
916 | 916 | } |
917 | 917 | $query_params['limit'] = 1; |
918 | 918 | $items = $this->get_all($query_params); |
919 | - if(empty($items)){ |
|
919 | + if (empty($items)) { |
|
920 | 920 | return null; |
921 | - }else{ |
|
921 | + } else { |
|
922 | 922 | return array_shift($items); |
923 | 923 | } |
924 | 924 | } |
@@ -942,8 +942,8 @@ discard block |
||
942 | 942 | * |
943 | 943 | * @return EE_Base_Class[]|array |
944 | 944 | */ |
945 | - public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
946 | - return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
945 | + public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
946 | + return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | |
@@ -966,8 +966,8 @@ discard block |
||
966 | 966 | * |
967 | 967 | * @return EE_Base_Class[]|array |
968 | 968 | */ |
969 | - public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
970 | - return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
969 | + public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
970 | + return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | |
@@ -989,9 +989,9 @@ discard block |
||
989 | 989 | * |
990 | 990 | * @return EE_Base_Class|null|array() |
991 | 991 | */ |
992 | - public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
993 | - $results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
994 | - return empty( $results ) ? null : reset( $results ); |
|
992 | + public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
993 | + $results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
994 | + return empty($results) ? null : reset($results); |
|
995 | 995 | } |
996 | 996 | |
997 | 997 | |
@@ -1013,9 +1013,9 @@ discard block |
||
1013 | 1013 | * |
1014 | 1014 | * @return EE_Base_Class|null|array() |
1015 | 1015 | */ |
1016 | - public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1017 | - $results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1018 | - return empty( $results ) ? null : reset( $results ); |
|
1016 | + public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1017 | + $results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1018 | + return empty($results) ? null : reset($results); |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | |
@@ -1041,40 +1041,40 @@ discard block |
||
1041 | 1041 | * @return EE_Base_Class[]|array |
1042 | 1042 | * @throws EE_Error |
1043 | 1043 | */ |
1044 | - protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1044 | + protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1045 | 1045 | //if $field_to_order_by is empty then let's assume we're ordering by the primary key. |
1046 | - if ( empty( $field_to_order_by ) ) { |
|
1047 | - if ( $this->has_primary_key_field() ) { |
|
1046 | + if (empty($field_to_order_by)) { |
|
1047 | + if ($this->has_primary_key_field()) { |
|
1048 | 1048 | $field_to_order_by = $this->get_primary_key_field()->get_name(); |
1049 | 1049 | } else { |
1050 | 1050 | |
1051 | - if ( WP_DEBUG ) { |
|
1052 | - 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' ) ); |
|
1051 | + if (WP_DEBUG) { |
|
1052 | + 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')); |
|
1053 | 1053 | } |
1054 | - EE_Error::add_error( __('There was an error with the query.', 'event_espresso') ); |
|
1054 | + EE_Error::add_error(__('There was an error with the query.', 'event_espresso')); |
|
1055 | 1055 | return array(); |
1056 | 1056 | } |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - if( ! is_array( $query_params ) ){ |
|
1060 | - 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' ); |
|
1059 | + if ( ! is_array($query_params)) { |
|
1060 | + 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'); |
|
1061 | 1061 | $query_params = array(); |
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | //let's add the where query param for consecutive look up. |
1065 | - $query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value ); |
|
1065 | + $query_params[0][$field_to_order_by] = array($operand, $current_field_value); |
|
1066 | 1066 | $query_params['limit'] = $limit; |
1067 | 1067 | |
1068 | 1068 | //set direction |
1069 | - $incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array(); |
|
1070 | - $query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby; |
|
1069 | + $incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array(); |
|
1070 | + $query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby; |
|
1071 | 1071 | |
1072 | 1072 | //if $columns_to_select is empty then that means we're returning EE_Base_Class objects |
1073 | - if ( empty( $columns_to_select ) ) { |
|
1074 | - return $this->get_all( $query_params ); |
|
1073 | + if (empty($columns_to_select)) { |
|
1074 | + return $this->get_all($query_params); |
|
1075 | 1075 | } else { |
1076 | 1076 | //getting just the fields |
1077 | - return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select ); |
|
1077 | + return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select); |
|
1078 | 1078 | } |
1079 | 1079 | } |
1080 | 1080 | |
@@ -1085,18 +1085,18 @@ discard block |
||
1085 | 1085 | * This sets the _timezone property after model object has been instantiated. |
1086 | 1086 | * @param null | string $timezone valid PHP DateTimeZone timezone string |
1087 | 1087 | */ |
1088 | - public function set_timezone( $timezone ) { |
|
1089 | - if ( $timezone !== null ) { |
|
1088 | + public function set_timezone($timezone) { |
|
1089 | + if ($timezone !== null) { |
|
1090 | 1090 | $this->_timezone = $timezone; |
1091 | 1091 | } |
1092 | 1092 | //note we need to loop through relations and set the timezone on those objects as well. |
1093 | - foreach ( $this->_model_relations as $relation ) { |
|
1094 | - $relation->set_timezone( $timezone ); |
|
1093 | + foreach ($this->_model_relations as $relation) { |
|
1094 | + $relation->set_timezone($timezone); |
|
1095 | 1095 | } |
1096 | 1096 | //and finally we do the same for any datetime fields |
1097 | - foreach ( $this->_fields as $field ) { |
|
1098 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1099 | - $field->set_timezone( $timezone ); |
|
1097 | + foreach ($this->_fields as $field) { |
|
1098 | + if ($field instanceof EE_Datetime_Field) { |
|
1099 | + $field->set_timezone($timezone); |
|
1100 | 1100 | } |
1101 | 1101 | } |
1102 | 1102 | } |
@@ -1111,9 +1111,9 @@ discard block |
||
1111 | 1111 | */ |
1112 | 1112 | public function get_timezone() { |
1113 | 1113 | //first validate if timezone is set. If not, then let's set it be whatever is set on the model fields. |
1114 | - if ( empty( $this->_timezone ) ) { |
|
1115 | - foreach( $this->_fields as $field ) { |
|
1116 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1114 | + if (empty($this->_timezone)) { |
|
1115 | + foreach ($this->_fields as $field) { |
|
1116 | + if ($field instanceof EE_Datetime_Field) { |
|
1117 | 1117 | $this->set_timezone($field->get_timezone()); |
1118 | 1118 | break; |
1119 | 1119 | } |
@@ -1121,9 +1121,9 @@ discard block |
||
1121 | 1121 | } |
1122 | 1122 | |
1123 | 1123 | //if timezone STILL empty then return the default timezone for the site. |
1124 | - if ( empty( $this->_timezone ) ) { |
|
1125 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1126 | - $this->set_timezone( EEH_DTT_Helper::get_timezone() ); |
|
1124 | + if (empty($this->_timezone)) { |
|
1125 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1126 | + $this->set_timezone(EEH_DTT_Helper::get_timezone()); |
|
1127 | 1127 | } |
1128 | 1128 | return $this->_timezone; |
1129 | 1129 | } |
@@ -1141,19 +1141,19 @@ discard block |
||
1141 | 1141 | * |
1142 | 1142 | * @return array formats in an array with the date format first, and the time format last. |
1143 | 1143 | */ |
1144 | - public function get_formats_for( $field_name, $pretty = false ) { |
|
1145 | - $field_settings = $this->field_settings_for( $field_name ); |
|
1144 | + public function get_formats_for($field_name, $pretty = false) { |
|
1145 | + $field_settings = $this->field_settings_for($field_name); |
|
1146 | 1146 | |
1147 | 1147 | //if not a valid EE_Datetime_Field then throw error |
1148 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
1149 | - 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 ) ); |
|
1148 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1149 | + 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)); |
|
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | //while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on |
1153 | 1153 | //the field. |
1154 | 1154 | $this->_timezone = $field_settings->get_timezone(); |
1155 | 1155 | |
1156 | - return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) ); |
|
1156 | + return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty)); |
|
1157 | 1157 | } |
1158 | 1158 | |
1159 | 1159 | |
@@ -1177,25 +1177,25 @@ discard block |
||
1177 | 1177 | * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
1178 | 1178 | * exception is triggered. |
1179 | 1179 | */ |
1180 | - public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
|
1181 | - $formats = $this->get_formats_for( $field_name ); |
|
1180 | + public function current_time_for_query($field_name, $timestamp = false, $what = 'both') { |
|
1181 | + $formats = $this->get_formats_for($field_name); |
|
1182 | 1182 | |
1183 | - $DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) ); |
|
1183 | + $DateTime = new DateTime("now", new DateTimeZone($this->_timezone)); |
|
1184 | 1184 | |
1185 | - if ( $timestamp ) { |
|
1186 | - return $DateTime->format( 'U' ); |
|
1185 | + if ($timestamp) { |
|
1186 | + return $DateTime->format('U'); |
|
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | //not returning timestamp, so return formatted string in timezone. |
1190 | - switch( $what ) { |
|
1190 | + switch ($what) { |
|
1191 | 1191 | case 'time' : |
1192 | - return $DateTime->format( $formats[1] ); |
|
1192 | + return $DateTime->format($formats[1]); |
|
1193 | 1193 | break; |
1194 | 1194 | case 'date' : |
1195 | - return $DateTime->format( $formats[0] ); |
|
1195 | + return $DateTime->format($formats[0]); |
|
1196 | 1196 | break; |
1197 | 1197 | default : |
1198 | - return $DateTime->format( implode( ' ', $formats ) ); |
|
1198 | + return $DateTime->format(implode(' ', $formats)); |
|
1199 | 1199 | break; |
1200 | 1200 | } |
1201 | 1201 | } |
@@ -1219,18 +1219,18 @@ discard block |
||
1219 | 1219 | * 'U', this is ignored. |
1220 | 1220 | * @return DateTime |
1221 | 1221 | */ |
1222 | - public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) { |
|
1222 | + public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') { |
|
1223 | 1223 | |
1224 | 1224 | //just using this to ensure the timezone is set correctly internally |
1225 | - $this->get_formats_for( $field_name ); |
|
1225 | + $this->get_formats_for($field_name); |
|
1226 | 1226 | |
1227 | 1227 | //load EEH_DTT_Helper |
1228 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1229 | - $set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1228 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1229 | + $set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1230 | 1230 | |
1231 | - $incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) ); |
|
1231 | + $incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone)); |
|
1232 | 1232 | |
1233 | - return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) ); |
|
1233 | + return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone)); |
|
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects |
1241 | 1241 | * @return EE_Table_Base[] |
1242 | 1242 | */ |
1243 | - function get_tables(){ |
|
1243 | + function get_tables() { |
|
1244 | 1244 | return $this->_tables; |
1245 | 1245 | } |
1246 | 1246 | |
@@ -1274,9 +1274,9 @@ discard block |
||
1274 | 1274 | * be aware that model objects being used could get out-of-sync with the database |
1275 | 1275 | * @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) |
1276 | 1276 | */ |
1277 | - function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){ |
|
1278 | - if( ! is_array( $query_params ) ){ |
|
1279 | - 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' ); |
|
1277 | + function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
1278 | + if ( ! is_array($query_params)) { |
|
1279 | + 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'); |
|
1280 | 1280 | $query_params = array(); |
1281 | 1281 | } |
1282 | 1282 | /** |
@@ -1286,7 +1286,7 @@ discard block |
||
1286 | 1286 | * @param array $fields_n_values the updated fields and their new values |
1287 | 1287 | * @param array $query_params @see EEM_Base::get_all() |
1288 | 1288 | */ |
1289 | - do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params ); |
|
1289 | + do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params); |
|
1290 | 1290 | /** |
1291 | 1291 | * Filters the fields about to be updated given the query parameters. You can provide the |
1292 | 1292 | * $query_params to $this->get_all() to find exactly which records will be updated |
@@ -1294,10 +1294,10 @@ discard block |
||
1294 | 1294 | * @param EEM_Base $model the model being queried |
1295 | 1295 | * @param array $query_params see EEM_Base::get_all() |
1296 | 1296 | */ |
1297 | - $fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params ); |
|
1297 | + $fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params); |
|
1298 | 1298 | //need to verify that, for any entry we want to update, there are entries in each secondary table. |
1299 | 1299 | //to do that, for each table, verify that it's PK isn't null. |
1300 | - $tables= $this->get_tables(); |
|
1300 | + $tables = $this->get_tables(); |
|
1301 | 1301 | |
1302 | 1302 | //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 |
1303 | 1303 | //NOTE: we should make this code more efficient by NOT querying twice |
@@ -1307,29 +1307,29 @@ discard block |
||
1307 | 1307 | //we want to make sure the default_where strategy is ignored |
1308 | 1308 | $this->_ignore_where_strategy = TRUE; |
1309 | 1309 | $wpdb_select_results = $this->_get_all_wpdb_results($query_params); |
1310 | - foreach( $wpdb_select_results as $wpdb_result ){ |
|
1310 | + foreach ($wpdb_select_results as $wpdb_result) { |
|
1311 | 1311 | // type cast stdClass as array |
1312 | - $wpdb_result = (array)$wpdb_result; |
|
1312 | + $wpdb_result = (array) $wpdb_result; |
|
1313 | 1313 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1314 | - if( $this->has_primary_key_field() ){ |
|
1315 | - $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1316 | - }else{ |
|
1314 | + if ($this->has_primary_key_field()) { |
|
1315 | + $main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()]; |
|
1316 | + } else { |
|
1317 | 1317 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it woudl be lots of work) |
1318 | 1318 | $main_table_pk_value = null; |
1319 | 1319 | } |
1320 | 1320 | //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 |
1321 | 1321 | //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 |
1322 | - if(count($tables) > 1){ |
|
1322 | + if (count($tables) > 1) { |
|
1323 | 1323 | //foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry |
1324 | 1324 | //in that table, and so we'll want to insert one |
1325 | - foreach($tables as $table_obj){ |
|
1325 | + foreach ($tables as $table_obj) { |
|
1326 | 1326 | $this_table_pk_column = $table_obj->get_fully_qualified_pk_column(); |
1327 | 1327 | //if there is no private key for this table on the results, it means there's no entry |
1328 | 1328 | //in this table, right? so insert a row in the current table, using any fields available |
1329 | - if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){ |
|
1329 | + if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) { |
|
1330 | 1330 | $success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value); |
1331 | 1331 | //if we died here, report the error |
1332 | - if( ! $success ) { |
|
1332 | + if ( ! $success) { |
|
1333 | 1333 | return false; |
1334 | 1334 | } |
1335 | 1335 | } |
@@ -1349,44 +1349,44 @@ discard block |
||
1349 | 1349 | //if this wasn't called from a model object (to update itself) |
1350 | 1350 | //then we want to make sure we keep all the existing |
1351 | 1351 | //model objects in sync with the db |
1352 | - if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
|
1353 | - if( $this->has_primary_key_field() ){ |
|
1354 | - $model_objs_affected_ids = $this->get_col( $query_params ); |
|
1355 | - }else{ |
|
1352 | + if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) { |
|
1353 | + if ($this->has_primary_key_field()) { |
|
1354 | + $model_objs_affected_ids = $this->get_col($query_params); |
|
1355 | + } else { |
|
1356 | 1356 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1357 | - $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
|
1357 | + $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A); |
|
1358 | 1358 | $model_objs_affected_ids = array(); |
1359 | - foreach( $models_affected_key_columns as $row ){ |
|
1360 | - $combined_index_key = $this->get_index_primary_key_string( $row ); |
|
1361 | - $model_objs_affected_ids[ $combined_index_key ] = $combined_index_key; |
|
1359 | + foreach ($models_affected_key_columns as $row) { |
|
1360 | + $combined_index_key = $this->get_index_primary_key_string($row); |
|
1361 | + $model_objs_affected_ids[$combined_index_key] = $combined_index_key; |
|
1362 | 1362 | } |
1363 | 1363 | |
1364 | 1364 | } |
1365 | 1365 | |
1366 | - if( ! $model_objs_affected_ids ){ |
|
1366 | + if ( ! $model_objs_affected_ids) { |
|
1367 | 1367 | //wait wait wait- if nothing was affected let's stop here |
1368 | 1368 | return 0; |
1369 | 1369 | } |
1370 | - foreach( $model_objs_affected_ids as $id ){ |
|
1371 | - $model_obj_in_entity_map = $this->get_from_entity_map( $id ); |
|
1372 | - if( $model_obj_in_entity_map ){ |
|
1373 | - foreach( $fields_n_values as $field => $new_value ){ |
|
1374 | - $model_obj_in_entity_map->set( $field, $new_value ); |
|
1370 | + foreach ($model_objs_affected_ids as $id) { |
|
1371 | + $model_obj_in_entity_map = $this->get_from_entity_map($id); |
|
1372 | + if ($model_obj_in_entity_map) { |
|
1373 | + foreach ($fields_n_values as $field => $new_value) { |
|
1374 | + $model_obj_in_entity_map->set($field, $new_value); |
|
1375 | 1375 | } |
1376 | 1376 | } |
1377 | 1377 | } |
1378 | 1378 | //if there is a primary key on this model, we can now do a slight optimization |
1379 | - if( $this->has_primary_key_field() ){ |
|
1379 | + if ($this->has_primary_key_field()) { |
|
1380 | 1380 | //we already know what we want to update. So let's make the query simpler so it's a little more efficient |
1381 | 1381 | $query_params = array( |
1382 | - array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ), |
|
1383 | - 'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' ); |
|
1382 | + array($this->primary_key_name() => array('IN', $model_objs_affected_ids)), |
|
1383 | + 'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' ); |
|
1384 | 1384 | } |
1385 | 1385 | } |
1386 | 1386 | |
1387 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
1388 | - $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. |
|
1389 | - $rows_affected = $this->_do_wpdb_query('query', array( $SQL ) ); |
|
1387 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
1388 | + $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. |
|
1389 | + $rows_affected = $this->_do_wpdb_query('query', array($SQL)); |
|
1390 | 1390 | /** |
1391 | 1391 | * Action called after a model update call has been made. |
1392 | 1392 | * |
@@ -1395,8 +1395,8 @@ discard block |
||
1395 | 1395 | * @param array $query_params @see EEM_Base::get_all() |
1396 | 1396 | * @param int $rows_affected |
1397 | 1397 | */ |
1398 | - do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected ); |
|
1399 | - return $rows_affected;//how many supposedly got updated |
|
1398 | + do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected); |
|
1399 | + return $rows_affected; //how many supposedly got updated |
|
1400 | 1400 | } |
1401 | 1401 | |
1402 | 1402 | /** |
@@ -1408,22 +1408,22 @@ discard block |
||
1408 | 1408 | * @param string $field_to_select |
1409 | 1409 | * @return array just like $wpdb->get_col() |
1410 | 1410 | */ |
1411 | - public function get_col( $query_params = array(), $field_to_select = NULL ){ |
|
1411 | + public function get_col($query_params = array(), $field_to_select = NULL) { |
|
1412 | 1412 | |
1413 | - if( $field_to_select ){ |
|
1414 | - $field = $this->field_settings_for( $field_to_select ); |
|
1415 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1413 | + if ($field_to_select) { |
|
1414 | + $field = $this->field_settings_for($field_to_select); |
|
1415 | + }elseif ($this->has_primary_key_field( )) { |
|
1416 | 1416 | $field = $this->get_primary_key_field(); |
1417 | - }else{ |
|
1417 | + } else { |
|
1418 | 1418 | //no primary key, just grab the first column |
1419 | - $field = reset( $this->field_settings()); |
|
1419 | + $field = reset($this->field_settings()); |
|
1420 | 1420 | } |
1421 | 1421 | |
1422 | 1422 | |
1423 | 1423 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1424 | 1424 | $select_expressions = $field->get_qualified_column(); |
1425 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1426 | - $results = $this->_do_wpdb_query('get_col', array( $SQL ) ); |
|
1425 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1426 | + $results = $this->_do_wpdb_query('get_col', array($SQL)); |
|
1427 | 1427 | return $results; |
1428 | 1428 | } |
1429 | 1429 | |
@@ -1433,12 +1433,12 @@ discard block |
||
1433 | 1433 | * @param string $field_to_select @see EEM_Base::get_col() |
1434 | 1434 | * @return string |
1435 | 1435 | */ |
1436 | - public function get_var( $query_params = array(), $field_to_select = NULL ) { |
|
1437 | - $query_params[ 'limit' ] = 1; |
|
1438 | - $col = $this->get_col( $query_params, $field_to_select ); |
|
1439 | - if( ! empty( $col ) ) { |
|
1440 | - return reset( $col ); |
|
1441 | - }else{ |
|
1436 | + public function get_var($query_params = array(), $field_to_select = NULL) { |
|
1437 | + $query_params['limit'] = 1; |
|
1438 | + $col = $this->get_col($query_params, $field_to_select); |
|
1439 | + if ( ! empty($col)) { |
|
1440 | + return reset($col); |
|
1441 | + } else { |
|
1442 | 1442 | return NULL; |
1443 | 1443 | } |
1444 | 1444 | } |
@@ -1452,19 +1452,19 @@ discard block |
||
1452 | 1452 | * @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 |
1453 | 1453 | * @return string of SQL |
1454 | 1454 | */ |
1455 | - function _construct_update_sql($fields_n_values){ |
|
1455 | + function _construct_update_sql($fields_n_values) { |
|
1456 | 1456 | /** @type WPDB $wpdb */ |
1457 | 1457 | global $wpdb; |
1458 | 1458 | $cols_n_values = array(); |
1459 | - foreach($fields_n_values as $field_name => $value){ |
|
1459 | + foreach ($fields_n_values as $field_name => $value) { |
|
1460 | 1460 | $field_obj = $this->field_settings_for($field_name); |
1461 | 1461 | //if the value is NULL, we want to assign the value to that. |
1462 | 1462 | //wpdb->prepare doesn't really handle that properly |
1463 | - $prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values ); |
|
1464 | - $value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value ); |
|
1463 | + $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
|
1464 | + $value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value); |
|
1465 | 1465 | $cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql; |
1466 | 1466 | } |
1467 | - return implode(",",$cols_n_values); |
|
1467 | + return implode(",", $cols_n_values); |
|
1468 | 1468 | |
1469 | 1469 | } |
1470 | 1470 | |
@@ -1476,11 +1476,11 @@ discard block |
||
1476 | 1476 | * @param mixed $id |
1477 | 1477 | * @return boolean whether the row got deleted or not |
1478 | 1478 | */ |
1479 | - public function delete_by_ID( $id ){ |
|
1480 | - return $this->delete( array( |
|
1481 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1479 | + public function delete_by_ID($id) { |
|
1480 | + return $this->delete(array( |
|
1481 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1482 | 1482 | 'limit' => 1 |
1483 | - ) ); |
|
1483 | + )); |
|
1484 | 1484 | } |
1485 | 1485 | |
1486 | 1486 | |
@@ -1495,7 +1495,7 @@ discard block |
||
1495 | 1495 | * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
1496 | 1496 | * @return int how many rows got deleted |
1497 | 1497 | */ |
1498 | - function delete($query_params,$allow_blocking = true){ |
|
1498 | + function delete($query_params, $allow_blocking = true) { |
|
1499 | 1499 | /** |
1500 | 1500 | * Action called just before performing a real deletion query. You can use the |
1501 | 1501 | * model and its $query_params to find exactly which items will be deleted |
@@ -1504,34 +1504,34 @@ discard block |
||
1504 | 1504 | * @param boolean $allow_blocking whether or not to allow related model objects |
1505 | 1505 | * to block (prevent) this deletion |
1506 | 1506 | */ |
1507 | - do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking ); |
|
1507 | + do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking); |
|
1508 | 1508 | //some MySQL databases may be running safe mode, which may restrict |
1509 | 1509 | //deletion if there is no KEY column used in the WHERE statement of a deletion. |
1510 | 1510 | //to get around this, we first do a SELECT, get all the IDs, and then run another query |
1511 | 1511 | //to delete them |
1512 | 1512 | $items_for_deletion = $this->_get_all_wpdb_results($query_params); |
1513 | - $deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking); |
|
1514 | - if($deletion_where){ |
|
1513 | + $deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking); |
|
1514 | + if ($deletion_where) { |
|
1515 | 1515 | //echo "objects for deletion:";var_dump($objects_for_deletion); |
1516 | 1516 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1517 | 1517 | $table_aliases = array(); |
1518 | - foreach(array_keys($this->_tables) as $table_alias){ |
|
1518 | + foreach (array_keys($this->_tables) as $table_alias) { |
|
1519 | 1519 | $table_aliases[] = $table_alias; |
1520 | 1520 | } |
1521 | - $SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1521 | + $SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1522 | 1522 | |
1523 | 1523 | // /echo "delete sql:$SQL"; |
1524 | - $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
|
1525 | - }else{ |
|
1524 | + $rows_deleted = $this->_do_wpdb_query('query', array($SQL)); |
|
1525 | + } else { |
|
1526 | 1526 | $rows_deleted = 0; |
1527 | 1527 | } |
1528 | 1528 | |
1529 | 1529 | //and lastly make sure those items are removed from the entity map; if they could be put into it at all |
1530 | - if( $this->has_primary_key_field() ){ |
|
1531 | - foreach($items_for_deletion as $item_for_deletion_row ){ |
|
1532 | - $pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1533 | - if( isset( $this->_entity_map[ $pk_value ] ) ){ |
|
1534 | - unset( $this->_entity_map[ $pk_value ] ); |
|
1530 | + if ($this->has_primary_key_field()) { |
|
1531 | + foreach ($items_for_deletion as $item_for_deletion_row) { |
|
1532 | + $pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()]; |
|
1533 | + if (isset($this->_entity_map[$pk_value])) { |
|
1534 | + unset($this->_entity_map[$pk_value]); |
|
1535 | 1535 | } |
1536 | 1536 | } |
1537 | 1537 | } |
@@ -1543,8 +1543,8 @@ discard block |
||
1543 | 1543 | * @param array $query_params @see EEM_Base::get_all() |
1544 | 1544 | * @param int $rows_deleted |
1545 | 1545 | */ |
1546 | - do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted ); |
|
1547 | - return $rows_deleted;//how many supposedly got deleted |
|
1546 | + do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted); |
|
1547 | + return $rows_deleted; //how many supposedly got deleted |
|
1548 | 1548 | } |
1549 | 1549 | |
1550 | 1550 | |
@@ -1560,28 +1560,28 @@ discard block |
||
1560 | 1560 | * blocking its deletion before removing the relation between A and B |
1561 | 1561 | * @return boolean |
1562 | 1562 | */ |
1563 | - public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){ |
|
1563 | + public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) { |
|
1564 | 1564 | //first, if $ignore_this_model_obj was supplied, get its model |
1565 | - if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
|
1565 | + if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) { |
|
1566 | 1566 | $ignored_model = $ignore_this_model_obj->get_model(); |
1567 | - }else{ |
|
1567 | + } else { |
|
1568 | 1568 | $ignored_model = null; |
1569 | 1569 | } |
1570 | 1570 | //now check all the relations of $this_model_obj_or_id and see if there |
1571 | 1571 | //are any related model objects blocking it? |
1572 | 1572 | $is_blocked = false; |
1573 | - foreach($this->_model_relations as $relation_name => $relation_obj){ |
|
1574 | - if( $relation_obj->block_delete_if_related_models_exist()){ |
|
1573 | + foreach ($this->_model_relations as $relation_name => $relation_obj) { |
|
1574 | + if ($relation_obj->block_delete_if_related_models_exist()) { |
|
1575 | 1575 | //if $ignore_this_model_obj was supplied, then for the query |
1576 | 1576 | //on that model needs to be told to ignore $ignore_this_model_obj |
1577 | - if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){ |
|
1578 | - $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
|
1579 | - array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
|
1580 | - }else{ |
|
1577 | + if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) { |
|
1578 | + $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array( |
|
1579 | + array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID())))); |
|
1580 | + } else { |
|
1581 | 1581 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1582 | 1582 | } |
1583 | 1583 | |
1584 | - if($related_model_objects){ |
|
1584 | + if ($related_model_objects) { |
|
1585 | 1585 | EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__); |
1586 | 1586 | $is_blocked = true; |
1587 | 1587 | } |
@@ -1601,65 +1601,65 @@ discard block |
||
1601 | 1601 | * @throws EE_Error |
1602 | 1602 | * @return string everything that comes after the WHERE statement. |
1603 | 1603 | */ |
1604 | - protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) { |
|
1605 | - if($this->has_primary_key_field()){ |
|
1604 | + protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) { |
|
1605 | + if ($this->has_primary_key_field()) { |
|
1606 | 1606 | $primary_table = $this->_get_main_table(); |
1607 | 1607 | $other_tables = $this->_get_other_tables(); |
1608 | 1608 | $deletes = $query = array(); |
1609 | - foreach ( $objects_for_deletion as $delete_object ) { |
|
1609 | + foreach ($objects_for_deletion as $delete_object) { |
|
1610 | 1610 | //before we mark this object for deletion, |
1611 | 1611 | //make sure there's no related objects blocking its deletion (if we're checking) |
1612 | - if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){ |
|
1612 | + if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) { |
|
1613 | 1613 | continue; |
1614 | 1614 | } |
1615 | 1615 | |
1616 | 1616 | //primary table deletes |
1617 | - if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) |
|
1617 | + if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) |
|
1618 | 1618 | $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
1619 | 1619 | |
1620 | 1620 | //other tables |
1621 | - if ( !empty( $other_tables ) ) { |
|
1622 | - foreach ( $other_tables as $ot ) { |
|
1621 | + if ( ! empty($other_tables)) { |
|
1622 | + foreach ($other_tables as $ot) { |
|
1623 | 1623 | |
1624 | 1624 | //first check if we've got the foreign key column here. |
1625 | - if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) |
|
1625 | + if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) |
|
1626 | 1626 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
1627 | 1627 | |
1628 | 1628 | //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 |
1629 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) |
|
1629 | + if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) |
|
1630 | 1630 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1631 | 1631 | |
1632 | 1632 | //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! |
1633 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) |
|
1633 | + if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) |
|
1634 | 1634 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1635 | 1635 | } |
1636 | 1636 | } |
1637 | 1637 | } |
1638 | 1638 | |
1639 | 1639 | //we should have deletes now, so let's just go through and setup the where statement |
1640 | - foreach ( $deletes as $column => $values ) { |
|
1640 | + foreach ($deletes as $column => $values) { |
|
1641 | 1641 | //make sure we have unique $values; |
1642 | 1642 | $values = array_unique($values); |
1643 | - $query[] = $column . ' IN(' . implode(",",$values) . ')'; |
|
1643 | + $query[] = $column.' IN('.implode(",", $values).')'; |
|
1644 | 1644 | } |
1645 | 1645 | |
1646 | - return !empty($query) ? implode(' AND ', $query ) : ''; |
|
1647 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1646 | + return ! empty($query) ? implode(' AND ', $query) : ''; |
|
1647 | + }elseif (count($this->get_combined_primary_key_fields()) > 1) { |
|
1648 | 1648 | $ways_to_identify_a_row = array(); |
1649 | 1649 | $fields = $this->get_combined_primary_key_fields(); |
1650 | 1650 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
1651 | - foreach($objects_for_deletion as $delete_object){ |
|
1651 | + foreach ($objects_for_deletion as $delete_object) { |
|
1652 | 1652 | $values_for_each_cpk_for_a_row = array(); |
1653 | - foreach($fields as $cpk_field){ |
|
1653 | + foreach ($fields as $cpk_field) { |
|
1654 | 1654 | $values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()]; |
1655 | 1655 | } |
1656 | - $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
|
1656 | + $ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")"; |
|
1657 | 1657 | } |
1658 | - return implode(" OR ",$ways_to_identify_a_row); |
|
1659 | - }else{ |
|
1658 | + return implode(" OR ", $ways_to_identify_a_row); |
|
1659 | + } else { |
|
1660 | 1660 | //so there's no primary key and no combined key... |
1661 | 1661 | //sorry, can't help you |
1662 | - 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))); |
|
1662 | + 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))); |
|
1663 | 1663 | } |
1664 | 1664 | } |
1665 | 1665 | |
@@ -1673,21 +1673,21 @@ discard block |
||
1673 | 1673 | * @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; |
1674 | 1674 | * @return int |
1675 | 1675 | */ |
1676 | - function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1676 | + function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1677 | 1677 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1678 | - if($field_to_count){ |
|
1678 | + if ($field_to_count) { |
|
1679 | 1679 | $field_obj = $this->field_settings_for($field_to_count); |
1680 | 1680 | $column_to_count = $field_obj->get_qualified_column(); |
1681 | - }elseif($this->has_primary_key_field ()){ |
|
1681 | + }elseif ($this->has_primary_key_field()) { |
|
1682 | 1682 | $pk_field_obj = $this->get_primary_key_field(); |
1683 | 1683 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1684 | - }else{//there's no primary key |
|
1684 | + } else {//there's no primary key |
|
1685 | 1685 | $column_to_count = '*'; |
1686 | 1686 | } |
1687 | 1687 | |
1688 | - $column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count; |
|
1689 | - $SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1690 | - return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) ); |
|
1688 | + $column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count; |
|
1689 | + $SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1690 | + return (int) $this->_do_wpdb_query('get_var', array($SQL)); |
|
1691 | 1691 | } |
1692 | 1692 | |
1693 | 1693 | /** |
@@ -1697,23 +1697,23 @@ discard block |
||
1697 | 1697 | * @param string $field_to_sum name of field (array key in $_fields array) |
1698 | 1698 | * @return float |
1699 | 1699 | */ |
1700 | - function sum($query_params, $field_to_sum = NULL){ |
|
1700 | + function sum($query_params, $field_to_sum = NULL) { |
|
1701 | 1701 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1702 | 1702 | |
1703 | - if($field_to_sum){ |
|
1703 | + if ($field_to_sum) { |
|
1704 | 1704 | $field_obj = $this->field_settings_for($field_to_sum); |
1705 | 1705 | |
1706 | - }else{ |
|
1706 | + } else { |
|
1707 | 1707 | $field_obj = $this->get_primary_key_field(); |
1708 | 1708 | } |
1709 | 1709 | $column_to_count = $field_obj->get_qualified_column(); |
1710 | 1710 | |
1711 | - $SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1712 | - $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
|
1713 | - if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){ |
|
1714 | - return (float)$return_value; |
|
1715 | - }else{//must be %f |
|
1716 | - return (float)$return_value; |
|
1711 | + $SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1712 | + $return_value = $this->_do_wpdb_query('get_var', array($SQL)); |
|
1713 | + if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') { |
|
1714 | + return (float) $return_value; |
|
1715 | + } else {//must be %f |
|
1716 | + return (float) $return_value; |
|
1717 | 1717 | } |
1718 | 1718 | } |
1719 | 1719 | |
@@ -1728,33 +1728,33 @@ discard block |
||
1728 | 1728 | * @global wpdb $wpdb |
1729 | 1729 | * @return mixed |
1730 | 1730 | */ |
1731 | - protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){ |
|
1731 | + protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1732 | 1732 | //if we're in maintenance mode level 2, DON'T run any queries |
1733 | 1733 | //because level 2 indicates the database needs updating and |
1734 | 1734 | //is probably out of sync with the code |
1735 | - if( ! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
1735 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
1736 | 1736 | 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"))); |
1737 | 1737 | } |
1738 | 1738 | /** @type WPDB $wpdb */ |
1739 | 1739 | global $wpdb; |
1740 | - if( ! method_exists( $wpdb, $wpdb_method ) ){ |
|
1741 | - throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) ); |
|
1740 | + if ( ! method_exists($wpdb, $wpdb_method)) { |
|
1741 | + throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method)); |
|
1742 | 1742 | } |
1743 | - if( WP_DEBUG ){ |
|
1743 | + if (WP_DEBUG) { |
|
1744 | 1744 | $old_show_errors_value = $wpdb->show_errors; |
1745 | - $wpdb->show_errors( FALSE ); |
|
1746 | - } |
|
1747 | - $result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1748 | - $this->show_db_query_if_previously_requested( $wpdb->last_query ); |
|
1749 | - if( WP_DEBUG ){ |
|
1750 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1751 | - if( ! empty( $wpdb->last_error ) ){ |
|
1752 | - throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
|
1753 | - }elseif( $result === false ){ |
|
1754 | - 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 ) ) ); |
|
1745 | + $wpdb->show_errors(FALSE); |
|
1746 | + } |
|
1747 | + $result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1748 | + $this->show_db_query_if_previously_requested($wpdb->last_query); |
|
1749 | + if (WP_DEBUG) { |
|
1750 | + $wpdb->show_errors($old_show_errors_value); |
|
1751 | + if ( ! empty($wpdb->last_error)) { |
|
1752 | + throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error)); |
|
1753 | + }elseif ($result === false) { |
|
1754 | + 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))); |
|
1755 | 1755 | } |
1756 | - }elseif( $result === false ) { |
|
1757 | - EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
|
1756 | + }elseif ($result === false) { |
|
1757 | + EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__); |
|
1758 | 1758 | } |
1759 | 1759 | return $result; |
1760 | 1760 | } |
@@ -1770,23 +1770,23 @@ discard block |
||
1770 | 1770 | * @param array $arguments_to_provide |
1771 | 1771 | * @return mixed |
1772 | 1772 | */ |
1773 | - private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) { |
|
1773 | + private function _process_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1774 | 1774 | /** @type WPDB $wpdb */ |
1775 | 1775 | global $wpdb; |
1776 | 1776 | $wpdb->last_error = null; |
1777 | - $result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide ); |
|
1777 | + $result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide); |
|
1778 | 1778 | // was there an error running the query? |
1779 | - if ( ( $result === false || ! empty( $wpdb->last_error ) ) ) { |
|
1780 | - switch ( EEM_Base::$_db_verification_level ) { |
|
1779 | + if (($result === false || ! empty($wpdb->last_error))) { |
|
1780 | + switch (EEM_Base::$_db_verification_level) { |
|
1781 | 1781 | |
1782 | 1782 | case EEM_Base::db_verified_none : |
1783 | 1783 | // let's double-check core's DB |
1784 | - $error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide ); |
|
1784 | + $error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide); |
|
1785 | 1785 | break; |
1786 | 1786 | |
1787 | 1787 | case EEM_Base::db_verified_core : |
1788 | 1788 | // STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed |
1789 | - $error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide ); |
|
1789 | + $error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide); |
|
1790 | 1790 | break; |
1791 | 1791 | |
1792 | 1792 | case EEM_Base::db_verified_addons : |
@@ -1794,11 +1794,11 @@ discard block |
||
1794 | 1794 | return $result; |
1795 | 1795 | break; |
1796 | 1796 | } |
1797 | - if ( ! empty( $error_message ) ) { |
|
1798 | - EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' ); |
|
1799 | - trigger_error( $error_message ); |
|
1797 | + if ( ! empty($error_message)) { |
|
1798 | + EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error'); |
|
1799 | + trigger_error($error_message); |
|
1800 | 1800 | } |
1801 | - return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1801 | + return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1802 | 1802 | |
1803 | 1803 | } |
1804 | 1804 | |
@@ -1814,18 +1814,18 @@ discard block |
||
1814 | 1814 | * @param array $arguments_to_provide |
1815 | 1815 | * @return string |
1816 | 1816 | */ |
1817 | - private function _verify_core_db( $wpdb_method, $arguments_to_provide ){ |
|
1817 | + private function _verify_core_db($wpdb_method, $arguments_to_provide) { |
|
1818 | 1818 | /** @type WPDB $wpdb */ |
1819 | 1819 | global $wpdb; |
1820 | 1820 | //ok remember that we've already attempted fixing the core db, in case the problem persists |
1821 | 1821 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_core; |
1822 | 1822 | $error_message = sprintf( |
1823 | - __( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ), |
|
1823 | + __('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'), |
|
1824 | 1824 | $wpdb->last_error, |
1825 | 1825 | $wpdb_method, |
1826 | - json_encode( $arguments_to_provide ) |
|
1826 | + json_encode($arguments_to_provide) |
|
1827 | 1827 | ); |
1828 | - EE_System::instance()->initialize_db_if_no_migrations_required( false, true ); |
|
1828 | + EE_System::instance()->initialize_db_if_no_migrations_required(false, true); |
|
1829 | 1829 | return $error_message; |
1830 | 1830 | } |
1831 | 1831 | |
@@ -1838,16 +1838,16 @@ discard block |
||
1838 | 1838 | * @param $arguments_to_provide |
1839 | 1839 | * @return string |
1840 | 1840 | */ |
1841 | - private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) { |
|
1841 | + private function _verify_addons_db($wpdb_method, $arguments_to_provide) { |
|
1842 | 1842 | /** @type WPDB $wpdb */ |
1843 | 1843 | global $wpdb; |
1844 | 1844 | //ok remember that we've already attempted fixing the addons dbs, in case the problem persists |
1845 | 1845 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons; |
1846 | 1846 | $error_message = sprintf( |
1847 | - __( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ), |
|
1847 | + __('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'), |
|
1848 | 1848 | $wpdb->last_error, |
1849 | 1849 | $wpdb_method, |
1850 | - json_encode( $arguments_to_provide ) |
|
1850 | + json_encode($arguments_to_provide) |
|
1851 | 1851 | ); |
1852 | 1852 | EE_System::instance()->initialize_addons(); |
1853 | 1853 | return $error_message; |
@@ -1862,7 +1862,7 @@ discard block |
||
1862 | 1862 | * @param EE_Model_Query_Info_Carrier $model_query_info |
1863 | 1863 | * @return string |
1864 | 1864 | */ |
1865 | - private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){ |
|
1865 | + private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) { |
|
1866 | 1866 | return " FROM ".$model_query_info->get_full_join_sql(). |
1867 | 1867 | $model_query_info->get_where_sql(). |
1868 | 1868 | $model_query_info->get_group_by_sql(). |
@@ -1875,7 +1875,7 @@ discard block |
||
1875 | 1875 | * Set to easily debug the next X queries ran from this model. |
1876 | 1876 | * @param int $count |
1877 | 1877 | */ |
1878 | - function show_next_x_db_queries($count = 1){ |
|
1878 | + function show_next_x_db_queries($count = 1) { |
|
1879 | 1879 | $this->_show_next_x_db_queries = $count; |
1880 | 1880 | } |
1881 | 1881 | |
@@ -1884,8 +1884,8 @@ discard block |
||
1884 | 1884 | /** |
1885 | 1885 | * @param $sql_query |
1886 | 1886 | */ |
1887 | - function show_db_query_if_previously_requested($sql_query){ |
|
1888 | - if($this->_show_next_x_db_queries > 0){ |
|
1887 | + function show_db_query_if_previously_requested($sql_query) { |
|
1888 | + if ($this->_show_next_x_db_queries > 0) { |
|
1889 | 1889 | echo $sql_query; |
1890 | 1890 | $this->_show_next_x_db_queries--; |
1891 | 1891 | } |
@@ -1909,7 +1909,7 @@ discard block |
||
1909 | 1909 | * @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. |
1910 | 1910 | * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj |
1911 | 1911 | */ |
1912 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){ |
|
1912 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) { |
|
1913 | 1913 | $relation_obj = $this->related_settings_for($relationName); |
1914 | 1914 | return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
1915 | 1915 | } |
@@ -1930,9 +1930,9 @@ discard block |
||
1930 | 1930 | * @return boolean of success |
1931 | 1931 | * @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. |
1932 | 1932 | */ |
1933 | - public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
|
1933 | + public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
1934 | 1934 | $relation_obj = $this->related_settings_for($relationName); |
1935 | - return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query ); |
|
1935 | + return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query); |
|
1936 | 1936 | } |
1937 | 1937 | |
1938 | 1938 | |
@@ -1945,9 +1945,9 @@ discard block |
||
1945 | 1945 | * @param EE_Base_Class[] objects to which relations were removed |
1946 | 1946 | * @return \EE_Base_Class[] |
1947 | 1947 | */ |
1948 | - public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){ |
|
1948 | + public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) { |
|
1949 | 1949 | $relation_obj = $this->related_settings_for($relationName); |
1950 | - return $relation_obj->remove_relations($id_or_obj, $where_query_params ); |
|
1950 | + return $relation_obj->remove_relations($id_or_obj, $where_query_params); |
|
1951 | 1951 | } |
1952 | 1952 | |
1953 | 1953 | |
@@ -1960,10 +1960,10 @@ discard block |
||
1960 | 1960 | * @param array $query_params like EEM_Base::get_all |
1961 | 1961 | * @return EE_Base_Class[] |
1962 | 1962 | */ |
1963 | - function get_all_related($id_or_obj, $model_name, $query_params = null){ |
|
1963 | + function get_all_related($id_or_obj, $model_name, $query_params = null) { |
|
1964 | 1964 | $model_obj = $this->ensure_is_obj($id_or_obj); |
1965 | 1965 | $relation_settings = $this->related_settings_for($model_name); |
1966 | - return $relation_settings->get_all_related($model_obj,$query_params); |
|
1966 | + return $relation_settings->get_all_related($model_obj, $query_params); |
|
1967 | 1967 | } |
1968 | 1968 | |
1969 | 1969 | /** |
@@ -1976,10 +1976,10 @@ discard block |
||
1976 | 1976 | * @param array $query_params |
1977 | 1977 | * @return int how many deleted |
1978 | 1978 | */ |
1979 | - public function delete_related($id_or_obj,$model_name, $query_params = array()){ |
|
1979 | + public function delete_related($id_or_obj, $model_name, $query_params = array()) { |
|
1980 | 1980 | $model_obj = $this->ensure_is_obj($id_or_obj); |
1981 | 1981 | $relation_settings = $this->related_settings_for($model_name); |
1982 | - return $relation_settings->delete_all_related($model_obj,$query_params); |
|
1982 | + return $relation_settings->delete_all_related($model_obj, $query_params); |
|
1983 | 1983 | } |
1984 | 1984 | |
1985 | 1985 | /** |
@@ -1992,10 +1992,10 @@ discard block |
||
1992 | 1992 | * @param array $query_params |
1993 | 1993 | * @return int how many deleted |
1994 | 1994 | */ |
1995 | - public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){ |
|
1995 | + public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) { |
|
1996 | 1996 | $model_obj = $this->ensure_is_obj($id_or_obj); |
1997 | 1997 | $relation_settings = $this->related_settings_for($model_name); |
1998 | - return $relation_settings->delete_related_permanently($model_obj,$query_params); |
|
1998 | + return $relation_settings->delete_related_permanently($model_obj, $query_params); |
|
1999 | 1999 | } |
2000 | 2000 | |
2001 | 2001 | /** |
@@ -2008,17 +2008,17 @@ discard block |
||
2008 | 2008 | * @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; |
2009 | 2009 | * @return int |
2010 | 2010 | */ |
2011 | - function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){ |
|
2011 | + function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) { |
|
2012 | 2012 | $related_model = $this->get_related_model_obj($model_name); |
2013 | 2013 | //we're just going to use the query params on the related model's normal get_all query, |
2014 | 2014 | //except add a condition to say to match the current mod |
2015 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2016 | - $query_params['default_where_conditions']='none'; |
|
2015 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2016 | + $query_params['default_where_conditions'] = 'none'; |
|
2017 | 2017 | } |
2018 | 2018 | $this_model_name = $this->get_this_model_name(); |
2019 | 2019 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2020 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2021 | - return $related_model->count($query_params,$field_to_count,$distinct); |
|
2020 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2021 | + return $related_model->count($query_params, $field_to_count, $distinct); |
|
2022 | 2022 | } |
2023 | 2023 | |
2024 | 2024 | |
@@ -2032,21 +2032,21 @@ discard block |
||
2032 | 2032 | * @param string $field_to_sum name of field to count by. By default, uses primary key |
2033 | 2033 | * @return float |
2034 | 2034 | */ |
2035 | - function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){ |
|
2035 | + function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) { |
|
2036 | 2036 | $related_model = $this->get_related_model_obj($model_name); |
2037 | - if( ! is_array( $query_params ) ){ |
|
2038 | - 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' ); |
|
2037 | + if ( ! is_array($query_params)) { |
|
2038 | + 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'); |
|
2039 | 2039 | $query_params = array(); |
2040 | 2040 | } |
2041 | 2041 | //we're just going to use the query params on the related model's normal get_all query, |
2042 | 2042 | //except add a condition to say to match the current mod |
2043 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2044 | - $query_params['default_where_conditions']='none'; |
|
2043 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2044 | + $query_params['default_where_conditions'] = 'none'; |
|
2045 | 2045 | } |
2046 | 2046 | $this_model_name = $this->get_this_model_name(); |
2047 | 2047 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2048 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2049 | - return $related_model->sum($query_params,$field_to_sum); |
|
2048 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2049 | + return $related_model->sum($query_params, $field_to_sum); |
|
2050 | 2050 | } |
2051 | 2051 | |
2052 | 2052 | |
@@ -2058,12 +2058,12 @@ discard block |
||
2058 | 2058 | * @param array $query_params like EEM_Base::get_all's |
2059 | 2059 | * @return EE_Base_Class |
2060 | 2060 | */ |
2061 | - public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){ |
|
2062 | - $query_params['limit']=1; |
|
2063 | - $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
|
2064 | - if( $results ){ |
|
2061 | + public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) { |
|
2062 | + $query_params['limit'] = 1; |
|
2063 | + $results = $this->get_all_related($id_or_obj, $other_model_name, $query_params); |
|
2064 | + if ($results) { |
|
2065 | 2065 | return array_shift($results); |
2066 | - }else{ |
|
2066 | + } else { |
|
2067 | 2067 | return null; |
2068 | 2068 | } |
2069 | 2069 | |
@@ -2073,8 +2073,8 @@ discard block |
||
2073 | 2073 | * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event |
2074 | 2074 | * @return string |
2075 | 2075 | */ |
2076 | - function get_this_model_name(){ |
|
2077 | - return str_replace("EEM_","",get_class($this)); |
|
2076 | + function get_this_model_name() { |
|
2077 | + return str_replace("EEM_", "", get_class($this)); |
|
2078 | 2078 | } |
2079 | 2079 | |
2080 | 2080 | /** |
@@ -2082,14 +2082,14 @@ discard block |
||
2082 | 2082 | * @return EE_Any_Foreign_Model_Name_Field |
2083 | 2083 | * @throws EE_Error |
2084 | 2084 | */ |
2085 | - public function get_field_containing_related_model_name(){ |
|
2086 | - foreach($this->field_settings(true) as $field){ |
|
2087 | - if($field instanceof EE_Any_Foreign_Model_Name_Field){ |
|
2085 | + public function get_field_containing_related_model_name() { |
|
2086 | + foreach ($this->field_settings(true) as $field) { |
|
2087 | + if ($field instanceof EE_Any_Foreign_Model_Name_Field) { |
|
2088 | 2088 | $field_with_model_name = $field; |
2089 | 2089 | } |
2090 | 2090 | } |
2091 | - if( !isset($field_with_model_name) || !$field_with_model_name ){ |
|
2092 | - throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() )); |
|
2091 | + if ( ! isset($field_with_model_name) || ! $field_with_model_name) { |
|
2092 | + throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name())); |
|
2093 | 2093 | } |
2094 | 2094 | return $field_with_model_name; |
2095 | 2095 | } |
@@ -2110,19 +2110,19 @@ discard block |
||
2110 | 2110 | * @return int new primary key on main table that got inserted |
2111 | 2111 | * @throws EE_Error |
2112 | 2112 | */ |
2113 | - function insert($field_n_values){ |
|
2113 | + function insert($field_n_values) { |
|
2114 | 2114 | /** |
2115 | 2115 | * Filters the fields and their values before inserting an item using the models |
2116 | 2116 | * @param array $fields_n_values keys are the fields and values are their new values |
2117 | 2117 | * @param EEM_Base $model the model used |
2118 | 2118 | */ |
2119 | - $field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this ); |
|
2120 | - if($this->_satisfies_unique_indexes($field_n_values)){ |
|
2119 | + $field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this); |
|
2120 | + if ($this->_satisfies_unique_indexes($field_n_values)) { |
|
2121 | 2121 | $main_table = $this->_get_main_table(); |
2122 | 2122 | $new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false); |
2123 | - if( $new_id !== false ) { |
|
2124 | - foreach($this->_get_other_tables() as $other_table){ |
|
2125 | - $this->_insert_into_specific_table($other_table, $field_n_values,$new_id); |
|
2123 | + if ($new_id !== false) { |
|
2124 | + foreach ($this->_get_other_tables() as $other_table) { |
|
2125 | + $this->_insert_into_specific_table($other_table, $field_n_values, $new_id); |
|
2126 | 2126 | } |
2127 | 2127 | } |
2128 | 2128 | /** |
@@ -2132,9 +2132,9 @@ discard block |
||
2132 | 2132 | * @param array $fields_n_values fields and their values |
2133 | 2133 | * @param int|string the ID of the newly-inserted model object |
2134 | 2134 | */ |
2135 | - do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
|
2135 | + do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id); |
|
2136 | 2136 | return $new_id; |
2137 | - }else{ |
|
2137 | + } else { |
|
2138 | 2138 | return FALSE; |
2139 | 2139 | } |
2140 | 2140 | } |
@@ -2147,11 +2147,11 @@ discard block |
||
2147 | 2147 | * @param string $action |
2148 | 2148 | * @return boolean |
2149 | 2149 | */ |
2150 | - protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){ |
|
2151 | - foreach($this->unique_indexes() as $index_name => $index){ |
|
2150 | + protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') { |
|
2151 | + foreach ($this->unique_indexes() as $index_name => $index) { |
|
2152 | 2152 | $uniqueness_where_params = array_intersect_key($field_n_values, $index->fields()); |
2153 | - if($this->exists(array($uniqueness_where_params))){ |
|
2154 | - 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__ ); |
|
2153 | + if ($this->exists(array($uniqueness_where_params))) { |
|
2154 | + 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__); |
|
2155 | 2155 | return false; |
2156 | 2156 | } |
2157 | 2157 | } |
@@ -2172,28 +2172,28 @@ discard block |
||
2172 | 2172 | * @throws EE_Error |
2173 | 2173 | * @return EE_Base_Class |
2174 | 2174 | */ |
2175 | - public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
|
2176 | - if($obj_or_fields_array instanceof EE_Base_Class){ |
|
2175 | + public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) { |
|
2176 | + if ($obj_or_fields_array instanceof EE_Base_Class) { |
|
2177 | 2177 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2178 | - }elseif( is_array($obj_or_fields_array)){ |
|
2178 | + }elseif (is_array($obj_or_fields_array)) { |
|
2179 | 2179 | $fields_n_values = $obj_or_fields_array; |
2180 | - }else{ |
|
2181 | - 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)); |
|
2180 | + } else { |
|
2181 | + 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)); |
|
2182 | 2182 | } |
2183 | 2183 | $query_params = array(); |
2184 | - if( $this->has_primary_key_field() && |
|
2185 | - ( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2186 | - isset($fields_n_values[$this->primary_key_name()])){ |
|
2184 | + if ($this->has_primary_key_field() && |
|
2185 | + ($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2186 | + isset($fields_n_values[$this->primary_key_name()])) { |
|
2187 | 2187 | $query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()]; |
2188 | 2188 | } |
2189 | - foreach($this->unique_indexes() as $unique_index_name=>$unique_index){ |
|
2189 | + foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) { |
|
2190 | 2190 | $uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields()); |
2191 | 2191 | $query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params; |
2192 | 2192 | } |
2193 | 2193 | //if there is nothing to base this search on, then we shouldn't find anything |
2194 | - if( empty( $query_params ) ){ |
|
2194 | + if (empty($query_params)) { |
|
2195 | 2195 | return array(); |
2196 | - }else{ |
|
2196 | + } else { |
|
2197 | 2197 | return $this->get_one($query_params); |
2198 | 2198 | } |
2199 | 2199 | } |
@@ -2203,7 +2203,7 @@ discard block |
||
2203 | 2203 | * @param array $query_params |
2204 | 2204 | * @return boolean |
2205 | 2205 | */ |
2206 | - function exists($query_params){ |
|
2206 | + function exists($query_params) { |
|
2207 | 2207 | $query_params['limit'] = 1; |
2208 | 2208 | return $this->count($query_params) > 0; |
2209 | 2209 | } |
@@ -2213,7 +2213,7 @@ discard block |
||
2213 | 2213 | * @param int|string $id |
2214 | 2214 | * @return boolean |
2215 | 2215 | */ |
2216 | - function exists_by_ID($id){ |
|
2216 | + function exists_by_ID($id) { |
|
2217 | 2217 | return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id))); |
2218 | 2218 | } |
2219 | 2219 | |
@@ -2233,45 +2233,45 @@ discard block |
||
2233 | 2233 | * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert |
2234 | 2234 | * @return int ID of new row inserted, or FALSE on failure |
2235 | 2235 | */ |
2236 | - protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){ |
|
2236 | + protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) { |
|
2237 | 2237 | global $wpdb; |
2238 | 2238 | $insertion_col_n_values = array(); |
2239 | 2239 | $format_for_insertion = array(); |
2240 | 2240 | $fields_on_table = $this->_get_fields_for_table($table->get_table_alias()); |
2241 | - foreach($fields_on_table as $field_name => $field_obj){ |
|
2241 | + foreach ($fields_on_table as $field_name => $field_obj) { |
|
2242 | 2242 | //check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing |
2243 | - if($field_obj->is_auto_increment()){ |
|
2243 | + if ($field_obj->is_auto_increment()) { |
|
2244 | 2244 | continue; |
2245 | 2245 | } |
2246 | 2246 | $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
2247 | 2247 | //if the value we want to assign it to is NULL, just don't mention it for the insertion |
2248 | - if( $prepared_value !== NULL ){ |
|
2249 | - $insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value; |
|
2248 | + if ($prepared_value !== NULL) { |
|
2249 | + $insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value; |
|
2250 | 2250 | $format_for_insertion[] = $field_obj->get_wpdb_data_type(); |
2251 | 2251 | } |
2252 | 2252 | } |
2253 | 2253 | |
2254 | - if($table instanceof EE_Secondary_Table && $new_id){ |
|
2254 | + if ($table instanceof EE_Secondary_Table && $new_id) { |
|
2255 | 2255 | //its not the main table, so we should have already saved the main table's PK which we just inserted |
2256 | 2256 | //so add the fk to the main table as a column |
2257 | 2257 | $insertion_col_n_values[$table->get_fk_on_table()] = $new_id; |
2258 | - $format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs |
|
2258 | + $format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs |
|
2259 | 2259 | } |
2260 | 2260 | //insert the new entry |
2261 | - $result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) ); |
|
2262 | - if( $result === false ) { |
|
2261 | + $result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion)); |
|
2262 | + if ($result === false) { |
|
2263 | 2263 | return false; |
2264 | 2264 | } |
2265 | 2265 | //ok, now what do we return for the ID of the newly-inserted thing? |
2266 | - if($this->has_primary_key_field()){ |
|
2267 | - if($this->get_primary_key_field()->is_auto_increment()){ |
|
2266 | + if ($this->has_primary_key_field()) { |
|
2267 | + if ($this->get_primary_key_field()->is_auto_increment()) { |
|
2268 | 2268 | return $wpdb->insert_id; |
2269 | - }else{ |
|
2269 | + } else { |
|
2270 | 2270 | //it's not an auto-increment primary key, so |
2271 | 2271 | //it must have been supplied |
2272 | 2272 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2273 | 2273 | } |
2274 | - }else{ |
|
2274 | + } else { |
|
2275 | 2275 | //we can't return a primary key because there is none. instead return |
2276 | 2276 | //a unique string indicating this model |
2277 | 2277 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2286,15 +2286,15 @@ discard block |
||
2286 | 2286 | * @param array $fields_n_values |
2287 | 2287 | * @return mixed string|int|float depending on what the table column will be expecting |
2288 | 2288 | */ |
2289 | - protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){ |
|
2289 | + protected function _prepare_value_or_use_default($field_obj, $fields_n_values) { |
|
2290 | 2290 | //if this field doesn't allow nullable, don't allow it |
2291 | - if( ! $field_obj->is_nullable() && ( |
|
2292 | - ! isset( $fields_n_values[ $field_obj->get_name() ] ) || |
|
2293 | - $fields_n_values[ $field_obj->get_name() ] === NULL ) ){ |
|
2294 | - $fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value(); |
|
2291 | + if ( ! $field_obj->is_nullable() && ( |
|
2292 | + ! isset($fields_n_values[$field_obj->get_name()]) || |
|
2293 | + $fields_n_values[$field_obj->get_name()] === NULL )) { |
|
2294 | + $fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value(); |
|
2295 | 2295 | } |
2296 | - $unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL; |
|
2297 | - return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj); |
|
2296 | + $unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL; |
|
2297 | + return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj); |
|
2298 | 2298 | } |
2299 | 2299 | |
2300 | 2300 | |
@@ -2306,9 +2306,9 @@ discard block |
||
2306 | 2306 | * @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 |
2307 | 2307 | * @return mixed a value ready for use in the database for insertions, updating, or in a where clause |
2308 | 2308 | */ |
2309 | - private function _prepare_value_for_use_in_db($value, $field){ |
|
2310 | - if($field && $field instanceof EE_Model_Field_Base){ |
|
2311 | - switch( $this->_values_already_prepared_by_model_object ){ |
|
2309 | + private function _prepare_value_for_use_in_db($value, $field) { |
|
2310 | + if ($field && $field instanceof EE_Model_Field_Base) { |
|
2311 | + switch ($this->_values_already_prepared_by_model_object) { |
|
2312 | 2312 | /** @noinspection PhpMissingBreakStatementInspection */ |
2313 | 2313 | case self::not_prepared_by_model_object: |
2314 | 2314 | $value = $field->prepare_for_set($value); |
@@ -2319,7 +2319,7 @@ discard block |
||
2319 | 2319 | //leave the value alone |
2320 | 2320 | } |
2321 | 2321 | return $value; |
2322 | - }else{ |
|
2322 | + } else { |
|
2323 | 2323 | return $value; |
2324 | 2324 | } |
2325 | 2325 | } |
@@ -2329,13 +2329,13 @@ discard block |
||
2329 | 2329 | * @return EE_Primary_Table |
2330 | 2330 | * @throws EE_Error |
2331 | 2331 | */ |
2332 | - protected function _get_main_table(){ |
|
2333 | - foreach($this->_tables as $table){ |
|
2334 | - if($table instanceof EE_Primary_Table){ |
|
2332 | + protected function _get_main_table() { |
|
2333 | + foreach ($this->_tables as $table) { |
|
2334 | + if ($table instanceof EE_Primary_Table) { |
|
2335 | 2335 | return $table; |
2336 | 2336 | } |
2337 | 2337 | } |
2338 | - 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))); |
|
2338 | + 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))); |
|
2339 | 2339 | } |
2340 | 2340 | |
2341 | 2341 | /** |
@@ -2354,7 +2354,7 @@ discard block |
||
2354 | 2354 | */ |
2355 | 2355 | public function second_table() { |
2356 | 2356 | // grab second table from tables array |
2357 | - $second_table = end( $this->_tables ); |
|
2357 | + $second_table = end($this->_tables); |
|
2358 | 2358 | return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL; |
2359 | 2359 | } |
2360 | 2360 | |
@@ -2367,8 +2367,8 @@ discard block |
||
2367 | 2367 | * @param string $table_alias |
2368 | 2368 | * @return EE_Primary_Table | EE_Secondary_Table |
2369 | 2369 | */ |
2370 | - public function get_table_obj_by_alias( $table_alias = '' ) { |
|
2371 | - return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL; |
|
2370 | + public function get_table_obj_by_alias($table_alias = '') { |
|
2371 | + return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL; |
|
2372 | 2372 | } |
2373 | 2373 | |
2374 | 2374 | |
@@ -2377,10 +2377,10 @@ discard block |
||
2377 | 2377 | * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables |
2378 | 2378 | * @return EE_Secondary_Table[] |
2379 | 2379 | */ |
2380 | - protected function _get_other_tables(){ |
|
2381 | - $other_tables =array(); |
|
2382 | - foreach($this->_tables as $table_alias => $table){ |
|
2383 | - if($table instanceof EE_Secondary_Table){ |
|
2380 | + protected function _get_other_tables() { |
|
2381 | + $other_tables = array(); |
|
2382 | + foreach ($this->_tables as $table_alias => $table) { |
|
2383 | + if ($table instanceof EE_Secondary_Table) { |
|
2384 | 2384 | $other_tables[$table_alias] = $table; |
2385 | 2385 | } |
2386 | 2386 | } |
@@ -2392,7 +2392,7 @@ discard block |
||
2392 | 2392 | * @param string $table_alias, array key in EEM_Base::_tables |
2393 | 2393 | * @return EE_Model_Field_Base[] |
2394 | 2394 | */ |
2395 | - function _get_fields_for_table($table_alias){ |
|
2395 | + function _get_fields_for_table($table_alias) { |
|
2396 | 2396 | return $this->_fields[$table_alias]; |
2397 | 2397 | } |
2398 | 2398 | |
@@ -2404,29 +2404,29 @@ discard block |
||
2404 | 2404 | * @param array $query_params like EEM_Base::get_all's $query_parameters['where'] |
2405 | 2405 | * @return EE_Model_Query_Info_Carrier |
2406 | 2406 | */ |
2407 | - function _extract_related_models_from_query($query_params){ |
|
2407 | + function _extract_related_models_from_query($query_params) { |
|
2408 | 2408 | $query_info_carrier = new EE_Model_Query_Info_Carrier(); |
2409 | - if(array_key_exists(0,$query_params)){ |
|
2410 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0); |
|
2411 | - } |
|
2412 | - if(array_key_exists('group_by', $query_params)){ |
|
2413 | - if(is_array($query_params['group_by'])){ |
|
2414 | - $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by'); |
|
2415 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2416 | - $this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by'); |
|
2409 | + if (array_key_exists(0, $query_params)) { |
|
2410 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0); |
|
2411 | + } |
|
2412 | + if (array_key_exists('group_by', $query_params)) { |
|
2413 | + if (is_array($query_params['group_by'])) { |
|
2414 | + $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2415 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2416 | + $this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2417 | 2417 | } |
2418 | 2418 | } |
2419 | - if(array_key_exists('having',$query_params)){ |
|
2420 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having'); |
|
2419 | + if (array_key_exists('having', $query_params)) { |
|
2420 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having'); |
|
2421 | 2421 | } |
2422 | - if(array_key_exists('order_by', $query_params)){ |
|
2423 | - if ( is_array( $query_params['order_by'] ) ) |
|
2424 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2425 | - elseif( ! empty( $query_params['order_by'] )) |
|
2426 | - $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2422 | + if (array_key_exists('order_by', $query_params)) { |
|
2423 | + if (is_array($query_params['order_by'])) |
|
2424 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2425 | + elseif ( ! empty($query_params['order_by'])) |
|
2426 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2427 | 2427 | } |
2428 | - if(array_key_exists('force_join', $query_params)){ |
|
2429 | - $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join'); |
|
2428 | + if (array_key_exists('force_join', $query_params)) { |
|
2429 | + $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join'); |
|
2430 | 2430 | } |
2431 | 2431 | return $query_info_carrier; |
2432 | 2432 | } |
@@ -2439,34 +2439,34 @@ discard block |
||
2439 | 2439 | * @throws EE_Error |
2440 | 2440 | * @return \EE_Model_Query_Info_Carrier |
2441 | 2441 | */ |
2442 | - 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){ |
|
2443 | - if (!empty($sub_query_params)){ |
|
2442 | + 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) { |
|
2443 | + if ( ! empty($sub_query_params)) { |
|
2444 | 2444 | $sub_query_params = (array) $sub_query_params; |
2445 | - foreach($sub_query_params as $param => $possibly_array_of_params){ |
|
2445 | + foreach ($sub_query_params as $param => $possibly_array_of_params) { |
|
2446 | 2446 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2447 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type); |
|
2447 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2448 | 2448 | |
2449 | 2449 | //if $possibly_array_of_params is an array, try recursing into it, searching for keys which |
2450 | 2450 | //indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried |
2451 | 2451 | //extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value |
2452 | 2452 | //of array('Registration.TXN_ID'=>23) |
2453 | 2453 | $query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param); |
2454 | - if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){ |
|
2455 | - if (! is_array($possibly_array_of_params)){ |
|
2454 | + if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) { |
|
2455 | + if ( ! is_array($possibly_array_of_params)) { |
|
2456 | 2456 | 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"), |
2457 | - $param,$possibly_array_of_params)); |
|
2458 | - }else{ |
|
2459 | - $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
|
2457 | + $param, $possibly_array_of_params)); |
|
2458 | + } else { |
|
2459 | + $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type); |
|
2460 | 2460 | } |
2461 | - }elseif($query_param_type === 0 //ie WHERE |
|
2461 | + }elseif ($query_param_type === 0 //ie WHERE |
|
2462 | 2462 | && is_array($possibly_array_of_params) |
2463 | 2463 | && isset($possibly_array_of_params[2]) |
2464 | - && $possibly_array_of_params[2] == true){ |
|
2464 | + && $possibly_array_of_params[2] == true) { |
|
2465 | 2465 | //then $possible_array_of_params looks something like array('<','DTT_sold',true) |
2466 | 2466 | //indicating that $possible_array_of_params[1] is actually a field name, |
2467 | 2467 | //from which we should extract query parameters! |
2468 | - if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){ |
|
2469 | - 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))); |
|
2468 | + if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) { |
|
2469 | + 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))); |
|
2470 | 2470 | } |
2471 | 2471 | $this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type); |
2472 | 2472 | } |
@@ -2485,14 +2485,14 @@ discard block |
||
2485 | 2485 | * @throws EE_Error |
2486 | 2486 | * @return \EE_Model_Query_Info_Carrier |
2487 | 2487 | */ |
2488 | - 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){ |
|
2489 | - if (!empty($sub_query_params)){ |
|
2490 | - if(!is_array($sub_query_params)){ |
|
2491 | - throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params)); |
|
2488 | + 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) { |
|
2489 | + if ( ! empty($sub_query_params)) { |
|
2490 | + if ( ! is_array($sub_query_params)) { |
|
2491 | + throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params)); |
|
2492 | 2492 | } |
2493 | - foreach($sub_query_params as $param){ |
|
2493 | + foreach ($sub_query_params as $param) { |
|
2494 | 2494 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2495 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type); |
|
2495 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2496 | 2496 | } |
2497 | 2497 | } |
2498 | 2498 | return $model_query_info_carrier; |
@@ -2511,81 +2511,81 @@ discard block |
||
2511 | 2511 | * @throws EE_Error |
2512 | 2512 | * @return EE_Model_Query_Info_Carrier |
2513 | 2513 | */ |
2514 | - function _create_model_query_info_carrier($query_params){ |
|
2515 | - if( ! is_array( $query_params ) ){ |
|
2516 | - 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' ); |
|
2514 | + function _create_model_query_info_carrier($query_params) { |
|
2515 | + if ( ! is_array($query_params)) { |
|
2516 | + 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'); |
|
2517 | 2517 | $query_params = array(); |
2518 | 2518 | } |
2519 | - if( isset( $query_params[0] ) ) { |
|
2519 | + if (isset($query_params[0])) { |
|
2520 | 2520 | $where_query_params = $query_params[0]; |
2521 | - }else{ |
|
2521 | + } else { |
|
2522 | 2522 | $where_query_params = array(); |
2523 | 2523 | } |
2524 | 2524 | //first check if we should alter the query to account for caps or not |
2525 | 2525 | //because the caps might require us to do extra joins |
2526 | - if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) { |
|
2527 | - $query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) ); |
|
2526 | + if (isset($query_params['caps']) && $query_params['caps'] != 'none') { |
|
2527 | + $query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps'])); |
|
2528 | 2528 | } |
2529 | 2529 | $query_object = $this->_extract_related_models_from_query($query_params); |
2530 | 2530 | |
2531 | 2531 | //verify where_query_params has NO numeric indexes.... that's simply not how you use it! |
2532 | - foreach($where_query_params as $key => $value){ |
|
2533 | - if(is_int($key)){ |
|
2534 | - 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))); |
|
2532 | + foreach ($where_query_params as $key => $value) { |
|
2533 | + if (is_int($key)) { |
|
2534 | + 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))); |
|
2535 | 2535 | } |
2536 | 2536 | } |
2537 | - if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){ |
|
2537 | + if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) { |
|
2538 | 2538 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2539 | - }else{ |
|
2539 | + } else { |
|
2540 | 2540 | $use_default_where_conditions = 'all'; |
2541 | 2541 | } |
2542 | - $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 ); |
|
2543 | - $query_object->set_where_sql( $this->_construct_where_clause($where_query_params)); |
|
2542 | + $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); |
|
2543 | + $query_object->set_where_sql($this->_construct_where_clause($where_query_params)); |
|
2544 | 2544 | |
2545 | 2545 | |
2546 | 2546 | //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: |
2547 | 2547 | //array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) ) |
2548 | - if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) { |
|
2549 | - $query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) ); |
|
2548 | + if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) { |
|
2549 | + $query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1])); |
|
2550 | 2550 | } |
2551 | 2551 | |
2552 | 2552 | |
2553 | 2553 | //set limit |
2554 | - if(array_key_exists('limit',$query_params)){ |
|
2555 | - if(is_array($query_params['limit'])){ |
|
2556 | - if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){ |
|
2557 | - $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'])); |
|
2554 | + if (array_key_exists('limit', $query_params)) { |
|
2555 | + if (is_array($query_params['limit'])) { |
|
2556 | + if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) { |
|
2557 | + $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'])); |
|
2558 | 2558 | throw new EE_Error($e."|".$e); |
2559 | 2559 | } |
2560 | 2560 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2561 | 2561 | $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
2562 | - }elseif( ! empty ( $query_params['limit'] )){ |
|
2562 | + }elseif ( ! empty ($query_params['limit'])) { |
|
2563 | 2563 | $query_object->set_limit_sql((" LIMIT ".$query_params['limit'])); |
2564 | 2564 | } |
2565 | 2565 | } |
2566 | 2566 | //set order by |
2567 | - if(array_key_exists('order_by',$query_params)){ |
|
2568 | - if(is_array($query_params['order_by'])){ |
|
2567 | + if (array_key_exists('order_by', $query_params)) { |
|
2568 | + if (is_array($query_params['order_by'])) { |
|
2569 | 2569 | //if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must |
2570 | 2570 | //specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So |
2571 | 2571 | //including 'order' wouldn't make any sense if 'order_by' has already specified which way to order! |
2572 | - if(array_key_exists('order', $query_params)){ |
|
2572 | + if (array_key_exists('order', $query_params)) { |
|
2573 | 2573 | 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"), |
2574 | - get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order'])); |
|
2574 | + get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order'])); |
|
2575 | 2575 | } |
2576 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by'); |
|
2576 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by'); |
|
2577 | 2577 | //assume it's an array of fields to order by |
2578 | 2578 | $order_array = array(); |
2579 | - foreach($query_params['order_by'] as $field_name_to_order_by => $order){ |
|
2579 | + foreach ($query_params['order_by'] as $field_name_to_order_by => $order) { |
|
2580 | 2580 | $order = $this->_extract_order($order); |
2581 | 2581 | $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
2582 | 2582 | } |
2583 | - $query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array)); |
|
2584 | - }elseif( ! empty ( $query_params['order_by'] )){ |
|
2585 | - $this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']); |
|
2586 | - if(isset($query_params['order'])){ |
|
2583 | + $query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array)); |
|
2584 | + }elseif ( ! empty ($query_params['order_by'])) { |
|
2585 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']); |
|
2586 | + if (isset($query_params['order'])) { |
|
2587 | 2587 | $order = $this->_extract_order($query_params['order']); |
2588 | - }else{ |
|
2588 | + } else { |
|
2589 | 2589 | $order = 'DESC'; |
2590 | 2590 | } |
2591 | 2591 | $query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order); |
@@ -2593,46 +2593,46 @@ discard block |
||
2593 | 2593 | } |
2594 | 2594 | |
2595 | 2595 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2596 | - if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){ |
|
2596 | + if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) { |
|
2597 | 2597 | $pk_field = $this->get_primary_key_field(); |
2598 | 2598 | $order = $this->_extract_order($query_params['order']); |
2599 | 2599 | $query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order); |
2600 | 2600 | } |
2601 | 2601 | |
2602 | 2602 | //set group by |
2603 | - if(array_key_exists('group_by',$query_params)){ |
|
2604 | - if(is_array($query_params['group_by'])){ |
|
2603 | + if (array_key_exists('group_by', $query_params)) { |
|
2604 | + if (is_array($query_params['group_by'])) { |
|
2605 | 2605 | //it's an array, so assume we'll be grouping by a bunch of stuff |
2606 | 2606 | $group_by_array = array(); |
2607 | - foreach($query_params['group_by'] as $field_name_to_group_by){ |
|
2607 | + foreach ($query_params['group_by'] as $field_name_to_group_by) { |
|
2608 | 2608 | $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
2609 | 2609 | } |
2610 | - $query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array)); |
|
2611 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2610 | + $query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array)); |
|
2611 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2612 | 2612 | $query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])); |
2613 | 2613 | } |
2614 | 2614 | } |
2615 | 2615 | //set having |
2616 | - if(array_key_exists('having',$query_params) && $query_params['having']){ |
|
2617 | - $query_object->set_having_sql( $this->_construct_having_clause($query_params['having'])); |
|
2616 | + if (array_key_exists('having', $query_params) && $query_params['having']) { |
|
2617 | + $query_object->set_having_sql($this->_construct_having_clause($query_params['having'])); |
|
2618 | 2618 | } |
2619 | 2619 | |
2620 | 2620 | //now, just verify they didn't pass anything wack |
2621 | - foreach($query_params as $query_key => $query_value){ |
|
2622 | - if( ! in_array($query_key,$this->_allowed_query_params,true)){ |
|
2621 | + foreach ($query_params as $query_key => $query_value) { |
|
2622 | + if ( ! in_array($query_key, $this->_allowed_query_params, true)) { |
|
2623 | 2623 | throw new EE_Error( |
2624 | 2624 | sprintf( |
2625 | - __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'), |
|
2625 | + __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'), |
|
2626 | 2626 | $query_key, |
2627 | 2627 | get_class($this), |
2628 | 2628 | // print_r( $this->_allowed_query_params, TRUE ) |
2629 | - implode( ', ', $this->_allowed_query_params ) |
|
2629 | + implode(', ', $this->_allowed_query_params) |
|
2630 | 2630 | ) |
2631 | 2631 | ); |
2632 | 2632 | } |
2633 | 2633 | } |
2634 | 2634 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2635 | - if ( empty( $main_model_join_sql ) ) |
|
2635 | + if (empty($main_model_join_sql)) |
|
2636 | 2636 | $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
2637 | 2637 | return $query_object; |
2638 | 2638 | } |
@@ -2643,17 +2643,17 @@ discard block |
||
2643 | 2643 | * @param string $context one of EEM_Base::valid_cap_contexts() |
2644 | 2644 | * @return array like EEM_Base::get_all() 's $query_params[0] |
2645 | 2645 | */ |
2646 | - public function caps_where_conditions( $context = self::caps_read ) { |
|
2647 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
2646 | + public function caps_where_conditions($context = self::caps_read) { |
|
2647 | + EEM_Base::verify_is_valid_cap_context($context); |
|
2648 | 2648 | $cap_where_conditions = array(); |
2649 | - $cap_restrictions = $this->caps_missing( $context ); |
|
2649 | + $cap_restrictions = $this->caps_missing($context); |
|
2650 | 2650 | /** |
2651 | 2651 | * @var $cap_restrictions EE_Default_Where_Conditions[] |
2652 | 2652 | */ |
2653 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
2654 | - $cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() ); |
|
2653 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
2654 | + $cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions()); |
|
2655 | 2655 | } |
2656 | - return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions ); |
|
2656 | + return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions); |
|
2657 | 2657 | } |
2658 | 2658 | |
2659 | 2659 | /** |
@@ -2663,11 +2663,11 @@ discard block |
||
2663 | 2663 | * @return string either ASC, asc, DESC or desc |
2664 | 2664 | * @throws EE_Error |
2665 | 2665 | */ |
2666 | - private function _extract_order($should_be_order_string){ |
|
2667 | - if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
|
2666 | + private function _extract_order($should_be_order_string) { |
|
2667 | + if (in_array($should_be_order_string, $this->_allowed_order_values)) { |
|
2668 | 2668 | return $should_be_order_string; |
2669 | - }else{ |
|
2670 | - 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)); |
|
2669 | + } else { |
|
2670 | + 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)); |
|
2671 | 2671 | } |
2672 | 2672 | } |
2673 | 2673 | |
@@ -2685,19 +2685,19 @@ discard block |
||
2685 | 2685 | * @throws EE_Error |
2686 | 2686 | * @return array like $query_params[0], see EEM_Base::get_all for documentation |
2687 | 2687 | */ |
2688 | - 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()){ |
|
2689 | - $allowed_used_default_where_conditions_values = array('all','this_model_only', 'other_models_only','none'); |
|
2690 | - if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){ |
|
2691 | - 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))); |
|
2688 | + 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()) { |
|
2689 | + $allowed_used_default_where_conditions_values = array('all', 'this_model_only', 'other_models_only', 'none'); |
|
2690 | + if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) { |
|
2691 | + 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))); |
|
2692 | 2692 | } |
2693 | - if( in_array($use_default_where_conditions, array('all','this_model_only')) ){ |
|
2693 | + if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) { |
|
2694 | 2694 | $universal_query_params = $this->_get_default_where_conditions(); |
2695 | - }else{ |
|
2695 | + } else { |
|
2696 | 2696 | $universal_query_params = array(); |
2697 | 2697 | } |
2698 | 2698 | |
2699 | - if(in_array($use_default_where_conditions,array('all','other_models_only'))){ |
|
2700 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
2699 | + if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) { |
|
2700 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
2701 | 2701 | $related_model = $this->get_related_model_obj($model_name); |
2702 | 2702 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
2703 | 2703 | |
@@ -2724,22 +2724,22 @@ discard block |
||
2724 | 2724 | * @param string $model_relation_path like 'Transaction.Payment.' |
2725 | 2725 | * @return array like EEM_Base::get_all's $query_params[0] |
2726 | 2726 | */ |
2727 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
2727 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
2728 | 2728 | $null_friendly_where_conditions = array(); |
2729 | 2729 | $none_overridden = true; |
2730 | 2730 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
2731 | 2731 | |
2732 | - foreach($default_where_conditions as $key => $val){ |
|
2733 | - if( isset($provided_where_conditions[$key])){ |
|
2732 | + foreach ($default_where_conditions as $key => $val) { |
|
2733 | + if (isset($provided_where_conditions[$key])) { |
|
2734 | 2734 | $none_overridden = false; |
2735 | - }else{ |
|
2735 | + } else { |
|
2736 | 2736 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
2737 | 2737 | } |
2738 | 2738 | } |
2739 | - if( $none_overridden && $default_where_conditions){ |
|
2740 | - if($model->has_primary_key_field()){ |
|
2739 | + if ($none_overridden && $default_where_conditions) { |
|
2740 | + if ($model->has_primary_key_field()) { |
|
2741 | 2741 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
2742 | - }else{ |
|
2742 | + } else { |
|
2743 | 2743 | //@todo NO PK, use other defaults |
2744 | 2744 | } |
2745 | 2745 | } |
@@ -2754,8 +2754,8 @@ discard block |
||
2754 | 2754 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
2755 | 2755 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2756 | 2756 | */ |
2757 | - private function _get_default_where_conditions($model_relation_path = null){ |
|
2758 | - if ( $this->_ignore_where_strategy ) |
|
2757 | + private function _get_default_where_conditions($model_relation_path = null) { |
|
2758 | + if ($this->_ignore_where_strategy) |
|
2759 | 2759 | return array(); |
2760 | 2760 | |
2761 | 2761 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -2766,13 +2766,13 @@ discard block |
||
2766 | 2766 | * @param EE_Model_Query_Info_Carrier $model_query_info |
2767 | 2767 | * @return string |
2768 | 2768 | */ |
2769 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
2769 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
2770 | 2770 | $selects = $this->_get_columns_to_select_for_this_model(); |
2771 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
2771 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
2772 | 2772 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
2773 | 2773 | $selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain)); |
2774 | 2774 | } |
2775 | - return implode(", ",$selects); |
|
2775 | + return implode(", ", $selects); |
|
2776 | 2776 | } |
2777 | 2777 | |
2778 | 2778 | /** |
@@ -2781,19 +2781,19 @@ discard block |
||
2781 | 2781 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
2782 | 2782 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
2783 | 2783 | */ |
2784 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
2784 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
2785 | 2785 | $fields = $this->field_settings(); |
2786 | 2786 | $selects = array(); |
2787 | 2787 | $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()); |
2788 | - foreach($fields as $field_obj){ |
|
2789 | - $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()."'"; |
|
2788 | + foreach ($fields as $field_obj) { |
|
2789 | + $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()."'"; |
|
2790 | 2790 | } |
2791 | 2791 | //make sure we are also getting the PKs of each table |
2792 | 2792 | $tables = $this->get_tables(); |
2793 | - if(count($tables) > 1){ |
|
2794 | - foreach($tables as $table_obj){ |
|
2795 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
2796 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
2793 | + if (count($tables) > 1) { |
|
2794 | + foreach ($tables as $table_obj) { |
|
2795 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
2796 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
2797 | 2797 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
2798 | 2798 | } |
2799 | 2799 | } |
@@ -2817,66 +2817,66 @@ discard block |
||
2817 | 2817 | * @throws EE_Error |
2818 | 2818 | * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it |
2819 | 2819 | */ |
2820 | - 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 ){ |
|
2821 | - if($original_query_param == NULL){ |
|
2820 | + 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) { |
|
2821 | + if ($original_query_param == NULL) { |
|
2822 | 2822 | $original_query_param = $query_param; |
2823 | 2823 | } |
2824 | 2824 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
2825 | 2825 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
2826 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
2827 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
2826 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
2827 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
2828 | 2828 | //check to see if we have a field on this model |
2829 | 2829 | $this_model_fields = $this->field_settings(true); |
2830 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
2831 | - if($allow_fields){ |
|
2830 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
2831 | + if ($allow_fields) { |
|
2832 | 2832 | return; |
2833 | - }else{ |
|
2833 | + } else { |
|
2834 | 2834 | 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"), |
2835 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
2835 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
2836 | 2836 | } |
2837 | 2837 | } |
2838 | 2838 | //check if this is a special logic query param |
2839 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
2840 | - if($allow_logic_query_params){ |
|
2839 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
2840 | + if ($allow_logic_query_params) { |
|
2841 | 2841 | return; |
2842 | - }else{ |
|
2842 | + } else { |
|
2843 | 2843 | throw new EE_Error( |
2844 | 2844 | sprintf( |
2845 | - __( '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' ), |
|
2846 | - implode( '", "', $this->_logic_query_param_keys ), |
|
2847 | - $query_param , |
|
2848 | - get_class( $this ), |
|
2845 | + __('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'), |
|
2846 | + implode('", "', $this->_logic_query_param_keys), |
|
2847 | + $query_param, |
|
2848 | + get_class($this), |
|
2849 | 2849 | '<br />', |
2850 | - "\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 |
|
2850 | + "\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 |
|
2851 | 2851 | ) |
2852 | 2852 | ); |
2853 | 2853 | } |
2854 | 2854 | } |
2855 | 2855 | |
2856 | 2856 | //check if it's a custom selection |
2857 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
2857 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
2858 | 2858 | return; |
2859 | 2859 | } |
2860 | 2860 | |
2861 | 2861 | //check if has a model name at the beginning |
2862 | 2862 | //and |
2863 | 2863 | //check if it's a field on a related model |
2864 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
2865 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
2866 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
2864 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
2865 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
2866 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
2867 | 2867 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
2868 | - if($query_param == ''){ |
|
2868 | + if ($query_param == '') { |
|
2869 | 2869 | //nothing left to $query_param |
2870 | 2870 | //we should actually end in a field name, not a model like this! |
2871 | 2871 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
2872 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
2873 | - }else{ |
|
2872 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
2873 | + } else { |
|
2874 | 2874 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
2875 | 2875 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
2876 | 2876 | return; |
2877 | 2877 | } |
2878 | - }elseif($query_param == $valid_related_model_name){ |
|
2879 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
2878 | + }elseif ($query_param == $valid_related_model_name) { |
|
2879 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
2880 | 2880 | return; |
2881 | 2881 | } |
2882 | 2882 | } |
@@ -2886,7 +2886,7 @@ discard block |
||
2886 | 2886 | //and we previously confirmed it wasn't a logic query param or field on the current model |
2887 | 2887 | //it's wack, that's what it is |
2888 | 2888 | 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"), |
2889 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
2889 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
2890 | 2890 | |
2891 | 2891 | } |
2892 | 2892 | |
@@ -2903,26 +2903,26 @@ discard block |
||
2903 | 2903 | * 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) |
2904 | 2904 | * @return void |
2905 | 2905 | */ |
2906 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
2906 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
2907 | 2907 | $relation_obj = $this->related_settings_for($model_name); |
2908 | 2908 | |
2909 | 2909 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
2910 | 2910 | //check if the relation is HABTM, because then we're essentially doing two joins |
2911 | 2911 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
2912 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
2912 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
2913 | 2913 | $join_model_obj = $relation_obj->get_join_model(); |
2914 | 2914 | //replace the model specified with the join model for this relation chain, whi |
2915 | 2915 | $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); |
2916 | 2916 | $new_query_info = new EE_Model_Query_Info_Carrier( |
2917 | 2917 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
2918 | 2918 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
2919 | - $passed_in_query_info->merge( $new_query_info ); |
|
2919 | + $passed_in_query_info->merge($new_query_info); |
|
2920 | 2920 | } |
2921 | 2921 | //now just join to the other table pointed to by the relation object, and add its data types |
2922 | 2922 | $new_query_info = new EE_Model_Query_Info_Carrier( |
2923 | 2923 | array($model_relation_chain=>$model_name), |
2924 | 2924 | $relation_obj->get_join_statement($model_relation_chain)); |
2925 | - $passed_in_query_info->merge( $new_query_info ); |
|
2925 | + $passed_in_query_info->merge($new_query_info); |
|
2926 | 2926 | } |
2927 | 2927 | |
2928 | 2928 | |
@@ -2931,11 +2931,11 @@ discard block |
||
2931 | 2931 | * @param array $where_params like EEM_Base::get_all |
2932 | 2932 | * @return string of SQL |
2933 | 2933 | */ |
2934 | - private function _construct_where_clause($where_params){ |
|
2934 | + private function _construct_where_clause($where_params) { |
|
2935 | 2935 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
2936 | - if($SQL){ |
|
2937 | - return " WHERE ". $SQL; |
|
2938 | - }else{ |
|
2936 | + if ($SQL) { |
|
2937 | + return " WHERE ".$SQL; |
|
2938 | + } else { |
|
2939 | 2939 | return ''; |
2940 | 2940 | } |
2941 | 2941 | } |
@@ -2946,11 +2946,11 @@ discard block |
||
2946 | 2946 | * @param array $having_params |
2947 | 2947 | * @return string |
2948 | 2948 | */ |
2949 | - private function _construct_having_clause($having_params){ |
|
2949 | + private function _construct_having_clause($having_params) { |
|
2950 | 2950 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
2951 | - if($SQL){ |
|
2952 | - return " HAVING ". $SQL; |
|
2953 | - }else{ |
|
2951 | + if ($SQL) { |
|
2952 | + return " HAVING ".$SQL; |
|
2953 | + } else { |
|
2954 | 2954 | return ''; |
2955 | 2955 | } |
2956 | 2956 | |
@@ -2964,17 +2964,17 @@ discard block |
||
2964 | 2964 | * @return EE_Model_Field_Base |
2965 | 2965 | * @throws EE_Error |
2966 | 2966 | */ |
2967 | - protected function _get_field_on_model($field_name,$model_name){ |
|
2967 | + protected function _get_field_on_model($field_name, $model_name) { |
|
2968 | 2968 | $model_class = 'EEM_'.$model_name; |
2969 | 2969 | $model_filepath = $model_class.".model.php"; |
2970 | - EE_Registry::instance()->load_helper( 'File' ); |
|
2971 | - if ( is_readable($model_filepath)){ |
|
2970 | + EE_Registry::instance()->load_helper('File'); |
|
2971 | + if (is_readable($model_filepath)) { |
|
2972 | 2972 | require_once($model_filepath); |
2973 | - $model_instance=call_user_func($model_name."::instance"); |
|
2973 | + $model_instance = call_user_func($model_name."::instance"); |
|
2974 | 2974 | /* @var $model_instance EEM_Base */ |
2975 | 2975 | return $model_instance->field_settings_for($field_name); |
2976 | - }else{ |
|
2977 | - throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
|
2976 | + } else { |
|
2977 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
2978 | 2978 | } |
2979 | 2979 | } |
2980 | 2980 | |
@@ -2987,43 +2987,43 @@ discard block |
||
2987 | 2987 | * @throws EE_Error |
2988 | 2988 | * @return string of SQL |
2989 | 2989 | */ |
2990 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
2991 | - $where_clauses=array(); |
|
2992 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
2993 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
2994 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
2995 | - switch($query_param){ |
|
2990 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
2991 | + $where_clauses = array(); |
|
2992 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
2993 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
2994 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
2995 | + switch ($query_param) { |
|
2996 | 2996 | case 'not': |
2997 | 2997 | case 'NOT': |
2998 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
2998 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
2999 | 2999 | break; |
3000 | 3000 | case 'and': |
3001 | 3001 | case 'AND': |
3002 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
3002 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
3003 | 3003 | break; |
3004 | 3004 | case 'or': |
3005 | 3005 | case 'OR': |
3006 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
3006 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
3007 | 3007 | break; |
3008 | 3008 | } |
3009 | - }else{ |
|
3009 | + } else { |
|
3010 | 3010 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3011 | 3011 | |
3012 | 3012 | //if it's not a normal field, maybe it's a custom selection? |
3013 | - if( ! $field_obj){ |
|
3014 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
3013 | + if ( ! $field_obj) { |
|
3014 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
3015 | 3015 | $field_obj = $this->_custom_selections[$query_param][1]; |
3016 | - }else{ |
|
3017 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
3016 | + } else { |
|
3017 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
3018 | 3018 | } |
3019 | 3019 | } |
3020 | 3020 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
3021 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3021 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3022 | 3022 | } |
3023 | 3023 | } |
3024 | - if($where_clauses){ |
|
3025 | - $SQL = implode($glue,$where_clauses); |
|
3026 | - }else{ |
|
3024 | + if ($where_clauses) { |
|
3025 | + $SQL = implode($glue, $where_clauses); |
|
3026 | + } else { |
|
3027 | 3027 | $SQL = ''; |
3028 | 3028 | } |
3029 | 3029 | return $SQL; |
@@ -3037,18 +3037,18 @@ discard block |
||
3037 | 3037 | * @throws EE_Error |
3038 | 3038 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
3039 | 3039 | */ |
3040 | - private function _deduce_column_name_from_query_param($query_param){ |
|
3040 | + private function _deduce_column_name_from_query_param($query_param) { |
|
3041 | 3041 | $field = $this->_deduce_field_from_query_param($query_param); |
3042 | 3042 | |
3043 | - if( $field ){ |
|
3044 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
3045 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
3046 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3043 | + if ($field) { |
|
3044 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
3045 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
3046 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3047 | 3047 | //maybe it's custom selection item? |
3048 | 3048 | //if so, just use it as the "column name" |
3049 | 3049 | return $query_param; |
3050 | - }else{ |
|
3051 | - 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))); |
|
3050 | + } else { |
|
3051 | + 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))); |
|
3052 | 3052 | } |
3053 | 3053 | } |
3054 | 3054 | |
@@ -3060,11 +3060,11 @@ discard block |
||
3060 | 3060 | * @param string $condition_query_param_key |
3061 | 3061 | * @return string |
3062 | 3062 | */ |
3063 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
3063 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
3064 | 3064 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3065 | - if($pos_of_star === FALSE){ |
|
3065 | + if ($pos_of_star === FALSE) { |
|
3066 | 3066 | return $condition_query_param_key; |
3067 | - }else{ |
|
3067 | + } else { |
|
3068 | 3068 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3069 | 3069 | return $condition_query_param_sans_star; |
3070 | 3070 | } |
@@ -3079,54 +3079,54 @@ discard block |
||
3079 | 3079 | * @throws EE_Error |
3080 | 3080 | * @return string |
3081 | 3081 | */ |
3082 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
3083 | - if(is_array( $op_and_value )){ |
|
3082 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
3083 | + if (is_array($op_and_value)) { |
|
3084 | 3084 | $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
3085 | - if( ! $operator){ |
|
3085 | + if ( ! $operator) { |
|
3086 | 3086 | $php_array_like_string = array(); |
3087 | - foreach($op_and_value as $key => $value){ |
|
3087 | + foreach ($op_and_value as $key => $value) { |
|
3088 | 3088 | $php_array_like_string[] = "$key=>$value"; |
3089 | 3089 | } |
3090 | - 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))); |
|
3090 | + 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))); |
|
3091 | 3091 | } |
3092 | 3092 | $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
3093 | - }else{ |
|
3093 | + } else { |
|
3094 | 3094 | $operator = '='; |
3095 | 3095 | $value = $op_and_value; |
3096 | 3096 | } |
3097 | 3097 | |
3098 | 3098 | //check to see if the value is actually another field |
3099 | - if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){ |
|
3099 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
3100 | 3100 | return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
3101 | - }elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3101 | + }elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3102 | 3102 | //in this case, the value should be an array, or at least a comma-separated list |
3103 | 3103 | //it will need to handle a little differently |
3104 | 3104 | $cleaned_value = $this->_construct_in_value($value, $field_obj); |
3105 | 3105 | //note: $cleaned_value has already been run through $wpdb->prepare() |
3106 | 3106 | return $operator.SP.$cleaned_value; |
3107 | - } elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
3107 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
3108 | 3108 | //the value should be an array with count of two. |
3109 | - if ( count($value) !== 2 ) |
|
3110 | - 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" ) ); |
|
3111 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
3109 | + if (count($value) !== 2) |
|
3110 | + 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")); |
|
3111 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
3112 | 3112 | return $operator.SP.$cleaned_value; |
3113 | - } elseif( in_array( $operator, $this->_null_style_operators ) ) { |
|
3114 | - if($value != NULL){ |
|
3115 | - 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)); |
|
3113 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
3114 | + if ($value != NULL) { |
|
3115 | + 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)); |
|
3116 | 3116 | } |
3117 | 3117 | return $operator; |
3118 | - }elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3118 | + }elseif ($operator == 'LIKE' && ! is_array($value)) { |
|
3119 | 3119 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3120 | 3120 | //remove other junk. So just treat it as a string. |
3121 | 3121 | return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
3122 | - }elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3123 | - return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj); |
|
3124 | - }elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3125 | - 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)); |
|
3126 | - }elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3127 | - 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)); |
|
3128 | - }else{ |
|
3129 | - 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))); |
|
3122 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3123 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3124 | + }elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3125 | + 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)); |
|
3126 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3127 | + 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)); |
|
3128 | + } else { |
|
3129 | + 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))); |
|
3130 | 3130 | } |
3131 | 3131 | } |
3132 | 3132 | |
@@ -3138,12 +3138,12 @@ discard block |
||
3138 | 3138 | * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s' |
3139 | 3139 | * @return string |
3140 | 3140 | */ |
3141 | - function _construct_between_value( $values, $field_obj ) { |
|
3141 | + function _construct_between_value($values, $field_obj) { |
|
3142 | 3142 | $cleaned_values = array(); |
3143 | - foreach ( $values as $value ) { |
|
3144 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3143 | + foreach ($values as $value) { |
|
3144 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3145 | 3145 | } |
3146 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3146 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3147 | 3147 | } |
3148 | 3148 | |
3149 | 3149 | |
@@ -3159,26 +3159,26 @@ discard block |
||
3159 | 3159 | * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d' |
3160 | 3160 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3161 | 3161 | */ |
3162 | - function _construct_in_value($values, $field_obj){ |
|
3162 | + function _construct_in_value($values, $field_obj) { |
|
3163 | 3163 | //check if the value is a CSV list |
3164 | - if(is_string($values)){ |
|
3164 | + if (is_string($values)) { |
|
3165 | 3165 | //in which case, turn it into an array |
3166 | - $values = explode(",",$values); |
|
3166 | + $values = explode(",", $values); |
|
3167 | 3167 | } |
3168 | 3168 | $cleaned_values = array(); |
3169 | - foreach($values as $value){ |
|
3170 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3169 | + foreach ($values as $value) { |
|
3170 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3171 | 3171 | } |
3172 | 3172 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3173 | 3173 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3174 | 3174 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3175 | - if(empty($cleaned_values)){ |
|
3175 | + if (empty($cleaned_values)) { |
|
3176 | 3176 | $all_fields = $this->field_settings(); |
3177 | 3177 | $a_field = array_shift($all_fields); |
3178 | 3178 | $main_table = $this->_get_main_table(); |
3179 | 3179 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3180 | 3180 | } |
3181 | - return "(".implode(",",$cleaned_values).")"; |
|
3181 | + return "(".implode(",", $cleaned_values).")"; |
|
3182 | 3182 | } |
3183 | 3183 | |
3184 | 3184 | |
@@ -3190,16 +3190,16 @@ discard block |
||
3190 | 3190 | * @throws EE_Error |
3191 | 3191 | * @return false|null|string |
3192 | 3192 | */ |
3193 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3193 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3194 | 3194 | /** @type WPDB $wpdb */ |
3195 | 3195 | global $wpdb; |
3196 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3197 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3198 | - }else{//$field_obj should really just be a data type |
|
3199 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3200 | - 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))); |
|
3196 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3197 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3198 | + } else {//$field_obj should really just be a data type |
|
3199 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3200 | + 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))); |
|
3201 | 3201 | } |
3202 | - return $wpdb->prepare($field_obj,$value); |
|
3202 | + return $wpdb->prepare($field_obj, $value); |
|
3203 | 3203 | } |
3204 | 3204 | } |
3205 | 3205 | |
@@ -3211,27 +3211,27 @@ discard block |
||
3211 | 3211 | * @throws EE_Error |
3212 | 3212 | * @return EE_Model_Field_Base |
3213 | 3213 | */ |
3214 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3214 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3215 | 3215 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3216 | 3216 | //which will help us find the database table and column |
3217 | 3217 | |
3218 | - $query_param_parts = explode(".",$query_param_name); |
|
3219 | - if(empty($query_param_parts)){ |
|
3220 | - 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)); |
|
3218 | + $query_param_parts = explode(".", $query_param_name); |
|
3219 | + if (empty($query_param_parts)) { |
|
3220 | + 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)); |
|
3221 | 3221 | } |
3222 | 3222 | $number_of_parts = count($query_param_parts); |
3223 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3224 | - if($number_of_parts == 1){ |
|
3223 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3224 | + if ($number_of_parts == 1) { |
|
3225 | 3225 | $field_name = $last_query_param_part; |
3226 | 3226 | $model_obj = $this; |
3227 | - }else{// $number_of_parts >= 2 |
|
3227 | + } else {// $number_of_parts >= 2 |
|
3228 | 3228 | //the last part is the column name, and there are only 2parts. therefore... |
3229 | 3229 | $field_name = $last_query_param_part; |
3230 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3230 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3231 | 3231 | } |
3232 | - try{ |
|
3232 | + try { |
|
3233 | 3233 | return $model_obj->field_settings_for($field_name); |
3234 | - }catch(EE_Error $e){ |
|
3234 | + } catch (EE_Error $e) { |
|
3235 | 3235 | return null; |
3236 | 3236 | } |
3237 | 3237 | } |
@@ -3245,13 +3245,13 @@ discard block |
||
3245 | 3245 | * @throws EE_Error |
3246 | 3246 | * @return string |
3247 | 3247 | */ |
3248 | - function _get_qualified_column_for_field($field_name){ |
|
3248 | + function _get_qualified_column_for_field($field_name) { |
|
3249 | 3249 | $all_fields = $this->field_settings(); |
3250 | 3250 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3251 | - if($field){ |
|
3251 | + if ($field) { |
|
3252 | 3252 | return $field->get_qualified_column(); |
3253 | - }else{ |
|
3254 | - 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))); |
|
3253 | + } else { |
|
3254 | + 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))); |
|
3255 | 3255 | } |
3256 | 3256 | } |
3257 | 3257 | |
@@ -3265,14 +3265,14 @@ discard block |
||
3265 | 3265 | * @param mixed|string $limit The limit for this select |
3266 | 3266 | * @return string The final select join element for the query. |
3267 | 3267 | */ |
3268 | - function _construct_limit_join_select( $table_alias, $limit ) { |
|
3268 | + function _construct_limit_join_select($table_alias, $limit) { |
|
3269 | 3269 | $SQL = ''; |
3270 | 3270 | |
3271 | - foreach ( $this->_tables as $table_obj ) { |
|
3272 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3273 | - $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; |
|
3274 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3275 | - $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; |
|
3271 | + foreach ($this->_tables as $table_obj) { |
|
3272 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3273 | + $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; |
|
3274 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3275 | + $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; |
|
3276 | 3276 | } |
3277 | 3277 | } |
3278 | 3278 | return $SQL; |
@@ -3285,7 +3285,7 @@ discard block |
||
3285 | 3285 | * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id" |
3286 | 3286 | * @return string SQL |
3287 | 3287 | */ |
3288 | - function _construct_internal_join(){ |
|
3288 | + function _construct_internal_join() { |
|
3289 | 3289 | $SQL = $this->_get_main_table()->get_table_sql(); |
3290 | 3290 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3291 | 3291 | return $SQL; |
@@ -3306,17 +3306,17 @@ discard block |
||
3306 | 3306 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3307 | 3307 | * @return string |
3308 | 3308 | */ |
3309 | - function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3309 | + function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3310 | 3310 | $SQL = ''; |
3311 | 3311 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3312 | - foreach($this->_tables as $table_obj){ |
|
3313 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3314 | - if($alias_sans_prefix == $table_obj->get_table_alias()){ |
|
3312 | + foreach ($this->_tables as $table_obj) { |
|
3313 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3314 | + if ($alias_sans_prefix == $table_obj->get_table_alias()) { |
|
3315 | 3315 | //so we're joining to this table, meaning the table is already in |
3316 | 3316 | //the FROM statement, BUT the primary table isn't. So we want |
3317 | 3317 | //to add the inverse join sql |
3318 | 3318 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3319 | - }else{ |
|
3319 | + } else { |
|
3320 | 3320 | //just add a regular JOIN to this table from the primary table |
3321 | 3321 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3322 | 3322 | } |
@@ -3330,9 +3330,9 @@ discard block |
||
3330 | 3330 | * 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) |
3331 | 3331 | * @return array |
3332 | 3332 | */ |
3333 | - function _get_data_types(){ |
|
3333 | + function _get_data_types() { |
|
3334 | 3334 | $data_types = array(); |
3335 | - foreach(array_values($this->field_settings()) as $field_obj){ |
|
3335 | + foreach (array_values($this->field_settings()) as $field_obj) { |
|
3336 | 3336 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3337 | 3337 | /** @var $field_obj EE_Model_Field_Base */ |
3338 | 3338 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3348,11 +3348,11 @@ discard block |
||
3348 | 3348 | * @throws EE_Error |
3349 | 3349 | * @return EEM_Base |
3350 | 3350 | */ |
3351 | - function get_related_model_obj($model_name){ |
|
3351 | + function get_related_model_obj($model_name) { |
|
3352 | 3352 | |
3353 | - $model_classname = strpos( $model_name, 'EEM_' ) === 0 ? $model_name : 'EEM_' . $model_name; |
|
3354 | - if(!class_exists($model_classname)){ |
|
3355 | - 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)); |
|
3353 | + $model_classname = strpos($model_name, 'EEM_') === 0 ? $model_name : 'EEM_'.$model_name; |
|
3354 | + if ( ! class_exists($model_classname)) { |
|
3355 | + 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)); |
|
3356 | 3356 | } |
3357 | 3357 | $model_obj = call_user_func($model_classname."::instance"); |
3358 | 3358 | return $model_obj; |
@@ -3363,7 +3363,7 @@ discard block |
||
3363 | 3363 | * Returns the array of EE_ModelRelations for this model. |
3364 | 3364 | * @return EE_Model_Relation_Base[] |
3365 | 3365 | */ |
3366 | - public function relation_settings(){ |
|
3366 | + public function relation_settings() { |
|
3367 | 3367 | return $this->_model_relations; |
3368 | 3368 | } |
3369 | 3369 | |
@@ -3373,10 +3373,10 @@ discard block |
||
3373 | 3373 | * (Eg, without an event, datetimes have little purpose.) |
3374 | 3374 | * @return EE_Belongs_To_Relation[] |
3375 | 3375 | */ |
3376 | - public function belongs_to_relations(){ |
|
3376 | + public function belongs_to_relations() { |
|
3377 | 3377 | $belongs_to_relations = array(); |
3378 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3379 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3378 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3379 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3380 | 3380 | $belongs_to_relations[$model_name] = $relation_obj; |
3381 | 3381 | } |
3382 | 3382 | } |
@@ -3391,15 +3391,15 @@ discard block |
||
3391 | 3391 | * @throws EE_Error |
3392 | 3392 | * @return EE_Model_Relation_Base |
3393 | 3393 | */ |
3394 | - public function related_settings_for($relation_name){ |
|
3395 | - $relatedModels=$this->relation_settings(); |
|
3396 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3394 | + public function related_settings_for($relation_name) { |
|
3395 | + $relatedModels = $this->relation_settings(); |
|
3396 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3397 | 3397 | throw new EE_Error( |
3398 | 3398 | sprintf( |
3399 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3399 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3400 | 3400 | $relation_name, |
3401 | 3401 | $this->_get_class_name(), |
3402 | - implode( ', ', array_keys( $relatedModels )) |
|
3402 | + implode(', ', array_keys($relatedModels)) |
|
3403 | 3403 | ) |
3404 | 3404 | ); |
3405 | 3405 | } |
@@ -3414,10 +3414,10 @@ discard block |
||
3414 | 3414 | * @throws EE_Error |
3415 | 3415 | * @return EE_Model_Field_Base |
3416 | 3416 | */ |
3417 | - public function field_settings_for($fieldName){ |
|
3418 | - $fieldSettings=$this->field_settings(true); |
|
3419 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3420 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3417 | + public function field_settings_for($fieldName) { |
|
3418 | + $fieldSettings = $this->field_settings(true); |
|
3419 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3420 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3421 | 3421 | } |
3422 | 3422 | return $fieldSettings[$fieldName]; |
3423 | 3423 | } |
@@ -3427,11 +3427,11 @@ discard block |
||
3427 | 3427 | * @param string $fieldName a key in the model's _field_settings array |
3428 | 3428 | * @return boolean |
3429 | 3429 | */ |
3430 | - public function has_field($fieldName){ |
|
3430 | + public function has_field($fieldName) { |
|
3431 | 3431 | $fieldSettings = $this->field_settings(true); |
3432 | - if( isset($fieldSettings[$fieldName])){ |
|
3432 | + if (isset($fieldSettings[$fieldName])) { |
|
3433 | 3433 | return true; |
3434 | - }else{ |
|
3434 | + } else { |
|
3435 | 3435 | return false; |
3436 | 3436 | } |
3437 | 3437 | } |
@@ -3441,11 +3441,11 @@ discard block |
||
3441 | 3441 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3442 | 3442 | * @return boolean |
3443 | 3443 | */ |
3444 | - public function has_relation($relation_name){ |
|
3444 | + public function has_relation($relation_name) { |
|
3445 | 3445 | $relations = $this->relation_settings(); |
3446 | - if(isset($relations[$relation_name])){ |
|
3446 | + if (isset($relations[$relation_name])) { |
|
3447 | 3447 | return true; |
3448 | - }else{ |
|
3448 | + } else { |
|
3449 | 3449 | return false; |
3450 | 3450 | } |
3451 | 3451 | } |
@@ -3457,7 +3457,7 @@ discard block |
||
3457 | 3457 | * @param $field_obj |
3458 | 3458 | * @return EE_Model_Field_Base |
3459 | 3459 | */ |
3460 | - public function is_primary_key_field( $field_obj ){ |
|
3460 | + public function is_primary_key_field($field_obj) { |
|
3461 | 3461 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3462 | 3462 | } |
3463 | 3463 | |
@@ -3469,16 +3469,16 @@ discard block |
||
3469 | 3469 | * @return EE_Model_Field_Base |
3470 | 3470 | * @throws EE_Error |
3471 | 3471 | */ |
3472 | - public function get_primary_key_field(){ |
|
3473 | - if( $this->_primary_key_field === NULL ){ |
|
3474 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3475 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3472 | + public function get_primary_key_field() { |
|
3473 | + if ($this->_primary_key_field === NULL) { |
|
3474 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3475 | + if ($this->is_primary_key_field($field_obj)) { |
|
3476 | 3476 | $this->_primary_key_field = $field_obj; |
3477 | 3477 | break; |
3478 | 3478 | } |
3479 | 3479 | } |
3480 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3481 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3480 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3481 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3482 | 3482 | } |
3483 | 3483 | } |
3484 | 3484 | return $this->_primary_key_field; |
@@ -3491,12 +3491,12 @@ discard block |
||
3491 | 3491 | * Internally does some caching. |
3492 | 3492 | * @return boolean |
3493 | 3493 | */ |
3494 | - public function has_primary_key_field(){ |
|
3495 | - if($this->_has_primary_key_field === null){ |
|
3496 | - try{ |
|
3494 | + public function has_primary_key_field() { |
|
3495 | + if ($this->_has_primary_key_field === null) { |
|
3496 | + try { |
|
3497 | 3497 | $this->get_primary_key_field(); |
3498 | 3498 | $this->_has_primary_key_field = true; |
3499 | - }catch(EE_Error $e){ |
|
3499 | + } catch (EE_Error $e) { |
|
3500 | 3500 | $this->_has_primary_key_field = false; |
3501 | 3501 | } |
3502 | 3502 | } |
@@ -3510,9 +3510,9 @@ discard block |
||
3510 | 3510 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3511 | 3511 | * @return EE_Model_Field_Base or null if none is found |
3512 | 3512 | */ |
3513 | - public function get_a_field_of_type($field_class_name){ |
|
3514 | - foreach($this->field_settings() as $field){ |
|
3515 | - if( $field instanceof $field_class_name ){ |
|
3513 | + public function get_a_field_of_type($field_class_name) { |
|
3514 | + foreach ($this->field_settings() as $field) { |
|
3515 | + if ($field instanceof $field_class_name) { |
|
3516 | 3516 | return $field; |
3517 | 3517 | } |
3518 | 3518 | } |
@@ -3526,21 +3526,21 @@ discard block |
||
3526 | 3526 | * @return EE_Foreign_Key_Field_Base |
3527 | 3527 | * @throws EE_Error |
3528 | 3528 | */ |
3529 | - public function get_foreign_key_to($model_name){ |
|
3530 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3531 | - foreach($this->field_settings() as $field){ |
|
3529 | + public function get_foreign_key_to($model_name) { |
|
3530 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3531 | + foreach ($this->field_settings() as $field) { |
|
3532 | 3532 | // if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){ |
3533 | - if( $field instanceof EE_Foreign_Key_Field_Base ){ |
|
3534 | - if (in_array($model_name,$field->get_model_names_pointed_to() ) ) { |
|
3535 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
3533 | + if ($field instanceof EE_Foreign_Key_Field_Base) { |
|
3534 | + if (in_array($model_name, $field->get_model_names_pointed_to())) { |
|
3535 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
3536 | 3536 | } |
3537 | 3537 | } |
3538 | 3538 | } |
3539 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3540 | - 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))); |
|
3539 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3540 | + 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))); |
|
3541 | 3541 | } |
3542 | 3542 | } |
3543 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
3543 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
3544 | 3544 | } |
3545 | 3545 | |
3546 | 3546 | |
@@ -3551,7 +3551,7 @@ discard block |
||
3551 | 3551 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3552 | 3552 | * @return EE_Table_Base |
3553 | 3553 | */ |
3554 | - function get_table_for_alias($table_alias){ |
|
3554 | + function get_table_for_alias($table_alias) { |
|
3555 | 3555 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
3556 | 3556 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
3557 | 3557 | } |
@@ -3564,25 +3564,25 @@ discard block |
||
3564 | 3564 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
3565 | 3565 | * @return EE_Model_Field_Base[] where the keys are the field's name |
3566 | 3566 | */ |
3567 | - public function field_settings($include_db_only_fields = false){ |
|
3568 | - if( $include_db_only_fields ){ |
|
3569 | - if( $this->_cached_fields === NULL ){ |
|
3567 | + public function field_settings($include_db_only_fields = false) { |
|
3568 | + if ($include_db_only_fields) { |
|
3569 | + if ($this->_cached_fields === NULL) { |
|
3570 | 3570 | $this->_cached_fields = array(); |
3571 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3572 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3573 | - $this->_cached_fields[$field_name]=$field_obj; |
|
3571 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3572 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3573 | + $this->_cached_fields[$field_name] = $field_obj; |
|
3574 | 3574 | } |
3575 | 3575 | } |
3576 | 3576 | } |
3577 | 3577 | return $this->_cached_fields; |
3578 | - }else{ |
|
3579 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
3578 | + } else { |
|
3579 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
3580 | 3580 | $this->_cached_fields_non_db_only = array(); |
3581 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3582 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3581 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3582 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3583 | 3583 | /** @var $field_obj EE_Model_Field_Base */ |
3584 | - if( ! $field_obj->is_db_only_field() ){ |
|
3585 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
3584 | + if ( ! $field_obj->is_db_only_field()) { |
|
3585 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
3586 | 3586 | } |
3587 | 3587 | } |
3588 | 3588 | } |
@@ -3601,67 +3601,67 @@ discard block |
||
3601 | 3601 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
3602 | 3602 | * @throws \EE_Error |
3603 | 3603 | */ |
3604 | - protected function _create_objects( $rows = array() ) { |
|
3605 | - $array_of_objects=array(); |
|
3606 | - if(empty($rows)){ |
|
3604 | + protected function _create_objects($rows = array()) { |
|
3605 | + $array_of_objects = array(); |
|
3606 | + if (empty($rows)) { |
|
3607 | 3607 | return array(); |
3608 | 3608 | } |
3609 | 3609 | $count_if_model_has_no_primary_key = 0; |
3610 | 3610 | $has_primary_key = $this->has_primary_key_field(); |
3611 | - if( $has_primary_key ) { |
|
3611 | + if ($has_primary_key) { |
|
3612 | 3612 | $primary_key_field = $this->get_primary_key_field(); |
3613 | 3613 | } else { |
3614 | 3614 | $primary_key_field = null; |
3615 | 3615 | } |
3616 | - foreach ( $rows as $row ) { |
|
3617 | - if(empty($row)){ |
|
3616 | + foreach ($rows as $row) { |
|
3617 | + if (empty($row)) { |
|
3618 | 3618 | //wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
3619 | 3619 | return array(); |
3620 | 3620 | } |
3621 | 3621 | //check if we've already set this object in the results array, |
3622 | 3622 | //in which case there's no need to process it further (again) |
3623 | - if( $has_primary_key ) { |
|
3623 | + if ($has_primary_key) { |
|
3624 | 3624 | $table_pk_value = $this->_get_column_value_with_table_alias_or_not( |
3625 | 3625 | $row, |
3626 | 3626 | $primary_key_field->get_qualified_column(), |
3627 | 3627 | $primary_key_field->get_table_column() |
3628 | 3628 | ); |
3629 | - if( $table_pk_value && |
|
3630 | - isset( $array_of_objects[ $table_pk_value ] ) ) { |
|
3629 | + if ($table_pk_value && |
|
3630 | + isset($array_of_objects[$table_pk_value])) { |
|
3631 | 3631 | continue; |
3632 | 3632 | } |
3633 | 3633 | } |
3634 | - $classInstance=$this->instantiate_class_from_array_or_object($row); |
|
3635 | - if( ! $classInstance ) { |
|
3634 | + $classInstance = $this->instantiate_class_from_array_or_object($row); |
|
3635 | + if ( ! $classInstance) { |
|
3636 | 3636 | throw new EE_Error( |
3637 | 3637 | sprintf( |
3638 | - __( 'Could not create instance of class %s from row %s', 'event_espresso' ), |
|
3638 | + __('Could not create instance of class %s from row %s', 'event_espresso'), |
|
3639 | 3639 | $this->get_this_model_name(), |
3640 | - http_build_query( $row ) |
|
3640 | + http_build_query($row) |
|
3641 | 3641 | ) |
3642 | 3642 | ); |
3643 | 3643 | } |
3644 | 3644 | //set the timezone on the instantiated objects |
3645 | - $classInstance->set_timezone( $this->_timezone ); |
|
3645 | + $classInstance->set_timezone($this->_timezone); |
|
3646 | 3646 | //make sure if there is any timezone setting present that we set the timezone for the object |
3647 | 3647 | $key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++; |
3648 | - $array_of_objects[ $key ] = $classInstance; |
|
3648 | + $array_of_objects[$key] = $classInstance; |
|
3649 | 3649 | //also, for all the relations of type BelongsTo, see if we can cache |
3650 | 3650 | //those related models |
3651 | 3651 | //(we could do this for other relations too, but if there are conditions |
3652 | 3652 | //that filtered out some fo the results, then we'd be caching an incomplete set |
3653 | 3653 | //so it requires a little more thought than just caching them immediately...) |
3654 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
3655 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
3654 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
3655 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3656 | 3656 | //check if this model's INFO is present. If so, cache it on the model |
3657 | 3657 | $other_model = $relation_obj->get_other_model(); |
3658 | 3658 | |
3659 | 3659 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
3660 | 3660 | |
3661 | 3661 | //if we managed to make a model object from the results, cache it on the main model object |
3662 | - if( $other_model_obj_maybe ){ |
|
3662 | + if ($other_model_obj_maybe) { |
|
3663 | 3663 | //set timezone on these other model objects if they are present |
3664 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
3664 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
3665 | 3665 | $classInstance->cache($modelName, $other_model_obj_maybe); |
3666 | 3666 | } |
3667 | 3667 | } |
@@ -3682,12 +3682,12 @@ discard block |
||
3682 | 3682 | |
3683 | 3683 | $this_model_fields_and_values = array(); |
3684 | 3684 | //setup the row using default values; |
3685 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
3685 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
3686 | 3686 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
3687 | 3687 | } |
3688 | 3688 | |
3689 | 3689 | $className = $this->_get_class_name(); |
3690 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
3690 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
3691 | 3691 | |
3692 | 3692 | return $classInstance; |
3693 | 3693 | } |
@@ -3700,40 +3700,40 @@ discard block |
||
3700 | 3700 | * or an stdClass where each property is the name of a column, |
3701 | 3701 | * @return EE_Base_Class |
3702 | 3702 | */ |
3703 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
3704 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
3705 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
3703 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
3704 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
3705 | + $cols_n_values = get_object_vars($cols_n_values); |
|
3706 | 3706 | } |
3707 | 3707 | $primary_key = NULL; |
3708 | 3708 | //make sure the array only has keys that are fields/columns on this model |
3709 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3710 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
3711 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
3709 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3710 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3711 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
3712 | 3712 | } |
3713 | - $className=$this->_get_class_name(); |
|
3713 | + $className = $this->_get_class_name(); |
|
3714 | 3714 | |
3715 | 3715 | //check we actually found results that we can use to build our model object |
3716 | 3716 | //if not, return null |
3717 | - if( $this->has_primary_key_field()){ |
|
3718 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
3717 | + if ($this->has_primary_key_field()) { |
|
3718 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3719 | 3719 | return NULL; |
3720 | 3720 | } |
3721 | 3721 | } |
3722 | 3722 | |
3723 | 3723 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
3724 | - if ( $primary_key){ |
|
3725 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
3726 | - if( ! $classInstance) { |
|
3727 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3724 | + if ($primary_key) { |
|
3725 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
3726 | + if ( ! $classInstance) { |
|
3727 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3728 | 3728 | // add this new object to the entity map |
3729 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
3729 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
3730 | 3730 | } |
3731 | - }else{ |
|
3732 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3731 | + } else { |
|
3732 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3733 | 3733 | } |
3734 | 3734 | |
3735 | 3735 | //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. |
3736 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
3736 | + $this->set_timezone($classInstance->get_timezone()); |
|
3737 | 3737 | return $classInstance; |
3738 | 3738 | } |
3739 | 3739 | /** |
@@ -3741,8 +3741,8 @@ discard block |
||
3741 | 3741 | * @param int|string $id the ID of the model object |
3742 | 3742 | * @return EE_Base_Class |
3743 | 3743 | */ |
3744 | - public function get_from_entity_map( $id ){ |
|
3745 | - return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL; |
|
3744 | + public function get_from_entity_map($id) { |
|
3745 | + return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL; |
|
3746 | 3746 | } |
3747 | 3747 | |
3748 | 3748 | |
@@ -3761,21 +3761,21 @@ discard block |
||
3761 | 3761 | * @throws EE_Error |
3762 | 3762 | * @return \EE_Base_Class |
3763 | 3763 | */ |
3764 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
3764 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
3765 | 3765 | $className = $this->_get_class_name(); |
3766 | - if( ! $object instanceof $className ){ |
|
3767 | - 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 ) ); |
|
3766 | + if ( ! $object instanceof $className) { |
|
3767 | + 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)); |
|
3768 | 3768 | } |
3769 | 3769 | /** @var $object EE_Base_Class */ |
3770 | - if ( ! $object->ID() ){ |
|
3771 | - throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this))); |
|
3770 | + if ( ! $object->ID()) { |
|
3771 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
3772 | 3772 | } |
3773 | 3773 | // double check it's not already there |
3774 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
3775 | - if ( $classInstance ) { |
|
3774 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
3775 | + if ($classInstance) { |
|
3776 | 3776 | return $classInstance; |
3777 | 3777 | } else { |
3778 | - $this->_entity_map[ $object->ID() ] = $object; |
|
3778 | + $this->_entity_map[$object->ID()] = $object; |
|
3779 | 3779 | return $object; |
3780 | 3780 | } |
3781 | 3781 | } |
@@ -3788,8 +3788,8 @@ discard block |
||
3788 | 3788 | * @param array $cols_n_values |
3789 | 3789 | * @return array |
3790 | 3790 | */ |
3791 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
3792 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3791 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3792 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3793 | 3793 | } |
3794 | 3794 | |
3795 | 3795 | |
@@ -3802,40 +3802,40 @@ discard block |
||
3802 | 3802 | * @param string $cols_n_values |
3803 | 3803 | * @return array |
3804 | 3804 | */ |
3805 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
3805 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3806 | 3806 | $this_model_fields_n_values = array(); |
3807 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
3808 | - $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() ); |
|
3807 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
3808 | + $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()); |
|
3809 | 3809 | //there is a primary key on this table and its not set. Use defaults for all its columns |
3810 | - if( $table_obj->get_pk_column() && $table_pk_value === NULL ){ |
|
3811 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
3812 | - if( ! $field_obj->is_db_only_field() ){ |
|
3810 | + if ($table_obj->get_pk_column() && $table_pk_value === NULL) { |
|
3811 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
3812 | + if ( ! $field_obj->is_db_only_field()) { |
|
3813 | 3813 | //prepare field as if its coming from db |
3814 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
3815 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
3814 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
3815 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
3816 | 3816 | } |
3817 | 3817 | } |
3818 | - }else{ |
|
3818 | + } else { |
|
3819 | 3819 | //the table's rows existed. Use their values |
3820 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
3821 | - if( ! $field_obj->is_db_only_field() ) |
|
3822 | - $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() ); |
|
3820 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
3821 | + if ( ! $field_obj->is_db_only_field()) |
|
3822 | + $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()); |
|
3823 | 3823 | } |
3824 | 3824 | } |
3825 | 3825 | } |
3826 | 3826 | return $this_model_fields_n_values; |
3827 | 3827 | } |
3828 | 3828 | |
3829 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
3829 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
3830 | 3830 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
3831 | 3831 | //does the field on the model relate to this column retrieved from the db? |
3832 | 3832 | //or is it a db-only field? (not relating to the model) |
3833 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
3834 | - $value = $cols_n_values[ $qualified_column ]; |
|
3833 | + if (isset($cols_n_values[$qualified_column])) { |
|
3834 | + $value = $cols_n_values[$qualified_column]; |
|
3835 | 3835 | |
3836 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
3837 | - $value = $cols_n_values[ $regular_column ]; |
|
3838 | - }else{ |
|
3836 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
3837 | + $value = $cols_n_values[$regular_column]; |
|
3838 | + } else { |
|
3839 | 3839 | $value = NULL; |
3840 | 3840 | } |
3841 | 3841 | |
@@ -3853,23 +3853,23 @@ discard block |
||
3853 | 3853 | * @param int|string $id |
3854 | 3854 | * @return EE_Base_Class |
3855 | 3855 | */ |
3856 | - public function refresh_entity_map_from_db( $id ){ |
|
3857 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
3858 | - if( $obj_in_map ){ |
|
3859 | - $wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) ); |
|
3860 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
3861 | - $one_row = reset( $wpdb_results ); |
|
3862 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
3863 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
3856 | + public function refresh_entity_map_from_db($id) { |
|
3857 | + $obj_in_map = $this->get_from_entity_map($id); |
|
3858 | + if ($obj_in_map) { |
|
3859 | + $wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1)); |
|
3860 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
3861 | + $one_row = reset($wpdb_results); |
|
3862 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
3863 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
3864 | 3864 | } |
3865 | 3865 | //clear the cache of related model objects |
3866 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
3867 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
3866 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
3867 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
3868 | 3868 | } |
3869 | 3869 | } |
3870 | 3870 | return $obj_in_map; |
3871 | - }else{ |
|
3872 | - return $this->get_one_by_ID( $id ); |
|
3871 | + } else { |
|
3872 | + return $this->get_one_by_ID($id); |
|
3873 | 3873 | } |
3874 | 3874 | } |
3875 | 3875 | |
@@ -3887,24 +3887,24 @@ discard block |
||
3887 | 3887 | * @param EE_Base_Class $replacing_model_obj |
3888 | 3888 | * @return \EE_Base_Class |
3889 | 3889 | */ |
3890 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
3891 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
3892 | - if( $obj_in_map ){ |
|
3893 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
3894 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
3895 | - $obj_in_map->set( $field_name, $value ); |
|
3890 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
3891 | + $obj_in_map = $this->get_from_entity_map($id); |
|
3892 | + if ($obj_in_map) { |
|
3893 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
3894 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
3895 | + $obj_in_map->set($field_name, $value); |
|
3896 | 3896 | } |
3897 | 3897 | //make the model object in the entity map's cache match the $replacing_model_obj |
3898 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
3899 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
3900 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
3901 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
3898 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
3899 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
3900 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
3901 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
3902 | 3902 | } |
3903 | 3903 | } |
3904 | 3904 | } |
3905 | 3905 | return $obj_in_map; |
3906 | - }else{ |
|
3907 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
3906 | + } else { |
|
3907 | + $this->add_to_entity_map($replacing_model_obj); |
|
3908 | 3908 | return $replacing_model_obj; |
3909 | 3909 | } |
3910 | 3910 | } |
@@ -3917,7 +3917,7 @@ discard block |
||
3917 | 3917 | * require_once($this->_getClassName().".class.php"); |
3918 | 3918 | * @return string |
3919 | 3919 | */ |
3920 | - private function _get_class_name(){ |
|
3920 | + private function _get_class_name() { |
|
3921 | 3921 | return "EE_".$this->get_this_model_name(); |
3922 | 3922 | } |
3923 | 3923 | |
@@ -3930,10 +3930,10 @@ discard block |
||
3930 | 3930 | * @param int $quantity |
3931 | 3931 | * @return string |
3932 | 3932 | */ |
3933 | - public function item_name($quantity = 1){ |
|
3934 | - if($quantity == 1){ |
|
3933 | + public function item_name($quantity = 1) { |
|
3934 | + if ($quantity == 1) { |
|
3935 | 3935 | return $this->singular_item; |
3936 | - }else{ |
|
3936 | + } else { |
|
3937 | 3937 | return $this->plural_item; |
3938 | 3938 | } |
3939 | 3939 | } |
@@ -3962,13 +3962,13 @@ discard block |
||
3962 | 3962 | * @throws EE_Error |
3963 | 3963 | * @return mixed whatever the plugin which calls add_filter decides |
3964 | 3964 | */ |
3965 | - public function __call($methodName,$args){ |
|
3966 | - $className=get_class($this); |
|
3967 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
3968 | - if(!has_filter($tagName)){ |
|
3965 | + public function __call($methodName, $args) { |
|
3966 | + $className = get_class($this); |
|
3967 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
3968 | + if ( ! has_filter($tagName)) { |
|
3969 | 3969 | throw new EE_Error( |
3970 | 3970 | sprintf( |
3971 | - __( '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' ), |
|
3971 | + __('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'), |
|
3972 | 3972 | $methodName, |
3973 | 3973 | $className, |
3974 | 3974 | $tagName, |
@@ -3977,7 +3977,7 @@ discard block |
||
3977 | 3977 | ); |
3978 | 3978 | } |
3979 | 3979 | |
3980 | - return apply_filters($tagName,null,$this,$args); |
|
3980 | + return apply_filters($tagName, null, $this, $args); |
|
3981 | 3981 | } |
3982 | 3982 | |
3983 | 3983 | |
@@ -3990,22 +3990,22 @@ discard block |
||
3990 | 3990 | * @throws EE_Error |
3991 | 3991 | * @return EE_Base_Class |
3992 | 3992 | */ |
3993 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
3993 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
3994 | 3994 | $className = $this->_get_class_name(); |
3995 | 3995 | $primary_key_field = $this->get_primary_key_field(); |
3996 | - if( $base_class_obj_or_id instanceof $className ){ |
|
3996 | + if ($base_class_obj_or_id instanceof $className) { |
|
3997 | 3997 | $model_object = $base_class_obj_or_id; |
3998 | - }elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
3999 | - is_int( $base_class_obj_or_id ) || |
|
4000 | - 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) |
|
3998 | + }elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
3999 | + is_int($base_class_obj_or_id) || |
|
4000 | + 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) |
|
4001 | 4001 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4002 | - }elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
4002 | + }elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) { |
|
4003 | 4003 | //assume its a string representation of the object |
4004 | 4004 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4005 | - }else{ |
|
4006 | - 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))); |
|
4005 | + } else { |
|
4006 | + 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))); |
|
4007 | 4007 | } |
4008 | - if( $model_object->ID() == NULL && $ensure_is_in_db){ |
|
4008 | + if ($model_object->ID() == NULL && $ensure_is_in_db) { |
|
4009 | 4009 | $model_object->save(); |
4010 | 4010 | } |
4011 | 4011 | return $model_object; |
@@ -4021,19 +4021,19 @@ discard block |
||
4021 | 4021 | * @return int|string depending on the type of this model object's ID |
4022 | 4022 | * @throws EE_Error |
4023 | 4023 | */ |
4024 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
4024 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
4025 | 4025 | $className = $this->_get_class_name(); |
4026 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4026 | + if ($base_class_obj_or_id instanceof $className) { |
|
4027 | 4027 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4028 | 4028 | $id = $base_class_obj_or_id->ID(); |
4029 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4029 | + }elseif (is_int($base_class_obj_or_id)) { |
|
4030 | 4030 | //assume it's an ID |
4031 | 4031 | $id = $base_class_obj_or_id; |
4032 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4032 | + }elseif (is_string($base_class_obj_or_id)) { |
|
4033 | 4033 | //assume its a string representation of the object |
4034 | 4034 | $id = $base_class_obj_or_id; |
4035 | - }else{ |
|
4036 | - 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))); |
|
4035 | + } else { |
|
4036 | + 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))); |
|
4037 | 4037 | } |
4038 | 4038 | return $id; |
4039 | 4039 | } |
@@ -4056,14 +4056,14 @@ discard block |
||
4056 | 4056 | * @param int $values_already_prepared like one of the constants on EEM_Base |
4057 | 4057 | * @return void |
4058 | 4058 | */ |
4059 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
4059 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
4060 | 4060 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
4061 | 4061 | } |
4062 | 4062 | /** |
4063 | 4063 | * Read comments for assume_values_already_prepared_by_model_object() |
4064 | 4064 | * @return int |
4065 | 4065 | */ |
4066 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
4066 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
4067 | 4067 | return $this->_values_already_prepared_by_model_object; |
4068 | 4068 | } |
4069 | 4069 | |
@@ -4071,17 +4071,17 @@ discard block |
||
4071 | 4071 | * Gets all the indexes on this model |
4072 | 4072 | * @return EE_Index[] |
4073 | 4073 | */ |
4074 | - public function indexes(){ |
|
4074 | + public function indexes() { |
|
4075 | 4075 | return $this->_indexes; |
4076 | 4076 | } |
4077 | 4077 | /** |
4078 | 4078 | * Gets all the Unique Indexes on this model |
4079 | 4079 | * @return EE_Unique_Index[] |
4080 | 4080 | */ |
4081 | - public function unique_indexes(){ |
|
4081 | + public function unique_indexes() { |
|
4082 | 4082 | $unique_indexes = array(); |
4083 | - foreach($this->_indexes as $name => $index){ |
|
4084 | - if($index instanceof EE_Unique_Index){ |
|
4083 | + foreach ($this->_indexes as $name => $index) { |
|
4084 | + if ($index instanceof EE_Unique_Index) { |
|
4085 | 4085 | $unique_indexes [$name] = $index; |
4086 | 4086 | } |
4087 | 4087 | } |
@@ -4094,9 +4094,9 @@ discard block |
||
4094 | 4094 | * on a primary index |
4095 | 4095 | * @return EE_Model_Field_Base[] |
4096 | 4096 | */ |
4097 | - public function get_combined_primary_key_fields(){ |
|
4098 | - foreach($this->indexes() as $index){ |
|
4099 | - if($index instanceof EE_Primary_Key_Index){ |
|
4097 | + public function get_combined_primary_key_fields() { |
|
4098 | + foreach ($this->indexes() as $index) { |
|
4099 | + if ($index instanceof EE_Primary_Key_Index) { |
|
4100 | 4100 | return $index->fields(); |
4101 | 4101 | } |
4102 | 4102 | } |
@@ -4109,7 +4109,7 @@ discard block |
||
4109 | 4109 | * @param array $cols_n_values keys are field names, values are their values |
4110 | 4110 | * @return string |
4111 | 4111 | */ |
4112 | - public function get_index_primary_key_string($cols_n_values){ |
|
4112 | + public function get_index_primary_key_string($cols_n_values) { |
|
4113 | 4113 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
4114 | 4114 | return http_build_query($cols_n_values_for_primary_key_index); |
4115 | 4115 | } |
@@ -4121,13 +4121,13 @@ discard block |
||
4121 | 4121 | * @param string $index_primary_key_string |
4122 | 4122 | * @return null|array |
4123 | 4123 | */ |
4124 | - function parse_index_primary_key_string( $index_primary_key_string) { |
|
4124 | + function parse_index_primary_key_string($index_primary_key_string) { |
|
4125 | 4125 | $key_fields = $this->get_combined_primary_key_fields(); |
4126 | 4126 | //check all of them are in the $id |
4127 | 4127 | $key_vals_in_combined_pk = array(); |
4128 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
4129 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
4130 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
4128 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
4129 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
4130 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
4131 | 4131 | return NULL; |
4132 | 4132 | } |
4133 | 4133 | } |
@@ -4140,10 +4140,10 @@ discard block |
||
4140 | 4140 | * @param array $key_vals |
4141 | 4141 | * @return boolean |
4142 | 4142 | */ |
4143 | - function has_all_combined_primary_key_fields( $key_vals ) { |
|
4144 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4145 | - foreach( $keys_it_should_have as $key ){ |
|
4146 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4143 | + function has_all_combined_primary_key_fields($key_vals) { |
|
4144 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4145 | + foreach ($keys_it_should_have as $key) { |
|
4146 | + if ( ! isset($key_vals[$key])) { |
|
4147 | 4147 | return false; |
4148 | 4148 | } |
4149 | 4149 | } |
@@ -4159,23 +4159,23 @@ discard block |
||
4159 | 4159 | * @throws EE_Error |
4160 | 4160 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4161 | 4161 | */ |
4162 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4162 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4163 | 4163 | |
4164 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4164 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4165 | 4165 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4166 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4166 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4167 | 4167 | $attributes_array = $model_object_or_attributes_array; |
4168 | - }else{ |
|
4169 | - 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)); |
|
4168 | + } else { |
|
4169 | + 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)); |
|
4170 | 4170 | } |
4171 | 4171 | //even copies obviously won't have the same ID, so remove the primary key |
4172 | 4172 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4173 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4173 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4174 | 4174 | unset($attributes_array[$this->primary_key_name()]); |
4175 | 4175 | } |
4176 | - if(isset($query_params[0])){ |
|
4177 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4178 | - }else{ |
|
4176 | + if (isset($query_params[0])) { |
|
4177 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4178 | + } else { |
|
4179 | 4179 | $query_params[0] = $attributes_array; |
4180 | 4180 | } |
4181 | 4181 | return $this->get_all($query_params); |
@@ -4189,16 +4189,16 @@ discard block |
||
4189 | 4189 | * @param array $query_params |
4190 | 4190 | * @return EE_Base_Class |
4191 | 4191 | */ |
4192 | - function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4193 | - if( ! is_array( $query_params ) ){ |
|
4194 | - 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' ); |
|
4192 | + function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4193 | + if ( ! is_array($query_params)) { |
|
4194 | + 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'); |
|
4195 | 4195 | $query_params = array(); |
4196 | 4196 | } |
4197 | 4197 | $query_params['limit'] = 1; |
4198 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4199 | - if(is_array($copies)){ |
|
4198 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4199 | + if (is_array($copies)) { |
|
4200 | 4200 | return array_shift($copies); |
4201 | - }else{ |
|
4201 | + } else { |
|
4202 | 4202 | return null; |
4203 | 4203 | } |
4204 | 4204 | } |
@@ -4212,10 +4212,10 @@ discard block |
||
4212 | 4212 | * @param int|string $id the value of the primary key to update |
4213 | 4213 | * @return int number of rows updated |
4214 | 4214 | */ |
4215 | - public function update_by_ID($fields_n_values,$id){ |
|
4215 | + public function update_by_ID($fields_n_values, $id) { |
|
4216 | 4216 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4217 | 4217 | 'default_where_conditions'=>'other_models_only',); |
4218 | - return $this->update($fields_n_values,$query_params); |
|
4218 | + return $this->update($fields_n_values, $query_params); |
|
4219 | 4219 | } |
4220 | 4220 | |
4221 | 4221 | |
@@ -4226,12 +4226,12 @@ discard block |
||
4226 | 4226 | * @return string an operator which can be used in SQL |
4227 | 4227 | * @throws EE_Error |
4228 | 4228 | */ |
4229 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4229 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4230 | 4230 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4231 | - if($sql_operator){ |
|
4231 | + if ($sql_operator) { |
|
4232 | 4232 | return $sql_operator; |
4233 | - }else{ |
|
4234 | - 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)))); |
|
4233 | + } else { |
|
4234 | + 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)))); |
|
4235 | 4235 | } |
4236 | 4236 | } |
4237 | 4237 | |
@@ -4241,10 +4241,10 @@ discard block |
||
4241 | 4241 | * @param array $query_params like get_all's |
4242 | 4242 | * @return string[] |
4243 | 4243 | */ |
4244 | - public function get_all_names($query_params = array()){ |
|
4244 | + public function get_all_names($query_params = array()) { |
|
4245 | 4245 | $objs = $this->get_all($query_params); |
4246 | 4246 | $names = array(); |
4247 | - foreach($objs as $obj){ |
|
4247 | + foreach ($objs as $obj) { |
|
4248 | 4248 | $names[$obj->ID()] = $obj->name(); |
4249 | 4249 | } |
4250 | 4250 | return $names; |
@@ -4259,22 +4259,22 @@ discard block |
||
4259 | 4259 | * @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 |
4260 | 4260 | * @return array |
4261 | 4261 | */ |
4262 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4263 | - if( ! $this->has_primary_key_field() ) { |
|
4264 | - if( WP_DEBUG ) { |
|
4265 | - EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
4262 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4263 | + if ( ! $this->has_primary_key_field()) { |
|
4264 | + if (WP_DEBUG) { |
|
4265 | + EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
4266 | 4266 | return array(); |
4267 | 4267 | } |
4268 | 4268 | } |
4269 | 4269 | $IDs = array(); |
4270 | - foreach( $model_objects as $model_object ) { |
|
4270 | + foreach ($model_objects as $model_object) { |
|
4271 | 4271 | $id = $model_object->ID(); |
4272 | - if( ! $id ) { |
|
4273 | - if( $filter_out_empty_ids ) { |
|
4272 | + if ( ! $id) { |
|
4273 | + if ($filter_out_empty_ids) { |
|
4274 | 4274 | continue; |
4275 | 4275 | } |
4276 | - if( WP_DEBUG ) { |
|
4277 | - 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__ ); |
|
4276 | + if (WP_DEBUG) { |
|
4277 | + 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__); |
|
4278 | 4278 | } |
4279 | 4279 | } |
4280 | 4280 | $IDs[] = $id; |
@@ -4287,8 +4287,8 @@ discard block |
||
4287 | 4287 | * are no capabilities that relate to this model returns false |
4288 | 4288 | * @return string|false |
4289 | 4289 | */ |
4290 | - public function cap_slug(){ |
|
4291 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4290 | + public function cap_slug() { |
|
4291 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4292 | 4292 | } |
4293 | 4293 | |
4294 | 4294 | /** |
@@ -4300,27 +4300,27 @@ discard block |
||
4300 | 4300 | * @param string $context |
4301 | 4301 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4302 | 4302 | */ |
4303 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4304 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4303 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4304 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4305 | 4305 | //check if we ought to run the restriction generator first |
4306 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
4307 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base && |
|
4308 | - ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) { |
|
4309 | - $this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ], $this->_cap_restriction_generators[ $context ]->generate_restrictions() ); |
|
4306 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
4307 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base && |
|
4308 | + ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) { |
|
4309 | + $this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions()); |
|
4310 | 4310 | } |
4311 | 4311 | //and make sure we've finalized the construction of each restriction |
4312 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4313 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4312 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4313 | + $where_conditions_obj->_finalize_construct($this); |
|
4314 | 4314 | } |
4315 | 4315 | |
4316 | - return $this->_cap_restrictions[ $context ]; |
|
4316 | + return $this->_cap_restrictions[$context]; |
|
4317 | 4317 | } |
4318 | 4318 | |
4319 | 4319 | /** |
4320 | 4320 | * Indicating whether or not this model thinks its a wp core model |
4321 | 4321 | * @return boolean |
4322 | 4322 | */ |
4323 | - public function is_wp_core_model(){ |
|
4323 | + public function is_wp_core_model() { |
|
4324 | 4324 | return $this->_wp_core_model; |
4325 | 4325 | } |
4326 | 4326 | |
@@ -4330,12 +4330,12 @@ discard block |
||
4330 | 4330 | * @param string $context one of EEM_Base::caps_ constants |
4331 | 4331 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4332 | 4332 | */ |
4333 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4333 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4334 | 4334 | $missing_caps = array(); |
4335 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4336 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4337 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4338 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4335 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4336 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4337 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4338 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4339 | 4339 | } |
4340 | 4340 | } |
4341 | 4341 | return $missing_caps; |
@@ -4347,7 +4347,7 @@ discard block |
||
4347 | 4347 | * one of 'read', 'edit', or 'delete' |
4348 | 4348 | */ |
4349 | 4349 | public function cap_contexts_to_cap_action_map() { |
4350 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4350 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4351 | 4351 | } |
4352 | 4352 | |
4353 | 4353 | |
@@ -4358,19 +4358,19 @@ discard block |
||
4358 | 4358 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4359 | 4359 | * @throws \EE_Error |
4360 | 4360 | */ |
4361 | - public function cap_action_for_context( $context ) { |
|
4361 | + public function cap_action_for_context($context) { |
|
4362 | 4362 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4363 | - if( isset( $mapping[ $context ] ) ) { |
|
4364 | - return $mapping[ $context ]; |
|
4363 | + if (isset($mapping[$context])) { |
|
4364 | + return $mapping[$context]; |
|
4365 | 4365 | } |
4366 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4366 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4367 | 4367 | return $action; |
4368 | 4368 | } |
4369 | 4369 | throw new EE_Error( |
4370 | 4370 | sprintf( |
4371 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4371 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4372 | 4372 | $context, |
4373 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4373 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4374 | 4374 | ) |
4375 | 4375 | ); |
4376 | 4376 | |
@@ -4381,7 +4381,7 @@ discard block |
||
4381 | 4381 | * @return array |
4382 | 4382 | */ |
4383 | 4383 | static public function valid_cap_contexts() { |
4384 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4384 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4385 | 4385 | self::caps_read, |
4386 | 4386 | self::caps_read_admin, |
4387 | 4387 | self::caps_edit, |
@@ -4397,17 +4397,17 @@ discard block |
||
4397 | 4397 | * @return bool |
4398 | 4398 | * @throws \EE_Error |
4399 | 4399 | */ |
4400 | - static public function verify_is_valid_cap_context( $context ) { |
|
4400 | + static public function verify_is_valid_cap_context($context) { |
|
4401 | 4401 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4402 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4402 | + if (in_array($context, $valid_cap_contexts)) { |
|
4403 | 4403 | return true; |
4404 | - }else{ |
|
4404 | + } else { |
|
4405 | 4405 | throw new EE_Error( |
4406 | 4406 | sprintf( |
4407 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4407 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4408 | 4408 | $context, |
4409 | - 'EEM_Base' , |
|
4410 | - implode(',', $valid_cap_contexts ) |
|
4409 | + 'EEM_Base', |
|
4410 | + implode(',', $valid_cap_contexts) |
|
4411 | 4411 | ) |
4412 | 4412 | ); |
4413 | 4413 | } |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | if( isset( $this->_cap_restriction_generators[ $context ] ) && |
521 | 521 | $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
522 | 522 | return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
523 | - }else{ |
|
523 | + } else{ |
|
524 | 524 | return array(); |
525 | 525 | } |
526 | 526 | } |
@@ -571,8 +571,9 @@ discard block |
||
571 | 571 | * @return array |
572 | 572 | */ |
573 | 573 | public function status_array( $translated = FALSE ) { |
574 | - if ( !array_key_exists('Status', $this->_model_relations ) ) |
|
575 | - return array(); |
|
574 | + if ( !array_key_exists('Status', $this->_model_relations ) ) { |
|
575 | + return array(); |
|
576 | + } |
|
576 | 577 | $model_name = $this->get_this_model_name(); |
577 | 578 | $status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) ); |
578 | 579 | $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
@@ -751,13 +752,13 @@ discard block |
||
751 | 752 | $last_model_name = end( $models_to_follow_to_wp_users ); |
752 | 753 | $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
753 | 754 | $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
754 | - }else{ |
|
755 | + } else{ |
|
755 | 756 | $model_with_fk_to_wp_users = $this; |
756 | 757 | $model_chain_to_wp_user = ''; |
757 | 758 | } |
758 | 759 | $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
759 | 760 | return $model_chain_to_wp_user . $wp_user_field->get_name(); |
760 | - }catch( EE_Error $e ) { |
|
761 | + } catch( EE_Error $e ) { |
|
761 | 762 | return false; |
762 | 763 | } |
763 | 764 | } |
@@ -785,11 +786,11 @@ discard block |
||
785 | 786 | public function is_owned() { |
786 | 787 | if( $this->model_chain_to_wp_user() ){ |
787 | 788 | return true; |
788 | - }else{ |
|
789 | + } else{ |
|
789 | 790 | try{ |
790 | 791 | $this->get_foreign_key_to( 'WP_User' ); |
791 | 792 | return true; |
792 | - }catch( EE_Error $e ){ |
|
793 | + } catch( EE_Error $e ){ |
|
793 | 794 | return false; |
794 | 795 | } |
795 | 796 | } |
@@ -812,9 +813,9 @@ discard block |
||
812 | 813 | //remember the custom selections, if any |
813 | 814 | if(is_array($columns_to_select)){ |
814 | 815 | $this->_custom_selections = $columns_to_select; |
815 | - }elseif(is_string($columns_to_select)){ |
|
816 | + } elseif(is_string($columns_to_select)){ |
|
816 | 817 | $this->_custom_selections = array($this->_custom_selections); |
817 | - }else{ |
|
818 | + } else{ |
|
818 | 819 | $this->_custom_selections = array(); |
819 | 820 | } |
820 | 821 | |
@@ -865,7 +866,7 @@ discard block |
||
865 | 866 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
866 | 867 | } |
867 | 868 | $columns_to_select_string = implode(", ",$select_sql_array); |
868 | - }else{ |
|
869 | + } else{ |
|
869 | 870 | $columns_to_select_string = $columns_to_select; |
870 | 871 | } |
871 | 872 | return $columns_to_select_string; |
@@ -893,10 +894,10 @@ discard block |
||
893 | 894 | function get_one_by_ID($id){ |
894 | 895 | if( $this->get_from_entity_map( $id ) ){ |
895 | 896 | return $this->get_from_entity_map( $id ); |
896 | - }elseif( $this->has_primary_key_field ( ) ) { |
|
897 | + } elseif( $this->has_primary_key_field ( ) ) { |
|
897 | 898 | $primary_key_name = $this->get_primary_key_field()->get_name(); |
898 | 899 | return $this->get_one(array(array($primary_key_name => $id))); |
899 | - }else{ |
|
900 | + } else{ |
|
900 | 901 | //no primary key, so the $id must be from the get_index_primary_key_string() |
901 | 902 | return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) ); |
902 | 903 | } |
@@ -918,7 +919,7 @@ discard block |
||
918 | 919 | $items = $this->get_all($query_params); |
919 | 920 | if(empty($items)){ |
920 | 921 | return null; |
921 | - }else{ |
|
922 | + } else{ |
|
922 | 923 | return array_shift($items); |
923 | 924 | } |
924 | 925 | } |
@@ -1313,7 +1314,7 @@ discard block |
||
1313 | 1314 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1314 | 1315 | if( $this->has_primary_key_field() ){ |
1315 | 1316 | $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
1316 | - }else{ |
|
1317 | + } else{ |
|
1317 | 1318 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it woudl be lots of work) |
1318 | 1319 | $main_table_pk_value = null; |
1319 | 1320 | } |
@@ -1352,7 +1353,7 @@ discard block |
||
1352 | 1353 | if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
1353 | 1354 | if( $this->has_primary_key_field() ){ |
1354 | 1355 | $model_objs_affected_ids = $this->get_col( $query_params ); |
1355 | - }else{ |
|
1356 | + } else{ |
|
1356 | 1357 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1357 | 1358 | $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
1358 | 1359 | $model_objs_affected_ids = array(); |
@@ -1412,9 +1413,9 @@ discard block |
||
1412 | 1413 | |
1413 | 1414 | if( $field_to_select ){ |
1414 | 1415 | $field = $this->field_settings_for( $field_to_select ); |
1415 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1416 | + } elseif( $this->has_primary_key_field ( ) ){ |
|
1416 | 1417 | $field = $this->get_primary_key_field(); |
1417 | - }else{ |
|
1418 | + } else{ |
|
1418 | 1419 | //no primary key, just grab the first column |
1419 | 1420 | $field = reset( $this->field_settings()); |
1420 | 1421 | } |
@@ -1438,7 +1439,7 @@ discard block |
||
1438 | 1439 | $col = $this->get_col( $query_params, $field_to_select ); |
1439 | 1440 | if( ! empty( $col ) ) { |
1440 | 1441 | return reset( $col ); |
1441 | - }else{ |
|
1442 | + } else{ |
|
1442 | 1443 | return NULL; |
1443 | 1444 | } |
1444 | 1445 | } |
@@ -1522,7 +1523,7 @@ discard block |
||
1522 | 1523 | |
1523 | 1524 | // /echo "delete sql:$SQL"; |
1524 | 1525 | $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
1525 | - }else{ |
|
1526 | + } else{ |
|
1526 | 1527 | $rows_deleted = 0; |
1527 | 1528 | } |
1528 | 1529 | |
@@ -1564,7 +1565,7 @@ discard block |
||
1564 | 1565 | //first, if $ignore_this_model_obj was supplied, get its model |
1565 | 1566 | if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
1566 | 1567 | $ignored_model = $ignore_this_model_obj->get_model(); |
1567 | - }else{ |
|
1568 | + } else{ |
|
1568 | 1569 | $ignored_model = null; |
1569 | 1570 | } |
1570 | 1571 | //now check all the relations of $this_model_obj_or_id and see if there |
@@ -1577,7 +1578,7 @@ discard block |
||
1577 | 1578 | if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){ |
1578 | 1579 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
1579 | 1580 | array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
1580 | - }else{ |
|
1581 | + } else{ |
|
1581 | 1582 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1582 | 1583 | } |
1583 | 1584 | |
@@ -1614,24 +1615,28 @@ discard block |
||
1614 | 1615 | } |
1615 | 1616 | |
1616 | 1617 | //primary table deletes |
1617 | - if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) |
|
1618 | - $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1618 | + if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) { |
|
1619 | + $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1620 | + } |
|
1619 | 1621 | |
1620 | 1622 | //other tables |
1621 | 1623 | if ( !empty( $other_tables ) ) { |
1622 | 1624 | foreach ( $other_tables as $ot ) { |
1623 | 1625 | |
1624 | 1626 | //first check if we've got the foreign key column here. |
1625 | - if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) |
|
1626 | - $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1627 | + if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) { |
|
1628 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1629 | + } |
|
1627 | 1630 | |
1628 | 1631 | //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 |
1629 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) |
|
1630 | - $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1632 | + if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) { |
|
1633 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1634 | + } |
|
1631 | 1635 | |
1632 | 1636 | //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! |
1633 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) |
|
1634 | - $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1637 | + if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) { |
|
1638 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1639 | + } |
|
1635 | 1640 | } |
1636 | 1641 | } |
1637 | 1642 | } |
@@ -1644,7 +1649,7 @@ discard block |
||
1644 | 1649 | } |
1645 | 1650 | |
1646 | 1651 | return !empty($query) ? implode(' AND ', $query ) : ''; |
1647 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1652 | + } elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1648 | 1653 | $ways_to_identify_a_row = array(); |
1649 | 1654 | $fields = $this->get_combined_primary_key_fields(); |
1650 | 1655 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
@@ -1656,7 +1661,7 @@ discard block |
||
1656 | 1661 | $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
1657 | 1662 | } |
1658 | 1663 | return implode(" OR ",$ways_to_identify_a_row); |
1659 | - }else{ |
|
1664 | + } else{ |
|
1660 | 1665 | //so there's no primary key and no combined key... |
1661 | 1666 | //sorry, can't help you |
1662 | 1667 | 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))); |
@@ -1678,10 +1683,10 @@ discard block |
||
1678 | 1683 | if($field_to_count){ |
1679 | 1684 | $field_obj = $this->field_settings_for($field_to_count); |
1680 | 1685 | $column_to_count = $field_obj->get_qualified_column(); |
1681 | - }elseif($this->has_primary_key_field ()){ |
|
1686 | + } elseif($this->has_primary_key_field ()){ |
|
1682 | 1687 | $pk_field_obj = $this->get_primary_key_field(); |
1683 | 1688 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1684 | - }else{//there's no primary key |
|
1689 | + } else{//there's no primary key |
|
1685 | 1690 | $column_to_count = '*'; |
1686 | 1691 | } |
1687 | 1692 | |
@@ -1703,7 +1708,7 @@ discard block |
||
1703 | 1708 | if($field_to_sum){ |
1704 | 1709 | $field_obj = $this->field_settings_for($field_to_sum); |
1705 | 1710 | |
1706 | - }else{ |
|
1711 | + } else{ |
|
1707 | 1712 | $field_obj = $this->get_primary_key_field(); |
1708 | 1713 | } |
1709 | 1714 | $column_to_count = $field_obj->get_qualified_column(); |
@@ -1712,7 +1717,7 @@ discard block |
||
1712 | 1717 | $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
1713 | 1718 | if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){ |
1714 | 1719 | return (float)$return_value; |
1715 | - }else{//must be %f |
|
1720 | + } else{//must be %f |
|
1716 | 1721 | return (float)$return_value; |
1717 | 1722 | } |
1718 | 1723 | } |
@@ -1750,10 +1755,10 @@ discard block |
||
1750 | 1755 | $wpdb->show_errors( $old_show_errors_value ); |
1751 | 1756 | if( ! empty( $wpdb->last_error ) ){ |
1752 | 1757 | throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
1753 | - }elseif( $result === false ){ |
|
1758 | + } elseif( $result === false ){ |
|
1754 | 1759 | 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 ) ) ); |
1755 | 1760 | } |
1756 | - }elseif( $result === false ) { |
|
1761 | + } elseif( $result === false ) { |
|
1757 | 1762 | EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
1758 | 1763 | } |
1759 | 1764 | return $result; |
@@ -2063,7 +2068,7 @@ discard block |
||
2063 | 2068 | $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
2064 | 2069 | if( $results ){ |
2065 | 2070 | return array_shift($results); |
2066 | - }else{ |
|
2071 | + } else{ |
|
2067 | 2072 | return null; |
2068 | 2073 | } |
2069 | 2074 | |
@@ -2134,7 +2139,7 @@ discard block |
||
2134 | 2139 | */ |
2135 | 2140 | do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
2136 | 2141 | return $new_id; |
2137 | - }else{ |
|
2142 | + } else{ |
|
2138 | 2143 | return FALSE; |
2139 | 2144 | } |
2140 | 2145 | } |
@@ -2175,9 +2180,9 @@ discard block |
||
2175 | 2180 | public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
2176 | 2181 | if($obj_or_fields_array instanceof EE_Base_Class){ |
2177 | 2182 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2178 | - }elseif( is_array($obj_or_fields_array)){ |
|
2183 | + } elseif( is_array($obj_or_fields_array)){ |
|
2179 | 2184 | $fields_n_values = $obj_or_fields_array; |
2180 | - }else{ |
|
2185 | + } else{ |
|
2181 | 2186 | 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)); |
2182 | 2187 | } |
2183 | 2188 | $query_params = array(); |
@@ -2193,7 +2198,7 @@ discard block |
||
2193 | 2198 | //if there is nothing to base this search on, then we shouldn't find anything |
2194 | 2199 | if( empty( $query_params ) ){ |
2195 | 2200 | return array(); |
2196 | - }else{ |
|
2201 | + } else{ |
|
2197 | 2202 | return $this->get_one($query_params); |
2198 | 2203 | } |
2199 | 2204 | } |
@@ -2266,12 +2271,12 @@ discard block |
||
2266 | 2271 | if($this->has_primary_key_field()){ |
2267 | 2272 | if($this->get_primary_key_field()->is_auto_increment()){ |
2268 | 2273 | return $wpdb->insert_id; |
2269 | - }else{ |
|
2274 | + } else{ |
|
2270 | 2275 | //it's not an auto-increment primary key, so |
2271 | 2276 | //it must have been supplied |
2272 | 2277 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2273 | 2278 | } |
2274 | - }else{ |
|
2279 | + } else{ |
|
2275 | 2280 | //we can't return a primary key because there is none. instead return |
2276 | 2281 | //a unique string indicating this model |
2277 | 2282 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2319,7 +2324,7 @@ discard block |
||
2319 | 2324 | //leave the value alone |
2320 | 2325 | } |
2321 | 2326 | return $value; |
2322 | - }else{ |
|
2327 | + } else{ |
|
2323 | 2328 | return $value; |
2324 | 2329 | } |
2325 | 2330 | } |
@@ -2412,7 +2417,7 @@ discard block |
||
2412 | 2417 | if(array_key_exists('group_by', $query_params)){ |
2413 | 2418 | if(is_array($query_params['group_by'])){ |
2414 | 2419 | $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by'); |
2415 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2420 | + } elseif( ! empty ( $query_params['group_by'] )){ |
|
2416 | 2421 | $this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by'); |
2417 | 2422 | } |
2418 | 2423 | } |
@@ -2420,10 +2425,11 @@ discard block |
||
2420 | 2425 | $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having'); |
2421 | 2426 | } |
2422 | 2427 | if(array_key_exists('order_by', $query_params)){ |
2423 | - if ( is_array( $query_params['order_by'] ) ) |
|
2424 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2425 | - elseif( ! empty( $query_params['order_by'] )) |
|
2426 | - $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2428 | + if ( is_array( $query_params['order_by'] ) ) { |
|
2429 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2430 | + } elseif( ! empty( $query_params['order_by'] )) { |
|
2431 | + $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2432 | + } |
|
2427 | 2433 | } |
2428 | 2434 | if(array_key_exists('force_join', $query_params)){ |
2429 | 2435 | $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join'); |
@@ -2455,10 +2461,10 @@ discard block |
||
2455 | 2461 | if (! is_array($possibly_array_of_params)){ |
2456 | 2462 | 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"), |
2457 | 2463 | $param,$possibly_array_of_params)); |
2458 | - }else{ |
|
2464 | + } else{ |
|
2459 | 2465 | $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
2460 | 2466 | } |
2461 | - }elseif($query_param_type === 0 //ie WHERE |
|
2467 | + } elseif($query_param_type === 0 //ie WHERE |
|
2462 | 2468 | && is_array($possibly_array_of_params) |
2463 | 2469 | && isset($possibly_array_of_params[2]) |
2464 | 2470 | && $possibly_array_of_params[2] == true){ |
@@ -2518,7 +2524,7 @@ discard block |
||
2518 | 2524 | } |
2519 | 2525 | if( isset( $query_params[0] ) ) { |
2520 | 2526 | $where_query_params = $query_params[0]; |
2521 | - }else{ |
|
2527 | + } else{ |
|
2522 | 2528 | $where_query_params = array(); |
2523 | 2529 | } |
2524 | 2530 | //first check if we should alter the query to account for caps or not |
@@ -2536,7 +2542,7 @@ discard block |
||
2536 | 2542 | } |
2537 | 2543 | if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){ |
2538 | 2544 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2539 | - }else{ |
|
2545 | + } else{ |
|
2540 | 2546 | $use_default_where_conditions = 'all'; |
2541 | 2547 | } |
2542 | 2548 | $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 ); |
@@ -2559,7 +2565,7 @@ discard block |
||
2559 | 2565 | } |
2560 | 2566 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2561 | 2567 | $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
2562 | - }elseif( ! empty ( $query_params['limit'] )){ |
|
2568 | + } elseif( ! empty ( $query_params['limit'] )){ |
|
2563 | 2569 | $query_object->set_limit_sql((" LIMIT ".$query_params['limit'])); |
2564 | 2570 | } |
2565 | 2571 | } |
@@ -2581,11 +2587,11 @@ discard block |
||
2581 | 2587 | $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
2582 | 2588 | } |
2583 | 2589 | $query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array)); |
2584 | - }elseif( ! empty ( $query_params['order_by'] )){ |
|
2590 | + } elseif( ! empty ( $query_params['order_by'] )){ |
|
2585 | 2591 | $this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']); |
2586 | 2592 | if(isset($query_params['order'])){ |
2587 | 2593 | $order = $this->_extract_order($query_params['order']); |
2588 | - }else{ |
|
2594 | + } else{ |
|
2589 | 2595 | $order = 'DESC'; |
2590 | 2596 | } |
2591 | 2597 | $query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order); |
@@ -2608,7 +2614,7 @@ discard block |
||
2608 | 2614 | $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
2609 | 2615 | } |
2610 | 2616 | $query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array)); |
2611 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2617 | + } elseif( ! empty ( $query_params['group_by'] )){ |
|
2612 | 2618 | $query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])); |
2613 | 2619 | } |
2614 | 2620 | } |
@@ -2632,8 +2638,9 @@ discard block |
||
2632 | 2638 | } |
2633 | 2639 | } |
2634 | 2640 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2635 | - if ( empty( $main_model_join_sql ) ) |
|
2636 | - $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
2641 | + if ( empty( $main_model_join_sql ) ) { |
|
2642 | + $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
2643 | + } |
|
2637 | 2644 | return $query_object; |
2638 | 2645 | } |
2639 | 2646 | |
@@ -2666,7 +2673,7 @@ discard block |
||
2666 | 2673 | private function _extract_order($should_be_order_string){ |
2667 | 2674 | if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
2668 | 2675 | return $should_be_order_string; |
2669 | - }else{ |
|
2676 | + } else{ |
|
2670 | 2677 | 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)); |
2671 | 2678 | } |
2672 | 2679 | } |
@@ -2692,7 +2699,7 @@ discard block |
||
2692 | 2699 | } |
2693 | 2700 | if( in_array($use_default_where_conditions, array('all','this_model_only')) ){ |
2694 | 2701 | $universal_query_params = $this->_get_default_where_conditions(); |
2695 | - }else{ |
|
2702 | + } else{ |
|
2696 | 2703 | $universal_query_params = array(); |
2697 | 2704 | } |
2698 | 2705 | |
@@ -2732,14 +2739,14 @@ discard block |
||
2732 | 2739 | foreach($default_where_conditions as $key => $val){ |
2733 | 2740 | if( isset($provided_where_conditions[$key])){ |
2734 | 2741 | $none_overridden = false; |
2735 | - }else{ |
|
2742 | + } else{ |
|
2736 | 2743 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
2737 | 2744 | } |
2738 | 2745 | } |
2739 | 2746 | if( $none_overridden && $default_where_conditions){ |
2740 | 2747 | if($model->has_primary_key_field()){ |
2741 | 2748 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
2742 | - }else{ |
|
2749 | + } else{ |
|
2743 | 2750 | //@todo NO PK, use other defaults |
2744 | 2751 | } |
2745 | 2752 | } |
@@ -2755,8 +2762,9 @@ discard block |
||
2755 | 2762 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2756 | 2763 | */ |
2757 | 2764 | private function _get_default_where_conditions($model_relation_path = null){ |
2758 | - if ( $this->_ignore_where_strategy ) |
|
2759 | - return array(); |
|
2765 | + if ( $this->_ignore_where_strategy ) { |
|
2766 | + return array(); |
|
2767 | + } |
|
2760 | 2768 | |
2761 | 2769 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
2762 | 2770 | } |
@@ -2830,7 +2838,7 @@ discard block |
||
2830 | 2838 | if(array_key_exists($query_param,$this_model_fields)){ |
2831 | 2839 | if($allow_fields){ |
2832 | 2840 | return; |
2833 | - }else{ |
|
2841 | + } else{ |
|
2834 | 2842 | 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"), |
2835 | 2843 | $query_param,get_class($this),$query_param_type,$original_query_param)); |
2836 | 2844 | } |
@@ -2839,7 +2847,7 @@ discard block |
||
2839 | 2847 | elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
2840 | 2848 | if($allow_logic_query_params){ |
2841 | 2849 | return; |
2842 | - }else{ |
|
2850 | + } else{ |
|
2843 | 2851 | throw new EE_Error( |
2844 | 2852 | sprintf( |
2845 | 2853 | __( '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' ), |
@@ -2870,12 +2878,12 @@ discard block |
||
2870 | 2878 | //we should actually end in a field name, not a model like this! |
2871 | 2879 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
2872 | 2880 | $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
2873 | - }else{ |
|
2881 | + } else{ |
|
2874 | 2882 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
2875 | 2883 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
2876 | 2884 | return; |
2877 | 2885 | } |
2878 | - }elseif($query_param == $valid_related_model_name){ |
|
2886 | + } elseif($query_param == $valid_related_model_name){ |
|
2879 | 2887 | $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
2880 | 2888 | return; |
2881 | 2889 | } |
@@ -2935,7 +2943,7 @@ discard block |
||
2935 | 2943 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
2936 | 2944 | if($SQL){ |
2937 | 2945 | return " WHERE ". $SQL; |
2938 | - }else{ |
|
2946 | + } else{ |
|
2939 | 2947 | return ''; |
2940 | 2948 | } |
2941 | 2949 | } |
@@ -2950,7 +2958,7 @@ discard block |
||
2950 | 2958 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
2951 | 2959 | if($SQL){ |
2952 | 2960 | return " HAVING ". $SQL; |
2953 | - }else{ |
|
2961 | + } else{ |
|
2954 | 2962 | return ''; |
2955 | 2963 | } |
2956 | 2964 | |
@@ -2973,7 +2981,7 @@ discard block |
||
2973 | 2981 | $model_instance=call_user_func($model_name."::instance"); |
2974 | 2982 | /* @var $model_instance EEM_Base */ |
2975 | 2983 | return $model_instance->field_settings_for($field_name); |
2976 | - }else{ |
|
2984 | + } else{ |
|
2977 | 2985 | throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
2978 | 2986 | } |
2979 | 2987 | } |
@@ -3006,14 +3014,14 @@ discard block |
||
3006 | 3014 | $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
3007 | 3015 | break; |
3008 | 3016 | } |
3009 | - }else{ |
|
3017 | + } else{ |
|
3010 | 3018 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3011 | 3019 | |
3012 | 3020 | //if it's not a normal field, maybe it's a custom selection? |
3013 | 3021 | if( ! $field_obj){ |
3014 | 3022 | if(isset( $this->_custom_selections[$query_param][1])){ |
3015 | 3023 | $field_obj = $this->_custom_selections[$query_param][1]; |
3016 | - }else{ |
|
3024 | + } else{ |
|
3017 | 3025 | throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
3018 | 3026 | } |
3019 | 3027 | } |
@@ -3023,7 +3031,7 @@ discard block |
||
3023 | 3031 | } |
3024 | 3032 | if($where_clauses){ |
3025 | 3033 | $SQL = implode($glue,$where_clauses); |
3026 | - }else{ |
|
3034 | + } else{ |
|
3027 | 3035 | $SQL = ''; |
3028 | 3036 | } |
3029 | 3037 | return $SQL; |
@@ -3043,11 +3051,11 @@ discard block |
||
3043 | 3051 | if( $field ){ |
3044 | 3052 | $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
3045 | 3053 | return $table_alias_prefix . $field->get_qualified_column(); |
3046 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3054 | + } elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3047 | 3055 | //maybe it's custom selection item? |
3048 | 3056 | //if so, just use it as the "column name" |
3049 | 3057 | return $query_param; |
3050 | - }else{ |
|
3058 | + } else{ |
|
3051 | 3059 | 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))); |
3052 | 3060 | } |
3053 | 3061 | } |
@@ -3064,7 +3072,7 @@ discard block |
||
3064 | 3072 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3065 | 3073 | if($pos_of_star === FALSE){ |
3066 | 3074 | return $condition_query_param_key; |
3067 | - }else{ |
|
3075 | + } else{ |
|
3068 | 3076 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3069 | 3077 | return $condition_query_param_sans_star; |
3070 | 3078 | } |
@@ -3090,7 +3098,7 @@ discard block |
||
3090 | 3098 | 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))); |
3091 | 3099 | } |
3092 | 3100 | $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
3093 | - }else{ |
|
3101 | + } else{ |
|
3094 | 3102 | $operator = '='; |
3095 | 3103 | $value = $op_and_value; |
3096 | 3104 | } |
@@ -3098,7 +3106,7 @@ discard block |
||
3098 | 3106 | //check to see if the value is actually another field |
3099 | 3107 | if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){ |
3100 | 3108 | return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
3101 | - }elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3109 | + } elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3102 | 3110 | //in this case, the value should be an array, or at least a comma-separated list |
3103 | 3111 | //it will need to handle a little differently |
3104 | 3112 | $cleaned_value = $this->_construct_in_value($value, $field_obj); |
@@ -3106,8 +3114,9 @@ discard block |
||
3106 | 3114 | return $operator.SP.$cleaned_value; |
3107 | 3115 | } elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
3108 | 3116 | //the value should be an array with count of two. |
3109 | - if ( count($value) !== 2 ) |
|
3110 | - 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" ) ); |
|
3117 | + if ( count($value) !== 2 ) { |
|
3118 | + 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" ) ); |
|
3119 | + } |
|
3111 | 3120 | $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
3112 | 3121 | return $operator.SP.$cleaned_value; |
3113 | 3122 | } elseif( in_array( $operator, $this->_null_style_operators ) ) { |
@@ -3115,17 +3124,17 @@ discard block |
||
3115 | 3124 | 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)); |
3116 | 3125 | } |
3117 | 3126 | return $operator; |
3118 | - }elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3127 | + } elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3119 | 3128 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3120 | 3129 | //remove other junk. So just treat it as a string. |
3121 | 3130 | return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
3122 | - }elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3131 | + } elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3123 | 3132 | return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj); |
3124 | - }elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3133 | + } elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3125 | 3134 | 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)); |
3126 | - }elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3135 | + } elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3127 | 3136 | 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)); |
3128 | - }else{ |
|
3137 | + } else{ |
|
3129 | 3138 | 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))); |
3130 | 3139 | } |
3131 | 3140 | } |
@@ -3195,7 +3204,7 @@ discard block |
||
3195 | 3204 | global $wpdb; |
3196 | 3205 | if($field_obj instanceof EE_Model_Field_Base){ |
3197 | 3206 | return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
3198 | - }else{//$field_obj should really just be a data type |
|
3207 | + } else{//$field_obj should really just be a data type |
|
3199 | 3208 | if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
3200 | 3209 | 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))); |
3201 | 3210 | } |
@@ -3224,14 +3233,14 @@ discard block |
||
3224 | 3233 | if($number_of_parts == 1){ |
3225 | 3234 | $field_name = $last_query_param_part; |
3226 | 3235 | $model_obj = $this; |
3227 | - }else{// $number_of_parts >= 2 |
|
3236 | + } else{// $number_of_parts >= 2 |
|
3228 | 3237 | //the last part is the column name, and there are only 2parts. therefore... |
3229 | 3238 | $field_name = $last_query_param_part; |
3230 | 3239 | $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
3231 | 3240 | } |
3232 | 3241 | try{ |
3233 | 3242 | return $model_obj->field_settings_for($field_name); |
3234 | - }catch(EE_Error $e){ |
|
3243 | + } catch(EE_Error $e){ |
|
3235 | 3244 | return null; |
3236 | 3245 | } |
3237 | 3246 | } |
@@ -3250,7 +3259,7 @@ discard block |
||
3250 | 3259 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3251 | 3260 | if($field){ |
3252 | 3261 | return $field->get_qualified_column(); |
3253 | - }else{ |
|
3262 | + } else{ |
|
3254 | 3263 | 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))); |
3255 | 3264 | } |
3256 | 3265 | } |
@@ -3316,7 +3325,7 @@ discard block |
||
3316 | 3325 | //the FROM statement, BUT the primary table isn't. So we want |
3317 | 3326 | //to add the inverse join sql |
3318 | 3327 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3319 | - }else{ |
|
3328 | + } else{ |
|
3320 | 3329 | //just add a regular JOIN to this table from the primary table |
3321 | 3330 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3322 | 3331 | } |
@@ -3431,7 +3440,7 @@ discard block |
||
3431 | 3440 | $fieldSettings = $this->field_settings(true); |
3432 | 3441 | if( isset($fieldSettings[$fieldName])){ |
3433 | 3442 | return true; |
3434 | - }else{ |
|
3443 | + } else{ |
|
3435 | 3444 | return false; |
3436 | 3445 | } |
3437 | 3446 | } |
@@ -3445,7 +3454,7 @@ discard block |
||
3445 | 3454 | $relations = $this->relation_settings(); |
3446 | 3455 | if(isset($relations[$relation_name])){ |
3447 | 3456 | return true; |
3448 | - }else{ |
|
3457 | + } else{ |
|
3449 | 3458 | return false; |
3450 | 3459 | } |
3451 | 3460 | } |
@@ -3496,7 +3505,7 @@ discard block |
||
3496 | 3505 | try{ |
3497 | 3506 | $this->get_primary_key_field(); |
3498 | 3507 | $this->_has_primary_key_field = true; |
3499 | - }catch(EE_Error $e){ |
|
3508 | + } catch(EE_Error $e){ |
|
3500 | 3509 | $this->_has_primary_key_field = false; |
3501 | 3510 | } |
3502 | 3511 | } |
@@ -3575,7 +3584,7 @@ discard block |
||
3575 | 3584 | } |
3576 | 3585 | } |
3577 | 3586 | return $this->_cached_fields; |
3578 | - }else{ |
|
3587 | + } else{ |
|
3579 | 3588 | if( $this->_cached_fields_non_db_only === NULL ){ |
3580 | 3589 | $this->_cached_fields_non_db_only = array(); |
3581 | 3590 | foreach($this->_fields as $fields_corresponding_to_table){ |
@@ -3728,7 +3737,7 @@ discard block |
||
3728 | 3737 | // add this new object to the entity map |
3729 | 3738 | $classInstance = $this->add_to_entity_map( $classInstance ); |
3730 | 3739 | } |
3731 | - }else{ |
|
3740 | + } else{ |
|
3732 | 3741 | $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
3733 | 3742 | } |
3734 | 3743 | |
@@ -3815,11 +3824,12 @@ discard block |
||
3815 | 3824 | $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
3816 | 3825 | } |
3817 | 3826 | } |
3818 | - }else{ |
|
3827 | + } else{ |
|
3819 | 3828 | //the table's rows existed. Use their values |
3820 | 3829 | foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
3821 | - if( ! $field_obj->is_db_only_field() ) |
|
3822 | - $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() ); |
|
3830 | + if( ! $field_obj->is_db_only_field() ) { |
|
3831 | + $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() ); |
|
3832 | + } |
|
3823 | 3833 | } |
3824 | 3834 | } |
3825 | 3835 | } |
@@ -3833,9 +3843,9 @@ discard block |
||
3833 | 3843 | if( isset( $cols_n_values[ $qualified_column ] ) ){ |
3834 | 3844 | $value = $cols_n_values[ $qualified_column ]; |
3835 | 3845 | |
3836 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
3846 | + } elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
3837 | 3847 | $value = $cols_n_values[ $regular_column ]; |
3838 | - }else{ |
|
3848 | + } else{ |
|
3839 | 3849 | $value = NULL; |
3840 | 3850 | } |
3841 | 3851 | |
@@ -3868,7 +3878,7 @@ discard block |
||
3868 | 3878 | } |
3869 | 3879 | } |
3870 | 3880 | return $obj_in_map; |
3871 | - }else{ |
|
3881 | + } else{ |
|
3872 | 3882 | return $this->get_one_by_ID( $id ); |
3873 | 3883 | } |
3874 | 3884 | } |
@@ -3903,7 +3913,7 @@ discard block |
||
3903 | 3913 | } |
3904 | 3914 | } |
3905 | 3915 | return $obj_in_map; |
3906 | - }else{ |
|
3916 | + } else{ |
|
3907 | 3917 | $this->add_to_entity_map( $replacing_model_obj ); |
3908 | 3918 | return $replacing_model_obj; |
3909 | 3919 | } |
@@ -3933,7 +3943,7 @@ discard block |
||
3933 | 3943 | public function item_name($quantity = 1){ |
3934 | 3944 | if($quantity == 1){ |
3935 | 3945 | return $this->singular_item; |
3936 | - }else{ |
|
3946 | + } else{ |
|
3937 | 3947 | return $this->plural_item; |
3938 | 3948 | } |
3939 | 3949 | } |
@@ -3995,14 +4005,14 @@ discard block |
||
3995 | 4005 | $primary_key_field = $this->get_primary_key_field(); |
3996 | 4006 | if( $base_class_obj_or_id instanceof $className ){ |
3997 | 4007 | $model_object = $base_class_obj_or_id; |
3998 | - }elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
4008 | + } elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
3999 | 4009 | is_int( $base_class_obj_or_id ) || |
4000 | 4010 | 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) |
4001 | 4011 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4002 | - }elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
4012 | + } elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
4003 | 4013 | //assume its a string representation of the object |
4004 | 4014 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4005 | - }else{ |
|
4015 | + } else{ |
|
4006 | 4016 | 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))); |
4007 | 4017 | } |
4008 | 4018 | if( $model_object->ID() == NULL && $ensure_is_in_db){ |
@@ -4026,13 +4036,13 @@ discard block |
||
4026 | 4036 | if( $base_class_obj_or_id instanceof $className ){ |
4027 | 4037 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4028 | 4038 | $id = $base_class_obj_or_id->ID(); |
4029 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4039 | + } elseif(is_int($base_class_obj_or_id)){ |
|
4030 | 4040 | //assume it's an ID |
4031 | 4041 | $id = $base_class_obj_or_id; |
4032 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4042 | + } elseif(is_string($base_class_obj_or_id)){ |
|
4033 | 4043 | //assume its a string representation of the object |
4034 | 4044 | $id = $base_class_obj_or_id; |
4035 | - }else{ |
|
4045 | + } else{ |
|
4036 | 4046 | 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))); |
4037 | 4047 | } |
4038 | 4048 | return $id; |
@@ -4163,9 +4173,9 @@ discard block |
||
4163 | 4173 | |
4164 | 4174 | if($model_object_or_attributes_array instanceof EE_Base_Class){ |
4165 | 4175 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4166 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4176 | + } elseif(is_array($model_object_or_attributes_array)){ |
|
4167 | 4177 | $attributes_array = $model_object_or_attributes_array; |
4168 | - }else{ |
|
4178 | + } else{ |
|
4169 | 4179 | 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)); |
4170 | 4180 | } |
4171 | 4181 | //even copies obviously won't have the same ID, so remove the primary key |
@@ -4175,7 +4185,7 @@ discard block |
||
4175 | 4185 | } |
4176 | 4186 | if(isset($query_params[0])){ |
4177 | 4187 | $query_params[0] = array_merge($attributes_array,$query_params); |
4178 | - }else{ |
|
4188 | + } else{ |
|
4179 | 4189 | $query_params[0] = $attributes_array; |
4180 | 4190 | } |
4181 | 4191 | return $this->get_all($query_params); |
@@ -4198,7 +4208,7 @@ discard block |
||
4198 | 4208 | $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
4199 | 4209 | if(is_array($copies)){ |
4200 | 4210 | return array_shift($copies); |
4201 | - }else{ |
|
4211 | + } else{ |
|
4202 | 4212 | return null; |
4203 | 4213 | } |
4204 | 4214 | } |
@@ -4230,7 +4240,7 @@ discard block |
||
4230 | 4240 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4231 | 4241 | if($sql_operator){ |
4232 | 4242 | return $sql_operator; |
4233 | - }else{ |
|
4243 | + } else{ |
|
4234 | 4244 | 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)))); |
4235 | 4245 | } |
4236 | 4246 | } |
@@ -4401,7 +4411,7 @@ discard block |
||
4401 | 4411 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4402 | 4412 | if( in_array( $context, $valid_cap_contexts ) ) { |
4403 | 4413 | return true; |
4404 | - }else{ |
|
4414 | + } else{ |
|
4405 | 4415 | throw new EE_Error( |
4406 | 4416 | sprintf( |
4407 | 4417 | __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
@@ -47,25 +47,25 @@ discard block |
||
47 | 47 | |
48 | 48 | |
49 | 49 | /** |
50 | - * date format |
|
51 | - * |
|
52 | - * pattern or format for displaying dates |
|
53 | - * |
|
54 | - * @access protected |
|
55 | - * @var string |
|
56 | - */ |
|
50 | + * date format |
|
51 | + * |
|
52 | + * pattern or format for displaying dates |
|
53 | + * |
|
54 | + * @access protected |
|
55 | + * @var string |
|
56 | + */ |
|
57 | 57 | protected $_dt_frmt; |
58 | 58 | |
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * time format |
|
63 | - * |
|
64 | - * pattern or format for displaying time |
|
65 | - * |
|
66 | - * @access protected |
|
67 | - * @var string |
|
68 | - */ |
|
61 | + /** |
|
62 | + * time format |
|
63 | + * |
|
64 | + * pattern or format for displaying time |
|
65 | + * |
|
66 | + * @access protected |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | protected $_tm_frmt; |
70 | 70 | |
71 | 71 | |
@@ -205,12 +205,12 @@ discard block |
||
205 | 205 | |
206 | 206 | |
207 | 207 | /** |
208 | - * Gets the field's original value when this object was constructed during this request. |
|
209 | - * This can be helpful when determining if a model object has changed or not |
|
210 | - * |
|
211 | - * @param string $field_name |
|
212 | - * @return mixed|null |
|
213 | - */ |
|
208 | + * Gets the field's original value when this object was constructed during this request. |
|
209 | + * This can be helpful when determining if a model object has changed or not |
|
210 | + * |
|
211 | + * @param string $field_name |
|
212 | + * @return mixed|null |
|
213 | + */ |
|
214 | 214 | public function get_original( $field_name ){ |
215 | 215 | if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
216 | 216 | $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
@@ -1273,7 +1273,7 @@ discard block |
||
1273 | 1273 | */ |
1274 | 1274 | do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
1275 | 1275 | $result = $this->get_model()->delete_by_ID( $this->ID() ); |
1276 | - $this->refresh_cache_of_related_objects(); |
|
1276 | + $this->refresh_cache_of_related_objects(); |
|
1277 | 1277 | /** |
1278 | 1278 | * Called just after deleting a model object |
1279 | 1279 | * @param EE_Base_Class $model_object that was just 'deleted' |
@@ -1293,35 +1293,35 @@ discard block |
||
1293 | 1293 | $model=$this->get_model(); |
1294 | 1294 | if($model instanceof EEM_Soft_Delete_Base){ |
1295 | 1295 | $result=$model->delete_permanently_by_ID($this->ID()); |
1296 | - $this->refresh_cache_of_related_objects(); |
|
1296 | + $this->refresh_cache_of_related_objects(); |
|
1297 | 1297 | }else{ |
1298 | 1298 | $result = $this->delete(); |
1299 | 1299 | } |
1300 | 1300 | return $result ? true : false; |
1301 | 1301 | } |
1302 | 1302 | |
1303 | - /** |
|
1304 | - * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
1305 | - * related model objects |
|
1306 | - */ |
|
1307 | - public function refresh_cache_of_related_objects() { |
|
1308 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1309 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1310 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
1311 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1312 | - //this relation only stores a single model object, not an array |
|
1313 | - //but let's make it consistent |
|
1314 | - $related_objects = array( $related_objects ); |
|
1315 | - } |
|
1316 | - foreach( $related_objects as $related_object ) { |
|
1317 | - //only refresh their cache if they're in memory |
|
1318 | - if( $related_object instanceof EE_Base_Class ) { |
|
1303 | + /** |
|
1304 | + * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
1305 | + * related model objects |
|
1306 | + */ |
|
1307 | + public function refresh_cache_of_related_objects() { |
|
1308 | + foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1309 | + if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1310 | + $related_objects = $this->_model_relations[ $relation_name ]; |
|
1311 | + if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1312 | + //this relation only stores a single model object, not an array |
|
1313 | + //but let's make it consistent |
|
1314 | + $related_objects = array( $related_objects ); |
|
1315 | + } |
|
1316 | + foreach( $related_objects as $related_object ) { |
|
1317 | + //only refresh their cache if they're in memory |
|
1318 | + if( $related_object instanceof EE_Base_Class ) { |
|
1319 | 1319 | $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
1320 | - } |
|
1321 | - } |
|
1322 | - } |
|
1323 | - } |
|
1324 | - } |
|
1320 | + } |
|
1321 | + } |
|
1322 | + } |
|
1323 | + } |
|
1324 | + } |
|
1325 | 1325 | |
1326 | 1326 | |
1327 | 1327 | |
@@ -1671,9 +1671,9 @@ discard block |
||
1671 | 1671 | $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
1672 | 1672 | //clear cache so future get_many_related and get_first_related() return new results. |
1673 | 1673 | $this->clear_cache( $relationName, $otherObject, TRUE ); |
1674 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1675 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1676 | - } |
|
1674 | + if( $otherObject instanceof EE_Base_Class ) { |
|
1675 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1676 | + } |
|
1677 | 1677 | } else { |
1678 | 1678 | //this thing doesn't exist in the DB, so just cache it |
1679 | 1679 | if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
@@ -1687,18 +1687,18 @@ discard block |
||
1687 | 1687 | } |
1688 | 1688 | $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
1689 | 1689 | } |
1690 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1691 | - //fix the reciprocal relation too |
|
1692 | - if( $otherObject->ID() ) { |
|
1693 | - //its saved so assumed relations exist in the DB, so we can just |
|
1694 | - //clear the cache so future queries use the updated info in the DB |
|
1695 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1696 | - } else { |
|
1697 | - |
|
1698 | - //it's not saved, so it caches relations like this |
|
1699 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1700 | - } |
|
1701 | - } |
|
1690 | + if( $otherObject instanceof EE_Base_Class ) { |
|
1691 | + //fix the reciprocal relation too |
|
1692 | + if( $otherObject->ID() ) { |
|
1693 | + //its saved so assumed relations exist in the DB, so we can just |
|
1694 | + //clear the cache so future queries use the updated info in the DB |
|
1695 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1696 | + } else { |
|
1697 | + |
|
1698 | + //it's not saved, so it caches relations like this |
|
1699 | + $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1700 | + } |
|
1701 | + } |
|
1702 | 1702 | return $otherObject; |
1703 | 1703 | } |
1704 | 1704 | |
@@ -1728,9 +1728,9 @@ discard block |
||
1728 | 1728 | //this doesn't exist in the DB, just remove it from the cache |
1729 | 1729 | $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
1730 | 1730 | } |
1731 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1732 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1733 | - } |
|
1731 | + if( $otherObject instanceof EE_Base_Class ) { |
|
1732 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1733 | + } |
|
1734 | 1734 | return $otherObject; |
1735 | 1735 | } |
1736 | 1736 | |
@@ -1749,11 +1749,11 @@ discard block |
||
1749 | 1749 | //this doesn't exist in the DB, just remove it from the cache |
1750 | 1750 | $otherObjects = $this->clear_cache( $relationName, null, true ); |
1751 | 1751 | } |
1752 | - if( is_array( $otherObjects ) ) { |
|
1753 | - foreach ( $otherObjects as $otherObject ) { |
|
1754 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1755 | - } |
|
1756 | - } |
|
1752 | + if( is_array( $otherObjects ) ) { |
|
1753 | + foreach ( $otherObjects as $otherObject ) { |
|
1754 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1755 | + } |
|
1756 | + } |
|
1757 | 1757 | return $otherObjects; |
1758 | 1758 | } |
1759 | 1759 |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @access protected |
511 | 511 | * @param string $fieldname the property item the corresponding value is for. |
512 | 512 | * @param mixed $value The value we are caching. |
513 | - * @param null $cache_type |
|
513 | + * @param string $cache_type |
|
514 | 514 | * @return void |
515 | 515 | */ |
516 | 516 | protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | * |
824 | 824 | * @param null $field_to_order_by What field is being used as the reference point. |
825 | 825 | * @param array $query_params Any additional conditions on the query. |
826 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
826 | + * @param string $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
827 | 827 | * you can indicate just the columns you want returned |
828 | 828 | * |
829 | 829 | * @return array|EE_Base_Class |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | * |
849 | 849 | * @param null $field_to_order_by What field is being used as the reference point. |
850 | 850 | * @param array $query_params Any additional conditions on the query. |
851 | - * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
851 | + * @param string $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
852 | 852 | * you can indicate just the column you want returned |
853 | 853 | * |
854 | 854 | * @return array|EE_Base_Class |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | /** |
912 | 912 | * This method simply returns the RAW unprocessed value for the given property in this class |
913 | 913 | * @param string $field_name A valid fieldname |
914 | - * @return mixed Whatever the raw value stored on the property is. |
|
914 | + * @return integer|null Whatever the raw value stored on the property is. |
|
915 | 915 | * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
916 | 916 | */ |
917 | 917 | public function get_raw($field_name) { |
@@ -985,11 +985,11 @@ discard block |
||
985 | 985 | * |
986 | 986 | * @access protected |
987 | 987 | * @param string $field_name Field on the instantiated EE_Base_Class child object |
988 | - * @param null $dt_frmt valid datetime format used for date (if '' then we just use the default on the field, if NULL we use the last-used format) |
|
989 | - * @param null $tm_frmt Same as above except this is for time format |
|
988 | + * @param string|null $dt_frmt valid datetime format used for date (if '' then we just use the default on the field, if NULL we use the last-used format) |
|
989 | + * @param null|string $tm_frmt Same as above except this is for time format |
|
990 | 990 | * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
991 | 991 | * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
992 | - * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
|
992 | + * @return string|boolean | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
|
993 | 993 | */ |
994 | 994 | protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
995 | 995 | |
@@ -1162,7 +1162,7 @@ discard block |
||
1162 | 1162 | * sets the time on a datetime property |
1163 | 1163 | * |
1164 | 1164 | * @access protected |
1165 | - * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
1165 | + * @param string $time a valid time string for php datetime functions (or DateTime object) |
|
1166 | 1166 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
1167 | 1167 | */ |
1168 | 1168 | protected function _set_time_for( $time, $fieldname ) { |
@@ -1177,7 +1177,7 @@ discard block |
||
1177 | 1177 | * sets the date on a datetime property |
1178 | 1178 | * |
1179 | 1179 | * @access protected |
1180 | - * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
1180 | + * @param string $date a valid date string for php datetime functions ( or DateTime object) |
|
1181 | 1181 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
1182 | 1182 | */ |
1183 | 1183 | protected function _set_date_for( $date, $fieldname ) { |
@@ -1506,7 +1506,7 @@ discard block |
||
1506 | 1506 | |
1507 | 1507 | /** |
1508 | 1508 | * for getting a model while instantiated. |
1509 | - * @return \EEM_Base | \EEM_CPT_Base |
|
1509 | + * @return boolean | \EEM_CPT_Base |
|
1510 | 1510 | */ |
1511 | 1511 | public function get_model() { |
1512 | 1512 | $modelName = self::_get_model_classname( get_class($this) ); |
@@ -1537,7 +1537,7 @@ discard block |
||
1537 | 1537 | * If there is a key in the incoming array that matches the primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not we return false. |
1538 | 1538 | * @param array $props_n_values incoming array of properties and their values |
1539 | 1539 | * @param string $classname the classname of the child class |
1540 | - * @param null $timezone |
|
1540 | + * @param null|string $timezone |
|
1541 | 1541 | * @return mixed (EE_Base_Class|bool) |
1542 | 1542 | */ |
1543 | 1543 | protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL ) { |
@@ -1573,7 +1573,7 @@ discard block |
||
1573 | 1573 | * @param $classname |
1574 | 1574 | * @param null $timezone |
1575 | 1575 | * @throws EE_Error |
1576 | - * @return EEM_Base |
|
1576 | + * @return boolean |
|
1577 | 1577 | */ |
1578 | 1578 | protected static function _get_model( $classname, $timezone = NULL ){ |
1579 | 1579 | //find model for this class |
@@ -1589,8 +1589,8 @@ discard block |
||
1589 | 1589 | /** |
1590 | 1590 | * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
1591 | 1591 | * @param string $model_classname |
1592 | - * @param null $timezone |
|
1593 | - * @return EEM_Base |
|
1592 | + * @param string|null $timezone |
|
1593 | + * @return boolean |
|
1594 | 1594 | */ |
1595 | 1595 | protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
1596 | 1596 | $model_classname = str_replace( 'EEM_', '', $model_classname ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * Event Espresso |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * ------------------------------------------------------------------------ |
25 | 25 | */ |
26 | 26 | |
27 | -abstract class EE_Base_Class{ |
|
27 | +abstract class EE_Base_Class { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * This is an array of the original properties and values provided during construction |
@@ -117,60 +117,60 @@ discard block |
||
117 | 117 | * @throws EE_Error |
118 | 118 | * @return \EE_Base_Class |
119 | 119 | */ |
120 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array() ){ |
|
120 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array()) { |
|
121 | 121 | |
122 | - $className=get_class($this); |
|
122 | + $className = get_class($this); |
|
123 | 123 | |
124 | - do_action("AHEE__{$className}__construct",$this,$fieldValues); |
|
125 | - $model=$this->get_model(); |
|
126 | - $model_fields = $model->field_settings( FALSE ); |
|
124 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
125 | + $model = $this->get_model(); |
|
126 | + $model_fields = $model->field_settings(FALSE); |
|
127 | 127 | // ensure $fieldValues is an array |
128 | - $fieldValues = is_array( $fieldValues ) ? $fieldValues : array( $fieldValues ); |
|
128 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
129 | 129 | // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
130 | 130 | // verify client code has not passed any invalid field names |
131 | - foreach($fieldValues as $field_name=> $field_value){ |
|
132 | - if( ! isset( $model_fields[ $field_name] ) ){ |
|
133 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"),$field_name,get_class($this),implode(", ",array_keys($model_fields)))); |
|
131 | + foreach ($fieldValues as $field_name=> $field_value) { |
|
132 | + if ( ! isset($model_fields[$field_name])) { |
|
133 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
137 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
138 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
137 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
138 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
139 | 139 | |
140 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
140 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
141 | 141 | $this->_dt_frmt = $date_formats[0]; |
142 | 142 | $this->_tm_frmt = $date_formats[1]; |
143 | 143 | } else { |
144 | 144 | //set default formats for date and time |
145 | - $this->_dt_frmt = get_option( 'date_format' ); |
|
146 | - $this->_tm_frmt = get_option( 'time_format' ); |
|
145 | + $this->_dt_frmt = get_option('date_format'); |
|
146 | + $this->_tm_frmt = get_option('time_format'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | //if db model is instantiating |
150 | - if ( $bydb ){ |
|
150 | + if ($bydb) { |
|
151 | 151 | //client code has indicated these field values are from the database |
152 | - foreach( $model_fields as $fieldName => $field ){ |
|
153 | - $this->set_from_db( $fieldName, isset( $fieldValues[ $fieldName] ) ? $fieldValues[ $fieldName ] : null ); |
|
152 | + foreach ($model_fields as $fieldName => $field) { |
|
153 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
154 | 154 | } |
155 | 155 | } else { |
156 | 156 | //we're constructing a brand |
157 | 157 | //new instance of the model object. Generally, this means we'll need to do more field validation |
158 | - foreach( $model_fields as $fieldName => $field ){ |
|
159 | - $this->set( $fieldName, isset( $fieldValues[ $fieldName ] ) ? $fieldValues[ $fieldName ] : null, true ); |
|
158 | + foreach ($model_fields as $fieldName => $field) { |
|
159 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | //remember what values were passed to this constructor |
164 | 164 | $this->_props_n_values_provided_in_constructor = $fieldValues; |
165 | 165 | //remember in entity mapper |
166 | - if($model->has_primary_key_field() && $this->ID() && ! $bydb ){ |
|
166 | + if ($model->has_primary_key_field() && $this->ID() && ! $bydb) { |
|
167 | 167 | $model->add_to_entity_map($this); |
168 | 168 | } |
169 | 169 | //setup all the relations |
170 | - foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
|
171 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
170 | + foreach ($this->get_model()->relation_settings() as $relation_name=>$relation_obj) { |
|
171 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
172 | 172 | $this->_model_relations[$relation_name] = NULL; |
173 | - }else{ |
|
173 | + } else { |
|
174 | 174 | $this->_model_relations[$relation_name] = array(); |
175 | 175 | } |
176 | 176 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * Action done at the end of each model object construction |
179 | 179 | * @param EE_Base_Class $this the model object just created |
180 | 180 | */ |
181 | - do_action( 'AHEE__EE_Base_Class__construct__finished', $this ); |
|
181 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @param boolean $allow_persist |
199 | 199 | * @return boolean |
200 | 200 | */ |
201 | - function set_allow_persist( $allow_persist ) { |
|
201 | + function set_allow_persist($allow_persist) { |
|
202 | 202 | return $this->_allow_persist = $allow_persist; |
203 | 203 | } |
204 | 204 | |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | * @param string $field_name |
212 | 212 | * @return mixed|null |
213 | 213 | */ |
214 | - public function get_original( $field_name ){ |
|
215 | - if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
|
216 | - $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
|
217 | - return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
|
218 | - }else{ |
|
214 | + public function get_original($field_name) { |
|
215 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) && |
|
216 | + $field_settings = $this->get_Model()->field_settings_for($field_name)) { |
|
217 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
218 | + } else { |
|
219 | 219 | return NULL; |
220 | 220 | } |
221 | 221 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param EE_Base_Class $obj |
226 | 226 | * @return string |
227 | 227 | */ |
228 | - public function get_class($obj){ |
|
228 | + public function get_class($obj) { |
|
229 | 229 | return get_class($obj); |
230 | 230 | } |
231 | 231 | |
@@ -238,19 +238,19 @@ discard block |
||
238 | 238 | * @param mixed $field_value |
239 | 239 | * @param bool $use_default |
240 | 240 | */ |
241 | - public function set( $field_name, $field_value, $use_default = FALSE ){ |
|
242 | - $field_obj = $this->get_model()->field_settings_for( $field_name ); |
|
243 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
241 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
242 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
243 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
244 | 244 | // if ( method_exists( $field_obj, 'set_timezone' )) { |
245 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
246 | - $field_obj->set_timezone( $this->_timezone ); |
|
247 | - $field_obj->set_date_format( $this->_dt_frmt ); |
|
248 | - $field_obj->set_time_format( $this->_tm_frmt ); |
|
245 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
246 | + $field_obj->set_timezone($this->_timezone); |
|
247 | + $field_obj->set_date_format($this->_dt_frmt); |
|
248 | + $field_obj->set_time_format($this->_tm_frmt); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | $holder_of_value = $field_obj->prepare_for_set($field_value); |
252 | 252 | //should the value be null? |
253 | - if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){ |
|
253 | + if (($field_value === NULL || $holder_of_value === NULL || $holder_of_value === '') && $use_default) { |
|
254 | 254 | $this->_fields[$field_name] = $field_obj->get_default_value(); |
255 | 255 | |
256 | 256 | /** |
@@ -260,19 +260,19 @@ discard block |
||
260 | 260 | * object. |
261 | 261 | * @since 4.6.10+ |
262 | 262 | */ |
263 | - if ( $field_obj instanceof EE_Datetime_Field && ! is_null( $this->_fields[$field_name] ) && ! $this->_fields[$field_name] instanceof DateTime ) { |
|
264 | - empty( $this->_fields[$field_name] ) ? $this->set( $field_name, time() ) : $this->set( $field_name, $this->_fields[$field_name] ); |
|
263 | + if ($field_obj instanceof EE_Datetime_Field && ! is_null($this->_fields[$field_name]) && ! $this->_fields[$field_name] instanceof DateTime) { |
|
264 | + empty($this->_fields[$field_name]) ? $this->set($field_name, time()) : $this->set($field_name, $this->_fields[$field_name]); |
|
265 | 265 | } |
266 | 266 | |
267 | - }else{ |
|
267 | + } else { |
|
268 | 268 | $this->_fields[$field_name] = $holder_of_value; |
269 | 269 | } |
270 | 270 | |
271 | 271 | //if we're not in the constructor... |
272 | 272 | //now check if what we set was a primary key |
273 | - if($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
273 | + if ($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
274 | 274 | $field_name == $this->_get_primary_key_name(get_class($this)) && |
275 | - $field_value){ |
|
275 | + $field_value) { |
|
276 | 276 | //if so, we want all this object's fields to be filled either with |
277 | 277 | //what we've explicitly set on this model |
278 | 278 | //or what we have in the db |
@@ -280,20 +280,20 @@ discard block |
||
280 | 280 | $fields_on_model = $this->_get_model(get_class($this))->field_settings(); |
281 | 281 | |
282 | 282 | $obj_in_db = $this->_get_model(get_class($this))->get_one_by_ID($field_value); |
283 | - foreach($fields_on_model as $field_obj){ |
|
284 | - if( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
285 | - && $field_obj->get_name() != $field_name ){ |
|
283 | + foreach ($fields_on_model as $field_obj) { |
|
284 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
285 | + && $field_obj->get_name() != $field_name) { |
|
286 | 286 | |
287 | - $this->set($field_obj->get_name(),$obj_in_db->get($field_obj->get_name())); |
|
287 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | //oh this model object has an ID? well make sure its in the entity mapper |
291 | 291 | $this->get_model()->add_to_entity_map($this); |
292 | 292 | } |
293 | 293 | //let's unset any cache for this field_name from the $_cached_properties property. |
294 | - $this->_clear_cached_property( $field_name ); |
|
295 | - }else{ |
|
296 | - throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
|
294 | + $this->_clear_cached_property($field_name); |
|
295 | + } else { |
|
296 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name)); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | } |
@@ -312,14 +312,14 @@ discard block |
||
312 | 312 | * @param mixed $field_value The value to set. |
313 | 313 | * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
314 | 314 | */ |
315 | - public function set_field_or_extra_meta( $field_name, $field_value ) { |
|
316 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
317 | - $this->set( $field_name, $field_value ); |
|
315 | + public function set_field_or_extra_meta($field_name, $field_value) { |
|
316 | + if ($this->get_model()->has_field($field_name)) { |
|
317 | + $this->set($field_name, $field_value); |
|
318 | 318 | return true; |
319 | 319 | } else { |
320 | 320 | //ensure this object is saved first so that extra meta can be properly related. |
321 | 321 | $this->save(); |
322 | - return $this->update_extra_meta( $field_name, $field_value ); |
|
322 | + return $this->update_extra_meta($field_name, $field_value); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
@@ -343,12 +343,12 @@ discard block |
||
343 | 343 | * @param string $field_name expecting the fully qualified field name. |
344 | 344 | * @return mixed|null value for the field if found. null if not found. |
345 | 345 | */ |
346 | - public function get_field_or_extra_meta( $field_name ) { |
|
347 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
348 | - $column_value = $this->get( $field_name ); |
|
346 | + public function get_field_or_extra_meta($field_name) { |
|
347 | + if ($this->get_model()->has_field($field_name)) { |
|
348 | + $column_value = $this->get($field_name); |
|
349 | 349 | } else { |
350 | 350 | //This isn't a column in the main table, let's see if it is in the extra meta. |
351 | - $column_value = $this->get_extra_meta( $field_name, true, null ); |
|
351 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
352 | 352 | } |
353 | 353 | return $column_value; |
354 | 354 | } |
@@ -367,19 +367,19 @@ discard block |
||
367 | 367 | * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
368 | 368 | * @return void |
369 | 369 | */ |
370 | - public function set_timezone( $timezone = '' ) { |
|
370 | + public function set_timezone($timezone = '') { |
|
371 | 371 | EE_Registry::instance()->load_helper('DTT_Helper'); |
372 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
372 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
373 | 373 | //make sure we clear all cached properties because they won't be relevant now |
374 | 374 | $this->_clear_cached_properties(); |
375 | 375 | |
376 | 376 | //make sure we update field settings and the date for all EE_Datetime_Fields |
377 | - $model_fields = $this->get_model()->field_settings( false ); |
|
378 | - foreach ( $model_fields as $field_name => $field_obj ) { |
|
379 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
380 | - $field_obj->set_timezone( $this->_timezone ); |
|
381 | - if ( isset( $this->_fields[$field_name] ) && $this->_fields[$field_name] instanceof DateTime ) { |
|
382 | - $this->_fields[$field_name]->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
377 | + $model_fields = $this->get_model()->field_settings(false); |
|
378 | + foreach ($model_fields as $field_name => $field_obj) { |
|
379 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
380 | + $field_obj->set_timezone($this->_timezone); |
|
381 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
382 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | * |
409 | 409 | * @param string $format should be a format recognizable by PHP date() functions. |
410 | 410 | */ |
411 | - public function set_date_format( $format ) { |
|
411 | + public function set_date_format($format) { |
|
412 | 412 | $this->_dt_frmt = $format; |
413 | 413 | //clear cached_properties because they won't be relevant now. |
414 | 414 | $this->_clear_cached_properties(); |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * @since 4.6 |
425 | 425 | * @param string $format should be a format recognizable by PHP date() functions. |
426 | 426 | */ |
427 | - public function set_time_format( $format ) { |
|
427 | + public function set_time_format($format) { |
|
428 | 428 | $this->_tm_frmt = $format; |
429 | 429 | //clear cached_properties because they won't be relevant now. |
430 | 430 | $this->_clear_cached_properties(); |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | * |
442 | 442 | * @return mixed string|array |
443 | 443 | */ |
444 | - public function get_format( $full = true ) { |
|
445 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array( $this->_dt_frmt, $this->_tm_frmt ); |
|
444 | + public function get_format($full = true) { |
|
445 | + return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | |
@@ -460,17 +460,17 @@ discard block |
||
460 | 460 | * @throws EE_Error |
461 | 461 | * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array) |
462 | 462 | */ |
463 | - public function cache( $relationName = '', $object_to_cache = NULL, $cache_id = NULL ){ |
|
463 | + public function cache($relationName = '', $object_to_cache = NULL, $cache_id = NULL) { |
|
464 | 464 | // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
465 | - if ( ! $object_to_cache instanceof EE_Base_Class ) { |
|
465 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
466 | 466 | return FALSE; |
467 | 467 | } |
468 | 468 | // also get "how" the object is related, or throw an error |
469 | - if( ! $relationship_to_model = $this->get_model()->related_settings_for( $relationName )) { |
|
470 | - throw new EE_Error( sprintf( __( 'There is no relationship to %s on a %s. Cannot cache it', 'event_espresso' ), $relationName, get_class( $this ))); |
|
469 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
470 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
471 | 471 | } |
472 | 472 | // how many things are related ? |
473 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ){ |
|
473 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
474 | 474 | // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
475 | 475 | // so for these model objects just set it to be cached |
476 | 476 | $this->_model_relations[$relationName] = $object_to_cache; |
@@ -478,26 +478,26 @@ discard block |
||
478 | 478 | } else { |
479 | 479 | // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
480 | 480 | // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
481 | - if( ! is_array( $this->_model_relations[$relationName] )) { |
|
481 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
482 | 482 | // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
483 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array( $this->_model_relations[$relationName] ) : array(); |
|
483 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
484 | 484 | } |
485 | 485 | // first check for a cache_id which is normally empty |
486 | - if ( ! empty( $cache_id )) { |
|
486 | + if ( ! empty($cache_id)) { |
|
487 | 487 | // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
488 | - $this->_model_relations[$relationName][ $cache_id ] = $object_to_cache; |
|
488 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
489 | 489 | $return = $cache_id; |
490 | - } elseif ( $object_to_cache->ID() ) { |
|
490 | + } elseif ($object_to_cache->ID()) { |
|
491 | 491 | // OR the cached object originally came from the db, so let's just use it's PK for an ID |
492 | - $this->_model_relations[$relationName][ $object_to_cache->ID() ] = $object_to_cache; |
|
492 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
493 | 493 | $return = $object_to_cache->ID(); |
494 | 494 | } else { |
495 | 495 | // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
496 | 496 | $this->_model_relations[$relationName][] = $object_to_cache; |
497 | 497 | // move the internal pointer to the end of the array |
498 | - end( $this->_model_relations[$relationName] ); |
|
498 | + end($this->_model_relations[$relationName]); |
|
499 | 499 | // and grab the key so that we can return it |
500 | - $return = key( $this->_model_relations[$relationName] ); |
|
500 | + $return = key($this->_model_relations[$relationName]); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | } |
@@ -515,11 +515,11 @@ discard block |
||
515 | 515 | * @param null $cache_type |
516 | 516 | * @return void |
517 | 517 | */ |
518 | - protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
|
518 | + protected function _set_cached_property($fieldname, $value, $cache_type = NULL) { |
|
519 | 519 | //first make sure this property exists |
520 | 520 | $this->get_model()->field_settings_for($fieldname); |
521 | 521 | |
522 | - $cache_type = empty( $cache_type ) ? 'standard' : $cache_type; |
|
522 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
523 | 523 | $this->_cached_properties[$fieldname][$cache_type] = $value; |
524 | 524 | } |
525 | 525 | |
@@ -534,34 +534,34 @@ discard block |
||
534 | 534 | * It can also accept certain pre-defined "schema" strings to define how to output the property. see the field's prepare_for_pretty_echoing for what strings can be used |
535 | 535 | * @return mixed whatever the value for the property is we're retrieving |
536 | 536 | */ |
537 | - protected function _get_cached_property( $fieldname, $pretty = FALSE, $extra_cache_ref = NULL ) { |
|
537 | + protected function _get_cached_property($fieldname, $pretty = FALSE, $extra_cache_ref = NULL) { |
|
538 | 538 | //verify the field exists |
539 | 539 | $this->get_model()->field_settings_for($fieldname); |
540 | 540 | |
541 | 541 | $cache_type = $pretty ? 'pretty' : 'standard'; |
542 | - $cache_type .= !empty( $extra_cache_ref ) ? '_' . $extra_cache_ref : ''; |
|
542 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
543 | 543 | |
544 | - if ( isset( $this->_cached_properties[$fieldname][$cache_type] ) ) { |
|
544 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
545 | 545 | return $this->_cached_properties[$fieldname][$cache_type]; |
546 | 546 | } |
547 | 547 | |
548 | 548 | $field_obj = $this->get_model()->field_settings_for($fieldname); |
549 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
549 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
550 | 550 | /** |
551 | 551 | * maybe this is EE_Datetime_Field. If so we need to make sure timezone and |
552 | 552 | * formats are correct. |
553 | 553 | */ |
554 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
555 | - $field_obj->set_timezone( $this->_timezone ); |
|
556 | - $field_obj->set_date_format( $this->_dt_frmt, $pretty ); |
|
557 | - $field_obj->set_time_format( $this->_tm_frmt, $pretty ); |
|
554 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
555 | + $field_obj->set_timezone($this->_timezone); |
|
556 | + $field_obj->set_date_format($this->_dt_frmt, $pretty); |
|
557 | + $field_obj->set_time_format($this->_tm_frmt, $pretty); |
|
558 | 558 | } |
559 | 559 | |
560 | - if( ! isset($this->_fields[$fieldname])){ |
|
560 | + if ( ! isset($this->_fields[$fieldname])) { |
|
561 | 561 | $this->_fields[$fieldname] = NULL; |
562 | 562 | } |
563 | - $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname] ); |
|
564 | - $this->_set_cached_property( $fieldname, $value, $cache_type ); |
|
563 | + $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
564 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
565 | 565 | return $value; |
566 | 566 | } |
567 | 567 | return FALSE; |
@@ -587,9 +587,9 @@ discard block |
||
587 | 587 | * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
588 | 588 | * @return void |
589 | 589 | */ |
590 | - protected function _clear_cached_property( $property_name ) { |
|
591 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
592 | - unset( $this->_cached_properties[ $property_name ] ); |
|
590 | + protected function _clear_cached_property($property_name) { |
|
591 | + if (isset($this->_cached_properties[$property_name])) |
|
592 | + unset($this->_cached_properties[$property_name]); |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | * @param string $model_name name of the related thing, eg 'Attendee', |
601 | 601 | * @return EE_Base_Class |
602 | 602 | */ |
603 | - protected function ensure_related_thing_is_model_obj($object_or_id,$model_name){ |
|
603 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) { |
|
604 | 604 | $other_model_instance = self::_get_model_instance_with_name(self::_get_model_classname($model_name), $this->_timezone); |
605 | 605 | $model_obj = $other_model_instance->ensure_is_obj($object_or_id); |
606 | 606 | return $model_obj; |
@@ -620,55 +620,55 @@ discard block |
||
620 | 620 | * @throws EE_Error |
621 | 621 | * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
622 | 622 | */ |
623 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE){ |
|
623 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE) { |
|
624 | 624 | $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
625 | 625 | $index_in_cache = ''; |
626 | - if( ! $relationship_to_model){ |
|
627 | - throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache",'event_espresso'),$relationName,get_class($this))); |
|
626 | + if ( ! $relationship_to_model) { |
|
627 | + throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), $relationName, get_class($this))); |
|
628 | 628 | } |
629 | - if($clear_all){ |
|
629 | + if ($clear_all) { |
|
630 | 630 | $obj_removed = true; |
631 | 631 | $this->_model_relations[$relationName] = null; |
632 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
632 | + }elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
633 | 633 | $obj_removed = $this->_model_relations[$relationName]; |
634 | 634 | $this->_model_relations[$relationName] = null; |
635 | - }else{ |
|
636 | - if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
|
635 | + } else { |
|
636 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
637 | 637 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
638 | - if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
|
638 | + if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
639 | 639 | $index_found_at = NULL; |
640 | 640 | //find this object in the array even though it has a different key |
641 | - foreach($this->_model_relations[$relationName] as $index=>$obj){ |
|
642 | - if( $obj instanceof EE_Base_Class && ( $obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID() )) { |
|
641 | + foreach ($this->_model_relations[$relationName] as $index=>$obj) { |
|
642 | + if ($obj instanceof EE_Base_Class && ($obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID())) { |
|
643 | 643 | $index_found_at = $index; |
644 | 644 | break; |
645 | 645 | } |
646 | 646 | } |
647 | - if($index_found_at){ |
|
647 | + if ($index_found_at) { |
|
648 | 648 | $index_in_cache = $index_found_at; |
649 | - }else{ |
|
649 | + } else { |
|
650 | 650 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
651 | 651 | //if it wasn't in it to begin with. So we're done |
652 | 652 | return $object_to_remove_or_index_into_array; |
653 | 653 | } |
654 | 654 | } |
655 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
655 | + }elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
656 | 656 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
657 | - foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
|
658 | - if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
|
657 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
658 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
659 | 659 | $index_in_cache = $index; |
660 | 660 | } |
661 | 661 | } |
662 | - }else{ |
|
662 | + } else { |
|
663 | 663 | $index_in_cache = $object_to_remove_or_index_into_array; |
664 | 664 | } |
665 | 665 | //supposedly we've found it. But it could just be that the client code |
666 | 666 | //provided a bad index/object |
667 | - if(isset( $this->_model_relations[$relationName]) && |
|
668 | - isset( $this->_model_relations[$relationName][$index_in_cache])){ |
|
667 | + if (isset($this->_model_relations[$relationName]) && |
|
668 | + isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
669 | 669 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
670 | 670 | unset($this->_model_relations[$relationName][$index_in_cache]); |
671 | - }else{ |
|
671 | + } else { |
|
672 | 672 | //that thing was never cached anyways. |
673 | 673 | $obj_removed = NULL; |
674 | 674 | } |
@@ -687,24 +687,24 @@ discard block |
||
687 | 687 | * @param string $current_cache_id - the ID that was used when originally caching the object |
688 | 688 | * @return boolean TRUE on success, FALSE on fail |
689 | 689 | */ |
690 | - public function update_cache_after_object_save( $relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
690 | + public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
691 | 691 | // verify that incoming object is of the correct type |
692 | - $obj_class = 'EE_' . $relationName; |
|
693 | - if ( $newly_saved_object instanceof $obj_class ) { |
|
692 | + $obj_class = 'EE_'.$relationName; |
|
693 | + if ($newly_saved_object instanceof $obj_class) { |
|
694 | 694 | /* @type EE_Base_Class $newly_saved_object*/ |
695 | 695 | // now get the type of relation |
696 | - $relationship_to_model = $this->get_model()->related_settings_for( $relationName ); |
|
696 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
697 | 697 | // if this is a 1:1 relationship |
698 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ) { |
|
698 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
699 | 699 | // then just replace the cached object with the newly saved object |
700 | 700 | $this->_model_relations[$relationName] = $newly_saved_object; |
701 | 701 | return TRUE; |
702 | 702 | // or if it's some kind of sordid feral polyamorous relationship... |
703 | - } elseif ( is_array( $this->_model_relations[$relationName] ) && isset( $this->_model_relations[$relationName][ $current_cache_id ] )) { |
|
703 | + } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
704 | 704 | // then remove the current cached item |
705 | - unset( $this->_model_relations[$relationName][ $current_cache_id ] ); |
|
705 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
706 | 706 | // and cache the newly saved object using it's new ID |
707 | - $this->_model_relations[$relationName][ $newly_saved_object->ID() ] = $newly_saved_object; |
|
707 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
708 | 708 | return TRUE; |
709 | 709 | } |
710 | 710 | } |
@@ -720,11 +720,11 @@ discard block |
||
720 | 720 | * @param string $relationName |
721 | 721 | * @return EE_Base_Class |
722 | 722 | */ |
723 | - public function get_one_from_cache($relationName){ |
|
724 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
|
725 | - if(is_array($cached_array_or_object)){ |
|
723 | + public function get_one_from_cache($relationName) { |
|
724 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null; |
|
725 | + if (is_array($cached_array_or_object)) { |
|
726 | 726 | return array_shift($cached_array_or_object); |
727 | - }else{ |
|
727 | + } else { |
|
728 | 728 | return $cached_array_or_object; |
729 | 729 | } |
730 | 730 | } |
@@ -739,14 +739,14 @@ discard block |
||
739 | 739 | * @throws \EE_Error |
740 | 740 | * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
741 | 741 | */ |
742 | - public function get_all_from_cache($relationName){ |
|
743 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
|
744 | - if(is_array($cached_array_or_object)){ |
|
742 | + public function get_all_from_cache($relationName) { |
|
743 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
744 | + if (is_array($cached_array_or_object)) { |
|
745 | 745 | $objects = $cached_array_or_object; |
746 | - }elseif($cached_array_or_object){ |
|
746 | + }elseif ($cached_array_or_object) { |
|
747 | 747 | //if the result is not an array, but exists, make it an array |
748 | 748 | $objects = array($cached_array_or_object); |
749 | - }else{ |
|
749 | + } else { |
|
750 | 750 | //if nothing was found, return an empty array |
751 | 751 | $objects = array(); |
752 | 752 | } |
@@ -754,15 +754,15 @@ discard block |
||
754 | 754 | //basically, if this model object was stored in the session, and these cached model objects |
755 | 755 | //already have IDs, let's make sure they're in their model's entity mapper |
756 | 756 | //otherwise we will have duplicates next time we call EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
757 | - foreach( $objects as $model_object ){ |
|
758 | - $model = EE_Registry::instance()->load_model( $relationName ); |
|
759 | - if( $model instanceof EEM_Base && $model_object instanceof EE_Base_Class ){ |
|
757 | + foreach ($objects as $model_object) { |
|
758 | + $model = EE_Registry::instance()->load_model($relationName); |
|
759 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
760 | 760 | //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
761 | - if( $model_object->ID() ){ |
|
762 | - $model->add_to_entity_map( $model_object ); |
|
761 | + if ($model_object->ID()) { |
|
762 | + $model->add_to_entity_map($model_object); |
|
763 | 763 | } |
764 | - }else{ |
|
765 | - throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
|
764 | + } else { |
|
765 | + throw new EE_Error(sprintf(__('Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso'), $relationName, gettype($model_object))); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | return $objects; |
@@ -781,13 +781,13 @@ discard block |
||
781 | 781 | * |
782 | 782 | * @return array|EE_Base_Class[] |
783 | 783 | */ |
784 | - public function next_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
785 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
786 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
787 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
784 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
785 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
786 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
787 | + if (empty($field) || empty($current_value)) { |
|
788 | 788 | return array(); |
789 | 789 | } |
790 | - return $this->get_model()->next_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
790 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | |
@@ -806,13 +806,13 @@ discard block |
||
806 | 806 | * |
807 | 807 | * @return array|EE_Base_Class[] |
808 | 808 | */ |
809 | - public function previous_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
810 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
811 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
812 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
809 | + public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
810 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
811 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
812 | + if (empty($field) || empty($current_value)) { |
|
813 | 813 | return array(); |
814 | 814 | } |
815 | - return $this->get_model()->previous_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
815 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | |
@@ -830,13 +830,13 @@ discard block |
||
830 | 830 | * |
831 | 831 | * @return array|EE_Base_Class |
832 | 832 | */ |
833 | - public function next( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
834 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
835 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
836 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
833 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
834 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
835 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
836 | + if (empty($field) || empty($current_value)) { |
|
837 | 837 | return array(); |
838 | 838 | } |
839 | - return $this->get_model()->next( $current_value, $field, $query_params, $columns_to_select ); |
|
839 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | |
@@ -855,13 +855,13 @@ discard block |
||
855 | 855 | * |
856 | 856 | * @return array|EE_Base_Class |
857 | 857 | */ |
858 | - public function previous( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
859 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
860 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
861 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
858 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
859 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
860 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
861 | + if (empty($field) || empty($current_value)) { |
|
862 | 862 | return array(); |
863 | 863 | } |
864 | - return $this->get_model()->previous( $current_value, $field, $query_params, $columns_to_select ); |
|
864 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | |
@@ -875,25 +875,25 @@ discard block |
||
875 | 875 | * @param string $field_name |
876 | 876 | * @param mixed $field_value_from_db |
877 | 877 | */ |
878 | - public function set_from_db($field_name,$field_value_from_db){ |
|
878 | + public function set_from_db($field_name, $field_value_from_db) { |
|
879 | 879 | $field_obj = $this->get_model()->field_settings_for($field_name); |
880 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
880 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
881 | 881 | //you would think the DB has no NULLs for non-null label fields right? wrong! |
882 | 882 | //eg, a CPT model object could have an entry in the posts table, but no |
883 | 883 | //entry in the meta table. Meaning that all its columns in the meta table |
884 | 884 | //are null! yikes! so when we find one like that, use defaults for its meta columns |
885 | - if($field_value_from_db === NULL ){ |
|
886 | - if( $field_obj->is_nullable()){ |
|
885 | + if ($field_value_from_db === NULL) { |
|
886 | + if ($field_obj->is_nullable()) { |
|
887 | 887 | //if the field allows nulls, then let it be null |
888 | 888 | $field_value = NULL; |
889 | - }else{ |
|
889 | + } else { |
|
890 | 890 | $field_value = $field_obj->get_default_value(); |
891 | 891 | } |
892 | - }else{ |
|
893 | - $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
|
892 | + } else { |
|
893 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
894 | 894 | } |
895 | 895 | $this->_fields[$field_name] = $field_value; |
896 | - $this->_clear_cached_property( $field_name ); |
|
896 | + $this->_clear_cached_property($field_name); |
|
897 | 897 | } |
898 | 898 | } |
899 | 899 | |
@@ -905,8 +905,8 @@ discard block |
||
905 | 905 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
906 | 906 | * @return boolean |
907 | 907 | */ |
908 | - public function get($field_name, $extra_cache_ref = NULL ){ |
|
909 | - return $this->_get_cached_property( $field_name, FALSE, $extra_cache_ref ); |
|
908 | + public function get($field_name, $extra_cache_ref = NULL) { |
|
909 | + return $this->_get_cached_property($field_name, FALSE, $extra_cache_ref); |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | |
@@ -936,11 +936,11 @@ discard block |
||
936 | 936 | * just null is returned (because that indicates that likely |
937 | 937 | * this field is nullable). |
938 | 938 | */ |
939 | - public function get_DateTime_object( $field_name ) { |
|
940 | - $field_settings = $this->get_model()->field_settings_for( $field_name ); |
|
939 | + public function get_DateTime_object($field_name) { |
|
940 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
941 | 941 | |
942 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
943 | - EE_Error::add_error( sprintf( __('The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', 'event_espresso' ), $field_name ), __FILE__, __FUNCTION__, __LINE__ ); |
|
942 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
943 | + EE_Error::add_error(sprintf(__('The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', 'event_espresso'), $field_name), __FILE__, __FUNCTION__, __LINE__); |
|
944 | 944 | return false; |
945 | 945 | } |
946 | 946 | |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
957 | 957 | * @return void |
958 | 958 | */ |
959 | - public function e($field_name, $extra_cache_ref = NULL){ |
|
959 | + public function e($field_name, $extra_cache_ref = NULL) { |
|
960 | 960 | echo $this->get_pretty($field_name, $extra_cache_ref); |
961 | 961 | } |
962 | 962 | /** |
@@ -965,8 +965,8 @@ discard block |
||
965 | 965 | * @param string $field_name |
966 | 966 | * @return void |
967 | 967 | */ |
968 | - public function f($field_name){ |
|
969 | - $this->e($field_name,'form_input'); |
|
968 | + public function f($field_name) { |
|
969 | + $this->e($field_name, 'form_input'); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | /** |
@@ -975,8 +975,8 @@ discard block |
||
975 | 975 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
976 | 976 | * @return mixed |
977 | 977 | */ |
978 | - public function get_pretty($field_name, $extra_cache_ref = NULL){ |
|
979 | - return $this->_get_cached_property( $field_name, TRUE, $extra_cache_ref ); |
|
978 | + public function get_pretty($field_name, $extra_cache_ref = NULL) { |
|
979 | + return $this->_get_cached_property($field_name, TRUE, $extra_cache_ref); |
|
980 | 980 | } |
981 | 981 | |
982 | 982 | |
@@ -993,37 +993,37 @@ discard block |
||
993 | 993 | * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
994 | 994 | * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
995 | 995 | */ |
996 | - protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
|
996 | + protected function _get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE) { |
|
997 | 997 | |
998 | - $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
998 | + $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
999 | 999 | $in_tm_frmt = empty($tm_frmt) ? $this->_tm_frmt : $tm_frmt; |
1000 | 1000 | |
1001 | 1001 | //validate field for datetime and returns field settings if valid. |
1002 | - $field = $this->_get_dtt_field_settings( $field_name ); |
|
1002 | + $field = $this->_get_dtt_field_settings($field_name); |
|
1003 | 1003 | |
1004 | 1004 | //clear cached property if either formats are not null. |
1005 | - if( $dt_frmt !== null || $tm_frmt !== null ) { |
|
1006 | - $this->_clear_cached_property( $field_name ); |
|
1005 | + if ($dt_frmt !== null || $tm_frmt !== null) { |
|
1006 | + $this->_clear_cached_property($field_name); |
|
1007 | 1007 | //reset format properties because they are used in get() |
1008 | 1008 | $this->_dt_frmt = $in_dt_frmt; |
1009 | 1009 | $this->_tm_frmt = $in_tm_frmt; |
1010 | 1010 | } |
1011 | 1011 | |
1012 | - if ( $echo ) |
|
1013 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
1012 | + if ($echo) |
|
1013 | + $field->set_pretty_date_format($in_dt_frmt); |
|
1014 | 1014 | else |
1015 | - $field->set_date_format( $in_dt_frmt ); |
|
1015 | + $field->set_date_format($in_dt_frmt); |
|
1016 | 1016 | |
1017 | - if ( $echo ) |
|
1018 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
1017 | + if ($echo) |
|
1018 | + $field->set_pretty_time_format($in_tm_frmt); |
|
1019 | 1019 | else |
1020 | - $field->set_time_format( $in_tm_frmt ); |
|
1020 | + $field->set_time_format($in_tm_frmt); |
|
1021 | 1021 | |
1022 | 1022 | //set timezone in field object |
1023 | - $field->set_timezone( $this->_timezone ); |
|
1023 | + $field->set_timezone($this->_timezone); |
|
1024 | 1024 | |
1025 | 1025 | //set the output returned |
1026 | - switch ( $date_or_time ) { |
|
1026 | + switch ($date_or_time) { |
|
1027 | 1027 | |
1028 | 1028 | case 'D' : |
1029 | 1029 | $field->set_date_time_output('date'); |
@@ -1038,11 +1038,11 @@ discard block |
||
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | |
1041 | - if ( $echo ) { |
|
1042 | - $this->e( $field_name, $date_or_time ); |
|
1041 | + if ($echo) { |
|
1042 | + $this->e($field_name, $date_or_time); |
|
1043 | 1043 | return ''; |
1044 | 1044 | } |
1045 | - return $this->get( $field_name, $date_or_time ); |
|
1045 | + return $this->get($field_name, $date_or_time); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | |
@@ -1052,8 +1052,8 @@ discard block |
||
1052 | 1052 | * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
1053 | 1053 | * @return string datetime value formatted |
1054 | 1054 | */ |
1055 | - public function get_date( $field_name, $format = NULL ) { |
|
1056 | - return $this->_get_datetime( $field_name, $format, NULL, 'D' ); |
|
1055 | + public function get_date($field_name, $format = NULL) { |
|
1056 | + return $this->_get_datetime($field_name, $format, NULL, 'D'); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | |
@@ -1062,8 +1062,8 @@ discard block |
||
1062 | 1062 | * @param $field_name |
1063 | 1063 | * @param null $format |
1064 | 1064 | */ |
1065 | - public function e_date( $field_name, $format = NULL ) { |
|
1066 | - $this->_get_datetime( $field_name, $format, NULL, 'D', TRUE ); |
|
1065 | + public function e_date($field_name, $format = NULL) { |
|
1066 | + $this->_get_datetime($field_name, $format, NULL, 'D', TRUE); |
|
1067 | 1067 | } |
1068 | 1068 | |
1069 | 1069 | |
@@ -1073,8 +1073,8 @@ discard block |
||
1073 | 1073 | * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
1074 | 1074 | * @return string datetime value formatted |
1075 | 1075 | */ |
1076 | - public function get_time( $field_name, $format = NULL ) { |
|
1077 | - return $this->_get_datetime( $field_name, NULL, $format, 'T' ); |
|
1076 | + public function get_time($field_name, $format = NULL) { |
|
1077 | + return $this->_get_datetime($field_name, NULL, $format, 'T'); |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | |
@@ -1083,8 +1083,8 @@ discard block |
||
1083 | 1083 | * @param $field_name |
1084 | 1084 | * @param null $format |
1085 | 1085 | */ |
1086 | - public function e_time( $field_name, $format = NULL ) { |
|
1087 | - $this->_get_datetime( $field_name, NULL, $format, 'T', TRUE ); |
|
1086 | + public function e_time($field_name, $format = NULL) { |
|
1087 | + $this->_get_datetime($field_name, NULL, $format, 'T', TRUE); |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
1098 | 1098 | * @return string datetime value formatted |
1099 | 1099 | */ |
1100 | - public function get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
1101 | - return $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt ); |
|
1100 | + public function get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
1101 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | |
@@ -1108,8 +1108,8 @@ discard block |
||
1108 | 1108 | * @param null $dt_frmt |
1109 | 1109 | * @param null $tm_frmt |
1110 | 1110 | */ |
1111 | - public function e_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
1112 | - $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
1111 | + public function e_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
1112 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | |
@@ -1124,10 +1124,10 @@ discard block |
||
1124 | 1124 | * @return string Date and time string in set locale or false if no field exists for the given |
1125 | 1125 | * field name. |
1126 | 1126 | */ |
1127 | - public function get_i18n_datetime( $field_name, $format = NULL ) { |
|
1128 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1129 | - $format = empty( $format ) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
1130 | - return date_i18n( $format, EEH_DTT_Helper::get_timestamp_with_offset( $this->get_raw( $field_name ), $this->_timezone ) ); |
|
1127 | + public function get_i18n_datetime($field_name, $format = NULL) { |
|
1128 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1129 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
1130 | + return date_i18n($format, EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | |
@@ -1139,14 +1139,14 @@ discard block |
||
1139 | 1139 | * @throws EE_Error |
1140 | 1140 | * @return EE_Datetime_Field |
1141 | 1141 | */ |
1142 | - protected function _get_dtt_field_settings( $field_name ) { |
|
1142 | + protected function _get_dtt_field_settings($field_name) { |
|
1143 | 1143 | $field = $this->get_model()->field_settings_for($field_name); |
1144 | 1144 | |
1145 | 1145 | //check if field is dtt |
1146 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1146 | + if ($field instanceof EE_Datetime_Field) { |
|
1147 | 1147 | return $field; |
1148 | 1148 | } else { |
1149 | - throw new EE_Error( sprintf( __('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname( get_class($this) ) ) ); |
|
1149 | + throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
1150 | 1150 | } |
1151 | 1151 | } |
1152 | 1152 | |
@@ -1167,8 +1167,8 @@ discard block |
||
1167 | 1167 | * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
1168 | 1168 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
1169 | 1169 | */ |
1170 | - protected function _set_time_for( $time, $fieldname ) { |
|
1171 | - $this->_set_date_time( 'T', $time, $fieldname ); |
|
1170 | + protected function _set_time_for($time, $fieldname) { |
|
1171 | + $this->_set_date_time('T', $time, $fieldname); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | |
@@ -1182,8 +1182,8 @@ discard block |
||
1182 | 1182 | * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
1183 | 1183 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
1184 | 1184 | */ |
1185 | - protected function _set_date_for( $date, $fieldname ) { |
|
1186 | - $this->_set_date_time( 'D', $date, $fieldname ); |
|
1185 | + protected function _set_date_for($date, $fieldname) { |
|
1186 | + $this->_set_date_time('D', $date, $fieldname); |
|
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | |
@@ -1199,21 +1199,21 @@ discard block |
||
1199 | 1199 | * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
1200 | 1200 | * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
1201 | 1201 | */ |
1202 | - protected function _set_date_time( $what = 'T', $datetime_value, $fieldname ) { |
|
1203 | - $field = $this->_get_dtt_field_settings( $fieldname ); |
|
1204 | - $field->set_timezone( $this->_timezone ); |
|
1205 | - $field->set_date_format( $this->_dt_frmt ); |
|
1206 | - $field->set_time_format( $this->_tm_frmt ); |
|
1202 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) { |
|
1203 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
1204 | + $field->set_timezone($this->_timezone); |
|
1205 | + $field->set_date_format($this->_dt_frmt); |
|
1206 | + $field->set_time_format($this->_tm_frmt); |
|
1207 | 1207 | |
1208 | - switch ( $what ) { |
|
1208 | + switch ($what) { |
|
1209 | 1209 | case 'T' : |
1210 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( $datetime_value, $this->_fields[$fieldname] ); |
|
1210 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time($datetime_value, $this->_fields[$fieldname]); |
|
1211 | 1211 | break; |
1212 | 1212 | case 'D' : |
1213 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( $datetime_value, $this->_fields[$fieldname] ); |
|
1213 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date($datetime_value, $this->_fields[$fieldname]); |
|
1214 | 1214 | break; |
1215 | 1215 | case 'B' : |
1216 | - $this->_fields[$fieldname] = $field->prepare_for_set( $datetime_value ); |
|
1216 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
1217 | 1217 | break; |
1218 | 1218 | } |
1219 | 1219 | |
@@ -1236,25 +1236,25 @@ discard block |
||
1236 | 1236 | * @throws EE_Error |
1237 | 1237 | * @return string timestamp |
1238 | 1238 | */ |
1239 | - public function display_in_my_timezone( $field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '' ) { |
|
1239 | + public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '') { |
|
1240 | 1240 | EE_Registry::instance()->load_helper('DTT_Helper'); |
1241 | 1241 | $timezone = EEH_DTT_Helper::get_timezone(); |
1242 | 1242 | |
1243 | - if ( $timezone == $this->_timezone ) |
|
1243 | + if ($timezone == $this->_timezone) |
|
1244 | 1244 | return ''; |
1245 | 1245 | |
1246 | 1246 | $original_timezone = $this->_timezone; |
1247 | - $this->set_timezone( $timezone ); |
|
1247 | + $this->set_timezone($timezone); |
|
1248 | 1248 | |
1249 | 1249 | $fn = (array) $field_name; |
1250 | - $args = array_merge( $fn, (array) $args ); |
|
1250 | + $args = array_merge($fn, (array) $args); |
|
1251 | 1251 | |
1252 | - if ( !method_exists( $this, $callback ) ) |
|
1253 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1252 | + if ( ! method_exists($this, $callback)) |
|
1253 | + throw new EE_Error(sprintf(__('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback)); |
|
1254 | 1254 | $args = (array) $args; |
1255 | - $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
|
1255 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
1256 | 1256 | |
1257 | - $this->set_timezone( $original_timezone ); |
|
1257 | + $this->set_timezone($original_timezone); |
|
1258 | 1258 | return $return; |
1259 | 1259 | } |
1260 | 1260 | |
@@ -1265,21 +1265,21 @@ discard block |
||
1265 | 1265 | * Deletes this model object. That may mean just 'soft deleting' it though. |
1266 | 1266 | * @return boolean | int |
1267 | 1267 | */ |
1268 | - public function delete(){ |
|
1268 | + public function delete() { |
|
1269 | 1269 | /** |
1270 | 1270 | * Called just before deleting a model object |
1271 | 1271 | * |
1272 | 1272 | * @param EE_Base_Class $model_object about to be 'deleted' |
1273 | 1273 | */ |
1274 | - do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
|
1275 | - $result = $this->get_model()->delete_by_ID( $this->ID() ); |
|
1274 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
1275 | + $result = $this->get_model()->delete_by_ID($this->ID()); |
|
1276 | 1276 | $this->refresh_cache_of_related_objects(); |
1277 | 1277 | /** |
1278 | 1278 | * Called just after deleting a model object |
1279 | 1279 | * @param EE_Base_Class $model_object that was just 'deleted' |
1280 | 1280 | * @param boolean $result |
1281 | 1281 | */ |
1282 | - do_action( 'AHEE__EE_Base_Class__delete__end', $this, $result ); |
|
1282 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
1283 | 1283 | return $result; |
1284 | 1284 | } |
1285 | 1285 | |
@@ -1289,12 +1289,12 @@ discard block |
||
1289 | 1289 | * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error) |
1290 | 1290 | * @return bool |
1291 | 1291 | */ |
1292 | - public function delete_permanently(){ |
|
1293 | - $model=$this->get_model(); |
|
1294 | - if($model instanceof EEM_Soft_Delete_Base){ |
|
1295 | - $result=$model->delete_permanently_by_ID($this->ID()); |
|
1292 | + public function delete_permanently() { |
|
1293 | + $model = $this->get_model(); |
|
1294 | + if ($model instanceof EEM_Soft_Delete_Base) { |
|
1295 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
1296 | 1296 | $this->refresh_cache_of_related_objects(); |
1297 | - }else{ |
|
1297 | + } else { |
|
1298 | 1298 | $result = $this->delete(); |
1299 | 1299 | } |
1300 | 1300 | return $result ? true : false; |
@@ -1305,18 +1305,18 @@ discard block |
||
1305 | 1305 | * related model objects |
1306 | 1306 | */ |
1307 | 1307 | public function refresh_cache_of_related_objects() { |
1308 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1309 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1310 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
1311 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1308 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1309 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
1310 | + $related_objects = $this->_model_relations[$relation_name]; |
|
1311 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
1312 | 1312 | //this relation only stores a single model object, not an array |
1313 | 1313 | //but let's make it consistent |
1314 | - $related_objects = array( $related_objects ); |
|
1314 | + $related_objects = array($related_objects); |
|
1315 | 1315 | } |
1316 | - foreach( $related_objects as $related_object ) { |
|
1316 | + foreach ($related_objects as $related_object) { |
|
1317 | 1317 | //only refresh their cache if they're in memory |
1318 | - if( $related_object instanceof EE_Base_Class ) { |
|
1319 | - $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1318 | + if ($related_object instanceof EE_Base_Class) { |
|
1319 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1320 | 1320 | } |
1321 | 1321 | } |
1322 | 1322 | } |
@@ -1336,17 +1336,17 @@ discard block |
||
1336 | 1336 | * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
1337 | 1337 | * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
1338 | 1338 | */ |
1339 | - public function save($set_cols_n_values=array()) { |
|
1339 | + public function save($set_cols_n_values = array()) { |
|
1340 | 1340 | /** |
1341 | 1341 | * Filters the fields we're about to save on the model object |
1342 | 1342 | * |
1343 | 1343 | * @param array $set_cols_n_values |
1344 | 1344 | * @param EE_Base_Class $model_object |
1345 | 1345 | */ |
1346 | - $set_cols_n_values = apply_filters( 'FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this ); |
|
1346 | + $set_cols_n_values = apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
1347 | 1347 | //set attributes as provided in $set_cols_n_values |
1348 | - foreach($set_cols_n_values as $column=>$value){ |
|
1349 | - $this->set($column,$value); |
|
1348 | + foreach ($set_cols_n_values as $column=>$value) { |
|
1349 | + $this->set($column, $value); |
|
1350 | 1350 | } |
1351 | 1351 | /** |
1352 | 1352 | * Saving a model object. |
@@ -1354,8 +1354,8 @@ discard block |
||
1354 | 1354 | * Before we perform a save, this action is fired. |
1355 | 1355 | * @param EE_Base_Class $model_object the model object about to be saved. |
1356 | 1356 | */ |
1357 | - do_action( 'AHEE__EE_Base_Class__save__begin', $this ); |
|
1358 | - if( ! $this->allow_persist() ) { |
|
1357 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
1358 | + if ( ! $this->allow_persist()) { |
|
1359 | 1359 | return 0; |
1360 | 1360 | } |
1361 | 1361 | //now get current attribute values |
@@ -1365,61 +1365,61 @@ discard block |
||
1365 | 1365 | $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
1366 | 1366 | $this->get_model()->assume_values_already_prepared_by_model_object(true); |
1367 | 1367 | //does this model have an autoincrement PK? |
1368 | - if($this->get_model()->has_primary_key_field()){ |
|
1369 | - if($this->get_model()->get_primary_key_field()->is_auto_increment()){ |
|
1368 | + if ($this->get_model()->has_primary_key_field()) { |
|
1369 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
1370 | 1370 | //ok check if it's set, if so: update; if not, insert |
1371 | - if ( ! empty( $save_cols_n_values[self::_get_primary_key_name( get_class($this) )] ) ){ |
|
1372 | - $results = $this->get_model()->update_by_ID ( $save_cols_n_values, $this->ID() ); |
|
1371 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
1372 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
1373 | 1373 | } else { |
1374 | - unset($save_cols_n_values[self::_get_primary_key_name( get_class( $this) )]); |
|
1375 | - $results = $this->get_model()->insert( $save_cols_n_values, true); |
|
1376 | - if($results){ |
|
1374 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
1375 | + $results = $this->get_model()->insert($save_cols_n_values, true); |
|
1376 | + if ($results) { |
|
1377 | 1377 | //if successful, set the primary key |
1378 | 1378 | //but don't use the normal SET method, because it will check if |
1379 | 1379 | //an item with the same ID exists in the mapper & db, then |
1380 | 1380 | //will find it in the db (because we just added it) and THAT object |
1381 | 1381 | //will get added to the mapper before we can add this one! |
1382 | 1382 | //but if we just avoid using the SET method, all that headache can be avoided |
1383 | - $pk_field_name =self::_get_primary_key_name( get_class($this)); |
|
1383 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
1384 | 1384 | $this->_fields[$pk_field_name] = $results; |
1385 | 1385 | $this->_clear_cached_property($pk_field_name); |
1386 | - $this->get_model()->add_to_entity_map( $this ); |
|
1386 | + $this->get_model()->add_to_entity_map($this); |
|
1387 | 1387 | $this->_update_cached_related_model_objs_fks(); |
1388 | 1388 | } |
1389 | 1389 | } |
1390 | - }else{//PK is NOT auto-increment |
|
1390 | + } else {//PK is NOT auto-increment |
|
1391 | 1391 | //so check if one like it already exists in the db |
1392 | - if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
|
1393 | - if( ! $this->in_entity_map() && WP_DEBUG ){ |
|
1392 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
1393 | + if ( ! $this->in_entity_map() && WP_DEBUG) { |
|
1394 | 1394 | throw new EE_Error( |
1395 | 1395 | sprintf( |
1396 | - __( 'Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso' ), |
|
1396 | + __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso'), |
|
1397 | 1397 | get_class($this), |
1398 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
1399 | - get_class( $this->get_model() ) . '::instance()->get_one_by_ID()', |
|
1398 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
1399 | + get_class($this->get_model()).'::instance()->get_one_by_ID()', |
|
1400 | 1400 | '<br />' |
1401 | 1401 | ) |
1402 | 1402 | ); |
1403 | 1403 | } |
1404 | 1404 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
1405 | - }else{ |
|
1405 | + } else { |
|
1406 | 1406 | $results = $this->get_model()->insert($save_cols_n_values); |
1407 | 1407 | $this->_update_cached_related_model_objs_fks(); |
1408 | 1408 | } |
1409 | 1409 | } |
1410 | - }else{//there is NO primary key |
|
1410 | + } else {//there is NO primary key |
|
1411 | 1411 | $already_in_db = false; |
1412 | - foreach($this->get_model()->unique_indexes() as $index){ |
|
1412 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
1413 | 1413 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
1414 | - if($this->get_model()->exists(array($uniqueness_where_params))){ |
|
1414 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
1415 | 1415 | $already_in_db = true; |
1416 | 1416 | } |
1417 | 1417 | } |
1418 | - if( $already_in_db ){ |
|
1419 | - $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
|
1420 | - $results = $this->get_model()->update( $save_cols_n_values,array( $combined_pk_fields_n_values ) ); |
|
1421 | - }else{ |
|
1422 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
1418 | + if ($already_in_db) { |
|
1419 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
1420 | + $results = $this->get_model()->update($save_cols_n_values, array($combined_pk_fields_n_values)); |
|
1421 | + } else { |
|
1422 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
1423 | 1423 | } |
1424 | 1424 | } |
1425 | 1425 | //restore the old assumption about values being prepared by the model object |
@@ -1432,7 +1432,7 @@ discard block |
||
1432 | 1432 | * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
1433 | 1433 | * the new ID (or 0 if an error occurred and it wasn't updated) |
1434 | 1434 | */ |
1435 | - do_action( 'AHEE__EE_Base_Class__save__end', $this, $results ); |
|
1435 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
1436 | 1436 | return $results; |
1437 | 1437 | } |
1438 | 1438 | |
@@ -1444,13 +1444,13 @@ discard block |
||
1444 | 1444 | * and we want to let its cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether or not they exist in the DB (if they do, their DB records will be automatically updated) |
1445 | 1445 | * @return void |
1446 | 1446 | */ |
1447 | - protected function _update_cached_related_model_objs_fks(){ |
|
1448 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ){ |
|
1449 | - if( $relation_obj instanceof EE_Has_Many_Relation ){ |
|
1450 | - foreach( $this->get_all_from_cache( $relation_name ) as $related_model_obj_in_cache) { |
|
1451 | - $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( $this->get_model()->get_this_model_name() ); |
|
1452 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID() ); |
|
1453 | - if( $related_model_obj_in_cache->ID() ){ |
|
1447 | + protected function _update_cached_related_model_objs_fks() { |
|
1448 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1449 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
1450 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
1451 | + $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to($this->get_model()->get_this_model_name()); |
|
1452 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
1453 | + if ($related_model_obj_in_cache->ID()) { |
|
1454 | 1454 | $related_model_obj_in_cache->save(); |
1455 | 1455 | } |
1456 | 1456 | } |
@@ -1466,21 +1466,21 @@ discard block |
||
1466 | 1466 | * and this object and properly setup |
1467 | 1467 | * @return int ID of new model object on save; 0 on failure+ |
1468 | 1468 | */ |
1469 | - public function save_new_cached_related_model_objs(){ |
|
1469 | + public function save_new_cached_related_model_objs() { |
|
1470 | 1470 | //make sure this has been saved |
1471 | - if( ! $this->ID()){ |
|
1471 | + if ( ! $this->ID()) { |
|
1472 | 1472 | $id = $this->save(); |
1473 | - }else{ |
|
1473 | + } else { |
|
1474 | 1474 | $id = $this->ID(); |
1475 | 1475 | } |
1476 | 1476 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
1477 | - foreach($this->get_model()->relation_settings() as $relationName => $relationObj){ |
|
1477 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
1478 | 1478 | |
1479 | 1479 | |
1480 | - if($this->_model_relations[$relationName]){ |
|
1480 | + if ($this->_model_relations[$relationName]) { |
|
1481 | 1481 | //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
1482 | 1482 | //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
1483 | - if($relationObj instanceof EE_Belongs_To_Relation){ |
|
1483 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
1484 | 1484 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1485 | 1485 | //but ONLY if it DOES NOT exist in the DB |
1486 | 1486 | /* @var $related_model_obj EE_Base_Class */ |
@@ -1489,8 +1489,8 @@ discard block |
||
1489 | 1489 | $this->_add_relation_to($related_model_obj, $relationName); |
1490 | 1490 | $related_model_obj->save_new_cached_related_model_objs(); |
1491 | 1491 | // } |
1492 | - }else{ |
|
1493 | - foreach($this->_model_relations[$relationName] as $related_model_obj){ |
|
1492 | + } else { |
|
1493 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
1494 | 1494 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1495 | 1495 | //but ONLY if it DOES NOT exist in the DB |
1496 | 1496 | // if( ! $related_model_obj->ID()){ |
@@ -1511,8 +1511,8 @@ discard block |
||
1511 | 1511 | * @return \EEM_Base | \EEM_CPT_Base |
1512 | 1512 | */ |
1513 | 1513 | public function get_model() { |
1514 | - $modelName = self::_get_model_classname( get_class($this) ); |
|
1515 | - return self::_get_model_instance_with_name($modelName, $this->_timezone ); |
|
1514 | + $modelName = self::_get_model_classname(get_class($this)); |
|
1515 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
1516 | 1516 | } |
1517 | 1517 | |
1518 | 1518 | |
@@ -1522,10 +1522,10 @@ discard block |
||
1522 | 1522 | * @param $classname |
1523 | 1523 | * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
1524 | 1524 | */ |
1525 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname){ |
|
1525 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) { |
|
1526 | 1526 | //TODO: will not work for Term_Relationships because they have no PK! |
1527 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1528 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
1527 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1528 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1529 | 1529 | $id = $props_n_values[$primary_id_ref]; |
1530 | 1530 | return self::_get_model($classname)->get_from_entity_map($id); |
1531 | 1531 | } |
@@ -1542,24 +1542,24 @@ discard block |
||
1542 | 1542 | * @param null $timezone |
1543 | 1543 | * @return mixed (EE_Base_Class|bool) |
1544 | 1544 | */ |
1545 | - protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL ) { |
|
1546 | - if( self::_get_model( $classname )->has_primary_key_field()){ |
|
1547 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1545 | + protected static function _check_for_object($props_n_values, $classname, $timezone = NULL) { |
|
1546 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
1547 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1548 | 1548 | |
1549 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
1550 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
|
1551 | - }else{ |
|
1549 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1550 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID($props_n_values[$primary_id_ref]); |
|
1551 | + } else { |
|
1552 | 1552 | $existing = null; |
1553 | 1553 | } |
1554 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1554 | + }elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
1555 | 1555 | //no primary key on this model, but there's still a matching item in the DB |
1556 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
|
1557 | - }else{ |
|
1556 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID(self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)); |
|
1557 | + } else { |
|
1558 | 1558 | $existing = null; |
1559 | 1559 | } |
1560 | - if ( $existing ) { |
|
1561 | - foreach ( $props_n_values as $property => $field_value ) { |
|
1562 | - $existing->set( $property, $field_value ); |
|
1560 | + if ($existing) { |
|
1561 | + foreach ($props_n_values as $property => $field_value) { |
|
1562 | + $existing->set($property, $field_value); |
|
1563 | 1563 | } |
1564 | 1564 | return $existing; |
1565 | 1565 | } else { |
@@ -1577,13 +1577,13 @@ discard block |
||
1577 | 1577 | * @throws EE_Error |
1578 | 1578 | * @return EEM_Base |
1579 | 1579 | */ |
1580 | - protected static function _get_model( $classname, $timezone = NULL ){ |
|
1580 | + protected static function _get_model($classname, $timezone = NULL) { |
|
1581 | 1581 | //find model for this class |
1582 | - if( ! $classname ){ |
|
1583 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"),$classname)); |
|
1582 | + if ( ! $classname) { |
|
1583 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"), $classname)); |
|
1584 | 1584 | } |
1585 | - $modelName=self::_get_model_classname($classname); |
|
1586 | - return self::_get_model_instance_with_name($modelName, $timezone ); |
|
1585 | + $modelName = self::_get_model_classname($classname); |
|
1586 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
1587 | 1587 | } |
1588 | 1588 | |
1589 | 1589 | |
@@ -1594,10 +1594,10 @@ discard block |
||
1594 | 1594 | * @param null $timezone |
1595 | 1595 | * @return EEM_Base |
1596 | 1596 | */ |
1597 | - protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
|
1598 | - $model_classname = str_replace( 'EEM_', '', $model_classname ); |
|
1599 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
1600 | - $model->set_timezone( $timezone ); |
|
1597 | + protected static function _get_model_instance_with_name($model_classname, $timezone = NULL) { |
|
1598 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
1599 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
1600 | + $model->set_timezone($timezone); |
|
1601 | 1601 | return $model; |
1602 | 1602 | } |
1603 | 1603 | |
@@ -1609,10 +1609,10 @@ discard block |
||
1609 | 1609 | * @param null $model_name |
1610 | 1610 | * @return string like EEM_Attendee |
1611 | 1611 | */ |
1612 | - private static function _get_model_classname( $model_name = null){ |
|
1613 | - if(strpos($model_name,"EE_")===0){ |
|
1614 | - $model_classname=str_replace("EE_","EEM_",$model_name); |
|
1615 | - }else{ |
|
1612 | + private static function _get_model_classname($model_name = null) { |
|
1613 | + if (strpos($model_name, "EE_") === 0) { |
|
1614 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
1615 | + } else { |
|
1616 | 1616 | $model_classname = "EEM_".$model_name; |
1617 | 1617 | } |
1618 | 1618 | return $model_classname; |
@@ -1626,11 +1626,11 @@ discard block |
||
1626 | 1626 | * @throws EE_Error |
1627 | 1627 | * @return string |
1628 | 1628 | */ |
1629 | - protected static function _get_primary_key_name( $classname = NULL ){ |
|
1630 | - if( ! $classname){ |
|
1631 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),$classname)); |
|
1629 | + protected static function _get_primary_key_name($classname = NULL) { |
|
1630 | + if ( ! $classname) { |
|
1631 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), $classname)); |
|
1632 | 1632 | } |
1633 | - return self::_get_model( $classname )->get_primary_key_field()->get_name(); |
|
1633 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
1634 | 1634 | } |
1635 | 1635 | |
1636 | 1636 | |
@@ -1642,12 +1642,12 @@ discard block |
||
1642 | 1642 | * Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
1643 | 1643 | * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
1644 | 1644 | */ |
1645 | - public function ID(){ |
|
1645 | + public function ID() { |
|
1646 | 1646 | //now that we know the name of the variable, use a variable variable to get its value and return its |
1647 | - if( $this->get_model()->has_primary_key_field() ) { |
|
1648 | - return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
|
1649 | - }else{ |
|
1650 | - return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
|
1647 | + if ($this->get_model()->has_primary_key_field()) { |
|
1648 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
1649 | + } else { |
|
1650 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
1651 | 1651 | } |
1652 | 1652 | } |
1653 | 1653 | |
@@ -1665,38 +1665,38 @@ discard block |
||
1665 | 1665 | * @throws EE_Error |
1666 | 1666 | * @return EE_Base_Class the object the relation was added to |
1667 | 1667 | */ |
1668 | - public function _add_relation_to( $otherObjectModelObjectOrID,$relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL ){ |
|
1668 | + public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL) { |
|
1669 | 1669 | //if this thing exists in the DB, save the relation to the DB |
1670 | - if( $this->ID() ){ |
|
1671 | - $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
|
1670 | + if ($this->ID()) { |
|
1671 | + $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values); |
|
1672 | 1672 | //clear cache so future get_many_related and get_first_related() return new results. |
1673 | - $this->clear_cache( $relationName, $otherObject, TRUE ); |
|
1674 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1675 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1673 | + $this->clear_cache($relationName, $otherObject, TRUE); |
|
1674 | + if ($otherObject instanceof EE_Base_Class) { |
|
1675 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1676 | 1676 | } |
1677 | 1677 | } else { |
1678 | 1678 | //this thing doesn't exist in the DB, so just cache it |
1679 | - if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
|
1680 | - throw new EE_Error( sprintf( |
|
1681 | - __( 'Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso' ), |
|
1679 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
1680 | + throw new EE_Error(sprintf( |
|
1681 | + __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'), |
|
1682 | 1682 | $otherObjectModelObjectOrID, |
1683 | - get_class( $this ) |
|
1683 | + get_class($this) |
|
1684 | 1684 | )); |
1685 | 1685 | } else { |
1686 | 1686 | $otherObject = $otherObjectModelObjectOrID; |
1687 | 1687 | } |
1688 | - $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
|
1688 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
1689 | 1689 | } |
1690 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1690 | + if ($otherObject instanceof EE_Base_Class) { |
|
1691 | 1691 | //fix the reciprocal relation too |
1692 | - if( $otherObject->ID() ) { |
|
1692 | + if ($otherObject->ID()) { |
|
1693 | 1693 | //its saved so assumed relations exist in the DB, so we can just |
1694 | 1694 | //clear the cache so future queries use the updated info in the DB |
1695 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1695 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
1696 | 1696 | } else { |
1697 | 1697 | |
1698 | 1698 | //it's not saved, so it caches relations like this |
1699 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1699 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
1700 | 1700 | } |
1701 | 1701 | } |
1702 | 1702 | return $otherObject; |
@@ -1719,17 +1719,17 @@ discard block |
||
1719 | 1719 | * Also remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is created in the join table. |
1720 | 1720 | * @return EE_Base_Class the relation was removed from |
1721 | 1721 | */ |
1722 | - public function _remove_relation_to($otherObjectModelObjectOrID,$relationName, $where_query = array() ){ |
|
1723 | - if ( $this->ID() ) { |
|
1722 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) { |
|
1723 | + if ($this->ID()) { |
|
1724 | 1724 | //if this exists in the DB, save the relation change to the DB too |
1725 | - $otherObject = $this->get_model()->remove_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
|
1726 | - $this->clear_cache( $relationName, $otherObject ); |
|
1725 | + $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
1726 | + $this->clear_cache($relationName, $otherObject); |
|
1727 | 1727 | } else { |
1728 | 1728 | //this doesn't exist in the DB, just remove it from the cache |
1729 | - $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
|
1729 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
1730 | 1730 | } |
1731 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1732 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1731 | + if ($otherObject instanceof EE_Base_Class) { |
|
1732 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1733 | 1733 | } |
1734 | 1734 | return $otherObject; |
1735 | 1735 | } |
@@ -1740,18 +1740,18 @@ discard block |
||
1740 | 1740 | * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
1741 | 1741 | * @return EE_Base_Class |
1742 | 1742 | */ |
1743 | - public function _remove_relations($relationName,$where_query_params = array()){ |
|
1744 | - if ( $this->ID() ) { |
|
1743 | + public function _remove_relations($relationName, $where_query_params = array()) { |
|
1744 | + if ($this->ID()) { |
|
1745 | 1745 | //if this exists in the DB, save the relation change to the DB too |
1746 | - $otherObjects = $this->get_model()->remove_relations( $this, $relationName, $where_query_params ); |
|
1747 | - $this->clear_cache( $relationName, null, true ); |
|
1746 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
1747 | + $this->clear_cache($relationName, null, true); |
|
1748 | 1748 | } else { |
1749 | 1749 | //this doesn't exist in the DB, just remove it from the cache |
1750 | - $otherObjects = $this->clear_cache( $relationName, null, true ); |
|
1750 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
1751 | 1751 | } |
1752 | - if( is_array( $otherObjects ) ) { |
|
1753 | - foreach ( $otherObjects as $otherObject ) { |
|
1754 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1752 | + if (is_array($otherObjects)) { |
|
1753 | + foreach ($otherObjects as $otherObject) { |
|
1754 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1755 | 1755 | } |
1756 | 1756 | } |
1757 | 1757 | return $otherObjects; |
@@ -1769,26 +1769,26 @@ discard block |
||
1769 | 1769 | * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
1770 | 1770 | * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs |
1771 | 1771 | */ |
1772 | - public function get_many_related($relationName,$query_params = array()){ |
|
1773 | - if($this->ID()){//this exists in the DB, so get the related things from either the cache or the DB |
|
1772 | + public function get_many_related($relationName, $query_params = array()) { |
|
1773 | + if ($this->ID()) {//this exists in the DB, so get the related things from either the cache or the DB |
|
1774 | 1774 | //if there are query parameters, forget about caching the related model objects. |
1775 | - if( $query_params ){ |
|
1775 | + if ($query_params) { |
|
1776 | 1776 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1777 | - }else{ |
|
1777 | + } else { |
|
1778 | 1778 | //did we already cache the result of this query? |
1779 | 1779 | $cached_results = $this->get_all_from_cache($relationName); |
1780 | - if ( ! $cached_results ){ |
|
1780 | + if ( ! $cached_results) { |
|
1781 | 1781 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1782 | 1782 | //if no query parameters were passed, then we got all the related model objects |
1783 | 1783 | //for that relation. We can cache them then. |
1784 | - foreach($related_model_objects as $related_model_object){ |
|
1784 | + foreach ($related_model_objects as $related_model_object) { |
|
1785 | 1785 | $this->cache($relationName, $related_model_object); |
1786 | 1786 | } |
1787 | - }else{ |
|
1787 | + } else { |
|
1788 | 1788 | $related_model_objects = $cached_results; |
1789 | 1789 | } |
1790 | 1790 | } |
1791 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1791 | + } else {//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1792 | 1792 | $related_model_objects = $this->get_all_from_cache($relationName); |
1793 | 1793 | } |
1794 | 1794 | return $related_model_objects; |
@@ -1805,8 +1805,8 @@ discard block |
||
1805 | 1805 | * @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; |
1806 | 1806 | * @return int |
1807 | 1807 | */ |
1808 | - public function count_related($relation_name, $query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1809 | - return $this->get_model()->count_related($this,$relation_name,$query_params,$field_to_count,$distinct); |
|
1808 | + public function count_related($relation_name, $query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1809 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
1810 | 1810 | } |
1811 | 1811 | |
1812 | 1812 | |
@@ -1820,7 +1820,7 @@ discard block |
||
1820 | 1820 | * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
1821 | 1821 | * @return int |
1822 | 1822 | */ |
1823 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null){ |
|
1823 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) { |
|
1824 | 1824 | return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
1825 | 1825 | } |
1826 | 1826 | |
@@ -1832,34 +1832,34 @@ discard block |
||
1832 | 1832 | * @param array $query_params like EEM_Base::get_all |
1833 | 1833 | * @return EE_Base_Class (not an array, a single object) |
1834 | 1834 | */ |
1835 | - public function get_first_related($relationName,$query_params = array()){ |
|
1836 | - if($this->ID()){//this exists in the DB, get from the cache OR the DB |
|
1835 | + public function get_first_related($relationName, $query_params = array()) { |
|
1836 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
1837 | 1837 | |
1838 | 1838 | //if they've provided some query parameters, don't bother trying to cache the result |
1839 | 1839 | //also make sure we're not caching the result of get_first_related |
1840 | 1840 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
1841 | - if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
1842 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1843 | - }else{ |
|
1841 | + if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
1842 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1843 | + } else { |
|
1844 | 1844 | //first, check if we've already cached the result of this query |
1845 | 1845 | $cached_result = $this->get_one_from_cache($relationName); |
1846 | - if ( ! $cached_result ){ |
|
1846 | + if ( ! $cached_result) { |
|
1847 | 1847 | |
1848 | 1848 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1849 | - $this->cache($relationName,$related_model_object); |
|
1850 | - }else{ |
|
1849 | + $this->cache($relationName, $related_model_object); |
|
1850 | + } else { |
|
1851 | 1851 | $related_model_object = $cached_result; |
1852 | 1852 | } |
1853 | 1853 | } |
1854 | - }else{ |
|
1854 | + } else { |
|
1855 | 1855 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
1856 | - if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
1857 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1858 | - }else{ |
|
1856 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
1857 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1858 | + } else { |
|
1859 | 1859 | $related_model_object = null; |
1860 | 1860 | } |
1861 | 1861 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
1862 | - if( ! $related_model_object){ |
|
1862 | + if ( ! $related_model_object) { |
|
1863 | 1863 | $related_model_object = $this->get_one_from_cache($relationName); |
1864 | 1864 | } |
1865 | 1865 | |
@@ -1878,12 +1878,12 @@ discard block |
||
1878 | 1878 | * @param array $query_params like EEM_Base::get_all's |
1879 | 1879 | * @return int how many deleted |
1880 | 1880 | */ |
1881 | - public function delete_related($relationName,$query_params = array()){ |
|
1882 | - if($this->ID()){ |
|
1883 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
1884 | - }else{ |
|
1881 | + public function delete_related($relationName, $query_params = array()) { |
|
1882 | + if ($this->ID()) { |
|
1883 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
1884 | + } else { |
|
1885 | 1885 | $count = count($this->get_all_from_cache($relationName)); |
1886 | - $this->clear_cache($relationName,NULL,TRUE); |
|
1886 | + $this->clear_cache($relationName, NULL, TRUE); |
|
1887 | 1887 | } |
1888 | 1888 | return $count; |
1889 | 1889 | } |
@@ -1898,13 +1898,13 @@ discard block |
||
1898 | 1898 | * @param array $query_params like EEM_Base::get_all's |
1899 | 1899 | * @return int how many deleted (including those soft deleted) |
1900 | 1900 | */ |
1901 | - public function delete_related_permanently($relationName,$query_params = array()){ |
|
1902 | - if($this->ID()){ |
|
1903 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
1904 | - }else{ |
|
1901 | + public function delete_related_permanently($relationName, $query_params = array()) { |
|
1902 | + if ($this->ID()) { |
|
1903 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
1904 | + } else { |
|
1905 | 1905 | $count = count($this->get_all_from_cache($relationName)); |
1906 | 1906 | } |
1907 | - $this->clear_cache($relationName,NULL,TRUE); |
|
1907 | + $this->clear_cache($relationName, NULL, TRUE); |
|
1908 | 1908 | return $count; |
1909 | 1909 | } |
1910 | 1910 | |
@@ -1920,7 +1920,7 @@ discard block |
||
1920 | 1920 | * @param string $field_name property to check |
1921 | 1921 | * @return bool TRUE if existing,FALSE if not. |
1922 | 1922 | */ |
1923 | - public function is_set( $field_name ) { |
|
1923 | + public function is_set($field_name) { |
|
1924 | 1924 | return isset($this->_fields[$field_name]); |
1925 | 1925 | } |
1926 | 1926 | |
@@ -1932,12 +1932,12 @@ discard block |
||
1932 | 1932 | * @throws EE_Error |
1933 | 1933 | * @return bool TRUE if existing, throw EE_Error if not. |
1934 | 1934 | */ |
1935 | - protected function _property_exists( $properties ) { |
|
1935 | + protected function _property_exists($properties) { |
|
1936 | 1936 | |
1937 | - foreach ( (array) $properties as $property_name ) { |
|
1937 | + foreach ((array) $properties as $property_name) { |
|
1938 | 1938 | //first make sure this property exists |
1939 | - if ( ! $this->_fields[ $property_name ] ) |
|
1940 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1939 | + if ( ! $this->_fields[$property_name]) |
|
1940 | + throw new EE_Error(sprintf(__('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name)); |
|
1941 | 1941 | } |
1942 | 1942 | |
1943 | 1943 | return TRUE; |
@@ -1954,7 +1954,7 @@ discard block |
||
1954 | 1954 | $fields = $this->get_model()->field_settings(FALSE); |
1955 | 1955 | $properties = array(); |
1956 | 1956 | //remove prepended underscore |
1957 | - foreach ( $fields as $field_name => $settings ) { |
|
1957 | + foreach ($fields as $field_name => $settings) { |
|
1958 | 1958 | $properties[$field_name] = $this->get($field_name); |
1959 | 1959 | } |
1960 | 1960 | return $properties; |
@@ -1984,14 +1984,14 @@ discard block |
||
1984 | 1984 | * @throws EE_Error |
1985 | 1985 | * @return mixed whatever the plugin which calls add_filter decides |
1986 | 1986 | */ |
1987 | - public function __call($methodName,$args){ |
|
1988 | - $className=get_class($this); |
|
1989 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
1990 | - if(!has_filter($tagName)){ |
|
1991 | - throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}","event_espresso"), |
|
1992 | - $methodName,$className,$tagName)); |
|
1987 | + public function __call($methodName, $args) { |
|
1988 | + $className = get_class($this); |
|
1989 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
1990 | + if ( ! has_filter($tagName)) { |
|
1991 | + throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}", "event_espresso"), |
|
1992 | + $methodName, $className, $tagName)); |
|
1993 | 1993 | } |
1994 | - return apply_filters($tagName,null,$this,$args); |
|
1994 | + return apply_filters($tagName, null, $this, $args); |
|
1995 | 1995 | } |
1996 | 1996 | |
1997 | 1997 | |
@@ -2006,22 +2006,22 @@ discard block |
||
2006 | 2006 | * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
2007 | 2007 | * NOTE: if the values haven't changed, returns 0 |
2008 | 2008 | */ |
2009 | - public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL){ |
|
2010 | - $query_params = array(array( |
|
2009 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL) { |
|
2010 | + $query_params = array(array( |
|
2011 | 2011 | 'EXM_key'=>$meta_key, |
2012 | 2012 | 'OBJ_ID'=>$this->ID(), |
2013 | 2013 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
2014 | - if($previous_value !== NULL){ |
|
2014 | + if ($previous_value !== NULL) { |
|
2015 | 2015 | $query_params[0]['EXM_value'] = $meta_value; |
2016 | 2016 | } |
2017 | 2017 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
2018 | - if( ! $existing_rows_like_that){ |
|
2018 | + if ( ! $existing_rows_like_that) { |
|
2019 | 2019 | return $this->add_extra_meta($meta_key, $meta_value); |
2020 | - }else{ |
|
2021 | - foreach( $existing_rows_like_that as $existing_row){ |
|
2022 | - $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
|
2020 | + } else { |
|
2021 | + foreach ($existing_rows_like_that as $existing_row) { |
|
2022 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
2023 | 2023 | } |
2024 | - return count( $existing_rows_like_that ); |
|
2024 | + return count($existing_rows_like_that); |
|
2025 | 2025 | } |
2026 | 2026 | } |
2027 | 2027 | |
@@ -2034,10 +2034,10 @@ discard block |
||
2034 | 2034 | * @param boolean $unique |
2035 | 2035 | * @return boolean |
2036 | 2036 | */ |
2037 | - public function add_extra_meta($meta_key,$meta_value,$unique = false){ |
|
2038 | - if($unique){ |
|
2039 | - $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key,'OBJ_ID'=>$this->ID(),'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
2040 | - if($existing_extra_meta){ |
|
2037 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) { |
|
2038 | + if ($unique) { |
|
2039 | + $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key, 'OBJ_ID'=>$this->ID(), 'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
2040 | + if ($existing_extra_meta) { |
|
2041 | 2041 | return false; |
2042 | 2042 | } |
2043 | 2043 | } |
@@ -2057,12 +2057,12 @@ discard block |
||
2057 | 2057 | * @param string $meta_value |
2058 | 2058 | * @return int number of extra meta rows deleted |
2059 | 2059 | */ |
2060 | - public function delete_extra_meta($meta_key,$meta_value = NULL){ |
|
2061 | - $query_params = array(array( |
|
2060 | + public function delete_extra_meta($meta_key, $meta_value = NULL) { |
|
2061 | + $query_params = array(array( |
|
2062 | 2062 | 'EXM_key'=>$meta_key, |
2063 | 2063 | 'OBJ_ID'=>$this->ID(), |
2064 | 2064 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
2065 | - if($meta_value !== NULL){ |
|
2065 | + if ($meta_value !== NULL) { |
|
2066 | 2066 | $query_params[0]['EXM_value'] = $meta_value; |
2067 | 2067 | } |
2068 | 2068 | $count_deleted = EEM_Extra_Meta::instance()->delete($query_params); |
@@ -2078,25 +2078,25 @@ discard block |
||
2078 | 2078 | * @param mixed $default if we don't find anything, what should we return? |
2079 | 2079 | * @return mixed single value if $single; array if ! $single |
2080 | 2080 | */ |
2081 | - public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){ |
|
2082 | - if($single){ |
|
2083 | - $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
2084 | - if ( $result instanceof EE_Extra_Meta ){ |
|
2081 | + public function get_extra_meta($meta_key, $single = FALSE, $default = NULL) { |
|
2082 | + if ($single) { |
|
2083 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
2084 | + if ($result instanceof EE_Extra_Meta) { |
|
2085 | 2085 | return $result->value(); |
2086 | - }else{ |
|
2086 | + } else { |
|
2087 | 2087 | return $default; |
2088 | 2088 | } |
2089 | - }else{ |
|
2090 | - $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
2091 | - if($results){ |
|
2089 | + } else { |
|
2090 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
2091 | + if ($results) { |
|
2092 | 2092 | $values = array(); |
2093 | - foreach($results as $result){ |
|
2094 | - if ( $result instanceof EE_Extra_Meta ){ |
|
2093 | + foreach ($results as $result) { |
|
2094 | + if ($result instanceof EE_Extra_Meta) { |
|
2095 | 2095 | $values[$result->ID()] = $result->value(); |
2096 | 2096 | } |
2097 | 2097 | } |
2098 | 2098 | return $values; |
2099 | - }else{ |
|
2099 | + } else { |
|
2100 | 2100 | return $default; |
2101 | 2101 | } |
2102 | 2102 | } |
@@ -2113,20 +2113,20 @@ discard block |
||
2113 | 2113 | * @param boolean $one_of_each_key |
2114 | 2114 | * @return array |
2115 | 2115 | */ |
2116 | - public function all_extra_meta_array($one_of_each_key = true){ |
|
2116 | + public function all_extra_meta_array($one_of_each_key = true) { |
|
2117 | 2117 | $return_array = array(); |
2118 | - if($one_of_each_key){ |
|
2118 | + if ($one_of_each_key) { |
|
2119 | 2119 | $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by'=>'EXM_key')); |
2120 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
2121 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
2120 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2121 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2122 | 2122 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
2123 | 2123 | } |
2124 | 2124 | } |
2125 | - }else{ |
|
2125 | + } else { |
|
2126 | 2126 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
2127 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
2128 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
2129 | - if( ! isset($return_array[$extra_meta_obj->key()])){ |
|
2127 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2128 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2129 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
2130 | 2130 | $return_array[$extra_meta_obj->key()] = array(); |
2131 | 2131 | } |
2132 | 2132 | $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
@@ -2139,19 +2139,19 @@ discard block |
||
2139 | 2139 | * Gets a pretty nice displayable nice for this model object. Often overridden |
2140 | 2140 | * @return string |
2141 | 2141 | */ |
2142 | - public function name(){ |
|
2142 | + public function name() { |
|
2143 | 2143 | //find a field that's not a text field |
2144 | 2144 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
2145 | - if($field_we_can_use){ |
|
2145 | + if ($field_we_can_use) { |
|
2146 | 2146 | return $this->get($field_we_can_use->get_name()); |
2147 | - }else{ |
|
2147 | + } else { |
|
2148 | 2148 | $first_few_properties = $this->model_field_array(); |
2149 | - $first_few_properties = array_slice($first_few_properties,0,3); |
|
2149 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
2150 | 2150 | $name_parts = array(); |
2151 | - foreach( $first_few_properties as $name=> $value ){ |
|
2151 | + foreach ($first_few_properties as $name=> $value) { |
|
2152 | 2152 | $name_parts[] = "$name:$value"; |
2153 | 2153 | } |
2154 | - return implode(",",$name_parts); |
|
2154 | + return implode(",", $name_parts); |
|
2155 | 2155 | } |
2156 | 2156 | } |
2157 | 2157 | |
@@ -2160,11 +2160,11 @@ discard block |
||
2160 | 2160 | * Checks if this model object has been proven to already be in the entity map |
2161 | 2161 | * @return boolean |
2162 | 2162 | */ |
2163 | - public function in_entity_map(){ |
|
2164 | - if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
|
2163 | + public function in_entity_map() { |
|
2164 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
2165 | 2165 | //well, if we looked, did we find it in the entity map? |
2166 | 2166 | return TRUE; |
2167 | - }else{ |
|
2167 | + } else { |
|
2168 | 2168 | return FALSE; |
2169 | 2169 | } |
2170 | 2170 | } |
@@ -2175,21 +2175,21 @@ discard block |
||
2175 | 2175 | * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
2176 | 2176 | * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
2177 | 2177 | */ |
2178 | - public function refresh_from_db(){ |
|
2179 | - if( $this->ID() && $this->in_entity_map() ){ |
|
2180 | - $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
|
2181 | - }else{ |
|
2178 | + public function refresh_from_db() { |
|
2179 | + if ($this->ID() && $this->in_entity_map()) { |
|
2180 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
2181 | + } else { |
|
2182 | 2182 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
2183 | 2183 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
2184 | 2184 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
2185 | 2185 | //absolutely nothing in it for this ID |
2186 | - if( WP_DEBUG ) { |
|
2186 | + if (WP_DEBUG) { |
|
2187 | 2187 | throw new EE_Error( |
2188 | 2188 | sprintf( |
2189 | - __( 'Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso' ), |
|
2189 | + __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso'), |
|
2190 | 2190 | $this->ID(), |
2191 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
2192 | - get_class( $this->get_model() ) . '::instance()->refresh_entity_map()' |
|
2191 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
2192 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
2193 | 2193 | ) |
2194 | 2194 | ); |
2195 | 2195 | } |
@@ -2201,8 +2201,8 @@ discard block |
||
2201 | 2201 | * (probably a bad assumption they have made, oh well) |
2202 | 2202 | * @return string |
2203 | 2203 | */ |
2204 | - public function __toString(){ |
|
2205 | - return sprintf( '%s (%s)', $this->name(), $this->ID() ); |
|
2204 | + public function __toString() { |
|
2205 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
2206 | 2206 | } |
2207 | 2207 | |
2208 | 2208 | /** |
@@ -2234,16 +2234,16 @@ discard block |
||
2234 | 2234 | * @return array |
2235 | 2235 | */ |
2236 | 2236 | public function __sleep() { |
2237 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
2238 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
2239 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
2240 | - if( $this->get_one_from_cache( $relation_name ) instanceof $classname && |
|
2241 | - $this->get_one_from_cache( $relation_name )->ID() ) { |
|
2242 | - $this->clear_cache( $relation_name, $this->get_one_from_cache( $relation_name )->ID() ); |
|
2237 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
2238 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
2239 | + $classname = 'EE_'.$this->get_model()->get_this_model_name(); |
|
2240 | + if ($this->get_one_from_cache($relation_name) instanceof $classname && |
|
2241 | + $this->get_one_from_cache($relation_name)->ID()) { |
|
2242 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
2243 | 2243 | } |
2244 | 2244 | } |
2245 | 2245 | } |
2246 | - return array_keys( get_object_vars( $this ) ); |
|
2246 | + return array_keys(get_object_vars($this)); |
|
2247 | 2247 | } |
2248 | 2248 | |
2249 | 2249 |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
3 | 5 | /** |
4 | 6 | * |
@@ -170,7 +172,7 @@ discard block |
||
170 | 172 | foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
171 | 173 | if($relation_obj instanceof EE_Belongs_To_Relation){ |
172 | 174 | $this->_model_relations[$relation_name] = NULL; |
173 | - }else{ |
|
175 | + } else{ |
|
174 | 176 | $this->_model_relations[$relation_name] = array(); |
175 | 177 | } |
176 | 178 | } |
@@ -215,7 +217,7 @@ discard block |
||
215 | 217 | if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
216 | 218 | $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
217 | 219 | return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
218 | - }else{ |
|
220 | + } else{ |
|
219 | 221 | return NULL; |
220 | 222 | } |
221 | 223 | } |
@@ -264,7 +266,7 @@ discard block |
||
264 | 266 | empty( $this->_fields[$field_name] ) ? $this->set( $field_name, time() ) : $this->set( $field_name, $this->_fields[$field_name] ); |
265 | 267 | } |
266 | 268 | |
267 | - }else{ |
|
269 | + } else{ |
|
268 | 270 | $this->_fields[$field_name] = $holder_of_value; |
269 | 271 | } |
270 | 272 | |
@@ -292,7 +294,7 @@ discard block |
||
292 | 294 | } |
293 | 295 | //let's unset any cache for this field_name from the $_cached_properties property. |
294 | 296 | $this->_clear_cached_property( $field_name ); |
295 | - }else{ |
|
297 | + } else{ |
|
296 | 298 | throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
297 | 299 | } |
298 | 300 | |
@@ -588,8 +590,9 @@ discard block |
||
588 | 590 | * @return void |
589 | 591 | */ |
590 | 592 | protected function _clear_cached_property( $property_name ) { |
591 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
592 | - unset( $this->_cached_properties[ $property_name ] ); |
|
593 | + if ( isset( $this->_cached_properties[ $property_name ] ) ) { |
|
594 | + unset( $this->_cached_properties[ $property_name ] ); |
|
595 | + } |
|
593 | 596 | } |
594 | 597 | |
595 | 598 | |
@@ -629,10 +632,10 @@ discard block |
||
629 | 632 | if($clear_all){ |
630 | 633 | $obj_removed = true; |
631 | 634 | $this->_model_relations[$relationName] = null; |
632 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
635 | + } elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
633 | 636 | $obj_removed = $this->_model_relations[$relationName]; |
634 | 637 | $this->_model_relations[$relationName] = null; |
635 | - }else{ |
|
638 | + } else{ |
|
636 | 639 | if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
637 | 640 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
638 | 641 | if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
@@ -646,20 +649,20 @@ discard block |
||
646 | 649 | } |
647 | 650 | if($index_found_at){ |
648 | 651 | $index_in_cache = $index_found_at; |
649 | - }else{ |
|
652 | + } else{ |
|
650 | 653 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
651 | 654 | //if it wasn't in it to begin with. So we're done |
652 | 655 | return $object_to_remove_or_index_into_array; |
653 | 656 | } |
654 | 657 | } |
655 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
658 | + } elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
656 | 659 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
657 | 660 | foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
658 | 661 | if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
659 | 662 | $index_in_cache = $index; |
660 | 663 | } |
661 | 664 | } |
662 | - }else{ |
|
665 | + } else{ |
|
663 | 666 | $index_in_cache = $object_to_remove_or_index_into_array; |
664 | 667 | } |
665 | 668 | //supposedly we've found it. But it could just be that the client code |
@@ -668,7 +671,7 @@ discard block |
||
668 | 671 | isset( $this->_model_relations[$relationName][$index_in_cache])){ |
669 | 672 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
670 | 673 | unset($this->_model_relations[$relationName][$index_in_cache]); |
671 | - }else{ |
|
674 | + } else{ |
|
672 | 675 | //that thing was never cached anyways. |
673 | 676 | $obj_removed = NULL; |
674 | 677 | } |
@@ -724,7 +727,7 @@ discard block |
||
724 | 727 | $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
725 | 728 | if(is_array($cached_array_or_object)){ |
726 | 729 | return array_shift($cached_array_or_object); |
727 | - }else{ |
|
730 | + } else{ |
|
728 | 731 | return $cached_array_or_object; |
729 | 732 | } |
730 | 733 | } |
@@ -743,10 +746,10 @@ discard block |
||
743 | 746 | $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
744 | 747 | if(is_array($cached_array_or_object)){ |
745 | 748 | $objects = $cached_array_or_object; |
746 | - }elseif($cached_array_or_object){ |
|
749 | + } elseif($cached_array_or_object){ |
|
747 | 750 | //if the result is not an array, but exists, make it an array |
748 | 751 | $objects = array($cached_array_or_object); |
749 | - }else{ |
|
752 | + } else{ |
|
750 | 753 | //if nothing was found, return an empty array |
751 | 754 | $objects = array(); |
752 | 755 | } |
@@ -761,7 +764,7 @@ discard block |
||
761 | 764 | if( $model_object->ID() ){ |
762 | 765 | $model->add_to_entity_map( $model_object ); |
763 | 766 | } |
764 | - }else{ |
|
767 | + } else{ |
|
765 | 768 | throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
766 | 769 | } |
767 | 770 | } |
@@ -886,10 +889,10 @@ discard block |
||
886 | 889 | if( $field_obj->is_nullable()){ |
887 | 890 | //if the field allows nulls, then let it be null |
888 | 891 | $field_value = NULL; |
889 | - }else{ |
|
892 | + } else{ |
|
890 | 893 | $field_value = $field_obj->get_default_value(); |
891 | 894 | } |
892 | - }else{ |
|
895 | + } else{ |
|
893 | 896 | $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
894 | 897 | } |
895 | 898 | $this->_fields[$field_name] = $field_value; |
@@ -1009,15 +1012,17 @@ discard block |
||
1009 | 1012 | $this->_tm_frmt = $in_tm_frmt; |
1010 | 1013 | } |
1011 | 1014 | |
1012 | - if ( $echo ) |
|
1013 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
1014 | - else |
|
1015 | - $field->set_date_format( $in_dt_frmt ); |
|
1015 | + if ( $echo ) { |
|
1016 | + $field->set_pretty_date_format( $in_dt_frmt ); |
|
1017 | + } else { |
|
1018 | + $field->set_date_format( $in_dt_frmt ); |
|
1019 | + } |
|
1016 | 1020 | |
1017 | - if ( $echo ) |
|
1018 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
1019 | - else |
|
1020 | - $field->set_time_format( $in_tm_frmt ); |
|
1021 | + if ( $echo ) { |
|
1022 | + $field->set_pretty_time_format( $in_tm_frmt ); |
|
1023 | + } else { |
|
1024 | + $field->set_time_format( $in_tm_frmt ); |
|
1025 | + } |
|
1021 | 1026 | |
1022 | 1027 | //set timezone in field object |
1023 | 1028 | $field->set_timezone( $this->_timezone ); |
@@ -1240,8 +1245,9 @@ discard block |
||
1240 | 1245 | EE_Registry::instance()->load_helper('DTT_Helper'); |
1241 | 1246 | $timezone = EEH_DTT_Helper::get_timezone(); |
1242 | 1247 | |
1243 | - if ( $timezone == $this->_timezone ) |
|
1244 | - return ''; |
|
1248 | + if ( $timezone == $this->_timezone ) { |
|
1249 | + return ''; |
|
1250 | + } |
|
1245 | 1251 | |
1246 | 1252 | $original_timezone = $this->_timezone; |
1247 | 1253 | $this->set_timezone( $timezone ); |
@@ -1249,8 +1255,9 @@ discard block |
||
1249 | 1255 | $fn = (array) $field_name; |
1250 | 1256 | $args = array_merge( $fn, (array) $args ); |
1251 | 1257 | |
1252 | - if ( !method_exists( $this, $callback ) ) |
|
1253 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1258 | + if ( !method_exists( $this, $callback ) ) { |
|
1259 | + throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1260 | + } |
|
1254 | 1261 | $args = (array) $args; |
1255 | 1262 | $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
1256 | 1263 | |
@@ -1294,7 +1301,7 @@ discard block |
||
1294 | 1301 | if($model instanceof EEM_Soft_Delete_Base){ |
1295 | 1302 | $result=$model->delete_permanently_by_ID($this->ID()); |
1296 | 1303 | $this->refresh_cache_of_related_objects(); |
1297 | - }else{ |
|
1304 | + } else{ |
|
1298 | 1305 | $result = $this->delete(); |
1299 | 1306 | } |
1300 | 1307 | return $result ? true : false; |
@@ -1387,7 +1394,7 @@ discard block |
||
1387 | 1394 | $this->_update_cached_related_model_objs_fks(); |
1388 | 1395 | } |
1389 | 1396 | } |
1390 | - }else{//PK is NOT auto-increment |
|
1397 | + } else{//PK is NOT auto-increment |
|
1391 | 1398 | //so check if one like it already exists in the db |
1392 | 1399 | if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
1393 | 1400 | if( ! $this->in_entity_map() && WP_DEBUG ){ |
@@ -1402,12 +1409,12 @@ discard block |
||
1402 | 1409 | ); |
1403 | 1410 | } |
1404 | 1411 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
1405 | - }else{ |
|
1412 | + } else{ |
|
1406 | 1413 | $results = $this->get_model()->insert($save_cols_n_values); |
1407 | 1414 | $this->_update_cached_related_model_objs_fks(); |
1408 | 1415 | } |
1409 | 1416 | } |
1410 | - }else{//there is NO primary key |
|
1417 | + } else{//there is NO primary key |
|
1411 | 1418 | $already_in_db = false; |
1412 | 1419 | foreach($this->get_model()->unique_indexes() as $index){ |
1413 | 1420 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
@@ -1418,7 +1425,7 @@ discard block |
||
1418 | 1425 | if( $already_in_db ){ |
1419 | 1426 | $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
1420 | 1427 | $results = $this->get_model()->update( $save_cols_n_values,array( $combined_pk_fields_n_values ) ); |
1421 | - }else{ |
|
1428 | + } else{ |
|
1422 | 1429 | $results = $this->get_model()->insert( $save_cols_n_values ); |
1423 | 1430 | } |
1424 | 1431 | } |
@@ -1470,7 +1477,7 @@ discard block |
||
1470 | 1477 | //make sure this has been saved |
1471 | 1478 | if( ! $this->ID()){ |
1472 | 1479 | $id = $this->save(); |
1473 | - }else{ |
|
1480 | + } else{ |
|
1474 | 1481 | $id = $this->ID(); |
1475 | 1482 | } |
1476 | 1483 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
@@ -1489,7 +1496,7 @@ discard block |
||
1489 | 1496 | $this->_add_relation_to($related_model_obj, $relationName); |
1490 | 1497 | $related_model_obj->save_new_cached_related_model_objs(); |
1491 | 1498 | // } |
1492 | - }else{ |
|
1499 | + } else{ |
|
1493 | 1500 | foreach($this->_model_relations[$relationName] as $related_model_obj){ |
1494 | 1501 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1495 | 1502 | //but ONLY if it DOES NOT exist in the DB |
@@ -1548,13 +1555,13 @@ discard block |
||
1548 | 1555 | |
1549 | 1556 | if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
1550 | 1557 | $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
1551 | - }else{ |
|
1558 | + } else{ |
|
1552 | 1559 | $existing = null; |
1553 | 1560 | } |
1554 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1561 | + } elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1555 | 1562 | //no primary key on this model, but there's still a matching item in the DB |
1556 | 1563 | $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
1557 | - }else{ |
|
1564 | + } else{ |
|
1558 | 1565 | $existing = null; |
1559 | 1566 | } |
1560 | 1567 | if ( $existing ) { |
@@ -1612,7 +1619,7 @@ discard block |
||
1612 | 1619 | private static function _get_model_classname( $model_name = null){ |
1613 | 1620 | if(strpos($model_name,"EE_")===0){ |
1614 | 1621 | $model_classname=str_replace("EE_","EEM_",$model_name); |
1615 | - }else{ |
|
1622 | + } else{ |
|
1616 | 1623 | $model_classname = "EEM_".$model_name; |
1617 | 1624 | } |
1618 | 1625 | return $model_classname; |
@@ -1646,7 +1653,7 @@ discard block |
||
1646 | 1653 | //now that we know the name of the variable, use a variable variable to get its value and return its |
1647 | 1654 | if( $this->get_model()->has_primary_key_field() ) { |
1648 | 1655 | return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
1649 | - }else{ |
|
1656 | + } else{ |
|
1650 | 1657 | return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
1651 | 1658 | } |
1652 | 1659 | } |
@@ -1774,7 +1781,7 @@ discard block |
||
1774 | 1781 | //if there are query parameters, forget about caching the related model objects. |
1775 | 1782 | if( $query_params ){ |
1776 | 1783 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1777 | - }else{ |
|
1784 | + } else{ |
|
1778 | 1785 | //did we already cache the result of this query? |
1779 | 1786 | $cached_results = $this->get_all_from_cache($relationName); |
1780 | 1787 | if ( ! $cached_results ){ |
@@ -1784,11 +1791,11 @@ discard block |
||
1784 | 1791 | foreach($related_model_objects as $related_model_object){ |
1785 | 1792 | $this->cache($relationName, $related_model_object); |
1786 | 1793 | } |
1787 | - }else{ |
|
1794 | + } else{ |
|
1788 | 1795 | $related_model_objects = $cached_results; |
1789 | 1796 | } |
1790 | 1797 | } |
1791 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1798 | + } else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1792 | 1799 | $related_model_objects = $this->get_all_from_cache($relationName); |
1793 | 1800 | } |
1794 | 1801 | return $related_model_objects; |
@@ -1840,22 +1847,22 @@ discard block |
||
1840 | 1847 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
1841 | 1848 | if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
1842 | 1849 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1843 | - }else{ |
|
1850 | + } else{ |
|
1844 | 1851 | //first, check if we've already cached the result of this query |
1845 | 1852 | $cached_result = $this->get_one_from_cache($relationName); |
1846 | 1853 | if ( ! $cached_result ){ |
1847 | 1854 | |
1848 | 1855 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1849 | 1856 | $this->cache($relationName,$related_model_object); |
1850 | - }else{ |
|
1857 | + } else{ |
|
1851 | 1858 | $related_model_object = $cached_result; |
1852 | 1859 | } |
1853 | 1860 | } |
1854 | - }else{ |
|
1861 | + } else{ |
|
1855 | 1862 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
1856 | 1863 | if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
1857 | 1864 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1858 | - }else{ |
|
1865 | + } else{ |
|
1859 | 1866 | $related_model_object = null; |
1860 | 1867 | } |
1861 | 1868 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
@@ -1881,7 +1888,7 @@ discard block |
||
1881 | 1888 | public function delete_related($relationName,$query_params = array()){ |
1882 | 1889 | if($this->ID()){ |
1883 | 1890 | $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
1884 | - }else{ |
|
1891 | + } else{ |
|
1885 | 1892 | $count = count($this->get_all_from_cache($relationName)); |
1886 | 1893 | $this->clear_cache($relationName,NULL,TRUE); |
1887 | 1894 | } |
@@ -1901,7 +1908,7 @@ discard block |
||
1901 | 1908 | public function delete_related_permanently($relationName,$query_params = array()){ |
1902 | 1909 | if($this->ID()){ |
1903 | 1910 | $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
1904 | - }else{ |
|
1911 | + } else{ |
|
1905 | 1912 | $count = count($this->get_all_from_cache($relationName)); |
1906 | 1913 | } |
1907 | 1914 | $this->clear_cache($relationName,NULL,TRUE); |
@@ -1936,8 +1943,9 @@ discard block |
||
1936 | 1943 | |
1937 | 1944 | foreach ( (array) $properties as $property_name ) { |
1938 | 1945 | //first make sure this property exists |
1939 | - if ( ! $this->_fields[ $property_name ] ) |
|
1940 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1946 | + if ( ! $this->_fields[ $property_name ] ) { |
|
1947 | + throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1948 | + } |
|
1941 | 1949 | } |
1942 | 1950 | |
1943 | 1951 | return TRUE; |
@@ -2017,7 +2025,7 @@ discard block |
||
2017 | 2025 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
2018 | 2026 | if( ! $existing_rows_like_that){ |
2019 | 2027 | return $this->add_extra_meta($meta_key, $meta_value); |
2020 | - }else{ |
|
2028 | + } else{ |
|
2021 | 2029 | foreach( $existing_rows_like_that as $existing_row){ |
2022 | 2030 | $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
2023 | 2031 | } |
@@ -2083,10 +2091,10 @@ discard block |
||
2083 | 2091 | $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
2084 | 2092 | if ( $result instanceof EE_Extra_Meta ){ |
2085 | 2093 | return $result->value(); |
2086 | - }else{ |
|
2094 | + } else{ |
|
2087 | 2095 | return $default; |
2088 | 2096 | } |
2089 | - }else{ |
|
2097 | + } else{ |
|
2090 | 2098 | $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
2091 | 2099 | if($results){ |
2092 | 2100 | $values = array(); |
@@ -2096,7 +2104,7 @@ discard block |
||
2096 | 2104 | } |
2097 | 2105 | } |
2098 | 2106 | return $values; |
2099 | - }else{ |
|
2107 | + } else{ |
|
2100 | 2108 | return $default; |
2101 | 2109 | } |
2102 | 2110 | } |
@@ -2122,7 +2130,7 @@ discard block |
||
2122 | 2130 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
2123 | 2131 | } |
2124 | 2132 | } |
2125 | - }else{ |
|
2133 | + } else{ |
|
2126 | 2134 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
2127 | 2135 | foreach($extra_meta_objs as $extra_meta_obj){ |
2128 | 2136 | if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
@@ -2144,7 +2152,7 @@ discard block |
||
2144 | 2152 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
2145 | 2153 | if($field_we_can_use){ |
2146 | 2154 | return $this->get($field_we_can_use->get_name()); |
2147 | - }else{ |
|
2155 | + } else{ |
|
2148 | 2156 | $first_few_properties = $this->model_field_array(); |
2149 | 2157 | $first_few_properties = array_slice($first_few_properties,0,3); |
2150 | 2158 | $name_parts = array(); |
@@ -2164,7 +2172,7 @@ discard block |
||
2164 | 2172 | if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
2165 | 2173 | //well, if we looked, did we find it in the entity map? |
2166 | 2174 | return TRUE; |
2167 | - }else{ |
|
2175 | + } else{ |
|
2168 | 2176 | return FALSE; |
2169 | 2177 | } |
2170 | 2178 | } |
@@ -2178,7 +2186,7 @@ discard block |
||
2178 | 2186 | public function refresh_from_db(){ |
2179 | 2187 | if( $this->ID() && $this->in_entity_map() ){ |
2180 | 2188 | $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
2181 | - }else{ |
|
2189 | + } else{ |
|
2182 | 2190 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
2183 | 2191 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
2184 | 2192 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |