add search parameters to TwingleCampaign.get
This commit is contained in:
parent
6f69a8ebf6
commit
76adafe66c
1 changed files with 79 additions and 20 deletions
|
@ -26,10 +26,56 @@ function _civicrm_api3_twingle_campaign_Get_spec(array &$spec) {
|
||||||
'api.required' => 0,
|
'api.required' => 0,
|
||||||
'description' => E::ts('Twingle ID of the parent TwingleProject'),
|
'description' => E::ts('Twingle ID of the parent TwingleProject'),
|
||||||
];
|
];
|
||||||
|
$spec['name'] = [
|
||||||
|
'name' => 'name',
|
||||||
|
'title' => E::ts('Campaign Name'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Name of the Campaign'),
|
||||||
|
];
|
||||||
|
$spec['title'] = [
|
||||||
|
'name' => 'title',
|
||||||
|
'title' => E::ts('Campaign Title'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Title of the Campaign'),
|
||||||
|
];
|
||||||
|
$spec['start_date'] = [
|
||||||
|
'name' => 'start_date',
|
||||||
|
'title' => E::ts('Campaign Start Date'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Date and Time that Campaign starts.'),
|
||||||
|
];
|
||||||
|
$spec['last_modified_id'] = [
|
||||||
|
'name' => 'last_modified_id',
|
||||||
|
'title' => E::ts('Campaign Modified By'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('FK ti civicrm_contact, who recently edited this campaign'),
|
||||||
|
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||||
|
];
|
||||||
|
$spec['last_modified_date'] = [
|
||||||
|
'name' => 'last_modified_date',
|
||||||
|
'title' => E::ts('Campaign Modified Date'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('FK ti civicrm_contact, who recently edited this campaign'),
|
||||||
|
];
|
||||||
|
$spec['is_active'] = [
|
||||||
|
'name' => 'is_active',
|
||||||
|
'title' => E::ts('Campaign is active'),
|
||||||
|
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Is this Campaign enabled or disabled/cancelled?'),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwingleCampaign.Get API
|
* # TwingleCampaign.Get API
|
||||||
|
* Gets TwingleCampaign campaigns by the provided parameters.<br>
|
||||||
|
* If a TwingleProject **project_id** is provided, this API returns all its
|
||||||
|
* TwingleCampaign children campaigns.
|
||||||
*
|
*
|
||||||
* @param array $params
|
* @param array $params
|
||||||
*
|
*
|
||||||
|
@ -49,39 +95,53 @@ function civicrm_api3_twingle_campaign_Get(array $params): array {
|
||||||
|
|
||||||
$returnValues = [];
|
$returnValues = [];
|
||||||
|
|
||||||
// If an id is provided, get a single project
|
// Get campaign type id for TwingleCampaign
|
||||||
if ($params['id']) {
|
$twingle_campaign_campaign_type_id =
|
||||||
$campaigns = civicrm_api3('Campaign',
|
Cache::getInstance()
|
||||||
'get',
|
->getCampaigns()['campaign_types']['twingle_campaign']['id'];
|
||||||
['id' => $params['id']]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// If no id but a project_id is provided, get all TwingleCampaign children of
|
// If no id but a project_id is provided, get all TwingleCampaign children of
|
||||||
// this TwingleProject
|
// this TwingleProject
|
||||||
elseif ($params['project_id']) {
|
if (array_key_exists('project_id', $params) && $params['project_id']) {
|
||||||
|
|
||||||
// Get campaign type id for TwingleCampaign
|
|
||||||
$twingle_campaign_campaign_type_id =
|
|
||||||
Cache::getInstance()
|
|
||||||
->getCampaigns()['campaign_types']['twingle_campaign']['id'];
|
|
||||||
|
|
||||||
|
// Get TwingleProject
|
||||||
$project = civicrm_api3('TwingleProject',
|
$project = civicrm_api3('TwingleProject',
|
||||||
'get',
|
'get',
|
||||||
['project_id' => $params['project_id']]
|
['project_id' => $params['project_id']]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Remove 'parent_id' from $params
|
||||||
|
unset($params['project_id']);
|
||||||
|
|
||||||
|
// Include parent TwingleProject id in $params
|
||||||
|
$params['parent_id'] = $project['id'];
|
||||||
|
|
||||||
|
// Include campaign type ot TwingleCampaigns in $params
|
||||||
|
$params['campaign_type_id'] = $twingle_campaign_campaign_type_id;
|
||||||
|
|
||||||
|
// Get TwingleCampaign children campaigns of the TwingleProject
|
||||||
$campaigns = civicrm_api3('Campaign',
|
$campaigns = civicrm_api3('Campaign',
|
||||||
'get',
|
'get',
|
||||||
[
|
$params
|
||||||
'parent_id' => $project['id'],
|
);
|
||||||
'campaign_type_id' => $twingle_campaign_campaign_type_id
|
}
|
||||||
]
|
// If no 'project_id' is provided, get all TwingleCampaigns by the provided
|
||||||
|
// $params
|
||||||
|
else {
|
||||||
|
|
||||||
|
// Include campaign type ot TwingleCampaigns in $params
|
||||||
|
$params['campaign_type_id'] = $twingle_campaign_campaign_type_id;
|
||||||
|
|
||||||
|
$campaigns = civicrm_api3('Campaign',
|
||||||
|
'get',
|
||||||
|
$params
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate custom fields
|
// Translate custom fields
|
||||||
if (!empty($campaigns)) {
|
if (!empty($campaigns)) {
|
||||||
$custom_field_mapping_reverse = array_flip(Cache::getInstance()->getCustomFieldMapping());
|
$custom_field_mapping_reverse =
|
||||||
|
array_flip(Cache::getInstance()->getCustomFieldMapping());
|
||||||
|
|
||||||
foreach ($campaigns['values'] as $campaign) {
|
foreach ($campaigns['values'] as $campaign) {
|
||||||
foreach ($campaign as $key => $value) {
|
foreach ($campaign as $key => $value) {
|
||||||
|
@ -103,7 +163,6 @@ function civicrm_api3_twingle_campaign_Get(array $params): array {
|
||||||
}
|
}
|
||||||
|
|
||||||
return civicrm_api3_create_success($returnValues, $params, 'TwingleCampaign', 'Get');
|
return civicrm_api3_create_success($returnValues, $params, 'TwingleCampaign', 'Get');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return civicrm_api3_create_success($returnValues, $params, 'TwingleCampaign', 'Get');
|
return civicrm_api3_create_success($returnValues, $params, 'TwingleCampaign', 'Get');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue