Skip to content

Commit d118ffa

Browse files
committed
fixed reporting
1 parent f8961fa commit d118ffa

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>Time Tracker</name>
66
<summary>Time Tracker App</summary>
77
<description><![CDATA[Time Tracker App]]></description>
8-
<version>0.0.19</version>
8+
<version>0.0.20</version>
99
<licence>agpl</licence>
1010
<author mail="[email protected]" >MTier Ltd.</author>
1111
<namespace>TimeTracker</namespace>

lib/Controller/AjaxController.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,14 @@ public function workIntervals() {
111111
}
112112

113113

114-
public function isAdminUser(){
114+
public function isThisAdminUser(){
115115
return \OC_User::isAdminUser(\OC_User::getUser());
116116
}
117117

118+
public function isUserAdmin($user){
119+
return \OC_User::isAdminUser($user);
120+
}
121+
118122
/**
119123
*
120124
* @NoAdminRequired
@@ -370,7 +374,7 @@ public function addProject($name) {
370374
$p->setClientId($clientId);
371375
$this->projectMapper->insert($p);
372376
} else {
373-
if($p->locked && !$this->isAdminUser()){
377+
if($p->locked && !$this->isThisAdminUser()){
374378
return new JSONResponse(["Error" => "This project is locked"]);
375379
}
376380
}
@@ -478,7 +482,7 @@ public function getProjects(){
478482
* @NoCSRFRequired
479483
*/
480484
public function getProjectsTable(){
481-
if ($this->isAdminUser()){
485+
if ($this->isThisAdminUser()){
482486
$projects = $this->projectMapper->findAllAdmin();
483487
} else {
484488
$projects = $this->projectMapper->findAll($this->userId);
@@ -616,18 +620,20 @@ public function getReport(){
616620
}
617621

618622

619-
if($this->isAdminUser()){
623+
if(!$this->isThisAdminUser()){
620624
$allowedClients = $this->clientMapper->findAll($this->userId);
621625
$allowedClientsId = array_map(function($client){ return $client->id;}, $allowedClients );
622626
if(empty($filterClientId)){
623627
$filterClientId = $allowedClientsId;
628+
$filterClientId[] = null; // allow null clientid
624629
} else {
625630
$filterClientId = array_intersect($filterClientId, $allowedClientsId);
626631
}
627632
$allowedProjects = $this->projectMapper->findAll($this->userId);
628633
$allowedProjectsId = array_map(function($project){ return $project->id;}, $allowedProjects );
629634
if(empty($filterProjectId)){
630635
$filterProjectId = $allowedProjectsId;
636+
$filterProjectId[] = null; // allow null projectId
631637
} else {
632638
$filterProjectId = array_intersect($filterProjectId, $allowedProjectsId);
633639
}
@@ -637,7 +643,7 @@ public function getReport(){
637643
$filterTagId = [];
638644
$groupOn1 = $this->request->group1;
639645
$groupOn2 = $this->request->group2;
640-
$items = $this->reportItemMapper->report($name, $from, $to, $filterProjectId, $filterClientId, $filterTagId, $timegroup, $groupOn1, $groupOn2, 0, 1000);
646+
$items = $this->reportItemMapper->report($name, $from, $to, $filterProjectId, $filterClientId, $filterTagId, $timegroup, $groupOn1, $groupOn2, $this->isThisAdminUser(), 0, 1000);
641647
return new JSONResponse(["items" => json_decode(json_encode($items), true), 'total' => count($items)]);
642648
}
643649

lib/Db/ReportItemMapper.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function __construct(IDBConnection $db) {
2323
public $clientId;
2424
public $client;
2525
*/
26-
public function report($user, $from, $to, $filterProjectId, $filterClientId, $filterTagId, $timegroup, $groupOn1, $groupOn2, $start, $limit ){
26+
27+
public function report($user, $from, $to, $filterProjectId, $filterClientId, $filterTagId, $timegroup, $groupOn1, $groupOn2, $admin, $start, $limit ){
2728

2829
$selectFields = ['min(wi.id) as id', 'sum(duration) as totalDuration'];
2930
if(empty($timegroup)){
@@ -72,33 +73,42 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
7273
$filters = [];
7374
$params = [];
7475
if (!empty($from)){
75-
$filters[] = "start > ?";
76+
$filters[] = "(start > ?)";
7677
$params[] = $from;
7778

7879
}
7980
if (!empty($to)){
80-
$filters[] = "start < ?";
81+
$filters[] = "(start < ?)";
8182
$params[] = $to;
8283

8384
}
8485
if (!empty($filterProjectId)){
8586
$qm = [];
87+
$append = '';
8688
foreach($filterProjectId as $f){
8789
$qm[] = '?';
8890
$params[] = $f;
91+
92+
if($f == null) {
93+
$append = ' or wi.project_id is null ';
94+
}
8995
}
90-
$filters[] = 'wi.project_id in ('.implode(",",$qm).')';
96+
$filters[] = '(wi.project_id in ('.implode(",",$qm).')'.$append.')';
9197
}
9298
if (!empty($filterClientId)){
9399
$qm = [];
100+
$append = '';
94101
foreach($filterClientId as $f){
95102
$qm[] = '?';
96103
$params[] = $f;
104+
if ($f == null) {
105+
$append = ' or p.client_id is null ';
106+
}
97107
}
98-
$filters[] = 'p.client_id in ('.implode(",",$qm).')';
108+
$filters[] = '(p.client_id in ('.implode(",",$qm).')'.$append.')';
99109
}
100-
if ( (!empty($user)) && ($user !='admin') ){
101-
$filters[] = "user_uid = ?";
110+
if ( (!empty($user)) && (!$admin) ){
111+
$filters[] = "(user_uid = ?)";
102112
$params[] = $user;
103113

104114
}

0 commit comments

Comments
 (0)