Added custom fields to new export-import.
authorNik Okuntseff <support@anuko.com>
Sun, 11 Nov 2018 12:15:22 +0000 (12:15 +0000)
committerNik Okuntseff <support@anuko.com>
Sun, 11 Nov 2018 12:15:22 +0000 (12:15 +0000)
WEB-INF/lib/ttGroupExportHelper.class.php
WEB-INF/lib/ttOrgImportHelper.class.php
WEB-INF/templates/footer.tpl

index fecfba8..1b7e74a 100644 (file)
@@ -40,13 +40,15 @@ class ttGroupExportHelper {
 
   // The following arrays are maps between entity ids in the file versus the database.
   // We write to the file sequentially (1,2,3...) while in the database the entities have different ids.
-  var $userMap    = array(); // User ids.
-  var $roleMap    = array(); // Role ids.
-  var $taskMap    = array(); // Task ids.
-  var $projectMap = array(); // Project ids.
-  var $clientMap  = array(); // Client ids.
-  var $invoiceMap = array(); // Invoice ids.
-  var $logMap     = array(); // Time log ids.
+  var $userMap    = array();
+  var $roleMap    = array();
+  var $taskMap    = array();
+  var $projectMap = array();
+  var $clientMap  = array();
+  var $invoiceMap = array();
+  var $logMap     = array();
+  var $customFieldMap = array();
+  var $customFieldOptionMap = array();
 
   // Constructor.
   function __construct($group_id, $file, $indentation) {
@@ -231,6 +233,16 @@ class ttGroupExportHelper {
     foreach ($invoices as $key=>$invoice_item)
       $this->invoiceMap[$invoice_item['id']] = $key + 1;
 
+    // Prepare custom fields map.
+    $custom_fields = ttTeamHelper::getAllCustomFields($this->group_id);
+    foreach ($custom_fields as $key=>$custom_field)
+      $this->customFieldMap[$custom_field['id']] = $key + 1;
+
+    // Prepare custom field options map.
+    $custom_field_options = ttTeamHelper::getAllCustomFieldOptions($this->group_id);
+    foreach ($custom_field_options as $key=>$option)
+      $this->customFieldOptionMap[$option['id']] = $key + 1;
+
     // Write roles.
     fwrite($this->file, $this->indentation."  <roles>\n");
     foreach ($roles as $role) {
@@ -373,6 +385,20 @@ class ttGroupExportHelper {
     fwrite($this->file, $this->indentation."  </log>\n");
     unset($records);
 
+    // Write custom fields.
+    fwrite($this->file, $this->indentation."  <custom_fields>\n");
+    foreach ($custom_fields as $custom_field) {
+      $custom_field_part = $this->indentation.'    '."<custom_field id=\"".$this->customFieldMap[$custom_field['id']]."\"";
+      $custom_field_part .= " type=\"".$custom_field['type']."\"";
+      $custom_field_part .= " label=\"".htmlentities($custom_field['label'])."\"";
+      $custom_field_part .= " required=\"".$custom_field['required']."\"";
+      $custom_field_part .= " status=\"".$custom_field['status']."\"";
+      $custom_field_part .= "></custom_field>\n";
+      fwrite($this->file, $custom_field_part);
+    }
+    fwrite($this->file, $this->indentation."  </custom_fields>\n");
+    unset($custom_fields);
+
     // Call self recursively for all subgroups.
     foreach ($this->subgroups as $subgroup) {
       $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.'  ');
index 622b3fe..2cb6934 100644 (file)
@@ -32,6 +32,7 @@ import('ttTaskHelper');
 import('ttProjectHelper');
 import('ttClientHelper');
 import('ttInvoiceHelper');
+import('ttCustomFieldHelper');
 
 // ttOrgImportHelper - this class is a future replacement for ttImportHelper.
 // Currently, it is work in progress.
@@ -55,6 +56,8 @@ class ttOrgImportHelper {
   var $currentGroupUserMap    = array();
   var $currentGroupInvoiceMap = array();
   var $currentGroupLogMap     = array();
+  var $currentGroupCustomFieldMap = array();
+  var $currentGroupCustomFieldOptionMap = array();
 
   // Constructor.
   function __construct(&$errors) {
@@ -311,6 +314,28 @@ class ttOrgImportHelper {
           $this->currentGroupLogMap[$attrs['ID']] = $log_item_id;
         } else $this->errors->add($i18n->get('error.db'));
       }
+
+      if ($name == 'CUSTOM_FIELDS') {
+        // If we get here, we have to recycle $currentGroupCustomFieldMap.
+        unset($this->currentGroupCustomFieldMap);
+        $this->currentGroupCustomFieldMap = array();
+        // Custom field map is reconstructed after processing <custom_field> elements in XML. See below.
+      }
+
+      if ($name == 'CUSTOM_FIELD') {
+        // We get here when processing <custom_field> tags for the current group.
+        $custom_field_id = ttCustomFieldHelper::insertField(array(
+          'group_id' => $this->current_group_id,
+          // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table.
+          'type' => $attrs['TYPE'],
+          'label' => $attrs['LABEL'],
+          'required' => $attrs['REQUIRED'],
+          'status' => $attrs['STATUS']));
+        if ($custom_field_id) {
+          // Add a mapping.
+          $this->currentGroupCustomFieldMap[$attrs['ID']] = $custom_field_id;
+        } else $this->errors->add($i18n->get('error.db'));
+      }
     }
   }
 
index a93f706..4e17b95 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.18.12.4411 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.12.4412 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>