]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Confirm_address.php
2cb5b65131af2194c80616c1f80c00bdac1c8eff
[quix0rs-gnu-social.git] / classes / Confirm_address.php
1 <?php
2 /**
3  * Table Definition for confirm_address
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Confirm_address extends Managed_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'confirm_address';                 // table name
13     public $code;                            // varchar(32)  primary_key not_null
14     public $user_id;                         // int(4)   not_null
15     public $address;                         // varchar(191)   not_null   not 255 because utf8mb4 takes more space
16     public $address_extra;                   // varchar(191)   not_null   not 255 because utf8mb4 takes more space
17     public $address_type;                    // varchar(8)   not_null
18     public $claimed;                         // datetime()  
19     public $sent;                            // datetime()  
20     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
21
22     /* the code above is auto generated do not remove the tag below */
23     ###END_AUTOCODE
24
25     public static function schemaDef()
26     {
27         return array(
28             'fields' => array(
29                 'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'good random code'),
30                 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who requested confirmation'),
31                 'address' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'address (email, xmpp, SMS, etc.)'),
32                 'address_extra' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'carrier ID, for SMS'),
33                 'address_type' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'),
34                 'claimed' => array('type' => 'datetime', 'description' => 'date this was claimed for queueing'),
35                 'sent' => array('type' => 'datetime', 'description' => 'date this was sent for queueing'),
36                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
37             ),
38             'primary key' => array('code'),
39             'foreign keys' => array(
40                 'confirm_address_user_id_fkey' => array('user', array('user_id' => 'id')),
41             ),
42         );
43     }
44
45     static function getAddress($address, $addressType)
46     {
47         $ca = new Confirm_address();
48
49         $ca->address      = $address;
50         $ca->address_type = $addressType;
51
52         if ($ca->find(true)) {
53             return $ca;
54         }
55
56         return null;
57     }
58
59     static function saveNew(User $user, $address, $addressType, $extra=null)
60     {
61         $ca = new Confirm_address();
62
63         if (!empty($user)) {
64             $ca->user_id = $user->id;
65         }
66
67         $ca->address       = $address;
68         $ca->address_type  = $addressType;
69         $ca->address_extra = $extra;
70         $ca->code          = common_confirmation_code(64);
71
72         $ca->insert();
73
74         return $ca;
75     }
76 }