3 * Table Definition for oauth_application_user
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Oauth_application_user extends Managed_DataObject
10 /* the code below is auto generated do not remove the above tag */
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
21 function staticGet($k,$v=NULL) {
22 return Memcached_DataObject::staticGet('Oauth_application_user',$k,$v);
24 /* the code above is auto generated do not remove the tag below */
27 public static function schemaDef()
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'),
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')),
46 static function getByUserAndToken($user, $token)
48 if (empty($user) || empty($token)) {
52 $oau = new Oauth_application_user();
54 $oau->profile_id = $user->id;
58 $result = $oau->find(true);
60 return empty($result) ? null : $oau;
63 function updateKeys(&$orig)
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);
72 if (count($parts) == 0) {
76 $toupdate = implode(', ', $parts);
78 $table = $this->tableName();
79 if(common_config('db','quote_identifiers')) {
80 $table = '"' . $table . '"';
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'";
87 $result = $this->query($qry);