//if entity_id is set then treat it as ID (will be overridden by id if set)
$dao->id = $params[$entity . "_id"];
}
+
+ $options = _civicrm_api3_get_options_from_params($params);
//apply options like sort
_civicrm_api3_apply_options_to_dao($params, $dao, $entity);
}
}
}
- if (!empty($params['return']) && is_array($params['return'])) {
+ if (!empty($options['return']) && is_array($options['return'])) {
$dao->selectAdd();
+ $options['return']['id'] = TRUE;// ensure 'id' is included
$allfields = _civicrm_api3_get_unique_name_array($dao);
- $returnMatched = array_intersect($params['return'], $allfields);
+ $returnMatched = array_intersect(array_keys($options['return']), $allfields);
$returnUniqueMatched = array_intersect(
array_diff(// not already matched on the field names
- $params['return'],
+ $options['return'],
$returnMatched),
array_flip($allfields)// but a match for the field keys
);
$dao->selectAdd($allfields[$uniqueVal]);
}
- $dao->selectAdd('id');
}
}
}
+ /**
+ * Test custom field get works & return param works
+ */
+ function testCustomFieldGetReturnOptions(){
+ $customGroup = $this->customGroupCreate('Individual', 'test_group');
+ $customField = $this->customFieldCreate($customGroup['id'], 'test_name');
+
+ $result = civicrm_api('custom_field', 'getsingle', array(
+ 'version' => 3,
+ 'id' => $customField['id'],
+ 'return' => 'data_type',
+ ));
+ $this->assertTrue(array_key_exists('data_type', $result));
+ $this->assertFalse(array_key_exists('custom_group_id', $result));
+ }
+
+ /**
+ * Test custom field get works & return param works
+ */
+ function testCustomFieldGetReturnArray(){
+ $customGroup = $this->customGroupCreate('Individual', 'test_group');
+ $customField = $this->customFieldCreate($customGroup['id'], 'test_name');
+
+ $result = civicrm_api('custom_field', 'getsingle', array(
+ 'version' => 3,
+ 'id' => $customField['id'],
+ 'return' => array('data_type'),
+ ));
+ $this->assertTrue(array_key_exists('data_type', $result));
+ $this->assertFalse(array_key_exists('custom_group_id', $result));
+ }
+
+ /**
+ * Test custom field get works & return param works
+ */
+ function testCustomFieldGetReturnTwoOptions(){
+ $customGroup = $this->customGroupCreate('Individual', 'test_group');
+ $customField = $this->customFieldCreate($customGroup['id'], 'test_name');
+
+ $result = civicrm_api('custom_field', 'getsingle', array(
+ 'version' => 3,
+ 'id' => $customField['id'],
+ 'return' => 'data_type, custom_group_id',
+ ));
+ $this->assertTrue(array_key_exists('data_type', $result));
+ $this->assertTrue(array_key_exists('custom_group_id', $result));
+ $this->assertFalse(array_key_exists('label', $result));
+ }
+
function testCustomFieldCreateWithOptionValues() {
$customGroup = $this->customGroupCreate('Contact', 'select_test_group', 3);