/** * @return mixed */ public function search() { $query = Input::get('q'); $order_by = null !== Input::get('field') ? Input::get('field') : 'id'; $sort = null !== Input::get('sort') ? Input::get('sort') : 'asc'; $participant = $this->participants->searchParticipants($query, $order_by, $sort); $total = $participant->count(); $pageName = 'page'; $per_page = config('aio.participant.default_per_page'); $page = null; //Create custom pagination $participants = new LengthAwarePaginator($participant, $total, $per_page, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]); if ($participants->count() == 0) { return redirect()->route('admin.participants.index')->withFlashDanger('Your search term "' . $query . '" not found!'); } return view('backend.participant.index', compact('participants'))->withRoles($this->roles->getAllRoles('id', 'asc', true)); }
/** * @param $id * @return mixed */ public function destroy($id) { $this->roles->destroy($id); return redirect()->route('admin.participants.proles.index')->withFlashSuccess('The role was successfully deleted.'); }
public function participantsDataSet($p, $org, \App\PLocation $location) { //dd($p); /** $obpair = []; foreach ($p as $keys => $val){ preg_match_all('/([[:alnum:]]+)(?:_)?/', $keys, $match); if(isset($match[1][1])){ if(preg_match('/^[a-zA-Z]$/',$match[1][1])){ $obpair[$match[1][0].$match[1][1]]['type'] = $match[1][0]; $obpair[$match[1][0].$match[1][1]]['key'] = $match[1][1]; }else{ $obpair[$match[1][0]]['type'] = $match[1][0]; $obpair[$match[1][0]]['key'] = $match[1][1]; } } } print_r($obpair); die(); * */ if (isset($p->supervisor_name)) { $spv['name'] = $p->supervisor_name; $spv['id'] = $p->supervisor_id; $spvrole = $this->role->findRoleByName('Supervisor'); if (is_null($spvrole)) { $sinput['name'] = 'Supervisor'; $sinput['level'] = 4; $spvrole = $this->role->create($sinput); } $spv['role_id'] = $spvrole->id; $spv['org_id'] = $org; $sattr = ['participant_code' => $p->supervisor_id, 'org_id' => $org, 'name' => $p->supervisor_name]; $supervisor = \App\Participant::updateOrCreate($sattr, $spv); } if (isset($p->pcode)) { $pcode = (string) $p->pcode; //$observer['B']['pcode'] = (string) $p->pcode; //$observer['A']['uec_code'] = $p->uec_polling_station_code; //$observer['B']['uec_code'] = $p->uec_polling_station_code; } else { throw new GeneralException('No valid location code found! Check your upload file!'); } if (isset($p->enumerator_name_english)) { $observer['name'] = $p->enumerator_name_english; } else { $observer['name'] = 'No Name'; } if (isset($p->phone_no_primary)) { $observer['phones']['primary'] = (string) $p->phone_no_primary; } if (isset($p->phone_no_primary)) { $observer['phones']['secondary'] = (string) $p->phone_no_secondary; } if (isset($p->enumerators_nrc_card)) { $observer['nrc_id'] = $p->enumerators_nrc_card; } else { $observer['nrc_id'] = null; } if (isset($p->dob)) { $observer['dob'] = $p->dob; } if (isset($p->gender)) { $observer['gender'] = is_null($p->gender) ? 'Not Specified' : $p->gender; } if (isset($p->address)) { $observer['address'] = $p->address; } if (isset($p->email)) { $observer['email'] = $p->email; } if (isset($p->enumerator_id)) { $role = $this->role->findRoleByName('Enumerator'); if (is_null($role)) { $input['name'] = 'Enumerator'; $input['level'] = 0; $role = $this->role->create($input); } //foreach($observer as $key => $person){ $participant_code = (string) $p->enumerator_id; $observer['role_id'] = $role->id; $observer['org_id'] = $org; //$place = $this->pcode->findOrThrowException($observer['pcode'].'-'.$org); $attr = ['participant_code' => $participant_code, 'org_id' => $org, 'nrc_id' => $observer['nrc_id']]; $participant = \App\Participant::updateOrCreate($attr, $observer); if (isset($supervisor)) { $participant->supervisor()->associate($supervisor); $participant->save(); } // detach first to avoid duplicate $location->participants()->detach($participant); $location->participants()->attach($participant); $location->save(); //} } else { throw new GeneralException('No valid participant found!'); } }