From: eileen Date: Thu, 21 Mar 2019 01:22:03 +0000 (+1300) Subject: Support a multiple select for activity types to include & exclude X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c1d3e3010c95425e5fbf44418244325830059f5e;p=civicrm-core.git Support a multiple select for activity types to include & exclude --- diff --git a/CRM/Activity/Form/ActivityFilter.php b/CRM/Activity/Form/ActivityFilter.php index 7b3abd0405..61eb0b2811 100644 --- a/CRM/Activity/Form/ActivityFilter.php +++ b/CRM/Activity/Form/ActivityFilter.php @@ -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 -')) diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index 476e209daa..a840524af6 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -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); diff --git a/CRM/Core/Page/AJAX.php b/CRM/Core/Page/AJAX.php index 1720351d7b..a51f0ad3e4 100644 --- a/CRM/Core/Page/AJAX.php +++ b/CRM/Core/Page/AJAX.php @@ -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); + } + } } } diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index 1921d5ef15..51b3dcd4de 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -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']);