50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Actions\Tabulation\RankAuditionEntries;
|
|
use App\Models\Entry;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class EntryService
|
|
{
|
|
/**
|
|
* Create a new class instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
|
|
}
|
|
|
|
public function isEntryLate(Entry $entry): bool
|
|
{
|
|
if ($entry->hasFlag('wave_late_fee')) {
|
|
return false;
|
|
}
|
|
|
|
return $entry->created_at > $entry->audition->entry_deadline;
|
|
}
|
|
|
|
public function entryExists(Entry $entry): bool
|
|
{
|
|
$cacheKey = 'allEntryIds';
|
|
$allEntryIds = Cache::remember($cacheKey, 60, function () {
|
|
return Entry::pluck('id');
|
|
});
|
|
|
|
return $allEntryIds->contains($entry->id);
|
|
}
|
|
|
|
public function rankOfEntry(string $mode, Entry $entry)
|
|
{
|
|
$ranker = App::make(RankAuditionEntries::class);
|
|
$rankings = $ranker->rank($mode, $entry->audition);
|
|
$rankedEntry = $rankings->find($entry->id);
|
|
if (isset($rankedEntry->score_message)) {
|
|
return $rankedEntry->score_message;
|
|
}
|
|
return $rankings->find($entry->id)->rank ?? 'No Rank';
|
|
}
|
|
}
|