@@ -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 |
@@ -117,59 +117,59 @@ 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 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
| 137 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 138 | 138 | |
| 139 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
| 139 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 140 | 140 | $this->_dt_frmt = $date_formats[0]; |
| 141 | 141 | $this->_tm_frmt = $date_formats[1]; |
| 142 | 142 | } else { |
| 143 | 143 | //set default formats for date and time |
| 144 | - $this->_dt_frmt = get_option( 'date_format' ); |
|
| 145 | - $this->_tm_frmt = get_option( 'time_format' ); |
|
| 144 | + $this->_dt_frmt = get_option('date_format'); |
|
| 145 | + $this->_tm_frmt = get_option('time_format'); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | //if db model is instantiating |
| 149 | - if ( $bydb ){ |
|
| 149 | + if ($bydb) { |
|
| 150 | 150 | //client code has indicated these field values are from the database |
| 151 | - foreach( $model_fields as $fieldName => $field ){ |
|
| 152 | - $this->set_from_db( $fieldName, isset( $fieldValues[ $fieldName] ) ? $fieldValues[ $fieldName ] : null ); |
|
| 151 | + foreach ($model_fields as $fieldName => $field) { |
|
| 152 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
| 153 | 153 | } |
| 154 | 154 | } else { |
| 155 | 155 | //we're constructing a brand |
| 156 | 156 | //new instance of the model object. Generally, this means we'll need to do more field validation |
| 157 | - foreach( $model_fields as $fieldName => $field ){ |
|
| 158 | - $this->set( $fieldName, isset( $fieldValues[ $fieldName ] ) ? $fieldValues[ $fieldName ] : null, true ); |
|
| 157 | + foreach ($model_fields as $fieldName => $field) { |
|
| 158 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | //remember what values were passed to this constructor |
| 163 | 163 | $this->_props_n_values_provided_in_constructor = $fieldValues; |
| 164 | 164 | //remember in entity mapper |
| 165 | - if( ! $bydb && $model->has_primary_key_field() && $this->ID() ){ |
|
| 165 | + if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
| 166 | 166 | $model->add_to_entity_map($this); |
| 167 | 167 | } |
| 168 | 168 | //setup all the relations |
| 169 | - foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
|
| 170 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
| 169 | + foreach ($this->get_model()->relation_settings() as $relation_name=>$relation_obj) { |
|
| 170 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 171 | 171 | $this->_model_relations[$relation_name] = NULL; |
| 172 | - }else{ |
|
| 172 | + } else { |
|
| 173 | 173 | $this->_model_relations[$relation_name] = array(); |
| 174 | 174 | } |
| 175 | 175 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * Action done at the end of each model object construction |
| 178 | 178 | * @param EE_Base_Class $this the model object just created |
| 179 | 179 | */ |
| 180 | - do_action( 'AHEE__EE_Base_Class__construct__finished', $this ); |
|
| 180 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @param boolean $allow_persist |
| 198 | 198 | * @return boolean |
| 199 | 199 | */ |
| 200 | - public function set_allow_persist( $allow_persist ) { |
|
| 200 | + public function set_allow_persist($allow_persist) { |
|
| 201 | 201 | return $this->_allow_persist = $allow_persist; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | * @return mixed|null |
| 212 | 212 | * @throws \EE_Error |
| 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 | |
@@ -240,19 +240,19 @@ discard block |
||
| 240 | 240 | * @param bool $use_default |
| 241 | 241 | * @throws \EE_Error |
| 242 | 242 | */ |
| 243 | - public function set( $field_name, $field_value, $use_default = FALSE ){ |
|
| 244 | - $field_obj = $this->get_model()->field_settings_for( $field_name ); |
|
| 245 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
| 243 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
| 244 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 245 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 246 | 246 | // if ( method_exists( $field_obj, 'set_timezone' )) { |
| 247 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
| 248 | - $field_obj->set_timezone( $this->_timezone ); |
|
| 249 | - $field_obj->set_date_format( $this->_dt_frmt ); |
|
| 250 | - $field_obj->set_time_format( $this->_tm_frmt ); |
|
| 247 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 248 | + $field_obj->set_timezone($this->_timezone); |
|
| 249 | + $field_obj->set_date_format($this->_dt_frmt); |
|
| 250 | + $field_obj->set_time_format($this->_tm_frmt); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | $holder_of_value = $field_obj->prepare_for_set($field_value); |
| 254 | 254 | //should the value be null? |
| 255 | - if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){ |
|
| 255 | + if (($field_value === NULL || $holder_of_value === NULL || $holder_of_value === '') && $use_default) { |
|
| 256 | 256 | $this->_fields[$field_name] = $field_obj->get_default_value(); |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -264,26 +264,26 @@ discard block |
||
| 264 | 264 | */ |
| 265 | 265 | if ( |
| 266 | 266 | $field_obj instanceof EE_Datetime_Field |
| 267 | - && $this->_fields[ $field_name ] !== null |
|
| 267 | + && $this->_fields[$field_name] !== null |
|
| 268 | 268 | && ! $this->_fields[$field_name] instanceof DateTime |
| 269 | 269 | ) { |
| 270 | - empty( $this->_fields[$field_name] ) |
|
| 271 | - ? $this->set( $field_name, time() ) |
|
| 272 | - : $this->set( $field_name, $this->_fields[$field_name] ); |
|
| 270 | + empty($this->_fields[$field_name]) |
|
| 271 | + ? $this->set($field_name, time()) |
|
| 272 | + : $this->set($field_name, $this->_fields[$field_name]); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - }else{ |
|
| 275 | + } else { |
|
| 276 | 276 | $this->_fields[$field_name] = $holder_of_value; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | //if we're not in the constructor... |
| 280 | 280 | //now check if what we set was a primary key |
| 281 | - if( |
|
| 281 | + if ( |
|
| 282 | 282 | //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
| 283 | 283 | $this->_props_n_values_provided_in_constructor |
| 284 | 284 | && $field_value |
| 285 | - && $field_name === self::_get_primary_key_name( get_class( $this ) ) |
|
| 286 | - ){ |
|
| 285 | + && $field_name === self::_get_primary_key_name(get_class($this)) |
|
| 286 | + ) { |
|
| 287 | 287 | //if so, we want all this object's fields to be filled either with |
| 288 | 288 | //what we've explicitly set on this model |
| 289 | 289 | //or what we have in the db |
@@ -291,20 +291,20 @@ discard block |
||
| 291 | 291 | $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
| 292 | 292 | |
| 293 | 293 | $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
| 294 | - foreach($fields_on_model as $field_obj){ |
|
| 295 | - if( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 296 | - && $field_obj->get_name() !== $field_name ){ |
|
| 294 | + foreach ($fields_on_model as $field_obj) { |
|
| 295 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 296 | + && $field_obj->get_name() !== $field_name) { |
|
| 297 | 297 | |
| 298 | - $this->set($field_obj->get_name(),$obj_in_db->get($field_obj->get_name())); |
|
| 298 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
| 299 | 299 | } |
| 300 | 300 | } |
| 301 | 301 | //oh this model object has an ID? well make sure its in the entity mapper |
| 302 | 302 | $this->get_model()->add_to_entity_map($this); |
| 303 | 303 | } |
| 304 | 304 | //let's unset any cache for this field_name from the $_cached_properties property. |
| 305 | - $this->_clear_cached_property( $field_name ); |
|
| 306 | - }else{ |
|
| 307 | - 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 ) ); |
|
| 305 | + $this->_clear_cached_property($field_name); |
|
| 306 | + } else { |
|
| 307 | + 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)); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | } |
@@ -321,14 +321,14 @@ discard block |
||
| 321 | 321 | * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
| 322 | 322 | * @throws \EE_Error |
| 323 | 323 | */ |
| 324 | - public function set_field_or_extra_meta( $field_name, $field_value ) { |
|
| 325 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
| 326 | - $this->set( $field_name, $field_value ); |
|
| 324 | + public function set_field_or_extra_meta($field_name, $field_value) { |
|
| 325 | + if ($this->get_model()->has_field($field_name)) { |
|
| 326 | + $this->set($field_name, $field_value); |
|
| 327 | 327 | return true; |
| 328 | 328 | } else { |
| 329 | 329 | //ensure this object is saved first so that extra meta can be properly related. |
| 330 | 330 | $this->save(); |
| 331 | - return $this->update_extra_meta( $field_name, $field_value ); |
|
| 331 | + return $this->update_extra_meta($field_name, $field_value); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
@@ -349,12 +349,12 @@ discard block |
||
| 349 | 349 | * @return mixed|null value for the field if found. null if not found. |
| 350 | 350 | * @throws \EE_Error |
| 351 | 351 | */ |
| 352 | - public function get_field_or_extra_meta( $field_name ) { |
|
| 353 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
| 354 | - $column_value = $this->get( $field_name ); |
|
| 352 | + public function get_field_or_extra_meta($field_name) { |
|
| 353 | + if ($this->get_model()->has_field($field_name)) { |
|
| 354 | + $column_value = $this->get($field_name); |
|
| 355 | 355 | } else { |
| 356 | 356 | //This isn't a column in the main table, let's see if it is in the extra meta. |
| 357 | - $column_value = $this->get_extra_meta( $field_name, true, null ); |
|
| 357 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
| 358 | 358 | } |
| 359 | 359 | return $column_value; |
| 360 | 360 | } |
@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | * @return void |
| 371 | 371 | * @throws \EE_Error |
| 372 | 372 | */ |
| 373 | - public function set_timezone( $timezone = '' ) { |
|
| 374 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
| 373 | + public function set_timezone($timezone = '') { |
|
| 374 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 375 | 375 | //make sure we clear all cached properties because they won't be relevant now |
| 376 | 376 | $this->_clear_cached_properties(); |
| 377 | 377 | |
| 378 | 378 | //make sure we update field settings and the date for all EE_Datetime_Fields |
| 379 | - $model_fields = $this->get_model()->field_settings( false ); |
|
| 380 | - foreach ( $model_fields as $field_name => $field_obj ) { |
|
| 381 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
| 382 | - $field_obj->set_timezone( $this->_timezone ); |
|
| 383 | - if ( isset( $this->_fields[$field_name] ) && $this->_fields[$field_name] instanceof DateTime ) { |
|
| 384 | - $this->_fields[$field_name]->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
| 379 | + $model_fields = $this->get_model()->field_settings(false); |
|
| 380 | + foreach ($model_fields as $field_name => $field_obj) { |
|
| 381 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 382 | + $field_obj->set_timezone($this->_timezone); |
|
| 383 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
| 384 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | * |
| 411 | 411 | * @param string $format should be a format recognizable by PHP date() functions. |
| 412 | 412 | */ |
| 413 | - public function set_date_format( $format ) { |
|
| 413 | + public function set_date_format($format) { |
|
| 414 | 414 | $this->_dt_frmt = $format; |
| 415 | 415 | //clear cached_properties because they won't be relevant now. |
| 416 | 416 | $this->_clear_cached_properties(); |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | * @since 4.6 |
| 427 | 427 | * @param string $format should be a format recognizable by PHP date() functions. |
| 428 | 428 | */ |
| 429 | - public function set_time_format( $format ) { |
|
| 429 | + public function set_time_format($format) { |
|
| 430 | 430 | $this->_tm_frmt = $format; |
| 431 | 431 | //clear cached_properties because they won't be relevant now. |
| 432 | 432 | $this->_clear_cached_properties(); |
@@ -443,8 +443,8 @@ discard block |
||
| 443 | 443 | * |
| 444 | 444 | * @return mixed string|array |
| 445 | 445 | */ |
| 446 | - public function get_format( $full = true ) { |
|
| 447 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array( $this->_dt_frmt, $this->_tm_frmt ); |
|
| 446 | + public function get_format($full = true) { |
|
| 447 | + return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
@@ -462,17 +462,17 @@ discard block |
||
| 462 | 462 | * @throws EE_Error |
| 463 | 463 | * @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) |
| 464 | 464 | */ |
| 465 | - public function cache( $relationName = '', $object_to_cache = NULL, $cache_id = NULL ){ |
|
| 465 | + public function cache($relationName = '', $object_to_cache = NULL, $cache_id = NULL) { |
|
| 466 | 466 | // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
| 467 | - if ( ! $object_to_cache instanceof EE_Base_Class ) { |
|
| 467 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
| 468 | 468 | return FALSE; |
| 469 | 469 | } |
| 470 | 470 | // also get "how" the object is related, or throw an error |
| 471 | - if( ! $relationship_to_model = $this->get_model()->related_settings_for( $relationName )) { |
|
| 472 | - throw new EE_Error( sprintf( __( 'There is no relationship to %s on a %s. Cannot cache it', 'event_espresso' ), $relationName, get_class( $this ))); |
|
| 471 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
| 472 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
| 473 | 473 | } |
| 474 | 474 | // how many things are related ? |
| 475 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ){ |
|
| 475 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 476 | 476 | // 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 |
| 477 | 477 | // so for these model objects just set it to be cached |
| 478 | 478 | $this->_model_relations[$relationName] = $object_to_cache; |
@@ -480,26 +480,26 @@ discard block |
||
| 480 | 480 | } else { |
| 481 | 481 | // 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. |
| 482 | 482 | // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
| 483 | - if( ! is_array( $this->_model_relations[$relationName] )) { |
|
| 483 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
| 484 | 484 | // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
| 485 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array( $this->_model_relations[$relationName] ) : array(); |
|
| 485 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
| 486 | 486 | } |
| 487 | 487 | // first check for a cache_id which is normally empty |
| 488 | - if ( ! empty( $cache_id )) { |
|
| 488 | + if ( ! empty($cache_id)) { |
|
| 489 | 489 | // 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 |
| 490 | - $this->_model_relations[$relationName][ $cache_id ] = $object_to_cache; |
|
| 490 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
| 491 | 491 | $return = $cache_id; |
| 492 | - } elseif ( $object_to_cache->ID() ) { |
|
| 492 | + } elseif ($object_to_cache->ID()) { |
|
| 493 | 493 | // OR the cached object originally came from the db, so let's just use it's PK for an ID |
| 494 | - $this->_model_relations[$relationName][ $object_to_cache->ID() ] = $object_to_cache; |
|
| 494 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
| 495 | 495 | $return = $object_to_cache->ID(); |
| 496 | 496 | } else { |
| 497 | 497 | // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
| 498 | 498 | $this->_model_relations[$relationName][] = $object_to_cache; |
| 499 | 499 | // move the internal pointer to the end of the array |
| 500 | - end( $this->_model_relations[$relationName] ); |
|
| 500 | + end($this->_model_relations[$relationName]); |
|
| 501 | 501 | // and grab the key so that we can return it |
| 502 | - $return = key( $this->_model_relations[$relationName] ); |
|
| 502 | + $return = key($this->_model_relations[$relationName]); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | } |
@@ -518,11 +518,11 @@ discard block |
||
| 518 | 518 | * @return void |
| 519 | 519 | * @throws \EE_Error |
| 520 | 520 | */ |
| 521 | - protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
|
| 521 | + protected function _set_cached_property($fieldname, $value, $cache_type = NULL) { |
|
| 522 | 522 | //first make sure this property exists |
| 523 | 523 | $this->get_model()->field_settings_for($fieldname); |
| 524 | 524 | |
| 525 | - $cache_type = empty( $cache_type ) ? 'standard' : $cache_type; |
|
| 525 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
| 526 | 526 | $this->_cached_properties[$fieldname][$cache_type] = $value; |
| 527 | 527 | } |
| 528 | 528 | |
@@ -543,36 +543,36 @@ discard block |
||
| 543 | 543 | * @return mixed whatever the value for the property is we're retrieving |
| 544 | 544 | * @throws \EE_Error |
| 545 | 545 | */ |
| 546 | - protected function _get_cached_property( $fieldname, $pretty = FALSE, $extra_cache_ref = NULL ) { |
|
| 546 | + protected function _get_cached_property($fieldname, $pretty = FALSE, $extra_cache_ref = NULL) { |
|
| 547 | 547 | //verify the field exists |
| 548 | 548 | $this->get_model()->field_settings_for($fieldname); |
| 549 | 549 | |
| 550 | 550 | $cache_type = $pretty ? 'pretty' : 'standard'; |
| 551 | - $cache_type .= !empty( $extra_cache_ref ) ? '_' . $extra_cache_ref : ''; |
|
| 551 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
| 552 | 552 | |
| 553 | - if ( isset( $this->_cached_properties[$fieldname][$cache_type] ) ) { |
|
| 553 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
| 554 | 554 | return $this->_cached_properties[$fieldname][$cache_type]; |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | $field_obj = $this->get_model()->field_settings_for($fieldname); |
| 558 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
| 558 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 559 | 559 | /** |
| 560 | 560 | * maybe this is EE_Datetime_Field. If so we need to make sure timezone and |
| 561 | 561 | * formats are correct. |
| 562 | 562 | */ |
| 563 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
| 564 | - $field_obj->set_timezone( $this->_timezone ); |
|
| 565 | - $field_obj->set_date_format( $this->_dt_frmt, $pretty ); |
|
| 566 | - $field_obj->set_time_format( $this->_tm_frmt, $pretty ); |
|
| 563 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 564 | + $field_obj->set_timezone($this->_timezone); |
|
| 565 | + $field_obj->set_date_format($this->_dt_frmt, $pretty); |
|
| 566 | + $field_obj->set_time_format($this->_tm_frmt, $pretty); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - if( ! isset($this->_fields[$fieldname])){ |
|
| 569 | + if ( ! isset($this->_fields[$fieldname])) { |
|
| 570 | 570 | $this->_fields[$fieldname] = NULL; |
| 571 | 571 | } |
| 572 | 572 | $value = $pretty |
| 573 | 573 | ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
| 574 | - : $field_obj->prepare_for_get($this->_fields[$fieldname] ); |
|
| 575 | - $this->_set_cached_property( $fieldname, $value, $cache_type ); |
|
| 574 | + : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
| 575 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
| 576 | 576 | return $value; |
| 577 | 577 | } |
| 578 | 578 | return null; |
@@ -598,9 +598,9 @@ discard block |
||
| 598 | 598 | * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
| 599 | 599 | * @return void |
| 600 | 600 | */ |
| 601 | - protected function _clear_cached_property( $property_name ) { |
|
| 602 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) { |
|
| 603 | - unset( $this->_cached_properties[ $property_name ] ); |
|
| 601 | + protected function _clear_cached_property($property_name) { |
|
| 602 | + if (isset($this->_cached_properties[$property_name])) { |
|
| 603 | + unset($this->_cached_properties[$property_name]); |
|
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | |
@@ -614,12 +614,12 @@ discard block |
||
| 614 | 614 | * @return EE_Base_Class |
| 615 | 615 | * @throws \EE_Error |
| 616 | 616 | */ |
| 617 | - protected function ensure_related_thing_is_model_obj($object_or_id,$model_name){ |
|
| 617 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) { |
|
| 618 | 618 | $other_model_instance = self::_get_model_instance_with_name( |
| 619 | - self::_get_model_classname( $model_name ), |
|
| 619 | + self::_get_model_classname($model_name), |
|
| 620 | 620 | $this->_timezone |
| 621 | 621 | ); |
| 622 | - return $other_model_instance->ensure_is_obj( $object_or_id ); |
|
| 622 | + return $other_model_instance->ensure_is_obj($object_or_id); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | |
@@ -636,32 +636,32 @@ discard block |
||
| 636 | 636 | * @throws EE_Error |
| 637 | 637 | * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
| 638 | 638 | */ |
| 639 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE){ |
|
| 639 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE) { |
|
| 640 | 640 | $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
| 641 | 641 | $index_in_cache = ''; |
| 642 | - if( ! $relationship_to_model){ |
|
| 642 | + if ( ! $relationship_to_model) { |
|
| 643 | 643 | throw new EE_Error( |
| 644 | 644 | sprintf( |
| 645 | - __( "There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso' ), |
|
| 645 | + __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
| 646 | 646 | $relationName, |
| 647 | - get_class( $this ) |
|
| 647 | + get_class($this) |
|
| 648 | 648 | ) |
| 649 | 649 | ); |
| 650 | 650 | } |
| 651 | - if($clear_all){ |
|
| 651 | + if ($clear_all) { |
|
| 652 | 652 | $obj_removed = true; |
| 653 | 653 | $this->_model_relations[$relationName] = null; |
| 654 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
| 654 | + }elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 655 | 655 | $obj_removed = $this->_model_relations[$relationName]; |
| 656 | 656 | $this->_model_relations[$relationName] = null; |
| 657 | - }else{ |
|
| 658 | - if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
|
| 657 | + } else { |
|
| 658 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
| 659 | 659 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
| 660 | - if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
|
| 660 | + if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
| 661 | 661 | $index_found_at = NULL; |
| 662 | 662 | //find this object in the array even though it has a different key |
| 663 | - foreach($this->_model_relations[$relationName] as $index=>$obj){ |
|
| 664 | - if( |
|
| 663 | + foreach ($this->_model_relations[$relationName] as $index=>$obj) { |
|
| 664 | + if ( |
|
| 665 | 665 | $obj instanceof EE_Base_Class |
| 666 | 666 | && ( |
| 667 | 667 | $obj == $object_to_remove_or_index_into_array |
@@ -672,34 +672,34 @@ discard block |
||
| 672 | 672 | break; |
| 673 | 673 | } |
| 674 | 674 | } |
| 675 | - if($index_found_at){ |
|
| 675 | + if ($index_found_at) { |
|
| 676 | 676 | $index_in_cache = $index_found_at; |
| 677 | - }else{ |
|
| 677 | + } else { |
|
| 678 | 678 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
| 679 | 679 | //if it wasn't in it to begin with. So we're done |
| 680 | 680 | return $object_to_remove_or_index_into_array; |
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
| 683 | + }elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
| 684 | 684 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
| 685 | - foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
|
| 686 | - if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
|
| 685 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
| 686 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
| 687 | 687 | $index_in_cache = $index; |
| 688 | 688 | } |
| 689 | 689 | } |
| 690 | - }else{ |
|
| 690 | + } else { |
|
| 691 | 691 | $index_in_cache = $object_to_remove_or_index_into_array; |
| 692 | 692 | } |
| 693 | 693 | //supposedly we've found it. But it could just be that the client code |
| 694 | 694 | //provided a bad index/object |
| 695 | 695 | if ( |
| 696 | 696 | isset( |
| 697 | - $this->_model_relations[ $relationName ], |
|
| 698 | - $this->_model_relations[ $relationName ][ $index_in_cache ] |
|
| 697 | + $this->_model_relations[$relationName], |
|
| 698 | + $this->_model_relations[$relationName][$index_in_cache] |
|
| 699 | 699 | ) |
| 700 | 700 | ) { |
| 701 | - $obj_removed = $this->_model_relations[ $relationName ][ $index_in_cache ]; |
|
| 702 | - unset( $this->_model_relations[ $relationName ][ $index_in_cache ] ); |
|
| 701 | + $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
| 702 | + unset($this->_model_relations[$relationName][$index_in_cache]); |
|
| 703 | 703 | } else { |
| 704 | 704 | //that thing was never cached anyways. |
| 705 | 705 | $obj_removed = null; |
@@ -720,24 +720,24 @@ discard block |
||
| 720 | 720 | * @return boolean TRUE on success, FALSE on fail |
| 721 | 721 | * @throws \EE_Error |
| 722 | 722 | */ |
| 723 | - public function update_cache_after_object_save( $relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
| 723 | + public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
| 724 | 724 | // verify that incoming object is of the correct type |
| 725 | - $obj_class = 'EE_' . $relationName; |
|
| 726 | - if ( $newly_saved_object instanceof $obj_class ) { |
|
| 725 | + $obj_class = 'EE_'.$relationName; |
|
| 726 | + if ($newly_saved_object instanceof $obj_class) { |
|
| 727 | 727 | /* @type EE_Base_Class $newly_saved_object*/ |
| 728 | 728 | // now get the type of relation |
| 729 | - $relationship_to_model = $this->get_model()->related_settings_for( $relationName ); |
|
| 729 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 730 | 730 | // if this is a 1:1 relationship |
| 731 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ) { |
|
| 731 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 732 | 732 | // then just replace the cached object with the newly saved object |
| 733 | 733 | $this->_model_relations[$relationName] = $newly_saved_object; |
| 734 | 734 | return TRUE; |
| 735 | 735 | // or if it's some kind of sordid feral polyamorous relationship... |
| 736 | - } elseif ( is_array( $this->_model_relations[$relationName] ) && isset( $this->_model_relations[$relationName][ $current_cache_id ] )) { |
|
| 736 | + } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
| 737 | 737 | // then remove the current cached item |
| 738 | - unset( $this->_model_relations[$relationName][ $current_cache_id ] ); |
|
| 738 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
| 739 | 739 | // and cache the newly saved object using it's new ID |
| 740 | - $this->_model_relations[$relationName][ $newly_saved_object->ID() ] = $newly_saved_object; |
|
| 740 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
| 741 | 741 | return TRUE; |
| 742 | 742 | } |
| 743 | 743 | } |
@@ -753,11 +753,11 @@ discard block |
||
| 753 | 753 | * @param string $relationName |
| 754 | 754 | * @return EE_Base_Class |
| 755 | 755 | */ |
| 756 | - public function get_one_from_cache($relationName){ |
|
| 757 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
|
| 758 | - if(is_array($cached_array_or_object)){ |
|
| 756 | + public function get_one_from_cache($relationName) { |
|
| 757 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null; |
|
| 758 | + if (is_array($cached_array_or_object)) { |
|
| 759 | 759 | return array_shift($cached_array_or_object); |
| 760 | - }else{ |
|
| 760 | + } else { |
|
| 761 | 761 | return $cached_array_or_object; |
| 762 | 762 | } |
| 763 | 763 | } |
@@ -772,23 +772,23 @@ discard block |
||
| 772 | 772 | * @throws \EE_Error |
| 773 | 773 | * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
| 774 | 774 | */ |
| 775 | - public function get_all_from_cache($relationName){ |
|
| 776 | - $objects = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
|
| 775 | + public function get_all_from_cache($relationName) { |
|
| 776 | + $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
| 777 | 777 | // if the result is not an array, but exists, make it an array |
| 778 | - $objects = is_array( $objects ) ? $objects : array( $objects ); |
|
| 778 | + $objects = is_array($objects) ? $objects : array($objects); |
|
| 779 | 779 | //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
| 780 | 780 | //basically, if this model object was stored in the session, and these cached model objects |
| 781 | 781 | //already have IDs, let's make sure they're in their model's entity mapper |
| 782 | 782 | //otherwise we will have duplicates next time we call |
| 783 | 783 | // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
| 784 | - $model = EE_Registry::instance()->load_model( $relationName ); |
|
| 785 | - foreach( $objects as $model_object ){ |
|
| 786 | - if( $model instanceof EEM_Base && $model_object instanceof EE_Base_Class ){ |
|
| 784 | + $model = EE_Registry::instance()->load_model($relationName); |
|
| 785 | + foreach ($objects as $model_object) { |
|
| 786 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
| 787 | 787 | //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
| 788 | - if( $model_object->ID() ){ |
|
| 789 | - $model->add_to_entity_map( $model_object ); |
|
| 788 | + if ($model_object->ID()) { |
|
| 789 | + $model->add_to_entity_map($model_object); |
|
| 790 | 790 | } |
| 791 | - }else{ |
|
| 791 | + } else { |
|
| 792 | 792 | throw new EE_Error( |
| 793 | 793 | sprintf( |
| 794 | 794 | __( |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | 'event_espresso' |
| 797 | 797 | ), |
| 798 | 798 | $relationName, |
| 799 | - gettype( $model_object ) |
|
| 799 | + gettype($model_object) |
|
| 800 | 800 | ) |
| 801 | 801 | ); |
| 802 | 802 | } |
@@ -818,15 +818,15 @@ discard block |
||
| 818 | 818 | * @return array|EE_Base_Class[] |
| 819 | 819 | * @throws \EE_Error |
| 820 | 820 | */ |
| 821 | - public function next_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
| 822 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
| 821 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
| 822 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 823 | 823 | ? $this->get_model()->get_primary_key_field()->get_name() |
| 824 | 824 | : $field_to_order_by; |
| 825 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 826 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 825 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 826 | + if (empty($field) || empty($current_value)) { |
|
| 827 | 827 | return array(); |
| 828 | 828 | } |
| 829 | - return $this->get_model()->next_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
| 829 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | |
@@ -843,15 +843,15 @@ discard block |
||
| 843 | 843 | * @return array|EE_Base_Class[] |
| 844 | 844 | * @throws \EE_Error |
| 845 | 845 | */ |
| 846 | - public function previous_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
| 847 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
| 846 | + public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
| 847 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 848 | 848 | ? $this->get_model()->get_primary_key_field()->get_name() |
| 849 | 849 | : $field_to_order_by; |
| 850 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 851 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 850 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 851 | + if (empty($field) || empty($current_value)) { |
|
| 852 | 852 | return array(); |
| 853 | 853 | } |
| 854 | - return $this->get_model()->previous_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
| 854 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | |
@@ -867,15 +867,15 @@ discard block |
||
| 867 | 867 | * @return array|EE_Base_Class |
| 868 | 868 | * @throws \EE_Error |
| 869 | 869 | */ |
| 870 | - public function next( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
| 871 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
| 870 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
| 871 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 872 | 872 | ? $this->get_model()->get_primary_key_field()->get_name() |
| 873 | 873 | : $field_to_order_by; |
| 874 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 875 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 874 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 875 | + if (empty($field) || empty($current_value)) { |
|
| 876 | 876 | return array(); |
| 877 | 877 | } |
| 878 | - return $this->get_model()->next( $current_value, $field, $query_params, $columns_to_select ); |
|
| 878 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | |
@@ -891,15 +891,15 @@ discard block |
||
| 891 | 891 | * @return array|EE_Base_Class |
| 892 | 892 | * @throws \EE_Error |
| 893 | 893 | */ |
| 894 | - public function previous( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
| 895 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
| 894 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
| 895 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 896 | 896 | ? $this->get_model()->get_primary_key_field()->get_name() |
| 897 | 897 | : $field_to_order_by; |
| 898 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
| 899 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
| 898 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 899 | + if (empty($field) || empty($current_value)) { |
|
| 900 | 900 | return array(); |
| 901 | 901 | } |
| 902 | - return $this->get_model()->previous( $current_value, $field, $query_params, $columns_to_select ); |
|
| 902 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | |
@@ -912,25 +912,25 @@ discard block |
||
| 912 | 912 | * @param mixed $field_value_from_db |
| 913 | 913 | * @throws \EE_Error |
| 914 | 914 | */ |
| 915 | - public function set_from_db($field_name,$field_value_from_db){ |
|
| 915 | + public function set_from_db($field_name, $field_value_from_db) { |
|
| 916 | 916 | $field_obj = $this->get_model()->field_settings_for($field_name); |
| 917 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
| 917 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 918 | 918 | //you would think the DB has no NULLs for non-null label fields right? wrong! |
| 919 | 919 | //eg, a CPT model object could have an entry in the posts table, but no |
| 920 | 920 | //entry in the meta table. Meaning that all its columns in the meta table |
| 921 | 921 | //are null! yikes! so when we find one like that, use defaults for its meta columns |
| 922 | - if($field_value_from_db === NULL ){ |
|
| 923 | - if( $field_obj->is_nullable()){ |
|
| 922 | + if ($field_value_from_db === NULL) { |
|
| 923 | + if ($field_obj->is_nullable()) { |
|
| 924 | 924 | //if the field allows nulls, then let it be null |
| 925 | 925 | $field_value = NULL; |
| 926 | - }else{ |
|
| 926 | + } else { |
|
| 927 | 927 | $field_value = $field_obj->get_default_value(); |
| 928 | 928 | } |
| 929 | - }else{ |
|
| 930 | - $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
|
| 929 | + } else { |
|
| 930 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
| 931 | 931 | } |
| 932 | 932 | $this->_fields[$field_name] = $field_value; |
| 933 | - $this->_clear_cached_property( $field_name ); |
|
| 933 | + $this->_clear_cached_property($field_name); |
|
| 934 | 934 | } |
| 935 | 935 | } |
| 936 | 936 | |
@@ -946,8 +946,8 @@ discard block |
||
| 946 | 946 | * @return mixed |
| 947 | 947 | * @throws \EE_Error |
| 948 | 948 | */ |
| 949 | - public function get($field_name, $extra_cache_ref = NULL ){ |
|
| 950 | - return $this->_get_cached_property( $field_name, FALSE, $extra_cache_ref ); |
|
| 949 | + public function get($field_name, $extra_cache_ref = NULL) { |
|
| 950 | + return $this->_get_cached_property($field_name, FALSE, $extra_cache_ref); |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | |
@@ -980,10 +980,10 @@ discard block |
||
| 980 | 980 | * just null is returned (because that indicates that likely |
| 981 | 981 | * this field is nullable). |
| 982 | 982 | */ |
| 983 | - public function get_DateTime_object( $field_name ) { |
|
| 984 | - $field_settings = $this->get_model()->field_settings_for( $field_name ); |
|
| 983 | + public function get_DateTime_object($field_name) { |
|
| 984 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 985 | 985 | |
| 986 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
| 986 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
| 987 | 987 | EE_Error::add_error( |
| 988 | 988 | sprintf( |
| 989 | 989 | __( |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | * @return void |
| 1016 | 1016 | * @throws \EE_Error |
| 1017 | 1017 | */ |
| 1018 | - public function e($field_name, $extra_cache_ref = NULL){ |
|
| 1018 | + public function e($field_name, $extra_cache_ref = NULL) { |
|
| 1019 | 1019 | echo $this->get_pretty($field_name, $extra_cache_ref); |
| 1020 | 1020 | } |
| 1021 | 1021 | |
@@ -1029,8 +1029,8 @@ discard block |
||
| 1029 | 1029 | * @return void |
| 1030 | 1030 | * @throws \EE_Error |
| 1031 | 1031 | */ |
| 1032 | - public function f($field_name){ |
|
| 1033 | - $this->e($field_name,'form_input'); |
|
| 1032 | + public function f($field_name) { |
|
| 1033 | + $this->e($field_name, 'form_input'); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | |
@@ -1043,8 +1043,8 @@ discard block |
||
| 1043 | 1043 | * @return mixed |
| 1044 | 1044 | * @throws \EE_Error |
| 1045 | 1045 | */ |
| 1046 | - public function get_pretty($field_name, $extra_cache_ref = NULL){ |
|
| 1047 | - return $this->_get_cached_property( $field_name, TRUE, $extra_cache_ref ); |
|
| 1046 | + public function get_pretty($field_name, $extra_cache_ref = NULL) { |
|
| 1047 | + return $this->_get_cached_property($field_name, TRUE, $extra_cache_ref); |
|
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | 1050 | |
@@ -1062,36 +1062,36 @@ discard block |
||
| 1062 | 1062 | * @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 |
| 1063 | 1063 | * @throws \EE_Error |
| 1064 | 1064 | */ |
| 1065 | - protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
|
| 1065 | + protected function _get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE) { |
|
| 1066 | 1066 | |
| 1067 | - $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
| 1067 | + $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
| 1068 | 1068 | $in_tm_frmt = empty($tm_frmt) ? $this->_tm_frmt : $tm_frmt; |
| 1069 | 1069 | |
| 1070 | 1070 | //validate field for datetime and returns field settings if valid. |
| 1071 | - $field = $this->_get_dtt_field_settings( $field_name ); |
|
| 1071 | + $field = $this->_get_dtt_field_settings($field_name); |
|
| 1072 | 1072 | |
| 1073 | 1073 | //clear cached property if either formats are not null. |
| 1074 | - if( $dt_frmt !== null || $tm_frmt !== null ) { |
|
| 1075 | - $this->_clear_cached_property( $field_name ); |
|
| 1074 | + if ($dt_frmt !== null || $tm_frmt !== null) { |
|
| 1075 | + $this->_clear_cached_property($field_name); |
|
| 1076 | 1076 | //reset format properties because they are used in get() |
| 1077 | 1077 | $this->_dt_frmt = $in_dt_frmt; |
| 1078 | 1078 | $this->_tm_frmt = $in_tm_frmt; |
| 1079 | 1079 | } |
| 1080 | - if ( $echo ) { |
|
| 1081 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
| 1080 | + if ($echo) { |
|
| 1081 | + $field->set_pretty_date_format($in_dt_frmt); |
|
| 1082 | 1082 | } else { |
| 1083 | - $field->set_date_format( $in_dt_frmt ); |
|
| 1083 | + $field->set_date_format($in_dt_frmt); |
|
| 1084 | 1084 | } |
| 1085 | - if ( $echo ) { |
|
| 1086 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
| 1085 | + if ($echo) { |
|
| 1086 | + $field->set_pretty_time_format($in_tm_frmt); |
|
| 1087 | 1087 | } else { |
| 1088 | - $field->set_time_format( $in_tm_frmt ); |
|
| 1088 | + $field->set_time_format($in_tm_frmt); |
|
| 1089 | 1089 | } |
| 1090 | 1090 | //set timezone in field object |
| 1091 | - $field->set_timezone( $this->_timezone ); |
|
| 1091 | + $field->set_timezone($this->_timezone); |
|
| 1092 | 1092 | |
| 1093 | 1093 | //set the output returned |
| 1094 | - switch ( $date_or_time ) { |
|
| 1094 | + switch ($date_or_time) { |
|
| 1095 | 1095 | |
| 1096 | 1096 | case 'D' : |
| 1097 | 1097 | $field->set_date_time_output('date'); |
@@ -1106,11 +1106,11 @@ discard block |
||
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | |
| 1109 | - if ( $echo ) { |
|
| 1110 | - $this->e( $field_name, $date_or_time ); |
|
| 1109 | + if ($echo) { |
|
| 1110 | + $this->e($field_name, $date_or_time); |
|
| 1111 | 1111 | return ''; |
| 1112 | 1112 | } |
| 1113 | - return $this->get( $field_name, $date_or_time ); |
|
| 1113 | + return $this->get($field_name, $date_or_time); |
|
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | |
@@ -1123,8 +1123,8 @@ discard block |
||
| 1123 | 1123 | * @return string datetime value formatted |
| 1124 | 1124 | * @throws \EE_Error |
| 1125 | 1125 | */ |
| 1126 | - public function get_date( $field_name, $format = NULL ) { |
|
| 1127 | - return $this->_get_datetime( $field_name, $format, NULL, 'D' ); |
|
| 1126 | + public function get_date($field_name, $format = NULL) { |
|
| 1127 | + return $this->_get_datetime($field_name, $format, NULL, 'D'); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | |
@@ -1134,8 +1134,8 @@ discard block |
||
| 1134 | 1134 | * @param null $format |
| 1135 | 1135 | * @throws \EE_Error |
| 1136 | 1136 | */ |
| 1137 | - public function e_date( $field_name, $format = NULL ) { |
|
| 1138 | - $this->_get_datetime( $field_name, $format, NULL, 'D', TRUE ); |
|
| 1137 | + public function e_date($field_name, $format = NULL) { |
|
| 1138 | + $this->_get_datetime($field_name, $format, NULL, 'D', TRUE); |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | |
@@ -1148,8 +1148,8 @@ discard block |
||
| 1148 | 1148 | * @return string datetime value formatted |
| 1149 | 1149 | * @throws \EE_Error |
| 1150 | 1150 | */ |
| 1151 | - public function get_time( $field_name, $format = NULL ) { |
|
| 1152 | - return $this->_get_datetime( $field_name, NULL, $format, 'T' ); |
|
| 1151 | + public function get_time($field_name, $format = NULL) { |
|
| 1152 | + return $this->_get_datetime($field_name, NULL, $format, 'T'); |
|
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | |
@@ -1159,8 +1159,8 @@ discard block |
||
| 1159 | 1159 | * @param null $format |
| 1160 | 1160 | * @throws \EE_Error |
| 1161 | 1161 | */ |
| 1162 | - public function e_time( $field_name, $format = NULL ) { |
|
| 1163 | - $this->_get_datetime( $field_name, NULL, $format, 'T', TRUE ); |
|
| 1162 | + public function e_time($field_name, $format = NULL) { |
|
| 1163 | + $this->_get_datetime($field_name, NULL, $format, 'T', TRUE); |
|
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | |
@@ -1174,8 +1174,8 @@ discard block |
||
| 1174 | 1174 | * @return string datetime value formatted |
| 1175 | 1175 | * @throws \EE_Error |
| 1176 | 1176 | */ |
| 1177 | - public function get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
| 1178 | - return $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt ); |
|
| 1177 | + public function get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
| 1178 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | |
@@ -1186,8 +1186,8 @@ discard block |
||
| 1186 | 1186 | * @param null $tm_frmt |
| 1187 | 1187 | * @throws \EE_Error |
| 1188 | 1188 | */ |
| 1189 | - public function e_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
| 1190 | - $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
| 1189 | + public function e_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
| 1190 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | |
@@ -1201,11 +1201,11 @@ discard block |
||
| 1201 | 1201 | * @throws \EE_Error |
| 1202 | 1202 | * field name. |
| 1203 | 1203 | */ |
| 1204 | - public function get_i18n_datetime( $field_name, $format = NULL ) { |
|
| 1205 | - $format = empty( $format ) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1204 | + public function get_i18n_datetime($field_name, $format = NULL) { |
|
| 1205 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
| 1206 | 1206 | return date_i18n( |
| 1207 | 1207 | $format, |
| 1208 | - EEH_DTT_Helper::get_timestamp_with_offset( $this->get_raw( $field_name ), $this->_timezone ) |
|
| 1208 | + EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
| 1209 | 1209 | ); |
| 1210 | 1210 | } |
| 1211 | 1211 | |
@@ -1218,14 +1218,14 @@ discard block |
||
| 1218 | 1218 | * @throws EE_Error |
| 1219 | 1219 | * @return EE_Datetime_Field |
| 1220 | 1220 | */ |
| 1221 | - protected function _get_dtt_field_settings( $field_name ) { |
|
| 1221 | + protected function _get_dtt_field_settings($field_name) { |
|
| 1222 | 1222 | $field = $this->get_model()->field_settings_for($field_name); |
| 1223 | 1223 | |
| 1224 | 1224 | //check if field is dtt |
| 1225 | - if ( $field instanceof EE_Datetime_Field ) { |
|
| 1225 | + if ($field instanceof EE_Datetime_Field) { |
|
| 1226 | 1226 | return $field; |
| 1227 | 1227 | } else { |
| 1228 | - 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) ) ) ); |
|
| 1228 | + 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)))); |
|
| 1229 | 1229 | } |
| 1230 | 1230 | } |
| 1231 | 1231 | |
@@ -1246,8 +1246,8 @@ discard block |
||
| 1246 | 1246 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
| 1247 | 1247 | * @throws \EE_Error |
| 1248 | 1248 | */ |
| 1249 | - protected function _set_time_for( $time, $fieldname ) { |
|
| 1250 | - $this->_set_date_time( 'T', $time, $fieldname ); |
|
| 1249 | + protected function _set_time_for($time, $fieldname) { |
|
| 1250 | + $this->_set_date_time('T', $time, $fieldname); |
|
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | 1253 | |
@@ -1260,8 +1260,8 @@ discard block |
||
| 1260 | 1260 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
| 1261 | 1261 | * @throws \EE_Error |
| 1262 | 1262 | */ |
| 1263 | - protected function _set_date_for( $date, $fieldname ) { |
|
| 1264 | - $this->_set_date_time( 'D', $date, $fieldname ); |
|
| 1263 | + protected function _set_date_for($date, $fieldname) { |
|
| 1264 | + $this->_set_date_time('D', $date, $fieldname); |
|
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | |
@@ -1275,26 +1275,26 @@ discard block |
||
| 1275 | 1275 | * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
| 1276 | 1276 | * @throws \EE_Error |
| 1277 | 1277 | */ |
| 1278 | - protected function _set_date_time( $what = 'T', $datetime_value, $fieldname ) { |
|
| 1279 | - $field = $this->_get_dtt_field_settings( $fieldname ); |
|
| 1280 | - $field->set_timezone( $this->_timezone ); |
|
| 1281 | - $field->set_date_format( $this->_dt_frmt ); |
|
| 1282 | - $field->set_time_format( $this->_tm_frmt ); |
|
| 1283 | - switch ( $what ) { |
|
| 1278 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) { |
|
| 1279 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
| 1280 | + $field->set_timezone($this->_timezone); |
|
| 1281 | + $field->set_date_format($this->_dt_frmt); |
|
| 1282 | + $field->set_time_format($this->_tm_frmt); |
|
| 1283 | + switch ($what) { |
|
| 1284 | 1284 | case 'T' : |
| 1285 | - $this->_fields[ $fieldname ] = $field->prepare_for_set_with_new_time( |
|
| 1285 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
| 1286 | 1286 | $datetime_value, |
| 1287 | - $this->_fields[ $fieldname ] |
|
| 1287 | + $this->_fields[$fieldname] |
|
| 1288 | 1288 | ); |
| 1289 | 1289 | break; |
| 1290 | 1290 | case 'D' : |
| 1291 | - $this->_fields[ $fieldname ] = $field->prepare_for_set_with_new_date( |
|
| 1291 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
| 1292 | 1292 | $datetime_value, |
| 1293 | - $this->_fields[ $fieldname ] |
|
| 1293 | + $this->_fields[$fieldname] |
|
| 1294 | 1294 | ); |
| 1295 | 1295 | break; |
| 1296 | 1296 | case 'B' : |
| 1297 | - $this->_fields[ $fieldname ] = $field->prepare_for_set( $datetime_value ); |
|
| 1297 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
| 1298 | 1298 | break; |
| 1299 | 1299 | } |
| 1300 | 1300 | $this->_clear_cached_property($fieldname); |
@@ -1316,17 +1316,17 @@ discard block |
||
| 1316 | 1316 | * @throws EE_Error |
| 1317 | 1317 | * @return string timestamp |
| 1318 | 1318 | */ |
| 1319 | - public function display_in_my_timezone( $field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '' ) { |
|
| 1319 | + public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '') { |
|
| 1320 | 1320 | $timezone = EEH_DTT_Helper::get_timezone(); |
| 1321 | - if ( $timezone === $this->_timezone ) { |
|
| 1321 | + if ($timezone === $this->_timezone) { |
|
| 1322 | 1322 | return ''; |
| 1323 | 1323 | } |
| 1324 | 1324 | $original_timezone = $this->_timezone; |
| 1325 | - $this->set_timezone( $timezone ); |
|
| 1325 | + $this->set_timezone($timezone); |
|
| 1326 | 1326 | |
| 1327 | 1327 | $fn = (array) $field_name; |
| 1328 | - $args = array_merge( $fn, (array) $args ); |
|
| 1329 | - if ( ! method_exists( $this, $callback ) ) { |
|
| 1328 | + $args = array_merge($fn, (array) $args); |
|
| 1329 | + if ( ! method_exists($this, $callback)) { |
|
| 1330 | 1330 | throw new EE_Error( |
| 1331 | 1331 | sprintf( |
| 1332 | 1332 | __( |
@@ -1338,9 +1338,9 @@ discard block |
||
| 1338 | 1338 | ); |
| 1339 | 1339 | } |
| 1340 | 1340 | $args = (array) $args; |
| 1341 | - $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
|
| 1341 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
| 1342 | 1342 | |
| 1343 | - $this->set_timezone( $original_timezone ); |
|
| 1343 | + $this->set_timezone($original_timezone); |
|
| 1344 | 1344 | return $return; |
| 1345 | 1345 | } |
| 1346 | 1346 | |
@@ -1354,7 +1354,7 @@ discard block |
||
| 1354 | 1354 | * @return boolean | int |
| 1355 | 1355 | * @throws \EE_Error |
| 1356 | 1356 | */ |
| 1357 | - public function delete(){ |
|
| 1357 | + public function delete() { |
|
| 1358 | 1358 | /** |
| 1359 | 1359 | * Called just before the `EE_Base_Class::_delete` method call. |
| 1360 | 1360 | * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
@@ -1363,7 +1363,7 @@ discard block |
||
| 1363 | 1363 | * |
| 1364 | 1364 | * @param EE_Base_Class $model_object about to be 'deleted' |
| 1365 | 1365 | */ |
| 1366 | - do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
|
| 1366 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
| 1367 | 1367 | $result = $this->_delete(); |
| 1368 | 1368 | /** |
| 1369 | 1369 | * Called just after the `EE_Base_Class::_delete` method call. |
@@ -1373,7 +1373,7 @@ discard block |
||
| 1373 | 1373 | * @param EE_Base_Class $model_object that was just 'deleted' |
| 1374 | 1374 | * @param boolean $result |
| 1375 | 1375 | */ |
| 1376 | - do_action( 'AHEE__EE_Base_Class__delete__end', $this, $result ); |
|
| 1376 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
| 1377 | 1377 | return $result; |
| 1378 | 1378 | } |
| 1379 | 1379 | |
@@ -1399,22 +1399,22 @@ discard block |
||
| 1399 | 1399 | * @return bool | int |
| 1400 | 1400 | * @throws \EE_Error |
| 1401 | 1401 | */ |
| 1402 | - public function delete_permanently(){ |
|
| 1402 | + public function delete_permanently() { |
|
| 1403 | 1403 | /** |
| 1404 | 1404 | * Called just before HARD deleting a model object |
| 1405 | 1405 | * |
| 1406 | 1406 | * @param EE_Base_Class $model_object about to be 'deleted' |
| 1407 | 1407 | */ |
| 1408 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__before', $this ); |
|
| 1409 | - $model=$this->get_model(); |
|
| 1410 | - $result=$model->delete_permanently_by_ID($this->ID()); |
|
| 1408 | + do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
| 1409 | + $model = $this->get_model(); |
|
| 1410 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
| 1411 | 1411 | $this->refresh_cache_of_related_objects(); |
| 1412 | 1412 | /** |
| 1413 | 1413 | * Called just after HARD deleting a model object |
| 1414 | 1414 | * @param EE_Base_Class $model_object that was just 'deleted' |
| 1415 | 1415 | * @param boolean $result |
| 1416 | 1416 | */ |
| 1417 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__end', $this, $result ); |
|
| 1417 | + do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
| 1418 | 1418 | return $result; |
| 1419 | 1419 | } |
| 1420 | 1420 | |
@@ -1427,18 +1427,18 @@ discard block |
||
| 1427 | 1427 | * @throws \EE_Error |
| 1428 | 1428 | */ |
| 1429 | 1429 | public function refresh_cache_of_related_objects() { |
| 1430 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 1431 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
| 1432 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
| 1433 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 1430 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1431 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
| 1432 | + $related_objects = $this->_model_relations[$relation_name]; |
|
| 1433 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 1434 | 1434 | //this relation only stores a single model object, not an array |
| 1435 | 1435 | //but let's make it consistent |
| 1436 | - $related_objects = array( $related_objects ); |
|
| 1436 | + $related_objects = array($related_objects); |
|
| 1437 | 1437 | } |
| 1438 | - foreach( $related_objects as $related_object ) { |
|
| 1438 | + foreach ($related_objects as $related_object) { |
|
| 1439 | 1439 | //only refresh their cache if they're in memory |
| 1440 | - if( $related_object instanceof EE_Base_Class ) { |
|
| 1441 | - $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1440 | + if ($related_object instanceof EE_Base_Class) { |
|
| 1441 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1442 | 1442 | } |
| 1443 | 1443 | } |
| 1444 | 1444 | } |
@@ -1458,17 +1458,17 @@ discard block |
||
| 1458 | 1458 | * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
| 1459 | 1459 | * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
| 1460 | 1460 | */ |
| 1461 | - public function save($set_cols_n_values=array()) { |
|
| 1461 | + public function save($set_cols_n_values = array()) { |
|
| 1462 | 1462 | /** |
| 1463 | 1463 | * Filters the fields we're about to save on the model object |
| 1464 | 1464 | * |
| 1465 | 1465 | * @param array $set_cols_n_values |
| 1466 | 1466 | * @param EE_Base_Class $model_object |
| 1467 | 1467 | */ |
| 1468 | - $set_cols_n_values = (array)apply_filters( 'FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this ); |
|
| 1468 | + $set_cols_n_values = (array) apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
| 1469 | 1469 | //set attributes as provided in $set_cols_n_values |
| 1470 | - foreach($set_cols_n_values as $column=>$value){ |
|
| 1471 | - $this->set($column,$value); |
|
| 1470 | + foreach ($set_cols_n_values as $column=>$value) { |
|
| 1471 | + $this->set($column, $value); |
|
| 1472 | 1472 | } |
| 1473 | 1473 | /** |
| 1474 | 1474 | * Saving a model object. |
@@ -1476,8 +1476,8 @@ discard block |
||
| 1476 | 1476 | * Before we perform a save, this action is fired. |
| 1477 | 1477 | * @param EE_Base_Class $model_object the model object about to be saved. |
| 1478 | 1478 | */ |
| 1479 | - do_action( 'AHEE__EE_Base_Class__save__begin', $this ); |
|
| 1480 | - if( ! $this->allow_persist() ) { |
|
| 1479 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
| 1480 | + if ( ! $this->allow_persist()) { |
|
| 1481 | 1481 | return 0; |
| 1482 | 1482 | } |
| 1483 | 1483 | //now get current attribute values |
@@ -1487,61 +1487,61 @@ discard block |
||
| 1487 | 1487 | $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
| 1488 | 1488 | $this->get_model()->assume_values_already_prepared_by_model_object(true); |
| 1489 | 1489 | //does this model have an autoincrement PK? |
| 1490 | - if($this->get_model()->has_primary_key_field()){ |
|
| 1491 | - if($this->get_model()->get_primary_key_field()->is_auto_increment()){ |
|
| 1490 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1491 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
| 1492 | 1492 | //ok check if it's set, if so: update; if not, insert |
| 1493 | - if ( ! empty( $save_cols_n_values[self::_get_primary_key_name( get_class($this) )] ) ){ |
|
| 1494 | - $results = $this->get_model()->update_by_ID ( $save_cols_n_values, $this->ID() ); |
|
| 1493 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
| 1494 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1495 | 1495 | } else { |
| 1496 | - unset($save_cols_n_values[self::_get_primary_key_name( get_class( $this) )]); |
|
| 1497 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
| 1498 | - if($results){ |
|
| 1496 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
| 1497 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1498 | + if ($results) { |
|
| 1499 | 1499 | //if successful, set the primary key |
| 1500 | 1500 | //but don't use the normal SET method, because it will check if |
| 1501 | 1501 | //an item with the same ID exists in the mapper & db, then |
| 1502 | 1502 | //will find it in the db (because we just added it) and THAT object |
| 1503 | 1503 | //will get added to the mapper before we can add this one! |
| 1504 | 1504 | //but if we just avoid using the SET method, all that headache can be avoided |
| 1505 | - $pk_field_name =self::_get_primary_key_name( get_class($this)); |
|
| 1505 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
| 1506 | 1506 | $this->_fields[$pk_field_name] = $results; |
| 1507 | 1507 | $this->_clear_cached_property($pk_field_name); |
| 1508 | - $this->get_model()->add_to_entity_map( $this ); |
|
| 1508 | + $this->get_model()->add_to_entity_map($this); |
|
| 1509 | 1509 | $this->_update_cached_related_model_objs_fks(); |
| 1510 | 1510 | } |
| 1511 | 1511 | } |
| 1512 | - }else{//PK is NOT auto-increment |
|
| 1512 | + } else {//PK is NOT auto-increment |
|
| 1513 | 1513 | //so check if one like it already exists in the db |
| 1514 | - if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
|
| 1515 | - if( WP_DEBUG && ! $this->in_entity_map() ){ |
|
| 1514 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
| 1515 | + if (WP_DEBUG && ! $this->in_entity_map()) { |
|
| 1516 | 1516 | throw new EE_Error( |
| 1517 | 1517 | sprintf( |
| 1518 | - __( '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' ), |
|
| 1518 | + __('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'), |
|
| 1519 | 1519 | get_class($this), |
| 1520 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
| 1521 | - get_class( $this->get_model() ) . '::instance()->get_one_by_ID()', |
|
| 1520 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
| 1521 | + get_class($this->get_model()).'::instance()->get_one_by_ID()', |
|
| 1522 | 1522 | '<br />' |
| 1523 | 1523 | ) |
| 1524 | 1524 | ); |
| 1525 | 1525 | } |
| 1526 | 1526 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
| 1527 | - }else{ |
|
| 1527 | + } else { |
|
| 1528 | 1528 | $results = $this->get_model()->insert($save_cols_n_values); |
| 1529 | 1529 | $this->_update_cached_related_model_objs_fks(); |
| 1530 | 1530 | } |
| 1531 | 1531 | } |
| 1532 | - }else{//there is NO primary key |
|
| 1532 | + } else {//there is NO primary key |
|
| 1533 | 1533 | $already_in_db = false; |
| 1534 | - foreach($this->get_model()->unique_indexes() as $index){ |
|
| 1534 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
| 1535 | 1535 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
| 1536 | - if($this->get_model()->exists(array($uniqueness_where_params))){ |
|
| 1536 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
| 1537 | 1537 | $already_in_db = true; |
| 1538 | 1538 | } |
| 1539 | 1539 | } |
| 1540 | - if( $already_in_db ){ |
|
| 1541 | - $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
|
| 1542 | - $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
|
| 1543 | - }else{ |
|
| 1544 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
| 1540 | + if ($already_in_db) { |
|
| 1541 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
| 1542 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
| 1543 | + } else { |
|
| 1544 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1545 | 1545 | } |
| 1546 | 1546 | } |
| 1547 | 1547 | //restore the old assumption about values being prepared by the model object |
@@ -1554,7 +1554,7 @@ discard block |
||
| 1554 | 1554 | * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
| 1555 | 1555 | * the new ID (or 0 if an error occurred and it wasn't updated) |
| 1556 | 1556 | */ |
| 1557 | - do_action( 'AHEE__EE_Base_Class__save__end', $this, $results ); |
|
| 1557 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
| 1558 | 1558 | return $results; |
| 1559 | 1559 | } |
| 1560 | 1560 | |
@@ -1569,15 +1569,15 @@ discard block |
||
| 1569 | 1569 | * @return void |
| 1570 | 1570 | * @throws \EE_Error |
| 1571 | 1571 | */ |
| 1572 | - protected function _update_cached_related_model_objs_fks(){ |
|
| 1573 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ){ |
|
| 1574 | - if( $relation_obj instanceof EE_Has_Many_Relation ){ |
|
| 1575 | - foreach( $this->get_all_from_cache( $relation_name ) as $related_model_obj_in_cache) { |
|
| 1572 | + protected function _update_cached_related_model_objs_fks() { |
|
| 1573 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1574 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 1575 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
| 1576 | 1576 | $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
| 1577 | 1577 | $this->get_model()->get_this_model_name() |
| 1578 | 1578 | ); |
| 1579 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID() ); |
|
| 1580 | - if( $related_model_obj_in_cache->ID() ){ |
|
| 1579 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
| 1580 | + if ($related_model_obj_in_cache->ID()) { |
|
| 1581 | 1581 | $related_model_obj_in_cache->save(); |
| 1582 | 1582 | } |
| 1583 | 1583 | } |
@@ -1598,21 +1598,21 @@ discard block |
||
| 1598 | 1598 | * @return int ID of new model object on save; 0 on failure+ |
| 1599 | 1599 | * @throws \EE_Error |
| 1600 | 1600 | */ |
| 1601 | - public function save_new_cached_related_model_objs(){ |
|
| 1601 | + public function save_new_cached_related_model_objs() { |
|
| 1602 | 1602 | //make sure this has been saved |
| 1603 | - if( ! $this->ID()){ |
|
| 1603 | + if ( ! $this->ID()) { |
|
| 1604 | 1604 | $id = $this->save(); |
| 1605 | - }else{ |
|
| 1605 | + } else { |
|
| 1606 | 1606 | $id = $this->ID(); |
| 1607 | 1607 | } |
| 1608 | 1608 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
| 1609 | - foreach($this->get_model()->relation_settings() as $relationName => $relationObj){ |
|
| 1609 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
| 1610 | 1610 | |
| 1611 | 1611 | |
| 1612 | - if($this->_model_relations[$relationName]){ |
|
| 1612 | + if ($this->_model_relations[$relationName]) { |
|
| 1613 | 1613 | //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
| 1614 | 1614 | //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
| 1615 | - if($relationObj instanceof EE_Belongs_To_Relation){ |
|
| 1615 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
| 1616 | 1616 | //add a relation to that relation type (which saves the appropriate thing in the process) |
| 1617 | 1617 | //but ONLY if it DOES NOT exist in the DB |
| 1618 | 1618 | /* @var $related_model_obj EE_Base_Class */ |
@@ -1621,8 +1621,8 @@ discard block |
||
| 1621 | 1621 | $this->_add_relation_to($related_model_obj, $relationName); |
| 1622 | 1622 | $related_model_obj->save_new_cached_related_model_objs(); |
| 1623 | 1623 | // } |
| 1624 | - }else{ |
|
| 1625 | - foreach($this->_model_relations[$relationName] as $related_model_obj){ |
|
| 1624 | + } else { |
|
| 1625 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
| 1626 | 1626 | //add a relation to that relation type (which saves the appropriate thing in the process) |
| 1627 | 1627 | //but ONLY if it DOES NOT exist in the DB |
| 1628 | 1628 | // if( ! $related_model_obj->ID()){ |
@@ -1643,8 +1643,8 @@ discard block |
||
| 1643 | 1643 | * @return \EEM_Base | \EEM_CPT_Base |
| 1644 | 1644 | */ |
| 1645 | 1645 | public function get_model() { |
| 1646 | - $modelName = self::_get_model_classname( get_class($this) ); |
|
| 1647 | - return self::_get_model_instance_with_name($modelName, $this->_timezone ); |
|
| 1646 | + $modelName = self::_get_model_classname(get_class($this)); |
|
| 1647 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
| 1648 | 1648 | } |
| 1649 | 1649 | |
| 1650 | 1650 | |
@@ -1655,10 +1655,10 @@ discard block |
||
| 1655 | 1655 | * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
| 1656 | 1656 | * @throws \EE_Error |
| 1657 | 1657 | */ |
| 1658 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname){ |
|
| 1658 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) { |
|
| 1659 | 1659 | //TODO: will not work for Term_Relationships because they have no PK! |
| 1660 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
| 1661 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
| 1660 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1661 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1662 | 1662 | $id = $props_n_values[$primary_id_ref]; |
| 1663 | 1663 | return self::_get_model($classname)->get_from_entity_map($id); |
| 1664 | 1664 | } |
@@ -1679,37 +1679,37 @@ discard block |
||
| 1679 | 1679 | * @return mixed (EE_Base_Class|bool) |
| 1680 | 1680 | * @throws \EE_Error |
| 1681 | 1681 | */ |
| 1682 | - protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL, $date_formats = array() ) { |
|
| 1682 | + protected static function _check_for_object($props_n_values, $classname, $timezone = NULL, $date_formats = array()) { |
|
| 1683 | 1683 | $existing = null; |
| 1684 | - if ( self::_get_model( $classname )->has_primary_key_field() ) { |
|
| 1685 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
| 1686 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) |
|
| 1687 | - && ! empty( $props_n_values[ $primary_id_ref ] ) |
|
| 1684 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
| 1685 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1686 | + if (array_key_exists($primary_id_ref, $props_n_values) |
|
| 1687 | + && ! empty($props_n_values[$primary_id_ref]) |
|
| 1688 | 1688 | ) { |
| 1689 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( |
|
| 1690 | - $props_n_values[ $primary_id_ref ] |
|
| 1689 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1690 | + $props_n_values[$primary_id_ref] |
|
| 1691 | 1691 | ); |
| 1692 | 1692 | } |
| 1693 | - } elseif ( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ) { |
|
| 1693 | + } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
| 1694 | 1694 | //no primary key on this model, but there's still a matching item in the DB |
| 1695 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( |
|
| 1696 | - self::_get_model( $classname, $timezone )->get_index_primary_key_string( $props_n_values ) |
|
| 1695 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1696 | + self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
| 1697 | 1697 | ); |
| 1698 | 1698 | } |
| 1699 | - if ( $existing ) { |
|
| 1699 | + if ($existing) { |
|
| 1700 | 1700 | |
| 1701 | 1701 | //set date formats if present before setting values |
| 1702 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
| 1703 | - $existing->set_date_format( $date_formats[0] ); |
|
| 1704 | - $existing->set_time_format( $date_formats[1] ); |
|
| 1702 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 1703 | + $existing->set_date_format($date_formats[0]); |
|
| 1704 | + $existing->set_time_format($date_formats[1]); |
|
| 1705 | 1705 | } else { |
| 1706 | 1706 | //set default formats for date and time |
| 1707 | - $existing->set_date_format( get_option( 'date_format' ) ); |
|
| 1708 | - $existing->set_time_format( get_option( 'time_format' ) ); |
|
| 1707 | + $existing->set_date_format(get_option('date_format')); |
|
| 1708 | + $existing->set_time_format(get_option('time_format')); |
|
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | - foreach ( $props_n_values as $property => $field_value ) { |
|
| 1712 | - $existing->set( $property, $field_value ); |
|
| 1711 | + foreach ($props_n_values as $property => $field_value) { |
|
| 1712 | + $existing->set($property, $field_value); |
|
| 1713 | 1713 | } |
| 1714 | 1714 | return $existing; |
| 1715 | 1715 | } else { |
@@ -1727,9 +1727,9 @@ discard block |
||
| 1727 | 1727 | * @throws EE_Error |
| 1728 | 1728 | * @return EEM_Base |
| 1729 | 1729 | */ |
| 1730 | - protected static function _get_model( $classname, $timezone = NULL ){ |
|
| 1730 | + protected static function _get_model($classname, $timezone = NULL) { |
|
| 1731 | 1731 | //find model for this class |
| 1732 | - if( ! $classname ){ |
|
| 1732 | + if ( ! $classname) { |
|
| 1733 | 1733 | throw new EE_Error( |
| 1734 | 1734 | sprintf( |
| 1735 | 1735 | __( |
@@ -1740,8 +1740,8 @@ discard block |
||
| 1740 | 1740 | ) |
| 1741 | 1741 | ); |
| 1742 | 1742 | } |
| 1743 | - $modelName=self::_get_model_classname($classname); |
|
| 1744 | - return self::_get_model_instance_with_name($modelName, $timezone ); |
|
| 1743 | + $modelName = self::_get_model_classname($classname); |
|
| 1744 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | 1747 | |
@@ -1752,10 +1752,10 @@ discard block |
||
| 1752 | 1752 | * @param null $timezone |
| 1753 | 1753 | * @return EEM_Base |
| 1754 | 1754 | */ |
| 1755 | - protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
|
| 1756 | - $model_classname = str_replace( 'EEM_', '', $model_classname ); |
|
| 1757 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
| 1758 | - $model->set_timezone( $timezone ); |
|
| 1755 | + protected static function _get_model_instance_with_name($model_classname, $timezone = NULL) { |
|
| 1756 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
| 1757 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
| 1758 | + $model->set_timezone($timezone); |
|
| 1759 | 1759 | return $model; |
| 1760 | 1760 | } |
| 1761 | 1761 | |
@@ -1767,10 +1767,10 @@ discard block |
||
| 1767 | 1767 | * @param null $model_name |
| 1768 | 1768 | * @return string like EEM_Attendee |
| 1769 | 1769 | */ |
| 1770 | - private static function _get_model_classname( $model_name = null){ |
|
| 1771 | - if(strpos($model_name,"EE_")===0){ |
|
| 1772 | - $model_classname=str_replace("EE_","EEM_",$model_name); |
|
| 1773 | - }else{ |
|
| 1770 | + private static function _get_model_classname($model_name = null) { |
|
| 1771 | + if (strpos($model_name, "EE_") === 0) { |
|
| 1772 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
| 1773 | + } else { |
|
| 1774 | 1774 | $model_classname = "EEM_".$model_name; |
| 1775 | 1775 | } |
| 1776 | 1776 | return $model_classname; |
@@ -1784,16 +1784,16 @@ discard block |
||
| 1784 | 1784 | * @throws EE_Error |
| 1785 | 1785 | * @return string |
| 1786 | 1786 | */ |
| 1787 | - protected static function _get_primary_key_name( $classname = NULL ){ |
|
| 1788 | - if( ! $classname){ |
|
| 1787 | + protected static function _get_primary_key_name($classname = NULL) { |
|
| 1788 | + if ( ! $classname) { |
|
| 1789 | 1789 | throw new EE_Error( |
| 1790 | 1790 | sprintf( |
| 1791 | - __( "What were you thinking calling _get_primary_key_name(%s)", "event_espresso" ), |
|
| 1791 | + __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
| 1792 | 1792 | $classname |
| 1793 | 1793 | ) |
| 1794 | 1794 | ); |
| 1795 | 1795 | } |
| 1796 | - return self::_get_model( $classname )->get_primary_key_field()->get_name(); |
|
| 1796 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
| 1797 | 1797 | } |
| 1798 | 1798 | |
| 1799 | 1799 | |
@@ -1807,12 +1807,12 @@ discard block |
||
| 1807 | 1807 | * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
| 1808 | 1808 | * @throws \EE_Error |
| 1809 | 1809 | */ |
| 1810 | - public function ID(){ |
|
| 1810 | + public function ID() { |
|
| 1811 | 1811 | //now that we know the name of the variable, use a variable variable to get its value and return its |
| 1812 | - if( $this->get_model()->has_primary_key_field() ) { |
|
| 1813 | - return $this->_fields[ self::_get_primary_key_name( get_class($this) ) ]; |
|
| 1814 | - }else{ |
|
| 1815 | - return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
|
| 1812 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1813 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
| 1814 | + } else { |
|
| 1815 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
| 1816 | 1816 | } |
| 1817 | 1817 | } |
| 1818 | 1818 | |
@@ -1830,38 +1830,38 @@ discard block |
||
| 1830 | 1830 | * @throws EE_Error |
| 1831 | 1831 | * @return EE_Base_Class the object the relation was added to |
| 1832 | 1832 | */ |
| 1833 | - public function _add_relation_to( $otherObjectModelObjectOrID,$relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL ){ |
|
| 1833 | + public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL) { |
|
| 1834 | 1834 | //if this thing exists in the DB, save the relation to the DB |
| 1835 | - if( $this->ID() ){ |
|
| 1836 | - $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
|
| 1835 | + if ($this->ID()) { |
|
| 1836 | + $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values); |
|
| 1837 | 1837 | //clear cache so future get_many_related and get_first_related() return new results. |
| 1838 | - $this->clear_cache( $relationName, $otherObject, TRUE ); |
|
| 1839 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1840 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1838 | + $this->clear_cache($relationName, $otherObject, TRUE); |
|
| 1839 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1840 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1841 | 1841 | } |
| 1842 | 1842 | } else { |
| 1843 | 1843 | //this thing doesn't exist in the DB, so just cache it |
| 1844 | - if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
|
| 1845 | - throw new EE_Error( sprintf( |
|
| 1846 | - __( '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' ), |
|
| 1844 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
| 1845 | + throw new EE_Error(sprintf( |
|
| 1846 | + __('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'), |
|
| 1847 | 1847 | $otherObjectModelObjectOrID, |
| 1848 | - get_class( $this ) |
|
| 1848 | + get_class($this) |
|
| 1849 | 1849 | )); |
| 1850 | 1850 | } else { |
| 1851 | 1851 | $otherObject = $otherObjectModelObjectOrID; |
| 1852 | 1852 | } |
| 1853 | - $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
|
| 1853 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
| 1854 | 1854 | } |
| 1855 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1855 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1856 | 1856 | //fix the reciprocal relation too |
| 1857 | - if( $otherObject->ID() ) { |
|
| 1857 | + if ($otherObject->ID()) { |
|
| 1858 | 1858 | //its saved so assumed relations exist in the DB, so we can just |
| 1859 | 1859 | //clear the cache so future queries use the updated info in the DB |
| 1860 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
| 1860 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
| 1861 | 1861 | } else { |
| 1862 | 1862 | |
| 1863 | 1863 | //it's not saved, so it caches relations like this |
| 1864 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1864 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
| 1865 | 1865 | } |
| 1866 | 1866 | } |
| 1867 | 1867 | return $otherObject; |
@@ -1885,17 +1885,17 @@ discard block |
||
| 1885 | 1885 | * @return EE_Base_Class the relation was removed from |
| 1886 | 1886 | * @throws \EE_Error |
| 1887 | 1887 | */ |
| 1888 | - public function _remove_relation_to($otherObjectModelObjectOrID,$relationName, $where_query = array() ){ |
|
| 1889 | - if ( $this->ID() ) { |
|
| 1888 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) { |
|
| 1889 | + if ($this->ID()) { |
|
| 1890 | 1890 | //if this exists in the DB, save the relation change to the DB too |
| 1891 | - $otherObject = $this->get_model()->remove_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
|
| 1892 | - $this->clear_cache( $relationName, $otherObject ); |
|
| 1891 | + $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
| 1892 | + $this->clear_cache($relationName, $otherObject); |
|
| 1893 | 1893 | } else { |
| 1894 | 1894 | //this doesn't exist in the DB, just remove it from the cache |
| 1895 | - $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
|
| 1895 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
| 1896 | 1896 | } |
| 1897 | - if( $otherObject instanceof EE_Base_Class ) { |
|
| 1898 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1897 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1898 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1899 | 1899 | } |
| 1900 | 1900 | return $otherObject; |
| 1901 | 1901 | } |
@@ -1910,18 +1910,18 @@ discard block |
||
| 1910 | 1910 | * @return EE_Base_Class |
| 1911 | 1911 | * @throws \EE_Error |
| 1912 | 1912 | */ |
| 1913 | - public function _remove_relations($relationName,$where_query_params = array()){ |
|
| 1914 | - if ( $this->ID() ) { |
|
| 1913 | + public function _remove_relations($relationName, $where_query_params = array()) { |
|
| 1914 | + if ($this->ID()) { |
|
| 1915 | 1915 | //if this exists in the DB, save the relation change to the DB too |
| 1916 | - $otherObjects = $this->get_model()->remove_relations( $this, $relationName, $where_query_params ); |
|
| 1917 | - $this->clear_cache( $relationName, null, true ); |
|
| 1916 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
| 1917 | + $this->clear_cache($relationName, null, true); |
|
| 1918 | 1918 | } else { |
| 1919 | 1919 | //this doesn't exist in the DB, just remove it from the cache |
| 1920 | - $otherObjects = $this->clear_cache( $relationName, null, true ); |
|
| 1920 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
| 1921 | 1921 | } |
| 1922 | - if( is_array( $otherObjects ) ) { |
|
| 1923 | - foreach ( $otherObjects as $otherObject ) { |
|
| 1924 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
| 1922 | + if (is_array($otherObjects)) { |
|
| 1923 | + foreach ($otherObjects as $otherObject) { |
|
| 1924 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1925 | 1925 | } |
| 1926 | 1926 | } |
| 1927 | 1927 | return $otherObjects; |
@@ -1941,27 +1941,27 @@ discard block |
||
| 1941 | 1941 | * @throws \EE_Error |
| 1942 | 1942 | * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs |
| 1943 | 1943 | */ |
| 1944 | - public function get_many_related($relationName,$query_params = array()){ |
|
| 1945 | - if($this->ID()){ |
|
| 1944 | + public function get_many_related($relationName, $query_params = array()) { |
|
| 1945 | + if ($this->ID()) { |
|
| 1946 | 1946 | //this exists in the DB, so get the related things from either the cache or the DB |
| 1947 | 1947 | //if there are query parameters, forget about caching the related model objects. |
| 1948 | - if( $query_params ){ |
|
| 1948 | + if ($query_params) { |
|
| 1949 | 1949 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
| 1950 | - }else{ |
|
| 1950 | + } else { |
|
| 1951 | 1951 | //did we already cache the result of this query? |
| 1952 | 1952 | $cached_results = $this->get_all_from_cache($relationName); |
| 1953 | - if ( ! $cached_results ){ |
|
| 1953 | + if ( ! $cached_results) { |
|
| 1954 | 1954 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
| 1955 | 1955 | //if no query parameters were passed, then we got all the related model objects |
| 1956 | 1956 | //for that relation. We can cache them then. |
| 1957 | - foreach($related_model_objects as $related_model_object){ |
|
| 1957 | + foreach ($related_model_objects as $related_model_object) { |
|
| 1958 | 1958 | $this->cache($relationName, $related_model_object); |
| 1959 | 1959 | } |
| 1960 | - }else{ |
|
| 1960 | + } else { |
|
| 1961 | 1961 | $related_model_objects = $cached_results; |
| 1962 | 1962 | } |
| 1963 | 1963 | } |
| 1964 | - }else{ |
|
| 1964 | + } else { |
|
| 1965 | 1965 | //this doesn't exist in the DB, so just get the related things from the cache |
| 1966 | 1966 | $related_model_objects = $this->get_all_from_cache($relationName); |
| 1967 | 1967 | } |
@@ -1979,8 +1979,8 @@ discard block |
||
| 1979 | 1979 | * @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; |
| 1980 | 1980 | * @return int |
| 1981 | 1981 | */ |
| 1982 | - public function count_related($relation_name, $query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
| 1983 | - return $this->get_model()->count_related($this,$relation_name,$query_params,$field_to_count,$distinct); |
|
| 1982 | + public function count_related($relation_name, $query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
| 1983 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
| 1984 | 1984 | } |
| 1985 | 1985 | |
| 1986 | 1986 | |
@@ -1994,7 +1994,7 @@ discard block |
||
| 1994 | 1994 | * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
| 1995 | 1995 | * @return int |
| 1996 | 1996 | */ |
| 1997 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null){ |
|
| 1997 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) { |
|
| 1998 | 1998 | return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
| 1999 | 1999 | } |
| 2000 | 2000 | |
@@ -2008,33 +2008,33 @@ discard block |
||
| 2008 | 2008 | * @return EE_Base_Class (not an array, a single object) |
| 2009 | 2009 | * @throws \EE_Error |
| 2010 | 2010 | */ |
| 2011 | - public function get_first_related($relationName,$query_params = array()){ |
|
| 2012 | - if($this->ID()){//this exists in the DB, get from the cache OR the DB |
|
| 2011 | + public function get_first_related($relationName, $query_params = array()) { |
|
| 2012 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
| 2013 | 2013 | |
| 2014 | 2014 | //if they've provided some query parameters, don't bother trying to cache the result |
| 2015 | 2015 | //also make sure we're not caching the result of get_first_related |
| 2016 | 2016 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
| 2017 | - if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
| 2018 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2019 | - }else{ |
|
| 2017 | + if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2018 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2019 | + } else { |
|
| 2020 | 2020 | //first, check if we've already cached the result of this query |
| 2021 | 2021 | $cached_result = $this->get_one_from_cache($relationName); |
| 2022 | - if ( ! $cached_result ){ |
|
| 2022 | + if ( ! $cached_result) { |
|
| 2023 | 2023 | |
| 2024 | 2024 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
| 2025 | - $this->cache($relationName,$related_model_object); |
|
| 2026 | - }else{ |
|
| 2025 | + $this->cache($relationName, $related_model_object); |
|
| 2026 | + } else { |
|
| 2027 | 2027 | $related_model_object = $cached_result; |
| 2028 | 2028 | } |
| 2029 | 2029 | } |
| 2030 | - }else{ |
|
| 2030 | + } else { |
|
| 2031 | 2031 | $related_model_object = null; |
| 2032 | 2032 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
| 2033 | - if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
| 2034 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2033 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2034 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2035 | 2035 | } |
| 2036 | 2036 | //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 |
| 2037 | - if( ! $related_model_object){ |
|
| 2037 | + if ( ! $related_model_object) { |
|
| 2038 | 2038 | $related_model_object = $this->get_one_from_cache($relationName); |
| 2039 | 2039 | } |
| 2040 | 2040 | |
@@ -2056,12 +2056,12 @@ discard block |
||
| 2056 | 2056 | * @return int how many deleted |
| 2057 | 2057 | * @throws \EE_Error |
| 2058 | 2058 | */ |
| 2059 | - public function delete_related($relationName,$query_params = array()){ |
|
| 2060 | - if($this->ID()){ |
|
| 2061 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2062 | - }else{ |
|
| 2059 | + public function delete_related($relationName, $query_params = array()) { |
|
| 2060 | + if ($this->ID()) { |
|
| 2061 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2062 | + } else { |
|
| 2063 | 2063 | $count = count($this->get_all_from_cache($relationName)); |
| 2064 | - $this->clear_cache($relationName,NULL,TRUE); |
|
| 2064 | + $this->clear_cache($relationName, NULL, TRUE); |
|
| 2065 | 2065 | } |
| 2066 | 2066 | return $count; |
| 2067 | 2067 | } |
@@ -2080,13 +2080,13 @@ discard block |
||
| 2080 | 2080 | * @return int how many deleted (including those soft deleted) |
| 2081 | 2081 | * @throws \EE_Error |
| 2082 | 2082 | */ |
| 2083 | - public function delete_related_permanently($relationName,$query_params = array()){ |
|
| 2084 | - if($this->ID()){ |
|
| 2085 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2086 | - }else{ |
|
| 2083 | + public function delete_related_permanently($relationName, $query_params = array()) { |
|
| 2084 | + if ($this->ID()) { |
|
| 2085 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2086 | + } else { |
|
| 2087 | 2087 | $count = count($this->get_all_from_cache($relationName)); |
| 2088 | 2088 | } |
| 2089 | - $this->clear_cache($relationName,NULL,TRUE); |
|
| 2089 | + $this->clear_cache($relationName, NULL, TRUE); |
|
| 2090 | 2090 | return $count; |
| 2091 | 2091 | } |
| 2092 | 2092 | |
@@ -2102,7 +2102,7 @@ discard block |
||
| 2102 | 2102 | * @param string $field_name property to check |
| 2103 | 2103 | * @return bool TRUE if existing,FALSE if not. |
| 2104 | 2104 | */ |
| 2105 | - public function is_set( $field_name ) { |
|
| 2105 | + public function is_set($field_name) { |
|
| 2106 | 2106 | return isset($this->_fields[$field_name]); |
| 2107 | 2107 | } |
| 2108 | 2108 | |
@@ -2114,11 +2114,11 @@ discard block |
||
| 2114 | 2114 | * @throws EE_Error |
| 2115 | 2115 | * @return bool TRUE if existing, throw EE_Error if not. |
| 2116 | 2116 | */ |
| 2117 | - protected function _property_exists( $properties ) { |
|
| 2117 | + protected function _property_exists($properties) { |
|
| 2118 | 2118 | |
| 2119 | - foreach ( (array) $properties as $property_name ) { |
|
| 2119 | + foreach ((array) $properties as $property_name) { |
|
| 2120 | 2120 | //first make sure this property exists |
| 2121 | - if ( ! $this->_fields[ $property_name ] ) { |
|
| 2121 | + if ( ! $this->_fields[$property_name]) { |
|
| 2122 | 2122 | throw new EE_Error( |
| 2123 | 2123 | sprintf( |
| 2124 | 2124 | __( |
@@ -2146,7 +2146,7 @@ discard block |
||
| 2146 | 2146 | $fields = $this->get_model()->field_settings(FALSE); |
| 2147 | 2147 | $properties = array(); |
| 2148 | 2148 | //remove prepended underscore |
| 2149 | - foreach ( $fields as $field_name => $settings ) { |
|
| 2149 | + foreach ($fields as $field_name => $settings) { |
|
| 2150 | 2150 | $properties[$field_name] = $this->get($field_name); |
| 2151 | 2151 | } |
| 2152 | 2152 | return $properties; |
@@ -2176,10 +2176,10 @@ discard block |
||
| 2176 | 2176 | * @throws EE_Error |
| 2177 | 2177 | * @return mixed whatever the plugin which calls add_filter decides |
| 2178 | 2178 | */ |
| 2179 | - public function __call($methodName,$args){ |
|
| 2180 | - $className=get_class($this); |
|
| 2181 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
| 2182 | - if ( ! has_filter( $tagName ) ) { |
|
| 2179 | + public function __call($methodName, $args) { |
|
| 2180 | + $className = get_class($this); |
|
| 2181 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
| 2182 | + if ( ! has_filter($tagName)) { |
|
| 2183 | 2183 | throw new EE_Error( |
| 2184 | 2184 | sprintf( |
| 2185 | 2185 | __( |
@@ -2192,7 +2192,7 @@ discard block |
||
| 2192 | 2192 | ) |
| 2193 | 2193 | ); |
| 2194 | 2194 | } |
| 2195 | - return apply_filters($tagName,null,$this,$args); |
|
| 2195 | + return apply_filters($tagName, null, $this, $args); |
|
| 2196 | 2196 | } |
| 2197 | 2197 | |
| 2198 | 2198 | |
@@ -2208,7 +2208,7 @@ discard block |
||
| 2208 | 2208 | * @throws \EE_Error |
| 2209 | 2209 | * NOTE: if the values haven't changed, returns 0 |
| 2210 | 2210 | */ |
| 2211 | - public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL){ |
|
| 2211 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL) { |
|
| 2212 | 2212 | $query_params = array( |
| 2213 | 2213 | array( |
| 2214 | 2214 | 'EXM_key' => $meta_key, |
@@ -2216,17 +2216,17 @@ discard block |
||
| 2216 | 2216 | 'EXM_type' => $this->get_model()->get_this_model_name() |
| 2217 | 2217 | ) |
| 2218 | 2218 | ); |
| 2219 | - if ( $previous_value !== null ) { |
|
| 2219 | + if ($previous_value !== null) { |
|
| 2220 | 2220 | $query_params[0]['EXM_value'] = $meta_value; |
| 2221 | 2221 | } |
| 2222 | - $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all( $query_params ); |
|
| 2223 | - if ( ! $existing_rows_like_that ) { |
|
| 2224 | - return $this->add_extra_meta( $meta_key, $meta_value ); |
|
| 2222 | + $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
| 2223 | + if ( ! $existing_rows_like_that) { |
|
| 2224 | + return $this->add_extra_meta($meta_key, $meta_value); |
|
| 2225 | 2225 | } else { |
| 2226 | - foreach ( $existing_rows_like_that as $existing_row ) { |
|
| 2227 | - $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
|
| 2226 | + foreach ($existing_rows_like_that as $existing_row) { |
|
| 2227 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
| 2228 | 2228 | } |
| 2229 | - return count( $existing_rows_like_that ); |
|
| 2229 | + return count($existing_rows_like_that); |
|
| 2230 | 2230 | } |
| 2231 | 2231 | } |
| 2232 | 2232 | |
@@ -2243,8 +2243,8 @@ discard block |
||
| 2243 | 2243 | * @return boolean |
| 2244 | 2244 | * @throws \EE_Error |
| 2245 | 2245 | */ |
| 2246 | - public function add_extra_meta($meta_key,$meta_value,$unique = false){ |
|
| 2247 | - if ( $unique ) { |
|
| 2246 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) { |
|
| 2247 | + if ($unique) { |
|
| 2248 | 2248 | $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
| 2249 | 2249 | array( |
| 2250 | 2250 | array( |
@@ -2254,7 +2254,7 @@ discard block |
||
| 2254 | 2254 | ) |
| 2255 | 2255 | ) |
| 2256 | 2256 | ); |
| 2257 | - if ( $existing_extra_meta ) { |
|
| 2257 | + if ($existing_extra_meta) { |
|
| 2258 | 2258 | return false; |
| 2259 | 2259 | } |
| 2260 | 2260 | } |
@@ -2281,7 +2281,7 @@ discard block |
||
| 2281 | 2281 | * @return int number of extra meta rows deleted |
| 2282 | 2282 | * @throws \EE_Error |
| 2283 | 2283 | */ |
| 2284 | - public function delete_extra_meta($meta_key,$meta_value = NULL){ |
|
| 2284 | + public function delete_extra_meta($meta_key, $meta_value = NULL) { |
|
| 2285 | 2285 | $query_params = array( |
| 2286 | 2286 | array( |
| 2287 | 2287 | 'EXM_key' => $meta_key, |
@@ -2289,10 +2289,10 @@ discard block |
||
| 2289 | 2289 | 'EXM_type' => $this->get_model()->get_this_model_name() |
| 2290 | 2290 | ) |
| 2291 | 2291 | ); |
| 2292 | - if ( $meta_value !== null ) { |
|
| 2292 | + if ($meta_value !== null) { |
|
| 2293 | 2293 | $query_params[0]['EXM_value'] = $meta_value; |
| 2294 | 2294 | } |
| 2295 | - return EEM_Extra_Meta::instance()->delete( $query_params ); |
|
| 2295 | + return EEM_Extra_Meta::instance()->delete($query_params); |
|
| 2296 | 2296 | } |
| 2297 | 2297 | |
| 2298 | 2298 | |
@@ -2308,25 +2308,25 @@ discard block |
||
| 2308 | 2308 | * @return mixed single value if $single; array if ! $single |
| 2309 | 2309 | * @throws \EE_Error |
| 2310 | 2310 | */ |
| 2311 | - public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){ |
|
| 2312 | - if($single){ |
|
| 2313 | - $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
| 2314 | - if ( $result instanceof EE_Extra_Meta ){ |
|
| 2311 | + public function get_extra_meta($meta_key, $single = FALSE, $default = NULL) { |
|
| 2312 | + if ($single) { |
|
| 2313 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
| 2314 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2315 | 2315 | return $result->value(); |
| 2316 | - }else{ |
|
| 2316 | + } else { |
|
| 2317 | 2317 | return $default; |
| 2318 | 2318 | } |
| 2319 | - }else{ |
|
| 2320 | - $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
| 2321 | - if($results){ |
|
| 2319 | + } else { |
|
| 2320 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
| 2321 | + if ($results) { |
|
| 2322 | 2322 | $values = array(); |
| 2323 | - foreach($results as $result){ |
|
| 2324 | - if ( $result instanceof EE_Extra_Meta ){ |
|
| 2323 | + foreach ($results as $result) { |
|
| 2324 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2325 | 2325 | $values[$result->ID()] = $result->value(); |
| 2326 | 2326 | } |
| 2327 | 2327 | } |
| 2328 | 2328 | return $values; |
| 2329 | - }else{ |
|
| 2329 | + } else { |
|
| 2330 | 2330 | return $default; |
| 2331 | 2331 | } |
| 2332 | 2332 | } |
@@ -2348,20 +2348,20 @@ discard block |
||
| 2348 | 2348 | * @return array |
| 2349 | 2349 | * @throws \EE_Error |
| 2350 | 2350 | */ |
| 2351 | - public function all_extra_meta_array($one_of_each_key = true){ |
|
| 2351 | + public function all_extra_meta_array($one_of_each_key = true) { |
|
| 2352 | 2352 | $return_array = array(); |
| 2353 | - if($one_of_each_key){ |
|
| 2353 | + if ($one_of_each_key) { |
|
| 2354 | 2354 | $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by'=>'EXM_key')); |
| 2355 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
| 2356 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
| 2355 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2356 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2357 | 2357 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
| 2358 | 2358 | } |
| 2359 | 2359 | } |
| 2360 | - }else{ |
|
| 2360 | + } else { |
|
| 2361 | 2361 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
| 2362 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
| 2363 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
| 2364 | - if( ! isset($return_array[$extra_meta_obj->key()])){ |
|
| 2362 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2363 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2364 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
| 2365 | 2365 | $return_array[$extra_meta_obj->key()] = array(); |
| 2366 | 2366 | } |
| 2367 | 2367 | $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
@@ -2379,19 +2379,19 @@ discard block |
||
| 2379 | 2379 | * @return string |
| 2380 | 2380 | * @throws \EE_Error |
| 2381 | 2381 | */ |
| 2382 | - public function name(){ |
|
| 2382 | + public function name() { |
|
| 2383 | 2383 | //find a field that's not a text field |
| 2384 | 2384 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
| 2385 | - if($field_we_can_use){ |
|
| 2385 | + if ($field_we_can_use) { |
|
| 2386 | 2386 | return $this->get($field_we_can_use->get_name()); |
| 2387 | - }else{ |
|
| 2387 | + } else { |
|
| 2388 | 2388 | $first_few_properties = $this->model_field_array(); |
| 2389 | - $first_few_properties = array_slice($first_few_properties,0,3); |
|
| 2389 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
| 2390 | 2390 | $name_parts = array(); |
| 2391 | - foreach( $first_few_properties as $name=> $value ){ |
|
| 2391 | + foreach ($first_few_properties as $name=> $value) { |
|
| 2392 | 2392 | $name_parts[] = "$name:$value"; |
| 2393 | 2393 | } |
| 2394 | - return implode(",",$name_parts); |
|
| 2394 | + return implode(",", $name_parts); |
|
| 2395 | 2395 | } |
| 2396 | 2396 | } |
| 2397 | 2397 | |
@@ -2404,11 +2404,11 @@ discard block |
||
| 2404 | 2404 | * @return boolean |
| 2405 | 2405 | * @throws \EE_Error |
| 2406 | 2406 | */ |
| 2407 | - public function in_entity_map(){ |
|
| 2408 | - if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
|
| 2407 | + public function in_entity_map() { |
|
| 2408 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
| 2409 | 2409 | //well, if we looked, did we find it in the entity map? |
| 2410 | 2410 | return TRUE; |
| 2411 | - }else{ |
|
| 2411 | + } else { |
|
| 2412 | 2412 | return FALSE; |
| 2413 | 2413 | } |
| 2414 | 2414 | } |
@@ -2419,21 +2419,21 @@ discard block |
||
| 2419 | 2419 | * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
| 2420 | 2420 | * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
| 2421 | 2421 | */ |
| 2422 | - public function refresh_from_db(){ |
|
| 2423 | - if( $this->ID() && $this->in_entity_map() ){ |
|
| 2424 | - $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
|
| 2425 | - }else{ |
|
| 2422 | + public function refresh_from_db() { |
|
| 2423 | + if ($this->ID() && $this->in_entity_map()) { |
|
| 2424 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
| 2425 | + } else { |
|
| 2426 | 2426 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
| 2427 | 2427 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
| 2428 | 2428 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
| 2429 | 2429 | //absolutely nothing in it for this ID |
| 2430 | - if( WP_DEBUG ) { |
|
| 2430 | + if (WP_DEBUG) { |
|
| 2431 | 2431 | throw new EE_Error( |
| 2432 | 2432 | sprintf( |
| 2433 | - __( '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' ), |
|
| 2433 | + __('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'), |
|
| 2434 | 2434 | $this->ID(), |
| 2435 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
| 2436 | - get_class( $this->get_model() ) . '::instance()->refresh_entity_map()' |
|
| 2435 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
| 2436 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
| 2437 | 2437 | ) |
| 2438 | 2438 | ); |
| 2439 | 2439 | } |
@@ -2447,11 +2447,11 @@ discard block |
||
| 2447 | 2447 | * (probably a bad assumption they have made, oh well) |
| 2448 | 2448 | * @return string |
| 2449 | 2449 | */ |
| 2450 | - public function __toString(){ |
|
| 2450 | + public function __toString() { |
|
| 2451 | 2451 | try { |
| 2452 | - return sprintf( '%s (%s)', $this->name(), $this->ID() ); |
|
| 2453 | - } catch ( Exception $e ) { |
|
| 2454 | - EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 2452 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
| 2453 | + } catch (Exception $e) { |
|
| 2454 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2455 | 2455 | return ''; |
| 2456 | 2456 | } |
| 2457 | 2457 | } |
@@ -2487,16 +2487,16 @@ discard block |
||
| 2487 | 2487 | * @throws \EE_Error |
| 2488 | 2488 | */ |
| 2489 | 2489 | public function __sleep() { |
| 2490 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
| 2491 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
| 2492 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
| 2493 | - if( $this->get_one_from_cache( $relation_name ) instanceof $classname && |
|
| 2494 | - $this->get_one_from_cache( $relation_name )->ID() ) { |
|
| 2495 | - $this->clear_cache( $relation_name, $this->get_one_from_cache( $relation_name )->ID() ); |
|
| 2490 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 2491 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 2492 | + $classname = 'EE_'.$this->get_model()->get_this_model_name(); |
|
| 2493 | + if ($this->get_one_from_cache($relation_name) instanceof $classname && |
|
| 2494 | + $this->get_one_from_cache($relation_name)->ID()) { |
|
| 2495 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
| 2496 | 2496 | } |
| 2497 | 2497 | } |
| 2498 | 2498 | } |
| 2499 | - return array_keys( get_object_vars( $this ) ); |
|
| 2499 | + return array_keys(get_object_vars($this)); |
|
| 2500 | 2500 | } |
| 2501 | 2501 | |
| 2502 | 2502 | |