X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FCampaign.php;h=383d556f0409fa9c7ce178586d9ea4e048a15c36;hb=46d87393f7bd29c1a5416e62207293f58115412c;hp=caea8f4d46c0317c9d2d2c7de09c03120ae0e0d0;hpb=c3ba729df769eade45a1ea8a0cfd08f9599c43f2;p=civicrm-core.git diff --git a/api/v3/Campaign.php b/api/v3/Campaign.php index caea8f4d46..383d556f04 100644 --- a/api/v3/Campaign.php +++ b/api/v3/Campaign.php @@ -88,3 +88,61 @@ function civicrm_api3_campaign_get($params) { function civicrm_api3_campaign_delete($params) { return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); } + +/** + * Get campaign list parameters. + * + * @see _civicrm_api3_generic_getlist_params + * + * @param array $request + */ +function _civicrm_api3_campaign_getlist_params(&$request) { + $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']['options']['sort'] = 'start_date DESC, title'; + $request['params'] += [ + 'is_active' => 1, + ]; + } +} + +/** + * Get campaign list output. + * + * @see _civicrm_api3_generic_getlist_output + * + * @param array $result + * @param array $request + * + * @return array + */ +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']), + ], + ]; + 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'])) { + // 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; +}