From: Coleman Watts Date: Tue, 22 Jan 2019 14:39:39 +0000 (-0500) Subject: Campaign entityRef improvements X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b7b528bc8826971a6dbeebefc185ab19331d051f;p=civicrm-core.git Campaign entityRef improvements --- diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 195d224063..3e84242cde 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -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; diff --git a/api/v3/Campaign.php b/api/v3/Campaign.php index bb1520358b..f99feb3ab8 100644 --- a/api/v3/Campaign.php +++ b/api/v3/Campaign.php @@ -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 +}