PermissionModel::getGlobalPermissions PHP Method

getGlobalPermissions() public method

Get all of the global permissions for one or more roles.
public getGlobalPermissions ( integer | array $RoleID, string $LimitToSuffix = '' ) : Returns
$RoleID integer | array The role(s) to get the permissions for.
$LimitToSuffix string Whether or not to limit the permissions to a suffix.
return Returns an
    public function getGlobalPermissions($RoleID, $LimitToSuffix = '')
    {
        $RoleIDs = (array) $RoleID;
        // Get the global permissions.
        $Data = $this->SQL->select('*')->from('Permission p')->whereIn('p.RoleID', array_merge($RoleIDs, array(0)))->where('p.JunctionTable is null')->orderBy('p.RoleID')->get()->resultArray();
        $this->_MergeDisabledPermissions($Data);
        $Data = Gdn_DataSet::Index($Data, 'RoleID');
        $DefaultRow = $Data[0];
        unset($Data[0], $DefaultRow['RoleID'], $DefaultRow['JunctionTable'], $DefaultRow['JunctionColumn'], $DefaultRow['JunctionID']);
        $DefaultRow = $this->StripPermissions($DefaultRow, $DefaultRow, $LimitToSuffix);
        if ($RoleID) {
            // When editing a role make sure the default permissions are false so as not to be misleading.
            $DefaultRow = array_fill_keys(array_keys($DefaultRow), 0);
        }
        foreach ($RoleIDs as $ID) {
            if (isset($Data[$ID])) {
                $Data[$ID] = array_intersect_key($Data[$ID], $DefaultRow);
            } else {
                $Data[$ID] = $DefaultRow;
                $Data[$ID]['PermissionID'] = null;
            }
        }
        if (count($RoleIDs) === 1) {
            return array_pop($Data);
        } else {
            return $Data;
        }
    }