| 1 |
<?php |
| 2 |
/** |
| 3 |
* Data Table Builder list view. |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
$tables = get_posts([ |
| 13 |
'post_type' => \King_Addons\Data_Table_Builder::POST_TYPE, |
| 14 |
'post_status' => 'publish', |
| 15 |
'posts_per_page' => 50, |
| 16 |
'orderby' => 'date', |
| 17 |
'order' => 'DESC', |
| 18 |
]); |
| 19 |
?> |
| 20 |
|
| 21 |
<div class="ka-card"> |
| 22 |
<div class="ka-card-header"> |
| 23 |
<span class="dashicons dashicons-grid-view purple"></span> |
| 24 |
<h2><?php esc_html_e('All Tables', 'king-addons'); ?></h2> |
| 25 |
</div> |
| 26 |
<div class="ka-card-body" style="padding:0;"> |
| 27 |
<?php if (empty($tables)) : ?> |
| 28 |
<div class="ka-empty"> |
| 29 |
<span class="dashicons dashicons-grid-view"></span> |
| 30 |
<p><?php esc_html_e('No tables found.', 'king-addons'); ?></p> |
| 31 |
</div> |
| 32 |
<?php else : ?> |
| 33 |
<table class="ka-table"> |
| 34 |
<thead> |
| 35 |
<tr> |
| 36 |
<th><?php esc_html_e('Table', 'king-addons'); ?></th> |
| 37 |
<th><?php esc_html_e('Shortcode', 'king-addons'); ?></th> |
| 38 |
<th class="text-center"><?php esc_html_e('Rows', 'king-addons'); ?></th> |
| 39 |
<th class="text-center"><?php esc_html_e('Columns', 'king-addons'); ?></th> |
| 40 |
<th><?php esc_html_e('Updated', 'king-addons'); ?></th> |
| 41 |
<th><?php esc_html_e('Actions', 'king-addons'); ?></th> |
| 42 |
</tr> |
| 43 |
</thead> |
| 44 |
<tbody> |
| 45 |
<?php foreach ($tables as $table) : |
| 46 |
$data = get_post_meta($table->ID, \King_Addons\Data_Table_Builder::META_DATA, true); |
| 47 |
$rows = is_array($data) && isset($data['rows']) && is_array($data['rows']) ? count($data['rows']) : 0; |
| 48 |
$cols = is_array($data) && isset($data['columns']) && is_array($data['columns']) ? count($data['columns']) : 0; |
| 49 |
|
| 50 |
$edit_url = add_query_arg([ |
| 51 |
'page' => 'king-addons-table-builder', |
| 52 |
'view' => 'add', |
| 53 |
'table_id' => $table->ID, |
| 54 |
], admin_url('admin.php')); |
| 55 |
|
| 56 |
$duplicate_url = wp_nonce_url( |
| 57 |
add_query_arg([ |
| 58 |
'action' => 'kng_table_duplicate', |
| 59 |
'table_id' => $table->ID, |
| 60 |
], admin_url('admin-post.php')), |
| 61 |
'kng_table_duplicate_' . $table->ID |
| 62 |
); |
| 63 |
|
| 64 |
$delete_url = wp_nonce_url( |
| 65 |
add_query_arg([ |
| 66 |
'action' => 'kng_table_delete', |
| 67 |
'table_id' => $table->ID, |
| 68 |
], admin_url('admin-post.php')), |
| 69 |
'kng_table_delete_' . $table->ID |
| 70 |
); |
| 71 |
|
| 72 |
$export_url = wp_nonce_url( |
| 73 |
add_query_arg([ |
| 74 |
'action' => 'kng_table_export', |
| 75 |
'table_id' => $table->ID, |
| 76 |
], admin_url('admin-post.php')), |
| 77 |
'kng_table_export_' . $table->ID |
| 78 |
); |
| 79 |
?> |
| 80 |
<tr> |
| 81 |
<td> |
| 82 |
<strong><?php echo esc_html($table->post_title); ?></strong> |
| 83 |
</td> |
| 84 |
<td> |
| 85 |
<code>[kng_table id="<?php echo esc_attr($table->ID); ?>"]</code> |
| 86 |
</td> |
| 87 |
<td class="text-center"><?php echo esc_html(number_format_i18n($rows)); ?></td> |
| 88 |
<td class="text-center"><?php echo esc_html(number_format_i18n($cols)); ?></td> |
| 89 |
<td><?php echo esc_html(mysql2date('Y-m-d', $table->post_modified)); ?></td> |
| 90 |
<td> |
| 91 |
<div class="kng-table-actions"> |
| 92 |
<a href="<?php echo esc_url($edit_url); ?>"><?php esc_html_e('Edit', 'king-addons'); ?></a> |
| 93 |
<a href="<?php echo esc_url($duplicate_url); ?>"><?php esc_html_e('Duplicate', 'king-addons'); ?></a> |
| 94 |
<a href="<?php echo esc_url($export_url); ?>"><?php esc_html_e('Export CSV', 'king-addons'); ?></a> |
| 95 |
<a href="<?php echo esc_url($delete_url); ?>" onclick="return confirm('<?php echo esc_js(__('Delete this table?', 'king-addons')); ?>');"> |
| 96 |
<?php esc_html_e('Delete', 'king-addons'); ?> |
| 97 |
</a> |
| 98 |
</div> |
| 99 |
</td> |
| 100 |
</tr> |
| 101 |
<?php endforeach; ?> |
| 102 |
</tbody> |
| 103 |
</table> |
| 104 |
<?php endif; ?> |
| 105 |
</div> |
| 106 |
</div> |
| 107 |
|