function yasr_check_import_set_callback() { $multi_set_names = yasr_import_gdstar_multi_set(); echo "<div class=\"yasr-result-step-2\">"; //If multiple set are found if ($multi_set_names) { echo "<br /><strong>"; _e("I've found Multiple Set! Importing...", 'yet-another-stars-rating'); echo "</strong><br />"; //If multi set are found write in yasr_multi_set table $insert_multi_set = yasr_insert_gdstar_multi_set($multi_set_names); //If insert succes, go ahed if ($insert_multi_set) { echo " "; _e("Multi Set's name has been successfull imported.", 'yet-another-stars-rating'); echo "<br /><strong>"; _e("Now I'm going to import Multi Set data", 'yet-another-stars-rating'); echo "</strong> <br />"; //Import multiple set's values from GD star rating $multi_data = yasr_import_gdstar_multi_value(); //If set values are found, insert Gd Star multi values in yasr_multi_values if ($multi_data) { $insert_multidata = yasr_insert_gdstar_multi_value($multi_data); if ($insert_multidata) { echo " "; _e("All votes has been successfull imported.", 'yet-another-stars-rating'); echo "<br />"; echo "<button href=\"#\" class=\"button-delete\" id=\"end-import\">" . __('Done', 'yet-another-stars-rating') . "</button>"; } else { echo " "; _e("I've found Multiple Set's votes but I couldn't insert into db", 'yet-another-stars-rating'); echo "<br />"; } } else { echo " "; _e("I've found Multi Set but with no data", 'yet-another-stars-rating'); echo "<br />"; } } else { echo " "; _e("I've found Multi Sets names but I couldn't insert into db", 'yet-another-stars-rating'); echo "<br />"; } } else { echo " "; _e("Multisets were not found. Imported is done!", 'yet-another-stars-rating'); } echo "</div>"; die; }
function yasr_import_gdstar_multi_value() { global $wpdb; $table_gdsr_multis_values = $wpdb->prefix . 'gdsr_multis_values'; $table_gdsr_multis_data = $wpdb->prefix . 'gdsr_multis_data'; $table_gdsr_multis = $wpdb->prefix . 'gdsr_multis'; $multi_set_data = $wpdb->get_results(" SELECT d.post_id, \n\t\t\t\t\t\t\t v.user_votes, v.item_id, \n\t\t\t\t\t\t\t m.multi_id\n\t\t\t\t\t\t\t FROM {$table_gdsr_multis_values} AS v, {$table_gdsr_multis_data} AS d, {$wpdb->posts} AS p, {$table_gdsr_multis} AS m\n\t\t\t\t\t\t\t WHERE v.id = d.id\n\t\t\t\t\t\t\t AND 0 <> (\n\t\t\t\t\t\t\t SELECT SUM( user_votes )\n\t\t\t\t\t\t\t FROM {$table_gdsr_multis_values} AS tabin\n\t\t\t\t\t\t\t WHERE tabin.id = v.id )\n\t\t\t\t\t\t\t AND p.ID = d.post_id\n\t\t\t\t\t\t\t AND d.multi_id = m.multi_id\n\t\t\t\t\t\t\t AND p.post_status = 'publish'\n\t\t\t\t\t\t\t AND v.source = 'rvw' \n\t\t\t\t\t\t\t ORDER BY d.post_id, m.multi_id, v.item_id ASC "); //Import multi set name: if a multiset use != 5 stars, //then i search wich vote has that set and convert //the vote to fit 5 stars vote $old_multi_set = yasr_import_gdstar_multi_set(); foreach ($old_multi_set as $multi_set) { //Search wich set not use 5 stars if ($multi_set->stars != 5) { //Search in the $multi_set_data if some vote use a set with !=5 stars foreach ($multi_set_data as $data_row) { if ($data_row->multi_id == $multi_set->multi_id) { $data_row->user_votes = $data_row->user_votes / $multi_set->stars * 5; //Vote convertion } } //End foreach $multi_set_data } //End if $multi_set->stars != 5 } return $multi_set_data; }