Inheritance: extends Illuminate\Database\Eloquent\Model
Esempio n. 1
0
 public function getModeAttribute($value)
 {
     if (!present($value)) {
         return;
     }
     return Beatmap::modeStr((int) $value);
 }
Esempio n. 2
0
 public static function getClass($modeInt)
 {
     $modeStr = Beatmap::modeStr($modeInt);
     if ($modeStr !== null) {
         $klass = get_class_namespace(static::class) . '\\' . studly_case($modeStr);
         return new $klass();
     }
 }
Esempio n. 3
0
 public function includeAllRankHistories(User $user)
 {
     return $this->item($user, function ($user) {
         $all = [];
         foreach ($user->rankHistories as $history) {
             $modeStr = Beatmap::modeStr($history->mode);
             $all[$modeStr] = json_item($history, new RankHistoryTransformer());
         }
         return $all;
     });
 }
Esempio n. 4
0
 public function scores()
 {
     // FIXME: scores are obtained via filename/checksum lookup for legacy reason (temporarily)
     $filename = Request::input('f');
     $checksum = Request::input('c');
     $per_page = min(Request::input('n', 50), 50);
     $page = max(Request::input('p', 1), 1);
     $beatmap = Beatmap::where('filename', $filename)->where('checksum', $checksum)->firstorFail();
     $beatmap_meta = json_item($beatmap, new BeatmapTransformer());
     $scores = $beatmap->scoresBest()->defaultListing()->forPage($page, $per_page);
     if ($beatmap->approved >= 1) {
         $beatmap_scores = json_collection($scores->get(), new ScoreTransformer());
     } else {
         $beatmap_scores = [];
     }
     return Response::json(['beatmap' => $beatmap_meta, 'scores' => $beatmap_scores]);
 }
Esempio n. 5
0
 public function getUser()
 {
     $id = Request::input('u');
     $mode = Beatmap::modeStr(intval(Request::input('m', 0)));
     $type = Request::input('type');
     $event_days = min(31, (int) Request::input('event_days', 1));
     if ($mode === null) {
         return Response::json([]);
     }
     $user = User::lookup($id, $type);
     if (!$user) {
         return Response::json([]);
     }
     $stats = json_item($user->statistics($mode, true)->first(), new StatisticsTransformer());
     $events = json_collection($user->events()->where('date', '>', Carbon::now()->addDays(-$event_days))->orderBy('event_id', 'desc')->get(), new EventTransformer());
     $user = json_item($user, new UserTransformer());
     $combined = array_merge($user, $stats, ['events' => $events]);
     return Response::json([$combined]);
 }
Esempio n. 6
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'));
 }
Esempio n. 7
0
 public function scores($id)
 {
     $beatmap = Beatmap::findOrFail($id);
     $mode = Request::input('mode', Beatmap::modeStr($beatmap->playmode));
     $mods = Request::input('enabledMods');
     $type = Request::input('type', 'global');
     $user = Auth::user();
     if (!is_array($mods)) {
         $mods = [];
     }
     if ($type !== 'global' || !empty($mods)) {
         if ($user === null || !$user->isSupporter()) {
             return error_popup(trans('errors.supporter_only'));
         }
     }
     try {
         $query = $beatmap->scoresBest($mode)->defaultListing()->with('user');
     } catch (\InvalidArgumentException $ex) {
         return error_popup($ex->getMessage());
     }
     $query->withMods($mods);
     switch ($type) {
         case 'country':
             $query->fromCountry($user->country_acronym);
             break;
         case 'friend':
             $query->friendsOf($user);
             break;
     }
     $scoresList = json_collection($query->get(), new ScoreTransformer(), 'user');
     if ($user !== null) {
         $score = (clone $query)->where('user_id', $user->user_id)->first();
         if ($score !== null) {
             $userScore = json_item($score, new ScoreTransformer(), 'user');
             $userScorePosition = 1 + (clone $query)->limit(null)->where('score', '>', $score->score)->count();
         }
     }
     return ['scoresList' => $scoresList, 'userScore' => $userScore ?? null, 'userScorePosition' => $userScorePosition ?? null];
 }
Esempio n. 8
0
File: User.php Progetto: ppy/osu-web
 public function setPlaymodeAttribute($value)
 {
     $this->osu_playmode = Beatmap::modeInt($attribute);
 }
Esempio n. 9
0
 public function gamemodeString()
 {
     return Beatmap::modeStr($this->game->play_mode);
 }
Esempio n. 10
0
 public function includeScoresBest(Beatmap $beatmap)
 {
     $scores = $beatmap->scoresBest()->defaultListing()->limit(config('osu.beatmaps.max-scores'))->get();
     return $this->collection($scores, new ScoreTransformer());
 }
Esempio n. 11
0
 public function getPlaymodeAttribute($value)
 {
     return Beatmap::modeStr($this->osu_playmode);
 }
Esempio n. 12
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;
     });
 }
Esempio n. 13
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);
     }
 }
Esempio n. 14
0
 public function playModeStr()
 {
     return Beatmap::modeStr($this->play_mode);
 }
Esempio n. 15
0
File: Game.php Progetto: ppy/osu-web
 public function getModeAttribute()
 {
     return Beatmap::modeStr($this->play_mode);
 }
