PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Authentication » LiveUser » Bug #402

Problem with LiveUser_Admin_Perm_Container_DB_Complex::getGroups()

Details

Submitted2003-12-11 00:04 UTC
Fromkipaten21 at hotmail dot com
Assignedlsmith
StatusClosed
PackageLiveUser
PHP VersionIrrelevant
OSANY
Roadmaps(Not assigned)

Comments

[2003-12-11 00:04 UTC] kipaten21 at hotmail dot com

Description:
------------
I think there might be a problem with the way LiveUser_Admin_Perm_Container_DB_Complex::getGroups() retrieves subgroups.

First off, I noticed this when the returned array from getGroups() appeared to be missing information.

To test this, I created two groups, Users and Administrators.

The group_id of Administrators is 1.
The group_id of Users is 2.

In LIVEUSER_GROUP_SUBGROUPS, I gave one row, where group_id=1 and subgroup_id=2.

The returned array from getGroups() is missing the actual subgroup, and appears to loop again.

Array
(
[1] => Array
(
[group_id] => 1
[owner_user_id] =>
[owner_group_id] =>
[name] => Administrators
[comments] =>
[is_active] => Y
[subgroups] => Array
(
[2] => Array
(
[subgroups] => Array
(
)

)

)

)

)

Can anyone confirm this?

It looks like the code tries to get all the groups, then determine which are subgroups and then retrieve the parents....it looks like it does the whole process backwards. I'm having trouble even understanding what the code is trying to do.

Is this working for anyone?

[2003-12-11 00:10 UTC] kipaten21 at hotmail dot com

A further look at the code...

function getGroups($options = null, $parentgroup = null)
{
static $groups;
static $subgroups;
$result = array();

if ($parentgroup === null) {
<snip>
} else {
if (is_array($subgroups)) {
//when getGroups is called recursively with a
//$parentgroup set, the block to be entered
//depends on $subgroups being an array.
//$subgroups isn't even populated or declared
//as an array unless $parentgroup === null.
<snip>
};
}
}

[2003-12-11 16:35 UTC] alex at burgiss dot com

This sounds like the problem I was noticing for a while now (for at least the last 2 LiveUser version releases)
I brought it up on the mailing list, but never knew about this bug database until recently so.. I'm just confirming that I have the same problem..

Using GetGroups, the subgroups array doesn't return the subgroups properly.. it is just blank.. which was incorrect when i was testing it with example subgroups..

[2003-12-11 19:37 UTC] kipaten21 at hotmail dot com

I modified the getGroups() method to work properly. A minor change was made to the prototype. $parentname is no longer used and was changed to boolean $hierarchy.

Here is the returned result....

Array
(
[2] => Array
(
[group_id] => 2
[owner_user_id] => 1
[owner_group_id] => 1
[name] => Users
[comments] =>
[is_active] => Y
)

[1] => Array
(
[group_id] => 1
[owner_user_id] =>
[owner_group_id] =>
[name] => Administrators
[comments] =>
[is_active] => Y
[subgroups] => Array
(
[2] => Array
(
[group_id] => 2
[owner_user_id] => 1
[owner_group_id] => 1
[name] => Users
[comments] =>
[is_active] => Y
)

)

)

)

If $hierarchy is true, then the result would look like this...

Array
(
[1] => Array
(
[group_id] => 1
[owner_user_id] =>
[owner_group_id] =>
[name] => Administrators
[comments] =>
[is_active] => Y
[subgroups] => Array
(
[2] => Array
(
[group_id] => 2
[owner_user_id] => 1
[owner_group_id] => 1
[name] => Users
[comments] =>
[is_active] => Y
)

)

)

)

The hierarchy makes it nice if you want to build a tree view of your groups.

Now for the code...

function getGroups($options = null, $hierarchy = false)
{
static $groups;
static $subgroups;
$result = array();

$query = 'SELECT
groups.group_id AS group_id,
groups.owner_perm_user_id AS owner_user_id,
groups.owner_group_id AS owner_group_id,
translations.name AS name,
translations.comments AS comments,
groups.is_active AS is_active
FROM';

if (isset($options['where_user_id'])
&& is_numeric($options['where_user_id'])) {
$query .= ' ' . $this->prefix . 'groupusers groupusers,';
}

$query .= ' ' . $this->prefix . 'groups groups,
' . $this->prefix . 'translations translations
WHERE';

if (isset($options['where_user_id'])
&& is_numeric($options['where_user_id'])) {
$query .= ' groupusers.perm_user_id = ' . (int)$options['where_user_id'] . ' AND
groupusers.group_id = groups.group_id AND';
}

if (isset($options['where_group_id'])
&& is_numeric($options['where_group_id'])) {
$query .= ' groups.group_id = ' . (int)$options['where_group_id'] . ' AND';
}

if (isset($options['where_owner_user_id'])
&& is_numeric($options['where_owner_user_id'])) {
$query .= ' groups.owner_user_id = ' . (int)$options['where_owner_user_id'] . ' AND';
}

if (isset($options['where_owner_group_id'])
&& is_numeric($options['where_owner_group_id'])) {
$query .= ' groups.owner_group_id = ' . (int)$options['where_owner_group_id'] . ' AND';
}

if (isset($options['where_is_active'])
&& is_string($options['where_is_active'])) {
$query .= ' groups.is_active = ' . $options['where_is_active'] . ' AND';
}

$query .= ' translations.section_id = groups.group_id AND
translations.section_type = ' . LIVEUSER_SECTION_GROUP . ' AND
translations.language_id = ' . (int)$this->_langs[$this->getCurrentLanguage()];

$groups = $this->dbc->getAll($query, null, DB_FETCHMODE_ASSOC);

if (DB::isError($groups)) {
return $groups;
}

$_groups = array();
if (is_array($groups)) {
foreach($groups as $key => $value) {
if (isset($options['with_rights'])) {
$_options = $options;
$_options['where_group_id'] = $value['group_id'];
$value['rights'] = $this->getRights($_options);
}
$_groups[$value['group_id']] = $value;
}
}

$query = 'SELECT
subgroups.group_id as group_id,
subgroups.subgroup_id as subgroup_id
FROM
' . $this->prefix . 'group_subgroups subgroups';

$subgroups = $this->dbc->getAll($query, null, DB_FETCHMODE_ASSOC);

if (DB::isError($subgroups)) {
return $subgroups;
}

foreach($subgroups as $subgroup) {
if ($_groups[$subgroup['group_id']]) {
$result = $this->getGroups(array('where_group_id' => $subgroup['subgroup_id']));
$_groups[$subgroup['group_id']]['subgroups'][$subgroup['subgroup_id']] = $result[$subgroup['subgroup_id']];

if ($hierarchy)
unset($_groups[$subgroup['subgroup_id']]);
}
}

return $_groups;
}
}