]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Foreign_link.php
Merge branch '0.8.x' into twitter-oauth
[quix0rs-gnu-social.git] / classes / Foreign_link.php
1 <?php
2 /**
3  * Table Definition for foreign_link
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Foreign_link 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_link';                    // table name
13     public $user_id;                         // int(4)  primary_key not_null
14     public $foreign_id;                      // bigint(8)  primary_key not_null unsigned
15     public $service;                         // int(4)  primary_key not_null
16     public $credentials;                     // varchar(255)
17     public $token;                           // varchar(255)
18     public $noticesync;                      // tinyint(1)   not_null default_1
19     public $friendsync;                      // tinyint(1)   not_null default_2
20     public $profilesync;                     // tinyint(1)   not_null default_1
21     public $last_noticesync;                 // datetime()
22     public $last_friendsync;                 // datetime()
23     public $created;                         // datetime()   not_null
24     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
25
26     /* Static get */
27     function staticGet($k,$v=null)
28     { return Memcached_DataObject::staticGet('Foreign_link',$k,$v); }
29
30     /* the code above is auto generated do not remove the tag below */
31     ###END_AUTOCODE
32
33     // XXX:  This only returns a 1->1 single obj mapping.  Change?  Or make
34     // a getForeignUsers() that returns more than one? --Zach
35     static function getByUserID($user_id, $service)
36     {
37         $flink = new Foreign_link();
38         $flink->service = $service;
39         $flink->user_id = $user_id;
40         $flink->limit(1);
41
42         if ($flink->find(true)) {
43             return $flink;
44         }
45
46         return null;
47     }
48
49     static function getByForeignID($foreign_id, $service)
50     {
51         $flink = new Foreign_link();
52         $flink->service = $service;
53         $flink->foreign_id = $foreign_id;
54         $flink->limit(1);
55
56         if ($flink->find(true)) {
57             return $flink;
58         }
59
60         return null;
61     }
62
63     function set_flags($noticesend, $noticerecv, $replysync, $friendsync)
64     {
65         if ($noticesend) {
66             $this->noticesync |= FOREIGN_NOTICE_SEND;
67         } else {
68             $this->noticesync &= ~FOREIGN_NOTICE_SEND;
69         }
70         
71         if ($noticerecv) {
72             $this->noticesync |= FOREIGN_NOTICE_RECV;
73         } else {
74             $this->noticesync &= ~FOREIGN_NOTICE_RECV;
75         }
76
77         if ($replysync) {
78             $this->noticesync |= FOREIGN_NOTICE_SEND_REPLY;
79         } else {
80             $this->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY;
81         }
82
83         if ($friendsync) {
84             $this->friendsync |= FOREIGN_FRIEND_RECV;
85         } else {
86             $this->friendsync &= ~FOREIGN_FRIEND_RECV;
87         }
88
89         $this->profilesync = 0;
90     }
91
92     # Convenience methods
93     function getForeignUser()
94     {
95         $fuser = new Foreign_user();
96         $fuser->service = $this->service;
97         $fuser->id = $this->foreign_id;
98
99         $fuser->limit(1);
100
101         if ($fuser->find(true)) {
102             return $fuser;
103         }
104
105         return null;
106     }
107
108     function getUser()
109     {
110         return User::staticGet($this->user_id);
111     }
112
113 }