diff --git a/api/v3/TwingleSync/models/TwingleApiCall.php b/api/v3/TwingleSync/models/TwingleApiCall.php index 9c9f7b7..a760ebc 100644 --- a/api/v3/TwingleSync/models/TwingleApiCall.php +++ b/api/v3/TwingleSync/models/TwingleApiCall.php @@ -103,7 +103,14 @@ class TwingleApiCall { } /** - * @param $values + * + * Synchronizes projects between Twingle and CiviCRM (both directions) + * based on the timestamp. + * + * @param array $values + * + * If true: don't do any changes + * @param bool $is_test * * @return array|null * @throws \CiviCRM_API3_Exception @@ -182,12 +189,12 @@ class TwingleApiCall { private function curlPost($url, $data) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POST, TRUE); curl_setopt($curl, CURLOPT_HTTPHEADER, [ "x-access-code: $this->apiKey", 'Content-Type: application/json', ]); - curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); + curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); $response = json_decode(curl_exec($curl), TRUE); if (empty($response)) { $response = curl_error($curl); @@ -196,4 +203,4 @@ class TwingleApiCall { return $response; } -} \ No newline at end of file +} diff --git a/api/v3/TwingleSync/models/TwingleProject.php b/api/v3/TwingleSync/models/TwingleProject.php index a60c13e..5f707e1 100644 --- a/api/v3/TwingleSync/models/TwingleProject.php +++ b/api/v3/TwingleSync/models/TwingleProject.php @@ -52,7 +52,8 @@ class TwingleProject { if ($translate) { $this->values = $this->translateValues(TRUE); $this->id = $values['id']; - } else { + } + else { // Format data types for import into CiviCRM $this->formatForImport($this->values); } @@ -91,6 +92,10 @@ class TwingleProject { /** * Create the project as a campaign in CiviCRM if it does not exist * + * If true: don't do any changes + * + * @param bool $is_test + * * @return array * @throws \CiviCRM_API3_Exception */ @@ -99,7 +104,7 @@ class TwingleProject { // Translate $value keys to custom field names $translatedValues = $this->translateValues(); - // Create project if it does not exist yet and give back the result + // Create campaign if it does not already exist and give back the result if (!$this->exists()) { if (!$is_test) { $result = civicrm_api3('Campaign', 'create', $translatedValues); @@ -309,6 +314,10 @@ class TwingleProject { $values['last_update'] = $date->format('Y-m-d H:i:s'); } + // Change name to title + $values['title'] = $values['name']; + unset($values['name']); + // Change event type empty string into 'default' if ($values['type'] == '') { $values['type'] = 'default'; @@ -328,6 +337,10 @@ class TwingleProject { $values['last_update'] = $date->getTimestamp(); } + // Change title to name + $values['name'] = $values['title']; + unset($values['title']); + // Change event type 'default' into empty string if ($values['type'] == 'default') { $values['type'] = ''; @@ -402,4 +415,4 @@ class TwingleProject { } -} \ No newline at end of file +}