* @param int $id
*/
public static function getGroupContacts($id) {
- $params = array(array('group', 'IN', array($id => 1), 0, 0));
+ $params = array(array('group', 'IN', array(1 => $id), 0, 0));
list($contacts, $_) = CRM_Contact_BAO_Query::apiQuery($params, array('contact_id'));
return $contacts;
}
parse_str($cf['filter'], $filterParams);
$action = CRM_Utils_Array::value('action', $filterParams);
-
- if (!empty($action) &&
- !in_array($action, array('get', 'lookup'))
- ) {
+ if (!empty($action) && !in_array($action, array('get', 'lookup'))) {
CRM_Utils_System::civiExit('error');
}
+
+ if (!empty($filterParams['group'])) {
+ $filterParams['group'] = explode(',', $filterParams['group']);
+ }
}
$list = array_keys(CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
$contactList[] = array('id' => $value['id'], 'text' => implode(' :: ', $view));
}
+ if (!empty($_GET['is_unit_test'])) {
+ return $contactList;
+ }
CRM_Utils_JSON::output($contactList);
}
$this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result);
}
+ /**
+ * Test to check contact reference field
+ */
+ public function testContactReference() {
+ //create group
+ $groupId1 = $this->groupCreate();
+ $groupId2 = $this->groupCreate(array(
+ 'name' => 'Test Group 2',
+ 'domain_id' => 1,
+ 'title' => 'New Test Group2 Created',
+ 'description' => 'New Test Group2 Created',
+ 'is_active' => 1,
+ 'visibility' => 'User and User Admin Only',
+ ));
+
+ $contactIds = array();
+ foreach (array($groupId1, $groupId2) as $groupId) {
+ $this->groupContactCreate($groupId);
+ $contactIds = array_merge($contactIds, CRM_Contact_BAO_Group::getGroupContacts($groupId));
+ }
+ $contactIds = array_column($contactIds, 'contact_id');
+
+ // create custom group with contact reference field
+ $customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'select_test_group'));
+ $params = array(
+ 'custom_group_id' => $customGroup['id'],
+ 'name' => 'Worker_Lookup',
+ 'label' => 'Worker Lookup',
+ // limit this field to two groups created above
+ 'filter' => "action=lookup&group={$groupId1},{$groupId2}",
+ 'html_type' => 'Autocomplete-Select',
+ 'data_type' => 'ContactReference',
+ 'weight' => 4,
+ 'is_searchable' => 1,
+ 'is_active' => 1,
+ );
+ $customField = $this->callAPISuccess('custom_field', 'create', $params);
+
+ $_GET = array(
+ 'id' => $customField['id'],
+ 'is_unit_test' => TRUE,
+ );
+ $contactList = CRM_Contact_Page_AJAX::contactReference();
+ $contactList = array_column($contactList, 'id');
+
+ //assert each returned contact id to be present in group contact
+ foreach ($contactList as $contactId) {
+ $this->assertTrue(in_array($contactId, $contactIds));
+ }
+ }
+
}