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')); }
/** * @param $id * @param bool $withOrganizations * @return mixed * @throws GeneralException */ public function findOrThrowException($id, $withProject = false) { if ($withProject) { $result = Result::with('project')->find($id); } else { $result = Result::find($id); } if (!is_null($result)) { return $result; } throw new GeneralException('That result does not exist.'); }
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); }