src/Security/Member.php
public static function mapInCMSGroups($groups = null)
    {
        // non-countable $groups will issue a warning when using count() in PHP 7.2+
        if (!$groups) {
            $groups = [];
        }

        // Check CMS module exists
        if (!class_exists(LeftAndMain::class)) {
            return ArrayList::create()->map();
        }

        if (count($groups) == 0) {
            $perms = array('ADMIN', 'CMS_ACCESS_AssetAdmin');

            if (class_exists(CMSMain::class)) {
                $cmsPerms = CMSMain::singleton()->providePermissions();
            } else {
                $cmsPerms = LeftAndMain::singleton()->providePermissions();
            }

            if (!empty($cmsPerms)) {
                $perms = array_unique(array_merge($perms, array_keys($cmsPerms)));
            }

            $permsClause = DB::placeholders($perms);
            /** @skipUpgrade */
            $groups = Group::get()
                ->innerJoin("Permission", '"Permission"."GroupID" = "Group"."ID"')
                ->where(array(
                    "\"Permission\".\"Code\" IN ($permsClause)" => $perms
                ));
        }

        $groupIDList = array();

        if ($groups instanceof SS_List) {
            foreach ($groups as $group) {
                $groupIDList[] = $group->ID;
            }
        } elseif (is_array($groups)) {
            $groupIDList = $groups;
        }

        /** @skipUpgrade */
        $members = static::get()
            ->innerJoin("Group_Members", '"Group_Members"."MemberID" = "Member"."ID"')
            ->innerJoin("Group", '"Group"."ID" = "Group_Members"."GroupID"');
        if ($groupIDList) {
            $groupClause = DB::placeholders($groupIDList);
            $members = $members->where(array(
                "\"Group\".\"ID\" IN ($groupClause)" => $groupIDList
            ));
        }

        return $members->sort('"Member"."Surname", "Member"."FirstName"')->map();
    }
public static function mapInCMSGroups($groups = null)
    {
        // non-countable $groups will issue a warning when using count() in PHP 7.2+
        if (!$groups) {
            $groups = [];
        }

        // Check CMS module exists
        if (!class_exists(LeftAndMain::class)) {
            return ArrayList::create()->map();
        }

        if (count($groups) == 0) {
            $perms = array('ADMIN', 'CMS_ACCESS_AssetAdmin');

            if (class_exists(CMSMain::class)) {
                $cmsPerms = CMSMain::singleton()->providePermissions();
            } else {
                $cmsPerms = LeftAndMain::singleton()->providePermissions();
            }

            if (!empty($cmsPerms)) {
                $perms = array_unique(array_merge($perms, array_keys($cmsPerms)));
            }

            $permsClause = DB::placeholders($perms);
            /** @skipUpgrade */
            $groups = Group::get()
                ->innerJoin("Permission", '"Permission"."GroupID" = "Group"."ID"')
                ->where(array(
                    "\"Permission\".\"Code\" IN ($permsClause)" => $perms
                ));
        }

        $groupIDList = array();

        if ($groups instanceof SS_List) {
            foreach ($groups as $group) {
                $groupIDList[] = $group->ID;
            }
        } elseif (is_array($groups)) {
            $groupIDList = $groups;
        }

        /** @skipUpgrade */
        $members = static::get()
            ->innerJoin("Group_Members", '"Group_Members"."MemberID" = "Member"."ID"')
            ->innerJoin("Group", '"Group"."ID" = "Group_Members"."GroupID"');
        if ($groupIDList) {
            $groupClause = DB::placeholders($groupIDList);
            $members = $members->where(array(
                "\"Group\".\"ID\" IN ($groupClause)" => $groupIDList
            ));
        }

        return $members->sort('"Member"."Surname", "Member"."FirstName"')->map();
    }
public static function mapInCMSGroups ( $ groups = null ) { // non-countable $groups will issue a warning when using count() in PHP 7.2+ if ( ! $ groups ) { $ groups = [ ] ; } // Check CMS module exists if ( ! class_exists ( LeftAndMain :: class ) ) { return ArrayList :: create ( ) -> map ( ) ; } if ( count ( $ groups ) == 0 ) { $ perms = array ( 'ADMIN' , 'CMS_ACCESS_AssetAdmin' ) ; if ( class_exists ( CMSMain :: class ) ) { $ cmsPerms = CMSMain :: singleton ( ) -> providePermissions ( ) ; } else { $ cmsPerms = LeftAndMain :: singleton ( ) -> providePermissions ( ) ; } if ( ! empty ( $ cmsPerms ) ) { $ perms = array_unique ( array_merge ( $ perms , array_keys ( $ cmsPerms ) ) ) ; } $ permsClause = DB :: placeholders ( $ perms ) ; /** @skipUpgrade */ $ groups = Group :: get ( ) -> innerJoin ( "Permission" , '"Permission"."GroupID" = "Group"."ID"' ) -> where ( array ( "\"Permission\".\"Code\" IN ($permsClause)" => $ perms ) ) ; } $ groupIDList = array ( ) ; if ( $ groups instanceof SS_List ) { foreach ( $ groups as $ group ) { $ groupIDList [ ] = $ group -> ID ; } } elseif ( is_array ( $ groups ) ) { $ groupIDList = $ groups ; } /** @skipUpgrade */ $ members = static :: get ( ) -> innerJoin ( "Group_Members" , '"Group_Members"."MemberID" = "Member"."ID"' ) -> innerJoin ( "Group" , '"Group"."ID" = "Group_Members"."GroupID"' ) ; if ( $ groupIDList ) { $ groupClause = DB :: placeholders ( $ groupIDList ) ; $ members = $ members -> where ( array ( "\"Group\".\"ID\" IN ($groupClause)" => $ groupIDList ) ) ; } return $ members -> sort ( '"Member"."Surname", "Member"."FirstName"' ) -> map ( ) ; }
Get a map of all members in the groups given that have CMS permissions

If no groups are passed, all groups with CMS permissions will be used.

@param array $groups Groups to consider or NULL to use all groups with
CMS permissions.
@return Map Returns a map of all members in the groups given that
have CMS permissions.
Get a map of all members in the groups given that have CMS permissions