-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
33 lines (33 loc) · 1.47 KB
/
api.php
File metadata and controls
33 lines (33 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
class Api {
function __construct() {
$connecton = new MongoClient();
$db = $connecton->bigbrother;
$this->online = $db->online;
}
function getData($from, $to) {
$data = $this->online->aggregate(['$match' => [ 'start' => [ '$gte' => new MongoDate($from) ],
'end' => [ '$lt' => new MongoDate($to) ]]
],
['$group' => ['_id' => '$user_id',
'timeline' => [ '$push' => [ 'start' => '$start',
'end' => '$end',
'status' => '$status',
'duration' => '$duration' ]],
'timemarks' => ['$sum' => 1]
]
]);
$this->jsonOut($data['result']);
}
private function jsonOut($data) {
error_reporting(0);
header('Content-type: application/json');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
ob_clean();
echo(json_encode($data));
}
}
$loggerApi = new Api();
$loggerApi->getData(strtotime($_GET['from']),strtotime($_GET['to']));
?>