@@ -14,6 +14,8 @@ public function __construct(IDBConnection $db) {
1414 $ this ->dbengine = 'MYSQL ' ;
1515 if (strpos (get_class ($ db ->getDatabasePlatform ()),'PostgreSQL ' ) !== FALSE ){
1616 $ this ->dbengine = 'POSTGRES ' ;
17+ } else if (strpos (get_class ($ db ->getDatabasePlatform ()),'Sqlite ' ) !== FALSE ){
18+ $ this ->dbengine = 'SQLITE ' ;
1719 }
1820 parent ::__construct ($ db , 'timetracker_work_interval ' );
1921 }
@@ -52,36 +54,38 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
5254 }
5355
5456
55- if ($ this ->dbengine != 'MYSQL ' ) {
57+ if (empty ($ timegroup )){
58+ if (!$ aggregation ) {
59+ $ selectFields []= "start as time " ;
60+ } else {
61+ $ selectFields []= "min(start) as time " ;
62+ }
63+ } elseif ($ timegroup == 'day ' ) {
64+ $ selectFields []= "start as time " ;
65+ }
66+
67+ if ($ this ->dbengine == 'POSTGRES ' ) {
5668 $ pg = 1 ;
57- if (empty ($ timegroup )){
58- if (!$ aggregation ) {
59- $ selectFields []= "start as time " ;
60- } else {
61- $ selectFields []= "min(start) as time " ;
62- }
63- } elseif ($ timegroup == 'week ' ) {
69+ if ($ timegroup == 'week ' ) {
6470 $ selectFields []= "concat(date_part('year', to_timestamp(start)), 'W', to_char(to_timestamp(start), 'IW')) as time " ;
65- }elseif ($ timegroup == 'day ' ) {
66- $ selectFields []= "start as time " ;
6771 }elseif ($ timegroup == 'year ' ) {
6872 $ selectFields []= "date_part('year', to_timestamp(start)) as time " ;
6973 }elseif ($ timegroup == 'month ' ) {
7074 $ selectFields []= "to_char(to_timestamp(start), 'YYYY-MM') as time " ;
7175 }
76+ } else if ($ this ->dbengine == 'SQLITE ' ) {
77+ if ($ timegroup == 'week ' ) {
78+ $ selectFields []= "strftime('%YW%W', datetime(start, 'unixepoch')) as time " ;
79+ }elseif ($ timegroup == 'year ' ) {
80+ $ selectFields []= "strftime('%Y', datetime(start, 'unixepoch')) as time " ;
81+ }elseif ($ timegroup == 'month ' ) {
82+ $ selectFields []= "strftime('%Y-%m', datetime(start, 'unixepoch')) as time " ;
83+ }
7284 } else {
73- if (empty ($ timegroup )){
74- if (!$ aggregation ) {
75- $ selectFields []= "start as time " ;
76- } else {
77- $ selectFields []= "min(start) as time " ;
78- }
79- } elseif ($ timegroup == 'week ' ) {
85+ if ($ timegroup == 'week ' ) {
8086 $ selectFields []= "CONCAT(YEAR(FROM_UNIXTIME(start)), 'W', WEEK(FROM_UNIXTIME(start))) as time " ;
81- }elseif ($ timegroup == 'day ' ) {
82- $ selectFields []= "start as time " ;
8387 }elseif ($ timegroup == 'year ' ) {
84- $ selectFields []= ' YEAR(FROM_UNIXTIME(start)) as time ' ;
88+ $ selectFields []= " YEAR(FROM_UNIXTIME(start)) as time " ;
8589 }elseif ($ timegroup == 'month ' ) {
8690 $ selectFields []= "DATE_FORMAT(FROM_UNIXTIME(start),'%Y-%m') as time " ;
8791 }
@@ -104,7 +108,7 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
104108 if ($ aggregation ){
105109 if (($ groupOn1 != 'project ' ) && ($ groupOn2 != 'project ' )){
106110 $ selectFields [] = '\'* \' as "projectId" ' ;
107- if ($ this ->dbengine != ' MYSQL ' ) {
111+ if ($ this ->dbengine == ' POSTGRES ' ) {
108112 $ selectFields [] = 'string_agg(distinct p.name, \', \') as project ' ;
109113 } else {
110114 $ selectFields [] = 'group_concat(distinct p.name) as project ' ;
@@ -118,7 +122,7 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
118122
119123 if (($ groupOn1 != 'client ' ) && ($ groupOn2 != 'client ' )){
120124 $ selectFields [] = '\'* \' as "clientId" ' ;
121- if ($ this ->dbengine != ' MYSQL ' ) {
125+ if ($ this ->dbengine == ' POSTGRES ' ) {
122126 $ selectFields [] = 'string_agg(distinct c.name, \', \') as client ' ;
123127 } else {
124128 $ selectFields [] = 'group_concat(distinct c.name) as client ' ;
@@ -130,7 +134,7 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
130134 }
131135
132136 if (($ groupOn1 != 'userUid ' ) && ($ groupOn2 != 'userUid ' ) && $ aggregation ){
133- if ($ this ->dbengine != ' MYSQL ' ) {
137+ if ($ this ->dbengine == ' POSTGRES ' ) {
134138 $ selectFields [] = 'string_agg(distinct user_uid, \', \') as "userUid" ' ;
135139 } else {
136140 $ selectFields [] = 'group_concat(distinct user_uid) as "userUid" ' ;
0 commit comments