]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Oauth_application_user.php
Merge branch '1.0.x' into schema-x
[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 Memcached_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     static function getByUserAndToken($user, $token)
28     {
29         if (empty($user) || empty($token)) {
30             return null;
31         }
32
33         $oau = new Oauth_application_user();
34
35         $oau->profile_id = $user->id;
36         $oau->token      = $token;
37         $oau->limit(1);
38
39         $result = $oau->find(true);
40
41         return empty($result) ? null : $oau;
42     }
43
44     function updateKeys(&$orig)
45     {
46         $this->_connect();
47         $parts = array();
48         foreach (array('profile_id', 'application_id', 'token', 'access_type') as $k) {
49             if (strcmp($this->$k, $orig->$k) != 0) {
50                 $parts[] = $k . ' = ' . $this->_quote($this->$k);
51             }
52         }
53         if (count($parts) == 0) {
54             # No changes
55             return true;
56         }
57         $toupdate = implode(', ', $parts);
58
59         $table = $this->tableName();
60         if(common_config('db','quote_identifiers')) {
61             $table = '"' . $table . '"';
62         }
63         $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
64           ' WHERE profile_id = ' . $orig->profile_id
65           . ' AND application_id = ' . $orig->application_id
66           . " AND token = '$orig->token'";
67         $orig->decache();
68         $result = $this->query($qry);
69         if ($result) {
70             $this->encache();
71         }
72         return $result;
73     }
74 }