/**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['body' => 'required|min:5']);
     if ($request->user()->muted) {
         return \Redirect::back()->with('error', 'You are muted.');
     }
     $status = ['body' => $request->body];
     $st = $this->status->publish($status);
     // Create notification with Stream
     $not = new Notification();
     $not->from($request->user())->withType('UserStatusUpdate')->withSubject('A status is posted')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " published a post in his feedline " . link_to_route('show-status', "#" . $st->id, $st->id))->withStream(true)->regarding($st)->deliver();
     return \Redirect::back()->with('message', 'Status updated successfully');
 }
示例#2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param NewsRequest $request
  * @return Response
  */
 public function store(NewsRequest $request)
 {
     $slug = str_limit(str_slug($request->title), 50) . "--author-{$request->user()->username}";
     /*$news  = News::where('summary',$slug)->first();
     
             if($news)
             {
                 $slug = str_limit(str_slug($request->title),50)."-".time()."--author-{$request->user()->username}";
             }*/
     $news = $request->user()->news()->create(['title' => $request->title, 'text' => $request->text, 'summary' => $slug, 'is_published' => true, 'news_type' => $request->news_type]);
     // Create notification
     $not = new Notification();
     $not->from($request->user())->withType('NewsCreated')->withSubject('A news is created')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has created a news " . link_to_route('news.show', str_limit($news->title, 100), $news->summary))->withStream(true)->regarding($news)->deliver();
     return redirect()->route('news.show', $news->summary)->with('message', 'News Created');
 }
 public function storeForTournament($id, Request $request)
 {
     $t = KTournament::findOrFail($id);
     $comment = \Input::get('body');
     if ($comment == '') {
         return \Redirect::back();
     }
     if ($request->user()->muted) {
         return \Redirect::back()->with('error', 'You are muted.');
     }
     $t->comments()->create(['body' => $comment, 'user_id' => Auth::user()->id]);
     // Create notification
     $not = new Notification();
     $not->from($request->user())->withType('UserCommentOnTournament')->withSubject('A comment is done on tournament')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has commented on " . link_to_route('tournament.show', $t->name, $t->slug) . " tournament")->withStream(true)->regarding($t)->deliver();
     return \Redirect::back()->with('success', 'Success!');
 }
