Invitation.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Table Definition for invitation
  4. */
  5. require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
  6. class Invitation extends Managed_DataObject
  7. {
  8. ###START_AUTOCODE
  9. /* the code below is auto generated do not remove the above tag */
  10. public $__table = 'invitation'; // table name
  11. public $code; // varchar(32) primary_key not_null
  12. public $user_id; // int(4) not_null
  13. public $address; // varchar(191) multiple_key not_null not 255 because utf8mb4 takes more space
  14. public $address_type; // varchar(8) multiple_key not_null
  15. public $registered_user_id; // int(4) not_null
  16. public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
  17. /* the code above is auto generated do not remove the tag below */
  18. ###END_AUTOCODE
  19. function convert($user)
  20. {
  21. $orig = clone($this);
  22. $this->registered_user_id = $user->id;
  23. return $this->update($orig);
  24. }
  25. public static function schemaDef()
  26. {
  27. return array(
  28. 'fields' => array(
  29. 'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'random code for an invitation'),
  30. 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'who sent the invitation'),
  31. 'address' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'invitation sent to'),
  32. 'address_type' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'),
  33. 'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
  34. 'registered_user_id' => array('type' => 'int', 'not null' => false, 'description' => 'if the invitation is converted, who the new user is'),
  35. ),
  36. 'primary key' => array('code'),
  37. 'foreign keys' => array(
  38. 'invitation_user_id_fkey' => array('user', array('user_id' => 'id')),
  39. 'invitation_registered_user_id_fkey' => array('user', array('registered_user_id' => 'id')),
  40. ),
  41. 'indexes' => array(
  42. 'invitation_address_idx' => array('address', 'address_type'),
  43. 'invitation_user_id_idx' => array('user_id'),
  44. 'invitation_registered_user_id_idx' => array('registered_user_id'),
  45. ),
  46. );
  47. }
  48. }