]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Oauth_application_user.php
4d2567246506f68a45a32af658c2f1775d92a649
[quix0rs-gnu-social.git] / classes / Oauth_application_user.php
1 <?php
2 /**
3  * Table Definition for oauth_application_user
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Oauth_application_user extends Managed_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'oauth_application_user';          // table name
13     public $profile_id;                      // int(4)  primary_key not_null
14     public $application_id;                  // int(4)  primary_key not_null
15     public $access_type;                     // tinyint(1)
16     public $token;                           // varchar(255)
17     public $created;                         // datetime   not_null
18     public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
19
20     /* Static get */
21     function staticGet($k,$v=NULL) {
22         return Memcached_DataObject::staticGet('Oauth_application_user',$k,$v);
23     }
24     /* the code above is auto generated do not remove the tag below */
25     ###END_AUTOCODE
26
27     public static function schemaDef()
28     {
29         return array(
30             'fields' => array(
31                 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'user of the application'),
32                 'application_id' => array('type' => 'int', 'not null' => true, 'description' => 'id of the application'),
33                 'access_type' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'access type, bit 1 = read, bit 2 = write'),
34                 'token' => array('type' => 'varchar', 'length' => 255, 'description' => 'request or access token'),
35                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
36                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
37             ),
38             'primary key' => array('profile_id', 'application_id'),
39             'foreign keys' => array(
40                 'oauth_application_user_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
41                 'oauth_application_user_application_id_fkey' => array('oauth_application', array('application_id' => 'id')),
42             ),
43         );
44     }
45
46     static function getByUserAndToken($user, $token)
47     {
48         if (empty($user) || empty($token)) {
49             return null;
50         }
51
52         $oau = new Oauth_application_user();
53
54         $oau->profile_id = $user->id;
55         $oau->token      = $token;
56         $oau->limit(1);
57
58         $result = $oau->find(true);
59
60         return empty($result) ? null : $oau;
61     }
62
63     function updateKeys(&$orig)
64     {
65         $this->_connect();
66         $parts = array();
67         foreach (array('profile_id', 'application_id', 'token', 'access_type') as $k) {
68             if (strcmp($this->$k, $orig->$k) != 0) {
69                 $parts[] = $k . ' = ' . $this->_quote($this->$k);
70             }
71         }
72         if (count($parts) == 0) {
73             // No changes
74             return true;
75         }
76         $toupdate = implode(', ', $parts);
77
78         $table = $this->tableName();
79         if(common_config('db','quote_identifiers')) {
80             $table = '"' . $table . '"';
81         }
82         $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
83           ' WHERE profile_id = ' . $orig->profile_id
84           . ' AND application_id = ' . $orig->application_id
85           . " AND token = '$orig->token'";
86         $orig->decache();
87         $result = $this->query($qry);
88         if ($result) {
89             $this->encache();
90         }
91         return $result;
92     }
93 }