Exemple #1
0
 /**
  * Returns array of group ids of descendent groups of the specified group.
  *
  * @param array $groupIds
  *   An array of valid group ids (passed by reference).
  *
  * @param bool $includeSelf
  * @return array
  *   List of groupIds that represent the requested group and its descendents
  */
 public static function getDescendentGroupIds($groupIds, $includeSelf = TRUE)
 {
     if (!is_array($groupIds)) {
         $groupIds = array($groupIds);
     }
     $dao = new CRM_Contact_DAO_GroupNesting();
     $query = "SELECT child_group_id, parent_group_id FROM civicrm_group_nesting WHERE parent_group_id IN (" . implode(',', $groupIds) . ")";
     $dao->query($query);
     $tmpGroupIds = array();
     $childGroupIds = array();
     if ($includeSelf) {
         $childGroupIds = $groupIds;
     }
     while ($dao->fetch()) {
         // make sure we're not following any cyclical references
         if (!array_key_exists($dao->parent_group_id, $childGroupIds) && $dao->child_group_id != $groupIds[0]) {
             $tmpGroupIds[] = $dao->child_group_id;
         }
     }
     if (!empty($tmpGroupIds)) {
         $newChildGroupIds = self::getDescendentGroupIds($tmpGroupIds);
         $childGroupIds = array_merge($childGroupIds, $newChildGroupIds);
     }
     return $childGroupIds;
 }
Exemple #2
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  * @static
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['group_nesting'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
/**
 * Removes specific nesting records.
 * 
 * @param array &$params parameters array - allowed array keys include:
 * {@schema Contact/GroupNesting.xml}
 * 
 * @return array TBD
 * 
 * @todo Work out the return value.
 */
function civicrm_group_nesting_remove(&$params)
{
    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('You need to define parent_group_id and child_group_id in params.'));
    }
    require_once 'CRM/Contact/DAO/GroupNesting.php';
    $dao = new CRM_Contact_DAO_GroupNesting();
    $dao->copyValues($params);
    if ($dao->delete()) {
        $result = array('is_error' => 0);
    }
    return $result;
}