PermissionModel::sQLPermission PHP Méthode

sQLPermission() public méthode

Joins the query to a permission junction table and limits the results accordingly.
public sQLPermission ( Gdn_SQLDriver $SQL, mixed $Permissions, string $ForeignAlias, string $ForeignColumn, string $JunctionTable = '', string $JunctionColumn = '' )
$SQL Gdn_SQLDriver The SQL driver to add the permission to.
$Permissions mixed The permission name (or array of names) to use when limiting the query.
$ForeignAlias string The alias of the table to join to (ie. Category).
$ForeignColumn string The primary key column name of $JunctionTable (ie. CategoryID).
$JunctionTable string
$JunctionColumn string
    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;
    }