X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttTimesheetHelper.class.php;h=0afefa8048fe2205fe406d539032aa043ad8f2ef;hb=b53f880dcd61797fd2e6609477add03ca757d813;hp=a00b4b7a86dbffdf99ddeef5834918cba13a6dfc;hpb=920b5bff2bf2fb1caa10715ed8d40175e4798019;p=timetracker.git diff --git a/WEB-INF/lib/ttTimesheetHelper.class.php b/WEB-INF/lib/ttTimesheetHelper.class.php index a00b4b7a..0afefa80 100644 --- a/WEB-INF/lib/ttTimesheetHelper.class.php +++ b/WEB-INF/lib/ttTimesheetHelper.class.php @@ -27,6 +27,7 @@ // +----------------------------------------------------------------------+ import('ttUserHelper'); +import('ttFileHelper'); // Class ttTimesheetHelper is used to help with project related tasks. class ttTimesheetHelper { @@ -114,10 +115,18 @@ class ttTimesheetHelper { $group_id = $user->getGroup(); $org_id = $user->org_id; + $includeFiles = $user->isPluginEnabled('at'); + if ($includeFiles) { + $filePart = ', if(Sub1.entity_id is null, 0, 1) as has_files'; + $fileJoin = " left join (select distinct entity_id from tt_files". + " where entity_type = 'timesheet' and group_id = $group_id and org_id = $org_id and status = 1) Sub1". + " on (ts.id = Sub1.entity_id)"; + } + $result = array(); $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name,". - " ts.submit_status, ts.approve_status from tt_timesheets ts". - " left join tt_clients c on (c.id = ts.client_id)". + " ts.submit_status, ts.approve_status $filePart from tt_timesheets ts". + " left join tt_clients c on (c.id = ts.client_id) $fileJoin". " where ts.status = 1 and ts.group_id = $group_id and ts.org_id = $org_id and ts.user_id = $user_id". " order by ts.name"; $res = $mdb2->query($sql); @@ -140,10 +149,18 @@ class ttTimesheetHelper { $group_id = $user->getGroup(); $org_id = $user->org_id; + $includeFiles = $user->isPluginEnabled('at'); + if ($includeFiles) { + $filePart = ', if(Sub1.entity_id is null, 0, 1) as has_files'; + $fileJoin = " left join (select distinct entity_id from tt_files". + " where entity_type = 'timesheet' and group_id = $group_id and org_id = $org_id and status = 1) Sub1". + " on (ts.id = Sub1.entity_id)"; + } + $result = array(); $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name,". - " ts.submit_status, ts.approve_status from tt_timesheets ts". - " left join tt_clients c on (c.id = ts.client_id)". + " ts.submit_status, ts.approve_status $filePart from tt_timesheets ts". + " left join tt_clients c on (c.id = ts.client_id) $fileJoin". " where ts.status = 0 and ts.group_id = $group_id and ts.org_id = $org_id and ts.user_id = $user_id". " order by ts.name"; $res = $mdb2->query($sql); @@ -184,6 +201,15 @@ class ttTimesheetHelper { global $user; $mdb2 = getConnection(); + // Delete associated files. + if ($user->isPluginEnabled('at')) { + import('ttFileHelper'); + global $err; + $fileHelper = new ttFileHelper($err); + if (!$fileHelper->deleteEntityFiles($timesheet_id, 'timesheet')) + return false; + } + $user_id = $user->getUser(); $group_id = $user->getGroup(); $org_id = $user->org_id;