Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit cc50ab7

Browse files
Merge pull request #6 from BaranekD/statBugFix
Fixed drawing correct data into table by selected time range
2 parents 5ea9b64 + ae204f9 commit cc50ab7

File tree

5 files changed

+15
-84
lines changed

5 files changed

+15
-84
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ All notable changes to this project will be documented in this file.
88
[Changed]
99
- DB commands work with apostrophes in IdP/SP names
1010
- New visual form of the site
11+
- Draw tables without month
12+
13+
[Fixed]
14+
- Draws tables data by selected time range
15+
16+
[Removed]
17+
- Removed unused functions
1118

1219
## [v1.3.0]
1320
[Added]

lib/Auth/Process/DatabaseCommand.php

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,6 @@ public static function getLoginCountPerDay($days)
7777
}
7878

7979

80-
public static function getLoginCountPerDeyPerService()
81-
{
82-
$databaseConnector = new DatabaseConnector();
83-
$conn = $databaseConnector->getConnection();
84-
assert($conn != NULL);
85-
$identityProvidersTableName = $databaseConnector->getIdentityProvidersTableName();
86-
$identityProvidersMapTableName = $databaseConnector->getIdentityProvidersMapTableName();
87-
$stmt = $conn->prepare("SELECT year, month, IFNULL(name,sourceIdp) AS idPName, SUM(count) AS count FROM ".$identityProvidersTableName. " LEFT OUTER JOIN " . $identityProvidersMapTableName . " ON sourceIdp = entityId GROUP BY year, month, sourceIdp HAVING sourceIdp != '' ORDER BY year DESC, month DESC, count DESC");
88-
$stmt->execute();
89-
$result = $stmt->get_result();
90-
while($row = $result->fetch_assoc()) {
91-
echo "[new Date(".$row["year"].",".($row["month"] - 1 )."),'".str_replace("'","\'",$row["idPName"])."', {v:".$row["count"]."}],";
92-
}
93-
$conn->close();
94-
}
95-
96-
public static function getAccessToServicesPerMonth()
97-
{
98-
$databaseConnector = new DatabaseConnector();
99-
$conn = $databaseConnector->getConnection();
100-
assert($conn != NULL);
101-
$serviceProvidersTableName = $databaseConnector->getServiceProvidersTableName();
102-
$serviceProvidersMapTableName = $databaseConnector->getServiceProvidersMapTableName();
103-
$stmt = $conn->prepare("SELECT year, month, IFNULL(name,service) AS spName, SUM(count) AS count FROM ".$serviceProvidersTableName." LEFT OUTER JOIN " . $serviceProvidersMapTableName . " ON service = identifier GROUP BY year DESC, month DESC, service HAVING service != '' ORDER BY year DESC, month DESC, count DESC");
104-
$stmt->execute();
105-
$result = $stmt->get_result();
106-
while($row = $result->fetch_assoc()) {
107-
echo "[new Date(".$row["year"].",".($row["month"] - 1 )."),'".str_replace("'","\'",$row["spName"])."', {v:".$row["count"]."}],";
108-
}
109-
$conn->close();
110-
}
111-
11280
public static function getCountOfAllLogins()
11381
{
11482
$databaseConnector = new DatabaseConnector();
@@ -160,9 +128,9 @@ public static function getAccessCountPerService($days)
160128
$serviceProvidersTableName = $databaseConnector->getServiceProvidersTableName();
161129
$serviceProvidersMapTableName = $databaseConnector->getServiceProvidersMapTableName();
162130
if($days == 0) { // 0 = all time
163-
$stmt = $conn->prepare("SELECT IFNULL(name,service) AS spName, SUM(count) AS count FROM " . $serviceProvidersTableName . " LEFT OUTER JOIN " . $serviceProvidersMapTableName . " ON service = identifier GROUP BY service HAVING service != ''");
131+
$stmt = $conn->prepare("SELECT IFNULL(name,service) AS spName, SUM(count) AS count FROM " . $serviceProvidersTableName . " LEFT OUTER JOIN " . $serviceProvidersMapTableName . " ON service = identifier GROUP BY service HAVING service != '' ORDER BY count DESC");
164132
} else {
165-
$stmt = $conn->prepare("SELECT year, month, day, IFNULL(name,service) AS spName, SUM(count) AS count FROM " . $serviceProvidersTableName . " LEFT OUTER JOIN " . $serviceProvidersMapTableName . " ON service = identifier WHERE CONCAT(year,'-',LPAD(month,2,'00'),'-',LPAD(day,2,'00')) BETWEEN CURDATE() - INTERVAL ".$days." DAY AND CURDATE() GROUP BY service HAVING service != ''");
133+
$stmt = $conn->prepare("SELECT year, month, day, IFNULL(name,service) AS spName, SUM(count) AS count FROM " . $serviceProvidersTableName . " LEFT OUTER JOIN " . $serviceProvidersMapTableName . " ON service = identifier WHERE CONCAT(year,'-',LPAD(month,2,'00'),'-',LPAD(day,2,'00')) BETWEEN CURDATE() - INTERVAL ".$days." DAY AND CURDATE() GROUP BY service HAVING service != '' ORDER BY count DESC");
166134
}
167135
$stmt->execute();
168136
$result = $stmt->get_result();
@@ -180,9 +148,9 @@ public static function getLoginCountPerIdp($days)
180148
$identityProvidersTableName = $databaseConnector->getIdentityProvidersTableName();
181149
$identityProvidersMapTableName = $databaseConnector->getIdentityProvidersMapTableName();
182150
if($days == 0) { // 0 = all time
183-
$stmt = $conn->prepare("SELECT IFNULL(name,sourceIdp) AS idPName, SUM(count) AS count FROM ".$identityProvidersTableName. " LEFT OUTER JOIN " . $identityProvidersMapTableName . " ON sourceIdp = entityId GROUP BY sourceIdp HAVING sourceIdp != ''");
151+
$stmt = $conn->prepare("SELECT IFNULL(name,sourceIdp) AS idPName, SUM(count) AS count FROM ".$identityProvidersTableName. " LEFT OUTER JOIN " . $identityProvidersMapTableName . " ON sourceIdp = entityId GROUP BY sourceIdp HAVING sourceIdp != '' ORDER BY count DESC");
184152
} else {
185-
$stmt = $conn->prepare("SELECT year, month, day, IFNULL(name,sourceIdp) AS idPName, SUM(count) AS count FROM ".$identityProvidersTableName. " LEFT OUTER JOIN " . $identityProvidersMapTableName . " ON sourceIdp = entityId WHERE CONCAT(year,'-',LPAD(month,2,'00'),'-',LPAD(day,2,'00')) BETWEEN CURDATE() - INTERVAL ".$days." DAY AND CURDATE() GROUP BY sourceIdp HAVING sourceIdp != ''");
153+
$stmt = $conn->prepare("SELECT year, month, day, IFNULL(name,sourceIdp) AS idPName, SUM(count) AS count FROM ".$identityProvidersTableName. " LEFT OUTER JOIN " . $identityProvidersMapTableName . " ON sourceIdp = entityId WHERE CONCAT(year,'-',LPAD(month,2,'00'),'-',LPAD(day,2,'00')) BETWEEN CURDATE() - INTERVAL ".$days." DAY AND CURDATE() GROUP BY sourceIdp HAVING sourceIdp != '' ORDER BY count DESC");
186154
}
187155
$stmt->execute();
188156
$result = $stmt->get_result();

templates/identityProviders-tpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ function drawIdpsChart() {
3232

3333
function drawIdpsTable() {
3434
var data = new google.visualization.DataTable();
35-
data.addColumn('date', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_month}'); ?>');
35+
3636
data.addColumn('string', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_identity_provider}'); ?>');
3737
data.addColumn('number', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/count}'); ?>');
38-
data.addRows([<?php DatabaseCommand::getLoginCountPerDeyPerService()?>]);
38+
data.addRows([<?php DatabaseCommand::getLoginCountPerIdp($lastDays)?>]);
3939

