Campaign entityRef improvements
authorColeman Watts <coleman@civicrm.org>
Tue, 22 Jan 2019 14:39:39 +0000 (09:39 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 22 Jan 2019 14:39:39 +0000 (09:39 -0500)
CRM/Core/Resources.php
api/v3/Campaign.php

index 195d224063b14f810926b1733e83569a569eed95..3e84242cdeda3d8a05d80b4de51e3d9d65bd6aec 100644 (file)
@@ -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;
index bb1520358bce23c7779d1de3567a82b6b6c0eb98..f99feb3ab8a1e2b79cf8aa49b6b60b2722dae2c7 100644 (file)
@@ -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
+}