public function dsq_save($id, Request $request)
 {
     $competitiongroup = Competitiongroup::whereId($id)->firstOrFail();
     $act_competitor = $request->act_comp;
     $result = Result::where('competitiongroup_id', '=', $id)->where('competitor_id', '=', $act_competitor)->first();
     $result->dsq_status = 1;
     $result->fencing_win = null;
     $result->fencing_lose = null;
     $result->fencing_points = 0;
     $result->penalty_points_fencing = null;
     $result->fencing_order = 0;
     $result->swimming_time = "";
     $result->swimming_points = 0;
     $result->penalty_points_swimming = null;
     $result->swimming_order = 0;
     $result->riding_point = "";
     $result->riding_time = "";
     $result->riding_points = 0;
     $result->horse_id = null;
     $result->riding_order = 0;
     $result->ce_time = "";
     $result->ce_points = 0;
     $result->penalty_points_ce = null;
     $result->ce_order = 0;
     $result->total_points = 0;
     $result->total_penalty_points = null;
     $result->save();
     if ($competitiongroup->fencing_bouts != 0) {
         $competitiongroup->fencing_bouts = $competitiongroup->fencing_bouts - $competitiongroup->bouts_per_match;
         $competitiongroup->save();
     }
     $fencing_results1 = Fencing_result::where('competitiongroup_id', '=', $id)->where('competitor1_id', '=', $act_competitor)->get();
     $fencing_results2 = Fencing_result::where('competitiongroup_id', '=', $id)->where('competitor2_id', '=', $act_competitor)->get();
     foreach ($fencing_results1 as $fence) {
         $fence->delete();
     }
     foreach ($fencing_results2 as $fence) {
         $fence->delete();
     }
     //Sorrendek
     $this->riding_order($id);
     $this->swimming_order($id);
     $this->ce_order($id);
     $this->total_fencing_points($id);
     $this->total_points($id);
     $this->team_points_order($id);
     return redirect('admin/competitiongroups/' . $id . '/dsq')->with('status', 'Versenyző kizárva.');
 }
 public function entry_close(EntryCloseFormRequest $request, $id)
 {
     //Nevezés lezárása
     $competitiongroup = Competitiongroup::whereId($id)->firstOrFail();
     $competitiongroup->bouts_per_match = $request->get('bouts_per_match');
     $competitiongroup->fencing_bouts = $request->get('fencing_bouts');
     $competitiongroup->entry_closed = 1;
     $competitiongroup->riding_time_limit = $request->get('riding_time_limit');
     $competitiongroup->save();
     //Benevezett versenyzők vívó mérkőzéseinek összeállítása
     if ($request->fencing_bouts != 0) {
         $competitor_list = Result::select('competitor_id')->where('competitiongroup_id', '=', $id)->orderBy('competitor_id')->get()->toArray();
         $competitor_in = [];
         foreach ($competitor_list as $comp) {
             $competitor_in[] = $comp['competitor_id'];
         }
         while (count($competitor_in) >= 2) {
             foreach ($competitor_in as $comp) {
                 if ($competitor_in[0] != $comp) {
                     $fencing_result = new Fencing_result();
                     $fencing_result->competitiongroup_id = $id;
                     $fencing_result->competitor1_id = $competitor_in[0];
                     $fencing_result->competitor2_id = $comp;
                     $fencing_result->save();
                 }
             }
             unset($competitor_in[0]);
             $competitor_in = array_values($competitor_in);
         }
     }
     return redirect('admin/competitiongroups/')->with('status', 'Nevezés lezárva');
 }