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