PermissionModel::getRolePermissions PHP Method

getRolePermissions() public method

If no junction table is specified, will return ONLY non-junction permissions. If you need every permission regardless of junction & suffix, see CachePermissions.
public getRolePermissions ( integer $RoleID, string $LimitToSuffix = '', string $JunctionTable = false, string $JunctionColumn = false, string $ForeignKey = false, integer $ForeignID = false ) : array
$RoleID integer Unique identifier for role.
$LimitToSuffix string String permission name must match, starting on right (ex: 'View' would match *.*.View)
$JunctionTable string Optionally limit returned permissions to 1 junction (ex: 'Category').
$JunctionColumn string Column to join junction table on (ex: 'CategoryID'). Required if using $JunctionTable.
$ForeignKey string Foreign table column to join on.
$ForeignID integer Foreign ID to limit join to.
return array Permission records.
    public function getRolePermissions($RoleID, $LimitToSuffix = '', $JunctionTable = false, $JunctionColumn = false, $ForeignKey = false, $ForeignID = false)
    {
        // Get all permissions
        $PermissionColumns = $this->PermissionColumns($JunctionTable, $JunctionColumn);
        // Select any that match $LimitToSuffix
        foreach ($PermissionColumns as $ColumnName => $Value) {
            if (!empty($LimitToSuffix) && substr($ColumnName, -strlen($LimitToSuffix)) != $LimitToSuffix) {
                continue;
                // permission not in $LimitToSuffix
            }
            $this->SQL->select('p.`' . $ColumnName . '`', 'MAX');
        }
        // Generic part of query
        $this->SQL->from('Permission p')->where('p.RoleID', $RoleID);
        // Either limit to 1 junction or exclude junctions
        if ($JunctionTable && $JunctionColumn) {
            $this->SQL->select(array('p.JunctionTable', 'p.JunctionColumn', 'p.JunctionID'))->groupBy(array('p.JunctionTable', 'p.JunctionColumn', 'p.JunctionID'));
            if ($ForeignKey && $ForeignID) {
                $this->SQL->join("{$JunctionTable} j", "j.{$JunctionColumn} = p.JunctionID")->where("j.{$ForeignKey}", $ForeignID);
            }
        } else {
            $this->SQL->where('p.JunctionTable is null');
        }
        return $this->SQL->get()->resultArray();
    }