Skip to content
Merged
Show file tree
Hide file tree
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
49 changes: 49 additions & 0 deletions everblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ public function getContent()
'everblock_notifications' => $notifications,
'everblock_form' => $this->renderForm(),
'display_upgrade' => $displayUpgrade,
'everblock_stats' => $this->getModuleStatistics(),
]);
$output = $this->context->smarty->fetch(
$this->local_path . 'views/templates/admin/header.tpl'
Expand Down Expand Up @@ -1026,6 +1027,7 @@ protected function getConfigForm()

$tabs = [
'settings' => $this->l('Réglages'),
'stats' => $this->l('Statistiques'),
'meta_tools' => $this->l('Meta Tools'),
'google_maps' => $this->l('Google Maps'),
'migration' => $this->l('Migration des URL'),
Expand Down Expand Up @@ -1059,6 +1061,7 @@ protected function getConfigForm()

$docTemplates = [
'settings' => 'settings.tpl',
'stats' => 'stats.tpl',
'meta_tools' => 'meta_tools.tpl',
'google_maps' => 'google_maps.tpl',
'migration' => 'migration.tpl',
Expand Down Expand Up @@ -2148,6 +2151,52 @@ protected function getConfigFormValues()
return $configData;
}

protected function getModuleStatistics(): array
{
$idShop = (int) $this->context->shop->id;
$stats = [
'blocks_total' => $this->countTableRecords('everblock', 'id_shop = ' . $idShop),
'blocks_active' => $this->countTableRecords('everblock', 'id_shop = ' . $idShop . ' AND active = 1'),
'shortcodes' => $this->countTableRecords('everblock_shortcode', 'id_shop = ' . $idShop),
'faqs' => $this->countTableRecords('everblock_faq', 'id_shop = ' . $idShop),
'tabs' => $this->countTableRecords('everblock_tabs', 'id_shop = ' . $idShop),
'flags' => $this->countTableRecords('everblock_flags', 'id_shop = ' . $idShop),
'modals' => $this->countTableRecords('everblock_modal', 'id_shop = ' . $idShop),
'game_sessions' => $this->countTableRecords('everblock_game_play'),
];

return $stats;
}

protected function countTableRecords(string $table, string $whereClause = ''): int
{
if (!$this->moduleTableExists($table)) {
return 0;
}

$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
$sql = sprintf(
'SELECT COUNT(*) FROM `%s`',
bqSQL(_DB_PREFIX_ . $table)
);
if ($whereClause !== '') {
$sql .= ' WHERE ' . $whereClause;
}

return (int) $db->getValue($sql);
}

protected function moduleTableExists(string $table): bool
{
$tableName = _DB_PREFIX_ . $table;
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
$pattern = str_replace(['_', '%'], ['\\_', '\\%'], pSQL($tableName));
$sql = sprintf("SHOW TABLES LIKE '%s'", $pattern);
$result = $db->executeS($sql);

return !empty($result);
}

public function postValidation()
{
if (Tools::isSubmit('submit' . $this->name . 'Module')) {
Expand Down
79 changes: 79 additions & 0 deletions views/templates/admin/config/docs/stats.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{*
* 2019-2025 Team Ever
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author Team Ever <https://www.team-ever.com/>
* @copyright 2019-2025 Team Ever
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*}

<div class="card everblock-doc mt-3">
<div class="card-body">
<h3 class="card-title">
<i class="icon-bar-chart"></i>
{l s='Module statistics' mod='everblock'}
</h3>
<p class="mb-4">
{l s='Get a quick overview of the content managed by Everblock directly from the configuration page.' mod='everblock'}
</p>
<div class="row text-center">
<div class="col-md-3 col-sm-6 mb-3">
<div class="everblock-stat">
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.blocks_total|intval}</div>
<div class="everblock-stat__label text-muted">{l s='Blocks' mod='everblock'}</div>
</div>
</div>
<div class="col-md-3 col-sm-6 mb-3">
<div class="everblock-stat">
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.blocks_active|intval}</div>
<div class="everblock-stat__label text-muted">{l s='Active blocks' mod='everblock'}</div>
</div>
</div>
<div class="col-md-3 col-sm-6 mb-3">
<div class="everblock-stat">
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.shortcodes|intval}</div>
<div class="everblock-stat__label text-muted">{l s='Shortcodes' mod='everblock'}</div>
</div>
</div>
<div class="col-md-3 col-sm-6 mb-3">
<div class="everblock-stat">
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.faqs|intval}</div>
<div class="everblock-stat__label text-muted">{l s='FAQ entries' mod='everblock'}</div>
</div>
</div>
<div class="col-md-3 col-sm-6 mb-3">
<div class="everblock-stat">
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.tabs|intval}</div>
<div class="everblock-stat__label text-muted">{l s='Product tabs' mod='everblock'}</div>
</div>
</div>
<div class="col-md-3 col-sm-6 mb-3">
<div class="everblock-stat">
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.flags|intval}</div>
<div class="everblock-stat__label text-muted">{l s='Flags' mod='everblock'}</div>
</div>
</div>
<div class="col-md-3 col-sm-6 mb-3">
<div class="everblock-stat">
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.modals|intval}</div>
<div class="everblock-stat__label text-muted">{l s='Modals' mod='everblock'}</div>
</div>
</div>
<div class="col-md-3 col-sm-6 mb-3">
<div class="everblock-stat">
<div class="everblock-stat__value h3 mb-1">{$everblock_stats.game_sessions|intval}</div>
<div class="everblock-stat__label text-muted">{l s='Game sessions' mod='everblock'}</div>
</div>
</div>
</div>
</div>
</div>
Loading