@@ -36,10 +36,30 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
36
36
$ selectFields = ['min(wi.id) as id ' , 'sum(duration) as "totalDuration" ' ];
37
37
38
38
$ 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
+
39
55
if ($ this ->dbengine != 'MYSQL ' ) {
40
56
$ pg = 1 ;
41
57
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
+ }
43
63
} elseif ($ timegroup == 'week ' ) {
44
64
$ selectFields []= "to_char(to_timestamp(start)::date, 'YYYY-WW') as time " ;
45
65
}elseif ($ timegroup == 'day ' ) {
@@ -51,7 +71,7 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
51
71
}
52
72
} else {
53
73
if (empty ($ timegroup )){
54
- if (empty ( $ groupOn1 ) && empty ( $ groupOn2 ) ) {
74
+ if (! $ aggregation ) {
55
75
$ selectFields []= "DATE_FORMAT(FROM_UNIXTIME(start),'%Y-%m-%d %H:%i') as time " ;
56
76
} else {
57
77
$ 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
67
87
}
68
88
69
89
}
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';
73
98
} 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 ' ;
75
100
}
76
- //$selectFields[] = 'group_concat(distinct wi.name) as name';
77
- } else {
78
- $ selectFields [] = 'wi.name as name ' ;
79
101
}
80
102
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
+ }
91
112
} else {
92
- $ selectFields [] = 'group_concat(distinct p.name) as project ' ;
113
+
114
+ $ selectFields [] = '\'* \' as "projectId" ' ;
115
+ $ selectFields [] = 'p.name as project ' ;
93
116
}
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
+
103
127
} else {
104
- $ selectFields [] = 'group_concat(distinct c.name) as client ' ;
128
+ $ selectFields [] = '\'* \' as "clientId" ' ;
129
+ $ selectFields [] = 'c.name as client ' ;
105
130
}
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
+
115
139
} else {
116
- $ selectFields [] = 'group_concat(distinct user_uid) as "userUid" ' ;
140
+ $ selectFields [] = 'user_uid as "userUid" ' ;
117
141
}
118
142
119
- } else {
120
- $ selectFields [] = 'user_uid as "userUid" ' ;
121
143
}
122
144
123
145
$ selectItems = implode (", " ,$ selectFields ).
@@ -193,20 +215,21 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
193
215
$ groups [] = $ groupOn1 ;
194
216
}
195
217
}
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 ;
207
228
}
208
- }
229
+ }
230
+ }
209
231
}
232
+
210
233
if (!empty ($ groups )){
211
234
$ group = "group by " .implode (", " ,$ groups );
212
235
} else {
0 commit comments