/**
  * update an user
  * @param $id
  * @param array $data
  * @return mixed
  */
 public function update($id, array $data)
 {
     $user = $this->model->findOrFail($id)->update($data);
     if (isset($data['profile'])) {
         $this->model->findOrFail($id)->profile()->update($data['profile']);
     }
     return $user;
 }
Example #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $event = Event::findOrFail($id);
     $event->delete();
     \Flash::success('Agenda evenement verwijderd');
     return redirect('admin/events');
 }
 public function update($id, EventRequest $request)
 {
     $event = Event::findOrFail($id);
     $event->update($request->all());
     flash()->message('Successfully updated event: ' . $event->name, 'success');
     return redirect()->route('admin.events.edit', $event->id);
 }
Example #4
0
 /**
  * Page for the users' entries.
  * @return mixed
  */
 public function userEntries()
 {
     $user = Auth::user();
     $event_ids = $user->entries()->pluck('event_id')->unique();
     $eventsarray = array();
     foreach ($event_ids as $event_id) {
         $eventsarray[] = Event::findOrFail($event_id);
     }
     $events = collect($eventsarray);
     return view('user.entries')->with(['user' => $user, 'events' => $events]);
 }
 /**
  * Delete a detail
  * @param Request $request
  * @param $id
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function destroy(Request $request, $id)
 {
     $event = Event::find($request->input('event'));
     $detail = Detail::find($id);
     if ($detail && $event->user_id == $request->user()->id) {
         $detail->delete();
         //Flash a message to the user
         \Flash::success('Detail deleted');
     } else {
         //Flash a message to the user
         \Flash::danger('Sorry, permission denied');
     }
     $event = Event::findOrFail($request->input('event'));
     //Redirect back to the admin page
     return redirect(action('EventsController@admin', $event->slug));
 }
 public function buyTicket()
 {
     if (\Request::ajax()) {
         $event_id = (int) \Request::get('event_id');
         $event = Event::findOrFail($event_id);
         $ticket = [];
         $ticket['price'] = round($event->price * \Request::get('quantity'), 2);
         $ticket['raw_price'] = round($event->price * \Request::get('quantity'), 2);
         $ticket['quantity'] = \Request::get('quantity');
         if (\Request::get('promocode') === $event->promocode) {
             $ticket['price'] = round($ticket['price'] - $event->discount, 2);
         }
         $user = \Request::user();
         $ticket = $user->tickets()->create($ticket);
         $ticket->event()->associate($event)->save();
         return \Response::json(['status' => 'success']);
     }
     return \Response::json(['status' => 'error'], 400);
 }
 public function register($id)
 {
     $event = Event::findOrFail($id);
     if ($event->flash_message) {
         $_SESSION['ALERT'] = alert("Event Notice!", $event->flash_message, "warning");
     }
     $score = new Score();
     $score->event_id = $event->id;
     $score->player_id = Auth::user()->id;
     $score->save();
     if (!Auth::user()->no_email) {
         $subject = 'Event Registration';
         Mail::send('emails.registered', compact('subject', 'event'), function ($m) use($subject) {
             $m->to(Auth::user()->email)->subject($subject);
         });
     }
     return redirect('/');
 }
Example #8
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     //        $router->model('user' , 'App\User');
     $router->bind('user', function ($value) {
         return User::with('roles')->findOrFail($value);
     });
     /**
      * created by dara on 6/9/2015
      * add binding for admin wild card
      */
     $router->bind('admin', function ($value) {
         return User::with('roles')->findOrFail($value);
     });
     /**
      * Created by Emad Mirzaie on 09/09/2015.
      * province wild cart
      */
     $router->model('province', 'App\\Province');
     $router->model('city', 'App\\Province');
     $router->model('university', 'App\\University');
     $router->model('article', 'App\\Article');
     $router->model('post', 'App\\Post');
     $router->model('category', 'App\\Category');
     $router->model('sub_category', 'App\\Category');
     $router->model('skill', 'App\\Skill');
     $router->model('profile', 'App\\User');
     $router->model('comment', 'App\\Comment');
     $router->model('poll', 'App\\Poll');
     $router->model('questionnaire', 'App\\Questionnaire');
     $router->model('coupon_user', 'App\\CouponUser');
     $router->model('showcase', 'App\\Showcase');
     $router->model('sticky', 'App\\Sticky');
     /**
      * Created By Dara on 22/10/2015
      */
     //        $router->bind('offer',function($value){
     //            return Offer::findOrFail($value);
     //        });
     $router->bind('service', function ($value) {
         return CouponGallery::findOrFail($value);
     });
     $router->bind('coupon', function ($value) {
         return Coupon::findOrFail($value);
     });
     $router->bind('group', function ($value) {
         return Group::findOrFail($value);
     });
     $router->bind('problem', function ($value) {
         return Problem::findOrFail($value);
     });
     $router->model('offer', 'App\\Offer');
     $router->model('shop', 'App\\Shop');
     $router->model('product', 'App\\Product');
     $router->bind('event', function ($value) {
         return Event::findOrFail($value);
     });
     $router->bind('settle', function ($value) {
         return Settle::findOrFail($value);
     });
     $router->bind('report', function ($value) {
         return Report::findOrFail($value);
     });
     $router->bind('corporation', function ($value) {
         return Corporation::findOrFail($value);
     });
     /**
      * Created By Dara on 25/12/2015
      */
     $router->bind('announcement', function ($value) {
         return Announcement::findOrFail($value);
     });
     $router->bind('storage', function ($value) {
         return Storage::findOrFail($value);
     });
     $router->bind('role', function ($value) {
         return Role::findOrFail($value);
     });
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param EventRequest $request
  * @param $eventId
  * @return \Illuminate\Http\JsonResponse
  */
 public function destroy(EventRequest $request, $eventId)
 {
     Event::findOrFail($eventId)->delete();
     return $this->response->noContent();
 }
