PronounService.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Services;
  3. use Cache;
  4. use App\Models\UserPronoun;
  5. use App\Profile;
  6. class PronounService {
  7. public static function get($id)
  8. {
  9. $key = 'user:pronouns:' . $id;
  10. $ttl = now()->addHours(12);
  11. return Cache::remember($key, $ttl, function() use($id) {
  12. $res = UserPronoun::whereProfileId($id)->first();
  13. return $res ? json_decode($res->pronouns, true) : [];
  14. });
  15. }
  16. public static function put($id, $pronouns)
  17. {
  18. $res = UserPronoun::whereProfileId($id)->first();
  19. $key = 'user:pronouns:' . $id;
  20. if($res) {
  21. $res->pronouns = json_encode($pronouns);
  22. $res->save();
  23. Cache::forget($key);
  24. AccountService::del($id);
  25. return $res->pronouns;
  26. }
  27. $res = new UserPronoun;
  28. $res->profile_id = $id;
  29. $res->pronouns = json_encode($pronouns);
  30. $res->save();
  31. Cache::forget($key);
  32. AccountService::del($id);
  33. return $res->pronouns;
  34. }
  35. public static function clear($id)
  36. {
  37. $res = UserPronoun::whereProfileId($id)->first();
  38. if($res) {
  39. $res->pronouns = null;
  40. $res->save();
  41. }
  42. $key = 'user:pronouns:' . $id;
  43. Cache::forget($key);
  44. AccountService::del($id);
  45. }
  46. public static function pronouns()
  47. {
  48. return [
  49. 'co',
  50. 'cos',
  51. 'e',
  52. 'ey',
  53. 'em',
  54. 'eir',
  55. 'fae',
  56. 'faer',
  57. 'he',
  58. 'him',
  59. 'his',
  60. 'her',
  61. 'hers',
  62. 'hir',
  63. 'mer',
  64. 'mers',
  65. 'ne',
  66. 'nir',
  67. 'nirs',
  68. 'nee',
  69. 'ner',
  70. 'ners',
  71. 'per',
  72. 'pers',
  73. 'she',
  74. 'they',
  75. 'them',
  76. 'theirs',
  77. 'thon',
  78. 'thons',
  79. 've',
  80. 'ver',
  81. 'vis',
  82. 'vi',
  83. 'vir',
  84. 'xe',
  85. 'xem',
  86. 'xyr',
  87. 'ze',
  88. 'zir',
  89. 'zie'
  90. ];
  91. }
  92. }