src/Controller/Component/GroupComponent.php
public function getUserGroups(string $userId = ''): array
    {
        // if not specified, get current user's id
        if (empty($userId)) {
            $userId = $this->Auth->user('id');
        }

        $groups = TableRegistry::get('Groups.Groups');

        $query = $groups->find('list', [
            'keyField' => 'id',
            'valueField' => 'name'
        ]);
        $query->matching('Users', function ($q) use ($userId) {
            return $q->where(['Users.id' => $userId]);
        });

        return $query->toArray();
    }
public function getUserGroups(string $userId = ''): array
    {
        // if not specified, get current user's id
        if (empty($userId)) {
            $userId = $this->Auth->user('id');
        }

        $groups = TableRegistry::get('Groups.Groups');

        $query = $groups->find('list', [
            'keyField' => 'id',
            'valueField' => 'name'
        ]);
        $query->matching('Users', function ($q) use ($userId) {
            return $q->where(['Users.id' => $userId]);
        });

        return $query->toArray();
    }
public function getUserGroups ( string $ userId = '' ) : array { // if not specified, get current user's id if ( empty ( $ userId ) ) { $ userId = $ this -> Auth -> user ( 'id' ) ; } $ groups = TableRegistry :: get ( 'Groups.Groups' ) ; $ query = $ groups -> find ( 'list' , [ 'keyField' => 'id' , 'valueField' => 'name' ] ) ; $ query -> matching ( 'Users' , function ( $ q ) use ( $ userId ) { return $ q -> where ( [ 'Users.id' => $ userId ] ) ; } ) ; return $ query -> toArray ( ) ; }
Method that retrieves specified user's groups
@param  string $userId user id
@return mixed[]
Method that retrieves specified user s groups