]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Foreign_user.php
Merge branch 'master' into devel
[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 Memcached_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;                              // int(4)  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)
22     { return Memcached_DataObject::staticGet('Foreign_user',$k,$v); }
23
24     /* the code above is auto generated do not remove the tag below */
25     ###END_AUTOCODE
26     
27     // XXX:  This only returns a 1->1 single obj mapping.  Change?  Or make
28     // a getForeignUsers() that returns more than one? --Zach
29     static function getForeignUser($id, $service) {        
30         $fuser = new Foreign_user();
31         $fuser->whereAdd("service = $service");
32         $fuser->whereAdd("id = $id");
33         $fuser->limit(1);
34         
35         if ($fuser->find()) {
36             $fuser->fetch();
37             return $fuser;
38         }
39         
40         return null;        
41     }
42     
43     function updateKeys(&$orig)
44     {
45         $parts = array();
46         foreach (array('id', 'service', 'uri', 'nickname') as $k) {
47             if (strcmp($this->$k, $orig->$k) != 0) {
48                 $parts[] = $k . ' = ' . $this->_quote($this->$k);
49             }
50         }
51         if (count($parts) == 0) {
52             # No changes
53             return true;
54         }
55         $toupdate = implode(', ', $parts);
56
57         $table = $this->tableName();
58         if(common_config('db','quote_identifiers')) {
59             $table = '"' . $table . '"';
60         }
61         $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
62           ' WHERE id = ' . $this->id;
63         $orig->decache();
64         $result = $this->query($qry);
65         if ($result) {
66             $this->encache();
67         }
68         return $result;
69     }
70
71     
72 }