public function history($match_id) { $since = Request::input('since', 0); $full = Request::input('full', false) === 'true'; $match = Match::findOrFail($match_id); $events = $match->events()->with(['game.beatmap.beatmapset', 'game.scores' => function ($query) { $query->with('game')->default(); }])->where('event_id', '>', $since); if ($full) { $events->default(); } else { $events->orderBy('event_id', 'desc')->take(config('osu.mp-history.event-count')); } $events = $events->get(); if (!$full) { $events = $events->reverse(); } $userIds = []; foreach ($events as $event) { if ($event->user_id) { $userIds[] = $event->user_id; } if ($event->game) { foreach ($event->game->scores as $score) { $userIds[] = $score->user_id; } } } $users = User::with('country')->whereIn('user_id', array_unique($userIds))->get(); $users = json_collection($users, new UserCompactTransformer(), 'country'); $events = json_collection($events, new EventTransformer(), ['game.beatmap.beatmapset', 'game.scores']); return ['events' => $events, 'users' => $users, 'all_events_count' => $match->events()->count()]; }
public function privateMessages() { $since = intval(Request::input('since')); $limit = min(50, intval(Request::input('limit', 50))); $messages = PrivateMessage::toOrFrom($this->current_user->user_id)->with('sender')->with('receiver'); if ($since) { $messages = $messages->where('message_id', '>', $since); } $collection = json_collection($messages->orderBy('message_id', $since ? 'asc' : 'desc')->limit($limit)->get(), new PrivateMessageTransformer()); return $since ? $collection : array_reverse($collection); }
public function show($id) { $artist = Artist::with('label')->findOrFail($id); $tracks = $artist->tracks()->get(); $images = ['header_url' => $artist->header_url, 'cover_url' => $artist->cover_url]; $links = []; foreach (['twitter', 'facebook', 'soundcloud'] as $service) { if ($artist->{$service}) { $links[] = ['title' => ucwords($service), 'url' => $artist->{$service}, 'icon' => $service, 'class' => $service]; } } if ($artist->website) { $links[] = ['title' => trans('artist.links.site'), 'url' => $artist->website, 'icon' => 'globe', 'class' => '']; } return view('artists.show')->with('artist', $artist)->with('links', $links)->with('tracks', json_collection($tracks, new ArtistTrackTransformer()))->with('images', $images); }
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]); }
public function show($id) { $artist = Artist::with('label')->findOrFail($id); $albums = $artist->albums()->where('visible', true)->with(['tracks' => function ($query) { $query->orderBy('display_order', 'ASC'); }])->get(); $tracks = $artist->tracks()->whereNull('album_id')->orderBy('display_order', 'ASC NULLS LAST')->get(); $images = ['header_url' => $artist->header_url, 'cover_url' => $artist->cover_url]; // should probably move services to a separate model if the number increases further $links = []; foreach (['soundcloud', 'twitter', 'facebook', 'bandcamp', 'patreon'] as $service) { if ($artist->{$service}) { $links[] = ['title' => ucwords($service), 'url' => $artist->{$service}, 'icon' => $service === 'patreon' ? "extra-social-{$service}" : $service, 'class' => $service]; } } if ($artist->website) { $links[] = ['title' => trans('artist.links.site'), 'url' => $artist->website, 'icon' => 'globe', 'class' => 'website']; } return view('artists.show')->with('artist', $artist)->with('links', $links)->with('albums', json_collection($albums, new ArtistAlbumTransformer(), ['tracks']))->with('tracks', json_collection($tracks, new ArtistTrackTransformer()))->with('images', $images); }
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]; }
public function search() { $current_user = Auth::user(); $params = []; if (is_null($current_user)) { $params = ['page' => Request::input('page')]; } else { $params = ['query' => Request::input('q'), 'mode' => Request::input('m'), 'status' => Request::input('s'), 'genre' => Request::input('g'), 'language' => Request::input('l'), 'extra' => array_filter(explode('-', Request::input('e')), 'strlen'), 'rank' => array_filter(explode('-', Request::input('r')), 'strlen'), 'page' => Request::input('page'), 'sort' => explode('_', Request::input('sort'))]; if (!$current_user->isSupporter()) { unset($params['rank']); } } $params = array_filter($params, function ($v, $k) { if (is_array($v)) { return !empty($v); } else { return presence($v) !== null; } }, ARRAY_FILTER_USE_BOTH); $beatmaps = Beatmapset::search($params); return json_collection($beatmaps, new BeatmapsetTransformer(), 'beatmaps'); }
public function show($id) { $user = User::lookup($id); if ($user === null || !$user->hasProfile()) { abort(404); } if ((string) $user->user_id !== $id) { return ujs_redirect(route('users.show', $user)); } $achievements = json_collection(Achievement::achievable()->orderBy('grouping')->orderBy('ordering')->orderBy('progression')->get(), new AchievementTransformer()); $userArray = json_item($user, new UserTransformer(), ['userAchievements', 'allRankHistories', 'allScores', 'allScoresBest', 'allScoresFirst', 'allStatistics', 'beatmapPlaycounts', 'page', 'recentActivities', 'recentlyReceivedKudosu', 'rankedAndApprovedBeatmapsets.beatmaps', 'favouriteBeatmapsets.beatmaps']); return view('users.show', compact('user', 'userArray', 'achievements')); }
public function userEntries($user = null) { if ($user === null) { return []; } return json_collection(UserContestEntry::where(['contest_id' => $this->id, 'user_id' => $user->user_id])->get(), new UserContestEntryTransformer()); }
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 json_collection($beatmaps->with('set', 'difficulty', 'difficultyAttribs')->get(), new BeatmapTransformer()); }
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] = json_collection($scores, new ScoreTransformer(), 'beatmap,beatmapset'); } return $all; }); }
public static function listing() { return json_collection(static::all(), new GenreTransformer()); }
public function favourites() { $favourites = Auth::user()->favouriteBeatmapsets(); return json_collection($favourites->get(), new BeatmapsetTransformer()); }
function json_item($model, $transformer, $includes = null) { return json_collection([$model], $transformer, $includes)[0]; }