Array( // // [0] => Array( // [site_unique_key] => // [ad_swapper_site_sid] => 2kmv-hzgc // [site_title] => Plugdev // [home_page_url] => http://localhost/plugdev // [general_description] => // [ads_wanted_description] => // [sites_wanted_description] => // [categories_available] => // [categories_wanted] => // ) // // ... // // ) // // ... // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $api_passback_data , // '$api_passback_data' // ) ; // ========================================================================= // Init. // ========================================================================= $ns = __NAMESPACE__ ; $fn = __FUNCTION__ ; // ------------------------------------------------------------------------- $incoming_sites = $api_passback_data['sites'] ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $incoming_sites , // '$incoming_sites' // ) ; // ------------------------------------------------------------------------- $available_sites_dataset_slug = 'ad_swapper_available_sites' ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $loaded_datasets[ $available_sites_dataset_slug ]['records'] , // '$loaded_datasets[ $available_sites_dataset_slug ][\'records\']' // ) ; // ------------------------------------------------------------------------- require_once( $core_plugapp_dirs['plugins_includes_dir'] . '/sequential-ids-support.php' ) ; // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_sequentialIdsSupport\ // question_sequential_id( // $candidate_sid // ) // - - - - - - - - - - - - // Determines whether or not $candidate_sid looks like a sequential ID // as generated by (eg):- // get_new_sequential_id() // get_new_sequential_id_thats_unique_in_dataset() // // or not. And returns TRUE or FALSE accordingly. // // In other words, $candidate_sid must be something like (eg):- // "dczv-mwhk" // "9npd-xd2h" // "pxx4-4942-9vwm" // "2n43-3dny-dykm" // etc... // ------------------------------------------------------------------------- // ========================================================================= // VALIDATA the INCOMING DATA... // ========================================================================= require_once( $core_plugapp_dirs['plugins_includes_dir'] . '/validata/validate-things.php' ) ; // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_validata\ // validate_array_of_records( // $core_plugapp_dirs , // $record_structure_slug , // $array_of_records_to_validate , // $caller_ns , // $caller_fn , // $caller_ln // ) // - - - - - - - - - - - - - - - - - - - - - // RETURNS // On SUCCESS // TRUE // // On FALSE // $error_message STRING // // NOTE! The error message will probably be multi-line. Use // nl2br() or display it in PRE tags, if you don't want // the lines to wrap. // ------------------------------------------------------------------------- $record_structure_slug = 'ad-swapper-local-incoming-available-sites' ; $array_of_records_to_validate = $incoming_sites ; // ------------------------------------------------------------------------- $result = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_validata\validate_array_of_records( $core_plugapp_dirs , $record_structure_slug , $array_of_records_to_validate , __NAMESPACE__ , __FUNCTION__ , __LINE__ ) ; // ------------------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // ========================================================================= // Get the AD SWAPPER SITE SIDS of the existing records... // ========================================================================= $existing_record_indices_by_ad_swapper_site_sid = array() ; // ------------------------------------------------------------------------- foreach ( $loaded_datasets[ $available_sites_dataset_slug ]['records'] as $this_index => $this_record ) { // --------------------------------------------------------------------- if ( ! array_key_exists( 'ad_swapper_site_sid' , $this_record ) ) { return << $this_incoming_site_record ) { // --------------------------------------------------------------------- if ( ! array_key_exists( 'ad_swapper_site_sid' , $this_incoming_site_record ) ) { return << $this_record ) { // --------------------------------------------------------------------- if ( ! in_array( $this_record['ad_swapper_site_sid'] , $incoming_ad_swapper_site_sids ) ) { $existing_record_indices_to_delete[] = $this_index ; } // --------------------------------------------------------------------- } // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $incoming_record_indices_to_add , // '$incoming_record_indices_to_add' // ) ; // //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $incoming_record_indices_to_update_by_ad_swapper_site_sid , // '$incoming_record_indices_to_update_by_ad_swapper_site_sid' // ) ; // //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $existing_record_indices_to_delete , // '$existing_record_indices_to_delete' // ) ; //return TRUE ; // ========================================================================= // UPDATE the (existing) records to be updated... // ========================================================================= $question_any_existing_records_updated = FALSE ; // ------------------------------------------------------------------------- foreach ( $incoming_record_indices_to_update_by_ad_swapper_site_sid as $this_ad_swapper_site_sid => $this_incoming_record_index ) { // --------------------------------------------------------------------- $incoming_record_to_update = $incoming_sites[ $this_incoming_record_index ] ; // --------------------------------------------------------------------- $existing_record_to_update = $loaded_datasets[ $available_sites_dataset_slug ]['records'][ $existing_record_indices_by_ad_swapper_site_sid[ $this_ad_swapper_site_sid ] ] ; // --------------------------------------------------------------------- foreach ( $incoming_record_to_update as $field_name => $field_value ) { // ----------------------------------------------------------------- if ( $field_value !== $existing_record_to_update[ $field_name ] ) { $loaded_datasets[ $available_sites_dataset_slug ]['records'][ $existing_record_indices_by_ad_swapper_site_sid[ $this_ad_swapper_site_sid ] ][ $field_name ] = $field_value ; $question_any_existing_records_updated = TRUE ; } // ----------------------------------------------------------------- } // --------------------------------------------------------------------- } // ========================================================================= // DELETE the (already available) records to be deleted... // ========================================================================= foreach ( $existing_record_indices_to_delete as $this_index ) { unset( $loaded_datasets[ $available_sites_dataset_slug ]['records'][ $this_index ] ) ; } // ========================================================================= // If there were any updates or deletes, save the updated dataset // records (and reload the "record_indices_by_key", if necessary)... // ========================================================================= if ( $question_any_existing_records_updated || count( $existing_record_indices_to_delete ) > 0 ) { // ===================================================================== // SAVE the (modified) dataset records... // ===================================================================== // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_arrayStorage\ // save_numerically_indexed( // $dataset_name , // $array_to_save , // $question_die_on_error = FALSE , // $array_storage_data = NULL // ) // - - - - - - - - - - - - - - - - - - - - - - - - - // Saves the specified numerically-indexed PHP array. // // RETURNS // o On SUCCESS // - - - - - // TRUE // // o On FAILURE // - - - - - // $error message STRING // ------------------------------------------------------------------------- $question_die_on_error = FALSE ; $array_storage_data = NULL ; // --------------------------------------------------------------------- $result = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_arrayStorage\save_numerically_indexed( $available_sites_dataset_slug , $loaded_datasets[ $available_sites_dataset_slug ]['records'] , $question_die_on_error , $array_storage_data ) ; // --------------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // --------------------------------------------------------------------- if ( count( $existing_record_indices_to_delete ) > 0 ) { // ================================================================= // RELOAD the "record_indices_by_key"... // ================================================================= // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_standardDatasetManager\ // get_dataset_record_indices_by_key( // $dataset_title , // $dataset_records , // $key_field_slug // ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // RETURNS:- // o (array) $record_indices_by_id on SUCCESS // o (string) $error_message on FAILURE // ------------------------------------------------------------------------- $result = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_standardDatasetManager\get_dataset_record_indices_by_key( $loaded_datasets[ $available_sites_dataset_slug ]['title'] , $loaded_datasets[ $available_sites_dataset_slug ]['records'] , $loaded_datasets[ $available_sites_dataset_slug ]['key_field_slug'] ) ; // ----------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // ----------------------------------------------------------------- $loaded_datasets[ $available_sites_dataset_slug ]['record_indices_by_key'] = $result ; // ----------------------------------------------------------------- } // --------------------------------------------------------------------- } // ========================================================================= // ADD the records to be added... // ========================================================================= require_once( $core_plugapp_dirs['dataset_manager_includes_dir'] . '/add-record-programatically.php' ) ; // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_standardDatasetManager\ // add_record_programatically( // $dataset_manager_home_page_title , // $caller_apps_includes_dir , // $all_application_dataset_definitions , // $dataset_slug , // $selected_datasets_dmdd , // $dataset_title , // $dataset_records , // $record_indices_by_key , // $key_field_slug , // $form_slug_underscored , // $record_to_add // ) // - - - - - - - - - - - - - - - - - - - - - - - // Adds a record to the specified dataset at any random time (when this // function is called). // // As opposed to the normal method of adding a record; which is to // display the Zebra Form for an empty record - and then add the record // once that form has been successfully submitted. // // NOTES! // ====== // 1. $record_to_add need NOT contain all the fields from the dataset. // It generally just contains the main data fields:- // o name // o age // o title // o description // o etc, etc // // but not the hidden and background fields like (eg):- // o created_datetime_utc // o last_modified_datetime_utc // o key // o etc, etc // // The missing fields (if any), will be filled in from the:- // "array_storage_value_from" // // variables in the dataset's array storage record definition. // // 2. This routine should however be similar to (and updated with,) // the normal record adding routine (that runs when a new record // is submitted - and is found in):- // Function: handle_zebra_form_submission() // File....: add-edit-record_submission-handler.php // // --- // // RETURNS // o On SUCCESS // ARRAY( // $updated_record_to_add , // $updated_dataset_records , // $updated_record_indices_by_key // ) // // o On FAILURE // $error_message STRING // ------------------------------------------------------------------------- foreach ( $incoming_record_indices_to_add as $this_incoming_record_index ) { // --------------------------------------------------------------------- $record_to_add = $incoming_sites[ $this_incoming_record_index ] ; // --------------------------------------------------------------------- // $record_to_add['question_display_this_sites_ads_on_your_site'] = FALSE ; // // Safety first! // // // // Don't display a new site's ads, unless the site owner (of the // // site displaying the ads,) has approved it. // // // --------------------------------------------------------------------- // // $record_to_add['question_display_your_ads_on_this_site'] = FALSE ; // // Safety first! // // // // Don't display this site's ads on a new site, until this site's // // owner has approved that new site. // --------------------------------------------------------------------- $dataset_manager_home_page_title = '(dataset manager home page title)' ; $caller_apps_includes_dir = $core_plugapp_dirs['plugins_includes_dir'] ; $selected_datasets_dmdd = $all_application_dataset_definitions[ $available_sites_dataset_slug ] ; $form_slug_underscored = 'default' ; // --------------------------------------------------------------------- $_GET['application'] = 'ad-swapper' ; // --------------------------------------------------------------------- $result = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_standardDatasetManager\add_record_programatically( $dataset_manager_home_page_title , $caller_apps_includes_dir , $all_application_dataset_definitions , $available_sites_dataset_slug , $selected_datasets_dmdd , $loaded_datasets[ $available_sites_dataset_slug ]['title'] , $loaded_datasets[ $available_sites_dataset_slug ]['records'] , $loaded_datasets[ $available_sites_dataset_slug ]['record_indices_by_key'] , $loaded_datasets[ $available_sites_dataset_slug ]['key_field_slug'] , $form_slug_underscored , $record_to_add ) ; // --------------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // --------------------------------------------------------------------- list( $updated_record_to_add , $loaded_datasets[ $available_sites_dataset_slug ]['records'] , $loaded_datasets[ $available_sites_dataset_slug ]['record_indices_by_key'] ) = $result ; // --------------------------------------------------------------------- } // ========================================================================= // SUCCESS! // ========================================================================= return TRUE ; // ========================================================================= // That's that! // ========================================================================= } // ============================================================================= // That's that! // =============================================================================