Ejemplo n.º 1
0
 public function index()
 {
     $fractal = new Manager();
     $languages = Language::listing();
     $genres = Genre::listing();
     $beatmaps = fractal_collection_array(BeatmapSet::listing(), new BeatmapSetTransformer(), 'difficulties');
     // temporarily put filters here
     $modes = [['id' => null, 'name' => trans('beatmaps.mode.any')]];
     foreach (Beatmap::modes() as $name => $id) {
         $modes[] = ['id' => (string) $id, 'name' => trans("beatmaps.mode.{$name}")];
     }
     $statuses = [['id' => null, 'name' => trans('beatmaps.status.any')], ['id' => '0', 'name' => trans('beatmaps.status.ranked-approved')], ['id' => '1', 'name' => trans('beatmaps.status.approved')], ['id' => '2', 'name' => trans('beatmaps.status.faves')], ['id' => '3', 'name' => trans('beatmaps.status.modreqs')], ['id' => '4', 'name' => trans('beatmaps.status.pending')], ['id' => '5', 'name' => trans('beatmaps.status.graveyard')], ['id' => '6', 'name' => trans('beatmaps.status.my-maps')]];
     $extras = [['id' => '0', 'name' => trans('beatmaps.extra.video')], ['id' => '1', 'name' => trans('beatmaps.extra.storyboard')]];
     $ranks = [];
     foreach (['XH', 'X', 'SH', 'S', 'A', 'B', 'C', 'D'] as $rank) {
         $ranks[] = ['id' => $rank, 'name' => trans("beatmaps.rank.{$rank}")];
     }
     $filters = ['data' => compact('modes', 'statuses', 'genres', 'languages', 'extras', 'ranks')];
     return view('beatmaps.index', compact('filters', 'beatmaps'));
 }
Ejemplo n.º 2
0
 public function scoresBest($mode, $returnQuery = false)
 {
     if (!in_array($mode, array_keys(Beatmap::modes()), true)) {
         return;
     }
     if ($returnQuery) {
         $mode = studly_case($mode);
         return $this->hasMany("App\\Models\\Score\\Best\\{$mode}")->default();
     } else {
         $relation = camel_case("scores_best_{$mode}");
         return $this->{$relation};
     }
 }
Ejemplo n.º 3
0
 private static function sanitizeSearchParams(array &$params = [])
 {
     // sort param
     if (count($params['sort']) !== 2) {
         $params['sort'] = ['ranked', 'desc'];
     }
     if (!in_array((int) $params['mode'], Beatmap::modes(), true)) {
         $params['mode'] = null;
     }
     $valid_sort_fields = ['title', 'artist', 'creator', 'difficulty', 'ranked', 'rating', 'plays'];
     $valid_sort_orders = ['asc', 'desc'];
     if (!in_array($params['sort'][0], $valid_sort_fields, true) || !in_array($params['sort'][1], $valid_sort_orders, true)) {
         $params['sort'] = ['ranked', 'desc'];
     }
     // remap sort field to their db/elastic-search equivalents
     $params['sort'][0] = str_replace(['difficulty', 'ranked', 'plays'], ['difficultyrating', 'approved_date', 'playcount'], $params['sort'][0]);
     list($params['sort_field'], $params['sort_order']) = $params['sort'];
     unset($params['sort']);
     $valid_ranks = ['A', 'B', 'C', 'D', 'S', 'SH', 'X', 'XH'];
     foreach ($params['rank'] as $rank) {
         if (!in_array($rank, $valid_ranks, true)) {
             unset($params['rank'][$rank]);
         }
     }
     if ($params['query'] !== null) {
         $params['query'] = preg_replace('/\\s{2,}/', ' ', $params['query']);
         $params['query'] = trim($params['query']);
         $query_parts = explode(' ', $params['query']);
         foreach ($query_parts as $key => $value) {
             $query_parts[$key] = urlencode($value);
         }
         $params['query'] = implode(' AND ', $query_parts);
     }
 }
Ejemplo n.º 4
0
 public function includeAllScores(User $user)
 {
     return $this->item($user, function ($user) {
         $all = [];
         foreach (array_keys(Beatmap::modes()) as $mode) {
             $scores = $user->scores($mode, true)->default()->with('beatmapSet', 'beatmap')->get();
             $all[$mode] = fractal_collection_array($scores, new ScoreTransformer(), 'beatmap,beatmapSet');
         }
         return $all;
     });
 }
Ejemplo n.º 5
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 = get_int(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 = intval(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 = intval(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 ($mode !== null && in_array($mode, array_values(Beatmap::modes()), true) === false) {
         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());
 }