]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Foreign_user.php
Return dynamically generated URLs for thumbnails for all locally stored entries
[quix0rs-gnu-social.git] / classes / Foreign_user.php
1 <?php
2 /**
3  * Table Definition for foreign_user
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Foreign_user extends Managed_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'foreign_user';                    // table name
13     public $id;                              // bigint(8)  primary_key not_null
14     public $service;                         // int(4)  primary_key not_null
15     public $uri;                             // varchar(191)  unique_key not_null   not 255 because utf8mb4 takes more space
16     public $nickname;                        // varchar(191)   not 255 because utf8mb4 takes more space
17     public $created;                         // datetime()   not_null
18     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
19
20     /* the code above is auto generated do not remove the tag below */
21     ###END_AUTOCODE
22
23     public static function schemaDef()
24     {
25         return array(
26             'fields' => array(
27                 'id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'unique numeric key on foreign service'),
28                 'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
29                 'uri' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'identifying URI'),
30                 'nickname' => array('type' => 'varchar', 'length' => 191, 'description' => 'nickname on foreign service'),
31                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
32                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
33             ),
34             'primary key' => array('id', 'service'),
35             'foreign keys' => array(
36                 'foreign_user_service_fkey' => array('foreign_service', array('service' => 'id')),
37             ),
38             'unique keys' => array(
39                 'foreign_user_uri_key' => array('uri'),
40             ),
41         );
42     }
43
44     static function getForeignUser($id, $service)
45     {
46         if (empty($id) || empty($service)) {
47             throw new ServerException('Empty foreign user id or service for Foreign_user::getForeignUser');
48         }
49
50         $fuser = new Foreign_user();
51         $fuser->id      = $id;
52         $fuser->service = $service;
53         $fuser->limit(1);
54
55         if (!$fuser->find(true)) {
56             throw new NoResultException($fuser);
57         }
58
59         return $fuser;
60     }
61
62     static function getByNickname($nickname, $service)
63     {
64         if (empty($nickname) || empty($service)) {
65             throw new ServerException('Empty nickname or service for Foreign_user::getByNickname');
66         }
67
68         $fuser = new Foreign_user();
69         $fuser->service = $service;
70         $fuser->nickname = $nickname;
71         $fuser->limit(1);
72
73         if (!$fuser->find(true)) {
74             throw new NoResultException($fuser);
75         }
76
77         return $fuser;
78     }
79 }