Example #1
0
 /**
  * Display the specified resource.
  *
  * @param $slug
  * @return \Illuminate\Http\Response
  */
 public function show($slug)
 {
     $guild = Guild::where('slug', $slug)->firstOrFail();
     $now = Carbon::now();
     if (Input::has('month')) {
         $now->month = Input::get('month');
     }
     if (Input::has('year')) {
         $now->year = Input::get('year');
     }
     $startOfMonth = $now->copy()->startOfMonth();
     $endOfMonth = $now->copy()->endOfMonth();
     $occurrences = EventOccurrence::where('begin_at', '<', $endOfMonth)->where('end_at', '>', $startOfMonth)->whereHas('event', function ($query) use($guild) {
         $query->where('guild_id', $guild->id);
     })->with('event')->get();
     $events = [];
     foreach ($occurrences as $occurrence) {
         $events[$occurrence->begin_at->day][] = $occurrence;
     }
     $monthNames = [1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
     $dayNames = [1 => 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
     $month = $this->makeMonth($monthNames, $now);
     $lastRaids = EventOccurrence::with(['event', 'event.guild'])->whereHas('event.guild', function ($query) use($guild) {
         $query->where('id', $guild->id);
     })->where('begin_at', '<', Carbon::now())->orderBy('begin_at', 'desc')->limit(2)->get();
     $lastRaids = $lastRaids->reverse();
     $nextRaids = EventOccurrence::with(['event', 'event.guild'])->whereHas('event.guild', function ($query) use($guild) {
         $query->where('id', $guild->id);
     })->where('begin_at', '>', Carbon::now())->orderBy('begin_at')->limit(2)->get();
     return view('guilds.show', compact('guild', 'events', 'now', 'month', 'monthNames', 'dayNames', 'lastRaids', 'nextRaids'));
 }
 /**
  * Display the specified resource.
  *
  * @param $guildSlug
  * @param $occurrenceId
  * @return \Illuminate\Http\Response
  */
 public function show($guildSlug, $occurrenceId)
 {
     $guild = Guild::where('slug', $guildSlug)->firstOrFail();
     $occurrence = EventOccurrence::with(['event', 'event.guild'])->whereHas('event.guild', function ($query) use($guild) {
         $query->where('id', $guild->id);
     })->findOrFail($occurrenceId);
     $event = $occurrence->event;
     $guild = $event->guild;
     $signups = Signup::where(['event_occurrence_id' => $occurrence->id])->orderBy('created_at')->get();
     $comments = Comment::where(['event_occurrence_id' => $occurrence->id])->orderBy('created_at')->get();
     $character = Character::whereHas('guilds', function ($query) use($guild) {
         $query->where('guilds.id', $guild->id);
     })->where(['user_id' => Auth::user()->id])->firstOrFail();
     $ownSignup = null;
     $isSigned = false;
     foreach ($signups as $signup) {
         if ($signup->character_id == $character->id) {
             $ownSignup = $signup;
             $isSigned = true;
         }
     }
     if ($ownSignup == null) {
         $ownSignup = new Signup();
     }
     $statistic = new \stdClass();
     foreach (['YES', 'MAYBE', 'NO'] as $status) {
         $name = strtolower($status);
         $statistic->{$name} = $signups->filter(function ($signup) use($status) {
             return $signup->status == $status;
         })->count();
     }
     return view('guilds.events.show', compact('occurrence', 'event', 'guild', 'signups', 'comments', 'ownSignup', 'isSigned', 'statistic'));
 }