]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/User_username.php
Merge branch 'fixes/private_scope_on_tags' into social-master
[quix0rs-gnu-social.git] / classes / User_username.php
1 <?php
2 /**
3  * Table Definition for user_username
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class User_username extends Managed_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'user_username';                     // table name
13     public $user_id;                        // int(4)  not_null
14     public $provider_name;                  // varchar(255)  primary_key not_null
15     public $username;                       // varchar(255)  primary_key not_null
16     public $created;                        // datetime()   not_null
17     public $modified;                       // timestamp()   not_null default_CURRENT_TIMESTAMP
18
19     /* the code above is auto generated do not remove the tag below */
20     ###END_AUTOCODE
21
22     public static function schemaDef()
23     {
24         return array(
25             'fields' => array(
26                 'provider_name' => array('type' => 'varchar', 'length' => 255, 'description' => 'provider name'),
27                 'username' => array('type' => 'varchar', 'length' => 255, 'description' => 'username'),
28                 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
29                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
30                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
31             ),
32             'primary key' => array('provider_name', 'username'),
33             'indexes' => array(
34                 'user_id_idx' => array('user_id')
35             ),
36             'foreign keys' => array(
37                 'user_username_user_id_fkey' => array('user', array('user_id' => 'id')),
38             ),
39         );
40     }
41
42     /**
43     * Register a user with a username on a given provider
44     * @param User User object
45     * @param string username on the given provider
46     * @param provider_name string name of the provider
47     * @return mixed User_username instance if the registration succeeded, false if it did not
48     */
49     static function register($user, $username, $provider_name)
50     {
51         $user_username = new User_username();
52         $user_username->user_id = $user->id;
53         $user_username->provider_name = $provider_name;
54         $user_username->username = $username;
55         $user_username->created = common_sql_now();
56
57         if($user_username->insert()){
58             return $user_username;
59         }else{
60             return false;
61         }
62     }
63 }