array( 'group' => 'name', 'group_name' => 'name', 'parent' => 'parent', 'parent_name' => 'parent', 'created_at' => 'ctime', 'last_modified' => 'mtime', 'users' ) ); /** * The columns which are not permitted to be queried * * @var array */ protected $filterColumns = array('group', 'parent'); /** * The default sort rules to be applied on a query * * @var array */ protected $sortRules = array( 'group_name' => array( 'columns' => array( 'group_name', 'parent_name' ) ) ); /** * Return the groups the given user is a member of * * @param User $user * * @return array */ public function getMemberships(User $user) { $result = $this->select()->fetchAll(); $groups = array(); foreach ($result as $group) { if ($group->group_name) { // TODO: Can we set this somehow automatically to the section's name?? $groups[$group->group_name] = $group->parent_name; } } $username = strtolower($user->getUsername()); $memberships = array(); foreach ($result as $group) { if ($group->group_name && $group->users) { $users = array_map('strtolower', String::trimSplit($group->users)); if (! in_array($group->group_name, $memberships) && in_array($username, $users)) { $memberships[] = $group->group_name; $parent = $groups[$group->group_name]; while ($parent !== null) { $memberships[] = $parent; $parent = isset($groups[$parent]) ? $groups[$parent] : null; } } } } return $memberships; } }