]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/ttOrgImportHelper.class.php
Improved new export-import by adding time log.
[timetracker.git] / WEB-INF / lib / ttOrgImportHelper.class.php
index 015668807ba8130598b15c362bd31719f856f1fe..622b3fec51f67d1fef7df8df1e5dbff14c913841 100644 (file)
@@ -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 <log_item> elements in XML. See below.
+      }
+
+      if ($name == 'LOG_ITEM') {
+        // We get here when processing <log_item> 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'));
+      }
     }
   }