Fixed stats call + minor formatting

This commit is contained in:
Maximilian Giller 2021-07-26 22:57:39 +02:00
parent 18c4991c52
commit c17c6cfa02

View file

@ -216,7 +216,7 @@ function updateRecord($user_id, $record)
$data = []; $data = [];
$props = ["end_time", "start_time", "duration", "project_id"]; $props = ["end_time", "start_time", "duration", "project_id"];
foreach ($props as $p) { foreach ($props as $p) {
if (array_key_exists ($p, $record)) { if (array_key_exists($p, $record)) {
$data[$p] = $record[$p]; $data[$p] = $record[$p];
} }
} }
@ -236,7 +236,7 @@ function updateProject($user_id, $project)
$data = []; $data = [];
$props = ["name", "start_date", "color", "visible"]; $props = ["name", "start_date", "color", "visible"];
foreach ($props as $p) { foreach ($props as $p) {
if (array_key_exists ($p, $project)) { if (array_key_exists($p, $project)) {
$data[$p] = $project[$p]; $data[$p] = $project[$p];
} }
} }
@ -256,7 +256,7 @@ function updateRecordTag($user_id, $tag)
$data = []; $data = [];
$props = ["name", "visible", "bundle"]; $props = ["name", "visible", "bundle"];
foreach ($props as $p) { foreach ($props as $p) {
if (array_key_exists ($p, $tag)) { if (array_key_exists($p, $tag)) {
$data[$p] = $tag[$p]; $data[$p] = $tag[$p];
} }
} }
@ -465,7 +465,8 @@ function removeTagFromRecord($tag_id, $record_id)
$db->execute(); $db->execute();
} }
function getStats($user_id, $from_date, $until_date) { function getStats($user_id, $from_date, $until_date)
{
$sum_duration = "SUM(ju_time_records.duration) AS duration"; $sum_duration = "SUM(ju_time_records.duration) AS duration";
$date = "DATE(ju_time_records.start_time) AS date"; $date = "DATE(ju_time_records.start_time) AS date";
$record_count = "COUNT(*) AS record_count"; $record_count = "COUNT(*) AS record_count";
@ -475,16 +476,18 @@ function getStats($user_id, $from_date, $until_date) {
$where3 = " ) AND ju_time_records.end_time IS NOT NULL "; $where3 = " ) AND ju_time_records.end_time IS NOT NULL ";
$db = new DbOperations(); $db = new DbOperations();
$db->select("projects", ["name", "project_id", "color", "visible", $sum_duration, $date, $record_count], false); $db->select("projects", ["ju_projects.name AS name", "ju_projects.project_id", "color", "visible", $sum_duration, $date, $record_count], false);
$db->innerJoin("time_records", "project_id"); $db->innerJoin("time_records", "project_id");
// $db->innerJoin("tags_on_records", "record_id", "record_id", "time_records");
// $db->innerJoin("record_tags", "record_tag_id", "record_tag_id", "tags_on_records");
$db->where("user_id", Comparison::EQUAL, $user_id); $db->where("ju_projects.user_id", Comparison::EQUAL, $user_id);
$db->addSql($where1); $db->addSql($where1);
$db->addValue($from_date); $db->addValue($from_date);
$db->addSql($where2); $db->addSql($where2);
$db->addValue($until_date); $db->addValue($until_date);
$db->addSql($where3); $db->addSql($where3);
$db->groupBy(["project_id", "date"]); $db->groupBy(["ju_projects.project_id", "date"], false);
return $db->execute(); return $db->execute();
} }