]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Confirm_address.php
Merge commit 'refs/merge-requests/165' of git://gitorious.org/statusnet/mainline...
[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(255)   not_null
16     public $address_extra;                   // varchar(255)   not_null
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     /* Static get */
23     function staticGet($k,$v=null)
24     { return Memcached_DataObject::staticGet('Confirm_address',$k,$v); }
25
26     /* the code above is auto generated do not remove the tag below */
27     ###END_AUTOCODE
28
29     public static function schemaDef()
30     {
31         return array(
32             'fields' => array(
33                 'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'good random code'),
34                 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who requested confirmation'),
35                 'address' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'address (email, xmpp, SMS, etc.)'),
36                 'address_extra' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'carrier ID, for SMS'),
37                 'address_type' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'),
38                 'claimed' => array('type' => 'datetime', 'description' => 'date this was claimed for queueing'),
39                 'sent' => array('type' => 'datetime', 'description' => 'date this was sent for queueing'),
40                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
41             ),
42             'primary key' => array('code'),
43             'foreign keys' => array(
44                 'confirm_address_user_id_fkey' => array('user', array('user_id' => 'id')),
45             ),
46         );
47     }
48
49     static function getAddress($address, $addressType)
50     {
51         $ca = new Confirm_address();
52
53         $ca->address      = $address;
54         $ca->address_type = $addressType;
55
56         if ($ca->find(true)) {
57             return $ca;
58         }
59
60         return null;
61     }
62
63     static function saveNew($user, $address, $addressType, $extra=null)
64     {
65         $ca = new Confirm_address();
66
67         if (!empty($user)) {
68             $ca->user_id = $user->id;
69         }
70
71         $ca->address       = $address;
72         $ca->address_type  = $addressType;
73         $ca->address_extra = $extra;
74         $ca->code          = common_confirmation_code(64);
75
76         $ca->insert();
77
78         return $ca;
79     }
80 }