2021-01-03 12:29:41 +01:00
|
|
|
<?php
|
|
|
|
class JsonBuilder
|
|
|
|
{
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
$this->jsonData = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getJson()
|
|
|
|
{
|
|
|
|
return json_encode($this->jsonData, JSON_FORCE_OBJECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getArray()
|
|
|
|
{
|
|
|
|
return $this->jsonData;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addRecords(array $records)
|
|
|
|
{
|
|
|
|
if ($records === null) return;
|
|
|
|
|
|
|
|
$columns = array(
|
|
|
|
"record_id" => "",
|
|
|
|
"start_time" => "",
|
|
|
|
"end_time" => "",
|
|
|
|
"duration" => "",
|
|
|
|
"user_id" => "",
|
|
|
|
"project_id" => "",
|
2021-01-05 02:00:10 +01:00
|
|
|
"running" => "",
|
|
|
|
"tags" => "",
|
2021-01-03 12:29:41 +01:00
|
|
|
"start_device_id" => ""
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->jsonData['records'] = array();
|
|
|
|
foreach ($records as $record) {
|
|
|
|
$this->jsonData['records'][] = $this->createJsonArray($record, $columns);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addProjects(array $projects)
|
|
|
|
{
|
|
|
|
if ($projects === null) return;
|
|
|
|
|
|
|
|
$columns = array(
|
|
|
|
"project_id" => "",
|
|
|
|
"name" => "",
|
|
|
|
"user_id" => "",
|
|
|
|
"start_date" => "",
|
|
|
|
"duration" => "",
|
2021-01-08 00:01:42 +01:00
|
|
|
"record_count" => "",
|
|
|
|
"color" => "",
|
|
|
|
"visible" => ""
|
2021-01-03 12:29:41 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->jsonData['projects'] = array();
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
$this->jsonData['projects'][] = $this->createJsonArray($project, $columns);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addUsers(array $users)
|
|
|
|
{
|
|
|
|
if ($users === null) return;
|
|
|
|
|
|
|
|
$columns = array(
|
|
|
|
"user_id" => "",
|
|
|
|
"name" => "",
|
|
|
|
"mail_address" => ""
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->jsonData['users'] = array();
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$this->jsonData['users'][] = $this->createJsonArray($user, $columns);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addRecordTags(array $record_tags)
|
|
|
|
{
|
|
|
|
if ($record_tags === null) return;
|
|
|
|
|
|
|
|
$columns = array(
|
|
|
|
"record_tag_id" => "",
|
|
|
|
"name" => "",
|
2021-01-08 00:01:42 +01:00
|
|
|
"user_id" => "",
|
2021-04-13 00:27:41 +02:00
|
|
|
"visible" => "",
|
|
|
|
"bundle" => ""
|
2021-01-03 12:29:41 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->jsonData['record_tags'] = array();
|
|
|
|
foreach ($record_tags as $tag) {
|
|
|
|
$this->jsonData['record_tags'][] = $this->createJsonArray($tag, $columns);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-05-23 00:43:12 +02:00
|
|
|
function addStats(array $stats)
|
|
|
|
{
|
|
|
|
if ($stats === null) return;
|
|
|
|
|
|
|
|
$columns = array(
|
|
|
|
"name" => "",
|
|
|
|
"project_id" => "",
|
|
|
|
"color" => "",
|
|
|
|
"visible" => "",
|
|
|
|
"duration" => "",
|
|
|
|
"record_count" => "",
|
|
|
|
"date" => ""
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->jsonData['stats'] = array();
|
|
|
|
foreach ($stats as $tag) {
|
|
|
|
$this->jsonData['stats'][] = $this->createJsonArray($tag, $columns);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-01-03 12:29:41 +01:00
|
|
|
private function createJsonArray(array $data, array $columns)
|
|
|
|
{
|
|
|
|
$jsonArray = array();
|
|
|
|
foreach ($columns as $key => $column) {
|
|
|
|
if ($column === "") {
|
|
|
|
$column = $key;
|
|
|
|
}
|
|
|
|
$jsonArray[$key] = $data[$column];
|
|
|
|
}
|
|
|
|
return $jsonArray;
|
|
|
|
}
|
|
|
|
}
|