From bf300dab88607ee209b83f16a6915bb9d61787bb Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 11 Nov 2018 12:15:22 +0000 Subject: [PATCH] Added custom fields to new export-import. --- WEB-INF/lib/ttGroupExportHelper.class.php | 40 +++++++++++++++++++---- WEB-INF/lib/ttOrgImportHelper.class.php | 25 ++++++++++++++ WEB-INF/templates/footer.tpl | 2 +- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/WEB-INF/lib/ttGroupExportHelper.class.php b/WEB-INF/lib/ttGroupExportHelper.class.php index fecfba8a..1b7e74a7 100644 --- a/WEB-INF/lib/ttGroupExportHelper.class.php +++ b/WEB-INF/lib/ttGroupExportHelper.class.php @@ -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." \n"); foreach ($roles as $role) { @@ -373,6 +385,20 @@ class ttGroupExportHelper { fwrite($this->file, $this->indentation." \n"); unset($records); + // Write custom fields. + fwrite($this->file, $this->indentation." \n"); + foreach ($custom_fields as $custom_field) { + $custom_field_part = $this->indentation.' '."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 .= ">\n"; + fwrite($this->file, $custom_field_part); + } + fwrite($this->file, $this->indentation." \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.' '); diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 622b3fec..2cb69344 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -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 elements in XML. See below. + } + + if ($name == 'CUSTOM_FIELD') { + // We get here when processing 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')); + } } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index a93f706a..4e17b95e 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.12.4411 | Copyright © Anuko | +  Anuko Time Tracker 1.18.12.4412 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1