4040
var table = new google.visualization.Table(document.getElementById('idpsTable'));
4141

templates/serviceProviders-tpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ function drawSpsChart() {
3333

3434
function drawSpsTable() {
3535
var data = new google.visualization.DataTable();
36-
data.addColumn('date', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_month}'); ?>');
36+
3737
data.addColumn('string', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_service_provider}'); ?>');
3838
data.addColumn('number', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/count}'); ?>');
39-
data.addRows([<?php DatabaseCommand::getAccessToServicesPerMonth()?>]);
39+
data.addRows([<?php DatabaseCommand::getAccessCountPerService($lastDays)?>]);
4040

4141
var table = new google.visualization.Table(document.getElementById('spsTable'));
4242

templates/summary-tpl.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<script type="text/javascript">
1515
google.charts.load('current', {'packages':['corechart', 'controls', 'table']});
1616
google.charts.setOnLoadCallback(drawLoginsChart);
17-
google.charts.setOnLoadCallback(drawLoginsTable);
1817

1918
function drawLoginsChart() {
2019
var data = google.visualization.arrayToDataTable([
@@ -42,22 +41,7 @@ function drawLoginsChart() {
4241
dashboard.draw(data);
4342
}
4443

45-
function drawLoginsTable() {
46-
var data = new google.visualization.DataTable();
47-
data.addColumn('date', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_date}'); ?>');
48-
data.addColumn('number', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/count}'); ?>');
49-
data.addRows([<?php DatabaseCommand::getLoginCountPerDay($lastDays)?>]);
50-
51-
var table = new google.visualization.Table(document.getElementById('loginsTable'));
52-
53-
var formatter = new google.visualization.DateFormat({pattern: "d MMMM yyyy"});
54-
formatter.format(data, 0); // Apply formatter to second column
55-
56-
table.draw(data, {showRowNumber: false,});
57-
}
58-
5944
google.charts.setOnLoadCallback(drawIdpsChart);
60-
google.charts.setOnLoadCallback(drawIdpsTable);
6145

6246
function drawIdpsChart() {
6347
var data = google.visualization.arrayToDataTable([
@@ -76,23 +60,8 @@ function drawIdpsChart() {
7660
chart.draw(data, options);
7761
}
7862

79-
function drawIdpsTable() {
80-
var data = new google.visualization.DataTable();
81-
data.addColumn('date', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_month}'); ?>');
82-
data.addColumn('string', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_identity_provider}'); ?>');
83-
data.addColumn('number', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/count}'); ?>');
84-
data.addRows([<?php DatabaseCommand::getLoginCountPerDeyPerService()?>]);
85-
86-
var table = new google.visualization.Table(document.getElementById('idpsTable'));
87-
88-
var formatter = new google.visualization.DateFormat({pattern:"MMMM yyyy"});
89-
formatter.format(data, 0); // Apply formatter to second column
90-
91-
table.draw(data);
92-
}
9363

9464
google.charts.setOnLoadCallback(drawSpsChart);
95-
google.charts.setOnLoadCallback(drawSpsTable);
9665

9766
function drawSpsChart() {
9867
var data = google.visualization.arrayToDataTable([
@@ -111,20 +80,7 @@ function drawSpsChart() {
11180
chart.draw(data, options);
11281
}
11382

114-
function drawSpsTable() {
115-
var data = new google.visualization.DataTable();
116-
data.addColumn('date', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_month}'); ?>');
117-
data.addColumn('string', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_service_provider}'); ?>');
118-
data.addColumn('number', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/count}'); ?>');
119-
data.addRows([<?php DatabaseCommand::getAccessToServicesPerMonth()?>]);
12083

121-
var table = new google.visualization.Table(document.getElementById('spsTable'));
122-
123-
var formatter = new google.visualization.DateFormat({pattern:"MMMM yyyy"});
124-
formatter.format(data, 0); // Apply formatter to second column
125-
126-
table.draw(data);
127-
}
12884
</script>
12985
</head>
13086

0 commit comments

Comments
 (0)