function buildGroupArray() { global $default; $aDirectGroups = array(); $aGroupMemberships = DBUtil::getResultArray("SELECT parent_group_id, member_group_id FROM {$default->groups_groups_table}"); $aGroups =& Group::getList(); foreach ($aGroups as $oGroup) { $aDirectGroups[$oGroup->getID()] = array(); } foreach ($aGroupMemberships as $aRow) { $aList = KTUtil::arrayGet($aDirectGroups, $aRow['parent_group_id'], array()); $aList[] = $aRow['member_group_id']; $aDirectGroups[$aRow['parent_group_id']] = $aList; } return GroupUtil::expandGroupArray($aDirectGroups); }
<?php require_once "../../../config/dmsDefaults.php"; require_once KT_LIB_DIR . '/groups/GroupUtil.php'; error_reporting(E_ALL); $aGroupMembers = array(1 => array(3, 4), 2 => array(9), 3 => null, 4 => array(5), 5 => null, 6 => array(1), 7 => array(2, 3), 8 => array(1, 7)); $aExpectedRet = array(1 => array(3, 4, 5), 2 => array(9), 3 => null, 4 => array(5), 5 => null, 6 => array(1, 3, 4, 5), 7 => array(2, 3, 9), 8 => array(1, 2, 3, 4, 5, 7, 9)); $aRet = GroupUtil::expandGroupArray($aGroupMembers); if ($aRet === $aExpectedRet) { print "Success!\n"; } else { print "Failure!\n"; print "Expected: \n"; print_r($aExpectedRet); print "Received: \n"; print_r($aRet); }