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;
 }