cache campaign type ids
This commit is contained in:
parent
4b9700da9f
commit
cf6ed7344f
2 changed files with 26 additions and 17 deletions
|
@ -20,11 +20,12 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
|
||||||
private $templates;
|
private $templates;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an instance (singleton)
|
* ## Get an instance (singleton)
|
||||||
* @return self|null
|
*
|
||||||
|
* @return CRM_TwingleCampaign_Utils_ExtensionCache
|
||||||
*/
|
*/
|
||||||
public static function getInstance() {
|
public static function getInstance(): CRM_TwingleCampaign_Utils_ExtensionCache {
|
||||||
if (null === Civi::cache()->get('twinglecampaign_cache')) {
|
if (NULL === Civi::cache()->get('twinglecampaign_cache')) {
|
||||||
Civi::cache()->set('twinglecampaign_cache', new self);
|
Civi::cache()->set('twinglecampaign_cache', new self);
|
||||||
}
|
}
|
||||||
return Civi::cache()->get('twinglecampaign_cache');
|
return Civi::cache()->get('twinglecampaign_cache');
|
||||||
|
@ -34,6 +35,7 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
|
||||||
* Protected ExtensionCache constructor.
|
* Protected ExtensionCache constructor.
|
||||||
*
|
*
|
||||||
* @throws \CiviCRM_API3_Exception
|
* @throws \CiviCRM_API3_Exception
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
protected function __construct() {
|
protected function __construct() {
|
||||||
|
|
||||||
|
@ -67,12 +69,21 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
|
||||||
// Set attribute
|
// Set attribute
|
||||||
$this->$key = $array;
|
$this->$key = $array;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected function __clone() {}
|
// Get ids for Twingle related campaign types
|
||||||
|
foreach ($this->campaigns['campaign_types'] as $campaign_type) {
|
||||||
|
$this->campaigns['campaign_types'][$campaign_type['name']]['id'] = civicrm_api3(
|
||||||
|
'OptionValue',
|
||||||
|
'get',
|
||||||
|
['sequential' => 1, 'name' => $campaign_type['name']]
|
||||||
|
)['values'][0]['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a mapping of all custom field of the TwingleCampaign extension
|
* Returns a mapping of all custom field of the TwingleCampaign extension
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getCustomFieldMapping(): array {
|
public function getCustomFieldMapping(): array {
|
||||||
|
@ -80,23 +91,23 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getTranslations() {
|
public function getTranslations(): array {
|
||||||
return $this->translations;
|
return $this->translations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getCampaigns() {
|
public function getCampaigns(): array {
|
||||||
return $this->campaigns;
|
return $this->campaigns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getTemplates() {
|
public function getTemplates(): array {
|
||||||
return $this->templates;
|
return $this->templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,9 @@ function twinglecampaign_civicrm_postSave_civicrm_campaign($dao) {
|
||||||
$hook_campaign_id = $dao->id;
|
$hook_campaign_id = $dao->id;
|
||||||
|
|
||||||
// Get campaign type id for TwingleProject
|
// Get campaign type id for TwingleProject
|
||||||
$twingle_project_campaign_type_id = civicrm_api3(
|
$twingle_project_campaign_type_id =
|
||||||
'OptionValue',
|
ExtensionCache::getInstance()
|
||||||
'get',
|
->getCampaigns()['campaign_types']['twingle_project']['id'];
|
||||||
['sequential' => 1, 'name' => 'twingle_project']
|
|
||||||
)['values'][0]['value'];
|
|
||||||
|
|
||||||
// If $dao is a TwingleProject campaign, synchronize it
|
// If $dao is a TwingleProject campaign, synchronize it
|
||||||
if ($hook_campaign_type_id == $twingle_project_campaign_type_id) {
|
if ($hook_campaign_type_id == $twingle_project_campaign_type_id) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue