@@ -36,10 +36,30 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
3636 $ selectFields = ['min(wi.id) as id ' , 'sum(duration) as "totalDuration" ' ];
3737
3838 $ pg = 0 ;
39+ $ aggregation = true ;
40+ if (empty ($ groupOn1 ) && empty ($ groupOn2 ) && empty ($ timegroup )) {
41+ $ selectFields [] = 'min(wi.details) as "details" ' ;
42+ $ selectFields [] = 'min(wi.name) as "name" ' ;
43+ $ selectFields [] = '\'* \' as "projectId" ' ;
44+ $ selectFields [] = 'min(p.name) as "project" ' ;
45+
46+ $ selectFields [] = '\'* \' as "clientId" ' ;
47+ $ selectFields [] = 'min(c.name) as "client" ' ;
48+ $ selectFields [] = 'min(user_uid) as "userUid" ' ;
49+ $ aggregation = false ;
50+ } else {
51+ $ selectFields [] = '\'* \' as "details" ' ;
52+ }
53+
54+
3955 if ($ this ->dbengine != 'MYSQL ' ) {
4056 $ pg = 1 ;
4157 if (empty ($ timegroup )){
42- $ selectFields []= "to_timestamp(min(start))::date as time " ;
58+ if (!$ aggregation ) {
59+ $ selectFields []= "to_char(to_timestamp(min(start))::date,'YYYY-MM-DD HH24:MI') as time " ;
60+ } else {
61+ $ selectFields []= "to_timestamp(min(start))::date as time " ;
62+ }
4363 } elseif ($ timegroup == 'week ' ) {
4464 $ selectFields []= "to_char(to_timestamp(start)::date, 'YYYY-WW') as time " ;
4565 }elseif ($ timegroup == 'day ' ) {
@@ -51,7 +71,7 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
5171 }
5272 } else {
5373 if (empty ($ timegroup )){
54- if (empty ( $ groupOn1 ) && empty ( $ groupOn2 ) ) {
74+ if (! $ aggregation ) {
5575 $ selectFields []= "DATE_FORMAT(FROM_UNIXTIME(start),'%Y-%m-%d %H:%i') as time " ;
5676 } else {
5777 $ selectFields []= "DATE_FORMAT(FROM_UNIXTIME(min(start)),'%Y-%m-%d') as time " ;
@@ -67,57 +87,59 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
6787 }
6888
6989 }
70- if (($ groupOn1 != 'name ' ) && ($ groupOn2 != 'name ' ) && !empty ($ groupOn1 ) && !empty ($ groupOn2 )){
71- if ($ this ->dbengine != 'MYSQL ' ) {
72- $ selectFields [] = '\'* \' as name ' ;
90+ if ($ aggregation ){
91+ if ($ groupOn1 != 'name ' ){
92+ if ($ this ->dbengine != 'MYSQL ' ) {
93+ $ selectFields [] = '\'* \' as name ' ;
94+ } else {
95+ $ selectFields [] = 'CASE WHEN CHAR_LENGTH(group_concat(distinct wi.name)) > 40 THEN CONCAT(SUBSTRING(group_concat(distinct wi.name), 1, 40), "...") ELSE group_concat(distinct wi.name) END as name ' ;
96+ }
97+ //$selectFields[] = 'group_concat(distinct wi.name) as name';
7398 } else {
74- $ selectFields [] = 'CASE WHEN CHAR_LENGTH(group_concat(distinct wi.name)) > 40 THEN CONCAT(SUBSTRING(group_concat(distinct wi.name), 1, 40), "...") ELSE group_concat(distinct wi.name) END as name ' ;
99+ $ selectFields [] = 'wi.name as name ' ;
75100 }
76- //$selectFields[] = 'group_concat(distinct wi.name) as name';
77- } else {
78- $ selectFields [] = 'wi.name as name ' ;
79101 }
80102
81- if (($ groupOn1 != 'name ' ) && ($ groupOn2 != 'name ' ) && !empty ($ groupOn1 ) && !empty ($ groupOn2 )){
82- $ selectFields [] = '\'* \' as details ' ;
83- } else {
84- $ selectFields [] = 'wi.details as details ' ;
85- }
86-
87- if (($ groupOn1 != 'project ' ) && ($ groupOn2 != 'project ' && !empty ($ groupOn1 ) && !empty ($ groupOn2 ))){
88- $ selectFields [] = '\'* \' as "projectId" ' ;
89- if ($ this ->dbengine != 'MYSQL ' ) {
90- $ selectFields [] = 'string_agg(distinct p.name, \', \') as project ' ;
103+
104+ if ($ aggregation ){
105+ if (($ groupOn1 != 'project ' ) && ($ groupOn2 != 'project ' )){
106+ $ selectFields [] = '\'* \' as "projectId" ' ;
107+ if ($ this ->dbengine != 'MYSQL ' ) {
108+ $ selectFields [] = 'string_agg(distinct p.name, \', \') as project ' ;
109+ } else {
110+ $ selectFields [] = 'group_concat(distinct p.name) as project ' ;
111+ }
91112 } else {
92- $ selectFields [] = 'group_concat(distinct p.name) as project ' ;
113+
114+ $ selectFields [] = '\'* \' as "projectId" ' ;
115+ $ selectFields [] = 'p.name as project ' ;
93116 }
94- } else {
95- $ selectFields [] = '\'* \' as "projectId" ' ;
96- $ selectFields [] = 'p.name as project ' ;
97- }
98-
99- if (($ groupOn1 != 'client ' ) && ($ groupOn2 != 'client ' )){
100- $ selectFields [] = '\'* \' as "clientId" ' ;
101- if ($ this ->dbengine != 'MYSQL ' ) {
102- $ selectFields [] = 'string_agg(distinct c.name, \', \') as client ' ;
117+
118+
119+ if (($ groupOn1 != 'client ' ) && ($ groupOn2 != 'client ' )){
120+ $ selectFields [] = '\'* \' as "clientId" ' ;
121+ if ($ this ->dbengine != 'MYSQL ' ) {
122+ $ selectFields [] = 'string_agg(distinct c.name, \', \') as client ' ;
123+ } else {
124+ $ selectFields [] = 'group_concat(distinct c.name) as client ' ;
125+ }
126+
103127 } else {
104- $ selectFields [] = 'group_concat(distinct c.name) as client ' ;
128+ $ selectFields [] = '\'* \' as "clientId" ' ;
129+ $ selectFields [] = 'c.name as client ' ;
105130 }
106-
107- } else {
108- $ selectFields [] = '\'* \' as "clientId" ' ;
109- $ selectFields [] = 'c.name as client ' ;
110- }
111-
112- if (($ groupOn1 != 'userUid ' ) && ($ groupOn2 != 'userUid ' )){
113- if ($ this ->dbengine != 'MYSQL ' ) {
114- $ selectFields [] = 'string_agg(distinct user_uid, \', \') as "userUid" ' ;
131+
132+ if (($ groupOn1 != 'userUid ' ) && ($ groupOn2 != 'userUid ' ) && $ aggregation ){
133+ if ($ this ->dbengine != 'MYSQL ' ) {
134+ $ selectFields [] = 'string_agg(distinct user_uid, \', \') as "userUid" ' ;
135+ } else {
136+ $ selectFields [] = 'group_concat(distinct user_uid) as "userUid" ' ;
137+ }
138+
115139 } else {
116- $ selectFields [] = 'group_concat(distinct user_uid) as "userUid" ' ;
140+ $ selectFields [] = 'user_uid as "userUid" ' ;
117141 }
118142
119- } else {
120- $ selectFields [] = 'user_uid as "userUid" ' ;
121143 }
122144
123145 $ selectItems = implode (", " ,$ selectFields ).
@@ -193,20 +215,21 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
193215 $ groups [] = $ groupOn1 ;
194216 }
195217 }
196- if (!empty ($ groupOn2 )){
197- if ($ groupOn2 == "project " || $ groupOn2 == "client " || $ groupOn2 == "name " || $ groupOn2 == "userUid " ){
198- if ($ groupOn2 == 'name ' ){
199- $ groups [] = 'wi.name ' ;
200- } else {
201- if ($ pg ) {
202- $ groups [] = '" ' .$ groupOn2 .'" ' ;// postgres needs quotes on names
203- } else {
204- $ groups [] = $ groupOn2 ;
205- }
206- }
218+ }
219+ if (!empty ($ groupOn2 )){
220+ if ($ groupOn2 == "project " || $ groupOn2 == "client " || $ groupOn2 == "name " || $ groupOn2 == "userUid " ){
221+ if ($ groupOn2 == 'name ' ){
222+ $ groups [] = 'wi.name ' ;
223+ } else {
224+ if ($ pg ) {
225+ $ groups [] = '" ' .$ groupOn2 .'" ' ;// postgres needs quotes on names
226+ } else {
227+ $ groups [] = $ groupOn2 ;
207228 }
208- }
229+ }
230+ }
209231 }
232+
210233 if (!empty ($ groups )){
211234 $ group = "group by " .implode (", " ,$ groups );
212235 } else {
0 commit comments