Skip to content
Snippets Groups Projects
Unverified Commit f83c0df2 authored by Pavel Vyskočil's avatar Pavel Vyskočil
Browse files

Add API to get stats as JSON

parent 3b9e940e
Branches dev_api
No related tags found
No related merge requests found
......@@ -127,6 +127,19 @@ class DatabaseCommand
return $this->read($query, $params)->fetchAll(PDO::FETCH_NUM);
}
public function get_api_stats($year)
{
$query = 'select CONCAT(year,"-",month,"-",day) AS day, ss.spId, ss.identifier as sp_identifier, ss.name as sp_name, si.idpId, si.identifier as idp_identifier, si.name as idp_name, logins, users
from (' . $this->tables[self::TABLE_SUM] . ' join ' . $this->tables[self::TABLE_IDP] . ' si on ' . $this->tables[self::TABLE_SUM] . '.idpId = si.idpId) left join ' . $this->tables[self::TABLE_SP] . ' ss on ' . $this->tables[self::TABLE_SUM] . '.spId = ss.spId
group by year, month, day, spId, idpId
having spId is not NULL and year="' . $year . '"';
$params = [];
return $this->read($query, $params)->fetchAll(PDO::FETCH_NAMED);
}
public function aggregate()
{
foreach ([self::TABLE_IDS[self::TABLE_IDP], null] as $idpId) {
......
<?php
// required headers
use SimpleSAML\Module\proxystatistics\DatabaseCommand;
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Content-Encoding: gzip");
$year = $_GET['year'] ?? date("Y");
$dbCmd = new DatabaseCommand();
$data = $dbCmd->get_api_stats($year);
echo gzencode(json_encode($data));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment