From: jitendrapurohit Date: Tue, 7 Jun 2016 11:17:53 +0000 (+0530) Subject: CRM-18706 - Activity type filter on user activities is not working X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=23289ddd6c95ac6a335a52d8aff5979755e2a159;p=civicrm-core.git CRM-18706 - Activity type filter on user activities is not working --- diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index b91804d8aa..95992e121e 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -396,6 +396,8 @@ class CRM_Activity_Page_AJAX { $optionalParameters = array( 'context' => 'String', + 'activity_type_id' => 'Integer', + 'activity_type_exclude_id' => 'Integer', ); $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); @@ -409,6 +411,10 @@ class CRM_Activity_Page_AJAX { // get the contact activities $activities = CRM_Activity_BAO_Activity::getContactActivitySelector($params); + if (!empty($_GET['is_unit_test'])) { + return $activities; + } + foreach ($activities['data'] as $key => $value) { // Check if recurring activity. if (!empty($value['is_recurring_activity'])) { diff --git a/templates/CRM/Activity/Selector/Selector.tpl b/templates/CRM/Activity/Selector/Selector.tpl index afd029e89d..e49ec1c4e7 100644 --- a/templates/CRM/Activity/Selector/Selector.tpl +++ b/templates/CRM/Activity/Selector/Selector.tpl @@ -62,14 +62,14 @@ "ajax": { "url": {/literal}'{crmURL p="civicrm/ajax/contactactivity" h=0 q="snippet=4&context=$context&cid=$contactId"}'{literal}, "data": function (d) { - d.activity_type_id = $('.crm-activity-selector-activity select#activity_type_filter_id').val(), - d.activity_type_exclude_id = $('.crm-activity-selector-activity select#activity_type_exclude_filter_id').val() + d.activity_type_id = $('.crm-activity-selector-' + context + ' select#activity_type_filter_id').val(), + d.activity_type_exclude_id = $('.crm-activity-selector-' + context + ' select#activity_type_exclude_filter_id').val() } } }); $(function($) { $('.activity-search-options :input').change(function(){ - CRM.$('.contact-activity-selector-activity').DataTable().draw(); + CRM.$('table.contact-activity-selector-' + context).DataTable().draw(); }); }); })(CRM.$); diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index 7e3bf5f1d6..18d949b8a7 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -360,6 +360,41 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $this->assertEquals($count, $activityCount); } + /** + * CRM-18706 - Test Include/Exclude Activity Filters + */ + public function testActivityFilters() { + $op = new PHPUnit_Extensions_Database_Operation_Insert(); + $op->execute($this->_dbconn, + $this->createFlatXMLDataSet( + dirname(__FILE__) . '/activities_for_dashboard_count.xml' + ) + ); + + global $_GET; + $_GET = array( + 'cid' => 9, + 'context' => 'activity', + 'activity_type_id' => 1, + 'is_unit_test' => 1, + ); + $obj = new CRM_Activity_Page_AJAX(); + + $activities = $obj->getContactActivity(); + // This should include activities of type Meeting only. + foreach ($activities['data'] as $key => $value) { + $this->assertEquals('Meeting', $value['activity_type']); + } + unset($_GET['activity_type_id']); + + $_GET['activity_type_exclude_id'] = 1; + $activities = $obj->getContactActivity(); + // None of the activities should be of type Meeting. + foreach ($activities['data'] as $key => $value) { + $this->assertNotEquals('Meeting', $value['activity_type']); + } + } + /** * Test getActivitiesCount BAO method. */