]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Foreign_link.php
Merge remote-tracking branch 'mainline/1.0.x' into people_tags_rebase
[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 $noticesync;                      // tinyint(1)   not_null default_1
18     public $friendsync;                      // tinyint(1)   not_null default_2
19     public $profilesync;                     // tinyint(1)   not_null default_1
20     public $last_noticesync;                 // datetime()
21     public $last_friendsync;                 // datetime()
22     public $created;                         // datetime()   not_null
23     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
24
25     /* Static get */
26     function staticGet($k,$v=null)
27     { return Memcached_DataObject::staticGet('Foreign_link',$k,$v); }
28
29     /* the code above is auto generated do not remove the tag below */
30     ###END_AUTOCODE
31
32     static function getByUserID($user_id, $service)
33     {
34         if (empty($user_id) || empty($service)) {
35             return null;
36         }
37
38         $flink = new Foreign_link();
39
40         $flink->service = $service;
41         $flink->user_id = $user_id;
42         $flink->limit(1);
43
44         $result = $flink->find(true);
45
46         return empty($result) ? null : $flink;
47     }
48
49     static function getByForeignID($foreign_id, $service)
50     {
51         if (empty($foreign_id) || empty($service)) {
52             return null;
53         } else {
54             $flink = new Foreign_link();
55             $flink->service = $service;
56             $flink->foreign_id = $foreign_id;
57             $flink->limit(1);
58
59             $result = $flink->find(true);
60
61             return empty($result) ? null : $flink;
62         }
63     }
64
65     function set_flags($noticesend, $noticerecv, $replysync, $friendsync)
66     {
67         if ($noticesend) {
68             $this->noticesync |= FOREIGN_NOTICE_SEND;
69         } else {
70             $this->noticesync &= ~FOREIGN_NOTICE_SEND;
71         }
72
73         if ($noticerecv) {
74             $this->noticesync |= FOREIGN_NOTICE_RECV;
75         } else {
76             $this->noticesync &= ~FOREIGN_NOTICE_RECV;
77         }
78
79         if ($replysync) {
80             $this->noticesync |= FOREIGN_NOTICE_SEND_REPLY;
81         } else {
82             $this->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY;
83         }
84
85         if ($friendsync) {
86             $this->friendsync |= FOREIGN_FRIEND_RECV;
87         } else {
88             $this->friendsync &= ~FOREIGN_FRIEND_RECV;
89         }
90
91         $this->profilesync = 0;
92     }
93
94     // Convenience methods
95     function getForeignUser()
96     {
97         $fuser = new Foreign_user();
98         $fuser->service = $this->service;
99         $fuser->id = $this->foreign_id;
100
101         $fuser->limit(1);
102
103         if ($fuser->find(true)) {
104             return $fuser;
105         }
106
107         return null;
108     }
109
110     function getUser()
111     {
112         return User::staticGet($this->user_id);
113     }
114
115     // Make sure we only ever delete one record at a time
116     function safeDelete()
117     {
118         if (!empty($this->user_id)
119             && !empty($this->foreign_id)
120             && !empty($this->service))
121         {
122             return $this->delete();
123         } else {
124             common_debug(LOG_WARNING,
125                 'Foreign_link::safeDelete() tried to delete a '
126                 . 'Foreign_link without a fully specified compound key: '
127                 . var_export($this, true));
128             return false;
129         }
130     }
131 }