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); }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { // parent::boot($router); $router->model('project', 'App\\Project'); $router->model('participants', 'App\\Participant'); $router->model('projects', 'App\\Project'); $router->model('questions', 'App\\Question'); $router->model('organizations', 'App\\Organization'); $router->model('result', 'App\\Result'); $router->model('code', 'App\\PLocation'); $router->bind('pcode', function ($value, $route) { if ($route->project->validate == 'person') { $pcode = \App\Participant::where('org_id', $route->project->organization->id)->where('participant_code', $value)->first(); } elseif ($route->project->validate == 'pcode') { $pcode = \App\PLocation::where('org_id', $route->project->organization->id)->where('pcode', $value)->first(); } if (!is_null($pcode)) { return $pcode; } else { \App::abort(404, 'Not Found.'); } }); $router->bind('person', function ($value, $route) { //dd($route->project); $person = \App\Participant::where('participant_code', $value)->where('org_id', $route->project->org_id)->first(); if (!is_null($person)) { return $person; } else { \App::abort(404, 'Not Found.'); } }); }
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)); }
/** * Temporary function to migrate old data * @param type $pid */ public function migrate($pid, $pcode, $org) { //echo $org; $pcode = substr($pcode, 0, -1); // get participant $participant = \App\Participant::find($pid); // attach participant to pcode if (!empty($pcode)) { $location = \App\PLocation::where('org_id', $org)->where('pcode', $pcode)->first(); if (!empty($location)) { $participant->pcode()->attach($location->primaryid); $participant->save(); } else { return false; } } return; }
/** * @param $per_page * @param string $order_by * @param string $sort * @param int $status * @return mixed */ public function searchLocations($q, $org_id, $order_by, $sort = 'asc', $pages = 100) { $query = PLocation::where('pcode', '=', $q)->where('org_id', '=', $org_id)->orderBy($order_by, $sort)->paginate($pages); return $query; }
/** * @param $per_page * @param string $order_by * @param string $sort * @param int $status * @return mixed */ public function getLocationsPaginated($per_page, $withUsers = false, $status = 0, $order_by = 'id', $sort = 'asc') { if ($withUsers) { $auth_id = access()->user()->id; return PLocation::where('owner_id', $auth_id)->orderBy($order_by, $sort)->paginate($per_page); } else { return PLocation::orderBy($order_by, $sort)->paginate($per_page); } }
public function getStatusCount($project, Request $request) { //$section = $request->get('section'); $location = $request->get('location'); $loctype = $request->get('loctype'); foreach ($project->sections as $section => $section_value) { if ($loctype && $location) { $total_forms = PLocation::where('org_id', $project->org_id)->where($loctype, $location)->count(); //dd($total_forms); $total_results = Result::where('project_id', $project->id)->where('section_id', $section)->OfWithPcode($loctype, $location)->count(); $result['complete'][$section]['y'] = Result::where('project_id', $project->id)->where('section_id', $section)->where('information', 'complete')->OfWithPcode($loctype, $location)->count(); $result['incomplete'][$section]['y'] = Result::where('project_id', $project->id)->where('section_id', $section)->where('information', 'incomplete')->OfWithPcode($loctype, $location)->count(); $result['error'][$section]['y'] = Result::where('project_id', $project->id)->where('section_id', $section)->where('information', 'error')->OfWithPcode($loctype, $location)->count(); $result['missing'][$section]['y'] = $total_forms - $total_results; $result['complete'][$section]['label'] = $section_value->text; $result['incomplete'][$section]['label'] = $section_value->text; $result['error'][$section]['label'] = $section_value->text; $result['missing'][$section]['label'] = $section_value->text; } else { $total_forms = PLocation::where('org_id', $project->org_id)->count(); $total_results = Result::where('project_id', $project->id)->where('section_id', $section)->count(); $result['complete'][$section]['y'] = Result::where('project_id', $project->id)->where('section_id', $section)->where('information', 'complete')->count(); $result['incomplete'][$section]['y'] = Result::where('project_id', $project->id)->where('section_id', $section)->where('information', 'incomplete')->count(); $result['error'][$section]['y'] = Result::where('project_id', $project->id)->where('section_id', $section)->where('information', 'error')->count(); $result['missing'][$section]['y'] = $total_forms - $total_results; $result['complete'][$section]['label'] = _t($section_value->text); $result['incomplete'][$section]['label'] = _t($section_value->text); $result['error'][$section]['label'] = _t($section_value->text); $result['missing'][$section]['label'] = _t($section_value->text); //$result['complete'][$section]['indexLabel'] = _t($section_value->text); //$result['incomplete'][$section]['indexLabel'] = _t($section_value->text); //$result['error'][$section]['indexLabel'] = _t($section_value->text); //$result['missing'][$section]['indexLabel'] = _t($section_value->text); //$result['complete'][$section]['indexLabelPlacement'] = 'inside'; //$result['incomplete'][$section]['indexLabelPlacement'] = 'inside'; //$result['error'][$section]['indexLabelPlacement'] = 'inside'; //$result['missing'][$section]['indexLabelPlacement'] = 'inside'; } } //$result = Result::where('section_id', $section)->where('information', $status)->OfWithPcode('state','Yangon')->count(); return response()->json($result); }
public function analysis($project) { $questions = $project->questions; //dd($project->answersQ); $results = $this->results->getAllResults($project->id); /** return $results->each(function($item, $key) use ($questions){ $qnum = $questions->each(function($qs, $qk) use ($item) { foreach($item as $q => $a){ if($q == $qs->qnum){ //dd($a); } } }); //dd($qnum); }); $sections = $project->results->groupBy('section_id'); foreach ($sections as $section){ // dd($section); } * */ $located = \App\PLocation::where('org_id', $project->organization->id); return view('backend.project.analysis')->withProject($project)->withQuestions($questions)->withLocations($located); }
/** * * @param integer $id * @param array $input * @param mixed $roles * @param mixed $locations * @return boolean * @throws GeneralException */ public function update($participant, $input, $pcode, $org, $role_id) { $organization = $this->organization->findOrThrowException($org['org_id']); $role = $this->role->findOrThrowException($role_id['role']); $area = ['village', 'village_tract', 'township', 'district', 'state', 'country']; if (!filter_var($input['email'], FILTER_VALIDATE_EMAIL)) { // valid address unset($input['email']); } if (empty($input['nrc_id'])) { $input['nrc_id'] = null; } // get participant //$participant = $this->findOrThrowException($id); // attach participant to pcode if (!empty($pcode['pcode_id'])) { $location = PLocation::where('org_id', $org['org_id'])->where('pcode', $pcode['pcode_id'])->first(); if (!empty($location)) { $participant->pcode()->attach($location); } else { return false; } } // dissociate old organization $participant->organization()->dissociate(); // associate with updated organization $participant->organization()->associate($organization); // dissociate old role $participant->role()->dissociate(); // associate with updated role $participant->role()->associate($role); if ($participant->update($input)) { return true; } throw new GeneralException('There was a problem updating this participant. Please try again.'); }