Fix Activity api to cope with renamed record type ids.
authoreileen <emcnaughton@wikimedia.org>
Thu, 25 Oct 2018 00:05:09 +0000 (13:05 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 25 Oct 2018 00:05:42 +0000 (13:05 +1300)
Filter activities based on the name of activity contacts options instead of option label

api/v3/Activity.php
tests/phpunit/api/v3/ActivityTest.php

index 67b01d965f609c24abd17c1a731238d353b00f89..cc468c0a1bd8ae4a880c4759a52fce10d3075cda 100644 (file)
@@ -368,13 +368,11 @@ function civicrm_api3_activity_get($params) {
  */
 function _civicrm_api3_activity_get_extraFilters(&$params, &$sql) {
   // Filter by activity contacts
-  $recordTypes = civicrm_api3('ActivityContact', 'getoptions', array('field' => 'record_type_id'));
-  $recordTypes = $recordTypes['values'];
   $activityContactOptions = array(
     'contact_id' => NULL,
-    'target_contact_id' => array_search('Activity Targets', $recordTypes),
-    'source_contact_id' => array_search('Activity Source', $recordTypes),
-    'assignee_contact_id' => array_search('Activity Assignees', $recordTypes),
+    'target_contact_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Targets'),
+    'source_contact_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Source'),
+    'assignee_contact_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Assignees'),
   );
   foreach ($activityContactOptions as $activityContactName => $activityContactValue) {
     if (!empty($params[$activityContactName])) {
index ec9ad219524b837b03acae9dad7683eeaf6622a6..8345c0bdcc7d639b888135025fd74bf51ba26ca2 100644 (file)
@@ -684,25 +684,27 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
 
     $contact2 = $this->individualCreate($contact2Params);
 
+    $this->callAPISuccess('OptionValue', 'get', ['name' => 'Activity Targets', 'api.OptionValue.create' => ['label' => 'oh so creative']]);
+
     $params['assignee_contact_id'] = array($contact1, $contact2);
     $params['target_contact_id'] = array($contact2 => $contact2);
     $activity = $this->callAPISuccess('Activity', 'Create', $params);
 
-    $activityget = $this->callAPISuccess('Activity', 'get', array(
+    $activityGet = $this->callAPISuccess('Activity', 'get', array(
       'id' => $activity['id'],
       'target_contact_id' => $contact2,
       'return.target_contact_id' => 1,
     ));
-    $this->assertEquals($activity['id'], $activityget['id']);
-    $this->assertEquals($contact2, $activityget['values'][$activityget['id']]['target_contact_id'][0]);
+    $this->assertEquals($activity['id'], $activityGet['id']);
+    $this->assertEquals($contact2, $activityGet['values'][$activityGet['id']]['target_contact_id'][0]);
 
-    $activityget = $this->callAPISuccess('activity', 'get', array(
+    $activityGet = $this->callAPISuccess('activity', 'get', array(
       'target_contact_id' => $this->_contactID,
       'return.target_contact_id' => 1,
       'id' => $activity['id'],
     ));
-    if ($activityget['count'] > 0) {
-      $this->assertNotEquals($contact2, $activityget['values'][$activityget['id']]['target_contact_id'][0]);
+    if ($activityGet['count'] > 0) {
+      $this->assertNotEquals($contact2, $activityGet['values'][$activityGet['id']]['target_contact_id'][0]);
     }
   }