Add update egd entries
This commit is contained in:
@@ -414,6 +414,66 @@ function go_form_delete_custom_field()
|
||||
add_action('admin_post_go_form_delete_custom_field', 'go_form_delete_custom_field');
|
||||
|
||||
// ========== Entry Edit Admin Action ==========
|
||||
function go_form_update_egd_data()
|
||||
{
|
||||
go_form_admin_action('update_egd_data');
|
||||
|
||||
if (!isset($_POST['value_one'])) {
|
||||
wp_redirect(admin_url('admin.php?page=go-form-settings'));
|
||||
exit;
|
||||
}
|
||||
|
||||
global $wpdb, $ranks;
|
||||
$form_id = intval($_POST['value_one']);
|
||||
$entries = go_form_get_entries($form_id);
|
||||
$updated_count = 0;
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
if (empty($entry->egd_number)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pin = trim($entry->egd_number);
|
||||
$url = 'https://europeangodatabase.eu/EGD/GetPlayerDataByPIN.php?pin=' . urlencode($pin);
|
||||
|
||||
$response = wp_remote_get($url, ['timeout' => 10]);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body($response);
|
||||
$data = json_decode($body, true);
|
||||
|
||||
if ($data && isset($data['retcode']) && $data['retcode'] === 'Ok') {
|
||||
// Map EGD Grade_n to our rank system
|
||||
// EGD Grade_n: 0=30k, 1=29k, ... 25=5k, 30=1d, ... 39=9d, 40=1p, ... 47=9p
|
||||
// Our ranks array: 0=30k, 1=29k, ... 25=5k, 30=1d, ... 39=9d, 40=1p, ... 47=9p
|
||||
// So we can use Grade_n directly as our rank value
|
||||
$new_rank = isset($data['Grade_n']) ? intval($data['Grade_n']) : $entry->rank;
|
||||
$new_rating = isset($data['Gor']) ? intval($data['Gor']) : $entry->rating;
|
||||
|
||||
// Only update if values changed
|
||||
if ($new_rank !== $entry->rank || $new_rating !== $entry->rating) {
|
||||
$wpdb->update(
|
||||
"{$wpdb->prefix}go_form_entries",
|
||||
['rank' => $new_rank, 'rating' => $new_rating],
|
||||
['id' => $entry->id]
|
||||
);
|
||||
$updated_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$redirect_url = add_query_arg(
|
||||
array('page' => 'go-form-settings', 'form_id' => $form_id, 'egd_updated' => $updated_count),
|
||||
admin_url('admin.php')
|
||||
);
|
||||
wp_redirect($redirect_url);
|
||||
exit;
|
||||
}
|
||||
add_action('admin_post_go_form_update_egd_data', 'go_form_update_egd_data');
|
||||
|
||||
function go_form_update_entry()
|
||||
{
|
||||
go_form_admin_action('update_entry');
|
||||
|
||||
Reference in New Issue
Block a user