src/Pyrite/ACL.php
public static function grant($userId = null, $role = null, $action = null, $objectType = '*', $objectId = 0)
    {
        global $PPHP;
        $db = $PPHP['db'];
        $success = false;

        if ($objectId === '') {
            $objectId = 0;
        };
        if ($userId !== null  &&  $role !== null) {
            $success = $db->insert(
                'users_roles',
                array(
                    'userId' => $userId,
                    'role'   => $role
                )
            );
        } elseif ($userId !== null  &&  $action !== null) {
            $success = $db->insert(
                'acl_users',
                array(
                    'userId'     => $userId,
                    'action'     => $action,
                    'objectType' => $objectType,
                    'objectId'   => $objectId
                )
            );
        } elseif ($role !== null  &&  $action !== null) {
            $success = $db->insert(
                'acl_roles',
                array(
                    'role'       => $role,
                    'action'     => $action,
                    'objectType' => $objectType,
                    'objectId'   => $objectId
                )
            );
        };

        if (($userId !== null
            && (isset($_SESSION['user']) && $_SESSION['user']['id'] == $userId))
            || ($userId === null && $role !== null && self::hasRole($role))
        ) {
            self::reload();
        };

        return $success;
    }
public static function grant($userId = null, $role = null, $action = null, $objectType = '*', $objectId = 0)
    {
        global $PPHP;
        $db = $PPHP['db'];
        $success = false;

        if ($objectId === '') {
            $objectId = 0;
        };
        if ($userId !== null  &&  $role !== null) {
            $success = $db->insert(
                'users_roles',
                array(
                    'userId' => $userId,
                    'role'   => $role
                )
            );
        } elseif ($userId !== null  &&  $action !== null) {
            $success = $db->insert(
                'acl_users',
                array(
                    'userId'     => $userId,
                    'action'     => $action,
                    'objectType' => $objectType,
                    'objectId'   => $objectId
                )
            );
        } elseif ($role !== null  &&  $action !== null) {
            $success = $db->insert(
                'acl_roles',
                array(
                    'role'       => $role,
                    'action'     => $action,
                    'objectType' => $objectType,
                    'objectId'   => $objectId
                )
            );
        };

        if (($userId !== null
            && (isset($_SESSION['user']) && $_SESSION['user']['id'] == $userId))
            || ($userId === null && $role !== null && self::hasRole($role))
        ) {
            self::reload();
        };

        return $success;
    }
public static function grant ( $ userId = null , $ role = null , $ action = null , $ objectType = '*' , $ objectId = 0 ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ success = false ; if ( $ objectId === '' ) { $ objectId = 0 ; } ; if ( $ userId !== null && $ role !== null ) { $ success = $ db -> insert ( 'users_roles' , array ( 'userId' => $ userId , 'role' => $ role ) ) ; } elseif ( $ userId !== null && $ action !== null ) { $ success = $ db -> insert ( 'acl_users' , array ( 'userId' => $ userId , 'action' => $ action , 'objectType' => $ objectType , 'objectId' => $ objectId ) ) ; } elseif ( $ role !== null && $ action !== null ) { $ success = $ db -> insert ( 'acl_roles' , array ( 'role' => $ role , 'action' => $ action , 'objectType' => $ objectType , 'objectId' => $ objectId ) ) ; } ; if ( ( $ userId !== null && ( isset ( $ _SESSION [ 'user' ] ) && $ _SESSION [ 'user' ] [ 'id' ] == $ userId ) ) || ( $ userId === null && $ role !== null && self :: hasRole ( $ role ) ) ) { self :: reload ( ) ; } ; return $ success ; }
Grant new right or role membership

Three possible signatures:

$userId, $role
...grants role to user

$userId, null, $action[, $objectType[, $objectId]]
...grants right to user

null, $role, $action[, $objectType[, $objectId]]
...grants right to role

@param int|null    $userId     User ID
@param string|null $role       Role
@param string|null $action     Action
@param string|null $objectType Object class
@param int|null    $objectId   Object ID

@return bool Result of operation
Grant new right or role membership