@@ -969,6 +969,7 @@ public function getContent()
969
969
'everblock_notifications ' => $ notifications ,
970
970
'everblock_form ' => $ this ->renderForm (),
971
971
'display_upgrade ' => $ displayUpgrade ,
972
+ 'everblock_stats ' => $ this ->getModuleStatistics (),
972
973
]);
973
974
$ output = $ this ->context ->smarty ->fetch (
974
975
$ this ->local_path . 'views/templates/admin/header.tpl '
@@ -1026,6 +1027,7 @@ protected function getConfigForm()
1026
1027
1027
1028
$ tabs = [
1028
1029
'settings ' => $ this ->l ('Réglages ' ),
1030
+ 'stats ' => $ this ->l ('Statistiques ' ),
1029
1031
'meta_tools ' => $ this ->l ('Meta Tools ' ),
1030
1032
'google_maps ' => $ this ->l ('Google Maps ' ),
1031
1033
'migration ' => $ this ->l ('Migration des URL ' ),
@@ -1059,6 +1061,7 @@ protected function getConfigForm()
1059
1061
1060
1062
$ docTemplates = [
1061
1063
'settings ' => 'settings.tpl ' ,
1064
+ 'stats ' => 'stats.tpl ' ,
1062
1065
'meta_tools ' => 'meta_tools.tpl ' ,
1063
1066
'google_maps ' => 'google_maps.tpl ' ,
1064
1067
'migration ' => 'migration.tpl ' ,
@@ -2148,6 +2151,52 @@ protected function getConfigFormValues()
2148
2151
return $ configData ;
2149
2152
}
2150
2153
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
+
2151
2200
public function postValidation ()
2152
2201
{
2153
2202
if (Tools::isSubmit ('submit ' . $ this ->name . 'Module ' )) {
0 commit comments