$p = array(1 => array($params['option_group_id'], 'Integer'));
CRM_Core_DAO::executeQuery($query, $p);
}
+
+ // CRM-13814 : evalute option group id
+ if (!array_key_exists('option_group_id', $params) && !empty($ids['optionValue'])) {
+ $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
+ $ids['optionValue'], 'option_group_id', 'id'
+ );
+ }
+ else {
+ $groupId = $params['option_group_id'];
+ }
+
$groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
- $params['option_group_id'], 'name', 'id'
+ $groupId, 'name', 'id'
);
if (in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups)) {
$optionValue->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
* @access public
*/
function civicrm_api3_option_value_create($params) {
-
$result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
- civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $params['option_group_id']));
+
+ // CRM-13814 : evalute option group id
+ // option group id would be passed in case of adding a new option value record
+ if (!empty($params['id']) && !array_key_exists('option_group_id', $params)) {
+ $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
+ $params['id'], 'option_group_id', 'id'
+ );
+ }
+ else {
+ $groupId = $params['option_group_id'];
+ }
+
+ civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $groupId));
return $result;
}
$fields = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
$this->assertFalse(in_array($newOption, $fields['values']));
}
-}
+
+ /*
+ * update option value with 'id' paramter and the value to update
+ * and not passing option group id
+ */
+ public function testUpdateOptionValueNoGroupId() {
+ // create a option group
+ $og = $this->callAPISuccess('option_group', 'create', array('name' => 'our test Option Group', 'is_active' => 1));
+ // create a option value
+ $ov = $this->callAPISuccess('option_value', 'create',
+ array('option_group_id' => $og['id'], 'label' => 'test option value')
+ );
+ // update option value without 'option_group_id'
+ $res = $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'is_active' => 0));
+ $val = $this->callAPISuccess('option_value', 'getvalue', array(
+ 'id' => $ov['id'], 'return' => 'is_active',
+ ));
+ $this->assertEquals($val, 0, "update with no group id is not proper" . __LINE__);
+ }
+
+ /*
+ * update option value with 'id' paramter and the value to update
+ * and as well as option group id
+ */
+ public function testUpdateOptionValueWithGroupId() {
+ // create a option group
+ $og = $this->callAPISuccess('option_group', 'create', array('name' => 'our test Option Group for with group id', 'is_active' => 1));
+ // create a option value
+ $ov = $this->callAPISuccess('option_value', 'create',
+ array('option_group_id' => $og['id'], 'label' => 'test option value')
+ );
+ // update option value without 'option_group_id'
+ $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'option_group_id' => $og['id'], 'is_active' => 0));
+ $val = $this->callAPISuccess('option_value', 'getvalue', array(
+ 'id' => $ov['id'], 'return' => 'is_active',
+ ));
+ $this->assertEquals($val, 0, "update with group id is not proper " . __LINE__);
+ }
+}
\ No newline at end of file