change way to give back the TwigleProject response

This commit is contained in:
Marc Michalsky forumZFD 2020-10-01 11:49:32 +02:00
parent 96952b7253
commit ad4f32e2d6
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
2 changed files with 23 additions and 12 deletions

View file

@ -121,13 +121,13 @@ class TwingleApiCall {
$project = new TwingleProject($values);
$result = $project->create($is_test);
if (
$result['state'] == 'exists' &&
$result['state'] == 'TwingleProject exists' &&
$values['last_update'] > $project->getTimestamp()
) {
$result = $project->update($is_test);
}
elseif (
$result['state'] == 'exists' &&
$result['state'] == 'TwingleProject exists' &&
$values['last_update'] < $project->getTimestamp()
) {
$result = $this->updateProject($project->export());

View file

@ -26,8 +26,6 @@ class TwingleProject {
private static $customFieldMapping;
private $state;
/**
* TwingleProject constructor.
*
@ -101,6 +99,8 @@ class TwingleProject {
*/
public function create(bool $is_test = FALSE) {
$response = '';
// Translate $value keys to custom field names
$translatedValues = $this->translateValues();
@ -110,18 +110,18 @@ class TwingleProject {
$result = civicrm_api3('Campaign', 'create', $translatedValues);
$this->id = $result['id'];
$this->timestamp = $result['last_update'];
$this->state['state'] = 'TwingleProject created';
$response = $this->getResponse('TwingleProject created');
}
// If this is a test, do not create campaign
else {
$this->state['state'] = 'TwingleProject not yet created';
$response = $this->getResponse('TwingleProject not yet created');
}
}
else {
// Give information back if campaign already exists
$this->state['state'] = 'TwingleProject exists';
$response = $this->getResponse('TwingleProject exists');
}
return $this->state;
return $response;
}
/**
@ -136,6 +136,8 @@ class TwingleProject {
*/
public function update(bool $is_test = FALSE) {
$response = '';
// Translate $value keys to custom field names
$translatedValues = $this->translateValues();
@ -143,17 +145,17 @@ class TwingleProject {
$result = civicrm_api3('Campaign', 'create', $translatedValues);
if ($result['is_error'] == 0) {
$this->state['state'] = 'TwingleProject updated form Twingle';
$response = $this->getResponse('TwingleProject updated form Twingle');
}
else {
$this->state['state'] = 'Updated from Twingle failed';
$response = $this->getResponse('Updated from Twingle failed');
}
}
else {
$this->state['state'] = 'TwingleProject outdated';
$response = $this->getResponse('TwingleProject outdated');
}
return $this->state;
return $response;
}
/**
@ -372,6 +374,15 @@ class TwingleProject {
}
public function getResponse(string $state) {
return [
'title' => $this->values['title'],
'id' => $this->id,
'project_id' => $this->values['id'],
'state' => $state,
];
}
/**
* @return mixed
*/