add $state array

This commit is contained in:
Marc Michalsky forumZFD 2020-09-30 15:32:29 +02:00
parent e8cbf505a9
commit aafce7c32f
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9

View file

@ -26,6 +26,8 @@ class TwingleProject {
private static $customFieldMapping;
private $state;
/**
* TwingleProject constructor.
*
@ -59,6 +61,13 @@ class TwingleProject {
$this->values['campaign_type_id'] = 'twingle_project';
$this->values['title'] = $this->values['name'];
// Set state
$this->state = [
'title' => $this->values['title'],
'id' => $this->id,
'project_id' => $this->values['id'],
];
// Fetch custom field mapping once
self::init();
@ -94,24 +103,20 @@ class TwingleProject {
if (!$this->exists()) {
if (!$is_test) {
$result = civicrm_api3('Campaign', 'create', $translatedValues);
$this->id = $result['id'];
$this->timestamp = $result['last_update'];
return [
$this->id = $result['id'];
$this->timestamp = $result['last_update'];
$this->state['state'] = 'TwingleProject created';
}
// If this is a test, do not create campaign
else {
'state' => 'created',
$this->state['state'] = 'TwingleProject not yet created';
}
}
else {
// Give information back if campaign already exists
$this->state['state'] = 'TwingleProject exists';
}
// Give information back if project already exists
return [
'title' => $this->values['title'],
'id' => $this->id,
'project_id' => $this->values['id'],
'state' => 'exists',
];
return $this->state;
}
/**
@ -131,12 +136,19 @@ class TwingleProject {
if (!$is_test) {
$result = civicrm_api3('Campaign', 'create', $translatedValues);
return [
'title' => $this->values['title'],
'id' => $this->id,
'project_id' => $this->values['id'],
'state' => 'fetched',
];
if ($result['is_error'] == 0) {
$this->state['state'] = 'TwingleProject updated form Twingle';
}
else {
$this->state['state'] = 'Updated from Twingle failed';
}
}
else {
$this->state['state'] = 'TwingleProject outdated';
}
return $this->state;
}
/**