2 require_once 'OAuth.php';
4 class OAuthAccessToken extends OAuthToken {
7 protected $provider_id;
11 function __construct( $provider_id, $key, $secret, $user_id, $time_stamp=null, $id=0) {
12 parent::__construct($key, $secret);
14 $this->provider_id = $provider_id;
15 $this->user_id = $user_id;
16 $this->time_stamp = $time_stamp;
19 public function get_id() {
23 public function set_id($id) {
27 public function get_provider_id() {
28 return $this->provider_id;
31 public function get_token_key() {
35 public function get_token_secret() {
39 public function get_user_id() {
40 return $this->user_id;
43 public function get_time_stamp() {
44 return $this->time_stamp;
47 static function convert_row_to_object($row) {
49 $access_token = new OAuthAccessToken($row['provider_id'], $row['token_key'], $row['token_secret'], $row['user_id'], $row['time_stamp'], $row['id']);
56 static function get_access_token($id) {
57 $conn = FFOAuthDataStore::singleton();
58 $row = $conn->find_token_from_id($id);
59 $access_token = self::convert_row_to_object($row);
63 static function get_all_access_tokens($user_id) {
64 $conn = FFOAuthDataStore::singleton();
65 $rows = $conn->find_all_access_tokens($user_id);
66 $access_tokens = array();
67 foreach ($rows as $row) {
68 $access_token = OAuthAccessToken::convert_row_to_object($row);
69 $access_tokens[] = $access_token;
71 return $access_tokens;
74 static function get_all_access_tokens_by_provider($provider_id, $user_id) {
75 $conn = FFOAuthDataStore::singleton();
76 $rows = $conn->find_access_tokens_by_provider($provider_id, $user_id);
77 $access_tokens = array();
78 foreach ($rows as $row) {
79 $access_token = OAuthAccessToken::convert_row_to_object($row);
80 $access_tokens[] = $access_token;
82 return $access_tokens;
85 function write_to_db() {
86 if ( strlen(trim( $this->get_provider_id() ))==0 || strlen(trim( $this->get_user_id() ))==0 || strlen(trim( $this->get_token_key() ))==0 || strlen(trim( $this->get_token_secret() ))==0 ) {
87 exit_error( "Error trying to add the access token. Some required parameters are not set.", 'oauthconsumer' );
89 $conn = FFOAuthDataStore::singleton();
90 $id = $conn->save_access_token($this);
92 exit_error("Error trying to add access token to DB", 'oauthconsumer');
99 $conn = FFOAuthDataStore::singleton();
100 $id = $this->get_id();
102 if(!($conn->delete_access_token($id))) {
103 exit_error("Error trying to delete access token from DB", 'oauthconsumer');
106 exit_error("Trying to delete non-existent access token from DB", 'oauthconsumer');