/** * Store a newly created resource in storage. * * Interviews are submitted as sets of tags and responses to questionnaires. * * @return Response */ public function store() { $v = Validator::make(Request::all(), ['type' => 'required|string', 'questionSet' => 'required|string', 'recordedAt' => 'required', 'questions' => 'array', 'taggable' => 'array', 'location' => 'required|string', 'area' => 'required|string', 'houseno' => 'string']); if ($v->fails()) { return Response::json(['errors' => $v->errors()], 400); } $Date = Carbon::createFromTimeStamp(Input::get('recordedAt')); $interview = Interview::firstOrNew(['date' => $Date, 'interviewer_id' => Auth::user()->id]); $Questionnaire = Questionnaire::where('name', '=', Input::get('questionSet'))->first(); // important to fail here, you shouldn't be able to submit an interview for a questionnaire that doesn't exist if (!$Questionnaire) { return Response::json(['message' => 'questionnaire "' . Input::get('questionSet') . '" does not exist'], 400); } $interview->questionnaire_id = $Questionnaire->id; $interview->type = Input::get('type'); // similarly, area has to exist already $area = Area::where(['name' => Input::get('area')])->first(); if (!$area) { return Response::json(['message' => 'area "' . Input::get('area') . '" does not exist'], 400); } // although we can allow for dynamically adding new locations as they come in. $location = Location::firstOrCreate(['name' => Input::get('location'), 'area_id' => $area->id]); $interview->location_id = $location->id; if (Input::has('houseno')) { $interview->house_number = Input::get('houseno'); } $interview->save(); if (Input::has('questions') && $interview->type === 'interview') { foreach (Input::get('questions') as $response) { InterviewResponse::create(['question' => $response['question'], 'answer' => $response['answer'], 'interview_id' => $interview->id]); } } if (Input::has('taggable') && $interview->type === 'interview') { foreach (Input::get('taggable') as $list) { if (isset($list['id'])) { $this->saveTagsToQuestionnaire($list); } $TagList = new TagList(); $TagList->name = $list['name']; $interview->tagLists()->save($TagList); foreach ($list['tagged'] as $tag) { $TagList->tags()->save(Tag::create(['name' => $tag, 'tag_list_id' => $TagList->id])); } } } $interview->push(); return Response::json(Interview::with('responses')->find($interview->id), 200); }
/** * Store a newly created resource in storage. * POST /area * * @return Response */ public function store() { $V = Validator::make(Input::all(), ['name' => 'required|string']); if ($V->fails()) { return Response::json($V->messages()->all(), 400); } $name = Input::get('name'); $Area = Area::where('name', '=', $name); if ($Area->count() > 0) { // already exists :/ return Response::json($Area->toArray(), 409); } $NewArea = new Area(); $NewArea->name = $name; $NewArea->save(); return Response::json($NewArea->toArray(), 201); }
public function search(Request $request) { $profesionales = Area::where('nombre_profesional', 'like', '%' . $request->nombre . '%')->get(); return \View::make('Profesional/list_profesional', compact('profesionales')); }
public function eliminarItem() { if (Auth::User()->Rol_Id == 7 or Auth::User()->Rol_Id == 1) { $IdContenido = Request::get('IdContenido'); $areaActual = Request::get('IdArea'); $IdSeccion = Request::get('IdSeccion'); $IdATS = Request::get('IdATS'); $IdTipoContenido = Request::get('TipoContenido'); $Item = new Contenido(); $areaActualNombre = Area::where('IdArea', $areaActual)->first(); $Seccion = Secciones::where('IdSeccion', $IdSeccion)->first(); if ($Item->eliminarItem($IdContenido)) { echo '<script type="text/javascript">alert("' . 'Se ha eliminado el Item' . '")</script>'; $TablaDeContenido = Contenido::join('area_tiene_secciones', 'ATS_Id', '=', 'area_tiene_secciones.IdATS')->where('area_tiene_secciones.Area_Id', '=', $areaActual)->where('area_tiene_secciones.Secciones_Id', '=', $IdSeccion)->get(); Session::flash('msg', 'Item eliminado correctamente.'); return View::make('SIG.editarContenido', array('areaActual' => $areaActual, 'areaActualNombre' => $areaActualNombre, 'Seccion' => $Seccion, 'IdATS' => $IdATS, 'Items' => $TablaDeContenido, 'TipoDeContenido' => $IdTipoContenido)); } else { $TablaDeContenido = Contenido::join('area_tiene_secciones', 'ATS_Id', '=', 'area_tiene_secciones.IdATS')->where('area_tiene_secciones.Area_Id', '=', $areaActual)->where('area_tiene_secciones.Secciones_Id', '=', $IdSeccion)->get(); Session::flash('msgWarning', 'Error en la aplicación, vuelva a intentarlo'); return View::make('SIG.editarContenido', array('areaActual' => $areaActual, 'areaActualNombre' => $areaActualNombre, 'Seccion' => $Seccion, 'IdATS' => $IdATS, 'Items' => $TablaDeContenido, 'TipoDeContenido' => $IdTipoContenido)); } } else { return Redirect::to('/SIG'); } }
/** * Get area by slug * * @param string $slug * @param int $publish * @return \FIIP\Areas\Area|null */ public function getBySlug($slug, $publish = 1, $county) { return Area::where('slug', $slug)->where('publish', $publish)->where('county_id', $county)->first(); }
/** * Get area list for rendering areas. * * @return void */ public function getAreaList($areaGroupId = NULL, $areas = array()) { global $data; global $settings; $stmt = Area::where('city_id', '=', $data['area']['id']); if ($areaGroupId != NULL) { $stmt->where('area_group_id', '=', $areaGroupId); } if (!empty($areas)) { $stmt->whereIn('code', $areas); $stmt->groupBy('code'); } $area = $stmt->get()->toArray(); return $area; }