Skip to content

Commit

Permalink
Adding support for monthly download statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Wolniewicz committed Dec 4, 2024
1 parent 805df9c commit 5baf9ed
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
16 changes: 15 additions & 1 deletion core/AbstractProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions schema/2_1_2-2_1_2_1.sql → schema/2_1_2-2_1_3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 14 additions & 0 deletions schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions web/admin/overview_org.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,13 @@ function displayClassicHotspotPropertyWidget($deploymentObject) {
<p>
<strong><?php echo _("User Downloads"); ?></strong>
</p>
<table>
<table class="downloads">
<tr><td></td>
<?php
echo "<td>"._("global")."</td><td>"._("this month")."</td></tr>";
$stats = $profile_list->getUserDownloadStats();
foreach ($stats as $dev => $count) {
echo "<tr><td><strong>$dev</strong></td><td>$count</td></tr>";
echo "<tr><td><strong>$dev</strong></td><td>".$count['current']."</td><td>".$count['monthly']."</td></tr>";
}
?>
</table>
Expand Down
10 changes: 9 additions & 1 deletion web/resources/css/cat.css.php
Original file line number Diff line number Diff line change
Expand Up @@ -1045,5 +1045,13 @@
}

.downloads tr td {
text-align: right;
text-align: <?php echo $end;?>;
padding-left: 5px;
padding-right: 5px;
border-bottom-style: solid;
border-bottom-width: 1px;
}

.downloads tr td:first-child {
text-align: <?php echo $start;?>;
}

0 comments on commit 5baf9ed

Please sign in to comment.