/** * Handles the withdrawal of activity from user. * * @param \Illuminate\Http\Request $request * @return JSON array with Status */ public function withdraw(Request $request) { if ($request->get('volunteer_id') == null || $request->get('activity_id') == null) { $status = ["Missing parameter"]; return response()->json(compact('status')); } else { $volunteer_id = $request->get('volunteer_id'); $activity_id = $request->get('activity_id'); $volunteer = Volunteer::findOrFail($volunteer_id); $withdrawnActivity = Activity::findOrFail($activity_id); $task = Task::where('volunteer_id', $volunteer_id)->where('activity_id', $activity_id)->update(['approval' => 'withdrawn']); $mailingList = Staff::where('is_admin', 'TRUE')->lists('email')->toArray(); $status = ["Withdrawn from activity"]; Mail::send('emails.volunteer_withdraw', compact('volunteer', 'withdrawnActivity'), function ($message) use($mailingList) { $message->subject('A volunteer has withdrawn from an activity'); $message->to($mailingList); }); return response()->json(compact('status')); } }
/** * 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')); } }
/** * Approve a given volunteer account. * Responds to requests to PATCH /volunteers/{id}/approve * * @param int $id the ID of the volunteer * @return Response */ public function approveVolunteer($id) { $volunteer = Volunteer::findOrFail($id); if ($volunteer->is_approved !== 'approved') { $volunteer->is_approved = 'approved'; $volunteer->save(); $email = $volunteer->email; Mail::send('emails.volunteer_approval', compact('volunteer'), function ($message) use($email) { $message->subject('Your CareGuide Volunteer account has been approved.'); $message->bcc($email); }); return back()->with('success', 'Volunteer is approved!'); } else { return back()->with('error', 'Volunteer is ' . $volunteer->is_approved . 'already!'); } }