]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Foreign_user.php
4a41e07f4d87d796d750140a29ef981a8a9642cf
[quix0rs-gnu-social.git] / classes / Foreign_user.php
1 <?php
2 /**
3  * Table Definition for foreign_user
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Foreign_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 = 'foreign_user';                    // table name
13     public $id;                              // bigint(8)  primary_key not_null
14     public $service;                         // int(4)  primary_key not_null
15     public $uri;                             // varchar(255)  unique_key not_null
16     public $nickname;                        // 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) { return Memcached_DataObject::staticGet('Foreign_user',$k,$v); }
22
23     /* the code above is auto generated do not remove the tag below */
24     ###END_AUTOCODE
25
26     public static function schemaDef()
27     {
28         return array(
29             'fields' => array(
30                 'id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'unique numeric key on foreign service'),
31                 'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
32                 'uri' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'identifying URI'),
33                 'nickname' => array('type' => 'varchar', 'length' => 255, 'description' => 'nickname on foreign service'),
34                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
35                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
36             ),
37             'primary key' => array('id', 'service'),
38             'foreign keys' => array(
39                 'foreign_user_service_fkey' => array('foreign_service', array('service' => 'id')),
40             ),
41             'unique keys' => array(
42                 'foreign_user_uri_key' => array('uri'),
43             ),
44         );
45     }
46
47     static function getForeignUser($id, $service) {
48
49         $fuser = new Foreign_user();
50
51         $fuser->id      = $id;
52         $fuser->service = $service;
53
54         $fuser->limit(1);
55
56         $result = $fuser->find(true);
57
58         return empty($result) ? null : $fuser;
59     }
60
61     static function getByNickname($nickname, $service)
62     {
63         if (empty($nickname) || empty($service)) {
64             return null;
65         } else {
66             $fuser = new Foreign_user();
67             $fuser->service = $service;
68             $fuser->nickname = $nickname;
69             $fuser->limit(1);
70
71             $result = $fuser->find(true);
72
73             return empty($result) ? null : $fuser;
74         }
75     }
76
77     function updateKeys(&$orig)
78     {
79         $this->_connect();
80         $parts = array();
81         foreach (array('id', 'service', 'uri', 'nickname') as $k) {
82             if (strcmp($this->$k, $orig->$k) != 0) {
83                 $parts[] = $k . ' = ' . $this->_quote($this->$k);
84             }
85         }
86         if (count($parts) == 0) {
87             // No changes
88             return true;
89         }
90         $toupdate = implode(', ', $parts);
91
92         $table = $this->tableName();
93         if(common_config('db','quote_identifiers')) {
94             $table = '"' . $table . '"';
95         }
96         $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
97           ' WHERE id = ' . $this->id;
98         $orig->decache();
99         $result = $this->query($qry);
100         if ($result) {
101             $this->encache();
102         }
103         return $result;
104     }
105 }