Confirm_address.php 3.0 KB

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