pixelfed/app/Http/Resources/AdminUser.php

48 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2023-01-15 03:38:33 +00:00
<?php
namespace App\Http\Resources;
use App\Services\AccountService;
2024-07-17 08:24:16 +00:00
use Illuminate\Http\Resources\Json\JsonResource;
2023-01-15 03:38:33 +00:00
class AdminUser extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$account = AccountService::get($this->profile_id, true);
$res = [
2024-07-17 08:24:16 +00:00
'id' => (string) $this->id,
'profile_id' => (string) $this->profile_id,
2023-01-15 03:38:33 +00:00
'name' => $this->name,
'username' => $this->username,
'is_admin' => (bool) $this->is_admin,
2023-06-22 07:12:53 +00:00
'email' => $this->email,
2023-01-15 03:38:33 +00:00
'email_verified_at' => $this->email_verified_at,
'two_factor_enabled' => (bool) $this->{'2fa_enabled'},
'register_source' => $this->register_source,
2023-06-22 07:12:53 +00:00
'app_register_ip' => $this->app_register_ip,
2024-07-17 08:24:16 +00:00
'has_interstitial' => (bool) $this->has_interstitial,
2023-01-15 03:38:33 +00:00
'last_active_at' => $this->last_active_at,
'created_at' => $this->created_at,
];
2024-07-17 08:24:16 +00:00
if ($account) {
2023-01-15 03:38:33 +00:00
$res['avatar'] = $account['avatar'];
$res['bio'] = $account['note_text'];
2024-07-17 08:24:16 +00:00
$res['statuses_count'] = (int) $account['statuses_count'];
$res['following_count'] = (int) $account['following_count'];
$res['followers_count'] = (int) $account['followers_count'];
$res['is_private'] = (bool) $account['locked'];
2023-01-15 03:38:33 +00:00
}
return $res;
}
}