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();
}