public function start($id) { $tournament = Tournament::find($id); $participants = $tournament->participants; if ($tournament->started == false) { // $registrations =$tournament->registrations()->get(); // echo $registrations[0]->user()->get(); // Von der Registrierung zum User $registrations = $tournament->registrations()->get(); for ($i = 0; $i <= $participants / 2; $i = $i + 2) { echo "test" . $i; $player1 = $registrations[$i]->user()->get(); $player2 = $registrations[$i + 1]->user()->get(); $post = new Result(); $post->user1()->associate($player1[0]); $post->user2()->associate($player2[0]); $post->tournament()->associate($tournament); $post->round = 0; $post->save(); } $tournament->started = 1; $tournament->round = 0; // $tournament->round++; $tournament->save(); } else { $tournament_already_started_message = "Tournament already started"; } // echo count($registrations); return view('results.index', array("tournament_already_started_message" => $tournament_already_started_message, "started" => $tournament->started, 'tournament' => $tournament)); }
/** * Run the database seeds. * * @return void */ public function run() { DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('results')->truncate(); $res = new Result(); $res->quiz_id = 1; $res->type = 1; $res->title = 'Seeded result'; $res->content = 'lorem ipsum'; $res->save(); $res = new Result(); $res->quiz_id = 1; $res->type = 2; $res->title = 'Seeded result'; $res->content = 'lorem ipsum'; $res->save(); $res = new Result(); $res->quiz_id = 1; $res->type = 3; $res->title = 'Seeded result'; $res->content = 'lorem ipsum'; $res->save(); $res = new Result(); $res->quiz_id = 1; $res->type = 4; $res->title = 'Seeded result'; $res->content = 'lorem ipsum'; $res->save(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); }
public function store() { //return $request->all(); $newResult = input::json(); //$slug = uniqid(); $result = new Result(array('vote' => $newResult->get('vote'), 'idUser' => $newResult->get('idUser'), 'slug' => $newResult->get('slug'))); $result->save(); return Response::json(['message' => 'Thanks for your vote!']); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $quiz = Quiz::findOrFail($id); $result = Result::where('quiz_id', $quiz->id)->first(); if (!$result) { $quiz->status = 'rejected'; $quiz->save(); $result = new Result(); $result->quiz_id = $quiz->id; $result->user_id = $quiz->user_id; $result->save(); } return view('teacher.results.show')->with('result', $result)->with('title', trans('titles.results')); }
public function showresult($date = '') { if (empty($date)) { $date = date_create('now'); } else { $date = date_create_from_format('Y-m-d', $date); } $date->setTime(0, 0, 0); $today_date = date_create('now')->setTime(0, 0, 0); //block future date results if ($date > $today_date) { $datestr = $date->format('Y-m-d'); $error = 'Future date, Result not declared yet'; return view('results', compact('error', 'datestr')); } $datestr = $date->format('Y-m-d'); $current_time = intval(date('Hi')); $_results = Result::with('lottery')->with('series')->where("date", '=', $date)->orderBy('lottery_id')->orderBy('series_id')->get(); // dd($results[0]); $results = array(); $time = date(""); if (count($_results) > 0) { foreach ($_results as $_result) { if ($date == $today_date && intval($_result->lottery->draw_time) > $current_time) { continue; } if (empty($results["{$_result->lottery->draw_time}"])) { $results["{$_result->lottery->draw_time}"] = array(); } $results["{$_result->lottery->draw_time}"]["{$_result->series->code}"] = $_result->winning_number; } } $series = Series::all(); return view('results', compact('results', 'series', 'datestr')); }
public function store(Request $request, PercentageCalculator $percentageCalculator, LambdaCalculator $lambdaCalculator, DeltaCalculator $deltaCalculator) { $lambda = $lambdaCalculator->calculateFromQuestions($request->test['questions']); $delta = $deltaCalculator->calculate($request->birthday, $request->studyHours); // dd($request->test['id']); return Result::create(['name' => $request->name, 'delta' => $delta, 'lambda' => $lambda, 'test_id' => $request->test['id']]); }
public function show($referen) { $empresa = Session::get('empresa'); Checklist::where('chk_referen', $referen)->delete(); $documentos = \DB::connection('master')->table('mdb_tipodocum')->select('doc_clave', 'doc_nombre')->get(); foreach ($documentos as $doc) { $result = Result::where('res_referen', $referen)->first(); if (!empty($result)) { $validacion = Validation::where('attribute_id', 9)->where('id', $result->validations_id)->whereRaw('SUBSTRING_INDEX(val_data, "|", 1) = ' . $doc->doc_clave)->count(); if ($validacion > 0) { $imagen = \DB::connection('users')->table('opauimg')->where('pk_referencia', $referen)->where('imgtipodoc', $doc->doc_clave)->count(); if ($imagen > 0) { $check = 1; } else { $check = 0; } } else { $check = 2; } } else { $check = 0; } $data = ["chk_referen" => $referen, "chk_document" => $doc->doc_nombre, "chk_status" => $check, "chk_company" => $empresa]; Checklist::create($data); } $result = Checklist::where('chk_company', $empresa)->get(); return view('list_document')->with(['document' => $result, 'referen' => $referen]); }
public function surveyIndex($project, Request $request) { $sections = count($project->sections); if ($project->validate == 'person') { $resultable_type = 'App\\Participant'; } else { $resultable_type = 'App\\PLocation'; } $total = $project->organization->pcode->count() * 10 * $sections; if ($total !== $project->results->count()) { $current_user = auth()->user(); for ($i = 0; $i < $sections; $i++) { for ($j = 1; $j <= 10; $j++) { foreach ($project->organization->pcode as $pcode) { $result = Result::firstOrNew(['section_id' => $i, 'incident_id' => $j, 'resultable_id' => $pcode->id, 'resultable_type' => $resultable_type]); if (is_null($result->information)) { $result->information = 'missing'; } $result->user()->associate($current_user); $result->project()->associate($project); $result->resultable()->associate($pcode); $result->save(); $final[] = $result; } } } } $alocations = PLocation::where('org_id', $project->organization->id)->get(); return view('frontend.result.survey-index')->withAllLoc($alocations)->withProject($project)->withRequest($request); }
public function run() { $faker = Faker\factory::create(); DB::table('results')->delete(); foreach (range(1, 5) as $index) { Result::create(['question1' => $faker->word, 'question1_option' => $faker->word, 'question1_answer' => $faker->word, 'question1_points' => $faker->numberBetween($min = 1, $max = 100), 'secrecy' => $faker->numberBetween($min = 1, $max = 3)]); } }
public function iresponse($project, Request $request) { $iresponseCol = Question::where('project_id', $project->id)->where('qnum', config('aio.iresponse'))->first(); $dbraw = DB::select(DB::raw("SELECT pcode.state,answers.*,q.* \n FROM pcode INNER JOIN results ON results.resultable_id = pcode.primaryid \n INNER JOIN answers ON answers.status_id = results.id \n INNER JOIN ( SELECT id,qnum FROM questions where id = '{$iresponseCol->id}') q ON q.id = answers.qid")); $dbGroupBy = DB::select(DB::raw("SELECT pcode.state,answers.*,q.* \n FROM pcode INNER JOIN results ON results.resultable_id = pcode.primaryid \n INNER JOIN answers ON answers.status_id = results.id \n INNER JOIN ( SELECT id,qnum FROM questions where id = '{$iresponseCol->id}') q ON q.id = answers.qid GROUP BY results.id")); $incidents = Result::where('project_id', $project->id); $locations = PLocation::where('org_id', $project->org_id)->groupBy('state'); return view('frontend.result.response-incident')->withProject($project)->withRequest($request)->withQuestion($iresponseCol)->withIncidents($incidents)->withLocations($locations)->withDbraw(collect($dbraw))->withDbGroup(collect($dbGroupBy)); }
public function destroy($id) { $solucion = Solution::find($id); $solucion->delete(); $result = Result::find($solucion->results_id); $result->res_status = 0; $result->save(); return 'Elemento eliminado'; }
public function getResultsTable(Report $report) { $rawResults = Result::whereHas('report', function ($query) use($report) { $query->where('id', $report->id); })->get(); $headers = array('indicators' => array(), 'components' => array()); foreach ($report['indicators'] as $indicator) { array_push($headers['indicators'], array('name' => $indicator->name, 'description' => $indicator->description, 'visible' => $indicator->pivot->show_value || $indicator->pivot->show_points, 'colspan' => $indicator->pivot->show_value && $indicator->pivot->show_points ? 2 : 1)); array_push($headers['components'], array('id' => $indicator->id, 'type' => 'value', 'displayName' => 'Wartość', 'visible' => $indicator->pivot->show_value)); array_push($headers['components'], array('id' => $indicator->id, 'type' => 'points', 'displayName' => 'Punkty', 'visible' => $indicator->pivot->show_points)); } $results = []; $resultsByIndicator = []; foreach ($rawResults as $result) { $userId = $result->user_id; if (!array_key_exists($userId, $results)) { $results[$userId] = array('displayName' => $result->user->name . ' ' . $result->user->surname, 'indicators' => [], 'sum' => 0); } $indicatorId = $result->indicator_id; $results[$userId]['indicators'][$indicatorId] = array('value' => array('visible' => $report->indicators()->find($indicatorId)->pivot->show_value, 'data' => $result->value), 'points' => array('visible' => $report->indicators()->find($indicatorId)->pivot->show_points, 'data' => $result->points)); if ($report->indicators()->find($indicatorId)->pivot->show_points) { $results[$userId]['sum'] += $result->points; } // results by indicator if (!array_key_exists($indicatorId, $resultsByIndicator)) { $resultsByIndicator[$indicatorId] = []; } $resultsByIndicator[$indicatorId][$userId] = $result; } $results = array_values($results); $statistics = array('min' => array('indicators' => [], 'sum' => min(array_map(function ($user) { return $user['sum']; }, $results))), 'max' => array('indicators' => [], 'sum' => max(array_map(function ($user) { return $user['sum']; }, $results))), 'avg' => array('indicators' => [], 'sum' => array_sum(array_map(function ($user) { return $user['sum']; }, $results)) / count($results))); foreach ($resultsByIndicator as $indicatorId => $indicatorResults) { $statistics['min']['indicators'][$indicatorId] = array('value' => array('visible' => $report->indicators()->find($indicatorId)->pivot->show_value, 'data' => min(array_map(function ($result) { return $result->value; }, $indicatorResults))), 'points' => array('visible' => $report->indicators()->find($indicatorId)->pivot->show_points, 'data' => min(array_map(function ($result) { return $result->points; }, $indicatorResults)))); $statistics['max']['indicators'][$indicatorId] = array('value' => array('visible' => $report->indicators()->find($indicatorId)->pivot->show_value, 'data' => max(array_map(function ($result) { return $result->value; }, $indicatorResults))), 'points' => array('visible' => $report->indicators()->find($indicatorId)->pivot->show_points, 'data' => max(array_map(function ($result) { return $result->points; }, $indicatorResults)))); $statistics['avg']['indicators'][$indicatorId] = array('value' => array('visible' => $report->indicators()->find($indicatorId)->pivot->show_value, 'data' => array_sum(array_map(function ($result) { return $result->value; }, $indicatorResults)) / count($indicatorResults)), 'points' => array('visible' => $report->indicators()->find($indicatorId)->pivot->show_points, 'data' => array_sum(array_map(function ($result) { return $result->value; }, $indicatorResults)) / count($indicatorResults))); } return array('headers' => $headers, 'results' => $results, 'statistics' => $statistics); }
/** * Store a newly created booking. If the booking is for a ladder match * store a record for each player in the results table, to enter their results once * they have completed their match. Refer to Ladder controller. * * @return Response */ public function store_booking(StoreBookingRequest $request) { $booking = Booking::create($request->all()); if ($booking->booking_cat_id == 3) { $player1 = new Result(); $player1->match_id = $booking->id; $player1->player_id = $booking->player1_id; $player1->save(); $player2 = new Result(); $player2->match_id = $booking->id; $player2->player_id = $booking->player2_id; $player2->save(); } $booking_data = Booking::find($booking->id); session()->flash('booking_data', $booking_data); //with array of emails dates and booking info - go to a get request - create session with cancellation data. return redirect('email/booking-confirmation'); //session()->flash('flash_message', 'Your booking was successful'); //return redirect('bookings/my-bookings'); }
public function getIndex(Request $request) { User::createTable(); // User::createAdmin('*****@*****.**','admin'); Img::createTable(); Mylog::createTable(); Email::createTable(); Banner::createTable(); Activity::createTable(); Form::createTable(); Field::createTable(); FieldChildren::createTable(); Result::createTable(); ResultRow::createTable(); Charge::createTable(); }
/** * Запрещает проходить более одного тренировочного теста одновременно * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (Session::has('test')) { //если у пользователя есть открытый тест $id_result = Session::get('test'); $query = Result::whereId_result($id_result)->select('saved_test', 'test_name', 'id_test')->first(); $test_name = $query->test_name; $id_test = $query->id_test; $current_test_id = $request->segment(3); if ($id_test != $current_test_id) { //если начатый тест и текущая страничка не совпадает return view('tests.single_test', compact('test_name', 'id_test')); } } return $next($request); }
public static function insertDocument($request) { $result = Result::find($request->results_id); $result->res_status = 1; $result->save(); $validacion = Validation::find($result->validations_id); $data = explode('|', $validacion->val_data); $documento = \Input::file('document'); $nombre = $result->res_referen . '_' . $data[0]; $dir = '../../public_html/clientes/ftp/' . Session::get('empresa') . '/pdf/'; if (null === $documento) { $documento->move($dir, $nombre); } $nombredoc = \DB::connection('master')->table('mdb_tipodocum')->where('doc_clave', $data[0])->first(); \DB::connection('users')->table('opauimg')->insert(['pk_referencia' => $result->res_referen, 'imgNameFile' => $nombre, 'strImageName' => $nombredoc->doc_nombre, 'imgtipo' => 'application/pdf', 'imgtipodoc' => $data[0]]); }
public function postFSave(FSavePRequest $request, $user_email, $form_url) { $user = User::where('user_email', base64_decode($user_email))->where('user_active', '1')->firstOrFail(); $form = $user->Form()->where('form_url', $form_url)->where('form_active', 1)->firstOrFail(); if (!$form->canWrite()) { return redirect()->back()->with('msgError', '表单已经超过填写人数的最大限制了'); } $agent = new Agent(); $platform = $agent->platform(); $platform_v = $agent->version($platform); $browser = $agent->browser(); $browser_v = $agent->version($browser); $device = $agent->device(); $result = Result::create(['result_ruid' => Auth::check() ? Auth::id() : 0, 'result_form_id' => $form->form_id, 'result_ip' => ip2long($request->ip()), 'result_device' => $device, 'result_system' => $platform, 'result_system_v' => $platform_v, 'result_browser' => $browser, 'result_browser_v' => $browser_v]); if ($result) { //插入数据 $fields = $form->Field()->orderBy('field_sort', 'ASC')->get(); $splitStr = ':$split$:'; $user_id = Auth::check() ? Auth::id() : 0; foreach ($fields as $field) { $inputs = $request->input($field->field_attr_name); if (is_array($inputs)) { if ($field->field_type == 'group:shop-thumbnail') { $rows = []; foreach ($inputs as $input) { $rows[] = $input['goods_name'] . '(' . $input['goods_preice'] . '):' . $input['goods_num']; } $resultrow_attr_value = implode($splitStr, $rows); } else { $resultrow_attr_value = implode($splitStr, $inputs); } } else { $resultrow_attr_value = $inputs; } ResultRow::create(['resultrow_ruid' => $user_id, 'resultrow_result_id' => $result->result_id, 'resultrow_sort' => $field->field_sort, 'resultrow_type' => $field->field_type, 'resultrow_title' => $field->field_title, 'resultrow_tips' => $field->field_tips, 'resultrow_attr_name' => $field->field_attr_name, 'resultrow_attr_value' => $resultrow_attr_value]); } // 发送邮件提示 if ($form->form_tips_email) { $email = Email::create(['email_cuid' => 0, 'email_ruid' => $user->user_id, 'email_block' => 'form_reply_tips', 'email_target' => $user->user_email, 'email_title' => '[ ' . WEBSITE_NAME . ' ]提示您:您的表单有了新的回复', 'email_datas' => $form->form_code, 'email_is_sent' => 0]); $this->dispatch(new SendReminderEmail($email)); } $res = redirect('/u/' . $user_email . '/f-success')->with('msgSuccess', '您的表单已经成功提交,感谢您的参与。'); } else { $res = redirect()->back()->with('msgError', MSG_FA); } return $res; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $test = Test::create($request->all()); $score = 0; $quiz = Quiz::find($request->get('quiz_id')); foreach ($quiz->questions as $question) { if ($request->has($question->id)) { $result = Result::create(['quiz_id' => $request->get('quiz_id'), 'user_id' => $request->get('user_id'), 'test_id' => $test->id, 'question_id' => $question->id, 'answer_id' => $request->get($question->id)]); $answer = Answer::find($request->get($question->id)); if ($answer->correct) { $score += 1; } } } $test->score = $score; $test->save(); return redirect()->route('tests.result', $test); }
public function uploadResult(Request $request) { $data = $request->all(); $questionResult = $data['question']; $result = explode(',', $questionResult); for ($i = 0; $i < count($result); $i++) { $saveResult = explode('-', $result[$i]); Result::create(['user_id' => $data['user_id'], 'question_id' => $saveResult[0], 'answer' => $saveResult[1], 'second' => $saveResult[2]]); if ($saveResult[3] == '1') { $FavoriteRecord = Favorite::where('user_id', $data['user_id'])->where('question_id', $saveResult[0])->first(); if ($FavoriteRecord == null || $FavoriteRecord == 'null') { Favorite::create(['user_id' => $data['user_id'], 'question_id' => $saveResult[0]]); } } else { if ($saveResult[3] == '0') { Favorite::where('user_id', $data['user_id'])->where('question_id', $saveResult[0])->delete(); } } } $UserRecord = UserRecord::where('user_id', $data['user_id'])->get(); $StageRecord = $UserRecord->where('stages_id', $data['stages_id'])->first(); $CrementRecord = UserRecord::where('user_id', $data['user_id'])->where('stages_id', $data['stages_id'])->max('stage_score'); $Crement = $data['score'] - $CrementRecord; $User = User::where('id', $data['user_id'])->first(); if (count($UserRecord) == 0 || $StageRecord == 'null' || $StageRecord == null) { $User->increment('score', $data['score']); } else { if ($Crement > 0) { $User->increment('score', $Crement); } } $UserSrcoreRecord = Score::where('user_id', $data['user_id'])->where('category_id', floor($data['stages_id'] / 100)); if (count($UserSrcoreRecord->get()) == 0) { Score::create(['user_id' => $data['user_id'], 'user_name' => $User['name'], 'category_id' => floor($data['stages_id'] / 100), 'score' => $data['score']]); } else { if ($Crement > 0) { $UserSrcoreRecord->first()->increment('score', $Crement); } } UserRecord::create(['user_id' => $data['user_id'], 'stages_id' => $data['stages_id'], 'accuracy' => $data['accuracy'], 'accuracy_detail' => $data['accuracy_detail'], 'status' => $data['status'], 'status_detail' => $data['status_detail'], 'stage_score' => $data['score']]); return response()->json(['RetCode' => '1']); }
/** * Check that losers score is not higher than the winners score. */ public function moreValidation($validator) { $match = Result::where('match_id', '=', $this->input('match_id'))->first(); $booking = Booking::find($this->input('match_id')); $validator->after(function ($validator) use($match, $booking) { if ($this->input('win')) { if ($this->input('user_score') < $this->input('opponent_score')) { $validator->errors()->add('user_score', ' Your score must be higher than your opponent'); } } elseif (!$this->input('result_by_default')) { if ($this->input('user_score') > $this->input('opponent_score')) { $validator->errors()->add('user_score', ' Your score must be lower than your opponent'); } } if ($match->created_at != $match->created_at) { $validator->errors()->add('match_id', 'Match score already entered by opponent'); } if ($booking->booking_date > date('Y-m-d')) { $validator->errors()->add('match_id', 'Match has not been played yet'); } }); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::table('results')->delete(); $faker = Faker::create(); foreach (Report::all() as $report) { $coefficients = array(); $organizationIndicators = $report->owner->organization->indicators; foreach ($organizationIndicators as $organizationIndicator) { $coefficients[$organizationIndicator->id] = $organizationIndicator->pivot->coefficient; } foreach ($report->users as $user) { foreach ($report->indicators as $indicator) { $value = $indicator->type == 'value' ? $faker->randomNumber(3) : $faker->randomFloat(3, 0, 1); $points = $value * $coefficients[$indicator->id]; Result::create(['report_id' => $report->id, 'user_id' => $user->id, 'indicator_id' => $indicator->id, 'value' => $value, 'points' => $points]); } $report->evaluated_at = Carbon::now(); $report->save(); } } Model::reguard(); }
/** * @param $input * @param $result * @throws GeneralException */ private function checkResultByEmail($input, $result) { //Figure out if email is not the same if ($result->email != $input['email']) { //Check to see if email exists if (Result::where('email', '=', $input['email'])->first()) { throw new GeneralException('That email address belongs to a different result.'); } } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $result = Result::find($id); if ($result->delete()) { //SE REGISTRA LA ACTIVIDAD EN LA BITACORA $this->binnacle("ElIMINÓ RESULTADO MENSUAL"); Session::flash('message', 'El resultado se eliminó correctamente'); } return Redirect::to('/result/'); }
public function getAllResults($project, Request $request) { $result = Result::with('resultable')->with('answers')->with('answers.question.qanswers'); return Datatables::of($result)->filter(function ($query) use($request, $project) { if ($request->get('pcode')) { $code = $request->get('pcode'); $query->OfWithPcode('pcode', $code); } if ($request->get('region')) { $region = $request->get('region'); $query->OfWithPcode('state', $region); } if ($request->get('district')) { $district = $request->get('district'); $query->OfWithPcode('district', $district); } if ($request->get('township')) { $township = $request->get('township'); $query->OfWithPcode('township', $township); } if ($request->get('vtract')) { $village_tract = $request->get('village_tract'); $query->OfWithPcode('village_tract', $village_tract); } if ($request->get('village')) { $village = $request->get('village'); $query->OfWithPcode('village', $village); } if ($request->get('question') && $request->get('answer')) { $question = $request->get('question'); $answer = $request->get('answer'); $query->ofWithAndWhereHas('answers', function ($q) use($question, $answer) { $q->where('qid', $question)->where('akey', $answer); })->with('answers'); } if ($request->get('phone')) { $phone = $request->get('phone'); if ($project->validate == 'pcode') { $query->OfWithParticipant($phone); } } $query->where('project_id', $project->id)->orderBy('resultable_id', 'asc'); })->editColumn('pcode', function ($model) use($project) { if ($model->resultable_type == 'App\\PLocation') { return $model->resultable->pcode . "<a href='" . route('data.project.results.edit', [$project->id, $model->id]) . "' title='Edit'> <i class='fa fa-edit'></i></a>"; } })->editColumn('cq', function ($model) use($project) { $q = Question::find($model->section_id); if (!is_null($q)) { return $q->question; } else { return 'none'; } })->editColumn('observers', function ($model) use($project) { $p = '<table class="table">'; if ($project->validate == 'pcode') { foreach ($model->resultable->participants as $participant) { $p .= '<tr><td>' . $participant->name . '</td>'; $p .= '<td>'; if (isset($participant->phones->mobile)) { $p .= ' M:' . $participant->phones->mobile . '<br>'; } if (isset($participant->phones->emergency) && $participant->phones->emergency) { $p .= ' E:' . $participant->phones->emergency . '<br>'; } $p .= '</td></tr>'; } $p .= '</table>'; } return $p; })->make(true); }
public function evaluate($id) { if (Gate::denies('managerOnly')) { abort(403); } $result = DB::transaction(function ($id) use($id) { $report = Report::find($id); if ($report) { if ($report->evaluated_at) { Result::whereHas('report', function ($report) use($id) { $report->where('id', $id); })->delete(); $report->evaluated_at = null; } $coefficients = array(); $organizationIndicators = $report->owner->organization->indicators; foreach ($organizationIndicators as $organizationIndicator) { $coefficients[$organizationIndicator->id] = $organizationIndicator->pivot->coefficient; } $faker = Faker::create(); foreach ($report->users as $user) { foreach ($report->indicators as $indicator) { $value = $indicator->type == 'value' ? $faker->randomNumber(2) : $faker->randomNumber(3, 0, 1); $points = $value * $coefficients[$indicator->id]; $result = new Result(); $result->report_id = $report->id; $result->user_id = $user->id; $result->indicator_id = $indicator->id; $result->value = $value; $result->points = $points; $result->save(); } } $report->evaluated_at = Carbon::now(); $report->save(); } return $report; }); return $result; }
/** Проверка теста */ public function checkTest(Request $request) { //обработать ответ на вопрос if (Session::has('test')) { //проверяем повторность обращения к результам $current_test = Session::get('test'); } else { return redirect('tests'); } Session::forget('test'); //тест считается честно пройденым Session::forget('end_time'); $amount = $request->input('amount'); $id_test = $request->input('id_test'); $test = new Test(); $score_sum = 0; //сумма набранных баллов $points_sum = 0; //сумма максимально овзможных баллов $choice = []; //запоминаем выбранные варианты пользователя $j = 1; $query = $test->whereId_test($id_test)->select('total', 'test_name', 'amount', 'test_type')->first(); $total = $query->total; $test_type = $query->test_type; for ($i = 0; $i < $amount; $i++) { //обрабатываем каждый вопрос $data = $request->input($i); $array = json_decode($data); $data = $this->check($array); $right_or_wrong[$j] = $data['mark']; $choice[$j] = $data['choice']; $j++; $score_sum += $data['score']; //сумма набранных баллов $points_sum += $data['points']; //сумма максимально возможных баллов } if ($points_sum != 0) { $score = $total * $score_sum / $points_sum; $score = round($score, 1); } else { $score = $total; } $mark_bologna = $this->calcMarkBologna($total, $score); //оценки $mark_rus = $this->calcMarkRus($total, $score); $result = new Result(); $date = date('Y-m-d H:i:s', time()); //текущее время if ($test_type != 'Тренировочный') { //если тест контрольный $result->whereId_result($current_test)->update(['result_date' => $date, 'result' => $score, 'mark_ru' => $mark_rus, 'mark_eu' => $mark_bologna]); return view('tests.ctrresults', compact('score', 'mark_bologna', 'mark_rus')); } else { //если тест тренировочный $amount = $query->amount; $widgets = []; $query = $result->whereId_result($current_test)->first(); //берем сохраненный тест из БД $saved_test = $query->saved_test; $saved_test = unserialize($saved_test); for ($i = 0; $i < $amount; $i++) { $widgets[] = View::make($saved_test[$i]['view'] . 'T', $saved_test[$i]['arguments'])->with('choice', $choice[$i + 1]); } $result->whereId_result($current_test)->update(['result_date' => $date, 'result' => $score, 'mark_ru' => $mark_rus, 'mark_eu' => $mark_bologna]); $widgetListView = View::make('questions.student.training_test', compact('score', 'right_or_wrong', 'mark_bologna', 'mark_rus'))->with('widgets', $widgets); return $widgetListView; } }
public function store_winning(Request $request) { //save winning numbers for $lottery_id for current date $input = Input::all(); $date = date('Y-m-d'); $lottery_id = (int) $input['lottery_id']; // dd(count($results)); $series = $input['series']; // dd($series); $ctr = 0; foreach ($series as $series_id => $win_no) { $series_id = (int) $series_id; //check if entry already created for this date and lottery id $result = Result::where(array('series_id' => $series_id, 'lottery_id' => $lottery_id, 'date' => $date))->get(); // dd(count($result)); if (count($result)) { $result = $result[0]; $result->winning_number = $win_no; } else { $result = new Result(array('date' => $date, 'lottery_id' => $lottery_id, 'series_id' => $series_id, 'winning_number' => $win_no)); } $rsp = $result->save(); // $rsp ? ($ctr++) : ''; } return Redirect::to('/admin/lotteries/winning'); }
/** Пользователь отказался от прохождения теста */ public function dropTest() { if (Session::has('test')) { $id_result = Session::get('test'); $date = date('Y-m-d H:i:s', time()); Session::forget('test'); Session::forget('end_time'); Result::whereId_result($id_result)->update(['result_date' => $date, 'result' => -1, 'mark_ru' => -1, 'mark_eu' => 'drop']); //Присваиваем результату и оценке значения -1 } return redirect('tests'); }
private function calculate_result($u_input) { $opponent_result = Result::where('match_id', '=', $u_input->input('match_id'))->where('player_id', '!=', \Auth::user()->id); $user_result = Result::where('match_id', '=', $u_input->input('match_id'))->where('player_id', '=', \Auth::user()->id); if ($u_input->input('win')) { $winner_points = $this->winners_result($u_input->input('result_by_default'), $u_input->input('user_score'), $u_input->input('opponent_score')); $loser_points = $this->losers_result($u_input->input('result_by_default'), $u_input->input('opponent_score')); $user_result->update(['points' => $winner_points, 'winner' => '1']); $opponent_result->update(['points' => $loser_points, 'winner' => '0']); return; } $winner_points = $this->winners_result($u_input->input('result_by_default'), $u_input->input('opponent_score'), $u_input->input('user_score')); $loser_points = $this->losers_result($u_input->input('result_by_default'), $u_input->input('user_score')); $user_result->update(['points' => $loser_points, 'winner' => '0']); $opponent_result->update(['points' => $winner_points, 'winner' => '1']); return; }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $result = Result::findOrFail($id); return view('results.show')->with('result', $result)->with('title', trans('titles.results_of_the_test')); }