Foreign_user.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Table Definition for foreign_user
  4. */
  5. require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
  6. class Foreign_user extends Managed_DataObject
  7. {
  8. ###START_AUTOCODE
  9. /* the code below is auto generated do not remove the above tag */
  10. public $__table = 'foreign_user'; // table name
  11. public $id; // bigint(8) primary_key not_null
  12. public $service; // int(4) primary_key not_null
  13. public $uri; // varchar(191) unique_key not_null not 255 because utf8mb4 takes more space
  14. public $nickname; // varchar(191) not 255 because utf8mb4 takes more space
  15. public $created; // datetime() not_null
  16. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  17. /* the code above is auto generated do not remove the tag below */
  18. ###END_AUTOCODE
  19. public static function schemaDef()
  20. {
  21. return array(
  22. 'fields' => array(
  23. 'id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'unique numeric key on foreign service'),
  24. 'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
  25. 'uri' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'identifying URI'),
  26. 'nickname' => array('type' => 'varchar', 'length' => 191, 'description' => 'nickname on foreign service'),
  27. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  28. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  29. ),
  30. 'primary key' => array('id', 'service'),
  31. 'foreign keys' => array(
  32. 'foreign_user_service_fkey' => array('foreign_service', array('service' => 'id')),
  33. ),
  34. 'unique keys' => array(
  35. 'foreign_user_uri_key' => array('uri'),
  36. ),
  37. );
  38. }
  39. static function getForeignUser($id, $service)
  40. {
  41. if (empty($id) || empty($service)) {
  42. throw new ServerException('Empty foreign user id or service for Foreign_user::getForeignUser');
  43. }
  44. $fuser = new Foreign_user();
  45. $fuser->id = $id;
  46. $fuser->service = $service;
  47. $fuser->limit(1);
  48. if (!$fuser->find(true)) {
  49. throw new NoResultException($fuser);
  50. }
  51. return $fuser;
  52. }
  53. static function getByNickname($nickname, $service)
  54. {
  55. if (empty($nickname) || empty($service)) {
  56. throw new ServerException('Empty nickname or service for Foreign_user::getByNickname');
  57. }
  58. $fuser = new Foreign_user();
  59. $fuser->service = $service;
  60. $fuser->nickname = $nickname;
  61. $fuser->limit(1);
  62. if (!$fuser->find(true)) {
  63. throw new NoResultException($fuser);
  64. }
  65. return $fuser;
  66. }
  67. }