Support a multiple select for activity types to include & exclude
authoreileen <emcnaughton@wikimedia.org>
Thu, 21 Mar 2019 01:22:03 +0000 (14:22 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 28 Mar 2019 19:02:53 +0000 (08:02 +1300)
CRM/Activity/Form/ActivityFilter.php
CRM/Activity/Page/AJAX.php
CRM/Core/Page/AJAX.php
tests/phpunit/CRM/Activity/BAO/ActivityTest.php

index 7b3abd0405c2b86fd9f262767243b0f8f1f5ef30..61eb0b281117adb650dc23c557d80bfa2e93fcf8 100644 (file)
@@ -40,8 +40,8 @@ class CRM_Activity_Form_ActivityFilter extends CRM_Core_Form {
     $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
     asort($activityOptions);
 
-    $this->add('select', 'activity_type_filter_id', ts('Include'), array('' => ts('- all activity type(s) -')) + $activityOptions);
-    $this->add('select', 'activity_type_exclude_filter_id', ts('Exclude'), array('' => ts('- select activity type -')) + $activityOptions);
+    $this->add('select', 'activity_type_filter_id', ts('Include'), $activityOptions, FALSE, ['class' => 'crm-select2', 'multiple' => TRUE, 'placeholder' => ts('- all activity type(s) -')]);
+    $this->add('select', 'activity_type_exclude_filter_id', ts('Exclude'), $activityOptions, FALSE, ['class' => 'crm-select2', 'multiple' => TRUE, 'placeholder' => ts('- no types excluded -')]);
     $this->addDatePickerRange('activity_date_time', ts('Date'));
     $this->addSelect('status_id',
       array('entity' => 'activity', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))
index 476e209daaea1c650251d046d9e31560e1935fe5..a840524af6e6b384054fca9560431a5acdb5b7fb 100644 (file)
@@ -437,7 +437,7 @@ class CRM_Activity_Page_AJAX {
           $formSearchField = 'activity_type_exclude_filter_id';
         }
         if (!empty($params[$searchField])) {
-          $activityFilter[$formSearchField] = CRM_Utils_Type::escape($params[$searchField], $dataType);
+          $activityFilter[$formSearchField] = $params[$searchField];
           if (in_array($searchField, array('activity_date_time_low', 'activity_date_time_high'))) {
             $activityFilter['activity_date_time_relative'] = 0;
           }
@@ -445,9 +445,6 @@ class CRM_Activity_Page_AJAX {
             $activityFilter['status_id'] = explode(',', $activityFilter[$searchField]);
           }
         }
-        elseif (in_array($searchField, array('activity_type_id', 'activity_type_exclude_id'))) {
-          $activityFilter[$formSearchField] = '';
-        }
       }
 
       Civi::contactSettings()->set('activity_tab_filter', $activityFilter);
index 1720351d7b699ab4ea68e5995ea42576a76f9c3c..a51f0ad3e4fb24be4eead9d611cbcb955ea3667b 100644 (file)
@@ -270,7 +270,14 @@ class CRM_Core_Page_AJAX {
 
     foreach ($optionalParams as $param => $type) {
       if (CRM_Utils_Array::value($param, $_GET)) {
-        $params[$param] = CRM_Utils_Type::validate(CRM_Utils_Array::value($param, $_GET), $type);
+        if (!is_array($_GET[$param])) {
+          $params[$param] = CRM_Utils_Type::validate(CRM_Utils_Array::value($param, $_GET), $type);
+        }
+        else {
+          foreach ($_GET[$param] as $index => $value) {
+            $params[$param][$index] = CRM_Utils_Type::validate($value, $type);
+          }
+        }
       }
     }
 
index 1921d5ef1565e0d11814c47c392925fc63a6d5fb..51b3dcd4def025ca69aefbf2c4f0475f47fc3b07 100644 (file)
@@ -403,7 +403,6 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
     );
     $expectedFilters = array(
       'activity_type_filter_id' => 1,
-      'activity_type_exclude_filter_id' => '',
     );
 
     list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity();
@@ -414,11 +413,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
       $this->assertContains('Meeting', $value['activity_type']);
     }
     unset($_GET['activity_type_id']);
-    $expectedFilters['activity_type_filter_id'] = '';
 
     $_GET['activity_type_exclude_id'] = $expectedFilters['activity_type_exclude_filter_id'] = 1;
     list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity();
-    $this->checkArrayEquals($expectedFilters, $activityFilter);
+    $this->assertEquals(['activity_type_exclude_filter_id' => 1], $activityFilter);
     // None of the activities should be of type Meeting.
     foreach ($activities['data'] as $value) {
       $this->assertNotContains('Meeting', $value['activity_type']);