App\Models\Score\Best\Model::fillInPosition PHP Method

fillInPosition() public static method

$scores shall be pre-sorted by pp (or whatever default scoring order).
public static fillInPosition ( $scores )
    public static function fillInPosition($scores)
    {
        if ($scores->first() === null) {
            return;
        }
        $position = $scores->first()->position();
        foreach ($scores as $score) {
            $score->position = $position;
            $position++;
        }
    }

Usage Example

示例#1
0
 public function includeAllScoresBest(User $user)
 {
     return $this->item($user, function ($user) {
         $all = [];
         foreach (array_keys(Beatmap::MODES) as $mode) {
             $scores = $user->scoresBest($mode, true)->default()->orderBy('pp', 'DESC')->with('beatmapset', 'beatmap')->limit(100)->get();
             ScoreBestModel::fillInPosition($scores);
             $all[$mode] = json_collection($scores, new ScoreTransformer(), 'beatmap,beatmapset,weight');
         }
         return $all;
     });
 }