]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/ttImportHelper.class.php
Some more work in progress on subgroups.
[timetracker.git] / WEB-INF / lib / ttImportHelper.class.php
index dfa3be5977ce2073528d116fcfaa82342ac0841c..6686d40f6e7087174f51f17e191c335a78f473c3 100644 (file)
@@ -248,6 +248,7 @@ class ttImportHelper {
       $this->logMap[$this->currentElement['ID']] =
         ttTimeHelper::insert(array(
           'user_id' => $this->userMap[$this->currentElement['USER_ID']],
+          'group_id' => $this->group_id,
           'date' => $this->currentElement['DATE'],
           'start' => $this->currentElement['START'],
           'finish' => $this->currentElement['FINISH'],
@@ -292,6 +293,7 @@ class ttImportHelper {
       ttExpenseHelper::insert(array(
         'date' => $this->currentElement['DATE'],
         'user_id' => $this->userMap[$this->currentElement['USER_ID']],
+        'group_id' => $this->group_id,
         'client_id' => $this->clientMap[$this->currentElement['CLIENT_ID']],
         'project_id' => $this->projectMap[$this->currentElement['PROJECT_ID']],
         'name' => $this->currentElement['NAME'],
@@ -332,7 +334,10 @@ class ttImportHelper {
         'chfinish' => (int) $this->currentElement['SHOW_END'],
         'chnote' => (int) $this->currentElement['SHOW_NOTE'],
         'chcf_1' => (int) $this->currentElement['SHOW_CUSTOM_FIELD_1'],
-        'group_by' => $this->currentElement['GROUP_BY'],
+        'chunits' => (int) $this->currentElement['SHOW_WORK_UNITS'],
+        'group_by1' => $this->currentElement['GROUP_BY1'],
+        'group_by2' => $this->currentElement['GROUP_BY2'],
+        'group_by3' => $this->currentElement['GROUP_BY3'],
         'chtotalsonly' => (int) $this->currentElement['SHOW_TOTALS_ONLY']));
     }
     $this->currentTag = '';
@@ -469,11 +474,18 @@ class ttImportHelper {
 
     $sql = 'insert into tt_groups '.$columns.$values;
     $affected = $mdb2->exec($sql);
-    if (!is_a($affected, 'PEAR_Error')) {
-      $group_id = $mdb2->lastInsertID('tt_groups', 'id');
-      return $group_id;
-    }
-    return false;
+    if (is_a($affected, 'PEAR_Error')) return false;
+
+    $group_id = $mdb2->lastInsertID('tt_groups', 'id');
+
+    // Update org_id with group_id.
+    // NOTE: Both export and import need an additional effort to properly operate on subgroups.
+    // Currently we are importing one group only, which becomes a top level group.
+    $sql = "update tt_groups set org_id = $group_id where org_id is NULL and id = $group_id";
+    $affected = $mdb2->exec($sql);
+    if (is_a($affected, 'PEAR_Error')) return false;
+
+    return $group_id;
   }
 
   // insertMonthlyQuota - a helper function to insert a monthly quota.