diff --git a/CRM/TwingleCampaign/BAO/Campaign.php b/CRM/TwingleCampaign/BAO/Campaign.php index a260b0b..c57201d 100644 --- a/CRM/TwingleCampaign/BAO/Campaign.php +++ b/CRM/TwingleCampaign/BAO/Campaign.php @@ -14,10 +14,6 @@ abstract class CRM_TwingleCampaign_BAO_Campaign { // OUT means: coming from the CiviCRM database public const OUT = 'OUT'; - public const CIVICRM = 'CIVICRM'; - - public const TWINGLE = 'TWINGLE'; - protected $className; protected $id; @@ -35,31 +31,18 @@ abstract class CRM_TwingleCampaign_BAO_Campaign { * @param array $campaign * Result array of Twingle API call * - * @param string $origin * Origin of the arrays. It can be one of two constants: * Campaign::TWINGLE|CIVICRM * * @throws Exception */ - protected function __construct(array $campaign, string $origin) { + protected function __construct(array $campaign) { $tmpClassName = explode('_', get_class($this)); $this->className = array_pop($tmpClassName); - // If values come from CiviCRM Campaign API - if ($origin == self::CIVICRM) { - - // Set id (campaign id) attribute - $this->id = $campaign['id']; - - // Translate custom field names into Twingle field names - $this->translateCustomFields($campaign, self::OUT); - - // Translate keys and values - //self::formatValues($campaign, self::OUT); - self::translateKeys($campaign, self::OUT); - - } + // Set campaign values + $this->update($campaign); // Filter project values $filter = Cache::getInstance()->getTemplates()[$this->className]; diff --git a/CRM/TwingleCampaign/BAO/TwingleEvent.php b/CRM/TwingleCampaign/BAO/TwingleEvent.php index 6632322..c16f9d2 100644 --- a/CRM/TwingleCampaign/BAO/TwingleEvent.php +++ b/CRM/TwingleCampaign/BAO/TwingleEvent.php @@ -15,14 +15,10 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign { * Result array of Twingle API call to * https://project.twingle.de/api/$project_id/event * - * @param string $origin - * Origin of the arrays. It can be one of two constants: - * TwingleEvent::TWINGLE|CIVICRM - * * @throws Exception */ - protected function __construct(array $event, string $origin) { - parent::__construct($event, $origin); + protected function __construct(array $event) { + parent::__construct($event); $this->prefix = 'twingle_event_'; $this->values['campaign_type_id'] = 'twingle_event'; @@ -60,10 +56,7 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign { // Instantiate TwingleEvent try { - $event = new self( - $values, - self::TWINGLE - ); + $event = new self($values); } catch (Exception $e) { $errorMessage = $e->getMessage(); diff --git a/CRM/TwingleCampaign/BAO/TwingleProject.php b/CRM/TwingleCampaign/BAO/TwingleProject.php index 228e39f..16ce5cb 100644 --- a/CRM/TwingleCampaign/BAO/TwingleProject.php +++ b/CRM/TwingleCampaign/BAO/TwingleProject.php @@ -13,15 +13,12 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign { * Result array of Twingle API call to * https://project.twingle.de/api/by-organisation/$organisation_id * - * @param string $origin - * Origin of the arrays. It can be one of two constants: - * TwingleProject::TWINGLE|CIVICRM * @param int|null $id * * @throws \Exception */ - function __construct(array $project, string $origin, int $id = NULL) { - parent::__construct($project, $origin); + function __construct(array $project, int $id = NULL) { + parent::__construct($project); $this->id = $id; $this->prefix = 'twingle_project_'; @@ -58,10 +55,7 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign { // Instantiate TwingleProject try { - $project = new self( - $values, - self::TWINGLE - ); + $project = new self($values); } catch (Exception $e) { $errorMessage = $e->getMessage(); diff --git a/api/v3/TwingleSync/Sync.php b/api/v3/TwingleSync/Sync.php index d21607e..41d4711 100644 --- a/api/v3/TwingleSync/Sync.php +++ b/api/v3/TwingleSync/Sync.php @@ -97,10 +97,11 @@ function civicrm_api3_twingle_sync_Sync($params) { $id = $project_from_civicrm['id']; unset($project_from_civicrm['id']); $project_from_civicrm['name'] = $project_from_civicrm['title']; - $project = new TwingleProject($project_from_civicrm, TwingleProject::TWINGLE, $id); + $project = new TwingleProject($project_from_civicrm, $id); $values = $twingleApi->pushProject($project); $project->update($values); $result_values['sync']['projects'][$i++] = $project->create(); + } }