App\Transformers\BeatmapsetTransformer::includeNominations PHP Метод

includeNominations() публичный Метод

public includeNominations ( Beatmapset $beatmapset )
$beatmapset app\models\Beatmapset
    public function includeNominations(Beatmapset $beatmapset)
    {
        if ($beatmapset->isPending()) {
            $currentUser = Auth::user();
            $nominations = $beatmapset->recentEvents()->get();
            foreach ($nominations as $nomination) {
                if ($nomination->type === BeatmapsetEvent::DISQUALIFY) {
                    $disqualifyEvent = $nomination;
                }
                if ($currentUser !== null && $nomination->user_id === $currentUser->user_id && $nomination->type === BeatmapsetEvent::NOMINATE) {
                    $alreadyNominated = true;
                }
            }
            $result = ['required' => $beatmapset->requiredNominationCount(), 'current' => $beatmapset->currentNominationCount()];
            if (isset($disqualifyEvent)) {
                $result['disqualification'] = ['reason' => $disqualifyEvent->comment, 'created_at' => json_time($disqualifyEvent->created_at)];
            }
            if ($currentUser !== null) {
                $result['nominated'] = $alreadyNominated ?? false;
            }
            return $this->item($beatmapset, function ($beatmapset) use($result) {
                return $result;
            });
        } elseif ($beatmapset->qualified()) {
            $eta = $beatmapset->rankingETA();
            $result = ['ranking_eta' => json_time($eta)];
            return $this->item($beatmapset, function ($beatmapset) use($result) {
                return $result;
            });
        } else {
            return;
        }
    }