User_username.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Table Definition for user_username
  4. */
  5. require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
  6. class User_username extends Managed_DataObject
  7. {
  8. ###START_AUTOCODE
  9. /* the code below is auto generated do not remove the above tag */
  10. public $__table = 'user_username'; // table name
  11. public $user_id; // int(4) not_null
  12. public $provider_name; // varchar(191) primary_key not_null not 255 because utf8mb4 takes more space
  13. public $username; // varchar(191) primary_key not_null not 255 because utf8mb4 takes more space
  14. public $created; // datetime() not_null
  15. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  16. /* the code above is auto generated do not remove the tag below */
  17. ###END_AUTOCODE
  18. public static function schemaDef()
  19. {
  20. return array(
  21. 'fields' => array(
  22. 'provider_name' => array('type' => 'varchar', 'length' => 191, 'description' => 'provider name'),
  23. 'username' => array('type' => 'varchar', 'length' => 191, 'description' => 'username'),
  24. 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
  25. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  26. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  27. ),
  28. 'primary key' => array('provider_name', 'username'),
  29. 'indexes' => array(
  30. 'user_id_idx' => array('user_id')
  31. ),
  32. 'foreign keys' => array(
  33. 'user_username_user_id_fkey' => array('user', array('user_id' => 'id')),
  34. ),
  35. );
  36. }
  37. /**
  38. * Register a user with a username on a given provider
  39. * @param User User object
  40. * @param string username on the given provider
  41. * @param provider_name string name of the provider
  42. * @return mixed User_username instance if the registration succeeded, false if it did not
  43. */
  44. static function register($user, $username, $provider_name)
  45. {
  46. $user_username = new User_username();
  47. $user_username->user_id = $user->id;
  48. $user_username->provider_name = $provider_name;
  49. $user_username->username = $username;
  50. $user_username->created = common_sql_now();
  51. if($user_username->insert()){
  52. return $user_username;
  53. }else{
  54. return false;
  55. }
  56. }
  57. }