move translateKeys into child classes

method logic differs between the child classes
This commit is contained in:
Marc Michalsky forumZFD 2020-12-15 14:52:07 +01:00
parent b210f42b8f
commit 57fd1b7d5a
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
3 changed files with 80 additions and 24 deletions

View file

@ -292,6 +292,45 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign {
}
}
/**
* Translate array keys between CiviCRM Campaigns and Twingle
*
* @param array $values
* array of which keys shall be translated
*
* @param string $direction
* Campaign::IN -> translate array keys from Twingle format into
* CiviCRM format <br>
* Campaign::OUT -> translate array keys from CiviCRM format into
* Twingle format
*
* @throws Exception
*/
public static function translateKeys(array &$values, string $direction) {
// Get translations for fields
$field_translations = Cache::getInstance()
->getTranslations()['TwingleEvent'];
// Set the direction of the translation
if ($direction == self::OUT) {
$field_translations = array_flip($field_translations);
}
// Throw error if $direction constant does not match IN or OUT
elseif ($direction != self::IN) {
throw new Exception(
"Invalid Parameter $direction for translateKeys()"
);
// TODO: use specific exception or create own
}
// Translate keys
foreach ($field_translations as $origin => $translation) {
$values[$translation] = $values[$origin];
unset($values[$origin]);
}
}
/**
* Get a response that describes the status of a TwingleEvent