Files
nexusphp/app/Http/Resources/UserResource.php

59 lines
2.4 KiB
PHP
Raw Normal View History

2021-04-17 19:01:33 +08:00
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
2021-05-15 19:29:44 +08:00
$out = [
2021-04-17 19:01:33 +08:00
'id' => $this->id,
'email' => $this->email,
'username' => $this->username,
'status' => $this->status,
2021-05-14 20:41:43 +08:00
'enabled' => $this->enabled,
'added' => format_datetime($this->added),
2022-03-06 15:43:29 +08:00
'last_access' => format_datetime($this->last_access),
2021-04-17 19:01:33 +08:00
'class' => $this->class,
2021-04-25 02:12:14 +08:00
'class_text' => $this->class_text,
2021-04-17 19:01:33 +08:00
'avatar' => $this->avatar,
'uploaded' => $this->uploaded,
2021-04-25 02:12:14 +08:00
'uploaded_text' => mksize($this->uploaded),
2021-04-17 19:01:33 +08:00
'downloaded' => $this->downloaded,
2021-04-25 02:12:14 +08:00
'downloaded_text' => mksize($this->downloaded),
2022-03-14 14:51:58 +08:00
'bonus' => number_format($this->seedbonus, 1),
2022-02-21 23:20:25 +08:00
'seed_points' => floatval($this->seed_points),
2021-04-17 19:01:33 +08:00
'seedtime' => $this->seedtime,
2021-04-30 15:10:31 +08:00
'seedtime_text' => mkprettytime($this->seedtime),
2021-04-17 19:01:33 +08:00
'leechtime' => $this->leechtime,
2021-04-30 15:10:31 +08:00
'leechtime_text' => mkprettytime($this->leechtime),
2021-05-12 13:45:00 +08:00
'inviter' => new UserResource($this->whenLoaded('inviter')),
2022-01-19 23:54:55 +08:00
'valid_medals' => MedalResource::collection($this->whenLoaded('valid_medals')),
2021-04-17 19:01:33 +08:00
];
2021-05-15 19:29:44 +08:00
if ($request->routeIs('user.me')) {
$out['downloaded_human'] = mksize($this->downloaded);
$out['uploaded_human'] = mksize($this->uploaded);
$out['seed_time'] = mkprettytime($this->seedtime);
$out['leech_time'] = mkprettytime($this->leechtime);
$out['share_ratio'] = get_share_ratio($this->uploaded, $this->downloaded);
$out['invites'] = $this->invites;
$out['comments_count'] = $this->comments_count;
$out['posts_count'] = $this->posts_count;
2022-02-21 17:20:04 +08:00
$out['torrents_count'] = $this->torrents_count;
$out['seeding_torrents_count'] = $this->seeding_torrents_count;
$out['leeching_torrents_count'] = $this->leeching_torrents_count;
$out['completed_torrents_count'] = $this->completed_torrents_count;
$out['incomplete_torrents_count'] = $this->incomplete_torrents_count;
2021-05-15 19:29:44 +08:00
}
return $out;
2021-04-17 19:01:33 +08:00
}
}