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