From 5baf9edba6faf0f40a05d672d574b13cd556550e Mon Sep 17 00:00:00 2001 From: Tomasz Wolniewicz Date: Wed, 4 Dec 2024 09:55:31 +0100 Subject: [PATCH] Adding support for monthly download statistics --- core/AbstractProfile.php | 16 +++++++++++++++- schema/{2_1_2-2_1_2_1.sql => 2_1_2-2_1_3.sql} | 14 ++++++++++++++ schema/schema.sql | 14 ++++++++++++++ web/admin/overview_org.php | 6 ++++-- web/resources/css/cat.css.php | 10 +++++++++- 5 files changed, 56 insertions(+), 4 deletions(-) rename schema/{2_1_2-2_1_2_1.sql => 2_1_2-2_1_3.sql} (71%) diff --git a/core/AbstractProfile.php b/core/AbstractProfile.php index b3e1c97c4..296f7d0e8 100644 --- a/core/AbstractProfile.php +++ b/core/AbstractProfile.php @@ -588,6 +588,7 @@ public function incrementDownloadStats($device, $area, $openRoaming) if ($area == "admin" || $area == "user" || $area == "silverbullet") { $lang = $this->languageInstance->getLang(); $this->frontendHandle->exec("INSERT INTO downloads (profile_id, device_id, lang, openroaming, downloads_$area) VALUES (? ,?, ?, ?, 1) ON DUPLICATE KEY UPDATE downloads_$area = downloads_$area + 1", "issi", $this->identifier, $device, $lang, $openRoaming); + $this->frontendHandle->exec("INSERT INTO downloads_history (profile_id, device_id, downloads_$area, openroaming, stat_date) VALUES (?, ?, 1, ?, DATE_FORMAT(NOW(), '%Y-%m-01')) ON DUPLICATE KEY UPDATE downloads_$area = downloads_$area + 1", "isi", $this->identifier, $device, $openRoaming); // get eap_type from the downloads table $eapTypeQuery = $this->frontendHandle->exec("SELECT eap_type FROM downloads WHERE profile_id = ? AND device_id = ? AND lang = ?", "iss", $this->identifier, $device, $lang); // SELECT queries always return a resource, not a boolean @@ -634,10 +635,23 @@ public function getUserDownloadStats($device = NULL) $devlist = \devices\Devices::listDevices($this->identifier); foreach ($returnarray as $devId => $count) { if (isset($devlist[$devId])) { - $finalarray[$devlist[$devId]['display']] = $count; + $finalarray[$devlist[$devId]['display']]['current'] = $count; } } + + $monthlyList = []; + $monthly = $this->frontendHandle->exec("SELECT downloads_user,device_id FROM downloads_history WHERE profile_id=? AND stat_date=DATE_FORMAT(NOW(),'%Y-%m-01')", "i", $this->identifier); + while ($statsQuery = mysqli_fetch_object(/** @scrutinizer ignore-type */ $monthly)) { + $monthlyList[$statsQuery->device_id] = $statsQuery->downloads_user; + } + foreach ($monthlyList as $devId => $count) { + if (isset($devlist[$devId])) { + $finalarray[$devlist[$devId]['display']]['monthly'] = $count; + } + + } + \core\common\Entity::intoThePotatoes(); ksort($finalarray, SORT_STRING|SORT_FLAG_CASE); \core\common\Entity::outOfThePotatoes(); diff --git a/schema/2_1_2-2_1_2_1.sql b/schema/2_1_2-2_1_3.sql similarity index 71% rename from schema/2_1_2-2_1_2_1.sql rename to schema/2_1_2-2_1_3.sql index fdf01c867..97dd9acf2 100644 --- a/schema/2_1_2-2_1_2_1.sql +++ b/schema/2_1_2-2_1_3.sql @@ -26,3 +26,17 @@ ALTER TABLE profile ADD COLUMN `preference` int DEFAULT '1000'; + +CREATE TABLE `downloads_history` ( + `profile_id` int NOT NULL, + `device_id` varchar(32) NOT NULL, + `downloads_admin` int NOT NULL DEFAULT '0', + `downloads_user` int NOT NULL DEFAULT '0', + `downloads_silverbullet` int NOT NULL DEFAULT '0', + `openroaming` int DEFAULT '0', + `stat_date` date DEFAULT NULL, + UNIQUE KEY `profile_device` (`profile_id`,`device_id`,`stat_date`), + KEY `profile_id` (`profile_id`), + KEY `device_id` (`device_id`), + KEY `stat_date` (`stat_date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/schema.sql b/schema/schema.sql index 9b427f063..cadf924ee 100644 --- a/schema/schema.sql +++ b/schema/schema.sql @@ -223,6 +223,20 @@ CREATE TABLE `user_options` ( CONSTRAINT `foreign_key_options` FOREIGN KEY (`option_name`) REFERENCES `profile_option_dict` (`name`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `downloads_history` ( + `profile_id` int NOT NULL, + `device_id` varchar(32) NOT NULL, + `downloads_admin` int NOT NULL DEFAULT '0', + `downloads_user` int NOT NULL DEFAULT '0', + `downloads_silverbullet` int NOT NULL DEFAULT '0', + `openroaming` int DEFAULT '0', + `stat_date` date DEFAULT NULL, + UNIQUE KEY `profile_device` (`profile_id`,`device_id`,`stat_date`), + KEY `profile_id` (`profile_id`), + KEY `device_id` (`device_id`), + KEY `stat_date` (`stat_date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE VIEW `v_active_inst` AS select distinct `profile`.`inst_id` AS `inst_id` from `profile` where (`profile`.`showtime` = 1); INSERT INTO `profile_option_dict` VALUES diff --git a/web/admin/overview_org.php b/web/admin/overview_org.php index 8cd4d3dab..83b7abd3e 100644 --- a/web/admin/overview_org.php +++ b/web/admin/overview_org.php @@ -697,11 +697,13 @@ function displayClassicHotspotPropertyWidget($deploymentObject) {

- +
+ "._("global").""; $stats = $profile_list->getUserDownloadStats(); foreach ($stats as $dev => $count) { - echo ""; + echo ""; } ?>
"._("this month")."
$dev$count
$dev".$count['current']."".$count['monthly']."
diff --git a/web/resources/css/cat.css.php b/web/resources/css/cat.css.php index c311c56c4..f93fe8022 100644 --- a/web/resources/css/cat.css.php +++ b/web/resources/css/cat.css.php @@ -1045,5 +1045,13 @@ } .downloads tr td { -text-align: right; + text-align: ; + padding-left: 5px; + padding-right: 5px; + border-bottom-style: solid; + border-bottom-width: 1px; +} + +.downloads tr td:first-child { + text-align: ; } \ No newline at end of file