/** * Retrieves information for volunteer leaderboard. * * @param \Illuminate\Http\Request $request * @return JSON array with top 10 users and position */ public function volunteerLeaderboard(Request $request) { if ($request->get('token') != null) { $authenticatedUser = JWTAuth::setToken($request->get('token'))->authenticate(); $id = $authenticatedUser->volunteer_id; $volunteerEnquired = Volunteer::findOrFail($id); $volunteerName = $volunteerEnquired->name; // user rank $rankid = Volunteer::where('volunteer_id', $id)->value('rank_id'); $rank = Rank::findOrFail($rankid)->name; $totalMinutes = Volunteer::where('volunteer_id', $id)->value('minutes_volunteered'); $volunteerIdList = Volunteer::where('is_approved', 'approved')->orderBy('minutes_volunteered', 'desc')->lists('volunteer_id'); $count = 0; $xCount = 1; $pos = 0; $returnArray = []; $listSize = count($volunteerIdList) - 1; do { $volunteerID = $volunteerIdList[$count]; $volunteer = Volunteer::find($volunteerID); $volunteerName = $volunteer->name; $volunteerMinutes = $volunteer->minutes_volunteered; $stringToAdd = $volunteerMinutes . "," . $volunteerName . "," . $xCount; $returnArray[] = $stringToAdd; if ($id == $volunteerID) { $pos = $xCount; } $count = $count + 1; $xCount = $xCount + 1; } while ($count <= $listSize); return response()->json(compact('rank', 'totalMinutes', 'returnArray', 'pos')); } else { $status = ["Missing parameter"]; return response()->json(compact('status')); } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $v = Volunteer::find($id); $page = get_page_contents(); return view('volunteers.show', compact('v', 'page')); }