start work on traffic-view refactoring

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-09-07 12:56:02 +02:00
parent 5f95293e0d
commit 6f2652f9dd
5 changed files with 252 additions and 44 deletions

View File

@@ -32,18 +32,33 @@ class Traffic
{
public static function getCustomerStats($userinfo, $range = null): array
{
$trafficCollection = (new Collection(\Froxlor\Api\Commands\Traffic::class, $userinfo, self::getParamsByRange($range, ['customer_traffic' => true,])))
->has('customer', Customers::class, 'customerid', 'customerid')
->get();
$trafficCollectionObj = (new Collection(\Froxlor\Api\Commands\Traffic::class, $userinfo, self::getParamsByRange($range, ['customer_traffic' => true,])));
if ($userinfo['adminsession'] == 1) {
$trafficCollectionObj->has('customer', Customers::class, 'customerid', 'customerid');
}
$trafficCollection = $trafficCollectionObj->get();
// build stats for each user
$users = [];
$years = [];
$months = [];
foreach ($trafficCollection['data']['list'] as $item) {
// per user total
$users[$item['customerid']]['loginname'] = $item['customer']['loginname'];
$users[$item['customerid']]['total'] += ($item['http'] + $item['ftp_up'] + $item['ftp_down'] + $item['mail']);
$users[$item['customerid']]['http'] += $item['http'];
$users[$item['customerid']]['ftp'] += ($item['ftp_up'] + $item['ftp_down']);
$users[$item['customerid']]['mail'] += $item['mail'];
// per year
$years[$item['year']]['total']['total'] += ($item['http'] + $item['ftp_up'] + $item['ftp_down'] + $item['mail']);
$years[$item['year']]['total']['http'] += $item['http'];
$years[$item['year']]['total']['ftp'] += ($item['ftp_up'] + $item['ftp_down']);
$years[$item['year']]['total']['mail'] += $item['mail'];
// per month
$months[$item['year']][$item['month']]['total'] += ($item['http'] + $item['ftp_up'] + $item['ftp_down'] + $item['mail']);
$months[$item['year']][$item['month']]['http'] += $item['http'];
$months[$item['year']][$item['month']]['ftp'] += ($item['ftp_up'] + $item['ftp_down']);
$months[$item['year']][$item['month']]['mail'] += $item['mail'];
}
// calculate overview for given range from users
@@ -58,10 +73,12 @@ class Traffic
return [
'metrics' => $metrics,
'users' => $users,
'years' => $years,
'months' => $months
];
}
private static function getParamsByRange(string $range, array $params = [])
private static function getParamsByRange($range = null, array $params = [])
{
$dateParams = [];