Пример #1
0
 public function show($match_id)
 {
     $match = Match::findOrFail($match_id);
     $match = json_item($match, new MatchTransformer());
     $full = Request::input('full', false);
     return view('multiplayer.match', compact('match', 'full'));
 }
Пример #2
0
 public function show($id)
 {
     $beatmapset = Beatmapset::with('beatmaps.failtimes', 'user')->findOrFail($id);
     $set = json_item($beatmapset, new BeatmapsetTransformer(), ['beatmaps', 'beatmaps.failtimes', 'converts', 'converts.failtimes', 'user', 'description', 'ratings']);
     $countries = json_collection(Country::all(), new CountryTransformer());
     $title = trans('layout.menu.beatmaps._') . ' / ' . $beatmapset->artist . ' - ' . $beatmapset->title;
     return view('beatmapsets.show', compact('set', 'title', 'countries'));
 }
Пример #3
0
 public function defaultJson($currentUser = null)
 {
     $includes = ['beatmap_discussions.beatmap_discussion_posts', 'users'];
     if ($currentUser !== null) {
         $includes[] = "beatmap_discussions.current_user_attributes:user_id({$currentUser->user_id})";
     }
     return json_item(static::with(['beatmapDiscussions.beatmapDiscussionPosts', 'beatmapDiscussions.beatmapDiscussionVotes'])->find($this->id), new BeatmapsetDiscussionTransformer(), $includes);
 }
Пример #4
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;
     });
 }
Пример #5
0
 public function update($id)
 {
     $cover = ForumCover::findOrFail($id);
     if (Request::hasFile('cover_file') === true) {
         try {
             $cover = $cover->updateFile(Request::file('cover_file')->getRealPath(), Auth::user());
         } catch (ImageProcessorException $e) {
             return error_popup($e->getMessage());
         }
     }
     return json_item($cover, new ForumCoverTransformer());
 }
Пример #6
0
 public function show($id)
 {
     $forum = Forum::with('subForums')->findOrFail($id);
     $sort = explode('_', Request::input('sort'));
     $withReplies = Request::input('with_replies', '');
     priv_check('ForumView', $forum)->ensureCan();
     $cover = json_item($forum->cover()->firstOrNew([]), new ForumCoverTransformer());
     $pinnedTopics = $forum->topics()->pinned()->orderBy('topic_type', 'desc')->recent()->get();
     $topics = $forum->topics()->normal()->recent(compact('sort', 'withReplies'))->paginate(15);
     $topicReadStatus = TopicTrack::readStatus(Auth::user(), $pinnedTopics, $topics);
     return view('forum.forums.show', compact('forum', 'topics', 'pinnedTopics', 'topicReadStatus', 'cover'));
 }
Пример #7
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]);
 }
Пример #8
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]);
 }
Пример #9
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];
 }
Пример #10
0
 public function defaultJson($currentUser = null)
 {
     $includes = ['beatmaps'];
     if ($currentUser !== null) {
         $includes[] = "nominations:user_id({$currentUser->user_id})";
     } else {
         $includes[] = 'nominations';
     }
     return json_item($this, new BeatmapsetTransformer(), $includes);
 }
Пример #11
0
 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'));
 }
