function fractal_api_serialize_item($model, $transformer, $includes = null) { return fractal_api_serialize_collection([$model], $transformer, $includes)[0]; }
public function getBeatmaps() { $since = Request::input('since'); // - return all beatmaps ranked since this date. Must be a MySQL date. $set_id = Request::input('s'); // - specify a beatmapset_id to return metadata from. $beatmap_id = Request::input('b'); // - specify a beatmap_id to return metadata from. $user_id = Request::input('u'); // - specify a user_id or a username to return metadata from. $type = Request::input('type'); // - specify if `u` is a user_id or a username. Use `string` for usernames or `id` for user_ids. Optional, default behaviour is automatic recognition (may be problematic for usernames made up of digits only). $mode = Request::input('m'); // - mode (0 = osu!, 1 = Taiko, 2 = osu!catch, 3 = osu!mania). Optional, maps of all modes are returned by default. $include_converted = Request::input('a', 0); // - specify whether converted beatmaps are included (0 = not included, 1 = included). Only has an effect if `m` is chosen and not 0. Converted maps show their converted difficulty rating. Optional, default is 0. $hash = Request::input('h'); // - the beatmap hash. It can be used, for instance, if you're trying to get what beatmap has a replay played in, as .osr replays only provide beatmap hashes (example of hash: a5b99395a42bd55bc5eb1d2411cbdf8b). Optional, by default all beatmaps are returned independently from the hash. $limit = Request::input('limit', 500); // - amount of results. Optional, default and maximum are 500. $beatmaps = new Beatmap(); $beatmaps = $beatmaps->join('osu_beatmapsets', 'osu_beatmaps.beatmapset_id', '=', 'osu_beatmapsets.beatmapset_id')->where('osu_beatmapsets.approved', '>=', -2)->where('osu_beatmapsets.active', 1)->orderBy('osu_beatmapsets.approved_date', 'desc')->limit($limit); if (present($beatmap_id)) { $beatmaps = $beatmaps->where('beatmap_id', $beatmap_id); } if (present($set_id)) { $beatmaps = $beatmaps->where('osu_beatmapsets.beatmapset_id', $set_id); } if (present($user_id)) { $user = User::lookup($user_id, $type); if (!$user) { return Response::json([]); } $beatmaps = $beatmaps->where('osu_beatmaps.user_id', $user->user_id); } if (!in_array($mode, [Beatmap::OSU, Beatmap::TAIKO, Beatmap::FRUITS, Beatmap::MANIA])) { return Response::json([]); } $playmodes = []; if (present($mode)) { $playmodes[] = $mode; } if (present($include_converted) && $include_converted == 1) { $playmodes[] = 0; } if (!empty($playmodes)) { $beatmaps = $beatmaps->whereIn('playmode', $playmodes); } if (present($hash)) { $beatmaps = $beatmaps->where('checksum', $hash); } if (present($since)) { $beatmaps = $beatmaps->where('approved_date', '>', $since); } return fractal_api_serialize_collection($beatmaps->with('set', 'difficulty', 'difficultyAttribs')->get(), new BeatmapTransformer()); }