Habari\ACL::grant_user PHP Method

grant_user() public static method

Grant a permission to a user
public static grant_user ( integer $user_id, integer $token_id, string $access = 'full' ) : Result
$user_id integer The user ID
$token_id integer The name or ID of the permission token to grant
$access string The kind of access to assign the group
return Result of the DB query
    public static function grant_user($user_id, $token_id, $access = 'full')
    {
        $token_id = self::token_id($token_id);
        $access_mask = DB::get_value('SELECT access_mask FROM {user_token_permissions} WHERE user_id=? AND token_id=?', array($user_id, $token_id));
        if ($access_mask === false) {
            $permission_bit = 0;
            // default is 'deny' (bitmask 0)
        }
        $bitmask = self::get_bitmask($access_mask);
        if ($access == 'full') {
            $bitmask->value = $bitmask->full;
        } elseif ($access == 'deny') {
            $bitmask->value = 0;
        } else {
            $bitmask->{$access} = true;
        }
        $result = DB::update('{user_token_permissions}', array('access_mask' => $bitmask->value), array('user_id' => $user_id, 'token_id' => $token_id));
        ACL::clear_caches();
        return $result;
    }