/** * Run the database seeds. * * @return void */ public function run() { $conferences = [['id' => 1, 'conferenceName' => 'Foo', 'dateStart' => '2016-01-01', 'dateEnd' => '2016-02-01', 'location' => 'Earth', 'description' => 'A test conference.', 'hasTransportation' => true, 'hasAccommodations' => false], ['id' => 2, 'conferenceName' => 'Bar', 'dateStart' => '2016-02-03', 'dateEnd' => '2016-02-05', 'location' => 'Earth', 'description' => 'A test conference number 2.', 'hasTransportation' => true, 'hasAccommodations' => true]]; foreach ($conferences as $conf) { $c = Conference::create($conf); $role = RoleCreate::AllConferenceRoles($c->id); Account::where('email', 'root@localhost')->get()->first()->attachRole($role); } }
private function roleListJson($roles) { $roleJson = []; $conferences = []; $events = []; foreach ($roles as $r) { if (PermissionNames::isConferencePermission($r->name)) { $conferences[] = PermissionNames::extractPermissionData($r->name)->idPart; } else { if (PermissionNames::isEventPermission($r->name)) { $events[] = PermissionNames::extractPermissionData($r->name)->idPart; } } } $eventData = Event::whereIn('id', $events)->get(); $conferenceData = Conference::whereIn('id', $conferences)->get(); $conferences = []; $events = []; foreach ($conferenceData as $conf) { $conferences[$conf->id] = $conf->conferenceName; } foreach ($eventData as $evt) { $events[$evt->id] = $evt->eventName; } foreach ($roles as $r) { $permData = PermissionNames::extractPermissionData($r->name); if (isset($r->displayName)) { $displayName = $r->displayName; } else { $wordified = str_replace("-", " ", $permData->namePart); $displayName = ucwords($wordified); } $retData = ["name" => $r->name, "displayName" => $displayName, "type" => "global"]; if (isset($permData->idPart)) { $retData["forId"] = $permData->idPart; if (PermissionNames::isConferencePermission($r->name)) { $retData['forName'] = $conferences[(string) $permData->idPart]; $retData['type'] = "conference"; } else { if (PermissionNames::isEventPermission($r->name)) { $retData['forName'] = $events[$permData->idPart]; $retData['type'] = "event"; } } } $roleJson[] = $retData; } return $roleJson; }
/** * Store a newly created resource in storage. * @param Request $request * @return Response */ public function store(Request $request, $id) { $conf = Conference::find($id); if (is_null($conf)) { return response("No conference for id {$id}.", 405); } if (!Entrust::can(PermissionNames::ConferenceEventCreate($id))) { return response("Permission not found", 403); } return DB::transaction(function () use($request, $id) { $event = new Event(); $event->eventName = $request->input('eventName'); $event->date = $request->input('date'); $event->location = $request->input('location'); $event->startTime = $request->input('startTime'); $event->endTime = $request->input('endTime'); $event->capacity = $request->input('capacity'); $event->description = $request->input('description'); $event->conferenceID = $id; $event->save(); $role = RoleCreate::AllEventRoles($event->id); $user = Auth::user(); $user->attachRole($role); return response()->json(['id' => $event->id]); }); }
function current_conference_published() { $id = get_current_conference_id(); $current_conference = Conference::find($id); return $current_conference->published; }
/** * Deletes a conference. */ public function delete($id) { if (!Entrust::can(PermissionNames::ConferenceInfoEdit($id))) { return response("", 403); } DB::transaction(function () use($id) { $events = Event::where('conferenceID', $id)->get(); $pnames = array_merge(PermissionNames::AllConferencePermissions($id), PermissionNames::ExclusiveConferencePermissions($id)); $evtIds = []; foreach ($events as $e) { $pnames = array_merge($pnames, PermissionNames::AllEventPermissions($e->id)); echo $e; $evtIds[] = $e->id; } Permission::whereIn('name', $pnames)->delete(); RoleCreate::deleteConferenceRoles($id); RoleCreate::deleteEventRoles($evtIds); Conference::destroy($id); }); Log::info("Conference with ID {$id} deleted"); return ''; }
public function removeRoom($room) { $conference = Conference::orderBy('id', 'desc')->first()->id; DB::table('timeslots')->where('room_code', $room)->where('conference_id', $conference)->delete(); return redirect()->route('room.index'); }
public function approved($conferenceId) { // TODO: add permission/role filter $conf = Conference::where('id', '=', $conferenceId)->first(); if ($conf === null) { return response()->json(['message' => 'conference_not_found'], 404); } else { $inventory = UserInventory::where('conferenceID', $conf->id)->where('approved', 1)->with('user')->with('inventory')->get(); return response()->json(['message' => 'returned_approved_inventory', 'inventory' => $inventory]); } }
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); }
public function store(Request $request) { if (Room::count() == 0) { flash()->error("You must add at least one room before creating\n a conference"); return back()->withInput(); } $this->validate($request, ['name' => 'required|min:5|max:255']); $first = $request['start_time']; $last = $request['end_time']; if (empty($first[0]) or empty($last[0])) { flash()->error("You must add a start time and an end time"); return back()->withInput(); } $conference = new Conference(); $conference->name = $request['name']; $conference->save(); $rooms = Room::where('available', true)->get(); $numDays = sizeOf($first); //start day loop from here if ($numDays == 1) { $times = []; $tStart = strtotime($first[0]); $tEnd = strtotime($last[0]); $tNow = $tStart; $i = 1; $times[0] = date("H:i", $tNow) . "\n"; while ($tNow < $tEnd) { $tNow = strtotime('+30 minutes', $tNow); $times[$i] = date("H:i", $tNow) . "\n"; $i = $i + 1; } foreach ($rooms as $room) { foreach ($times as $time) { $timeslot = new Timeslot(); $timeslot->day = 1; $timeslot->room_code = $room->code; $timeslot->conference_id = $conference->id; $timeslot->time = $time; $timeslot->save(); } } } else { for ($day = 1, $index = 0; $day < $numDays || $index < $numDays - 1; $day++, $index++) { $times = []; $tStart = strtotime($first[$index]); $tEnd = strtotime($last[$index]); $tNow = $tStart; $i = 1; $times[0] = date("H:i", $tNow) . "\n"; while ($tNow < $tEnd) { $tNow = strtotime('+30 minutes', $tNow); $times[$i] = date("H:i", $tNow) . "\n"; $i = $i + 1; } //$i os the number of timeslots foreach ($rooms as $room) { foreach ($times as $time) { $timeslot = new Timeslot(); $timeslot->day = $day; $timeslot->room_code = $room->code; $timeslot->conference_id = $conference->id; $timeslot->time = $time; $timeslot->save(); } } } } flash()->success("New conference created successfully!!"); return redirect()->route('user.show'); }
public function getAllConferences() { //automatically converts to json return Conference::all(); }