src/Pyrite/ACL.php
public static function sqlCondition($columnName, $action, $objectType = null)
    {
        global $PPHP;
        $db = $PPHP['db'];
        $sqlTRUE = '(1=1)';
        $sqlFALSE = '(1=2)';

        if (!isset($_SESSION['ACL_INFO'])) {
            return $db->query($sqlFALSE);
        };
        $acl = $_SESSION['ACL_INFO'];

        $granted = array();
        foreach (array('*', $action) as $act) {
            if (array_key_exists($act, $acl)) {
                $acl2 = $acl[$act];
                foreach (array('*', $objectType) as $typ) {
                    if (array_key_exists($typ, $acl2)) {
                        $granted = array_merge($granted, $acl2[$typ]);
                    };
                };
            };
        };
        if (in_array(0, $granted)) {
            return $db->query($sqlTRUE);
        } elseif (count($granted) === 1) {
            return $db->query("{$columnName}=?", $granted[0]);
        } elseif (count($granted) > 0) {
            return $db->query("{$columnName} IN")->varsClosed($granted);
        };
        return $db->query($sqlFALSE);
    }
public static function sqlCondition($columnName, $action, $objectType = null)
    {
        global $PPHP;
        $db = $PPHP['db'];
        $sqlTRUE = '(1=1)';
        $sqlFALSE = '(1=2)';

        if (!isset($_SESSION['ACL_INFO'])) {
            return $db->query($sqlFALSE);
        };
        $acl = $_SESSION['ACL_INFO'];

        $granted = array();
        foreach (array('*', $action) as $act) {
            if (array_key_exists($act, $acl)) {
                $acl2 = $acl[$act];
                foreach (array('*', $objectType) as $typ) {
                    if (array_key_exists($typ, $acl2)) {
                        $granted = array_merge($granted, $acl2[$typ]);
                    };
                };
            };
        };
        if (in_array(0, $granted)) {
            return $db->query($sqlTRUE);
        } elseif (count($granted) === 1) {
            return $db->query("{$columnName}=?", $granted[0]);
        } elseif (count($granted) > 0) {
            return $db->query("{$columnName} IN")->varsClosed($granted);
        };
        return $db->query($sqlFALSE);
    }
public static function sqlCondition ( $ columnName , $ action , $ objectType = null ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ sqlTRUE = '(1=1)' ; $ sqlFALSE = '(1=2)' ; if ( ! isset ( $ _SESSION [ 'ACL_INFO' ] ) ) { return $ db -> query ( $ sqlFALSE ) ; } ; $ acl = $ _SESSION [ 'ACL_INFO' ] ; $ granted = array ( ) ; foreach ( array ( '*' , $ action ) as $ act ) { if ( array_key_exists ( $ act , $ acl ) ) { $ acl2 = $ acl [ $ act ] ; foreach ( array ( '*' , $ objectType ) as $ typ ) { if ( array_key_exists ( $ typ , $ acl2 ) ) { $ granted = array_merge ( $ granted , $ acl2 [ $ typ ] ) ; } ; } ; } ; } ; if ( in_array ( 0 , $ granted ) ) { return $ db -> query ( $ sqlTRUE ) ; } elseif ( count ( $ granted ) === 1 ) { return $ db -> query ( "{$columnName}=?" , $ granted [ 0 ] ) ; } elseif ( count ( $ granted ) > 0 ) { return $ db -> query ( "{$columnName} IN" ) -> varsClosed ( $ granted ) ; } ; return $ db -> query ( $ sqlFALSE ) ; }
Get SQL condition for matching objectIds user has right to

This behaves identically to can(), except it returns one of:

When there is no right: "(1=2)"
When a single Id is allowed: "{$columnName}=?"
When multiple Ids are allowed: "{$columnName} IN (?, ...)"
When every Id is allowed: "(1=1)"

@param string $columnName Name of column to match Ids in your query
@param string $action     Action to test
@param string $objectType Class of object this applies to

@return object PDBquery object
Get SQL condition for matching objectIds user has right to