Skip to content

Commit 307f708

Browse files
committed
Add statistics to module configuration
1 parent 5d43bd0 commit 307f708

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

everblock.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ public function getContent()
969969
'everblock_notifications' => $notifications,
970970
'everblock_form' => $this->renderForm(),
971971
'display_upgrade' => $displayUpgrade,
972+
'everblock_stats' => $this->getModuleStatistics(),
972973
]);
973974
$output = $this->context->smarty->fetch(
974975
$this->local_path . 'views/templates/admin/header.tpl'
@@ -1026,6 +1027,7 @@ protected function getConfigForm()
10261027

10271028
$tabs = [
10281029
'settings' => $this->l('Réglages'),
1030+
'stats' => $this->l('Statistiques'),
10291031
'meta_tools' => $this->l('Meta Tools'),
10301032
'google_maps' => $this->l('Google Maps'),
10311033
'migration' => $this->l('Migration des URL'),
@@ -1059,6 +1061,7 @@ protected function getConfigForm()
10591061

10601062
$docTemplates = [
10611063
'settings' => 'settings.tpl',
1064+
'stats' => 'stats.tpl',
10621065
'meta_tools' => 'meta_tools.tpl',
10631066
'google_maps' => 'google_maps.tpl',
10641067
'migration' => 'migration.tpl',
@@ -2148,6 +2151,52 @@ protected function getConfigFormValues()
21482151
return $configData;
21492152
}
21502153

2154+
protected function getModuleStatistics(): array
2155+
{
2156+
$idShop = (int) $this->context->shop->id;
2157+
$stats = [
2158+
'blocks_total' => $this->countTableRecords('everblock', 'id_shop = ' . $idShop),
2159+
'blocks_active' => $this->countTableRecords('everblock', 'id_shop = ' . $idShop . ' AND active = 1'),
2160+
'shortcodes' => $this->countTableRecords('everblock_shortcode', 'id_shop = ' . $idShop),
2161+
'faqs' => $this->countTableRecords('everblock_faq', 'id_shop = ' . $idShop),
2162+
'tabs' => $this->countTableRecords('everblock_tabs', 'id_shop = ' . $idShop),
2163+
'flags' => $this->countTableRecords('everblock_flags', 'id_shop = ' . $idShop),
2164+
'modals' => $this->countTableRecords('everblock_modal', 'id_shop = ' . $idShop),
2165+
'game_sessions' => $this->countTableRecords('everblock_game_play'),
2166+
];
2167+
2168+
return $stats;
2169+
}
2170+
2171+
protected function countTableRecords(string $table, string $whereClause = ''): int
2172+
{
2173+
if (!$this->moduleTableExists($table)) {
2174+
return 0;
2175+
}
2176+
2177+
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
2178+
$sql = sprintf(
2179+
'SELECT COUNT(*) FROM `%s`',
2180+
bqSQL(_DB_PREFIX_ . $table)
2181+
);
2182+
if ($whereClause !== '') {
2183+
$sql .= ' WHERE ' . $whereClause;
2184+
}
2185+
2186+
return (int) $db->getValue($sql);
2187+
}
2188+
2189+
protected function moduleTableExists(string $table): bool
2190+
{
2191+
$tableName = _DB_PREFIX_ . $table;
2192+
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
2193+
$pattern = str_replace(['_', '%'], ['\\_', '\\%'], pSQL($tableName));
2194+
$sql = sprintf("SHOW TABLES LIKE '%s'", $pattern);
2195+
$result = $db->executeS($sql);
2196+
2197+
return !empty($result);
2198+
}
2199+
21512200
public function postValidation()
21522201
{
21532202
if (Tools::isSubmit('submit' . $this->name . 'Module')) {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{*
2+
* 2019-2025 Team Ever
3+
*
4+
* NOTICE OF LICENSE
5+
*
6+
* This source file is subject to the Academic Free License (AFL 3.0)
7+
* that is bundled with this package in the file LICENSE.txt.
8+
* It is also available through the world-wide-web at this URL:
9+
* http://opensource.org/licenses/afl-3.0.php
10+
* If you did not receive a copy of the license and are unable to
11+
* obtain it through the world-wide-web, please send an email
12+
* to [email protected] so we can send you a copy immediately.
13+
*
14+
* @author Team Ever <https://www.team-ever.com/>
15+
* @copyright 2019-2025 Team Ever
16+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
17+
*}
18+
19+
<div class="card everblock-doc mt-3">
20+
<div class="card-body">
21+
<h3 class="card-title">
22+
<i class="icon-bar-chart"></i>
23+
{l s='Module statistics' mod='everblock'}
24+
</h3>
25+
<p class="mb-4">
26+
{l s='Get a quick overview of the content managed by Everblock directly from the configuration page.' mod='everblock'}
27+
</p>
28+
<div class="row text-center">
29+
<div class="col-md-3 col-sm-6 mb-3">
30+
<div class="everblock-stat">
31+
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.blocks_total|intval}</div>
32+
<div class="everblock-stat__label text-muted">{l s='Blocks' mod='everblock'}</div>
33+
</div>
34+
</div>
35+
<div class="col-md-3 col-sm-6 mb-3">
36+
<div class="everblock-stat">
37+
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.blocks_active|intval}</div>
38+
<div class="everblock-stat__label text-muted">{l s='Active blocks' mod='everblock'}</div>
39+
</div>
40+
</div>
41+
<div class="col-md-3 col-sm-6 mb-3">
42+
<div class="everblock-stat">
43+
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.shortcodes|intval}</div>
44+
<div class="everblock-stat__label text-muted">{l s='Shortcodes' mod='everblock'}</div>
45+
</div>
46+
</div>
47+
<div class="col-md-3 col-sm-6 mb-3">
48+
<div class="everblock-stat">
49+
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.faqs|intval}</div>
50+
<div class="everblock-stat__label text-muted">{l s='FAQ entries' mod='everblock'}</div>
51+
</div>
52+
</div>
53+
<div class="col-md-3 col-sm-6 mb-3">
54+
<div class="everblock-stat">
55+
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.tabs|intval}</div>
56+
<div class="everblock-stat__label text-muted">{l s='Product tabs' mod='everblock'}</div>
57+
</div>
58+
</div>
59+
<div class="col-md-3 col-sm-6 mb-3">
60+
<div class="everblock-stat">
61+
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.flags|intval}</div>
62+
<div class="everblock-stat__label text-muted">{l s='Flags' mod='everblock'}</div>
63+
</div>
64+
</div>
65+
<div class="col-md-3 col-sm-6 mb-3">
66+
<div class="everblock-stat">
67+
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.modals|intval}</div>
68+
<div class="everblock-stat__label text-muted">{l s='Modals' mod='everblock'}</div>
69+
</div>
70+
</div>
71+
<div class="col-md-3 col-sm-6 mb-3">
72+
<div class="everblock-stat">
73+
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.game_sessions|intval}</div>
74+
<div class="everblock-stat__label text-muted">{l s='Game sessions' mod='everblock'}</div>
75+
</div>
76+
</div>
77+
</div>
78+
</div>
79+
</div>

0 commit comments

Comments
 (0)