/** * Execute the console command. * * @return mixed */ public function handle() { $liendivision = $this->argument('liendivision'); $id = $this->argument('id'); $matchs = xml_result_equ('', $liendivision); foreach ($matchs as $match) { $round = Round::where('team_id', $id)->where('equa', $match->equa)->where('equb', $match->equb)->first(); if ($round == null) { $round = new Round(); } $round->team_id = $id; $round->libelle = $match->libelle; $round->equa = $match->equa; $round->equb = $match->equb; $round->scorea = $match->scorea; $round->scoreb = $match->scoreb; $round->lien = $match->lien; $round->save(); Artisan::queue('FFTT:Games', ['lien' => $match->lien, 'id' => $round->id]); } }
public function store($userId, RoundRequest $request) { $teeSet = TeeSet::where('course_id', '=', $request->course)->where('tee_type_id', '=', $request->teeType)->first(); $date = Carbon::createFromDate($request->year, $request->month, $request->day); $round = new Round(); $round->date = $date->toDateString(); $round->user_id = $userId; $round->tee_set_id = $teeSet->id; $scores = []; for ($i = 1; $i <= 18; $i++) { $score = new Score(); $score->strokes = $request->scores[$i]; $score->putts = $request->putts[$i]; $score->gir = null; $score->fairway = null; $hole = Hole::where('course_id', '=', $request->course)->where('number', '=', $i)->first(); $score->hole_id = $hole->id; $scores[$i] = $score; } $round->save(); $round->scores()->saveMany($scores); return $round; }
public function create_event(Request $request) { $event_image = null; $background_image = null; $json['messages'] = []; $json['errors'] = []; $validator = Validator::make($request->all(), ['name' => 'required', 'no_of_rounds' => 'required|integer|max:3|min:1', 'category' => 'required|in:Computer Science,Electronics,History,Others', 'description' => 'required', 'prizes' => 'required', 'event_image' => 'required', 'background_image' => 'required', 'rounds' => 'required|array']); $validator->after(function ($validator) use($request, &$event_image, &$background_image) { if (!Session::has('id')) { $validator->errors()->add('user', 'Please login to continue'); } if (($event_image = base64_decode($request->event_image)) && ($background_image = base64_decode($request->background_image))) { if (strlen($event_image) > 2097152 || strlen($background_image) > 2097152) { $validator->errors()->add('image', 'image size exceeded'); } } else { $validator->errors()->add('image', 'curropted image'); } if (count($request->rounds) != $request->no_of_rounds) { $validator->errors()->add('round', 'Enter the correct no of rounds'); } else { foreach ($request->rounds as $round) { $subvalidator = Validator::make($round, ['no_of_questions' => 'required|integer|min:1', 'date' => 'required|date_format:Y-m-d|after:' . date('Y-m-d'), 'time' => 'required|date_format:H:i', 'cutoff' => 'integer', 'duration' => 'required|integer|min:1|max:3', 'questions' => 'required|array']); $subvalidator->after(function ($subvalidator) use($round) { foreach ($round['questions'] as $question) { $subsubvalidator = Validator::make($question, ['question' => 'required', 'option1' => 'required', 'option2' => 'required', 'option3' => 'required', 'option4' => 'required', 'answer' => 'required|in:"' . $question['option1'] . '","' . $question['option2'] . '","' . $question['option3'] . '","' . $question['option4'] . '"']); if ($subsubvalidator->fails()) { $subvalidator->errors()->merge($subsubvalidator->errors()->toArray()); break; } } }); if ($subvalidator->fails()) { $validator->errors()->merge($subvalidator->errors()->toArray()); break; } } } }); if ($validator->fails()) { $json['errors'] = $validator->errors()->toArray(); return response()->json($json); } else { $student = Student::where('id', Session::get('id'))->where('validated', true)->first(); $event = new Event(); $event->name = $request->name; $event->no_of_rounds = $request->no_of_rounds; $event->category = $request->category; $event->description = $request->description; $event->prizes = $request->prizes; $event->background_image = "abcd"; $event->event_image = "abcd"; $event->save(); $tempslug = str_slug($event->name, "-"); if (!Event::where('slug', $tempslug)->first()) { $event->slug = $tempslug; } else { $event->slug = $tempslug . "-" . $event->id; } $event->background_image = "/img/uploaded/background_" . $event->id . ".jpg"; $event->event_image = "/img/uploaded/event_" . $event->id . ".jpg"; $fh = fopen(public_path("img/uploaded/event_" . $event->id . ".jpg"), "w"); fwrite($fh, $event_image); fclose($fh); $fh = fopen(public_path("img/uploaded/background_" . $event->id . ".jpg"), "w"); fwrite($fh, $background_image); fclose($fh); $student->events()->save($event); foreach ($request->rounds as $i => $r) { $round = new Round(); $round->no = $i; $tz = new \DateTimeZone('Asia/Calcutta'); $round->start_date_time = new \DateTime($r['date'] . " " . $r['time'] . ":00", $tz); $round->duration = $r['duration']; $round->end_date_time = new \DateTime($r['date'] . " " . $r['time'] . ":00", $tz); $round->end_date_time->add(new \DateInterval('PT' . $r['duration'] . 'H')); $round->cutoff = isset($r['cutoff']) ? $r['cutoff'] : null; $round->no_of_questions = $r['no_of_questions']; $round->save(); $event->rounds()->save($round); foreach ($r['questions'] as $j => $q) { $question = new Question(); $question->no = $j; $question->question = $q['question']; $question->options = serialize([$q['option1'], $q['option2'], $q['option3'], $q['option4']]); $question->answer = $q['answer']; $question->save(); $round->questions()->save($question); } } $json['messages'] = "successfull"; return response()->json($json); } }