👾 bug fix: cannot set TwingleProject url via TwingleForm.create API
This commit is contained in:
parent
ef74a52e9f
commit
c22911e886
4 changed files with 66 additions and 26 deletions
|
@ -125,7 +125,9 @@ abstract class CRM_TwingleCampaign_BAO_Campaign {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Complement campaign values
|
* ## Complement campaign values
|
||||||
* Complement existing campaign values with new ones
|
* Complement existing campaign values with new ones.
|
||||||
|
* Existing values will not get overwritten.
|
||||||
|
*
|
||||||
* @param array $arrayToComplement
|
* @param array $arrayToComplement
|
||||||
*/
|
*/
|
||||||
public function complement(array $arrayToComplement) {
|
public function complement(array $arrayToComplement) {
|
||||||
|
@ -143,6 +145,27 @@ abstract class CRM_TwingleCampaign_BAO_Campaign {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ## Merge campaign values
|
||||||
|
* Merge existing campaign values with new ones.
|
||||||
|
* Existing values will be overwritten!
|
||||||
|
*
|
||||||
|
* @param array $arrayToMerge
|
||||||
|
*/
|
||||||
|
public function merge(array $arrayToMerge) {
|
||||||
|
$this->complement_r($arrayToMerge, $this->values);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function merge_r($orig, &$fill) {
|
||||||
|
foreach ($orig as $key => $value) {
|
||||||
|
if (is_array($value)) {
|
||||||
|
$this->complement_r($orig[$key], $fill[$key]);
|
||||||
|
} else {
|
||||||
|
$fill[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static abstract function formatValues(array &$values, string $direction);
|
public static abstract function formatValues(array &$values, string $direction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,15 +32,14 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
||||||
$this->id = $id ?? NULL;
|
$this->id = $id ?? NULL;
|
||||||
$this->values['campaign_type_id'] = 'twingle_campaign';
|
$this->values['campaign_type_id'] = 'twingle_campaign';
|
||||||
|
|
||||||
if (!isset($this->id)) {
|
|
||||||
$this->update($values);
|
$this->update($values);
|
||||||
$this->getParentProject();
|
$this->getParentProject();
|
||||||
|
if (!isset($this->values['cid'])) {
|
||||||
$this->createCid();
|
$this->createCid();
|
||||||
|
}
|
||||||
$this->createUrl();
|
$this->createUrl();
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this->update($values);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -318,7 +317,15 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
function getResponse(string $status = NULL): array {
|
function getResponse(string $status = NULL): array {
|
||||||
$keys = ['id', 'name', 'title', 'parent_project_id', 'parent_id', 'cid', 'url'];
|
$keys = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'title',
|
||||||
|
'parent_project_id',
|
||||||
|
'parent_id',
|
||||||
|
'cid',
|
||||||
|
'url',
|
||||||
|
];
|
||||||
$response = [];
|
$response = [];
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
if (isset($this->values[$key])) {
|
if (isset($this->values[$key])) {
|
||||||
|
@ -366,6 +373,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Get ID
|
* ## Get ID
|
||||||
|
*
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*/
|
*/
|
||||||
public function getId(): int {
|
public function getId(): int {
|
||||||
|
|
|
@ -86,8 +86,7 @@ function civicrm_api3_twingle_project_Create(array $params): array {
|
||||||
unset($result['project_id']);
|
unset($result['project_id']);
|
||||||
$project = new TwingleProject($result, $params['id']);
|
$project = new TwingleProject($result, $params['id']);
|
||||||
unset($params['id']);
|
unset($params['id']);
|
||||||
$project->update($params);
|
$project->merge($params);
|
||||||
$project->setEmbedData($params);
|
|
||||||
}
|
}
|
||||||
// If no id is provided, try to create a new project with provided values
|
// If no id is provided, try to create a new project with provided values
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -62,6 +62,8 @@ function twinglecampaign_civicrm_postSave_civicrm_campaign($dao) {
|
||||||
if (empty($_SESSION['CiviCRM']['de.forumzfd.twinglecampaign']['no_hook']) ||
|
if (empty($_SESSION['CiviCRM']['de.forumzfd.twinglecampaign']['no_hook']) ||
|
||||||
$_SESSION['CiviCRM']['de.forumzfd.twinglecampaign']['no_hook'] != TRUE) {
|
$_SESSION['CiviCRM']['de.forumzfd.twinglecampaign']['no_hook'] != TRUE) {
|
||||||
|
|
||||||
|
// If request is not an API-Call
|
||||||
|
if ($_GET['action'] != 'create') {
|
||||||
|
|
||||||
// If the db transaction is still running, add a function to it that will
|
// If the db transaction is still running, add a function to it that will
|
||||||
// be called afterwards
|
// be called afterwards
|
||||||
|
@ -83,6 +85,14 @@ function twinglecampaign_civicrm_postSave_civicrm_campaign($dao) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
CRM_Core_Transaction::addCallback(
|
||||||
|
CRM_Core_Transaction::PHASE_POST_COMMIT,
|
||||||
|
'twinglecampaign_postSave_campaign_update_callback',
|
||||||
|
[$dao->id, $dao->campaign_type_id]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Remove no hook flag
|
// Remove no hook flag
|
||||||
unset($_SESSION['CiviCRM']['de.forumzfd.twinglecampaign']['no_hook']);
|
unset($_SESSION['CiviCRM']['de.forumzfd.twinglecampaign']['no_hook']);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue