<?php
/**
 * Created by PhpStorm.
 * User: daedeloth
 * Date: 25/12/14
 * Time: 15:55
 */

namespace CatLab\OAuth2\Mappers;

use CatLab\Accounts\Models\User;
use Neuron\DB\Query;

class AccessTokenMapper {

	/**
	 * @param $token
	 * @return null|int
	 */
	public function getUserIdFromAccessToken ($token)
	{
		$data = Query::select (
			'oauth2_access_tokens',
			array (
				'user_id'
			),
			array (
				'access_token' => $token
			)
		)->execute ();

		if ($data)
		{
			return intval ($data[0]['user_id']);
		}
		return null;
	}

    /**
     * @param User $user
     */
	public function deleteFromUser(User $user)
    {
        Query::delete('oauth2_access_tokens', [ 'user_id' => $user->getId() ])->execute();
    }

}

<?php

namespace CatLab\OAuth2\Mappers;

use Neuron\DB\Query;
use Neuron\Interfaces\Models\User;

/**
 * Class AccessTokenMapper
 * @package CatLab\OAuth2\Mappers
 */
class AccessTokenMapper {

	/**
	 * @param $token
	 * @return null|int
	 */
	public function getUserIdFromAccessToken ($token)
	{
		$data = Query::select (
			'oauth2_access_tokens',
			array (
				'user_id'
			),
			array (
				'access_token' => $token
			)
		)->execute ();

		if ($data)
		{
			return intval ($data[0]['user_id']);
		}
		return null;
	}

    /**
     * @param User $user
     */
	public function deleteFromUser(User $user)
    {
        Query::delete('oauth2_access_tokens', [ 'user_id' => $user->getId() ])->execute();
    }

}

Add method to remove all access tokens from a user.
Add method to remove all access tokens from a user.
