pixelfed/app/Transformer/Api/AccountTransformer.php

54 lines
1.4 KiB
PHP
Raw Normal View History

2018-07-12 16:42:17 +00:00
<?php
namespace App\Transformer\Api;
2019-09-02 00:26:54 +00:00
use Auth;
2018-07-12 16:42:17 +00:00
use App\Profile;
use League\Fractal;
class AccountTransformer extends Fractal\TransformerAbstract
{
2019-09-02 00:26:54 +00:00
protected $defaultIncludes = [
'relationship',
];
2018-12-31 04:26:37 +00:00
public function transform(Profile $profile)
{
2019-09-21 05:15:35 +00:00
$local = $profile->domain == null;
$is_admin = !$local ? false : $profile->user->is_admin;
$acct = $local ? $profile->username : substr($profile->username, 1);
$username = $local ? $profile->username : explode('@', $acct)[0];
2018-12-31 04:26:37 +00:00
return [
'id' => (string) $profile->id,
2019-09-21 05:15:35 +00:00
'username' => $username,
'acct' => $acct,
2018-12-31 04:26:37 +00:00
'display_name' => $profile->name,
'locked' => (bool) $profile->is_private,
2019-09-21 05:45:19 +00:00
'created_at' => $profile->created_at->format('c'),
2018-12-31 04:26:37 +00:00
'followers_count' => $profile->followerCount(),
'following_count' => $profile->followingCount(),
'statuses_count' => (int) $profile->statusCount(),
2018-12-31 04:26:37 +00:00
'note' => $profile->bio,
'url' => $profile->url(),
'avatar' => $profile->avatarUrl(),
'avatar_static' => $profile->avatarUrl(),
'header' => null,
'header_static' => null,
2019-05-05 00:14:59 +00:00
'header_bg' => $profile->header_bg,
2018-12-31 04:26:37 +00:00
'moved' => null,
2019-09-21 05:56:00 +00:00
'fields' => null,
2018-12-31 04:26:37 +00:00
'bot' => null,
2019-06-09 20:13:43 +00:00
'website' => $profile->website,
'software' => 'pixelfed',
2019-09-02 00:26:54 +00:00
'is_admin' => (bool) $is_admin,
2019-09-21 05:15:35 +00:00
'last_status_at' => null,
2019-09-21 05:56:00 +00:00
'emojis' => null,
2018-12-31 04:26:37 +00:00
];
}
2019-09-02 00:26:54 +00:00
protected function includeRelationship(Profile $profile)
{
return $this->item($profile, new RelationshipTransformer());
}
2018-08-28 03:07:36 +00:00
}