| 1 |
<?php |
| 2 |
/** |
| 3 |
* Data Table Builder dashboard view. |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
$count = wp_count_posts(\King_Addons\Data_Table_Builder::POST_TYPE); |
| 13 |
$total_tables = $count && isset($count->publish) ? (int) $count->publish : 0; |
| 14 |
|
| 15 |
$tables = get_posts([ |
| 16 |
'post_type' => \King_Addons\Data_Table_Builder::POST_TYPE, |
| 17 |
'post_status' => 'publish', |
| 18 |
'posts_per_page' => 50, |
| 19 |
]); |
| 20 |
|
| 21 |
$total_rows = 0; |
| 22 |
$top_table = null; |
| 23 |
$top_rows = 0; |
| 24 |
|
| 25 |
foreach ($tables as $table) { |
| 26 |
$data = get_post_meta($table->ID, \King_Addons\Data_Table_Builder::META_DATA, true); |
| 27 |
$rows = is_array($data) && isset($data['rows']) && is_array($data['rows']) ? count($data['rows']) : 0; |
| 28 |
$total_rows += $rows; |
| 29 |
if ($rows > $top_rows) { |
| 30 |
$top_rows = $rows; |
| 31 |
$top_table = $table; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
$recent_tables = get_posts([ |
| 36 |
'post_type' => \King_Addons\Data_Table_Builder::POST_TYPE, |
| 37 |
'post_status' => 'publish', |
| 38 |
'posts_per_page' => 5, |
| 39 |
'orderby' => 'date', |
| 40 |
'order' => 'DESC', |
| 41 |
]); |
| 42 |
?> |
| 43 |
|
| 44 |
<div class="ka-stats-grid"> |
| 45 |
<div class="ka-stat-card"> |
| 46 |
<div class="ka-stat-label"><?php esc_html_e('Total Tables', 'king-addons'); ?></div> |
| 47 |
<div class="ka-stat-value"><?php echo esc_html(number_format_i18n($total_tables)); ?></div> |
| 48 |
</div> |
| 49 |
<div class="ka-stat-card"> |
| 50 |
<div class="ka-stat-label"><?php esc_html_e('Total Rows', 'king-addons'); ?></div> |
| 51 |
<div class="ka-stat-value"><?php echo esc_html(number_format_i18n($total_rows)); ?></div> |
| 52 |
</div> |
| 53 |
<div class="ka-stat-card"> |
| 54 |
<div class="ka-stat-label"><?php esc_html_e('Top Table', 'king-addons'); ?></div> |
| 55 |
<?php if ($top_table) : ?> |
| 56 |
<div class="ka-stat-value" style="font-size:16px;line-height:1.3"> |
| 57 |
<div><?php echo esc_html($top_table->post_title); ?></div> |
| 58 |
<small><?php echo esc_html(number_format_i18n($top_rows)); ?> <?php esc_html_e('rows', 'king-addons'); ?></small> |
| 59 |
</div> |
| 60 |
<?php else : ?> |
| 61 |
<div class="ka-stat-value" style="font-size:16px;line-height:1.3"> |
| 62 |
<?php esc_html_e('No data yet', 'king-addons'); ?> |
| 63 |
</div> |
| 64 |
<?php endif; ?> |
| 65 |
</div> |
| 66 |
<div class="ka-stat-card"> |
| 67 |
<div class="ka-stat-label"><?php esc_html_e('Presets', 'king-addons'); ?></div> |
| 68 |
<div class="ka-stat-value">10</div> |
| 69 |
</div> |
| 70 |
</div> |
| 71 |
|
| 72 |
<div class="ka-card"> |
| 73 |
<div class="ka-card-header"> |
| 74 |
<span class="dashicons dashicons-clock purple"></span> |
| 75 |
<h2><?php esc_html_e('Recent Tables', 'king-addons'); ?></h2> |
| 76 |
</div> |
| 77 |
<div class="ka-card-body" style="padding:0;"> |
| 78 |
<?php if (empty($recent_tables)) : ?> |
| 79 |
<div class="ka-empty"> |
| 80 |
<span class="dashicons dashicons-grid-view"></span> |
| 81 |
<p><?php esc_html_e('Create your first table to start building.', 'king-addons'); ?></p> |
| 82 |
</div> |
| 83 |
<?php else : ?> |
| 84 |
<table class="ka-table"> |
| 85 |
<thead> |
| 86 |
<tr> |
| 87 |
<th><?php esc_html_e('Table', 'king-addons'); ?></th> |
| 88 |
<th class="text-center"><?php esc_html_e('Rows', 'king-addons'); ?></th> |
| 89 |
<th class="text-center"><?php esc_html_e('Columns', 'king-addons'); ?></th> |
| 90 |
<th><?php esc_html_e('Updated', 'king-addons'); ?></th> |
| 91 |
</tr> |
| 92 |
</thead> |
| 93 |
<tbody> |
| 94 |
<?php foreach ($recent_tables as $table) : |
| 95 |
$data = get_post_meta($table->ID, \King_Addons\Data_Table_Builder::META_DATA, true); |
| 96 |
$rows = is_array($data) && isset($data['rows']) && is_array($data['rows']) ? count($data['rows']) : 0; |
| 97 |
$cols = is_array($data) && isset($data['columns']) && is_array($data['columns']) ? count($data['columns']) : 0; |
| 98 |
?> |
| 99 |
<tr> |
| 100 |
<td> |
| 101 |
<strong><?php echo esc_html($table->post_title); ?></strong> |
| 102 |
<small><?php echo esc_html('[kng_table id="' . $table->ID . '"]'); ?></small> |
| 103 |
</td> |
| 104 |
<td class="text-center"><?php echo esc_html(number_format_i18n($rows)); ?></td> |
| 105 |
<td class="text-center"><?php echo esc_html(number_format_i18n($cols)); ?></td> |
| 106 |
<td><?php echo esc_html(mysql2date('Y-m-d', $table->post_modified)); ?></td> |
| 107 |
</tr> |
| 108 |
<?php endforeach; ?> |
| 109 |
</tbody> |
| 110 |
</table> |
| 111 |
<?php endif; ?> |
| 112 |
</div> |
| 113 |
</div> |
| 114 |
|
| 115 |
<div class="ka-upgrade-card"> |
| 116 |
<h2><?php esc_html_e('Unlock Pro Table Studio', 'king-addons'); ?></h2> |
| 117 |
<p><?php esc_html_e('Enable conditional formatting, advanced filters, and rich tooltips.', 'king-addons'); ?></p> |
| 118 |
<ul> |
| 119 |
<li><?php esc_html_e('Advanced filters and column types', 'king-addons'); ?></li> |
| 120 |
<li><?php esc_html_e('Row details, inline charts, and formulas', 'king-addons'); ?></li> |
| 121 |
<li><?php esc_html_e('Google Sheets sync and JSON/PDF export', 'king-addons'); ?></li> |
| 122 |
</ul> |
| 123 |
<a href="https://kingaddons.com/pricing/" target="_blank" class="ka-btn ka-btn-pink"> |
| 124 |
<?php esc_html_e('Upgrade to Pro', 'king-addons'); ?> |
| 125 |
</a> |
| 126 |
</div> |
| 127 |
|