src/Security/Member.php
public function inGroup($group, $strict = false)
    {
        if (is_numeric($group)) {
            $groupCheckObj = DataObject::get_by_id(Group::class, $group);
        } elseif (is_string($group)) {
            $groupCheckObj = DataObject::get_one(Group::class, array(
                '"Group"."Code"' => $group
            ));
        } elseif ($group instanceof Group) {
            $groupCheckObj = $group;
        } else {
            throw new InvalidArgumentException('Member::inGroup(): Wrong format for $group parameter');
        }

        if (!$groupCheckObj) {
            return false;
        }

        $groupCandidateObjs = ($strict) ? $this->getManyManyComponents("Groups") : $this->Groups();
        if ($groupCandidateObjs) {
            foreach ($groupCandidateObjs as $groupCandidateObj) {
                if ($groupCandidateObj->ID == $groupCheckObj->ID) {
                    return true;
                }
            }
        }

        return false;
    }
public function inGroup($group, $strict = false)
    {
        if (is_numeric($group)) {
            $groupCheckObj = DataObject::get_by_id(Group::class, $group);
        } elseif (is_string($group)) {
            $groupCheckObj = DataObject::get_one(Group::class, array(
                '"Group"."Code"' => $group
            ));
        } elseif ($group instanceof Group) {
            $groupCheckObj = $group;
        } else {
            throw new InvalidArgumentException('Member::inGroup(): Wrong format for $group parameter');
        }

        if (!$groupCheckObj) {
            return false;
        }

        $groupCandidateObjs = ($strict) ? $this->getManyManyComponents("Groups") : $this->Groups();
        if ($groupCandidateObjs) {
            foreach ($groupCandidateObjs as $groupCandidateObj) {
                if ($groupCandidateObj->ID == $groupCheckObj->ID) {
                    return true;
                }
            }
        }

        return false;
    }
public function inGroup ( $ group , $ strict = false ) { if ( is_numeric ( $ group ) ) { $ groupCheckObj = DataObject :: get_by_id ( Group :: class , $ group ) ; } elseif ( is_string ( $ group ) ) { $ groupCheckObj = DataObject :: get_one ( Group :: class , array ( '"Group"."Code"' => $ group ) ) ; } elseif ( $ group instanceof Group ) { $ groupCheckObj = $ group ; } else { throw new InvalidArgumentException ( 'Member::inGroup(): Wrong format for $group parameter' ) ; } if ( ! $ groupCheckObj ) { return false ; } $ groupCandidateObjs = ( $ strict ) ? $ this -> getManyManyComponents ( "Groups" ) : $ this -> Groups ( ) ; if ( $ groupCandidateObjs ) { foreach ( $ groupCandidateObjs as $ groupCandidateObj ) { if ( $ groupCandidateObj -> ID == $ groupCheckObj -> ID ) { return true ; } } } return false ; }
Check if the member is in the given group or any parent groups.

@param int|Group|string $group Group instance, Group Code or ID
@param boolean $strict Only determine direct group membership if set to TRUE (Default: FALSE)
@return bool Returns TRUE if the member is in the given group, otherwise FALSE.
Check if the member is in the given group or any parent groups .