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