add $state array
This commit is contained in:
parent
e8cbf505a9
commit
aafce7c32f
1 changed files with 29 additions and 17 deletions
|
@ -26,6 +26,8 @@ class TwingleProject {
|
||||||
|
|
||||||
private static $customFieldMapping;
|
private static $customFieldMapping;
|
||||||
|
|
||||||
|
private $state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwingleProject constructor.
|
* TwingleProject constructor.
|
||||||
*
|
*
|
||||||
|
@ -59,6 +61,13 @@ class TwingleProject {
|
||||||
$this->values['campaign_type_id'] = 'twingle_project';
|
$this->values['campaign_type_id'] = 'twingle_project';
|
||||||
$this->values['title'] = $this->values['name'];
|
$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
|
// Fetch custom field mapping once
|
||||||
self::init();
|
self::init();
|
||||||
|
|
||||||
|
@ -94,24 +103,20 @@ class TwingleProject {
|
||||||
if (!$this->exists()) {
|
if (!$this->exists()) {
|
||||||
if (!$is_test) {
|
if (!$is_test) {
|
||||||
$result = civicrm_api3('Campaign', 'create', $translatedValues);
|
$result = civicrm_api3('Campaign', 'create', $translatedValues);
|
||||||
$this->id = $result['id'];
|
$this->id = $result['id'];
|
||||||
$this->timestamp = $result['last_update'];
|
$this->timestamp = $result['last_update'];
|
||||||
return [
|
$this->state['state'] = 'TwingleProject created';
|
||||||
}
|
}
|
||||||
// If this is a test, do not create campaign
|
// If this is a test, do not create campaign
|
||||||
else {
|
else {
|
||||||
'state' => 'created',
|
$this->state['state'] = 'TwingleProject not yet created';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Give information back if campaign already exists
|
||||||
|
$this->state['state'] = 'TwingleProject exists';
|
||||||
}
|
}
|
||||||
// Give information back if project already exists
|
return $this->state;
|
||||||
return [
|
|
||||||
'title' => $this->values['title'],
|
|
||||||
'id' => $this->id,
|
|
||||||
'project_id' => $this->values['id'],
|
|
||||||
'state' => 'exists',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,12 +136,19 @@ class TwingleProject {
|
||||||
|
|
||||||
if (!$is_test) {
|
if (!$is_test) {
|
||||||
$result = civicrm_api3('Campaign', 'create', $translatedValues);
|
$result = civicrm_api3('Campaign', 'create', $translatedValues);
|
||||||
return [
|
|
||||||
'title' => $this->values['title'],
|
if ($result['is_error'] == 0) {
|
||||||
'id' => $this->id,
|
$this->state['state'] = 'TwingleProject updated form Twingle';
|
||||||
'project_id' => $this->values['id'],
|
}
|
||||||
'state' => 'fetched',
|
else {
|
||||||
];
|
$this->state['state'] = 'Updated from Twingle failed';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->state['state'] = 'TwingleProject outdated';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue