From a05b671f90c2eecac59f9f17c57594da51eb033c Mon Sep 17 00:00:00 2001 From: Marc Michalsky forumZFD Date: Tue, 29 Sep 2020 14:15:04 +0200 Subject: [PATCH] translate values in two directions --- api/v3/TwingleSync/models/TwingleProject.php | 39 ++++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/api/v3/TwingleSync/models/TwingleProject.php b/api/v3/TwingleSync/models/TwingleProject.php index c9df4a6..43c6068 100644 --- a/api/v3/TwingleSync/models/TwingleProject.php +++ b/api/v3/TwingleSync/models/TwingleProject.php @@ -199,22 +199,37 @@ class TwingleProject { * * @return array */ - private function translateValues() { + private function translateValues($rev = FALSE) { $values = []; - foreach (TwingleProject::$customFieldMapping as $field => $custom) { - if (array_key_exists( - str_replace('twingle_project_', '', $field), - $this->values) - ) { - $values[$custom] = $this->values[str_replace( - 'twingle_project_', - '', - $field)]; + if (!$rev) { + foreach (TwingleProject::$customFieldMapping as $field => $custom) { + if (array_key_exists( + str_replace('twingle_project_', '', $field), + $this->values) + ) { + $values[$custom] = $this->values[str_replace( + 'twingle_project_', + '', + $field + )]; + } } } - // Add necessary attributes - $values['title'] = $this->values['name']; + else { + foreach (TwingleProject::$customFieldMapping as $field => $custom) { + if (array_key_exists($custom, $this->values) + ) { + $values[str_replace( + 'twingle_project_', + '', + $field + )] = $this->values[$custom]; + } + } + } + // Add necessary values $values['campaign_type_id'] = 'twingle_project'; + $values['title'] = $this->values['name']; return $values; }