add comments and style code

This commit is contained in:
Marc Michalsky forumZFD 2020-09-30 15:34:06 +02:00
parent 85afeedd23
commit c7eca6f641
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
2 changed files with 27 additions and 7 deletions

View file

@ -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 * @return array|null
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
@ -182,12 +189,12 @@ class TwingleApiCall {
private function curlPost($url, $data) { private function curlPost($url, $data) {
$curl = curl_init($url); $curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, [ curl_setopt($curl, CURLOPT_HTTPHEADER, [
"x-access-code: $this->apiKey", "x-access-code: $this->apiKey",
'Content-Type: application/json', '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); $response = json_decode(curl_exec($curl), TRUE);
if (empty($response)) { if (empty($response)) {
$response = curl_error($curl); $response = curl_error($curl);
@ -196,4 +203,4 @@ class TwingleApiCall {
return $response; return $response;
} }
} }

View file

@ -52,7 +52,8 @@ class TwingleProject {
if ($translate) { if ($translate) {
$this->values = $this->translateValues(TRUE); $this->values = $this->translateValues(TRUE);
$this->id = $values['id']; $this->id = $values['id'];
} else { }
else {
// Format data types for import into CiviCRM // Format data types for import into CiviCRM
$this->formatForImport($this->values); $this->formatForImport($this->values);
} }
@ -91,6 +92,10 @@ class TwingleProject {
/** /**
* Create the project as a campaign in CiviCRM if it does not exist * 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 * @return array
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
*/ */
@ -99,7 +104,7 @@ class TwingleProject {
// Translate $value keys to custom field names // Translate $value keys to custom field names
$translatedValues = $this->translateValues(); $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 (!$this->exists()) {
if (!$is_test) { if (!$is_test) {
$result = civicrm_api3('Campaign', 'create', $translatedValues); $result = civicrm_api3('Campaign', 'create', $translatedValues);
@ -309,6 +314,10 @@ class TwingleProject {
$values['last_update'] = $date->format('Y-m-d H:i:s'); $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' // Change event type empty string into 'default'
if ($values['type'] == '') { if ($values['type'] == '') {
$values['type'] = 'default'; $values['type'] = 'default';
@ -328,6 +337,10 @@ class TwingleProject {
$values['last_update'] = $date->getTimestamp(); $values['last_update'] = $date->getTimestamp();
} }
// Change title to name
$values['name'] = $values['title'];
unset($values['title']);
// Change event type 'default' into empty string // Change event type 'default' into empty string
if ($values['type'] == 'default') { if ($values['type'] == 'default') {
$values['type'] = ''; $values['type'] = '';
@ -402,4 +415,4 @@ class TwingleProject {
} }
} }