Skip to content

Commit 9330c85

Browse files
committed
fix grouping by re-introducig the date formatting in the sql queries
fixes mtierltd#132
1 parent a07f416 commit 9330c85

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Mit dem integrierten Dashboard lässt sich anhand eines Kuchen-/Donut-Diagramms
3535

3636
Diese App wird aktuell noch weiterentwickelt, also: Augen offen halten für neue Features! Und falls Dir irgendwelche Verbesserungsvorschläge, Probleme oder neue Features einfallen, schau mal auf unserem [GitHub Projekt](https://github.com/mtierltd/timetracker) vorbei, vielleicht wird Dein Thema bereits diskutiert! Und falls nicht, starte gerne eine neue Diskussion, wir freuen uns auf Dein Feedback!
3737
</description>
38-
<version>0.0.67</version>
38+
<version>0.0.68</version>
3939
<licence>agpl</licence>
4040
<author mail="[email protected]" >MTier Ltd.</author>
4141
<namespace>TimeTracker</namespace>

lib/Db/ReportItem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ReportItem extends Entity {
1212
public $projectId;
1313
public $userUid;
1414
public $time;
15+
public $ftime;
1516
public $totalDuration;
1617
public $project;
1718
public $clientId;
@@ -28,6 +29,7 @@ public function __construct() {
2829
$this->addType('projectId', 'integer');
2930
$this->addType('userUid', 'string');
3031
$this->addType('time', 'string');
32+
$this->addType('ftime', 'string');
3133
$this->addType('totalDuration', 'integer');
3234
$this->addType('project', 'string');
3335
}

lib/Db/ReportItemMapper.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,40 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
5656
if(empty($timegroup)){
5757
if (!$aggregation) {
5858
$selectFields[]= "start as time";
59+
$selectFields[]= "start as ftime";
5960
} else {
6061
$selectFields[]= "min(start) as time";
62+
$selectFields[]= "min(start) as ftime";
6163
}
6264
} else {
6365
$selectFields[]= "start as time";
66+
$selectFields[]= "start as ftime";
67+
}
68+
69+
if ($this->dbengine == 'POSTGRES') {
70+
if ($timegroup == 'week') {
71+
$selectFields[]= "concat(date_part('year', to_timestamp(start)), 'W', to_char(to_timestamp(start), 'IW')) as ftime";
72+
}elseif ($timegroup == 'year') {
73+
$selectFields[]= "date_part('year', to_timestamp(start)) as ftime";
74+
}elseif ($timegroup == 'month') {
75+
$selectFields[]= "to_char(to_timestamp(start), 'YYYY-MM') as ftime";
76+
}
77+
} else if ($this->dbengine == 'SQLITE') {
78+
if ($timegroup == 'week') {
79+
$selectFields[]= "strftime('%YW%W', datetime(start, 'unixepoch')) as ftime";
80+
}elseif ($timegroup == 'year') {
81+
$selectFields[]= "strftime('%Y', datetime(start, 'unixepoch')) as ftime";
82+
}elseif ($timegroup == 'month') {
83+
$selectFields[]= "strftime('%Y-%m', datetime(start, 'unixepoch')) as ftime";
84+
}
85+
} else {
86+
if ($timegroup == 'week') {
87+
$selectFields[]= "CONCAT(YEAR(FROM_UNIXTIME(start)), 'W', WEEK(FROM_UNIXTIME(start))) as ftime";
88+
}elseif ($timegroup == 'year') {
89+
$selectFields[]= "YEAR(FROM_UNIXTIME(start)) as ftime";
90+
}elseif ($timegroup == 'month') {
91+
$selectFields[]= "DATE_FORMAT(FROM_UNIXTIME(start),'%Y-%m') as ftime";
92+
}
6493
}
6594

6695
if ($aggregation){
@@ -176,7 +205,7 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
176205
// } elseif ($timegroup == 'year') {
177206
// $groups[] = "YEAR(start)";
178207
// }
179-
$groups[] = 'time';
208+
$groups[] = 'ftime';
180209
}
181210

182211
if (!empty($groupOn1)){

0 commit comments

Comments
 (0)