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); } }); }
/** * Execute the job. * * @return void */ public function handle() { DB::transaction(function () { $registration = UserConference::find($this->registrationId); $currentFlight = $registration->flight; if (!isset($currentFlight)) { return; } $others = Flight::where('flightNumber', $currentFlight->flightNumber)->where('airline', $currentFlight->airline)->where('arrivalDate', $currentFlight->arrivalDate)->where('arrivalTime', $currentFlight->arrivalTime)->where('airport', $currentFlight->airport)->where('id', '<>', $currentFlight->id)->get(); foreach ($others as $otherFlight) { UserConference::where('flightID', $otherFlight->id)->update(['flightID' => $currentFlight->id]); $otherFlight->delete(); } }); }
public static function getAccountRegistrationData($conferenceId, $account = null) { if (is_null($account)) { $account = Auth::user(); } //If no user is logged in, return an empty list if (is_null($account)) { return []; } $accountId = $account->id; $attendances = UserConference::where("conferenceID", $conferenceId)->whereHas("user", function ($query) use($accountId) { $query->where("accountID", $accountId); })->get(); $attendees = []; foreach ($attendances as $a) { $attendanceInventory = UserInventory::with('inventory')->whereHas('inventory', function ($query) use($conferenceId) { $query->where('conferenceID', $conferenceId); })->where('userID', $a->userID)->get()->toArray(); $attendees[] = ["user" => $a->userID, "userData" => $a->user, "status" => $a->approved ? "approved" : "pending", "id" => $a->id, "flight" => $a->flight, "room" => $a->room()->with('roomSet.residence', 'roomSet.type')->get()->toArray(), "userTransportation" => $a->userTransportation()->with('transportation')->get()->toArray(), "userInventory" => $attendanceInventory]; } return $attendees; }
/** * Replaces a given conference with the new values, given valid json. */ public function replace(Request $req, $id) { if (!Entrust::can(PermissionNames::ConferenceInfoEdit($id))) { return response("", 403); } $this->validateConferenceJson($req); $conf = Conference::find($id); if (is_null($conf)) { return response("Conference {$id} does not exist.", 400); } $this->assignInputToConference($req, $conf); $conf->save(); Log::info("Conference info for " . $conf->conferenceName . " edited."); $recipientModels = UserConference::where('conferenceID', $id)->with('user.account')->get(); $recipients = []; foreach ($recipientModels as $model) { if ($model->user->account->receiveUpdates) { $recipients[] = $model->user->account->email; } else { Log::debug("Discarding {$model->user->account->email} as updates aren't enabled"); } } Log::info("Dispatching conference update for " . sizeof($recipients) . " recipients"); $this->dispatch(new SendUpdateEmail("Conference Updated", "update-notification", ['typestr' => 'conference', 'name' => $conf->conferenceName, 'link' => config('app.url') . '/dashboard/conferences/list'], $recipients)); return ''; }
public function missingAssignments($confId) { if (!Entrust::can(PermissionNames::ConferenceRoomEdit($confId))) { return response("", 403); } return UserConference::where("needsAccommodation", true)->has("room", "<", 1)->where('conferenceID', $confId)->with("user")->get(); }
public function transportSummary($confId, Request $req) { if (!Entrust::can(PermissionNames::ConferenceTransportationEdit($confId))) { return response()->json(['message' => 'cannot_manage_transport'], 403); } if (!$this->isValidConference($confId)) { return response()->json(['message' => 'conference_not_found'], 404); } $userConfs = UserConference::where('needsTransportation', '=', true)->where('conferenceID', $confId)->where('approved', 1)->with(array('user' => function ($q) { $q->select('id', 'firstName', 'lastName', 'accountID'); }))->with('userTransportation'); $transports = []; foreach ($userConfs->get() as &$userConf) { $ut = $userConf->userTransportation; if ($ut != null) { $transport = Transportation::where('id', $ut->transportationID)->first(); $transports[$transport->id] = $transport; } } $flightsList = $userConfs->distinct()->lists('flightID'); $flights = Flight::whereIn('id', $flightsList)->get()->keyBy('id')->toArray(); $conference = Conference::where('id', $confId)->get()->toArray(); $summary = $this->buildSummaryJson($conference, $flights, $userConfs->get()->toArray(), $transports); return response()->json($summary, 200); }