| 1 |
<?php |
| 2 |
use SyncBasalam\Services\Products\FetchUnsyncProducts; |
| 3 |
use SyncBasalam\Admin\Components\ProductListComponents; |
| 4 |
|
| 5 |
defined('ABSPATH') || exit; |
| 6 |
|
| 7 |
$sync_basalam_sync_status_checker = new FetchUnsyncProducts(); |
| 8 |
|
| 9 |
$cursor = isset($_GET['unsync_cursor']) ? sanitize_text_field(wp_unslash($_GET['unsync_cursor'])) : null; |
| 10 |
$history = isset($_GET['unsync_history']) && is_array($_GET['unsync_history']) |
| 11 |
? array_values(array_filter(array_map('sanitize_text_field', wp_unslash($_GET['unsync_history'])))) |
| 12 |
: []; |
| 13 |
|
| 14 |
$hasPrev = false; |
| 15 |
$prevCursor = null; |
| 16 |
$prevHistory = $history; |
| 17 |
|
| 18 |
if (!empty($history)) { |
| 19 |
$hasPrev = true; |
| 20 |
$prevCursor = end($history); |
| 21 |
array_pop($prevHistory); |
| 22 |
} elseif (!empty($cursor)) { |
| 23 |
// If user opens a cursor page directly, previous page is the initial page (without cursor). |
| 24 |
$hasPrev = true; |
| 25 |
} |
| 26 |
|
| 27 |
$nextHistory = $history; |
| 28 |
if (!empty($cursor)) $nextHistory[] = $cursor; |
| 29 |
|
| 30 |
$nextCursor = null; |
| 31 |
|
| 32 |
$unsync_products = $sync_basalam_sync_status_checker->getUnsyncBasalamProducts($cursor, $nextCursor); |
| 33 |
|
| 34 |
if (!empty($unsync_products)) { |
| 35 |
ProductListComponents::renderUnsyncBasalamProductsTable($unsync_products); |
| 36 |
?> |
| 37 |
|
| 38 |
<div class="basalam-pagination basalam-pagination-flex"> |
| 39 |
<?php if ($hasPrev): |
| 40 |
$prevArgs = ['page' => 'basalam-show-products']; |
| 41 |
if (!empty($prevCursor)) $prevArgs['unsync_cursor'] = $prevCursor; |
| 42 |
if (!empty($prevHistory)) $prevArgs['unsync_history'] = $prevHistory; |
| 43 |
?> |
| 44 |
<a href="<?php echo esc_url(add_query_arg($prevArgs, admin_url('admin.php'))); ?>">قبلی</a> |
| 45 |
<?php endif; ?> |
| 46 |
|
| 47 |
<?php if (!empty($nextCursor)): ?> |
| 48 |
<?php |
| 49 |
$nextArgs = ['page' => 'basalam-show-products', 'unsync_cursor' => $nextCursor]; |
| 50 |
if (!empty($nextHistory)) $nextArgs['unsync_history'] = $nextHistory; |
| 51 |
?> |
| 52 |
<a href="<?php echo esc_url(add_query_arg($nextArgs, admin_url('admin.php'))); ?>">بعدی</a> |
| 53 |
<?php endif; ?> |
| 54 |
</div> |
| 55 |
<?php |
| 56 |
} else echo '<p class="basalam-p">� |
| 57 |
حصولی یافت نشد</p>'; |
| 58 |
|