/** * Provides group nesting record(s) given parent and/or child id. * * @param array $params an array containing at least child_group_id or parent_group_id * * @return array list of group nesting records */ function civicrm_group_nesting_get(&$params) { _civicrm_initialize(); if (!is_array($params)) { return civicrm_create_error('Params need to be of type array!'); } if (!array_key_exists('child_group_id', $params) && !array_key_exists('parent_group_id', $params)) { return civicrm_create_error(ts('At least one of child_group_id or parent_group_id is a required field')); } require_once 'CRM/Contact/DAO/GroupNesting.php'; $dao = new CRM_Contact_DAO_GroupNesting(); if (array_key_exists('child_group_id', $params)) { $dao->child_group_id = $params['child_group_id']; } if (array_key_exists('parent_group_id', $params)) { $dao->parent_group_id = $params['parent_group_id']; } $values = array(); if ($dao->find()) { while ($dao->fetch()) { $temp = array(); _civicrm_object_to_array($dao, $temp); $values[$dao->id] = $temp; } $values['is_error'] = 0; } else { return civicrm_create_error('No records found.'); } return $values; }
/** * Checks whether the association between parent and child is present. * * @param int $parentID * The parent id of the association. * * @param int $childID * The child id of the association. * * @return bool * True if association is found, false otherwise. */ public static function isParentChild($parentID, $childID) { $dao = new CRM_Contact_DAO_GroupNesting(); $dao->child_group_id = $childID; $dao->parent_group_id = $parentID; if ($dao->find()) { return TRUE; } return FALSE; }