]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Foreign_link.php
bc3ab006db43ea17f572f88828f1ed9707cf3de7
[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     static function getByUserID($user_id, $service)
34     {
35         if (empty($user_id) || empty($service)) {
36             return null;
37         }
38
39         $flink = new Foreign_link();
40
41         $flink->service = $service;
42         $flink->user_id = $user_id;
43         $flink->limit(1);
44
45         $result = $flink->find(true);
46
47         return empty($result) ? null : $flink;
48
49     }
50
51     static function getByForeignID($foreign_id, $service)
52     {
53         if (empty($foreign_id) || empty($service)) {
54             return null;
55         } else {
56             $flink = new Foreign_link();
57             $flink->service = $service;
58             $flink->foreign_id = $foreign_id;
59             $flink->limit(1);
60
61             $result = $flink->find(true);
62
63             return empty($result) ? null : $flink;
64         }
65     }
66
67     function set_flags($noticesend, $noticerecv, $replysync, $friendsync)
68     {
69         if ($noticesend) {
70             $this->noticesync |= FOREIGN_NOTICE_SEND;
71         } else {
72             $this->noticesync &= ~FOREIGN_NOTICE_SEND;
73         }
74
75         if ($noticerecv) {
76             $this->noticesync |= FOREIGN_NOTICE_RECV;
77         } else {
78             $this->noticesync &= ~FOREIGN_NOTICE_RECV;
79         }
80
81         if ($replysync) {
82             $this->noticesync |= FOREIGN_NOTICE_SEND_REPLY;
83         } else {
84             $this->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY;
85         }
86
87         if ($friendsync) {
88             $this->friendsync |= FOREIGN_FRIEND_RECV;
89         } else {
90             $this->friendsync &= ~FOREIGN_FRIEND_RECV;
91         }
92
93         $this->profilesync = 0;
94     }
95
96     # Convenience methods
97     function getForeignUser()
98     {
99         $fuser = new Foreign_user();
100         $fuser->service = $this->service;
101         $fuser->id = $this->foreign_id;
102
103         $fuser->limit(1);
104
105         if ($fuser->find(true)) {
106             return $fuser;
107         }
108
109         return null;
110     }
111
112     function getUser()
113     {
114         return User::staticGet($this->user_id);
115     }
116
117 }