]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Confirm_address.php
move core schema to class files
[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     function sequenceKey()
30     { return array(false, false); }
31
32     public static function schemaDef()
33     {
34         return array(
35             'fields' => array(
36                 'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'good random code'),
37                 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who requested confirmation'),
38                 'address' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'address (email, xmpp, SMS, etc.)'),
39                 'address_extra' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'carrier ID, for SMS'),
40                 'address_type' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'),
41                 'claimed' => array('type' => 'datetime', 'description' => 'date this was claimed for queueing'),
42                 'sent' => array('type' => 'datetime', 'description' => 'date this was sent for queueing'),
43                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
44             ),
45             'primary key' => array('code'),
46             'foreign keys' => array(
47                 'confirm_address_user_id_fkey' => array('user', array('user_id' => 'id')),
48             ),
49         );
50     }
51
52     static function getAddress($address, $addressType)
53     {
54         $ca = new Confirm_address();
55
56         $ca->address      = $address;
57         $ca->address_type = $addressType;
58
59         if ($ca->find(true)) {
60             return $ca;
61         }
62
63         return null;
64     }
65
66     static function saveNew($user, $address, $addressType, $extra=null)
67     {
68         $ca = new Confirm_address();
69
70         if (!empty($user)) {
71             $ca->user_id = $user->id;
72         }
73
74         $ca->address       = $address;
75         $ca->address_type  = $addressType;
76         $ca->address_extra = $extra;
77         $ca->code          = common_confirmation_code(64);
78
79         $ca->insert();
80
81         return $ca;
82     }
83 }