$params['name'] = CRM_Utils_String::titleToVar($params['title']);
}
+ if (!empty($params['parents'])) {
+ $params['parents'] = CRM_Utils_Array::convertCheckboxFormatToArray((array) $params['parents']);
+ }
+
// convert params if array type
if (isset($params['group_type'])) {
- if (is_array($params['group_type'])) {
- $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
- CRM_Utils_Array::convertCheckboxFormatToArray($params['group_type'])
- ) . CRM_Core_DAO::VALUE_SEPARATOR;
- }
- else {
- $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . $params['group_type'] . CRM_Core_DAO::VALUE_SEPARATOR;
- }
+ $params['group_type'] = CRM_Utils_Array::convertCheckboxFormatToArray((array) $params['group_type']);
}
else {
$params['group_type'] = NULL;
}
}
$group = new CRM_Contact_BAO_Group();
- $group->copyValues($params);
- //@todo very hacky fix for the fact this function wants to receive 'parents' as an array further down but
- // needs it as a separated string for the DB. Preferred approaches are having the copyParams or save fn
- // use metadata to translate the array to the appropriate DB type or altering the param in the api layer,
- // or at least altering the param in same section as 'group_type' rather than repeating here. However, further down
- // we need the $params one to be in it's original form & we are not sure what test coverage we have on that
- if (isset($group->parents) && is_array($group->parents)) {
- $group->parents = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
- array_keys($group->parents)
- ) . CRM_Core_DAO::VALUE_SEPARATOR;
- }
+ $group->copyValues($params, TRUE);
+
if (empty($params['id']) &&
!$nameParam
) {
) {
// if no parent present and the group doesn't already have any parents,
// make sure site group goes as parent
- $params['parents'] = array($domainGroupID => 1);
- }
- elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) {
- $params['parents'] = array($params['parents'] => 1);
+ $params['parents'] = array($domainGroupID);
}
if (!empty($params['parents'])) {
- foreach ($params['parents'] as $parentId => $dnc) {
+ foreach ($params['parents'] as $parentId) {
if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) {
CRM_Contact_BAO_GroupNesting::add($parentId, $group->id);
}