Ejemplo n.º 1
0
 /**
  * Get the full competition overview and include user activity if specified.
  *
  * @param  \Gladiator\Models\Competition  $competition
  * @param  bool $includeActivity
  * @return \Gladiator\Models\Competition
  */
 public function getCompetitionOverview($competition, $includeActivity = false)
 {
     $competition = $competition->load('contest');
     $competition->contest = $this->appendCampaign($competition->contest);
     $competition->contestants = $this->getModelUsers($competition, $includeActivity);
     if ($includeActivity) {
         $competition->activity = $this->catalogUsers($competition->contestants);
         $key = generate_model_flash_session_key($competition, ['includeActivity' => true]);
     } else {
         $competition->activity = null;
         $key = generate_model_flash_session_key($competition);
     }
     session()->flash($key, $competition);
     return $competition;
 }
 /**
  * Get the leaderboard photos form.
  *
  * @param  \Gladiator\Models\Competition  $competition
  * @param  \Gladiator\Models\Message  $message
  * @return \Illuminate\Http\Response
  */
 public function editLeaderboardPhotos(Competition $competition, Message $message)
 {
     $key = generate_model_flash_session_key($competition, ['includeActivity' => true]);
     if (session()->has($key)) {
         $competition = session($key);
         session()->reflash();
     } else {
         $competition = $this->manager->getCompetitionOverview($competition, true);
     }
     $leaderboard = $competition->activity['active'];
     $topThree = $this->manager->getTopThreeReportbacks($leaderboard, ['includeUserIds' => true]);
     $photos = [];
     foreach ($topThree as $key => $user) {
         $photos[] = LeaderboardPhoto::where('competition_id', '=', $competition->id)->where('message_id', '=', $message->id)->where('user_id', '=', $user['user_id'])->first();
     }
     return view('competitions.leaderboard_photos.edit', compact('competition', 'message', 'photos', 'topThree'));
 }
Ejemplo n.º 3
0
 /**
  * Fire an event that queues a message to be sent.
  *
  * @param int $id
  */
 public function sendMessage(Message $message)
 {
     // Get competition with activity.
     $competitionId = request('competition_id');
     $contest = Contest::find(request('contest_id'));
     $contest = $this->manager->appendCampaign($contest);
     if ($competitionId) {
         $competition = Competition::find($competitionId);
         // Get competition with activity from flash if it is there.
         // Otherwise, grab it.
         $key = generate_model_flash_session_key($competition, ['includeActivity' => true]);
         if (session()->has($key)) {
             $competition = session($key);
         } else {
             $competition = $this->manager->getCompetitionOverview($competition, true);
         }
     }
     // Send test emails to authenticated user.
     if (request('test')) {
         $user = Auth::user();
         $user = $this->userRepository->find($user->id);
         $user = $this->manager->appendReportback($user, []);
         $users = [$user];
     } else {
         $users = $competition->contestants;
         // Only send checkin messages to users who haven't reported back.
         if ($message->type === 'checkin') {
             $users = $competition->activity['inactive'];
         }
     }
     $resources = ['message' => $message, 'competition' => isset($competition) ? $competition : null, 'contest' => $contest, 'users' => $users, 'test' => request('test')];
     // Kick off email sending
     event(new QueueMessageRequest($resources));
     if (!$competitionId) {
         return redirect()->back()->with('status', 'Fired that right the hell off!');
     }
     return redirect()->route('competitions.message', ['competition' => $competitionId, 'contest' => request('contest_id')])->with('status', 'Fired that right the hell off!');
 }