From 56f1fd19f2c9c72878395b3275f03f192ccca082 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 10 Nov 2018 23:02:08 +0000 Subject: [PATCH] Improved new export-import by adding time log. --- WEB-INF/lib/ttGroupExportHelper.class.php | 30 +++++++++++++++++++++ WEB-INF/lib/ttOrgImportHelper.class.php | 32 +++++++++++++++++++++++ WEB-INF/templates/footer.tpl | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/WEB-INF/lib/ttGroupExportHelper.class.php b/WEB-INF/lib/ttGroupExportHelper.class.php index 91a36ce9..fecfba8a 100644 --- a/WEB-INF/lib/ttGroupExportHelper.class.php +++ b/WEB-INF/lib/ttGroupExportHelper.class.php @@ -46,6 +46,7 @@ class ttGroupExportHelper { var $projectMap = array(); // Project ids. var $clientMap = array(); // Client ids. var $invoiceMap = array(); // Invoice ids. + var $logMap = array(); // Time log ids. // Constructor. function __construct($group_id, $file, $indentation) { @@ -343,6 +344,35 @@ class ttGroupExportHelper { } fwrite($this->file, $this->indentation." \n"); + // Write time log entries and build logMap at the same time. + fwrite($this->file, $this->indentation." \n"); + $key = 0; + foreach ($users as $user_item) { + $records = ttTimeHelper::getAllRecords($user_item['id']); + foreach ($records as $record) { + $key++; + $this->logMap[$record['id']] = $key; + $log_part = $this->indentation.' '."userMap[$record['user_id']]."\""; + $log_part .= " date=\"".$record['date']."\""; + $log_part .= " start=\"".$record['start']."\""; + $log_part .= " finish=\"".$record['finish']."\""; + $log_part .= " duration=\"".($record['start']?"":$record['duration'])."\""; + $log_part .= " client_id=\"".$this->clientMap[$record['client_id']]."\""; + $log_part .= " project_id=\"".$this->projectMap[$record['project_id']]."\""; + $log_part .= " task_id=\"".$this->taskMap[$record['task_id']]."\""; + $log_part .= " invoice_id=\"".$this->invoiceMap[$record['invoice_id']]."\""; + $log_part .= " comment=\"".htmlentities($record['comment'])."\""; + $log_part .= " billable=\"".$record['billable']."\""; + $log_part .= " paid=\"".$record['paid']."\""; + $log_part .= " status=\"".$record['status']."\""; + $log_part .= ">\n"; + fwrite($this->file, $log_part); + } + } + fwrite($this->file, $this->indentation." \n"); + unset($records); + // Call self recursively for all subgroups. foreach ($this->subgroups as $subgroup) { $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.' '); diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 01566880..622b3fec 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -54,6 +54,7 @@ class ttOrgImportHelper { var $currentGroupClientMap = array(); var $currentGroupUserMap = array(); var $currentGroupInvoiceMap = array(); + var $currentGroupLogMap = array(); // Constructor. function __construct(&$errors) { @@ -279,6 +280,37 @@ class ttOrgImportHelper { $this->currentGroupInvoiceMap[$attrs['ID']] = $invoice_id; } else $this->errors->add($i18n->get('error.db')); } + + if ($name == 'LOG') { + // If we get here, we have to recycle $currentGroupLogMap. + unset($this->currentGroupLogMap); + $this->currentGroupLogMap = array(); + // Log map is reconstructed after processing elements in XML. See below. + } + + if ($name == 'LOG_ITEM') { + // We get here when processing tags for the current group. + $log_item_id = ttTimeHelper::insert(array( + 'user_id' => $this->currentGroupUserMap[$attrs['USER_ID']], + 'group_id' => $this->current_group_id, + 'org_id' => $this->org_id, + 'date' => $attrs['DATE'], + 'start' => $attrs['START'], + 'finish' => $attrs['FINISH'], + 'duration' => $attrs['DURATION'], + 'client' => $this->currentGroupClientMap[$attrs['CLIENT_ID']], + 'project' => $this->currentGroupProjectMap[$attrs['PROJECT_ID']], + 'task' => $this->currentGroupTaskMap[$attrs['TASK_ID']], + 'invoice' => $this->currentGroupInvoiceMap[$attrs['INVOICE_ID']], + 'note' => (isset($attrs['COMMENT']) ? $attrs['COMMENT'] : ''), + 'billable' => $attrs['BILLABLE'], + 'paid' => $attrs['PAID'], + 'status' => $attrs['STATUS'])); + if ($log_item_id) { + // Add a mapping. + $this->currentGroupLogMap[$attrs['ID']] = $log_item_id; + } else $this->errors->add($i18n->get('error.db')); + } } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 8995b12b..a93f706a 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.12.4410 | Copyright © Anuko | +  Anuko Time Tracker 1.18.12.4411 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1