@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Meant to add the new ee_message table to the database. |
|
| 4 | - */ |
|
| 3 | + * Meant to add the new ee_message table to the database. |
|
| 4 | + */ |
|
| 5 | 5 | //make sure we have all the stages loaded too |
| 6 | 6 | //unfortunately, this needs to be done upon INCLUSION of this file, |
| 7 | 7 | //instead of construction, because it only gets constructed on first page load |
@@ -8,13 +8,13 @@ discard block |
||
| 8 | 8 | //(all other times it gets resurrected from a wordpress option) |
| 9 | 9 | $stages = glob(EE_CORE.'data_migration_scripts/4_9_0_stages/*'); |
| 10 | 10 | $class_to_filepath = array(); |
| 11 | -foreach($stages as $filepath){ |
|
| 11 | +foreach ($stages as $filepath) { |
|
| 12 | 12 | $matches = array(); |
| 13 | - preg_match('~4_9_0_stages/(.*).dmsstage.php~',$filepath,$matches); |
|
| 13 | + preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 14 | 14 | $class_to_filepath[$matches[1]] = $filepath; |
| 15 | 15 | } |
| 16 | 16 | //give addons a chance to autoload their stages too |
| 17 | -$class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages',$class_to_filepath); |
|
| 17 | +$class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath); |
|
| 18 | 18 | EEH_Autoloader::register_autoloader($class_to_filepath); |
| 19 | 19 | |
| 20 | 20 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @since 4.6.0 |
| 31 | 31 | * |
| 32 | 32 | */ |
| 33 | -class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base{ |
|
| 33 | +class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base { |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * return EE_DMS_Core_4_9_0 |
@@ -54,14 +54,14 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function can_migrate_from_version($version_array) { |
| 56 | 56 | $version_string = $version_array['Core']; |
| 57 | - if( $version_string <= '4.9.0' && $version_string >= '4.8.0' ){ |
|
| 57 | + if ($version_string <= '4.9.0' && $version_string >= '4.8.0') { |
|
| 58 | 58 | // echo "$version_string can be migrated from"; |
| 59 | 59 | return true; |
| 60 | - } elseif( ! $version_string ){ |
|
| 60 | + } elseif ( ! $version_string) { |
|
| 61 | 61 | // echo "no version string provided: $version_string"; |
| 62 | 62 | //no version string provided... this must be pre 4.3 |
| 63 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
| 64 | - }else{ |
|
| 63 | + return false; //changed mind. dont want people thinking they should migrate yet because they cant |
|
| 64 | + } else { |
|
| 65 | 65 | // echo "$version_string doesnt apply"; |
| 66 | 66 | return false; |
| 67 | 67 | } |
@@ -82,18 +82,18 @@ discard block |
||
| 82 | 82 | * @return bool |
| 83 | 83 | */ |
| 84 | 84 | public function schema_changes_before_migration() { |
| 85 | - require_once( EE_HELPERS . 'EEH_Activation.helper.php' ); |
|
| 86 | - $now_in_mysql = current_time( 'mysql', true ); |
|
| 85 | + require_once(EE_HELPERS.'EEH_Activation.helper.php'); |
|
| 86 | + $now_in_mysql = current_time('mysql', true); |
|
| 87 | 87 | |
| 88 | - $table_name='esp_answer'; |
|
| 89 | - $sql=" ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 88 | + $table_name = 'esp_answer'; |
|
| 89 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 90 | 90 | REG_ID int(10) unsigned NOT NULL, |
| 91 | 91 | QST_ID int(10) unsigned NOT NULL, |
| 92 | 92 | ANS_value text NOT NULL, |
| 93 | 93 | PRIMARY KEY (ANS_ID), |
| 94 | 94 | KEY REG_ID (REG_ID), |
| 95 | 95 | KEY QST_ID (QST_ID)"; |
| 96 | - $this->_table_has_not_changed_since_previous($table_name,$sql, 'ENGINE=InnoDB'); |
|
| 96 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 97 | 97 | |
| 98 | 98 | $table_name = 'esp_attendee_meta'; |
| 99 | 99 | $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | KEY ATT_fname (ATT_fname)"; |
| 116 | 116 | $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
| 117 | 117 | |
| 118 | - $table_name='esp_checkin'; |
|
| 118 | + $table_name = 'esp_checkin'; |
|
| 119 | 119 | $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
| 120 | 120 | REG_ID int(10) unsigned NOT NULL, |
| 121 | 121 | DTT_ID int(10) unsigned NOT NULL, |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | CNT_is_EU tinyint(1) DEFAULT '0', |
| 144 | 144 | CNT_active tinyint(1) DEFAULT '0', |
| 145 | 145 | PRIMARY KEY (CNT_ISO)"; |
| 146 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB' ); |
|
| 146 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 147 | 147 | |
| 148 | 148 | $table_name = 'esp_currency'; |
| 149 | 149 | $sql = "CUR_code varchar(6) collate utf8_bin NOT NULL, |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | CUR_dec_plc varchar(1) collate utf8_bin NOT NULL DEFAULT '2', |
| 154 | 154 | CUR_active tinyint(1) DEFAULT '0', |
| 155 | 155 | PRIMARY KEY (CUR_code)"; |
| 156 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB' ); |
|
| 156 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 157 | 157 | |
| 158 | 158 | |
| 159 | 159 | $table_name = 'esp_currency_payment_method'; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | KEY DTT_EVT_start (DTT_EVT_start), |
| 182 | 182 | KEY EVT_ID (EVT_ID), |
| 183 | 183 | KEY DTT_is_primary (DTT_is_primary)"; |
| 184 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB' ); |
|
| 184 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 185 | 185 | |
| 186 | 186 | $table_name = "esp_datetime_ticket"; |
| 187 | 187 | $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | PRIMARY KEY (EMT_ID), |
| 200 | 200 | KEY EVT_ID (EVT_ID), |
| 201 | 201 | KEY GRP_ID (GRP_ID)"; |
| 202 | - $this->_table_has_not_changed_since_previous( $table_name, $sql, 'ENGINE=InnoDB'); |
|
| 202 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 203 | 203 | |
| 204 | 204 | $table_name = 'esp_event_meta'; |
| 205 | 205 | $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
@@ -217,9 +217,9 @@ discard block |
||
| 217 | 217 | EVT_donations tinyint(1) NULL, |
| 218 | 218 | PRIMARY KEY (EVTM_ID), |
| 219 | 219 | KEY EVT_ID (EVT_ID)"; |
| 220 | - $this->_table_has_not_changed_since_previous($table_name,$sql, 'ENGINE=InnoDB'); |
|
| 220 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 221 | 221 | |
| 222 | - $table_name='esp_event_question_group'; |
|
| 222 | + $table_name = 'esp_event_question_group'; |
|
| 223 | 223 | $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
| 224 | 224 | EVT_ID bigint(20) unsigned NOT NULL, |
| 225 | 225 | QSG_ID int(10) unsigned NOT NULL, |
@@ -227,17 +227,17 @@ discard block |
||
| 227 | 227 | PRIMARY KEY (EQG_ID), |
| 228 | 228 | KEY EVT_ID (EVT_ID), |
| 229 | 229 | KEY QSG_ID (QSG_ID)"; |
| 230 | - $this->_table_is_changed_in_this_version($table_name,$sql, 'ENGINE=InnoDB'); |
|
| 230 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 231 | 231 | |
| 232 | - $table_name='esp_event_venue'; |
|
| 232 | + $table_name = 'esp_event_venue'; |
|
| 233 | 233 | $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
| 234 | 234 | EVT_ID bigint(20) unsigned NOT NULL, |
| 235 | 235 | VNU_ID bigint(20) unsigned NOT NULL, |
| 236 | 236 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 237 | 237 | PRIMARY KEY (EVV_ID)"; |
| 238 | - $this->_table_has_not_changed_since_previous($table_name,$sql, 'ENGINE=InnoDB'); |
|
| 238 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 239 | 239 | |
| 240 | - $table_name='esp_extra_meta'; |
|
| 240 | + $table_name = 'esp_extra_meta'; |
|
| 241 | 241 | $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
| 242 | 242 | OBJ_ID int(11) DEFAULT NULL, |
| 243 | 243 | EXM_type varchar(45) DEFAULT NULL, |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | EXM_value text, |
| 246 | 246 | PRIMARY KEY (EXM_ID), |
| 247 | 247 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
| 248 | - $this->_table_has_not_changed_since_previous($table_name,$sql, 'ENGINE=InnoDB'); |
|
| 248 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 249 | 249 | |
| 250 | 250 | $table_name = 'esp_extra_join'; |
| 251 | 251 | $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
| 259 | 259 | $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
| 260 | 260 | |
| 261 | - $table_name='esp_line_item'; |
|
| 261 | + $table_name = 'esp_line_item'; |
|
| 262 | 262 | $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
| 263 | 263 | LIN_code varchar(245) NOT NULL DEFAULT '', |
| 264 | 264 | TXN_ID int(11) DEFAULT NULL, |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | PRIMARY KEY (LIN_ID), |
| 279 | 279 | KEY LIN_code (LIN_code(191)), |
| 280 | 280 | KEY TXN_ID (TXN_ID)"; |
| 281 | - $this->_table_has_not_changed_since_previous($table_name,$sql, 'ENGINE=InnoDB' ); |
|
| 281 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 282 | 282 | |
| 283 | 283 | $table_name = 'esp_log'; |
| 284 | 284 | $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | KEY STS_ID (STS_ID), |
| 328 | 328 | KEY MSG_created (MSG_created), |
| 329 | 329 | KEY MSG_modified (MSG_modified)"; |
| 330 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB' ); |
|
| 330 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 331 | 331 | |
| 332 | 332 | $table_name = 'esp_message_template'; |
| 333 | 333 | $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
| 353 | 353 | PRIMARY KEY (GRP_ID), |
| 354 | 354 | KEY MTP_user_id (MTP_user_id)"; |
| 355 | - $this->_table_has_not_changed_since_previous( $table_name, $sql, 'ENGINE=InnoDB'); |
|
| 355 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 356 | 356 | |
| 357 | 357 | $table_name = 'esp_payment'; |
| 358 | 358 | $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | PRIMARY KEY (TTM_ID)"; |
| 411 | 411 | $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
| 412 | 412 | |
| 413 | - $table_name='esp_question'; |
|
| 413 | + $table_name = 'esp_question'; |
|
| 414 | 414 | $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
| 415 | 415 | QST_display_text text NOT NULL, |
| 416 | 416 | QST_admin_label varchar(255) NOT NULL, |
@@ -425,9 +425,9 @@ discard block |
||
| 425 | 425 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
| 426 | 426 | PRIMARY KEY (QST_ID), |
| 427 | 427 | KEY QST_order (QST_order)'; |
| 428 | - $this->_table_has_not_changed_since_previous($table_name,$sql, 'ENGINE=InnoDB'); |
|
| 428 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 429 | 429 | |
| 430 | - $table_name='esp_question_group_question'; |
|
| 430 | + $table_name = 'esp_question_group_question'; |
|
| 431 | 431 | $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
| 432 | 432 | QSG_ID int(10) unsigned NOT NULL, |
| 433 | 433 | QST_ID int(10) unsigned NOT NULL, |
@@ -435,9 +435,9 @@ discard block |
||
| 435 | 435 | PRIMARY KEY (QGQ_ID), |
| 436 | 436 | KEY QST_ID (QST_ID), |
| 437 | 437 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
| 438 | - $this->_table_has_not_changed_since_previous($table_name,$sql, 'ENGINE=InnoDB'); |
|
| 438 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 439 | 439 | |
| 440 | - $table_name='esp_question_option'; |
|
| 440 | + $table_name = 'esp_question_option'; |
|
| 441 | 441 | $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
| 442 | 442 | QSO_value varchar(255) NOT NULL, |
| 443 | 443 | QSO_desc text NOT NULL, |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | PRIMARY KEY (QSO_ID), |
| 449 | 449 | KEY QST_ID (QST_ID), |
| 450 | 450 | KEY QSO_order (QSO_order)"; |
| 451 | - $this->_table_has_not_changed_since_previous($table_name,$sql, 'ENGINE=InnoDB'); |
|
| 451 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 452 | 452 | |
| 453 | 453 | $table_name = 'esp_registration'; |
| 454 | 454 | $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | PRC_parent int(10) unsigned DEFAULT 0, |
| 562 | 562 | PRIMARY KEY (PRC_ID), |
| 563 | 563 | KEY PRT_ID (PRT_ID)"; |
| 564 | - $this->_table_has_not_changed_since_previous($table_name,$sql, 'ENGINE=InnoDB'); |
|
| 564 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 565 | 565 | |
| 566 | 566 | $table_name = "esp_price_type"; |
| 567 | 567 | $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
| 599 | 599 | PRIMARY KEY (TKT_ID), |
| 600 | 600 | KEY TKT_start_date (TKT_start_date)"; |
| 601 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB' ); |
|
| 601 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 602 | 602 | |
| 603 | 603 | $table_name = 'esp_question_group'; |
| 604 | 604 | $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | PRIMARY KEY (QSG_ID), |
| 615 | 615 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
| 616 | 616 | KEY QSG_order (QSG_order)'; |
| 617 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB' ); |
|
| 617 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 618 | 618 | |
| 619 | 619 | /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
| 620 | 620 | $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
@@ -648,5 +648,5 @@ discard block |
||
| 648 | 648 | return true; |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - public function migration_page_hooks(){} |
|
| 651 | + public function migration_page_hooks() {} |
|
| 652 | 652 | } |
| 653 | 653 | \ No newline at end of file |
@@ -196,14 +196,14 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | |
| 198 | 198 | /** |
| 199 | - * detect_if_activation_or_upgrade |
|
| 200 | - * |
|
| 201 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 202 | - * and either setting up the DB or setting up maintenance mode etc. |
|
| 203 | - * |
|
| 204 | - * @access public |
|
| 205 | - * @return void |
|
| 206 | - */ |
|
| 199 | + * detect_if_activation_or_upgrade |
|
| 200 | + * |
|
| 201 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 202 | + * and either setting up the DB or setting up maintenance mode etc. |
|
| 203 | + * |
|
| 204 | + * @access public |
|
| 205 | + * @return void |
|
| 206 | + */ |
|
| 207 | 207 | public function detect_if_activation_or_upgrade() { |
| 208 | 208 | do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
| 209 | 209 | |
@@ -512,11 +512,11 @@ discard block |
||
| 512 | 512 | $query_params = array( 'page' => 'espresso_about' ); |
| 513 | 513 | |
| 514 | 514 | if ( EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation ) { |
| 515 | - $query_params['new_activation'] = TRUE; |
|
| 515 | + $query_params['new_activation'] = TRUE; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | if ( EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation ) { |
| 519 | - $query_params['reactivation'] = TRUE; |
|
| 519 | + $query_params['reactivation'] = TRUE; |
|
| 520 | 520 | } |
| 521 | 521 | $url = add_query_arg( $query_params, admin_url( 'admin.php' ) ); |
| 522 | 522 | wp_safe_redirect( $url ); |
@@ -619,11 +619,11 @@ discard block |
||
| 619 | 619 | |
| 620 | 620 | |
| 621 | 621 | /** |
| 622 | - * _incompatible_addon_error |
|
| 623 | - * |
|
| 624 | - * @access public |
|
| 625 | - * @return void |
|
| 626 | - */ |
|
| 622 | + * _incompatible_addon_error |
|
| 623 | + * |
|
| 624 | + * @access public |
|
| 625 | + * @return void |
|
| 626 | + */ |
|
| 627 | 627 | private function _incompatible_addon_error() { |
| 628 | 628 | // get array of classes hooking into here |
| 629 | 629 | $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( 'AHEE__EE_System__register_shortcodes_modules_and_addons' ); |
@@ -745,14 +745,14 @@ discard block |
||
| 745 | 745 | |
| 746 | 746 | |
| 747 | 747 | /** |
| 748 | - * load_controllers |
|
| 749 | - * |
|
| 750 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
| 751 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this time |
|
| 752 | - * |
|
| 753 | - * @access public |
|
| 754 | - * @return void |
|
| 755 | - */ |
|
| 748 | + * load_controllers |
|
| 749 | + * |
|
| 750 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
| 751 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this time |
|
| 752 | + * |
|
| 753 | + * @access public |
|
| 754 | + * @return void |
|
| 755 | + */ |
|
| 756 | 756 | public function load_controllers() { |
| 757 | 757 | do_action( 'AHEE__EE_System__load_controllers__start' ); |
| 758 | 758 | // let's get it started |
@@ -769,13 +769,13 @@ discard block |
||
| 769 | 769 | |
| 770 | 770 | |
| 771 | 771 | /** |
| 772 | - * core_loaded_and_ready |
|
| 773 | - * |
|
| 774 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 775 | - * |
|
| 776 | - * @access public |
|
| 777 | - * @return void |
|
| 778 | - */ |
|
| 772 | + * core_loaded_and_ready |
|
| 773 | + * |
|
| 774 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 775 | + * |
|
| 776 | + * @access public |
|
| 777 | + * @return void |
|
| 778 | + */ |
|
| 779 | 779 | public function core_loaded_and_ready() { |
| 780 | 780 | do_action( 'AHEE__EE_System__core_loaded_and_ready' ); |
| 781 | 781 | do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
@@ -786,13 +786,13 @@ discard block |
||
| 786 | 786 | |
| 787 | 787 | |
| 788 | 788 | /** |
| 789 | - * initialize |
|
| 790 | - * |
|
| 791 | - * this is the best place to begin initializing client code |
|
| 792 | - * |
|
| 793 | - * @access public |
|
| 794 | - * @return void |
|
| 795 | - */ |
|
| 789 | + * initialize |
|
| 790 | + * |
|
| 791 | + * this is the best place to begin initializing client code |
|
| 792 | + * |
|
| 793 | + * @access public |
|
| 794 | + * @return void |
|
| 795 | + */ |
|
| 796 | 796 | public function initialize() { |
| 797 | 797 | do_action( 'AHEE__EE_System__initialize' ); |
| 798 | 798 | } |
@@ -800,13 +800,13 @@ discard block |
||
| 800 | 800 | |
| 801 | 801 | |
| 802 | 802 | /** |
| 803 | - * initialize_last |
|
| 804 | - * |
|
| 805 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to initialize has done so |
|
| 806 | - * |
|
| 807 | - * @access public |
|
| 808 | - * @return void |
|
| 809 | - */ |
|
| 803 | + * initialize_last |
|
| 804 | + * |
|
| 805 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to initialize has done so |
|
| 806 | + * |
|
| 807 | + * @access public |
|
| 808 | + * @return void |
|
| 809 | + */ |
|
| 810 | 810 | public function initialize_last() { |
| 811 | 811 | do_action( 'AHEE__EE_System__initialize_last' ); |
| 812 | 812 | } |
@@ -815,14 +815,14 @@ discard block |
||
| 815 | 815 | |
| 816 | 816 | |
| 817 | 817 | /** |
| 818 | - * set_hooks_for_shortcodes_modules_and_addons |
|
| 819 | - * |
|
| 820 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 821 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
| 822 | - * |
|
| 823 | - * @access public |
|
| 824 | - * @return void |
|
| 825 | - */ |
|
| 818 | + * set_hooks_for_shortcodes_modules_and_addons |
|
| 819 | + * |
|
| 820 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 821 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
| 822 | + * |
|
| 823 | + * @access public |
|
| 824 | + * @return void |
|
| 825 | + */ |
|
| 826 | 826 | public function set_hooks_for_shortcodes_modules_and_addons() { |
| 827 | 827 | // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
| 828 | 828 | } |
@@ -831,13 +831,13 @@ discard block |
||
| 831 | 831 | |
| 832 | 832 | |
| 833 | 833 | /** |
| 834 | - * do_not_cache |
|
| 835 | - * |
|
| 836 | - * sets no cache headers and defines no cache constants for WP plugins |
|
| 837 | - * |
|
| 838 | - * @access public |
|
| 839 | - * @return void |
|
| 840 | - */ |
|
| 834 | + * do_not_cache |
|
| 835 | + * |
|
| 836 | + * sets no cache headers and defines no cache constants for WP plugins |
|
| 837 | + * |
|
| 838 | + * @access public |
|
| 839 | + * @return void |
|
| 840 | + */ |
|
| 841 | 841 | public static function do_not_cache() { |
| 842 | 842 | // set no cache constants |
| 843 | 843 | if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | //Current post |
| 957 | 957 | global $post; |
| 958 | 958 | |
| 959 | - if ( $this->registry->CAP->current_user_can( 'ee_edit_event', 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID ) ) { |
|
| 959 | + if ( $this->registry->CAP->current_user_can( 'ee_edit_event', 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID ) ) { |
|
| 960 | 960 | //Events Edit Current Event |
| 961 | 961 | $admin_bar->add_menu(array( |
| 962 | 962 | 'id' => 'espresso-toolbar-events-edit', |
@@ -6,8 +6,8 @@ discard block |
||
| 6 | 6 | use EventEspresso\core\libraries\rest_api\Rest_Exception; |
| 7 | 7 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
| 8 | 8 | |
| 9 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 10 | - exit( 'No direct script access allowed' ); |
|
| 9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | + exit('No direct script access allowed'); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function __construct() { |
| 40 | 40 | parent::__construct(); |
| 41 | - \EE_Registry::instance()->load_helper( 'Inflector' ); |
|
| 41 | + \EE_Registry::instance()->load_helper('Inflector'); |
|
| 42 | 42 | $this->_fields_calculator = new Calculated_Model_Fields(); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -47,22 +47,22 @@ discard block |
||
| 47 | 47 | * @param \WP_REST_Request $request |
| 48 | 48 | * @return \WP_REST_Response|\WP_Error |
| 49 | 49 | */ |
| 50 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
| 50 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
| 51 | 51 | $controller = new Read(); |
| 52 | - try{ |
|
| 52 | + try { |
|
| 53 | 53 | $matches = $controller->parse_route( |
| 54 | 54 | $request->get_route(), |
| 55 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
| 56 | - array( 'version', 'model' ) |
|
| 55 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
| 56 | + array('version', 'model') |
|
| 57 | 57 | ); |
| 58 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
| 59 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
| 60 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
| 58 | + $controller->set_requested_version($matches['version']); |
|
| 59 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 60 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 61 | 61 | return $controller->send_response( |
| 62 | 62 | new \WP_Error( |
| 63 | 63 | 'endpoint_parsing_error', |
| 64 | 64 | sprintf( |
| 65 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 65 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 66 | 66 | $model_name_singular |
| 67 | 67 | ) |
| 68 | 68 | ) |
@@ -70,12 +70,12 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | return $controller->send_response( |
| 72 | 72 | $controller->get_entities_from_model( |
| 73 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
| 73 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 74 | 74 | $request |
| 75 | 75 | ) |
| 76 | 76 | ); |
| 77 | - } catch( \Exception $e ) { |
|
| 78 | - return $controller->send_response( $e ); |
|
| 77 | + } catch (\Exception $e) { |
|
| 78 | + return $controller->send_response($e); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -85,21 +85,21 @@ discard block |
||
| 85 | 85 | * @param \WP_REST_Request $request |
| 86 | 86 | * @return \WP_REST_Response|\WP_Error |
| 87 | 87 | */ |
| 88 | - public static function handle_request_get_one( \WP_REST_Request $request ) { |
|
| 88 | + public static function handle_request_get_one(\WP_REST_Request $request) { |
|
| 89 | 89 | $controller = new Read(); |
| 90 | - try{ |
|
| 90 | + try { |
|
| 91 | 91 | $matches = $controller->parse_route( |
| 92 | 92 | $request->get_route(), |
| 93 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
| 94 | - array( 'version', 'model', 'id' ) ); |
|
| 95 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
| 96 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
| 97 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
| 93 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
| 94 | + array('version', 'model', 'id') ); |
|
| 95 | + $controller->set_requested_version($matches['version']); |
|
| 96 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 97 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 98 | 98 | return $controller->send_response( |
| 99 | 99 | new \WP_Error( |
| 100 | 100 | 'endpoint_parsing_error', |
| 101 | 101 | sprintf( |
| 102 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 102 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 103 | 103 | $model_name_singular |
| 104 | 104 | ) |
| 105 | 105 | ) |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | return $controller->send_response( |
| 109 | 109 | $controller->get_entity_from_model( |
| 110 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
| 110 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 111 | 111 | $request |
| 112 | 112 | ) |
| 113 | 113 | ); |
| 114 | - } catch( \Exception $e ) { |
|
| 115 | - return $controller->send_response( $e ); |
|
| 114 | + } catch (\Exception $e) { |
|
| 115 | + return $controller->send_response($e); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -124,40 +124,40 @@ discard block |
||
| 124 | 124 | * @param \WP_REST_Request $request |
| 125 | 125 | * @return \WP_REST_Response|\WP_Error |
| 126 | 126 | */ |
| 127 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
| 127 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
| 128 | 128 | $controller = new Read(); |
| 129 | - try{ |
|
| 129 | + try { |
|
| 130 | 130 | $matches = $controller->parse_route( |
| 131 | 131 | $request->get_route(), |
| 132 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
| 133 | - array( 'version', 'model', 'id', 'related_model' ) |
|
| 132 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
| 133 | + array('version', 'model', 'id', 'related_model') |
|
| 134 | 134 | ); |
| 135 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
| 136 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
| 137 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
| 135 | + $controller->set_requested_version($matches['version']); |
|
| 136 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 137 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
| 138 | 138 | return $controller->send_response( |
| 139 | 139 | new \WP_Error( |
| 140 | 140 | 'endpoint_parsing_error', |
| 141 | 141 | sprintf( |
| 142 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 142 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 143 | 143 | $main_model_name_singular |
| 144 | 144 | ) |
| 145 | 145 | ) |
| 146 | 146 | ); |
| 147 | 147 | } |
| 148 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
| 148 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
| 149 | 149 | //assume the related model name is plural and try to find the model's name |
| 150 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
| 151 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
| 150 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
| 151 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 152 | 152 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
| 153 | - $related_model_name_singular = \EEH_Inflector::humanize( $matches[ 'related_model' ] ); |
|
| 153 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
| 154 | 154 | } |
| 155 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
| 155 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 156 | 156 | return $controller->send_response( |
| 157 | 157 | new \WP_Error( |
| 158 | 158 | 'endpoint_parsing_error', |
| 159 | 159 | sprintf( |
| 160 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 160 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 161 | 161 | $related_model_name_singular |
| 162 | 162 | ) |
| 163 | 163 | ) |
@@ -166,13 +166,13 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | return $controller->send_response( |
| 168 | 168 | $controller->get_entities_from_relation( |
| 169 | - $request->get_param( 'id' ), |
|
| 170 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
| 169 | + $request->get_param('id'), |
|
| 170 | + $main_model->related_settings_for($related_model_name_singular), |
|
| 171 | 171 | $request |
| 172 | 172 | ) |
| 173 | 173 | ); |
| 174 | - } catch( \Exception $e ) { |
|
| 175 | - return $controller->send_response( $e ); |
|
| 174 | + } catch (\Exception $e) { |
|
| 175 | + return $controller->send_response($e); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
@@ -185,28 +185,28 @@ discard block |
||
| 185 | 185 | * @param \WP_REST_Request $request |
| 186 | 186 | * @return array |
| 187 | 187 | */ |
| 188 | - public function get_entities_from_model( $model, $request) { |
|
| 189 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
| 190 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
| 191 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
| 188 | + public function get_entities_from_model($model, $request) { |
|
| 189 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
| 190 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
| 191 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 192 | 192 | return new \WP_Error( |
| 193 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
| 193 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
| 194 | 194 | sprintf( |
| 195 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
| 195 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
| 196 | 196 | $model_name_plural, |
| 197 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
| 197 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
| 198 | 198 | ), |
| 199 | - array( 'status' => 403 ) |
|
| 199 | + array('status' => 403) |
|
| 200 | 200 | ); |
| 201 | 201 | } |
| 202 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
| 203 | - $this->_set_headers_from_query_params( $model, $query_params ); |
|
| 202 | + if ( ! $request->get_header('no_rest_headers')) { |
|
| 203 | + $this->_set_headers_from_query_params($model, $query_params); |
|
| 204 | 204 | } |
| 205 | 205 | /** @type array $results */ |
| 206 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
| 206 | + $results = $model->get_all_wpdb_results($query_params); |
|
| 207 | 207 | $nice_results = array( ); |
| 208 | - foreach ( $results as $result ) { |
|
| 209 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
| 208 | + foreach ($results as $result) { |
|
| 209 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
| 210 | 210 | $model, |
| 211 | 211 | $result, |
| 212 | 212 | $request |
@@ -227,64 +227,64 @@ discard block |
||
| 227 | 227 | * @param \WP_REST_Request $request |
| 228 | 228 | * @return array |
| 229 | 229 | */ |
| 230 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
| 231 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
| 230 | + public function get_entities_from_relation($id, $relation, $request) { |
|
| 231 | + $context = $this->validate_context($request->get_param('caps')); |
|
| 232 | 232 | $model = $relation->get_this_model(); |
| 233 | 233 | $related_model = $relation->get_other_model(); |
| 234 | 234 | //check if they can access the 1st model object |
| 235 | - $query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 ); |
|
| 236 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
| 235 | + $query_params = array(array($model->primary_key_name() => $id), 'limit' => 1); |
|
| 236 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 237 | 237 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
| 238 | 238 | } |
| 239 | 239 | $restricted_query_params = $query_params; |
| 240 | - $restricted_query_params[ 'caps' ] = $context; |
|
| 241 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
| 242 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
| 240 | + $restricted_query_params['caps'] = $context; |
|
| 241 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
| 242 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
| 243 | 243 | |
| 244 | - if( |
|
| 244 | + if ( |
|
| 245 | 245 | ! ( |
| 246 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
| 247 | - && $model->exists( $restricted_query_params ) |
|
| 246 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
| 247 | + && $model->exists($restricted_query_params) |
|
| 248 | 248 | ) |
| 249 | - ){ |
|
| 250 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
| 251 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
| 252 | - }else{ |
|
| 253 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
| 249 | + ) { |
|
| 250 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 251 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
| 252 | + } else { |
|
| 253 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
| 254 | 254 | } |
| 255 | 255 | return new \WP_Error( |
| 256 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
| 256 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
| 257 | 257 | sprintf( |
| 258 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
| 258 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
| 259 | 259 | $related_model_name_maybe_plural, |
| 260 | 260 | $relation->get_this_model()->get_this_model_name(), |
| 261 | 261 | implode( |
| 262 | 262 | ',', |
| 263 | 263 | array_keys( |
| 264 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
| 264 | + Capabilities::get_missing_permissions($related_model, $context) |
|
| 265 | 265 | ) |
| 266 | 266 | ) |
| 267 | 267 | ), |
| 268 | - array( 'status' => 403 ) |
|
| 268 | + array('status' => 403) |
|
| 269 | 269 | ); |
| 270 | 270 | } |
| 271 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
| 272 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id; |
|
| 273 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
| 274 | - $query_params[ 'caps' ] = $context; |
|
| 275 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
| 276 | - $this->_set_headers_from_query_params( $relation->get_other_model(), $query_params ); |
|
| 271 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
| 272 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id; |
|
| 273 | + $query_params['default_where_conditions'] = 'none'; |
|
| 274 | + $query_params['caps'] = $context; |
|
| 275 | + if ( ! $request->get_header('no_rest_headers')) { |
|
| 276 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
| 277 | 277 | } |
| 278 | 278 | /** @type array $results */ |
| 279 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
| 279 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
| 280 | 280 | $nice_results = array(); |
| 281 | - foreach( $results as $result ) { |
|
| 281 | + foreach ($results as $result) { |
|
| 282 | 282 | $nice_result = $this->create_entity_from_wpdb_result( |
| 283 | 283 | $relation->get_other_model(), |
| 284 | 284 | $result, |
| 285 | 285 | $request |
| 286 | 286 | ); |
| 287 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
| 287 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
| 288 | 288 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
| 289 | 289 | //if there are conflicts we prefer the properties from the main model |
| 290 | 290 | $join_model_result = $this->create_entity_from_wpdb_result( |
@@ -292,18 +292,18 @@ discard block |
||
| 292 | 292 | $result, |
| 293 | 293 | $request |
| 294 | 294 | ); |
| 295 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
| 295 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
| 296 | 296 | //but keep the meta stuff from the main model |
| 297 | - if( isset( $nice_result['meta'] ) ){ |
|
| 297 | + if (isset($nice_result['meta'])) { |
|
| 298 | 298 | $joined_result['meta'] = $nice_result['meta']; |
| 299 | 299 | } |
| 300 | 300 | $nice_result = $joined_result; |
| 301 | 301 | } |
| 302 | 302 | $nice_results[] = $nice_result; |
| 303 | 303 | } |
| 304 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
| 305 | - return array_shift( $nice_results ); |
|
| 306 | - }else{ |
|
| 304 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 305 | + return array_shift($nice_results); |
|
| 306 | + } else { |
|
| 307 | 307 | return $nice_results; |
| 308 | 308 | } |
| 309 | 309 | } |
@@ -316,30 +316,30 @@ discard block |
||
| 316 | 316 | * @param array $query_params |
| 317 | 317 | * @return void |
| 318 | 318 | */ |
| 319 | - protected function _set_headers_from_query_params( $model, $query_params ) { |
|
| 320 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
| 321 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) ); |
|
| 319 | + protected function _set_headers_from_query_params($model, $query_params) { |
|
| 320 | + $this->_set_debug_info('model query params', $query_params); |
|
| 321 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
| 322 | 322 | //normally the limit to a 2-part array, where the 2nd item is the limit |
| 323 | - if( ! isset( $query_params[ 'limit' ] ) ) { |
|
| 324 | - $query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 323 | + if ( ! isset($query_params['limit'])) { |
|
| 324 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 325 | 325 | } |
| 326 | - if( is_array( $query_params[ 'limit' ] ) ) { |
|
| 327 | - $limit_parts = $query_params[ 'limit' ]; |
|
| 326 | + if (is_array($query_params['limit'])) { |
|
| 327 | + $limit_parts = $query_params['limit']; |
|
| 328 | 328 | } else { |
| 329 | - $limit_parts = explode(',', $query_params[ 'limit' ] ); |
|
| 330 | - if( count( $limit_parts ) == 1 ){ |
|
| 331 | - $limit_parts = array(0, $limit_parts[ 0 ] ); |
|
| 329 | + $limit_parts = explode(',', $query_params['limit']); |
|
| 330 | + if (count($limit_parts) == 1) { |
|
| 331 | + $limit_parts = array(0, $limit_parts[0]); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | //remove the group by and having parts of the query, as those will |
| 335 | 335 | //make the sql query return an array of values, instead of just a single value |
| 336 | - unset( $query_params[ 'group_by' ], $query_params[ 'having' ], $query_params[ 'limit' ] ); |
|
| 337 | - $count = $model->count( $query_params, null, true ); |
|
| 336 | + unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
| 337 | + $count = $model->count($query_params, null, true); |
|
| 338 | 338 | |
| 339 | - $pages = $count / $limit_parts[ 1 ]; |
|
| 340 | - $this->_set_response_header( 'Total', $count, false ); |
|
| 341 | - $this->_set_response_header( 'PageSize', $limit_parts[ 1 ], false ); |
|
| 342 | - $this->_set_response_header( 'TotalPages', ceil( $pages ), false ); |
|
| 339 | + $pages = $count / $limit_parts[1]; |
|
| 340 | + $this->_set_response_header('Total', $count, false); |
|
| 341 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
| 342 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -352,47 +352,47 @@ discard block |
||
| 352 | 352 | * @param string $deprecated no longer used |
| 353 | 353 | * @return array ready for being converted into json for sending to client |
| 354 | 354 | */ |
| 355 | - public function create_entity_from_wpdb_result( $model, $db_row, $rest_request, $deprecated = null ) { |
|
| 356 | - if( ! $rest_request instanceof \WP_REST_Request ) { |
|
| 355 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) { |
|
| 356 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
| 357 | 357 | //ok so this was called in the old style, where the 3rd arg was |
| 358 | 358 | //$include, and the 4th arg was $context |
| 359 | 359 | //now setup the request just to avoid fatal errors, although we won't be able |
| 360 | 360 | //to truly make use of it because it's kinda devoid of info |
| 361 | 361 | $rest_request = new \WP_REST_Request(); |
| 362 | - $rest_request->set_param( 'include', $rest_request ); |
|
| 363 | - $rest_request->set_param( 'caps', $deprecated ); |
|
| 362 | + $rest_request->set_param('include', $rest_request); |
|
| 363 | + $rest_request->set_param('caps', $deprecated); |
|
| 364 | 364 | } |
| 365 | - if( $rest_request->get_param( 'caps' ) == null ) { |
|
| 366 | - $rest_request->set_param( 'caps', \EEM_Base::caps_read ); |
|
| 365 | + if ($rest_request->get_param('caps') == null) { |
|
| 366 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
| 367 | 367 | } |
| 368 | - $entity_array = $this->_create_bare_entity_from_wpdb_results( $model, $db_row ); |
|
| 369 | - $entity_array = $this->_add_extra_fields( $model, $db_row, $entity_array ); |
|
| 370 | - $entity_array[ '_links' ] = $this->_get_entity_links( $model, $db_row, $entity_array ); |
|
| 371 | - $entity_array[ '_calculated_fields'] = $this->_get_entity_calculations( $model, $db_row, $rest_request ); |
|
| 372 | - $entity_array = $this->_include_requested_models( $model, $rest_request, $entity_array ); |
|
| 368 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
| 369 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
| 370 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
| 371 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
| 372 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array); |
|
| 373 | 373 | $entity_array = apply_filters( |
| 374 | 374 | 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
| 375 | 375 | $entity_array, |
| 376 | 376 | $model, |
| 377 | - $rest_request->get_param( 'caps' ), |
|
| 377 | + $rest_request->get_param('caps'), |
|
| 378 | 378 | $rest_request, |
| 379 | 379 | $this |
| 380 | 380 | ); |
| 381 | 381 | $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
| 382 | 382 | $entity_array, |
| 383 | 383 | $model, |
| 384 | - $rest_request->get_param( 'caps' ), |
|
| 384 | + $rest_request->get_param('caps'), |
|
| 385 | 385 | $this->get_model_version_info() |
| 386 | 386 | ); |
| 387 | 387 | $this->_set_debug_info( |
| 388 | 388 | 'inaccessible fields', |
| 389 | - array_keys( array_diff_key( $entity_array, $result_without_inaccessible_fields ) ) |
|
| 389 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
| 390 | 390 | ); |
| 391 | 391 | return apply_filters( |
| 392 | 392 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
| 393 | 393 | $result_without_inaccessible_fields, |
| 394 | 394 | $model, |
| 395 | - $rest_request->get_param( 'caps' ) |
|
| 395 | + $rest_request->get_param('caps') |
|
| 396 | 396 | ); |
| 397 | 397 | } |
| 398 | 398 | |
@@ -404,38 +404,38 @@ discard block |
||
| 404 | 404 | * @param array $db_row |
| 405 | 405 | * @return array entity mostly ready for converting to JSON and sending in the response |
| 406 | 406 | */ |
| 407 | - protected function _create_bare_entity_from_wpdb_results( \EEM_Base $model, $db_row ) { |
|
| 408 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
| 409 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
| 410 | - foreach( $result as $field_name => $raw_field_value ) { |
|
| 407 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) { |
|
| 408 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
| 409 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
| 410 | + foreach ($result as $field_name => $raw_field_value) { |
|
| 411 | 411 | $field_obj = $model->field_settings_for($field_name); |
| 412 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
| 413 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
| 414 | - unset( $result[ $field_name ] ); |
|
| 415 | - }elseif( |
|
| 416 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
| 417 | - ){ |
|
| 418 | - $result[ $field_name ] = array( |
|
| 419 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
| 420 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
| 412 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
| 413 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
| 414 | + unset($result[$field_name]); |
|
| 415 | + }elseif ( |
|
| 416 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
| 417 | + ) { |
|
| 418 | + $result[$field_name] = array( |
|
| 419 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 420 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
| 421 | 421 | ); |
| 422 | - }elseif( |
|
| 423 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
| 424 | - ){ |
|
| 425 | - $result[ $field_name ] = array( |
|
| 426 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
| 427 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
| 422 | + }elseif ( |
|
| 423 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
| 424 | + ) { |
|
| 425 | + $result[$field_name] = array( |
|
| 426 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 427 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
| 428 | 428 | ); |
| 429 | - } elseif ( $field_obj instanceof \EE_Datetime_Field ) { |
|
| 430 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 429 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
| 430 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 431 | 431 | $field_obj, |
| 432 | 432 | $field_value, |
| 433 | 433 | $this->get_model_version_info()->requested_version() |
| 434 | 434 | ); |
| 435 | 435 | } else { |
| 436 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 436 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 437 | 437 | $field_obj, |
| 438 | - $field_obj->prepare_for_get( $field_value ), |
|
| 438 | + $field_obj->prepare_for_get($field_value), |
|
| 439 | 439 | $this->get_model_version_info()->requested_version() |
| 440 | 440 | ); |
| 441 | 441 | } |
@@ -450,9 +450,9 @@ discard block |
||
| 450 | 450 | * @param array $entity_array |
| 451 | 451 | * @return array modified entity |
| 452 | 452 | */ |
| 453 | - protected function _add_extra_fields( \EEM_Base $model, $db_row, $entity_array ) { |
|
| 454 | - if( $model instanceof \EEM_CPT_Base ) { |
|
| 455 | - $entity_array[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
| 453 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) { |
|
| 454 | + if ($model instanceof \EEM_CPT_Base) { |
|
| 455 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
| 456 | 456 | } |
| 457 | 457 | return $entity_array; |
| 458 | 458 | } |
@@ -466,20 +466,20 @@ discard block |
||
| 466 | 466 | * @param array $entity_array |
| 467 | 467 | * @return array the _links item in the entity |
| 468 | 468 | */ |
| 469 | - protected function _get_entity_links( $model, $db_row, $entity_array ) { |
|
| 469 | + protected function _get_entity_links($model, $db_row, $entity_array) { |
|
| 470 | 470 | //add basic links |
| 471 | 471 | $links = array( |
| 472 | 472 | 'self' => array( |
| 473 | 473 | array( |
| 474 | 474 | 'href' => $this->get_versioned_link_to( |
| 475 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] |
|
| 475 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()] |
|
| 476 | 476 | ) |
| 477 | 477 | ) |
| 478 | 478 | ), |
| 479 | 479 | 'collection' => array( |
| 480 | 480 | array( |
| 481 | 481 | 'href' => $this->get_versioned_link_to( |
| 482 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
| 482 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
| 483 | 483 | ) |
| 484 | 484 | ) |
| 485 | 485 | ), |
@@ -487,24 +487,24 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | //add link to the wp core endpoint, if wp api is active |
| 489 | 489 | global $wp_rest_server; |
| 490 | - if( $model instanceof \EEM_CPT_Base && |
|
| 490 | + if ($model instanceof \EEM_CPT_Base && |
|
| 491 | 491 | $wp_rest_server instanceof \WP_REST_Server && |
| 492 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) ) { |
|
| 493 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post' ] = array( |
|
| 492 | + $wp_rest_server->get_route_options('/wp/v2/posts')) { |
|
| 493 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.'self_wp_post'] = array( |
|
| 494 | 494 | array( |
| 495 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
| 495 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
| 496 | 496 | 'single' => true |
| 497 | 497 | ) |
| 498 | 498 | ); |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | //add links to related models |
| 502 | - foreach( $this->get_model_version_info()->relation_settings( $model ) as $relation_name => $relation_obj ) { |
|
| 503 | - $related_model_part = Read::get_related_entity_name( $relation_name, $relation_obj ); |
|
| 504 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array( |
|
| 502 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
| 503 | + $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
| 504 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
| 505 | 505 | array( |
| 506 | 506 | 'href' => $this->get_versioned_link_to( |
| 507 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] . '/' . $related_model_part |
|
| 507 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()].'/'.$related_model_part |
|
| 508 | 508 | ), |
| 509 | 509 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
| 510 | 510 | ) |
@@ -520,51 +520,51 @@ discard block |
||
| 520 | 520 | * @param array $entity_array |
| 521 | 521 | * @return array the modified entity |
| 522 | 522 | */ |
| 523 | - protected function _include_requested_models( \EEM_Base $model, \WP_REST_Request $rest_request, $entity_array ) { |
|
| 524 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'include' ), '' ); |
|
| 525 | - $includes_for_this_model = $this->_remove_model_names_from_array( $includes_for_this_model ); |
|
| 523 | + protected function _include_requested_models(\EEM_Base $model, \WP_REST_Request $rest_request, $entity_array) { |
|
| 524 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
| 525 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
| 526 | 526 | //if they passed in * or didn't specify any includes, return everything |
| 527 | - if( ! in_array( '*', $includes_for_this_model ) |
|
| 528 | - && ! empty( $includes_for_this_model ) ) { |
|
| 529 | - if( $model->has_primary_key_field() ) { |
|
| 527 | + if ( ! in_array('*', $includes_for_this_model) |
|
| 528 | + && ! empty($includes_for_this_model)) { |
|
| 529 | + if ($model->has_primary_key_field()) { |
|
| 530 | 530 | //always include the primary key. ya just gotta know that at least |
| 531 | 531 | $includes_for_this_model[] = $model->primary_key_name(); |
| 532 | 532 | } |
| 533 | - if( $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'calculate' ), '' ) ) { |
|
| 533 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
| 534 | 534 | $includes_for_this_model[] = '_calculated_fields'; |
| 535 | 535 | } |
| 536 | - $entity_array = array_intersect_key( $entity_array, array_flip( $includes_for_this_model ) ); |
|
| 536 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
| 537 | 537 | } |
| 538 | - $relation_settings = $this->get_model_version_info()->relation_settings( $model ); |
|
| 539 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
| 538 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
| 539 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
| 540 | 540 | $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
| 541 | - $rest_request->get_param( 'include' ), |
|
| 541 | + $rest_request->get_param('include'), |
|
| 542 | 542 | $relation_name |
| 543 | 543 | ); |
| 544 | 544 | $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
| 545 | - $rest_request->get_param( 'calculate' ), |
|
| 545 | + $rest_request->get_param('calculate'), |
|
| 546 | 546 | $relation_name |
| 547 | 547 | ); |
| 548 | 548 | //did they specify they wanted to include a related model, or |
| 549 | 549 | //specific fields from a related model? |
| 550 | 550 | //or did they specify to calculate a field from a related model? |
| 551 | - if( $related_fields_to_include || $related_fields_to_calculate ) { |
|
| 551 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
| 552 | 552 | //if so, we should include at least some part of the related model |
| 553 | 553 | $pretend_related_request = new \WP_REST_Request(); |
| 554 | 554 | $pretend_related_request->set_query_params( |
| 555 | 555 | array( |
| 556 | - 'caps' => $rest_request->get_param( 'caps' ), |
|
| 556 | + 'caps' => $rest_request->get_param('caps'), |
|
| 557 | 557 | 'include' => $related_fields_to_include, |
| 558 | 558 | 'calculate' => $related_fields_to_calculate, |
| 559 | 559 | ) |
| 560 | 560 | ); |
| 561 | - $pretend_related_request->add_header( 'no_rest_headers', true ); |
|
| 561 | + $pretend_related_request->add_header('no_rest_headers', true); |
|
| 562 | 562 | $related_results = $this->get_entities_from_relation( |
| 563 | - $entity_array[ $model->primary_key_name() ], |
|
| 563 | + $entity_array[$model->primary_key_name()], |
|
| 564 | 564 | $relation_obj, |
| 565 | 565 | $pretend_related_request |
| 566 | 566 | ); |
| 567 | - $entity_array[ Read::get_related_entity_name( $relation_name, $relation_obj ) ] = $related_results instanceof \WP_Error |
|
| 567 | + $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results instanceof \WP_Error |
|
| 568 | 568 | ? null |
| 569 | 569 | : $related_results; |
| 570 | 570 | } |
@@ -578,8 +578,8 @@ discard block |
||
| 578 | 578 | * @param array $arr |
| 579 | 579 | * @return array |
| 580 | 580 | */ |
| 581 | - private function _remove_model_names_from_array( $arr ) { |
|
| 582 | - return array_diff( $arr, array_keys( \EE_Registry::instance()->non_abstract_db_models ) ); |
|
| 581 | + private function _remove_model_names_from_array($arr) { |
|
| 582 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
| 583 | 583 | } |
| 584 | 584 | /** |
| 585 | 585 | * Gets the calculated fields for the response |
@@ -589,15 +589,15 @@ discard block |
||
| 589 | 589 | * @param \WP_REST_Request $rest_request |
| 590 | 590 | * @return array the _calculations item in the entity |
| 591 | 591 | */ |
| 592 | - protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
|
| 592 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) { |
|
| 593 | 593 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
| 594 | - $rest_request->get_param( 'calculate' ), |
|
| 594 | + $rest_request->get_param('calculate'), |
|
| 595 | 595 | '' |
| 596 | 596 | ); |
| 597 | 597 | //note: setting calculate=* doesn't do anything |
| 598 | 598 | $calculated_fields_to_return = new \stdClass(); |
| 599 | - foreach( $calculated_fields as $field_to_calculate ) { |
|
| 600 | - try{ |
|
| 599 | + foreach ($calculated_fields as $field_to_calculate) { |
|
| 600 | + try { |
|
| 601 | 601 | $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
| 602 | 602 | null, |
| 603 | 603 | $this->_fields_calculator->retrieve_calculated_field_value( |
@@ -609,10 +609,10 @@ discard block |
||
| 609 | 609 | ), |
| 610 | 610 | $this->get_model_version_info()->requested_version() |
| 611 | 611 | ); |
| 612 | - } catch( Rest_Exception $e ) { |
|
| 612 | + } catch (Rest_Exception $e) { |
|
| 613 | 613 | //if we don't have permission to read it, just leave it out. but let devs know about the problem |
| 614 | 614 | $this->_set_response_header( |
| 615 | - 'Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']', |
|
| 615 | + 'Notices-Field-Calculation-Errors['.$e->get_string_code().']['.$model->get_this_model_name().']['.$field_to_calculate.']', |
|
| 616 | 616 | $e->getMessage(), |
| 617 | 617 | true |
| 618 | 618 | ); |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
| 627 | 627 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
| 628 | 628 | */ |
| 629 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
| 629 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
| 630 | 630 | return rest_url( |
| 631 | 631 | \EED_Core_Rest_Api::ee_api_namespace |
| 632 | 632 | . $this->get_model_version_info()->requested_version() |
@@ -642,11 +642,11 @@ discard block |
||
| 642 | 642 | * @param \EE_Model_Relation_Base $relation_obj |
| 643 | 643 | * @return string |
| 644 | 644 | */ |
| 645 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
| 646 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
| 647 | - return strtolower( $relation_name ); |
|
| 648 | - }else{ |
|
| 649 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
| 645 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
| 646 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
| 647 | + return strtolower($relation_name); |
|
| 648 | + } else { |
|
| 649 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
| 650 | 650 | } |
| 651 | 651 | } |
| 652 | 652 | |
@@ -659,43 +659,43 @@ discard block |
||
| 659 | 659 | * @param \WP_REST_Request $request |
| 660 | 660 | * @return array |
| 661 | 661 | */ |
| 662 | - public function get_entity_from_model( $model, $request ) { |
|
| 663 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
| 664 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
| 662 | + public function get_entity_from_model($model, $request) { |
|
| 663 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
| 664 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 665 | 665 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
| 666 | 666 | } |
| 667 | 667 | $restricted_query_params = $query_params; |
| 668 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
| 669 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
| 670 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
| 671 | - if ( ! empty ( $model_rows ) ) { |
|
| 668 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
| 669 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
| 670 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
| 671 | + if ( ! empty ($model_rows)) { |
|
| 672 | 672 | return $this->create_entity_from_wpdb_result( |
| 673 | 673 | $model, |
| 674 | - array_shift( $model_rows ), |
|
| 674 | + array_shift($model_rows), |
|
| 675 | 675 | $request ); |
| 676 | 676 | } else { |
| 677 | 677 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
| 678 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
| 679 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
| 680 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
| 678 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
| 679 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
| 680 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
| 681 | 681 | //you got shafted- it existed but we didn't want to tell you! |
| 682 | 682 | return new \WP_Error( |
| 683 | 683 | 'rest_user_cannot_read', |
| 684 | 684 | sprintf( |
| 685 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
| 686 | - strtolower( $model->get_this_model_name() ), |
|
| 685 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
| 686 | + strtolower($model->get_this_model_name()), |
|
| 687 | 687 | Capabilities::get_missing_permissions_string( |
| 688 | 688 | $model, |
| 689 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
| 689 | + $this->validate_context($request->get_param('caps')) ) |
|
| 690 | 690 | ), |
| 691 | - array( 'status' => 403 ) |
|
| 691 | + array('status' => 403) |
|
| 692 | 692 | ); |
| 693 | 693 | } else { |
| 694 | 694 | //it's not you. It just doesn't exist |
| 695 | 695 | return new \WP_Error( |
| 696 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
| 697 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
| 698 | - array( 'status' => 404 ) |
|
| 696 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
| 697 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
| 698 | + array('status' => 404) |
|
| 699 | 699 | ); |
| 700 | 700 | } |
| 701 | 701 | } |
@@ -708,14 +708,14 @@ discard block |
||
| 708 | 708 | * @param string $context |
| 709 | 709 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
| 710 | 710 | */ |
| 711 | - public function validate_context( $context ) { |
|
| 712 | - if( ! $context ) { |
|
| 711 | + public function validate_context($context) { |
|
| 712 | + if ( ! $context) { |
|
| 713 | 713 | $context = \EEM_Base::caps_read; |
| 714 | 714 | } |
| 715 | 715 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
| 716 | - if( in_array( $context, $valid_contexts ) ){ |
|
| 716 | + if (in_array($context, $valid_contexts)) { |
|
| 717 | 717 | return $context; |
| 718 | - }else{ |
|
| 718 | + } else { |
|
| 719 | 719 | return \EEM_Base::caps_read; |
| 720 | 720 | } |
| 721 | 721 | } |
@@ -734,77 +734,77 @@ discard block |
||
| 734 | 734 | * that absolutely no results should be returned |
| 735 | 735 | * @throws \EE_Error |
| 736 | 736 | */ |
| 737 | - public function create_model_query_params( $model, $query_parameters ) { |
|
| 737 | + public function create_model_query_params($model, $query_parameters) { |
|
| 738 | 738 | $model_query_params = array( ); |
| 739 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
| 740 | - $model_query_params[ 0 ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 741 | - $query_parameters[ 'where' ], |
|
| 739 | + if (isset($query_parameters['where'])) { |
|
| 740 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 741 | + $query_parameters['where'], |
|
| 742 | 742 | $model, |
| 743 | 743 | $this->get_model_version_info()->requested_version() |
| 744 | 744 | ); |
| 745 | 745 | } |
| 746 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
| 747 | - $order_by = $query_parameters[ 'order_by' ]; |
|
| 748 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
| 749 | - $order_by = $query_parameters[ 'orderby' ]; |
|
| 750 | - }else{ |
|
| 746 | + if (isset($query_parameters['order_by'])) { |
|
| 747 | + $order_by = $query_parameters['order_by']; |
|
| 748 | + } elseif (isset($query_parameters['orderby'])) { |
|
| 749 | + $order_by = $query_parameters['orderby']; |
|
| 750 | + } else { |
|
| 751 | 751 | $order_by = null; |
| 752 | 752 | } |
| 753 | - if( $order_by !== null ){ |
|
| 754 | - $model_query_params[ 'order_by' ] = $order_by; |
|
| 753 | + if ($order_by !== null) { |
|
| 754 | + $model_query_params['order_by'] = $order_by; |
|
| 755 | 755 | } |
| 756 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
| 757 | - $group_by = $query_parameters[ 'group_by' ]; |
|
| 758 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
| 759 | - $group_by = $query_parameters[ 'groupby' ]; |
|
| 760 | - }else{ |
|
| 756 | + if (isset($query_parameters['group_by'])) { |
|
| 757 | + $group_by = $query_parameters['group_by']; |
|
| 758 | + } elseif (isset($query_parameters['groupby'])) { |
|
| 759 | + $group_by = $query_parameters['groupby']; |
|
| 760 | + } else { |
|
| 761 | 761 | $group_by = null; |
| 762 | 762 | } |
| 763 | - if( $group_by !== null ){ |
|
| 764 | - $model_query_params[ 'group_by' ] = $group_by; |
|
| 763 | + if ($group_by !== null) { |
|
| 764 | + $model_query_params['group_by'] = $group_by; |
|
| 765 | 765 | } |
| 766 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
| 767 | - $model_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 768 | - $query_parameters[ 'having' ], |
|
| 766 | + if (isset($query_parameters['having'])) { |
|
| 767 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 768 | + $query_parameters['having'], |
|
| 769 | 769 | $model, |
| 770 | 770 | $this->get_model_version_info()->requested_version() |
| 771 | 771 | ); |
| 772 | 772 | } |
| 773 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
| 774 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
| 773 | + if (isset($query_parameters['order'])) { |
|
| 774 | + $model_query_params['order'] = $query_parameters['order']; |
|
| 775 | 775 | } |
| 776 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
| 777 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
| 776 | + if (isset($query_parameters['mine'])) { |
|
| 777 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
| 778 | 778 | } |
| 779 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
| 779 | + if (isset($query_parameters['limit'])) { |
|
| 780 | 780 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
| 781 | - if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
|
| 782 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
| 783 | - }else { |
|
| 784 | - $limit_array = $query_parameters[ 'limit' ]; |
|
| 781 | + if ( ! is_array($query_parameters['limit'])) { |
|
| 782 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
| 783 | + } else { |
|
| 784 | + $limit_array = $query_parameters['limit']; |
|
| 785 | 785 | } |
| 786 | 786 | $sanitized_limit = array(); |
| 787 | - foreach( $limit_array as $key => $limit_part ) { |
|
| 788 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
| 787 | + foreach ($limit_array as $key => $limit_part) { |
|
| 788 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
| 789 | 789 | throw new \EE_Error( |
| 790 | 790 | sprintf( |
| 791 | - __( 'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso' ), |
|
| 792 | - json_encode( $query_parameters[ 'limit' ] ) |
|
| 791 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso'), |
|
| 792 | + json_encode($query_parameters['limit']) |
|
| 793 | 793 | ) |
| 794 | 794 | ); |
| 795 | 795 | } |
| 796 | - $sanitized_limit[] = (int)$limit_part; |
|
| 796 | + $sanitized_limit[] = (int) $limit_part; |
|
| 797 | 797 | } |
| 798 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
| 799 | - }else{ |
|
| 800 | - $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 798 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
| 799 | + } else { |
|
| 800 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 801 | 801 | } |
| 802 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
| 803 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
| 804 | - }else{ |
|
| 805 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
| 802 | + if (isset($query_parameters['caps'])) { |
|
| 803 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
| 804 | + } else { |
|
| 805 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
| 806 | 806 | } |
| 807 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
| 807 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | |
@@ -816,13 +816,13 @@ discard block |
||
| 816 | 816 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
| 817 | 817 | * @return array |
| 818 | 818 | */ |
| 819 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
| 819 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
| 820 | 820 | $model_ready_query_params = array(); |
| 821 | - foreach( $query_params as $key => $value ) { |
|
| 822 | - if( is_array( $value ) ) { |
|
| 823 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
| 824 | - }else{ |
|
| 825 | - $model_ready_query_params[ $key ] = $value; |
|
| 821 | + foreach ($query_params as $key => $value) { |
|
| 822 | + if (is_array($value)) { |
|
| 823 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
| 824 | + } else { |
|
| 825 | + $model_ready_query_params[$key] = $value; |
|
| 826 | 826 | } |
| 827 | 827 | } |
| 828 | 828 | return $model_ready_query_params; |
@@ -836,13 +836,13 @@ discard block |
||
| 836 | 836 | * @param $query_params |
| 837 | 837 | * @return array |
| 838 | 838 | */ |
| 839 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
| 839 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
| 840 | 840 | $model_ready_query_params = array(); |
| 841 | - foreach( $query_params as $key => $value ) { |
|
| 842 | - if( is_array( $value ) ) { |
|
| 843 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
| 841 | + foreach ($query_params as $key => $value) { |
|
| 842 | + if (is_array($value)) { |
|
| 843 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
| 844 | 844 | } else { |
| 845 | - $model_ready_query_params[ $key ] = $value; |
|
| 845 | + $model_ready_query_params[$key] = $value; |
|
| 846 | 846 | } |
| 847 | 847 | } |
| 848 | 848 | return $model_ready_query_params; |
@@ -857,33 +857,33 @@ discard block |
||
| 857 | 857 | * we only return strings starting with that and a period; if no prefix was specified |
| 858 | 858 | * we return all items containing NO periods |
| 859 | 859 | */ |
| 860 | - public function explode_and_get_items_prefixed_with( $string_to_explode, $prefix ) { |
|
| 861 | - if( is_string( $string_to_explode ) ) { |
|
| 862 | - $exploded_contents = explode( ',', $string_to_explode ); |
|
| 863 | - } else if( is_array( $string_to_explode ) ) { |
|
| 860 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) { |
|
| 861 | + if (is_string($string_to_explode)) { |
|
| 862 | + $exploded_contents = explode(',', $string_to_explode); |
|
| 863 | + } else if (is_array($string_to_explode)) { |
|
| 864 | 864 | $exploded_contents = $string_to_explode; |
| 865 | 865 | } else { |
| 866 | 866 | $exploded_contents = array(); |
| 867 | 867 | } |
| 868 | 868 | //if the string was empty, we want an empty array |
| 869 | - $exploded_contents = array_filter( $exploded_contents ); |
|
| 869 | + $exploded_contents = array_filter($exploded_contents); |
|
| 870 | 870 | $contents_with_prefix = array(); |
| 871 | - foreach( $exploded_contents as $item ) { |
|
| 872 | - $item = trim( $item ); |
|
| 871 | + foreach ($exploded_contents as $item) { |
|
| 872 | + $item = trim($item); |
|
| 873 | 873 | //if no prefix was provided, so we look for items with no "." in them |
| 874 | - if( ! $prefix ) { |
|
| 874 | + if ( ! $prefix) { |
|
| 875 | 875 | //does this item have a period? |
| 876 | - if( strpos( $item, '.' ) === false ) { |
|
| 876 | + if (strpos($item, '.') === false) { |
|
| 877 | 877 | //if not, then its what we're looking for |
| 878 | 878 | $contents_with_prefix[] = $item; |
| 879 | 879 | } |
| 880 | - } else if( strpos( $item, $prefix . '.' ) === 0 ) { |
|
| 880 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
| 881 | 881 | //this item has the prefix and a period, grab it |
| 882 | 882 | $contents_with_prefix[] = substr( |
| 883 | 883 | $item, |
| 884 | - strpos( $item, $prefix . '.' ) + strlen( $prefix . '.' ) |
|
| 884 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
| 885 | 885 | ); |
| 886 | - } else if( $item === $prefix ) { |
|
| 886 | + } else if ($item === $prefix) { |
|
| 887 | 887 | //this item is JUST the prefix |
| 888 | 888 | //so let's grab everything after, which is a blank string |
| 889 | 889 | $contents_with_prefix[] = ''; |
@@ -906,33 +906,33 @@ discard block |
||
| 906 | 906 | * the fields for that model, with the model's name removed from each. |
| 907 | 907 | * If $include_string was blank or '*' returns an empty array |
| 908 | 908 | */ |
| 909 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
| 910 | - if( is_array( $include_string ) ) { |
|
| 911 | - $include_string = implode( ',', $include_string ); |
|
| 909 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
| 910 | + if (is_array($include_string)) { |
|
| 911 | + $include_string = implode(',', $include_string); |
|
| 912 | 912 | } |
| 913 | - if( $include_string === '*' || $include_string === '' ) { |
|
| 913 | + if ($include_string === '*' || $include_string === '') { |
|
| 914 | 914 | return array(); |
| 915 | 915 | } |
| 916 | - $includes = explode( ',', $include_string ); |
|
| 916 | + $includes = explode(',', $include_string); |
|
| 917 | 917 | $extracted_fields_to_include = array(); |
| 918 | - if( $model_name ){ |
|
| 919 | - foreach( $includes as $field_to_include ) { |
|
| 920 | - $field_to_include = trim( $field_to_include ); |
|
| 921 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
| 918 | + if ($model_name) { |
|
| 919 | + foreach ($includes as $field_to_include) { |
|
| 920 | + $field_to_include = trim($field_to_include); |
|
| 921 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
| 922 | 922 | //found the model name at the exact start |
| 923 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
| 923 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
| 924 | 924 | $extracted_fields_to_include[] = $field_sans_model_name; |
| 925 | - }elseif( $field_to_include == $model_name ){ |
|
| 925 | + }elseif ($field_to_include == $model_name) { |
|
| 926 | 926 | $extracted_fields_to_include[] = '*'; |
| 927 | 927 | } |
| 928 | 928 | } |
| 929 | - }else{ |
|
| 929 | + } else { |
|
| 930 | 930 | //look for ones with no period |
| 931 | - foreach( $includes as $field_to_include ) { |
|
| 932 | - $field_to_include = trim( $field_to_include ); |
|
| 931 | + foreach ($includes as $field_to_include) { |
|
| 932 | + $field_to_include = trim($field_to_include); |
|
| 933 | 933 | if ( |
| 934 | - strpos( $field_to_include, '.' ) === false |
|
| 935 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
| 934 | + strpos($field_to_include, '.') === false |
|
| 935 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
| 936 | 936 | ) { |
| 937 | 937 | $extracted_fields_to_include[] = $field_to_include; |
| 938 | 938 | } |