示例#1
0
 public function approveVolunteer($volunteerId)
 {
     try {
         Volunteer::where('userId', $volunteerId)->update(['isVerified' => true]);
     } catch (\Exception $e) {
         return array('error' => ['message' => 'Error in updating object', 'code' => 101]);
     }
     return response()->json(['result' => 'success']);
 }
 /**
  * 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'));
     }
 }