]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Foreign_user.php
Merge commit 'refs/merge-requests/166' of git://gitorious.org/statusnet/mainline...
[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     // XXX:  This only returns a 1->1 single obj mapping.  Change?  Or make
48     // a getForeignUsers() that returns more than one? --Zach
49     static function getForeignUser($id, $service) {
50         $fuser = new Foreign_user();
51         $fuser->whereAdd("service = $service");
52         $fuser->whereAdd("id = $id");
53         $fuser->limit(1);
54
55         if ($fuser->find()) {
56             $fuser->fetch();
57             return $fuser;
58         }
59
60         return null;
61     }
62
63     static function getByNickname($nickname, $service)
64     {
65         if (empty($nickname) || empty($service)) {
66             return null;
67         } else {
68             $fuser = new Foreign_user();
69             $fuser->service = $service;
70             $fuser->nickname = $nickname;
71             $fuser->limit(1);
72
73             $result = $fuser->find(true);
74
75             return empty($result) ? null : $fuser;
76         }
77     }
78
79     function updateKeys(&$orig)
80     {
81         $this->_connect();
82         $parts = array();
83         foreach (array('id', 'service', 'uri', 'nickname') as $k) {
84             if (strcmp($this->$k, $orig->$k) != 0) {
85                 $parts[] = $k . ' = ' . $this->_quote($this->$k);
86             }
87         }
88         if (count($parts) == 0) {
89             // No changes
90             return true;
91         }
92         $toupdate = implode(', ', $parts);
93
94         $table = $this->tableName();
95         if(common_config('db','quote_identifiers')) {
96             $table = '"' . $table . '"';
97         }
98         $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
99           ' WHERE id = ' . $this->id;
100         $orig->decache();
101         $result = $this->query($qry);
102         if ($result) {
103             $this->encache();
104         }
105         return $result;
106     }
107 }