Esempio n. 16
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $beatmaps_array = [];
     $beatmapset_array = [];
     $overbeatmaps = [];
     $overbeatmapsets = [];
     $base_url = 'https://osu.ppy.sh/api/';
     $api_key = env('OSU_API_KEY', null);
     if (empty($api_key)) {
         $this->command->error('Error: No OSU_API_KEY value set in .env file. Can\'t seed beatmap data!');
         return;
     }
     $api = '&k=' . $api_key;
     $users = App\Models\User::orderByRaw('RAND()')->get()->toArray();
     if (count($users) < 1) {
         $users = [['user_id' => 1]];
     }
     try {
         $beatmaps = json_decode(file_get_contents($base_url . 'get_beatmaps?since=2016-01-01%2000:00:00' . $api));
         $last_beatmapset = null;
         $beatmap_diff_names = [];
         $beatmapset_versions = 0;
         $set_playcount = 0;
         $number_of_beatmaps = count($beatmaps);
         $i = 0;
         $first_map = true;
         $last_map = false;
         foreach ($beatmaps as $bm) {
             $make_new_set = false;
             if ($i === $number_of_beatmaps - 1) {
                 $make_new_set = true;
                 $last_map = true;
             }
             // Here we are going to check if the current beatmap belongs to a new set, and make the set if necessary
             if ($last_beatmapset === $bm->beatmapset_id || $first_map === true) {
                 ++$beatmapset_versions;
                 $beatmap_diff_names[] = $bm->version . '@' . $bm->mode;
                 $set_playcount += $bm->playcount;
             } else {
                 $make_new_set = true;
             }
             if ($make_new_set === true) {
                 if ($last_map === true) {
                     $the_beatmap = $bm;
                 } else {
                     $the_beatmap = $previous_beatmap;
                 }
                 // Create new beatmapset
                 $set = \App\Models\BeatmapSet::where('beatmapset_id', $the_beatmap->beatmapset_id)->first();
                 if ($set) {
                     $set->delete();
                     $overbeatmapsets[] = $the_beatmap->beatmapset_id;
                 }
                 $beatmap_diff_names = implode(',', $beatmap_diff_names);
                 $set = new \App\Models\BeatmapSet();
                 $set->beatmapset_id = $the_beatmap->beatmapset_id;
                 $set->creator = $the_beatmap->creator;
                 $set->artist = $the_beatmap->artist;
                 $set->title = $the_beatmap->title;
                 $set->displaytitle = $the_beatmap->title;
                 $set->source = $the_beatmap->source;
                 $set->tags = $the_beatmap->tags;
                 $set->bpm = $the_beatmap->bpm;
                 $set->approved = $the_beatmap->approved;
                 $set->approved_date = $the_beatmap->approved_date;
                 $set->genre_id = $the_beatmap->genre_id;
                 $set->language_id = $the_beatmap->language_id;
                 $set->versions_available = $beatmapset_versions;
                 $set->difficulty_names = $beatmap_diff_names;
                 $set->play_count = $set_playcount;
                 $set->favourite_count = $the_beatmap->favourite_count;
                 $set->user_id = array_rand_val($users)['user_id'];
                 $set->save();
                 $set->difficulty_names = $beatmap_diff_names;
                 $beatmapset_array[] = $set;
                 $set_playcount = $bm->playcount;
                 $beatmapset_versions = 1;
                 $beatmap_diff_names = [$bm->version . '@' . $bm->mode];
             }
             if ($new_bm = \App\Models\Beatmap::where('beatmap_id', $bm->beatmap_id)->first()) {
                 $new_bm->delete();
                 $overbeatmaps[] = $new_bm;
             }
             $new_bm = new \App\Models\Beatmap();
             $new_bm->beatmap_id = $bm->beatmap_id;
             $new_bm->beatmapset_id = $bm->beatmapset_id;
             $new_bm->filename = $bm->beatmapset_id . ' ' . $bm->artist . ' - ' . $bm->title . '.osz';
             $new_bm->checksum = $bm->file_md5;
             $new_bm->version = $bm->version;
             $new_bm->total_length = $bm->total_length;
             $new_bm->hit_length = $bm->hit_length;
             $new_bm->countTotal = $bm->max_combo !== null ? $bm->max_combo : 1500;
             $new_bm->countNormal = round(intval($bm->max_combo) - 0.2 * intval($bm->max_combo));
             $new_bm->countSlider = round(intval($bm->max_combo) - 0.8 * intval($bm->max_combo)) - 1;
             $new_bm->countSpinner = 1;
             $new_bm->diff_drain = $bm->diff_drain;
             $new_bm->diff_size = $bm->diff_size;
             $new_bm->diff_overall = $bm->diff_overall;
             $new_bm->diff_approach = $bm->diff_approach;
             $new_bm->playmode = $bm->mode;
             $new_bm->approved = $bm->approved;
             $new_bm->difficultyrating = $bm->difficultyrating;
             $new_bm->playcount = $bm->playcount;
             $new_bm->passcount = $bm->passcount;
             $new_bm->user_id = array_rand_val($users)['user_id'];
             $new_bm->save();
             $beatmaps_array[] = $new_bm;
             if ($first_map === true) {
                 $first_map = false;
             }
             $last_beatmapset = $bm->beatmapset_id;
             $previous_beatmap = $bm;
             ++$i;
         }
         // end foreach beatmap
         $this->command->info('Saved ' . strval(count($beatmaps_array)) . ' Beatmaps (Overwritten ' . strval(count($overbeatmaps)) . ').');
         $this->command->info('Saved ' . strval(count($beatmapset_array)) . ' Beatmap Sets (Overwritten ' . strval(count($overbeatmapsets)) . ').');
     } catch (\Illuminate\Database\QueryException $e) {
         $this->command->error("DB Error: Unable to save Beatmap Data\r\n" . $e->getMessage());
     } catch (Exception $ex) {
         $this->command->error("Error: Unable to save Beatmap Data\r\n" . $ex->getMessage());
     }
 }
Esempio n. 17
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());
 }