示例#4
0
 /**
  * Change role of user
  *
  * @param Request $request
  * @param $username
  * @return \Illuminate\Http\RedirectResponse
  */
 public function changeRole(Request $request, $username)
 {
     if (!$request->user()->isAdmin()) {
         return \Redirect::back()->with('error', "Aw! You are not any Admin ;)");
     }
     if ($request->username != $username) {
         return \Redirect::back()->with('error', "Aw! Please don't try to mess up the code ;)");
     }
     $user = User::findOrFail($request->user_id);
     if ($request->username != $user->username) {
         return \Redirect::back()->with('error', "Aw! Please don't try to mess up the code ;)");
     }
     if ($request->job == 'promote') {
         // If User role is equal to the one other person role - 1
         // If user admin 3 other also admin 3
         // 3 >= 4 -> True
         if ($request->user()->roles()->first()->id >= $user->roles()->first()->id - 1) {
             return \Redirect::back()->with('error', "Sorry! Not enough permissions");
         }
         // Cannot promote if already a SA
         if ($user->roles()->first()->id <= 2) {
             return \Redirect::back()->with('error', "Sorry! No more higher rank.");
         }
         $role = $user->roles()->first();
         $prevRoleID = $role->id;
         $nextRoleID = $prevRoleID - 1;
         $user->detachRole($role);
         $user->attachRole($nextRoleID);
         $nextrank = Role::find($nextRoleID);
         // Create notification
         $not = new Notification();
         $not->from($request->user())->withType('UserRolePromote')->withSubject('A User has promoted.')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has <span class='text-green notify-bold'>promoted</span> " . link_to_route('user.show', $user->displayName(), $user->username) . " to " . $nextrank->display_name)->withStream(true)->regarding($user)->deliver();
         return \Redirect::back()->with('message', "User promoted!");
     } elseif ($request->job == 'demote') {
         if ($request->user()->roles()->first()->id >= $user->roles()->first()->id) {
             return \Redirect::back()->with('error', "Sorry! Not enough permissions");
         }
         // Cannot demote if already a member
         if ($user->roles()->first()->id >= 5) {
             return \Redirect::back()->with('error', "Sorry! No more lower rank.");
         }
         $role = $user->roles()->first();
         $prevRoleID = $role->id;
         $nextRoleID = $prevRoleID + 1;
         $user->detachRole($role);
         $user->attachRole($nextRoleID);
         $nextrank = Role::find($nextRoleID);
         // Create notification
         $not = new Notification();
         $not->from($request->user())->withType('UserRoleDemote')->withSubject('A User has demoted.')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has <span class='text-danger notify-bold'>demoted</span> " . link_to_route('user.show', $user->displayName(), $user->username) . " to " . $nextrank->display_name)->withStream(true)->regarding($user)->deliver();
         return \Redirect::back()->with('message', "User demoted!");
     } else {
         return \Redirect::back()->with('error', "Whoops! Unknown error");
     }
 }
 /**
  * @param $slug
  * @param $id
  * @param Request $request
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function postCalculateMatchFinal($slug, $id, Request $request)
 {
     $tournament = KTournament::enabled()->whereSlug($slug)->first();
     $match = KMatch::find($id);
     if (!$tournament || !$match) {
         abort(404);
     }
     //If has enough permissions or not
     if (!$request->user()->canManageTournament($tournament)) {
         return redirect()->home();
     }
     if ($match->has_been_played) {
         return redirect()->route('tournament.bracket.show', [$tournament->slug])->with('error', "Error! Already calculated, Plz contact admin for support");
     }
     if ($request->overall_winner_id == "0" && $tournament->bracket_type > 0) {
         return redirect()->route('tournament.bracket.show', [$tournament->slug])->with('error', "Error! Tie only supported in Round Robin Tournament");
     }
     // Check is On. Turn off only for testing
     if (true) {
         //Check if all team1_p1_score is present
         foreach ($request->team1_p1_score as $x) {
             if ($x == null || $x == "") {
                 return redirect()->route('tournament.match.getcalculate', [$tournament->slug, $match->id])->with('error', "Error! Something is not correct. Please retry.");
             }
         }
         //Check if all team1_p2_score is present
         foreach ($request->team1_p2_score as $x) {
             if ($x == null || $x == "") {
                 return redirect()->route('tournament.match.getcalculate', [$tournament->slug, $match->id])->with('error', "Error! Something is not correct. Please retry.");
             }
         }
         //Check if all team2_p1_score is present
         foreach ($request->team2_p1_score as $x) {
             if ($x == null || $x == "") {
                 return redirect()->route('tournament.match.getcalculate', [$tournament->slug, $match->id])->with('error', "Error! Something is not correct. Please retry.");
             }
         }
         //Check if all team2_p2_score is present
         foreach ($request->team2_p2_score as $x) {
             if ($x == null || $x == "") {
                 return redirect()->route('tournament.match.getcalculate', [$tournament->slug, $match->id])->with('error', "Error! Something is not correct. Please retry.");
             }
         }
         if ($tournament->tournament_type == 2) {
             //Check if all team1_p3_score is present
             foreach ($request->team1_p3_score as $x) {
                 if ($x == null || $x == "") {
                     return redirect()->route('tournament.match.getcalculate', [$tournament->slug, $match->id])->with('error', "Error! Something is not correct. Please retry.");
                 }
             }
             //Check if all team2_p3_score is present
             foreach ($request->team2_p3_score as $x) {
                 if ($x == null || $x == "") {
                     return redirect()->route('tournament.match.getcalculate', [$tournament->slug, $match->id])->with('error', "Error! Something is not correct. Please retry.");
                 }
             }
         }
         //Check if all team1_p1_score is present
         foreach ($request->winner as $x) {
             if ($x == null || $x == "") {
                 return redirect()->route('tournament.match.getcalculate', [$tournament->slug, $match->id])->with('error', "Error! Something is not correct. Please retry.");
             }
         }
     }
     // Now Insertions will be here...
     //First insert game_id in Match Table
     //Check if all game_id is present
     $i = 1;
     foreach ($request->game_id as $x) {
         $match->{"game" . $i . "_id"} = $x;
         $i++;
     }
     /**
      * GAME WIN OUTCOMES
      * 0 -> Team 1 Wins
      * 1 -> Team 2 Wins
      * 2 -> A Tie
      * 3 -> None
      */
     $team1_w = 0;
     $team2_w = 0;
     $tie_w = 0;
     $no_w = 0;
     $i = 1;
     foreach ($request->winner as $x) {
         $match->{"game" . $i . "_id_outcome"} = $x;
         $i++;
         switch ($x) {
             case 0:
                 $team1_w++;
                 break;
             case 1:
                 $team2_w++;
                 break;
             case 2:
                 $tie_w++;
                 break;
             case 3:
                 $no_w++;
                 break;
             default:
                 break;
         }
     }
     if ($team1_w > $team2_w) {
         $match->winner_team_won_by = $team1_w . " - " . $team2_w;
     } else {
         $match->winner_team_won_by = $team2_w . " - " . $team1_w;
     }
     /*$collection = collect($request->winner);
             $items = ($collection->groupBy(function($item,$key){
                 return $item;
             }));
     
             dd($match->winner_team_won_by);
             foreach($items as $item)
             {
                 dd($item->count());
             }*/
     /**
      * If tournament type is 3v3 then take 3 players else only 2
      * @TODO: Change if 1v1 implemented
      */
     if ($tournament->tournament_type == 2) {
         $team1_p1_score_sum = array_sum($request->team1_p1_score);
         $team1_p2_score_sum = array_sum($request->team1_p2_score);
         $team1_p3_score_sum = array_sum($request->team1_p3_score);
         $team2_p1_score_sum = array_sum($request->team2_p1_score);
         $team2_p2_score_sum = array_sum($request->team2_p2_score);
         $team2_p3_score_sum = array_sum($request->team2_p3_score);
         $team1_total_score = $team1_p1_score_sum + $team1_p2_score_sum + $team1_p3_score_sum;
         $team2_total_score = $team2_p1_score_sum + $team2_p2_score_sum + $team2_p3_score_sum;
     } else {
         $team1_p1_score_sum = array_sum($request->team1_p1_score);
         $team1_p2_score_sum = array_sum($request->team1_p2_score);
         $team2_p1_score_sum = array_sum($request->team2_p1_score);
         $team2_p2_score_sum = array_sum($request->team2_p2_score);
         $team1_total_score = $team1_p1_score_sum + $team1_p2_score_sum;
         $team2_total_score = $team2_p1_score_sum + $team2_p2_score_sum;
     }
     $match->k_team1_total_score = $team1_total_score;
     $match->k_team2_total_score = $team2_total_score;
     if ($request->overall_winner_id != "-1" && $request->overall_winner_id != "0" && $request->overall_winner_id != $match->team1->id && $request->overall_winner_id != $match->team2->id) {
         return redirect()->home()->with("error", "Error! Don't mess up with codes.");
     }
     $match->winner_team_id = $request->overall_winner_id;
     $match->has_been_played = true;
     //SAVE MATCH
     $match->save();
     $team1 = $match->team1;
     $team2 = $match->team2;
     $team1->total_score += $team1_total_score;
     $team2->total_score += $team2_total_score;
     //If winner is team 1
     if ($request->overall_winner_id == $team1->id) {
         $team1->total_wins += 1;
         $team2->total_lost += 1;
         $team1->points += 2;
         $team2->points -= 2;
     } elseif ($request->overall_winner_id == $team2->id) {
         $team2->total_wins += 1;
         $team1->total_lost += 1;
         $team2->points += 2;
         $team1->points -= 2;
     } elseif ($request->overall_winner_id == "0") {
         $team2->total_tie += 1;
         $team1->total_tie += 1;
         $team1->points += 1;
         $team2->points += 1;
     } else {
     }
     //SAVE TEAMS
     $team1->save();
     $team2->save();
     //SAVE INDI PLAYER STATS
     if ($tournament->tournament_type == 0) {
         $team1_p1 = $match->team1->playerselected->first();
         $team1_p2 = $match->team1->playerselected->last();
         $team2_p1 = $match->team2->playerselected->first();
         $team2_p2 = $match->team2->playerselected->last();
         $match->team1->givescoretouser($team1_p1, $team1_p1_score_sum);
         $match->team1->givescoretouser($team1_p2, $team1_p2_score_sum);
         $match->team2->givescoretouser($team2_p1, $team2_p1_score_sum);
         $match->team2->givescoretouser($team2_p2, $team2_p2_score_sum);
     } else {
         if ($tournament->tournament_type == 2) {
             $i = 1;
             foreach ($match->team1->playerselected as $player) {
                 //${'team1_p'.$i} = $player;
                 $match->team1->givescoretouser($player, ${'team1_p' . $i . '_score_sum'});
                 $i++;
             }
             $y = 1;
             foreach ($match->team2->playerselected as $player) {
                 //${'team2_p'.$i} = $player;
                 $match->team2->givescoretouser($player, ${'team2_p' . $y . '_score_sum'});
                 $y++;
             }
         }
     }
     //@TODO: Add else here for 1v1
     //FOR DE/SE ONLY
     //Check all match id (TBA) and change to team id as per match schedule
     if ($tournament->bracket_type > 0) {
         // Check for all matches with has this match index for team 1...
         $team1_from_match_indexes = KMatch::where('team1_from_match_index', $match->match_index)->get();
         foreach ($team1_from_match_indexes as $team1_from_match_index) {
             if ($team1_from_match_index->team1_from_match_rank == 1) {
                 $team1_from_match_index->k_team1_id = $match->winner_team_id;
                 $team1_from_match_index->save();
             } elseif ($team1_from_match_index->team1_from_match_rank == 2) {
                 $team1_from_match_index->k_team1_id = $team1->id == $match->winner_team_id ? $team2->id : $team1->id;
                 $team1_from_match_index->save();
             }
         }
         // Check for all matches with has this match index for team 2...
         $team2_from_match_indexes = KMatch::where('team2_from_match_index', $match->match_index)->get();
         foreach ($team2_from_match_indexes as $team2_from_match_index) {
             if ($team2_from_match_index->team2_from_match_rank == 1) {
                 $team2_from_match_index->k_team2_id = $match->winner_team_id;
                 $team2_from_match_index->save();
             } elseif ($team2_from_match_index->team2_from_match_rank == 2) {
                 $team2_from_match_index->k_team2_id = $team1->id == $match->winner_team_id ? $team2->id : $team1->id;
                 $team2_from_match_index->save();
             }
         }
     }
     //Dispatch Notifications
     //If match is cancelled
     if ($request->winner_team_id == "-1") {
         // Create notification with Stream
         $not = new Notification();
         $not->from($request->user())->withType('TournamentMatchCancelled')->withSubject('Match is cancelled in a tournament')->withBody(link_to_route('tournament.show', $tournament->name, $tournament->slug) . " : Match between " . link_to_route('tournament.team.show', $match->team1->name, [$tournament->slug, $match->team1->id]) . " and " . link_to_route('tournament.team.show', $match->team2->name, [$tournament->slug, $match->team2->id]) . " was <span class='text-danger notify-bold'>cancelled</span>")->withStream(true)->regarding($tournament)->deliver();
     } else {
         if ($request->winner_team_id == "0") {
             $not = new Notification();
             $not->from($request->user())->withType('TournamentMatchTie')->withSubject('Match is tie in a tournament')->withBody(link_to_route('tournament.show', $tournament->name, $tournament->slug) . " : Match between " . link_to_route('tournament.team.show', $match->team1->name, [$tournament->slug, $match->team1->id]) . " and " . link_to_route('tournament.team.show', $match->team2->name, [$tournament->slug, $match->team2->id]) . " <span class='text-danger notify-bold'>tied</span> by " . $request->winner_team_won_by)->withStream(true)->regarding($tournament)->deliver();
         } else {
             $not = new Notification();
             $not->from($request->user())->withType('TournamentMatchPlayed')->withSubject('Match is played in a tournament')->withBody(link_to_route('tournament.show', $tournament->name, $tournament->slug) . " : " . $match->getWinningTextForNotifications())->withStream(true)->regarding($tournament)->deliver();
         }
     }
     //RANK THE TEAMS
     //@TODO: Its TEMP CHANGE IT
     $teams = KTeam::where('team_status', 1)->orderBy('points', 'desc')->orderBy('total_wins', 'desc')->orderBy('total_lost', 'asc')->orderBy('total_tie', 'desc')->orderBy('total_score', 'desc')->get();
     $i = 0;
     foreach ($teams as $team) {
         $team->team_position = ++$i;
         $team->save();
     }
     return redirect()->route('tournament.show', [$tournament->slug])->with('message', "Success! Match data has been recorded.");
 }
 public function notifyAll($user)
 {
     $not = new Notification();
     $not->from($user)->withType('UserRegistered')->withSubject('A new user registration')->withBody("A new user registered : " . link_to_route('user.show', $user->displayName(), [$user->username]))->withStream(true)->regarding($user)->deliver();
 }
 /**
  * @param $slug
  * @param $id
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function handleTeamsForManager($slug, $id, Request $request)
 {
     if ($request->team_id != $id) {
         return redirect()->home();
     }
     if (!($request->action_id == 0 || $request->action_id == 1 || $request->action_id == 2 || $request->action_id == 3)) {
         return redirect()->back()->with('error', 'Error! Invalid action');
     }
     $tournament = KTournament::whereSlug($slug)->firstOrFail();
     $team = KTeam::findOrFail($request->team_id);
     // Only if team belongs to this tour
     if ($team->k_tournament_id != $tournament->id) {
         return redirect()->home();
     }
     // Tournament has not begun or has ended or disabled then return
     if ($tournament->isRegistrationOpen() == 6 || $tournament->isRegistrationOpen() == 5 || $tournament->isRegistrationOpen() == 4) {
         return redirect()->back()->with('error', 'Error! Cannot modify team now.');
     }
     // Only if user has enough power
     if (!$request->user()->canManageTournament($tournament)) {
         return redirect()->back()->with('error', 'Error! Not Authorised');
     }
     // If Tournament is full
     if ($request->action_id == 1 && $tournament->isFullParticipants()) {
         return redirect()->back()->with('error', 'Error! Tournament already have maximum qualified participants.');
     }
     $old_action_id = $team->team_status;
     $team->team_status = $request->action_id;
     $team->save();
     // Stream Notifications.
     // Approved
     if ($request->action_id == 1 && $request->action_id != $old_action_id) {
         $not = new Notification();
         $not->from($request->user())->withType('TeamRequestApproved')->withSubject('Team has approved to join tournament')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has <span class='text-green notify-bold'>approved</span> team " . link_to_route('tournament.team.show', $team->name, [$tournament->slug, $team->id]) . " request to join " . link_to_route('tournament.show', $tournament->name, $tournament->slug))->withStream(true)->regarding($team)->deliver();
     } elseif ($request->action_id == 2 && $request->action_id != $old_action_id) {
         $not = new Notification();
         $not->from($request->user())->withType('TeamRequestDisqualified')->withSubject('Team has set to disqualified to join tournament')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has <span class='text-danger notify-bold'>disqualified</span> team " . link_to_route('tournament.team.show', $team->name, [$tournament->slug, $team->id]) . " from " . link_to_route('tournament.show', $tournament->name, $tournament->slug))->withStream(true)->regarding($team)->deliver();
     } elseif ($request->action_id == 3 && $request->action_id != $old_action_id) {
         $not = new Notification();
         $not->from($request->user())->withType('TeamRequestNoteligible')->withSubject('Team has set not eligible to join tournament')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has changed team " . link_to_route('tournament.team.show', $team->name, [$tournament->slug, $team->id]) . " status to <span class='text-danger notify-bold'>not eligible</span> in " . link_to_route('tournament.show', $tournament->name, $tournament->slug))->withStream(true)->regarding($team)->deliver();
     } elseif ($request->action_id == 0 && $request->action_id != $old_action_id) {
         $not = new Notification();
         $not->from($request->user())->withType('TeamRequestPending')->withSubject('Team has set pending to join tournament')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has changed team " . link_to_route('tournament.team.show', $team->name, [$tournament->slug, $team->id]) . " status to <span class='text-warning notify-bold'>pending</span> in " . link_to_route('tournament.show', $tournament->name, $tournament->slug))->withStream(true)->regarding($team)->deliver();
     }
     return redirect()->back()->with('message', 'Success! Team status changed');
 }
示例#8
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @param InputRequest $request
  * @return Response
  */
 public function update($id, InputRequest $request)
 {
     if (!$request->user()->isAdmin()) {
         return redirect()->home()->with('error', "Not authorized");
     }
     $validator = \Validator::make($request->all(), ['status' => 'required|in:0,1']);
     if ($validator->fails()) {
         return \Redirect::back()->with('errors', $validator->errors())->withInput();
     }
     $ban = Ban::findOrFail($id);
     $prev_status = $ban->status;
     $status = $request->status;
     $reason = $request->reason == "" ? null : $request->reason;
     $banned_till = $request->banned_till;
     $banned_till = $banned_till == "" ? null : Carbon::parse($banned_till);
     // If its a unban work then banned till will be set to now.
     if ($status == 0 && $prev_status == 1) {
         $banned_till = Carbon::now();
     } else {
         if ($status == 1 && $prev_status == 0 && $banned_till != null && $banned_till <= Carbon::now()) {
             $banned_till = null;
         } else {
             if ($status == 0 && $prev_status == 0) {
                 if ($banned_till >= Carbon::now()) {
                     return redirect()->back()->with('error', 'Ban Till cannot me in future if status is "Unbanned".')->withInput();
                 } else {
                     if ($banned_till == "" || $banned_till == null) {
                         $banned_till = $ban->banned_till;
                     }
                 }
             }
         }
     }
     $ban->reason = $reason;
     $ban->status = $status;
     $ban->banned_till = $banned_till;
     $ban->updated_by = $request->user()->username;
     $ban->updated_by_site = true;
     $ban->save();
     // Create notification
     $not = new Notification();
     $not->from($request->user())->withType('BanUpdated')->withSubject('A ban is updated')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has updated the ban " . link_to_route('bans.show', '#' . $ban->id, $ban->id) . " with IP <b>" . $ban->ipAddrWithMask() . "</b> <img src='" . $ban->countryImage() . "' class='tooltipster img' title='" . $ban->countryName() . "'>")->withStream(true)->regarding($ban)->deliver();
     if ($status == 0 && $prev_status == 1) {
         $ban->tellServerToRemove();
     } else {
         if ($status == 1 && $prev_status == 0) {
             $ban->tellServerToAdd();
         }
     }
     return redirect()->route('bans.show', $ban->id)->with('success', 'Ban has need updated!');
 }