FFXIV_Lodestone_Handler/app/Http/Controllers/HelixRankCheckController.php

46 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\FreeCompanyRankedUser;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class HelixRankCheckController extends Controller
{
public function getRankChanges()
{
$members = FreeCompanyRankedUser::all()->toArray();
$members = array_map(function ($e) {
$e['lodestoneId'] = (string)$e['lodestoneId'];
$e['shouldBeRole'] = null;
$editable_roles = config('chaosapi.helix.rank_time');
// We don't want to edit council or mentor
if (!in_array($e['ingameRole'], array_keys($editable_roles))) return $e;
// Keep track of the highest role
$highest_role = $e['ingameRole'];
foreach ($editable_roles as $role => $min_days) {
if ($min_days === null) continue;
$min_date = Carbon::parse($e['firstSeen'])->addDays($min_days);
if ($min_date <= Carbon::now())
$highest_role = $role;
}
if (array_search($e['ingameRole'], array_keys($editable_roles)) < array_search($highest_role, array_keys($editable_roles)))
$e['shouldBeRole'] = $highest_role;
return $e;
}, $members);
return [
'success' => true,
'error' => null,
'data' => $members
];
}
}