Example #10
0
 /**
  * Toggle the online
  * @param $id
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function toggle($id)
 {
     //Get the event by ID
     $item = Event::findOrFail($id);
     //Toggle the online property
     $item->online = !$item->online;
     $item->update();
     return redirect('event');
 }
 public function destroy($id)
 {
     $event = Event::findOrFail($id);
     $event->delete();
     return Response::json([], 200);
 }
Example #12
0
 /**
  * Creates a ticket for the event for the logged-in user, or if the user
  * already has a ticket, return theirs.
  *
  * @param  Integer 	$eventId 	ID of the event for the ticket.
  * @return View 		        Ticket View
  */
 public function store()
 {
     $data = Request::only(["event_id", "stripeToken"]);
     try {
         $event = Event::findOrFail($data["event_id"]);
     } catch (ModelNotFoundException $e) {
         return Redirect::back()->withErrors(['message' => $this->errorMessages['event_not_found']]);
     }
     $user = Auth::user();
     if (Ticket::where('event_id', $event->id)->where('user_id', $user->id)->get()->toArray()) {
         return Redirect::back()->withErrors(["message" => $this->errorMessages['ticket_exists']]);
     }
     if ($event->price > 0) {
         // If the ticket ain't free you're going to have to pay for it.
         // Let's Stripe.
         Stripe::setApiKey(env('STRIPE_SECRET'));
         try {
             // Create a reference for a Customer relating to the Stripe token we received
             $customer = Customer::create(["email" => $user->email, "card" => $data["stripeToken"]]);
             // Now, charge that customer for the ticket as expected.
             $charge = Charge::create(["customer" => $customer->id, "amount" => $event->price * 100, "currency" => "eur"]);
         } catch (Error\Card $e) {
             return Redirect::back()->withErrors(["message" => $this->errorMessages['card_declined']]);
         } catch (Error\RateLimit $e) {
             return \Redirect::back()->withErrors(["message" => $this->errorMessages['server_error']]);
         } catch (Error\InvalidRequest $e) {
             dd($e);
             return Redirect::back()->withErrors(["message" => $this->errorMessages['dev_mistake']]);
         } catch (Error\Authentication $e) {
             return Redirect::back()->withErrors(["message" => $this->errorMessages['dev_mistake_auth']]);
         } catch (Error\ApiConnection $e) {
             return Redirect::back()->withErrors(["message" => $this->errorMessages['network_error']]);
         } catch (Error\Base $e) {
             // I actually don't know what this error means
             // or what it does, so probably panic
             return Redirect::back()->withErrors(["message" => $this->errorMessages['something_wrong']]);
         }
         $ticket = Ticket::create(["user_id" => $user->id, "event_id" => $event->id, "price" => $event->price, "used" => false, "printed" => false, "charge_id" => $charge->id]);
     } else {
         $ticket = Ticket::create(["user_id" => $user->id, "event_id" => $event->id, "price" => $event->price, "used" => false, "printed" => false, "charge_id" => null]);
     }
     MailController::sendTicket($ticket);
     return Redirect::back()->with('message', "You've got a ticket! Find your details and print it out here.");
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function destroy($id)
 {
     /** @var Event $event */
     $event = Event::findOrFail($id);
     if ($event->date < Carbon::now()) {
         Flash::error('Este evento ya ocurrió, no puede ser eliminado.');
         return Redirect::route('events.show', $id);
     }
     if ($this->destroyPrototype($event, 'delete', 'Evento', 'Involucrados')) {
         return Redirect::route('events.index');
     }
     return Redirect::route('events.show', $id);
 }
Example #14
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['description' => 'string', 'end_date' => 'date', 'featured' => 'boolean', 'group' => 'exists:groups,id', 'image' => 'string', 'location' => 'string', 'name' => 'string', 'recurrence' => 'string', 'short_description' => 'string', 'short_name' => 'string', 'start_date' => 'date']);
     try {
         $event = Event::findOrFail($id);
         $event->description = $request->input('description', $event->description);
         $event->end_date = $request->input('end_date', $event->end_date);
         $event->featured = $request->input('featured', $event->featured);
         $event->group_id = $request->input('group', $event->group_id);
         $event->image = $request->input('image', $event->image);
         $event->location = $request->input('location', $event->location);
         $event->name = $request->input('name', $event->name);
         $event->recurrence = $request->input('recurrence', $event->recurrence);
         $event->short_description = $request->input('short_description', $event->short_description);
         $event->short_name = $request->input('short_name', $event->short_name);
         $event->start_date = $request->input('start_date', $event->start_date);
         $event->save();
         return new JsonResponse($event, Response::HTTP_CREATED);
     } catch (ModelNotFoundException $e) {
         return new JsonResponse(['error' => 'not found'], Response::HTTP_NOT_FOUND);
     }
 }
