mgd_get_group_by_path()
Fetch a Midgard Group Record based on its path.
Parameter Syntax
Searches the group indicated by the path $path and returns an instance of it. If the path does not lead to a valid group, FALSE is returned. Double Slashes in $path are silently ignored.
Code
<?php
// MidgardGroup mgd_get_group_by_path($path)
//
// Resolve a Midgard group name by its path in the group tree.
// If $path is found, mgd_get_group_by_path() returns an instance
// of it. Otherwise the function returns FALSE. Double slashes
// in $path are silently ignored.
function mgd_get_group_by_path($path) {
if (! $path) return(FALSE);
// Split path
$path_array = explode("/", $path);
// Traverse group tree
$current_group_id = 0;
foreach ($path_array as $group_name) {
if ($group_name == "") continue;
$current_group = mgd_get_group_by_name($current_group_id,
$group_name);
if ($current_group) {
$current_group_id = $current_group->id;
continue;
} else {
// $group_name not found in current level
return(FALSE);
}
}
// $path resolved until the end of $path_array
return($current_group);
}
?>