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');
|
add_action('admin_post_go_form_delete_custom_field', 'go_form_delete_custom_field');
|
||||||
|
|
||||||
// ========== Entry Edit Admin Action ==========
|
// ========== 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()
|
function go_form_update_entry()
|
||||||
{
|
{
|
||||||
go_form_admin_action('update_entry');
|
go_form_admin_action('update_entry');
|
||||||
|
|||||||
@@ -15,10 +15,14 @@ if (isset($_GET['deleted_field']))
|
|||||||
echo '<div class="notice notice-success"><p>Custom field deleted!</p></div>';
|
echo '<div class="notice notice-success"><p>Custom field deleted!</p></div>';
|
||||||
if (isset($_GET['updated_entry']))
|
if (isset($_GET['updated_entry']))
|
||||||
echo '<div class="notice notice-success"><p>Entry updated!</p></div>';
|
echo '<div class="notice notice-success"><p>Entry updated!</p></div>';
|
||||||
|
if (isset($_GET['egd_updated']))
|
||||||
|
echo '<div class="notice notice-success"><p>' . esc_html($_GET['egd_updated']) . ' entries updated with EGD data!</p></div>';
|
||||||
if (isset($_GET['error']) && $_GET['error'] == 'missing_required')
|
if (isset($_GET['error']) && $_GET['error'] == 'missing_required')
|
||||||
echo '<div class="notice notice-error"><p>First Name and Last Name are required!</p></div>';
|
echo '<div class="notice notice-error"><p>First Name and Last Name are required!</p></div>';
|
||||||
if (isset($_GET['error']) && $_GET['error'] == 'missing_required_field')
|
if (isset($_GET['error']) && $_GET['error'] == 'missing_required_field')
|
||||||
echo '<div class="notice notice-error"><p>A required custom field is missing!</p></div>';
|
echo '<div class="notice notice-error"><p>A required custom field is missing!</p></div>';
|
||||||
|
if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
|
||||||
|
echo '<div class="notice notice-error"><p>Failed to update EGD data. Check error logs.</p></div>';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
@@ -41,6 +45,7 @@ if (isset($_GET['error']) && $_GET['error'] == 'missing_required_field')
|
|||||||
action_button('go_form_export_pairgoth', 'Export to Pairgoth', 'Confrm Export', $selected_form_id);
|
action_button('go_form_export_pairgoth', 'Export to Pairgoth', 'Confrm Export', $selected_form_id);
|
||||||
action_button('go_form_export_opengotha', 'Export to Opengoth', 'Confrm Export', $selected_form_id);
|
action_button('go_form_export_opengotha', 'Export to Opengoth', 'Confrm Export', $selected_form_id);
|
||||||
action_button('go_form_export_mcmahon', 'Export to McMahon', 'Confrm Export', $selected_form_id);
|
action_button('go_form_export_mcmahon', 'Export to McMahon', 'Confrm Export', $selected_form_id);
|
||||||
|
action_button('go_form_update_egd_data', 'Update EGD Data', 'Update rank and rating from EGD for all entries with EGD numbers?', $selected_form_id);
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user