prefix variable. (If // you're developing for a version of WordPress older than 2.0, you'll // need to use the $table_prefix global variable, which is deprecated in // version 2.1)." // // ------------------------------------------------------------------------- $mysql_table_name = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_basepressMysql\prepend_wordpress_table_name_prefix( $dataset_slug ) ; // ========================================================================= // Create the dataset's MySQL table definition (from the dataset // definition)... // ========================================================================= require_once( dirname( __FILE__ ) . '/mysql-support.php' ) ; // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_mysqlSupport\ // get_corresponding_mysql_table_definition( // $core_plugapp_dirs , // $question_front_end , // $selected_datasets_dmdd , // $dataset_slug , // $mysql_table_name // ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - // Returns the definition of the MySQL table that corresponds to the // specified dataset (and it's array storage definition). // // The returned table definition will be like (eg):- // // $corresponding_mysql_table_definition = Array( // [columns] => Array( // [0] => Array( // [Field] => id // [Type] => BIGINT(20) UNSIGNED // [Null] => NO // [Key] => PRI // [Default] => // [Extra] => AUTO_INCREMENT // ) , // [1] => Array( // [Field] => created_server_datetime // [Type] => DATETIME // [Null] => NO // [Key] => // [Default] => 2014-12-16 08:52:39 // [Extra] => // ) , // ... // ) // [key_lengths_by_field_name] => Array( // [name] => 16 // ... // ) // // RETURNS // On SUCCESS // ARRAY $corresponding_mysql_table_definition // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- $corresponding_mysql_table_definition = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_mysqlSupport\get_corresponding_mysql_table_definition( $core_plugapp_dirs , $question_front_end , $selected_datasets_dmdd , $dataset_slug , $mysql_table_name ) ; // ------------------------------------------------------------------------- if ( is_string( $corresponding_mysql_table_definition ) ) { return $corresponding_mysql_table_definition ; } // ------------------------------------------------------------------------- // Here we should have (eg):- // // $corresponding_mysql_table_definition = Array( // // [columns] => Array( // // [0] => Array( // [Field] => id // [Type] => BIGINT(20) UNSIGNED // [Null] => NO // [Key] => PRI // [Default] => // [Extra] => AUTO_INCREMENT // ) // // [1] => Array ( // [Field] => created_server_datetime // [Type] => DATETIME // [Null] => NO // [Key] => // [Default] => "0000-00-00 00:00:00" // [Extra] => // ) // // [2] => Array( // [Field] => last_modified_server_datetime // [Type] => TIMESTAMP // [Null] => NO // [Key] => // [Default] => CURRENT_TIMESTAMP // [Extra] => ON UPDATE CURRENT_TIMESTAMP // ) // // [3] => Array( // [Field] => created_server_datetime_utc // [Type] => INT(10) UNSIGNED // [Null] => NO // [Key] => // [Default] => 0 // [Extra] => // ) // // [4] => Array( // [Field] => last_modified_server_datetime_utc // [Type] => INT(10) UNSIGNED // [Null] => NO // [Key] => // [Default] => 0 // [Extra] => // ) // // [5] => Array( // [Field] => this_field // [Type] => TEXT // [Null] => NO // [Key] => // [Default] => // [Extra] => // ) // // ... // // [8] => Array( // [Field] => boolean_field_one // [Type] => TEXT // [Null] => NO // [Key] => // [Default] => // [Extra] => // ) // // ... // // ) // // [key_lengths_by_field_name] => Array() // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $corresponding_mysql_table_definition , // '$corresponding_mysql_table_definition' // ) ; // ========================================================================= // Does the table exist ? // // If NOT, auto-create it... // ========================================================================= // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_basepressMysql\ // table_exists( // $table_name // ) // - - - - - - - - - - - - - - - // RETURNS TRUE or FALSE, depending on whether the table exists or not. // // NOTE! // ----- // $table_name is an ABSOLUTE table name (as stored in the MySQL database) // - with the WordPress table prefix prepended if necessary. // // Call:- // // table_exists( // prepend_wordpress_table_name_prefix( $table_name ) // ) // // if you want to supply the table name WITHOUT the WordPress table prefix // (and have that prefix automatically prepended for you). // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_mysqlSupport\ // auto_create_mysql_table( // $core_plugapp_dirs , // $question_front_end , // $dataset_slug , // $mysql_table_name , // $corresponding_mysql_table_definition // ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - // RETURNS // On SUCCESS // TRUE // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- if ( ! \greatKiwi_byFernTec_adSwapper_local_v0x1x211_basepressMysql\table_exists( $mysql_table_name ) ) { // --------------------------------------------------------------------- $result = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_mysqlSupport\auto_create_mysql_table( $core_plugapp_dirs , $question_front_end , $dataset_slug , $mysql_table_name , $corresponding_mysql_table_definition ) ; // --------------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // --------------------------------------------------------------------- } // ========================================================================= // Get the existing MySQL table's definition... // ========================================================================= // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_mysqlSupport\ // get_existing_mysql_table_definition( // $core_plugapp_dirs , // $question_front_end , // $mysql_table_name // ) // - - - - - - - - - - - - - - - - - // Returns the results of a SHOW COLUMNS query on the specified MySQL // Table... // // RETURNS // On SUCCESS // ARRAY $corresponding_mysql_table_definition // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- $existing_table_definition = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_mysqlSupport\get_existing_mysql_table_definition( $core_plugapp_dirs , $question_front_end , $mysql_table_name ) ; // ------------------------------------------------------------------------- if ( is_string( $existing_table_definition ) ) { return $existing_table_definition ; } // ------------------------------------------------------------------------- // Here we should have (eg):- // // $existing_table_definition = Array( // // [columns] => Array( // // [0] => Array( // [Field] => id // [Type] => bigint(20) unsigned // [Null] => NO // [Key] => PRI // [Default] => // [Extra] => auto_increment // ) // // [1] => Array( // [Field] => created_server_datetime // [Type] => datetime // [Null] => NO // [Key] => // [Default] => 0000-00-00 00:00:00 // [Extra] => // ) // // [2] => Array( // [Field] => last_modified_server_datetime // [Type] => timestamp // [Null] => NO // [Key] => // [Default] => CURRENT_TIMESTAMP // [Extra] => on update CURRENT_TIMESTAMP // ) // // [3] => Array( // [Field] => created_server_datetime_utc // [Type] => int(10) unsigned // [Null] => NO // [Key] => // [Default] => 0 // [Extra] => // ) // // [4] => Array( // [Field] => last_modified_server_datetime_utc // [Type] => int(10) unsigned // [Null] => NO // [Key] => // [Default] => 0 // [Extra] => // ) // // [5] => Array( // [Field] => this_field // [Type] => text // [Null] => NO // [Key] => // [Default] => // [Extra] => // ) // // ... // // [8] => Array( // [Field] => boolean_field_one // [Type] => text // [Null] => NO // [Key] => // [Default] => // [Extra] => // ) // // ... // // ) // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $existing_table_definition , // '$existing_table_definition' // ) ; // ========================================================================= // Index the column definitions by field_slug... // ========================================================================= $corresponding_column_definitions_by_field_slug = array() ; // ------------------------------------------------------------------------- foreach ( $corresponding_mysql_table_definition['columns'] as $this_column ) { $corresponding_column_definitions_by_field_slug[ $this_column['Field'] ] = $this_column ; } // ------------------------------------------------------------------------- // Here we should have (eg):- // // $corresponding_column_definitions_by_field_slug = Array( // // [id] => Array( // [Field] => id // [Type] => BIGINT(20) UNSIGNED // [Null] => NO // [Key] => PRI // [Default] => // [Extra] => AUTO_INCREMENT // ) // // ... // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $corresponding_column_definitions_by_field_slug , // '$corresponding_column_definitions_by_field_slug' // ) ; // ------------------------------------------------------------------------- $existing_column_definitions_by_field_slug = array() ; // ------------------------------------------------------------------------- foreach ( $existing_table_definition['columns'] as $this_column ) { $existing_column_definitions_by_field_slug[ $this_column['Field'] ] = $this_column ; } // ------------------------------------------------------------------------- // Here we should have (eg):- // // $existing_column_definitions_by_field_slug = Array( // // [id] => Array( // [Field] => id // [Type] => bigint(20) unsigned // [Null] => NO // [Key] => PRI // [Default] => // [Extra] => auto_increment // ) // // ... // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $existing_column_definitions_by_field_slug , // '$existing_column_definitions_by_field_slug' // ) ; // ========================================================================= // Support Routines.. // ========================================================================= require_once( dirname( __FILE__ ) . '/update-xxx-stored-dataset-data-support.php' ) ; // ========================================================================= // Get the fields/columns to ADD and UPDATE (if any)... // ========================================================================= $fields_to_add_by_field_slug = array() ; // ------------------------------------------------------------------------- $fields_to_update_by_field_slug = array() ; // ------------------------------------------------------------------------- foreach ( $corresponding_column_definitions_by_field_slug as $required_field_slug => $required_field_definition ) { // --------------------------------------------------------------------- if ( array_key_exists( $required_field_slug , $existing_column_definitions_by_field_slug ) ) { // ----------------------------------------------------------------- if ( question_mysql_column_defs_different( $required_field_definition , $existing_column_definitions_by_field_slug[ $required_field_slug ] ) ) { // ------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $required_field_definition , // '$required_field_definition' // ) ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $existing_column_definitions_by_field_slug[ $required_field_slug ] , // '$existing_column_definitions_by_field_slug[ $required_field_slug ]' // ) ; // ------------------------------------------------------------- $fields_to_update_by_field_slug[ $required_field_slug ] = $required_field_definition ; // ------------------------------------------------------------- } // ----------------------------------------------------------------- } else { // ----------------------------------------------------------------- $fields_to_add_by_field_slug[ $required_field_slug ] = $required_field_definition ; // ----------------------------------------------------------------- } // --------------------------------------------------------------------- } // ------------------------------------------------------------------------- // Here we should have (eg):- // // $fields_to_add_by_field_slug = Array( // // [new_field_one] => Array( // [Field] => new_field_one // [Type] => TEXT // [Null] => NO // [Key] => // [Default] => // [Extra] => // ) // // ... // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $fields_to_add_by_field_slug , // '$fields_to_add_by_field_slug' // ) ; // ------------------------------------------------------------------------- // Here we should have (eg):- // // $fields_to_update_by_field_slug = // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $fields_to_update_by_field_slug , // '$fields_to_update_by_field_slug' // ) ; // ========================================================================= // Get the fields to REMOVE (if any)... // ========================================================================= $fields_to_remove_by_field_slug = array() ; // ------------------------------------------------------------------------- foreach ( $existing_column_definitions_by_field_slug as $existing_field_slug => $existing_field_definition ) { // --------------------------------------------------------------------- if ( ! array_key_exists( $existing_field_slug , $corresponding_column_definitions_by_field_slug ) ) { // ----------------------------------------------------------------- $fields_to_remove_by_field_slug[ $existing_field_slug ] = $existing_field_definition ; // ----------------------------------------------------------------- } // --------------------------------------------------------------------- } // ------------------------------------------------------------------------- // Here we should have (eg):- // // $fields_to_remove_by_field_slug = // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $fields_to_remove_by_field_slug , // '$fields_to_remove_by_field_slug' // ) ; // ========================================================================= // Init. #2 // ========================================================================= $safe_dataset_slug = htmlentities( $dataset_slug ) ; // ------------------------------------------------------------------------- $nothing_to_do = array( '' , '' , '' ) ; // ========================================================================= // Anything to do ? // ========================================================================= if ( count( $fields_to_add_by_field_slug ) < 1 && count( $fields_to_update_by_field_slug ) < 1 && count( $fields_to_remove_by_field_slug ) < 1 ) { // ===================================================================== // Updaction Finished ? // ===================================================================== if ( array_key_exists( 'updaction_finished' , $_GET ) && $_GET['updaction_finished'] === $dataset_slug ) { return NULL ; } // ===================================================================== // That's that! // ===================================================================== return $nothing_to_do ; // --------------------------------------------------------------------- } // ========================================================================= // Check that each field to be ADDED has a GET NEW FIELD VALUE function... // ========================================================================= if ( count( $fields_to_add_by_field_slug ) > 0 ) { // ---------------------------------------------------------------------- // Here we should have (eg):- // // $selected_datasets_dmdd = array( // // ... // // 'get_new_field_value_functions' => array( // 'show_ads_list_reload_buttons' => array( // 'name' => '\\' . __NAMESPACE__ . '\\get_new_field_value_4_show_ads_list_reload_buttons' , // 'args' => array() // ) , // 'question_manual_update_approval' => array( // 'name' => '\\' . __NAMESPACE__ . '\\get_new_field_value_4_question_manual_update_approval' , // 'args' => array() // ) // ) // // ... // // ) // // --------------------------------------------------------------------- if ( ! array_key_exists( 'get_new_field_value_functions' , $selected_datasets_dmdd ) || ! is_array( $selected_datasets_dmdd['get_new_field_value_functions'] ) || count( $selected_datasets_dmdd['get_new_field_value_functions'] ) < 1 ) { // ----------------------------------------------------------------- $ln = __LINE__ - 8 ; $count = count( $fields_to_add_by_field_slug ) ; $field_slugs_to_add = '' ; foreach ( $fields_to_add_by_field_slug as $this_field_slug => $this_field_definition ) { $safe_field_slug = htmlentities( $this_field_slug ) ; $field_slugs_to_add .= <<{$safe_field_slug} EOT; } // ----------------------------------------------------------------- $msg = <<

Database Update


PROBLEM:  There are {$count} fields to ADD - but NO "get_new_field_value" functions defined.

The fields - of dataset/table {$safe_dataset_slug} - that need "get_new_field_value" functions - are:-

    {$field_slugs_to_add}

Detected in:  \\{$ns}\\{$fn}() near line {$ln}

EOT; // ----------------------------------------------------------------- $msg = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_stringUtils\to_one_line( $msg ) ; // ----------------------------------------------------------------- return $get_new_field_function_error_token . $msg ; // ----------------------------------------------------------------- } // --------------------------------------------------------------------- $get_new_field_value_function_errors = '' ; // --------------------------------------------------------------------- $tdh_style = << $this_field_definition ) { // ----------------------------------------------------------------- if ( ! array_key_exists( $this_field_slug , $selected_datasets_dmdd['get_new_field_value_functions'] ) ) { // ------------------------------------------------------------- $get_new_field_value_function_errors .= << {$this_field_slug} NO "get_new_field_value" function defined EOT; // ------------------------------------------------------------- continue ; // ------------------------------------------------------------- } // ----------------------------------------------------------------- if ( ! is_array( $selected_datasets_dmdd['get_new_field_value_functions'][ $this_field_slug ] ) ) { // ------------------------------------------------------------- $get_new_field_value_function_errors .= << {$this_field_slug} Bad "get_new_field_value" function definition (array expected) EOT; // ------------------------------------------------------------- continue ; // ------------------------------------------------------------- } // ----------------------------------------------------------------- if ( ! array_key_exists( 'name' , $selected_datasets_dmdd['get_new_field_value_functions'][ $this_field_slug ] ) ) { // ------------------------------------------------------------- $get_new_field_value_function_errors .= << {$this_field_slug} Bad "get_new_field_value" function definition (no function "name") EOT; // ------------------------------------------------------------- continue ; // ------------------------------------------------------------- } // ----------------------------------------------------------------- $get_new_field_value_function_name = $selected_datasets_dmdd['get_new_field_value_functions'][ $this_field_slug ]['name'] ; // ------------------------------------------------------------- if ( ! is_string( $get_new_field_value_function_name ) || trim( $get_new_field_value_function_name ) === '' ) { // ------------------------------------------------------------- $get_new_field_value_function_errors .= << {$this_field_slug} Bad "get_new_field_value" function "name" (non-empty string expected) EOT; // ------------------------------------------------------------- continue ; // ------------------------------------------------------------- } // ----------------------------------------------------------------- if ( ! function_exists( $get_new_field_value_function_name ) ) { // ------------------------------------------------------------- $get_new_field_value_function_errors .= << {$this_field_slug} Bad "get_new_field_value" function (function not found) EOT; // ------------------------------------------------------------- continue ; // ------------------------------------------------------------- } // ----------------------------------------------------------------- } // --------------------------------------------------------------------- if ( $get_new_field_value_function_errors !== '' ) { // ----------------------------------------------------------------- $ln = __LINE__ - 4 ; // ----------------------------------------------------------------- $msg = <<

Database Update


PROBLEM:  One or more of the fields to add - to the {$safe_dataset_slug} table - have NO or an invalid "get_new_field_value" function.  As follows:-

{$get_new_field_value_function_errors}
Field Problem/Error

Detected in:  \\{$ns}\\{$fn}() near line {$ln}

EOT; // ----------------------------------------------------------------- $msg = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_stringUtils\to_one_line( $msg ) ; // ----------------------------------------------------------------- return $get_new_field_function_error_token . $msg ; // ----------------------------------------------------------------- } // --------------------------------------------------------------------- } // ========================================================================= // Load ALL the TABLE RECORDS... // ========================================================================= // ------------------------------------------------------------------------- // NOTES! // ====== // 1. We need these records to get the DISTINCT VALUES to be added, // updated and removed. // // 2. We need ALL fields of ALL records, because the "get new field // value" functions - for the fields to be added - might potentially // want to read any field value in the existing record - to determine // the new field's value. // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_basepressMysql\ // get_zero_or_more_records( // $sql // ) // - - - - - - - - - - - - - - - - - - - - - // NOTES! // ====== // 1. The INPUT $sql should NOT be escaped. // // 2. MySQL Data Types AREN'T PRESERVED! // ---------------------------------- // In other words, something stored in the DB as a MySQL INT, WON'T // necessarily be returned as a PHP INT. It comes back as a STRING. // // I haven't checked FLOATs and TIMESTAMPS, etc. But I assume that // the same applies to them. // // Why this happens I'm not sure. But presumably, since we access // the database with the WordPress Wpdb class - it's that class's // fault. // // RETURNS // On SUCCESS // - - - - - // The 0+ records specified by the SQL string (as a PHP numeric // array of records). Eg:- // // $records = array( // 0 => array( // 'field_name_1' => , // 'field_name_2' => , // ... ... // 'field_name_N' => // ) // ... // ) // // On FAILURE // - - - - - // An error message STRING. // ------------------------------------------------------------------------- $sql = << 0 ) { // --------------------------------------------------------------------- // Walk over the fields to add, in turn... // --------------------------------------------------------------------- foreach ( $fields_to_add_by_field_slug as $this_field_slug => $this_field_definition ) { // ----------------------------------------------------------------- // Get the "get new field value" function (and it's args, if any)... // ----------------------------------------------------------------- $get_new_mysql_field_value_function_name = $selected_datasets_dmdd['get_new_field_value_functions'][ $this_field_slug ]['name'] ; // ----------------------------------------------------------------- if ( array_key_exists( 'args' , $selected_datasets_dmdd['get_new_field_value_functions'][ $this_field_slug ] ) ) { $get_new_field_value_function_args = $selected_datasets_dmdd['get_new_field_value_functions'][ $this_field_slug ]['args'] ; } else { $get_new_field_value_function_args = NULL ; } // ----------------------------------------------------------------- $distinct_values_and_their_record_ids = array() ; // ----------------------------------------------------------------- // Walk over the table records - collecting all the distinct values // to add... // ----------------------------------------------------------------- foreach ( $all_table_records_by_record_id as $this_record_id => $this_record ) { // ------------------------------------------------------------------------- // ( // $core_plugapp_dirs , // $selected_datasets_dmdd , // $dataset_slug , // $field_slug_to_add , // $all_table_records_by_record_id , // $this_record , // $get_new_field_value_function_args // ) // - - - - - - - - - - - - - - - - - - - - - - - // Returns the value for the specified field to be added to the // specified record. // // RETURNS // On SUCCESS // array( // $ok = TRUE // $new_field_value (any PHP type) // ) // // On FAILURE // array( // $ok = FALSE // $error_message STRING // ) // ------------------------------------------------------------------------- $result = $get_new_mysql_field_value_function_name( $core_plugapp_dirs , $selected_datasets_dmdd , $dataset_slug , $this_field_slug , $all_table_records_by_record_id , $this_record , $get_new_field_value_function_args ) ; // --------------------------------------------------------- list( $ok , $new_field_value ) = $result ; // --------------------------------------------------------- if ( $ok === FALSE ) { return $new_field_value ; } // ------------------------------------------------------------------------- // get_list_index_4_value( // $list , // $target_value // ) // - - - - - - - - - - - - // Searches a list of records like:- // array( // array( // 'value' => // 'record_ids' => array(...) // ) // ... // ) // // for the specified value. // // RETURNS // $list_index = NULL (if target value NOT found) // --OR-- // $list_index = INT 0+ (if target value found) // ------------------------------------------------------------------------- $list_index = get_list_index_4_value( $distinct_values_and_their_record_ids , $new_field_value ) ; // --------------------------------------------------------- if ( is_int( $list_index ) ) { $distinct_values_and_their_record_ids[ $list_index ]['record_ids'][] = $this_record_id ; } else { $distinct_values_and_their_record_ids[] = array( 'value' => $new_field_value , 'record_ids' => array( $this_record_id ) ) ; } // ------------------------------------------------------------- } // ----------------------------------------------------------------- $distinct_values_and_their_record_ids__by_field_slug__to_add[ $this_field_slug ] = $distinct_values_and_their_record_ids ; // ----------------------------------------------------------------- } // --------------------------------------------------------------------- } // ------------------------------------------------------------------------- // Here we should have (eg):- // // $distinct_values_and_their_record_ids__by_field_slug__to_add = Array( // // [new_field_one] => Array( // // [0] => Array( // [value] => 17 Dec 2015 1:45:20 GMT // [record_ids] => Array( // [0] => 1 // ) // ) // // ... // // ) // // ... // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $distinct_values_and_their_record_ids__by_field_slug__to_add , // '$distinct_values_and_their_record_ids__by_field_slug__to_add' // ) ; //foreach ( $distinct_values_and_their_record_ids__by_field_slug__to_add as $this_slug => $distinct_values_and_their_record_ids ) { // foreach ( $distinct_values_and_their_record_ids as $this_record ) { // echo '
' ; // var_dump( $this_record['value'] ) ; // } //} // ========================================================================= // Get the DISTINCT VALUES to UPDATE... // ========================================================================= $distinct_values_and_their_record_ids__by_field_slug__to_update = array() ; // ------------------------------------------------------------------------- if ( count( $fields_to_update_by_field_slug ) > 0 ) { // --------------------------------------------------------------------- // Walk over the fields to update, in turn... // --------------------------------------------------------------------- foreach ( $fields_to_update_by_field_slug as $this_field_slug => $this_field_definition ) { // ----------------------------------------------------------------- // Walk over the table records - collecting the distinct value to // update... // ----------------------------------------------------------------- $distinct_values_and_their_record_ids = array() ; // ----------------------------------------------------------------- foreach ( $all_table_records_by_record_id as $this_record_id => $this_record ) { // ------------------------------------------------------------- $this_field_value = $this_record[ $this_field_slug ] ; // ------------------------------------------------------------------------- // get_list_index_4_value( // $list , // $target_value // ) // - - - - - - - - - - - - // Searches a list of records like:- // array( // array( // 'value' => // 'record_ids' => array(...) // ) // ... // ) // // for the specified value. // // RETURNS // $list_index = NULL (if target value NOT found) // --OR-- // $list_index = INT 0+ (if target value found) // ------------------------------------------------------------------------- $list_index = get_list_index_4_value( $distinct_values_and_their_record_ids , $this_field_value ) ; // --------------------------------------------------------- if ( is_int( $list_index ) ) { $distinct_values_and_their_record_ids[ $list_index ]['record_ids'][] = $this_record_id ; } else { $distinct_values_and_their_record_ids[] = array( 'value' => $this_field_value , 'record_ids' => array( $this_record_id ) ) ; } // ------------------------------------------------------------- } // ----------------------------------------------------------------- $distinct_values_and_their_record_ids__by_field_slug__to_update[ $this_field_slug ] = $distinct_values_and_their_record_ids ; // ----------------------------------------------------------------- } // --------------------------------------------------------------------- } // ------------------------------------------------------------------------- // Here we should have (eg):- // // $distinct_values_and_their_record_ids__by_field_slug__to_update = Array( // // [new_field_one] => Array( // // [0] => Array( // [value] => 17 Dec 2015 1:45:20 GMT // [record_ids] => Array( // [0] => 1 // ) // ) // // ... // // ) // // ... // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $distinct_values_and_their_record_ids__by_field_slug__to_update , // '$distinct_values_and_their_record_ids__by_field_slug__to_update' // ) ; //foreach ( $distinct_values_and_their_record_ids__by_field_slug__to_update as $this_slug => $distinct_values_and_their_record_ids ) { // foreach ( $distinct_values_and_their_record_ids as $this_record ) { // echo '
' ; // var_dump( $this_record['value'] ) ; // } //} // ========================================================================= // Get the DISTINCT VALUES to REMOVE... // ========================================================================= $distinct_values_and_their_record_ids__by_field_slug__to_remove = array() ; // ------------------------------------------------------------------------- if ( count( $fields_to_remove_by_field_slug ) > 0 ) { // --------------------------------------------------------------------- // Walk over the fields to remove, in turn... // --------------------------------------------------------------------- foreach ( $fields_to_remove_by_field_slug as $this_field_slug => $this_field_definition ) { // ----------------------------------------------------------------- // Walk over the table records - collecting the distinct value to // remove... // ----------------------------------------------------------------- $distinct_values_and_their_record_ids = array() ; // ----------------------------------------------------------------- foreach ( $all_table_records_by_record_id as $this_record_id => $this_record ) { // ------------------------------------------------------------- $this_field_value = $this_record[ $this_field_slug ] ; // ------------------------------------------------------------------------- // get_list_index_4_value( // $list , // $target_value // ) // - - - - - - - - - - - - // Searches a list of records like:- // array( // array( // 'value' => // 'record_ids' => array(...) // ) // ... // ) // // for the specified value. // // RETURNS // $list_index = NULL (if target value NOT found) // --OR-- // $list_index = INT 0+ (if target value found) // ------------------------------------------------------------------------- $list_index = get_list_index_4_value( $distinct_values_and_their_record_ids , $this_field_value ) ; // --------------------------------------------------------- if ( is_int( $list_index ) ) { $distinct_values_and_their_record_ids[ $list_index ]['record_ids'][] = $this_record_id ; } else { $distinct_values_and_their_record_ids[] = array( 'value' => $this_field_value , 'record_ids' => array( $this_record_id ) ) ; } // ------------------------------------------------------------- } // ----------------------------------------------------------------- $distinct_values_and_their_record_ids__by_field_slug__to_remove[ $this_field_slug ] = $distinct_values_and_their_record_ids ; // ----------------------------------------------------------------- } // --------------------------------------------------------------------- } // ------------------------------------------------------------------------- // Here we should have (eg):- // // $distinct_values_and_their_record_ids__by_field_slug__to_remove = Array( // // [new_field_one] => Array( // // [0] => Array( // [value] => 17 Dec 2015 1:45:20 GMT // [record_ids] => Array( // [0] => 1 // ) // ) // // ... // // ) // // ... // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $distinct_values_and_their_record_ids__by_field_slug__to_remove , // '$distinct_values_and_their_record_ids__by_field_slug__to_remove' // ) ; //foreach ( $distinct_values_and_their_record_ids__by_field_slug__to_remove as $this_slug => $distinct_values_and_their_record_ids ) { // foreach ( $distinct_values_and_their_record_ids as $this_record ) { // echo '
' ; // var_dump( $this_record['value'] ) ; // } //} // ========================================================================= // Do the requested MANUAL UPDATING (for the currently selected dataset)... // ========================================================================= if ( $this_dataset_update_method === 'manual' && array_key_exists( 'updaction' , $_GET ) && trim( $_GET['updaction'] ) !== '' && ctype_xdigit( $_GET['updaction'] ) ) { // --------------------------------------------------------------------- require_once( dirname( __FILE__ ) . '/update-and-save-mysql-stored-dataset-data.php' ) ; // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_standardDatasetManager\ // do_updaction_4_mysql_table( // $core_plugapp_dirs , // $dataset_slug , // $selected_datasets_dmdd , // $mysql_table_name , // $all_table_records_by_record_id , // $fields_to_add_by_field_slug , // $fields_to_update_by_field_slug , // $fields_to_remove_by_field_slug , // $distinct_values_and_their_record_ids__by_field_slug__to_add , // $distinct_values_and_their_record_ids__by_field_slug__to_update , // $distinct_values_and_their_record_ids__by_field_slug__to_remove // ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Does the dataset updating requested by:- // $_GET['updaction'] // // Then saves the updated dataset back to array storage - and re-loads the // current page. // // RETURNS // On SUCCESS // FALSE Means NO "updaction" was requested for this dataset. // So we should continue with the "auto" or "manual" // updating. // NOTE! If "updaction" WAS requested for this dataset - and // was completed successfully - then this routine // DOESN'T return. // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- $result = do_updaction_4_mysql_table( $core_plugapp_dirs , $dataset_slug , $selected_datasets_dmdd , $mysql_table_name , $all_table_records_by_record_id , $fields_to_add_by_field_slug , $fields_to_update_by_field_slug , $fields_to_remove_by_field_slug , $distinct_values_and_their_record_ids__by_field_slug__to_add , $distinct_values_and_their_record_ids__by_field_slug__to_update , $distinct_values_and_their_record_ids__by_field_slug__to_remove ) ; // --------------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // --------------------------------------------------------------------- // Fall through to do this dataset's "auto" or "manual" updating... // --------------------------------------------------------------------- } // ========================================================================= // Display the "MANUAL APPROVAL" page ? // ========================================================================= if ( $this_dataset_update_method === 'manual' ) { // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_standardDatasetManager\ // get_manual_approval_page_html_4_mysql_table( // $core_plugapp_dirs , // $selected_datasets_dmdd , // $dataset_slug , // $all_table_records_by_record_id , // $fields_to_add_by_field_slug , // $fields_to_update_by_field_slug , // $fields_to_remove_by_field_slug , // $distinct_values_and_their_record_ids__by_field_slug__to_add , // $distinct_values_and_their_record_ids__by_field_slug__to_update , // $distinct_values_and_their_record_ids__by_field_slug__to_remove // ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Creates and returns a page like (eg):- // // Database Update Required // Database Update Required // // Dataset: array_stored_test_dataset_one // // 2 fields to ADD - to 3 records - as follows:- // ============================================================================================== // Field Name #Records To Add #Distinct Values #Records NOT To Action // This Field To To Add Add This Field To // ============== ================== ====================== ================== ============== // new_field_one All (3 records) 3 show distinct values None add this field // new_field_two All (3 records) 1 show distinct values None add this field // ============================================================================================== // // ADD ALL The Above Fields // // 1 field to REMOVE - from 3 records - as follows:- // ============================================================================================== // Field Name #Records To Remove #Distinct Values #Records NOT To Action // This Field From To Remove Remove This Field From // ============== ================== ====================== ========================== ====== // new_field_three All (3 records) 1 show distinct values None // ============================================================================================== // // UPDATE ENTIRE DATASET // (ADD ALL Fields To Be Added - Then REMOVE ALL Fields To Be Removed) // // RETURNS // On SUCCESS // array( // $manual_approval_page_html__4_dataset STRING , // $distinct_value_summary_pages__4_dataset STRING , // $record_listing_pages__4_dataset STRING // ) // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- return get_manual_approval_page_html_4_mysql_table( $core_plugapp_dirs , $selected_datasets_dmdd , $dataset_slug , $all_table_records_by_record_id , $fields_to_add_by_field_slug , $fields_to_update_by_field_slug , $fields_to_remove_by_field_slug , $distinct_values_and_their_record_ids__by_field_slug__to_add , $distinct_values_and_their_record_ids__by_field_slug__to_update , $distinct_values_and_their_record_ids__by_field_slug__to_remove ) ; // --------------------------------------------------------------------- } // ========================================================================= // AUTO-UPDATE ? // ========================================================================= /* if ( $this_dataset_update_method === 'auto' ) { // --------------------------------------------------------------------- // Create the updated dataset... // --------------------------------------------------------------------- $new_dataset_records = $loaded_datasets[ $dataset_slug ]['records'] ; // --------------------------------------------------------------------- // ADD ALL // --------------------------------------------------------------------- foreach ( $distinct_values_and_their_record_ids__by_field_slug__to_add as $this_field_slug => $these_distinct_values_and_record_indices ) { // ----------------------------------------------------------------- foreach ( $these_distinct_values_and_record_indices as $this_distinct_value_and_its_record_indices ) { // ------------------------------------------------------------- $this_distinct_value = $this_distinct_value_and_its_record_indices['value'] ; // ------------------------------------------------------------- $these_record_indices = $this_distinct_value_and_its_record_indices['record_indices'] ; // ------------------------------------------------------------- foreach ( $these_record_indices as $this_target_index ) { // --------------------------------------------------------- $new_dataset_records[ $this_target_index ][ $this_field_slug ] = $this_distinct_value ; // --------------------------------------------------------- } // ------------------------------------------------------------- } // ----------------------------------------------------------------- } // --------------------------------------------------------------------- // REMOVE ALL // --------------------------------------------------------------------- foreach ( $distinct_values_and_their_record_ids__by_field_slug__to_remove as $this_field_slug => $these_distinct_values_and_record_indices ) { // ----------------------------------------------------------------- foreach ( $these_distinct_values_and_record_indices as $this_distinct_value_and_its_record_indices ) { // ------------------------------------------------------------- foreach ( $this_distinct_value_and_its_record_indices['record_indices'] as $this_target_index ) { // --------------------------------------------------------- unset( $new_dataset_records[ $this_target_index ][ $this_field_slug ] ) ; // --------------------------------------------------------- } // ------------------------------------------------------------- } // ----------------------------------------------------------------- } // --------------------------------------------------------------------- // Save the updated dataset... // --------------------------------------------------------------------- // ------------------------------------------------------------------------- // \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. // // NOTE! // ----- // Does:- // $array_to_save = array_values( $array_to_save ) ; // // to ensures it's indices are 0, 1, 2... (before saving it). // // --- // // $array_storage_data can be either:- // // o NULL (in which case:- // $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE'] // is used), or; // // o array( // 'default_storage_method' => "json" | "basepress-dataset" // 'json_data_files_dir' => NULL | "xxx" // 'supported_datasets' => $supported_datasets // ) // Where $supported_datasets is:- // array( // '' => array( // 'storage_method' => NULL | "json" | "basepress-dataset" , // 'json_filespec' => NULL | "xxx" , // 'basepress_dataset_handle' => $some_basepress_dataset_handle // ) // ... // ) // Where $some_basepress_dataset_handle is (eg):- // array( // 'nice_name' => 'adSwapper_byFerntec_someDatasetName' , // 'unique_key' => $some_basepress_dataset_uid , // 'version' => '0.1' // ) // Where $some_basepress_dataset_uid is (eg):- // '2f35c079-ef2e-4dea-a0e2-f1f861375aef' . '-' . // 'afe2576d-76b2-4a5c-83a3-60b652467438' . '-' . // '995a2d40-63d3-11e3-949a-0800200c9a66' . '-' . // 'a6acf950-63d3-11e3-949a-0800200c9a66' // ; // // RETURNS // o On SUCCESS // - - - - - // TRUE // // o On FAILURE // - - - - - // $error message STRING // ------------------------------------------------------------------------- $result = \greatKiwi_byFernTec_adSwapper_local_v0x1x211_arrayStorage\save_numerically_indexed( $dataset_slug , $new_dataset_records ) ; // --------------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // --------------------------------------------------------------------- return TRUE ; // Update required and successfully completed! // --------------------------------------------------------------------- } */ // ========================================================================= // SUCCESS // ========================================================================= return FALSE ; // Update required but NOT done! // ========================================================================= // That's that! // ========================================================================= } // ============================================================================= // question_mysql_column_defs_different() // ============================================================================= function question_mysql_column_defs_different( $this_field_definition , $that_field_definition ) { // -------------------------------------------------------------------------- // question_mysql_column_defs_different( // $this_field_definition , // $that_field_definition // ) // - - - - - - - - - - - - - - - - - // RETURNS // On SUCCESS // TRUE or FALSE // // On FAILURE // $error_message STRING // -------------------------------------------------------------------------- if ( count( $this_field_definition ) !== count( $that_field_definition ) ) { return TRUE ; } // -------------------------------------------------------------------------- // Here we should have (eg):- // // $this_field_definition / $that_field_definition = Array( // [Field] => id // [Type] => BIGINT(20) UNSIGNED // [Null] => NO // [Key] => PRI // [Default] => // [Extra] => AUTO_INCREMENT // ) // // ------------------------------------------------------------------------- $required_allowed_field_names = array( 'Field' , 'Type' , 'Null' , 'Key' , 'Default' , 'Extra' ) ; // ------------------------------------------------------------------------- foreach ( $required_allowed_field_names as $this_field_name ) { // --------------------------------------------------------------------- if ( ! array_key_exists( $this_field_name , $this_field_definition ) || ! array_key_exists( $this_field_name , $that_field_definition ) ) { return TRUE ; } // --------------------------------------------------------------------- // NOTE! // ===== // The "created_server_datetime" field of a MySQL table has a string // Default value like:- // 0000-00-00 00:00:00 // // But:- // get_corresponding_mysql_table_definition() // // includes double quotes around the Default value. Ie, we have:- // // $this_field_definition = Array( // [Field] => created_server_datetime // [Type] => DATETIME // [Null] => NO // [Key] => // [Default] => "0000-00-00 00:00:00" // [Extra] => // ) // // $that_field_definition = Array( // [Field] => created_server_datetime // [Type] => datetime // [Null] => NO // [Key] => // [Default] => 0000-00-00 00:00:00 // [Extra] => // ) // // where it's $this_field_definition that's created by:- // get_corresponding_mysql_table_definition() // // and $that_field_definition that's retrieved from the created // table. // // I'm not sure if that's a bug in:- // get_corresponding_mysql_table_definition() // // or whether there's a reason for the surrounding double quotes. // // So, to prevent problems, we special case this field. // --------------------------------------------------------------------- if ( $this_field_name === 'Default' && $this_field_definition['Field'] === 'created_server_datetime' && $that_field_definition['Field'] === 'created_server_datetime' ) { $this_field_definition[ $this_field_name ] = trim( $this_field_definition[ $this_field_name ] , '"' ) ; } // --------------------------------------------------------------------- if ( strtolower( $this_field_definition[ $this_field_name ] ) !== strtolower( $that_field_definition[ $this_field_name ] ) ) { return TRUE ; } // --------------------------------------------------------------------- } // -------------------------------------------------------------------------- return FALSE ; // -------------------------------------------------------------------------- } // ============================================================================= // get_manual_approval_page_html_4_mysql_table() // ============================================================================= function get_manual_approval_page_html_4_mysql_table( $core_plugapp_dirs , $selected_datasets_dmdd , $dataset_slug , $all_table_records_by_record_id , $fields_to_add_by_field_slug , $fields_to_update_by_field_slug , $fields_to_remove_by_field_slug , $distinct_values_and_their_record_ids__by_field_slug__to_add , $distinct_values_and_their_record_ids__by_field_slug__to_update , $distinct_values_and_their_record_ids__by_field_slug__to_remove ) { // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x211_standardDatasetManager\ // get_manual_approval_page_html_4_mysql_table( // $core_plugapp_dirs , // $selected_datasets_dmdd , // $dataset_slug , // $all_table_records_by_record_id , // $fields_to_add_by_field_slug , // $fields_to_update_by_field_slug , // $fields_to_remove_by_field_slug , // $distinct_values_and_their_record_ids__by_field_slug__to_add , // $distinct_values_and_their_record_ids__by_field_slug__to_update , // $distinct_values_and_their_record_ids__by_field_slug__to_remove // ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Creates and returns a page like (eg):- // // Database Update Required // Database Update Required // // Dataset: array_stored_test_dataset_one // // 2 fields to ADD - to 3 records - as follows:- // ============================================================================================== // Field Name #Records To Add #Distinct Values #Records NOT To Action // This Field To To Add Add This Field To // ============== ================== ====================== ================== ============== // new_field_one All (3 records) 3 show distinct values None add this field // new_field_two All (3 records) 1 show distinct values None add this field // ============================================================================================== // // ADD ALL The Above Fields // // 1 field to REMOVE - from 3 records - as follows:- // ============================================================================================== // Field Name #Records To Remove #Distinct Values #Records NOT To Action // This Field From To Remove Remove This Field From // ============== ================== ====================== ========================== ====== // new_field_three All (3 records) 1 show distinct values None // ============================================================================================== // // UPDATE ENTIRE DATASET // (ADD ALL Fields To Be Added - Then REMOVE ALL Fields To Be Removed) // // RETURNS // On SUCCESS // array( // $manual_approval_page_html__4_dataset STRING , // $distinct_value_summary_pages__4_dataset STRING , // $record_listing_pages__4_dataset STRING // ) // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // Here we should have (eg):- // // $fields_to_add_by_field_slug = Array( // // [new_field_one] => Array( // [Field] => new_field_one // [Type] => TEXT // [Null] => NO // [Key] => // [Default] => // [Extra] => // ) // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $fields_to_add_by_field_slug , // '$fields_to_add_by_field_slug' // ) ; // ------------------------------------------------------------------------- // Here we should have (eg):- // // $fields_to_update_by_field_slug = // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $fields_to_update_by_field_slug , // '$fields_to_update_by_field_slug' // ) ; // ------------------------------------------------------------------------- // Here we should have (eg):- // // $fields_to_remove_by_field_slug = // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $fields_to_remove_by_field_slug , // '$fields_to_remove_by_field_slug' // ) ; // ------------------------------------------------------------------------- // Here we should have (eg):- // // $distinct_values_and_their_record_ids__by_field_slug__to_add = Array( // // [new_field_one] => Array( // // [0] => Array( // [value] => 17 Dec 2015 1:45:20 GMT // [record_ids] => Array( // [0] => 1 // ) // ) // // ... // // ) // // ... // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $distinct_values_and_their_record_ids__by_field_slug__to_add , // '$distinct_values_and_their_record_ids__by_field_slug__to_add' // ) ; // ------------------------------------------------------------------------- // Here we should have (eg):- // // $distinct_values_and_their_record_ids__by_field_slug__to_update = // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $distinct_values_and_their_record_ids__by_field_slug__to_update , // '$distinct_values_and_their_record_ids__by_field_slug__to_update' // ) ; // ------------------------------------------------------------------------- // Here we should have (eg):- // // $distinct_values_and_their_record_ids__by_field_slug__to_remove = // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $distinct_values_and_their_record_ids__by_field_slug__to_remove , // '$distinct_values_and_their_record_ids__by_field_slug__to_remove' // ) ; // ========================================================================= // Init. // ========================================================================= $ns = __NAMESPACE__ ; $fn = __FUNCTION__ ; // ------------------------------------------------------------------------- $total_records = count( $all_table_records_by_record_id ) ; // ------------------------------------------------------------------------- $intro_style = << $distinct_values_and_their_record_ids ) { // --------------------------------------------------------------------- // Here we should have (eg):- // // $distinct_values_and_their_record_ids = Array( // // [0] => Array( // [value] => 17 Dec 2015 1:45:20 GMT // [record_ids] => Array( // [0] => 1 // ) // ) // // ... // // ) // // --------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $distinct_values_and_their_record_ids , // '$distinct_values_and_their_record_ids' // ) ; // ===================================================================== // Get the $record_ids_to_add_this_field_to... // ===================================================================== $record_ids_to_add_this_field_to = array() ; // --------------------------------------------------------------------- foreach ( $distinct_values_and_their_record_ids as $this_index => $this_distinct_value_and_its_record_ids ) { // ----------------------------------------------------------------- // Here we should have (eg):- // // $this_distinct_value_and_its_record_ids = Array( // [value] => 17 Dec 2015 1:45:20 GMT // [record_ids] => Array( // [0] => 1 // ) // ) // // ----------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x211_testDebug\pr( // $this_distinct_value_and_its_record_ids , // '$this_distinct_value_and_its_record_ids' // ) ; // ----------------------------------------------------------------- $record_ids_to_add_this_field_to = array_merge( $record_ids_to_add_this_field_to , $this_distinct_value_and_its_record_ids['record_ids'] ) ; // ----------------------------------------------------------------- } // ===================================================================== // Get the "show_distinct_values" DIV ID... // ===================================================================== $id = <<show distinct values EOT; // ===================================================================== // Add the field slug row... // ===================================================================== // ------------------------------------------------------------------------- // get_updaction_url( // $core_plugapp_dirs , // $args // ) // - - - - - - - - - - - - - - - // Adds the "updaction" parameters specified in $args, to the current // page url. // // $args should be like (eg):- // // $args = array( // 'dataset' => $dataset_slug , // 'field' => $this_field_slug , // 'action' => 'add-this-field' // ) // // RETURNS // On SUCCESS // $url STRING // // On FAILURE // array( $error_message STRING ) // ------------------------------------------------------------------------- $url = get_updaction_url( $core_plugapp_dirs , array( 'dataset' => $dataset_slug , 'field' => $this_field_slug , 'action' => 'add-this-field' ) ) ; // --------------------------------------------------------------------- if ( is_array( $url ) ) { return $url[0] ; } // --------------------------------------------------------------------- $action = <<add this field EOT; // --------------------------------------------------------------------- $fields_to_add_html .= << {$this_field_slug} {$number_records_to_add_this_field_to__pretty} {$number_distinct_values__pretty} {$number_records_NOT_to_add_this_field_to__pretty} {$action} EOT; // ===================================================================== // Get the distinct values (for this field slug)... // ===================================================================== // ------------------------------------------------------------------------- // get_distinct_values_for_field__summary_and_record_listing_pages__mysql( // $core_plugapp_dirs , // $all_table_records_by_record_id , // $dataset_slug , // $field_slug , // $distinct_values_and_their_record_ids , // $add_update_remove // ) // - - - - - - - - - - - - - - - - - - - - - - - - - // RETURNS // array( // $distinct_values_summary_pages__4_field STRING // $record_listing_pages__4_field STRING // ) // ------------------------------------------------------------------------- list( $distinct_values_summary_pages__4_field , $record_listing_pages__4_field ) = get_distinct_values_for_field__summary_and_record_listing_pages__mysql( $core_plugapp_dirs , $all_table_records_by_record_id , $dataset_slug , $this_field_slug , $distinct_values_and_their_record_ids , $add_update_remove ) ; // --------------------------------------------------------------------- $distinct_value_summary_pages__4_dataset .= <<