move translateKeys into child classes
method logic differs between the child classes
This commit is contained in:
parent
b210f42b8f
commit
57fd1b7d5a
3 changed files with 80 additions and 24 deletions
|
@ -171,6 +171,7 @@ abstract class CRM_TwingleCampaign_BAO_Campaign {
|
||||||
* Deactivate all duplicates of a campaign but the newest one
|
* Deactivate all duplicates of a campaign but the newest one
|
||||||
*
|
*
|
||||||
* @param array $result
|
* @param array $result
|
||||||
|
*
|
||||||
* @throws CiviCRM_API3_Exception
|
* @throws CiviCRM_API3_Exception
|
||||||
*/
|
*/
|
||||||
protected function handleDuplicates(array &$result) {
|
protected function handleDuplicates(array &$result) {
|
||||||
|
@ -201,30 +202,7 @@ abstract class CRM_TwingleCampaign_BAO_Campaign {
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function translateKeys(array &$values, string $direction) {
|
public static abstract function translateKeys(array &$values, string $direction);
|
||||||
|
|
||||||
// Get translations for fields
|
|
||||||
$field_translations = Cache::getInstance()
|
|
||||||
->getTranslations()[$this->className];
|
|
||||||
|
|
||||||
// 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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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
|
* Get a response that describes the status of a TwingleEvent
|
||||||
|
|
|
@ -321,6 +321,45 @@ class CRM_TwingleCampaign_BAO_TwingleProject 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()['TwingleProject'];
|
||||||
|
|
||||||
|
// 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set embed data fields
|
* Set embed data fields
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue