Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve transaction fetch flow #253

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions plugin/src/Helpers/WebpayTransactionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,30 @@ public function prepare_items()
{
global $wpdb;

$orderby = isset($_GET['orderby']) ? sanitize_sql_orderby($_GET['orderby']) : 'ID';
$order = isset($_GET['order']) ? sanitize_sql_orderby($_GET['order']) : 'DESC';
$orderByColumns = $this->get_sortable_columns();
$orderby = isset($_GET['orderby']) && array_key_exists($_GET['orderby'], $orderByColumns)
? esc_sql($_GET['orderby'])
: 'ID';

$paged = (empty($_GET['paged']) ||
!is_numeric($_GET['paged']) ||
$_GET['paged'] <= 0) ? 1 : esc_sql($_GET['paged']);
$order = isset($_GET['order']) && in_array(strtoupper($_GET['order']), ['ASC', 'DESC'])
? esc_sql(strtoupper($_GET['order']))
: 'DESC';

$paged = isset($_GET['paged']) ? absint($_GET['paged']) : 1;
$paged = $paged > 0 ? $paged : 1;

$perPage = 20;
$offset = ($paged - 1) * $perPage;

$totalItemsQuery = 'SELECT COUNT(*) FROM '.Transaction::getTableName();
$itemsQuery = 'SELECT * FROM '.Transaction::getTableName().' ORDER BY %i '.$order.' LIMIT %d, %d';

$totalItemsQuery = 'SELECT COUNT(*) FROM ' . esc_sql(Transaction::getTableName());
$totalItems = $wpdb->get_var($totalItemsQuery);

$totalPages = ceil($totalItems / $perPage);

$itemsQuery = "SELECT * FROM " . esc_sql(Transaction::getTableName()) . "
ORDER BY %i {$order}
LIMIT %d, %d";

$this->items = $wpdb->get_results($wpdb->prepare(
$itemsQuery,
[$orderby, (int)$offset, (int)$perPage]
Expand All @@ -98,7 +106,7 @@ public function prepare_items()

public function column_amount($item)
{
return '$'.number_format($item->amount, 0, ',', '.');
return '$' . number_format($item->amount, 0, ',', '.');
}

public function column_transaction_date($item)
Expand Down Expand Up @@ -142,7 +150,7 @@ public function column_token($item)
return '-';
}

return '<a href="" onclick="this.innerHTML=\''.$item->token.'\';return false; " title="Haz click para ver el token completo">...'.substr($item->token, -5).'</a>';
return '<a href="" onclick="this.innerHTML=\'' . $item->token . '\';return false; " title="Haz click para ver el token completo">...' . substr($item->token, -5) . '</a>';
}

public function column_default($item, $column_name)
Expand Down
Loading