Example #15
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function update($id, Request $request)
 {
     $event = Event::findOrFail($id);
     $event->title = $request->title;
     $event->intro = $request->intro;
     $event->description = $request->description;
     $event->vortex_url = $request->vortex_url;
     $event->facebook_id = $request->facebook_id;
     $event->start_date = new Carbon($request->start_date);
     $event->location = $request->location;
     if (!$request->youtube_playlist_id) {
         $event->youtube_playlist_id = null;
     } else {
         $youtubePlaylist = YoutubePlaylist::find($request->youtube_playlist_id);
         $event->youtube_playlist_id = $youtubePlaylist->id;
     }
     $event->save();
     // Organizers: TODO
     $p1 = $event->presentations[0];
     $p1->start_time = $request->p1_start_time;
     $p1->end_time = $request->p1_end_time;
     // ...
     $p1->save();
     if ($request->has('p1_person1')) {
         // TODO
     }
     if ($request->has('p1_youtube_id')) {
         $recording = Recording::where('presentation_id', '=', $p1->id)->first();
         if (!is_null($recording)) {
             if ($recording->id != $request->p1_youtube_id) {
                 $recording->presentation_id = null;
             }
         }
         $recording = Recording::where('youtube_id', '=', $request->p1_youtube_id)->first();
         if (is_null($recording)) {
             die("TODO: Video not found, redirect back with meaningful error message");
         }
         $recording->presentation_id = $p1->id;
         $recording->save();
     }
     return redirect()->action('EventsController@show', $event->id)->with('status', 'Arrangementet ble oppdatert.');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $event = Event::findOrFail($id);
     if (Gate::allows('manage', $event)) {
         Event::destroy($id);
         return redirect('events');
     } else {
         return abort(403);
     }
 }
