示例#1
0
 public function update(RankRequest $request, $id, User $user)
 {
     $rank = Rank::findOrFail($id);
     $log = new Log();
     $log->user_id = $user->id;
     $log->log = "编辑等级" . print_r($rank->toArray(), true);
     $rank->fill($request->all());
     $rank->save();
     $log->save();
     return redirect()->action('RankController@index');
 }
 /**
  * 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'));
     }
 }