return;
case 'group':
- $this->group($values);
- return;
-
case 'group_type':
- // so we resolve this into a list of groups & proceed as if they had been
- // handed in
- list($name, $op, $value, $grouping, $wildcard) = $values;
- $values[0] = 'group';
- $values[1] = 'IN';
- $this->_paramLookup['group'][0][0] = 'group';
- $this->_paramLookup['group'][0][1] = 'IN';
- $this->_paramLookup['group'][0][2] = $values[2] = $this->getGroupsFromTypeCriteria($value);
$this->group($values);
return;
$value = CRM_Utils_Array::value($op, $value, $value);
}
+ if ($name == 'group_type') {
+ $value = array_keys($this->getGroupsFromTypeCriteria($value));
+ }
+
$regularGroupIDs = $smartGroupIDs = array();
foreach ((array) $value as $id) {
if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $id, 'saved_search_id')) {
}
}
+ /**
+ * CRM-19333: Test case for contact search on basis of group type
+ */
+ public function testbyGroupType() {
+ $groupTypes = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type');
+ $mailingListGT = array_search('Mailing List', $groupTypes);
+ $accessControlGT = array_search('Access Control', $groupTypes);
+
+ // create group with group type - Mailing list
+ $group1 = $this->callAPISuccess('Group', 'create', array(
+ 'title' => 'Group 1',
+ 'visibility' => 'User and User Admin Only',
+ 'is_active' => 1,
+ 'group_type' => $mailingListGT,
+ ));
+
+ // create group with group type - Access Control
+ $group2 = $this->callAPISuccess('Group', 'create', array(
+ 'title' => 'Group 2',
+ 'visibility' => 'User and User Admin Only',
+ 'is_active' => 1,
+ 'group_type' => $accessControlGT,
+ ));
+
+ // create contact in 'Group 1'
+ $contact1 = $this->individualCreate(array(
+ 'group' => array($group1['id'] => 1),
+ ));
+
+ // create contact in 'Group 2'
+ $contact2 = $this->individualCreate(array(
+ 'group' => array($group2['id'] => 1),
+ ), 1);
+
+ $useCases = array(
+ //Case 1: Find contacts in group type - Mailing List
+ array(
+ 'form_value' => array('group_type' => array($mailingListGT)),
+ 'expected_count' => 1,
+ 'expected_contact' => array($contact1),
+ ),
+ //Case 2: Find contacts in group type - Access Control
+ array(
+ 'form_value' => array('group_type' => array($accessControlGT)),
+ 'expected_count' => 1,
+ 'expected_contact' => array($contact2),
+ ),
+ //Case 3: Find contacts in group type - Mailing List or Access List
+ array(
+ 'form_value' => array('group_type' => array($mailingListGT, $accessControlGT)),
+ 'expected_count' => 2,
+ 'expected_contact' => array($contact1, $contact2),
+ ),
+ );
+
+ foreach ($useCases as $case) {
+ $query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($case['form_value']));
+ list($select, $from, $where, $having) = $query->query();
+ $groupContacts = CRM_Core_DAO::executeQuery("SELECT DISTINCT contact_a.id $from $where")->fetchAll();
+ foreach ($groupContacts as $key => $value) {
+ $groupContacts[$key] = $value['id'];
+ }
+ $this->assertEquals($case['expected_count'], count($groupContacts));
+ $this->checkArrayEquals($case['expected_contact'], $groupContacts);
+ }
+ }
+
}