Example #17
0
 /**
  * Update the specified event in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     $event = Event::findOrFail($id);
     $event->name = $request->name;
     $event->description = $request->description;
     $convert_date = date("Y-m-d", strtotime($request->date_start));
     $event->date_start = $convert_date;
     if ($request->date_end) {
         $convert_date = date("Y-m-d", strtotime($request->date_end));
         $event->date_end = $convert_date;
     }
     if ($request->id != null) {
         $place = Place::where('id', '=', $request->id)->first();
         if (!$place) {
             $place = new Place($request->only(['id', 'place_lat', 'place_lng', 'country', 'state', 'city']));
             $place->save();
         }
         $event_place = EventPlace::where('event_id', '=', $id);
         if (!$event_place) {
             $event_place = new EventPlace();
             $event_place->event_id = $id;
             $event_place->place_id = $place->id;
             $event_place->save();
         }
     }
     if (\Input::hasFile('img')) {
         $file = \Input::file('img');
         $filename = '';
         if ($event->photo == '../../default_photo.jpg') {
             $name = str_random(32);
             while (!User::where('avatar', '=', $name . $file->getClientOriginalExtension())->get()->isEmpty()) {
                 $name = str_random(32);
             }
             $filename = $name . '.' . $file->getClientOriginalExtension();
             $event->photo = $filename;
         } else {
             $filename = $event->photo;
         }
         $file->move(public_path() . '/img/events_large', $filename);
         Image::make(public_path() . '/img/events_large/' . $filename)->fit(1024, 576)->save();
         Image::make(public_path() . '/img/events_large/' . $filename)->resize(300, 169)->save(public_path() . '/img/events/' . $filename);
     }
     $event->save();
     \Session::flash('message', 'Event updated successfully');
     return redirect()->route('events.show', $id);
 }
Example #18
0
 /**
  * If the entry is cancelled by the user at paypal login page.
  */
 public function postPaypalCancelled(Request $request, $event_id)
 {
     $user = Auth::user();
     $entries_to_delete = $user->eventEntries($event_id);
     foreach ($entries_to_delete as $entry) {
         $entry->delete();
     }
     \Flash::info("We're sorry you changed your mind and cancelled your payment (your entry to this event was *not* completed). We've brought you back to the event entry page in case you still want to enter.");
     $event = Event::findOrFail($event_id);
     return redirect(action('EventsController@show', $event->slug));
 }