Пример #12
0
 public function defaultJson($user = null)
 {
     $includes = ['entries'];
     if ($this->type === 'art') {
         $includes[] = 'entries.artMeta';
     }
     if ($this->show_votes) {
         $includes[] = 'entries.results';
     }
     $contestJson = json_item($this, new ContestTransformer(), $includes);
     if (!empty($contestJson['entries'])) {
         if ($this->show_votes) {
             // Sort results by number of votes desc
             usort($contestJson['entries'], function ($a, $b) {
                 if ($a['results']['votes'] === $b['results']['votes']) {
                     return 0;
                 }
                 return $a['results']['votes'] > $b['results']['votes'] ? -1 : 1;
             });
         } else {
             // We want the results to appear randomized to the user but be
             // deterministic (i.e. we don't want the rows shuffling each time
             // the user votes), so we seed based on user_id
             $seed = $user ? $user->user_id : time();
             seeded_shuffle($contestJson['entries'], $seed);
         }
     }
     return json_encode(['contest' => $contestJson, 'userVotes' => $this->votesForUser($user)], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
 }
Пример #13
0
 public function show($id)
 {
     $postStartId = Request::input('start');
     $postEndId = get_int(Request::input('end'));
     $nthPost = get_int(Request::input('n'));
     $skipLayout = Request::input('skip_layout') === '1';
     $jumpTo = null;
     $topic = Topic::with(['forum.cover', 'pollOptions.votes'])->findOrFail($id);
     priv_check('ForumView', $topic->forum)->ensureCan();
     $posts = $topic->posts();
     if ($postStartId === 'unread') {
         $postStartId = Post::lastUnreadByUser($topic, Auth::user());
     } else {
         $postStartId = get_int($postStartId);
     }
     if ($nthPost !== null) {
         $post = $topic->nthPost($nthPost);
         if ($post) {
             $postStartId = $post->post_id;
         }
     }
     if (!$skipLayout) {
         foreach ([$postStartId, $postEndId, 0] as $jumpPoint) {
             if ($jumpPoint === null) {
                 continue;
             }
             $jumpTo = $jumpPoint;
             break;
         }
     }
     if ($postStartId !== null && !$skipLayout) {
         // move starting post up by ten to avoid hitting
         // page autoloader right after loading the page.
         $postPosition = $topic->postPosition($postStartId);
         $post = $topic->nthPost($postPosition - 10);
         $postStartId = $post->post_id;
     }
     if ($postStartId !== null) {
         $posts = $posts->where('post_id', '>=', $postStartId);
     } elseif ($postEndId !== null) {
         $posts = $posts->where('post_id', '<=', $postEndId)->orderBy('post_id', 'desc');
     }
     $posts = $posts->take(20)->with('topic')->with('user.rank')->with('user.country')->with('user.supports')->get()->sortBy('post_id');
     if ($posts->count() === 0) {
         abort($skipLayout ? 204 : 404);
     }
     $postsPosition = $topic->postsPosition($posts);
     $pollSummary = PollOption::summary($topic, Auth::user());
     Event::fire(new TopicWasViewed($topic, $posts->last(), Auth::user()));
     $template = $skipLayout ? '_posts' : 'show';
     $cover = json_item($topic->cover()->firstOrNew([]), new TopicCoverTransformer());
     $isWatching = TopicWatch::check($topic, Auth::user());
     return view("forum.topics.{$template}", compact('cover', 'isWatching', 'jumpTo', 'pollSummary', 'posts', 'postsPosition', 'topic'));
 }
 // line item number
 $cat_count = (int) $cat_data[3];
 // number of items in category
 $cat_checksum = (int) $cat_data[4];
 // running total
 // grabs TSV slice of data based on category meta data
 $data_slice = array_slice($data, $cat_line, $cat_count);
 $output_xml_cat['catdex'][] = $cat_name;
 $output_xml_cat['category'][$cat_tag]['comment'] = android_xml_comments($cat_name);
 $output_xml_cat['category'][$cat_tag]['name'] = $cat_name;
 // add the category tag for each item in that TSV data slice
 foreach ($data_slice as $k => $item) {
     // add category to TSV row
     $output_tsv_arr[] = $item . "\t" . $cat_tag;
     // parse TSV row, add JSON object with category
     $json_details = json_item($item, $cat_tag);
     $output_json_arr[] = $json_details;
     // build XML line item
     $xml_details = android_xml_item($item);
     $xml_name = $json_details['ITEM'];
     $itemstag = strtolower($cat_tag);
     $detailstag = $itemstag . "_details";
     $output_xml_cat['category'][$cat_tag]['items'][] = addslashes($xml_name);
     $output_xml_cat['category'][$cat_tag]['details'][] = addslashes($xml_details);
     $output_xml_cat['category'][$cat_tag]['items_name'] = $itemstag;
     $output_xml_cat['category'][$cat_tag]['details_name'] = $detailstag;
     $total++;
 }
 // double check total processed with running totals
 if ($total != $cat_checksum) {
     exit("ERR: MISMATCH! in category: " . $cat_name);
Пример #15
0
 public function defaultJson()
 {
     return json_item($this, new UserTransformer(), 'userAchievements,defaultStatistics');
 }
Пример #16
0
 private function showUser($user)
 {
     return json_item($user, new UserTransformer(), 'defaultStatistics');
 }
Пример #17
0
 public function defaultJson($currentUser = null)
 {
     $includes = ['beatmaps', 'nominations'];
     return json_item($this, new BeatmapsetTransformer(), $includes);
 }
Пример #18
0
 public function defaultJson()
 {
     $includes = ['beatmap_discussions.beatmap_discussion_posts', 'users', 'beatmap_discussions.current_user_attributes'];
     return json_item(static::with(['beatmapDiscussions.beatmapDiscussionPosts', 'beatmapDiscussions.beatmapDiscussionVotes'])->find($this->id), new BeatmapsetDiscussionTransformer(), $includes);
 }