Confirm_address.php 2.8 KB

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