Example #19
0
 /**
  * Export list of competitors and competitions
  */
 public function export($type, $id)
 {
     $header = array('Competitor name', 'ID', 'Email', 'Club', 'Home Country');
     if ($type == 'competitors') {
         $event = Event::findOrFail($id);
         $entries = $event->entries()->get()->sortBy('user_lastname');
         $competitor_ids = $entries->pluck('user_id')->unique();
         $competitions = $event->competitions()->get();
         $header = array();
         foreach ($competitions as $competition) {
             $header[] = $competition->name;
         }
         $sheetdata = array($header);
         foreach ($competitor_ids as $competitor_id) {
             $competitorEntries = $event->entries()->get()->where('user_id', $competitor_id);
             $thisCompetitor = User::findOrFail($competitor_id);
             $name = $thisCompetitor->lastname . ", " . $thisCompetitor->firstname;
             $row = array($name);
             foreach ($competitions as $competition) {
                 $entered_competition_ids = array();
                 foreach ($competitorEntries as $entry) {
                     $entered_competition_ids[] = $entry->competition_id;
                 }
                 if (in_array($competition->id, $entered_competition_ids)) {
                     $row[] = "Entered";
                 } else {
                     $row[] = "";
                 }
             }
             $sheetdata[] = $row;
         }
         Excel::create('competitors', function ($excel) use($sheetdata) {
             $excel->setTitle('Competitors List');
             $excel->setCreator('Foresight Entries');
             $excel->setCompany('Foresightentries.com');
             $excel->setDescription('Competitors list');
             // Create the sheet
             $excel->sheet('Competitors', function ($sheet) use($sheetdata) {
                 $sheet->fromArray($sheetdata);
             });
         })->export('xlsx');
         return redirect()->back();
     }
     // Download ALL the data in one mega spreadsheet (for the overview tab)
     if ($type == 'event') {
         $event = Event::findOrFail($id);
         $competitions = $event->competitions()->get();
         $megaheader = $header;
         $sheets = array();
         //Sheet showing all competitors, their entries, their answers, extras and how much paid
         // -- HEADERS --
         // ---- competitions --
         foreach ($event->competitions()->get() as $competition) {
             $megaheader[] = $competition->name;
         }
         // ---- questions --
         foreach ($event->questions()->get() as $question) {
             $megaheader[] = $question->question;
         }
         // ---- extras --
         foreach ($event->extras()->get() as $extra) {
             //fill in once extras is worked out
         }
         // ---- financial --
         $megaheader[] = "Entry fees (total)";
         //MEGASHEET INITIALISE
         $megasheet = array($megaheader);
         // DATA ENTRY TO MEGASHEET
         $entries = $event->entries()->get()->sortBy('user_lastname');
         $competitor_ids = $entries->pluck('user_id')->unique();
         foreach ($competitor_ids as $competitor_id) {
             $thisCompetitor = User::findOrFail($competitor_id);
             $row = array($thisCompetitor->firstname . " " . $thisCompetitor->lastname, $thisCompetitor->id + 1000, $thisCompetitor->email, $thisCompetitor->club, $thisCompetitor->homeCountry);
             // -- ENTRIES --
             $competitorEntries = $event->entries()->get()->where('user_id', $competitor_id);
             $competitorEntriesCompetitionIDs = array();
             foreach ($competitorEntries as $entry) {
                 $competitorEntriesCompetitionIDs[$entry->competition_id] = $entry->competition_id;
             }
             foreach ($event->competitions()->get() as $competition) {
                 // if entry->competition_id exists in $competitorEntries then entered row, else empty row.
                 if (key_exists($competition->id, $competitorEntriesCompetitionIDs)) {
                     $row[] = "x";
                 } else {
                     $row[] = " ";
                 }
             }
             // -- ANSWERS --
             $competitorAnswers = $event->answers()->get()->where('competitor_id', $competitor_id);
             $competitorAnsweredQuestionIDs = array();
             foreach ($competitorAnswers as $answer) {
                 $competitorAnsweredQuestionIDs[$answer->question_id] = $answer->question_id;
             }
             //@TODO: this needs to be tested with a user who has answered questions. 5/7/16
             foreach ($competitorAnswers as $competitorAnswer) {
                 if (key_exists($competitorAnswer->question_id, $competitorAnsweredQuestionIDs)) {
                     $row[] = $competitorAnswer->answer;
                 } else {
                     $row[] = "N/A";
                 }
             }
             // -- EXTRAS --
             //@TODO: fill in once extras is worked out
             // -- ENTRY FEES TOTAL --
             $row[] = "subtotal here (£)";
             // Add the row to the megasheet
             $megasheet[] = $row;
         }
         //Add the megasheet to sheets
         $sheets["Competitors"] = $megasheet;
         //Sheet for each competition and detail with the entries
         foreach ($competitions as $competition) {
             $details = $competition->details()->get();
             foreach ($details as $detail) {
                 $entries = $detail->entries()->get()->sortBy('user_lastname');
                 $sheetdata = array($header);
                 $competitor_ids = $entries->pluck('user_id')->unique();
                 foreach ($competitor_ids as $competitor_id) {
                     $competitor = User::findOrFail($competitor_id);
                     $row = array($competitor->firstname . " " . $competitor->lastname, $competitor->id + 1000, $competitor->email, $competitor->club, $competitor->homeCountry);
                     $sheetdata[] = $row;
                 }
                 $sheets[$competition->name . "-" . $detail->name] = $sheetdata;
             }
         }
         Excel::create($event->name, function ($excel) use($sheets, $competitions) {
             $excel->setTitle('Competitors');
             $excel->setCreator('Foresight Entries');
             $excel->setCompany('ForesightEntries.com');
             $excel->setDescription('Competitors List');
             $infosheet = $sheets["Competitors"];
             $excel->sheet('Competitors', function ($sheet) use($infosheet) {
                 $sheet->fromArray($infosheet);
             });
             foreach ($competitions as $competition) {
                 $details = $competition->details()->get();
                 foreach ($details as $detail) {
                     $sheet = $sheets[$competition->name . '-' . $detail->name];
                     $excel->sheet($competition->name . '-' . $detail->name, function ($thissheet) use($sheet) {
                         $thissheet->fromArray($sheet);
                     });
                 }
             }
         })->export('xlsx');
         return redirect()->back();
     }
     if ($type == 'competition') {
         $competition = Competition::findOrFail($id);
         $details = $competition->details()->get();
         $sheets = array();
         foreach ($details as $detail) {
             $entries = $detail->entries()->get()->sortBy('user_lastname');
             $sheetdata = array($header);
             $competitor_ids = $entries->pluck('user_id')->unique();
             foreach ($competitor_ids as $competitor_id) {
                 $competitor = User::findOrFail($competitor_id);
                 $row = array($competitor->firstname . " " . $competitor->lastname, $competitor->id + 1000, $competitor->email, $competitor->club, $competitor->homeCountry);
                 $sheetdata[] = $row;
             }
             $sheets[$detail->name] = $sheetdata;
         }
         Excel::create($competition->name, function ($excel) use($sheets, $details) {
             $excel->setTitle('Competitors');
             $excel->setCreator('Foresight Entries');
             $excel->setCompany('ForesightEntries.com');
             $excel->setDescription('Competitors List');
             foreach ($details as $detail) {
                 $sheet = $sheets[$detail->name];
                 $excel->sheet($detail->name, function ($thissheet) use($sheet) {
                     $thissheet->fromArray($sheet);
                 });
             }
         })->export('xlsx');
         return redirect()->back();
     }
     if ($type == 'detail') {
         $detail = Detail::findOrFail($id);
         $entries = $detail->entries()->get()->sortBy('user_lastname');
         $sheetdata = array($header);
         $competitor_ids = $entries->pluck('user_id')->unique();
         foreach ($competitor_ids as $competitor_id) {
             $competitor = User::findOrFail($competitor_id);
             $row = array($competitor->firstname . " " . $competitor->lastname, $competitor->id + 1000, $competitor->email, $competitor->club, $competitor->homeCountry);
             $sheetdata[] = $row;
         }
         Excel::create($detail->competition()->first()->name . "-" . $detail->name, function ($excel) use($sheetdata) {
             $excel->setTitle('Competitors');
             $excel->setCreator("Foresight Entries");
             $excel->setCompany("ForesightEntries.com");
             $excel->setDescription("Competitors List");
             $excel->sheet('Competitors', function ($sheet) use($sheetdata) {
                 $sheet->fromArray($sheetdata);
             });
         })->export('xlsx');
         return redirect()->back();
     }
     if ($type == 'competitor_entries') {
         $event = Event::findOrFail($id);
         $entries = $event->entries()->get()->sortBy('user_lastname');
         $competitor_ids = $entries->pluck('user_id')->unique();
         //Add competition names to the header
         foreach ($event->competitions()->get() as $competition) {
             $header[] = $competition->name;
         }
         $sheetdata = array($header);
         foreach ($competitor_ids as $competitor_id) {
             $competitorEntries = $event->entries()->get()->where('user_id', $competitor_id);
             $competitorEntriesCompetitionIDs = array();
             foreach ($competitorEntries as $entry) {
                 $competitorEntriesCompetitionIDs[$entry->competition_id] = $entry->competition_id;
             }
             $thisCompetitor = User::findOrFail($competitor_id);
             $row = array($thisCompetitor->firstname . " " . $thisCompetitor->lastname, $thisCompetitor->id + 1000, $thisCompetitor->email, $thisCompetitor->club, $thisCompetitor->homeCountry);
             foreach ($event->competitions()->get() as $competition) {
                 // if entry->competition_id exists in $competitorEntries then entered row, else empty row.
                 if (key_exists($competition->id, $competitorEntriesCompetitionIDs)) {
                     $row[] = "x";
                 } else {
                     $row[] = " ";
                 }
             }
             $sheetdata[] = $row;
         }
         Excel::create("Competitor entries", function ($excel) use($sheetdata) {
             $excel->setTitle('Competitor_entries');
             $excel->setCreator("Foresight Entries");
             $excel->setCompany("ForesightEntries.com");
             $excel->setDescription("Competitors List");
             $excel->sheet('Competitor_entries', function ($sheet) use($sheetdata) {
                 $sheet->fromArray($sheetdata);
             });
         })->export('xlsx');
         return redirect()->back();
     }
     if ($type == 'competitor_answers') {
         $event = Event::findOrFail($id);
         $entries = $event->entries()->get()->sortBy('user_lastname');
         $competitors = $entries->pluck('user_id')->unique();
         //Add the questions to the header
         foreach ($event->questions()->get() as $question) {
             $header[] = $question->question;
         }
         $sheetdata = array($header);
         foreach ($competitors as $competitor) {
             $competitorAnswers = $event->answers()->get()->where('competitor_id', $competitor);
             $competitorAnsweredQuestionIDs = array();
             foreach ($competitorAnswers as $answer) {
                 $competitorAnsweredQuestionIDs[$answer->question_id] = $answer->question_id;
             }
             $thisCompetitor = User::findOrFail($competitor);
             $row = array($thisCompetitor->firstname . " " . $thisCompetitor->lastname, $thisCompetitor->id + 1000, $thisCompetitor->email, $thisCompetitor->club, $thisCompetitor->homeCountry);
             //@TODO: this needs to be tested with a user who has answered questions. 5/7/16
             foreach ($competitorAnswers as $competitorAnswer) {
                 if (key_exists($competitorAnswer->question_id, $competitorAnsweredQuestionIDs)) {
                     $row[] = $competitorAnswer->answer;
                 } else {
                     $row[] = "N/A";
                 }
             }
             $sheetdata[] = $row;
         }
         Excel::create("Competitor answers", function ($excel) use($sheetdata) {
             $excel->setTitle('Competitor_answers');
             $excel->setCreator("Foresight Entries");
             $excel->setCompany("ForesightEntries.com");
             $excel->setDescription("Competitor answers");
             $excel->sheet('Competitor_answers', function ($sheet) use($sheetdata) {
                 $sheet->fromArray($sheetdata);
             });
         })->export('xlsx');
         return redirect()->back();
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['name' => 'required|min:5|max:15', 'title' => 'required|min:5|max:100', 'time' => 'required|available|duration']);
     $time = explode(" - ", $request->input('time'));
     $event = Event::findOrFail($id);
     $event->name = $request->input('name');
     $event->title = $request->input('title');
     $event->start_time = $this->change_date_format($time[0]);
     $event->end_time = $this->change_date_format($time[1]);
     $event->save();
     return redirect('events');
 }
 /**
  * @param                                   $id
  * @param \App\Http\Requests\GenericRequest $request
  * @return \Illuminate\Support\Facades\Response
  */
 public function toggleVolunteer($id, GenericRequest $request)
 {
     // Require ajax
     $this->requireAjax($request);
     // Get the event
     $event = Event::findOrFail($id);
     // Test if they are the EM
     if ($event->isEM($this->user)) {
         return $this->ajaxError('You can\'t unvolunteer as you are the EM!');
     }
     // Test if the user is already crew
     $crew = $event->crew->where('user_id', $this->user->id)->first();
     if ($crew) {
         // Only unvolunteer if it's not a social
         if ($event->isSocial()) {
             Flash::warning("You can't unvolunteer from a social");
         } else {
             $crew->delete();
             Flash::success('You have unvolunteered');
         }
     } else {
         $event->crew()->create(['name' => null, 'user_id' => $this->user->id]);
         Flash::success('You have volunteered');
         // Send the email to the crew
         $user = $this->user;
         Mail::queue('emails.events.volunteered_crew', ['event' => $event->name, 'user' => $user->forename, 'em' => $event->em_id ? $event->em->name : ''], function ($message) use($user, $event) {
             $message->to($user->email, $user->name)->subject("Volunteered to crew event '{$event->name}'");
         });
         // Send the email to the EM
         if ($event->em_id) {
             $em = $event->em;
             Mail::queue('emails.events.volunteered_em', ['em' => $em->forename, 'user' => $user->name, 'event' => $event->name], function ($message) use($em, $user, $event) {
                 $message->to($em->email, $em->name)->from($user->email, $user->name)->subject("Crew volunteered for '{$event->name}'");
             });
         }
     }
     return Response::json(true);
 }
