private function processRegistration($req, $conferenceID, $accountID) { return DB::transaction(function () use($req, $conferenceID, $accountID) { //Grab request data for use later $needsTransport = $req['needsTransportation']; $needsAccommodation = $req['needsAccommodation']; $attendees = $req['attendees']; //Check whether dependents are okay/owned by the current user if (!CheckDependents::dependentsOkay($attendees)) { return ["message" => "bad_attendee_listing", "code" => 400, "attendees" => $attendees]; } $existing = UserConference::where('conferenceID', $conferenceID)->whereIn('userID', $attendees)->count(); if ($existing > 0) { return ["message" => "already_registered", "code" => 400, "attendees" => $attendees]; } //If the request explicitly doesn't have a flight, just register attendees without one if (isset($req['hasFlight'])) { Log::debug("Attendees being registered without a flight."); if (!$req['hasFlight']) { return $this->registerAttendees($conferenceID, $attendees, $needsTransport, $needsAccommodation, null); } } $number = $req['flight']['number']; $arrivalDay = $req['flight']['arrivalDate']; $arrivalTime = $req['flight']['arrivalTime']; $airline = $req['flight']['airline']; $airport = $req['flight']['airport']; //Grab (checked) matching flights for airline/flight number/date $flights = Flight::where('flightNumber', $number)->where('airline', $airline)->where('arrivalDate', $arrivalDay)->where('isChecked', true)->get(); if (sizeof($flights) >= 1) { foreach ($flights as $row) { if ($row->arrivalTime == $arrivalTime && $row->airport == $airport) { Log::info("Attendees using {$row->airline} flight {$row->flightNumber} being registered using existing flight"); return $this->registerAttendees($conferenceID, $attendees, $needsTransport, $needsAccommodation, $row->id); } } return ["message" => "flight_data_mismatch", "code" => 400, "attendees" => $attendees]; } else { //Create a new flight with the given data $flight = new Flight(); $flight->flightNumber = $number; $flight->airline = $airline; $flight->arrivalDate = $arrivalDay; $flight->arrivalTime = $arrivalTime; $flight->airport = $airport; $flight->isChecked = false; $flight->save(); Log::info("Attendees using {$flight->airline} flight {$flight->flightNumber} being registered using new flight"); return $this->registerAttendees($conferenceID, $attendees, $needsTransport, $needsAccommodation, $flight->id); } }); }
/** * Register the user given the userID to the event given the eventID. * @param int $id, int $eventId * @return Response */ public function register(Request $req, $id) { $event = Event::find($id); if (is_null($event)) { return response()->json(["message" => "no_such_event"], 404); } $this->validateInputIDs($req); $idList = $req->input('ids'); if (!CheckDependents::dependentsOkay($idList)) { return response()->json(["message" => "bad_dependents"], 400); } if (!$this->checkConferenceAttendees($id, $idList)) { return response()->json(["message" => "not_in_conference"], 400); } $eventUser = UserEvent::where('eventID', $id)->whereIn('userID', $idList)->get(); if (count($eventUser) > 0) { return response()->json(["message" => "already_registered"], 400); } $data = array_map(function ($userId) use($id) { return ["userID" => $userId, "eventID" => $id]; }, $idList); UserEvent::insert($data); return UserEvent::select(["id", "userID"])->whereIn("userID", $idList)->get(); }