1
0

AccountTransformer.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Transformer\Api;
  3. use Auth;
  4. use App\Profile;
  5. use League\Fractal;
  6. use App\Services\PronounService;
  7. class AccountTransformer extends Fractal\TransformerAbstract
  8. {
  9. protected $defaultIncludes = [
  10. // 'relationship',
  11. ];
  12. public function transform(Profile $profile)
  13. {
  14. $local = $profile->domain == null;
  15. $is_admin = !$local ? false : $profile->user->is_admin;
  16. $acct = $local ? $profile->username : substr($profile->username, 1);
  17. $username = $local ? $profile->username : explode('@', $acct)[0];
  18. return [
  19. 'id' => (string) $profile->id,
  20. 'username' => $username,
  21. 'acct' => $acct,
  22. 'display_name' => $profile->name,
  23. 'discoverable' => true,
  24. 'locked' => (bool) $profile->is_private,
  25. 'followers_count' => (int) $profile->followerCount(),
  26. 'following_count' => (int) $profile->followingCount(),
  27. 'statuses_count' => (int) $profile->statusCount(),
  28. 'note' => $profile->bio ?? '',
  29. 'note_text' => strip_tags($profile->bio),
  30. 'url' => $profile->url(),
  31. 'avatar' => $profile->avatarUrl(),
  32. 'website' => $profile->website,
  33. 'local' => (bool) $local,
  34. 'is_admin' => (bool) $is_admin,
  35. 'created_at' => $profile->created_at->toJSON(),
  36. 'header_bg' => $profile->header_bg,
  37. 'last_fetched_at' => optional($profile->last_fetched_at)->toJSON(),
  38. 'pronouns' => PronounService::get($profile->id),
  39. 'location' => $profile->location
  40. ];
  41. }
  42. protected function includeRelationship(Profile $profile)
  43. {
  44. return $this->item($profile, new RelationshipTransformer());
  45. }
  46. }