Example #22
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     if (Auth::check()) {
         # code...
         if (Auth::user()->type == 1) {
             # code...
             //$event=Event::findOrFail($id);
             $events = Event::findOrFail($id);
             $image_path = $events->image_path;
             \File::delete($image_path);
             $event = Event::destroy($id);
             Session::flash('eventDeleted', 'The event has been deleted');
             return redirect('event');
         }
         return redirect('/');
     }
     return redirect('/');
 }
Example #23
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $event = Event::findOrFail($id);
     $location = Location::where('event_id', $event->id)->firstOrFail();
     return view('event.show', compact('event', 'location'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id, $occId)
 {
     $eventti = Event::findOrFail($id);
     if (Gate::allows('manage', $eventti)) {
         $this->validate($request, ['time' => 'required|date_format:H:i', 'place' => 'required|max:128']);
         $event = EventOccurrence::where('event_id', $id)->findOrFail($occId);
         $event->time = Carbon::createFromFormat('H:i', $request->input('time'));
         $event->place = $request->input('place');
         $event->save();
         return redirect()->action('EventOccurrenceController@show', [$id, $occId]);
     } else {
         return abort(403);
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $event = Event::findOrFail($id);
     $event->delete();
     return redirect()->route('events.index')->with('message', 'Item deleted successfully.');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     //   dd($request .  $id);
     $event = Event::findOrFail($id);
     if ($event && $event->user_id == $request->user()->id) {
         $event->delete();
         Session::flash('message', "Event deleted.");
         return Redirect::back();
     } else {
         return redirect('dashboard')->withErrors('You have no permission to delete this event.');
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /**
      * Create 10 events
      */
     $featuredCount = 0;
     //no more than 4
     for ($i = 0; $i < 10; $i++) {
         if ($featuredCount < 4) {
             $featured = rand(0, 1);
             if ($featured == 1) {
                 $featuredCount += 1;
             }
         } else {
             $featured = 0;
         }
         $year = 2016;
         $month = rand(5, 12);
         $startDate = rand(8, 28);
         $endDate = $startDate + 2;
         $closingDate = $startDate - 7;
         $statuses = array('unpublished', 'published', 'published', 'published');
         $status = $statuses[array_rand($statuses, 1)];
         $late = array_rand(array(0, 1), 1);
         $lateFee = 0;
         if ($late == 1) {
             $lateFee = rand(0, 10);
         }
         $reg = array_rand(array(0, 1), 1);
         $regFee = 0;
         if ($reg == 1) {
             $regFee = rand(0, 10);
         }
         $event_id = DB::table('events')->insertGetId(['user_id' => 1, 'name' => 'Awesome event ' . $i, 'slug' => Str::slug('Awesome event ' . $i), 'description' => 'This is the event description.', 'postcode' => 'YO24 4QP', 'startDate' => Carbon\Carbon::createFromDate($year, $month, $startDate, 'Europe/London'), 'endDate' => Carbon\Carbon::createFromDate($year, $month, $endDate, 'Europe/London'), 'closingDate' => Carbon\Carbon::createFromDate($year, $month, $closingDate, 'Europe/London'), 'paypal' => '*****@*****.**', 'status' => $status, 'lateEntries' => $late, 'lateEntriesFee' => $lateFee, 'registration' => $reg, 'registrationFee' => $regFee, 'featured' => $featured, 'currency' => 'GBP', 'imageFilename' => $i . ".jpg"]);
         //Create between 5-15 competitions
         for ($j = 0; $j < rand(5, 15); $j++) {
             $comp_id = DB::table('competitions')->insertGetId(['event_id' => $event_id, 'name' => 'Competition ' . $j, 'description' => 'This is the competition description.', 'fee' => rand(5, 25)]);
             //Create 1-3 details
             $numDetails = rand(1, 3);
             for ($k = 0; $k < $numDetails; $k++) {
                 $hour = rand(0, 23);
                 $minutes = array('00', '15', '30', '45');
                 $minute = $minutes[array_rand($minutes, 1)];
                 $max = rand(5, 25);
                 $detail_id = DB::table('details')->insertGetId(['competition_id' => $comp_id, 'name' => 'Qualification ' . $k, 'max' => $max, 'dateTime' => Carbon\Carbon::create($year, $month, $startDate, $hour, $minute, '00', 'Europe/London')]);
             }
         }
         //we've created competitions and details for this event. now do some entries
         $event = Event::findOrFail($event_id);
         foreach ($event->competitions()->get() as $competition) {
             $users = User::all()->keyBy('id');
             $users->forget(1);
             $details = $competition->details()->get();
             $detail = $details->random();
             for ($e = 0; $e < rand(1, 20); $e++) {
                 $user = $users->random();
                 DB::table('entries')->insert(['user_id' => $user->id, 'event_id' => $event_id, 'competition_id' => $competition->id, 'detail_id' => $detail->id, 'transaction_id' => null, 'user_lastname' => $user->lastname, 'paymentStatus' => 'paid']);
                 $users->forget($user->id);
                 $detail = $details->random();
             }
         }
     }
 }
Example #28
0
 public function deleteEvent()
 {
     $id = \Input::get('id');
     $event = Event::findOrFail($id);
     $event->delete();
 }
Example #29
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request $request
  * @param  int $id
  * @return Response
  */
 public function update(EventRequest $request, $id)
 {
     $event = Event::findOrFail($id);
     $event->update($this->returnEventRequest($request->all()));
     $this->syncPrices($event->id, json_decode($request->input('hiddenprice')));
     $tags = (array) $request->input('tag_list');
     $this->syncTags($event, $tags);
     $albums = (array) $request->input('album_list');
     $this->syncAlbums($event, $albums);
     $this->syncBanner($event, $request->input('bannerid'));
     flash('Event has been updated');
     return Redirect::back();
 }
Example #30
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $event = Event::findOrFail($id);
     if ($event->headline != 'Inici') {
         $event->delete();
         \Session::flash('message', 'Event ' . $event->headline . ' eliminat');
     } else {
         \Session::flash('message', 'Aquest event no es pot eliminar');
     }
 }