public function sQLPermission($SQL, $Permissions, $ForeignAlias, $ForeignColumn, $JunctionTable = '', $JunctionColumn = '')
{
$Session = Gdn::session();
// Figure out the junction table if necessary.
if (!$JunctionTable && StringEndsWith($ForeignColumn, 'ID')) {
$JunctionTable = substr($ForeignColumn, 0, -2);
}
// Check to see if the permission is disabled.
if (c('Garden.Permission.Disabled.' . $JunctionTable)) {
if (!$Session->checkPermission($Permissions)) {
$SQL->where('1', '0', false, false);
}
} elseif ($Session->UserID <= 0 || is_object($Session->User) && $Session->User->Admin != '1') {
$SQL->Distinct()->join('Permission _p', '_p.JunctionID = ' . $ForeignAlias . '.' . $ForeignColumn, 'inner')->join('UserRole _ur', '_p.RoleID = _ur.RoleID', 'inner')->beginWhereGroup()->where('_ur.UserID', $Session->UserID);
if (!is_array($Permissions)) {
$Permissions = array($Permissions);
}
$SQL->beginWhereGroup();
foreach ($Permissions as $Permission) {
$SQL->where('_p.`' . $Permission . '`', 1);
}
$SQL->endWhereGroup();
} else {
// Force this method to play nice in case it is used in an or clause
// (ie. it returns true in a sql sense by doing 1 = 1)
$SQL->where('1', '1', false, false);
}
return $SQL;
}