You've already forked Atomcms-edit
81e99933e4
- DRY FurniEditorController: extract duplicate try/catch blocks into handleApiError(), formatItemData(), buildUpdateData(), buildInsertData(), castValue() methods - ProfileController: replace 45 lines of manual date formatting with Carbon's diffForHumans() - Replace custom Password rule (180 lines) with Laravel's built-in Password::min() rule - RadioController: extract RadioStreamService and RadioScheduleService, reducing from 608 to 323 lines - Add RadioSettings enum to replace magic strings throughout radio feature - Add CurrencyTypes::columnName() helper method - Add consistent return types (JsonResponse, View, RedirectResponse) to all controller methods
81 lines
2.6 KiB
PHP
Executable File
81 lines
2.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\User;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Miscellaneous\WebsiteSetting;
|
|
use App\Models\User;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class ProfileController extends Controller
|
|
{
|
|
public function __invoke(User $user): View
|
|
{
|
|
$user->load([
|
|
'friends.friend:id,username,look',
|
|
'guilds.guild:id,name,badge',
|
|
'profileGuestbook.user:id,username,look',
|
|
'photos',
|
|
'badges',
|
|
]);
|
|
|
|
$showStats = (bool) (WebsiteSetting::where('key', 'profile_show_stats')->first()?->value ?? '1');
|
|
$showOnline = (bool) (WebsiteSetting::where('key', 'profile_show_online_status')->first()?->value ?? '1');
|
|
|
|
return view('user.profile', [
|
|
'user' => $user,
|
|
'friends' => $user->friends->take(10),
|
|
'groups' => $user->guilds->take(5),
|
|
'guestbook' => $user->profileGuestbook->take(5),
|
|
'photos' => $user->photos->take(3),
|
|
'badges' => $user->badges->take(3),
|
|
'showStats' => $showStats,
|
|
'showOnline' => $showOnline,
|
|
'accountAge' => $this->getAccountAge($user->account_created),
|
|
'lastLogin' => $this->getLastLogin($user->last_login),
|
|
'totalFriends' => $user->friends()->count(),
|
|
'totalGuilds' => $user->guilds()->count(),
|
|
]);
|
|
}
|
|
|
|
private function getAccountAge(int $timestamp): string
|
|
{
|
|
$created = Carbon::createFromTimestamp($timestamp);
|
|
|
|
if ($created->diffInYears() >= 1) {
|
|
return $created->diffInYears() . ' ' . str('year')->plural($created->diffInYears());
|
|
}
|
|
|
|
if ($created->diffInMonths() >= 1) {
|
|
return $created->diffInMonths() . ' ' . str('month')->plural($created->diffInMonths());
|
|
}
|
|
|
|
if ($created->diffInWeeks() >= 1) {
|
|
return $created->diffInWeeks() . ' ' . str('week')->plural($created->diffInWeeks());
|
|
}
|
|
|
|
return $created->diffInDays() . ' ' . str('day')->plural($created->diffInDays());
|
|
}
|
|
|
|
private function getLastLogin(int $timestamp): string
|
|
{
|
|
$lastLogin = Carbon::createFromTimestamp($timestamp);
|
|
$diffInMinutes = $lastLogin->diffInMinutes();
|
|
|
|
if ($diffInMinutes < 1) {
|
|
return 'Just now';
|
|
}
|
|
|
|
if ($diffInMinutes < 60) {
|
|
return $lastLogin->diffForHumans();
|
|
}
|
|
|
|
if ($diffInMinutes < 10080) {
|
|
return $lastLogin->diffForHumans();
|
|
}
|
|
|
|
return $lastLogin->format('d M Y');
|
|
}
|
|
}
|