123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Services;
- use Cache;
- use App\Models\UserPronoun;
- use App\Profile;
- class PronounService {
- public static function get($id)
- {
- $key = 'user:pronouns:' . $id;
- $ttl = now()->addHours(12);
- return Cache::remember($key, $ttl, function() use($id) {
- $res = UserPronoun::whereProfileId($id)->first();
- return $res ? json_decode($res->pronouns, true) : [];
- });
- }
- public static function put($id, $pronouns)
- {
- $res = UserPronoun::whereProfileId($id)->first();
- $key = 'user:pronouns:' . $id;
- if($res) {
- $res->pronouns = json_encode($pronouns);
- $res->save();
- Cache::forget($key);
- AccountService::del($id);
- return $res->pronouns;
- }
- $res = new UserPronoun;
- $res->profile_id = $id;
- $res->pronouns = json_encode($pronouns);
- $res->save();
- Cache::forget($key);
- AccountService::del($id);
- return $res->pronouns;
- }
- public static function clear($id)
- {
- $res = UserPronoun::whereProfileId($id)->first();
- if($res) {
- $res->pronouns = null;
- $res->save();
- }
- $key = 'user:pronouns:' . $id;
- Cache::forget($key);
- AccountService::del($id);
- }
- public static function pronouns()
- {
- return [
- 'co',
- 'cos',
- 'e',
- 'ey',
- 'em',
- 'eir',
- 'fae',
- 'faer',
- 'he',
- 'him',
- 'his',
- 'her',
- 'hers',
- 'hir',
- 'mer',
- 'mers',
- 'ne',
- 'nir',
- 'nirs',
- 'nee',
- 'ner',
- 'ners',
- 'per',
- 'pers',
- 'she',
- 'they',
- 'them',
- 'theirs',
- 'thon',
- 'thons',
- 've',
- 'ver',
- 'vis',
- 'vi',
- 'vir',
- 'xe',
- 'xem',
- 'xyr',
- 'ze',
- 'zir',
- 'zie'
- ];
- }
- }
|