Commit b7b528bc authored by colemanw's avatar colemanw

Campaign entityRef improvements

parent f7b32533
......@@ -870,6 +870,41 @@ class CRM_Core_Resources {
}
}
if (in_array('CiviCampaign', $config->enableComponents)) {
$filters['campaign'] = [
['key' => 'campaign_type_id', 'value' => ts('Campaign Type')],
['key' => 'status_id', 'value' => ts('Status')],
[
'key' => 'start_date',
'value' => ts('Start Date'),
'options' => [
['key' => '{">":"now"}', 'value' => ts('Upcoming')],
[
'key' => '{"BETWEEN":["now - 3 month","now"]}',
'value' => ts('Past 3 Months'),
],
[
'key' => '{"BETWEEN":["now - 6 month","now"]}',
'value' => ts('Past 6 Months'),
],
[
'key' => '{"BETWEEN":["now - 1 year","now"]}',
'value' => ts('Past Year'),
],
],
],
[
'key' => 'end_date',
'value' => ts('End Date'),
'options' => [
['key' => '{">":"now"}', 'value' => ts('In the future')],
['key' => '{"<":"now"}', 'value' => ts('In the past')],
['key' => '{"IS NULL":"1"}', 'value' => ts('Not set')],
],
],
];
}
CRM_Utils_Hook::entityRefFilters($filters);
return $filters;
......
......@@ -97,7 +97,7 @@ function civicrm_api3_campaign_delete($params) {
* @param array $request
*/
function _civicrm_api3_campaign_getlist_params(&$request) {
$fieldsToReturn = ['title', 'campaign_type_id', 'start_date', 'end_date'];
$fieldsToReturn = ['title', 'campaign_type_id', 'status_id', 'start_date', 'end_date'];
$request['params']['return'] = array_unique(array_merge($fieldsToReturn, $request['extra']));
if (empty($request['params']['id'])) {
$request['params'] += [
......@@ -119,25 +119,29 @@ function _civicrm_api3_campaign_getlist_params(&$request) {
function _civicrm_api3_campaign_getlist_output($result, $request) {
$output = [];
if (!empty($result['values'])) {
$config = CRM_Core_Config::singleton();
foreach ($result['values'] as $row) {
$data = [
'id' => $row[$request['id_field']],
'label' => $row[$request['label_field']],
'description' => [
CRM_Core_Pseudoconstant::getLabel(
'CRM_Campaign_BAO_Campaign',
'campaign_type_id',
$row['campaign_type_id']
),
CRM_Core_Pseudoconstant::getLabel('CRM_Campaign_BAO_Campaign', 'campaign_type_id', $row['campaign_type_id']),
],
];
$config = CRM_Core_Config::singleton();
$data['description'][0] .= ': ' . CRM_Utils_Date::customFormat($row['start_date'], $config->dateformatFull) . ' - ';
if (!empty($row['status_id'])) {
$data['description'][0] .= ': ' . CRM_Core_Pseudoconstant::getLabel('CRM_Campaign_BAO_Campaign', 'status_id', $row['status_id']);
}
$dateString = CRM_Utils_Date::customFormat($row['start_date'], $config->dateformatFull) . ' -';
if (!empty($row['end_date'])) {
$data['description'][0] .= CRM_Utils_Date::customFormat($row['end_date'], $config->dateformatFull);
// Remove redundant years
if (substr($row['start_date'], 0, 4) == substr($row['end_date'], 0, 4)) {
$dateString = preg_replace('/[, ]*' . substr($row['start_date'], 0, 4) . '/', '', $dateString);
}
$dateString .= ' ' . CRM_Utils_Date::customFormat($row['end_date'], $config->dateformatFull);
}
$data['description'][] = $dateString;
$output[] = $data;
}
}
return $output;
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment