From 77f0fbc75930d7d2f9a3d3acadb64be44b871621 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 11 Nov 2018 13:25:11 +0000 Subject: [PATCH] Improved new export-import by adding custom field options. --- .gitignore | 1 + WEB-INF/lib/ttGroupExportHelper.class.php | 12 ++++++++++++ WEB-INF/lib/ttOrgImportHelper.class.php | 20 ++++++++++++++++++++ WEB-INF/templates/footer.tpl | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9bfa047e..dc348cfa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ config.php WEB-INF/templates_c/*.* +WEB-INF/templates_c/import_* WEB-INF/lib/tcpdf/ nbproject/ upload/ diff --git a/WEB-INF/lib/ttGroupExportHelper.class.php b/WEB-INF/lib/ttGroupExportHelper.class.php index 1b7e74a7..f1ea228d 100644 --- a/WEB-INF/lib/ttGroupExportHelper.class.php +++ b/WEB-INF/lib/ttGroupExportHelper.class.php @@ -399,6 +399,18 @@ class ttGroupExportHelper { fwrite($this->file, $this->indentation." \n"); unset($custom_fields); + // Write custom field options. + fwrite($this->file, $this->indentation." \n"); + foreach ($custom_field_options as $option) { + $custom_field_option_part = $this->indentation.' '."customFieldOptionMap[$option['id']]."\""; + $custom_field_option_part .= " field_id=\"".$this->customFieldMap[$option['field_id']]."\""; + $custom_field_option_part .= " value=\"".htmlentities($option['value'])."\""; + $custom_field_option_part .= ">\n"; + fwrite($this->file, $custom_field_option_part); + } + fwrite($this->file, $this->indentation." \n"); + unset($custom_field_options); + // 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 2cb69344..9c39810f 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -336,6 +336,26 @@ class ttOrgImportHelper { $this->currentGroupCustomFieldMap[$attrs['ID']] = $custom_field_id; } else $this->errors->add($i18n->get('error.db')); } + + if ($name == 'CUSTOM_FIELD_OPTIONS') { + // If we get here, we have to recycle $currentGroupCustomFieldOptionMap. + unset($this->currentGroupCustomFieldOptionMap); + $this->currentGroupCustomFieldOptionMap = array(); + // Custom field option map is reconstructed after processing elements in XML. See below. + } + + if ($name == 'CUSTOM_FIELD_OPTION') { + // We get here when processing tags for the current group. + $custom_field_option_id = ttCustomFieldHelper::insertOption(array( + // 'group_id' => $this->current_group_id, TODO: add this when group_id field is added to the table. + // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table. + 'field_id' => $this->currentGroupCustomFieldMap[$attrs['FIELD_ID']], + 'value' => $attrs['VALUE'])); + if ($custom_field_option_id) { + // Add a mapping. + $this->currentGroupCustomFieldOptionMap[$attrs['ID']] = $custom_field_option_id; + } else $this->errors->add($i18n->get('error.db')); + } } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 4e17b95e..bd9cdf51 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.12.4412 | Copyright © Anuko | +  Anuko Time Tracker 1.18.12.4413 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1