function postSector(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); try { $sector = new Sector(); $sector->nombre = $data['nombre']; $sector->descripcion = $data['descripcion']; $sector->estado = "INACTIVO"; $sector->logo = $data['logo']; $sector->cupos = $data['cupos']; $sector->aleatorio = $data['aleatorio']; $sector->aplicaReserva = $data['aplicaReserva']; $sector->save(); /*for($i=0; $i< count($data['tipoturno']);$i++){ $tipo = new Tipoturnosucursal; $tipo->idsucursal = $sector->id; $tipo->idtipoturno = $data['tipoturno'][$i]['id']; $tipo->save(); }*/ $respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1)); $response = $response->withStatus(200); } catch (Exception $err) { $respuesta = json_encode(array('msg' => "error", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }
function form_agregar() { $respuesta = new stdClass(); $this->form_validation->set_rules('codigo', 'Código', 'trim|required|numeric'); $this->form_validation->set_rules('nombre', 'Nombre', 'trim|required'); $this->form_validation->set_rules('sector_padre_codigo', 'Sector', 'trim|required'); $this->form_validation->set_rules('lat', 'Latitud', 'trim|required'); $this->form_validation->set_rules('lng', 'Longitud', 'trim|required'); if ($this->form_validation->run() == TRUE) { $sector = new Sector(); $sector->codigo = $this->input->post('codigo'); $sector->nombre = $this->input->post('nombre'); $sector->tipo = $this->input->post('tipo'); $sector->sector_padre_codigo = $this->input->post('sector_padre_codigo'); $sector->lat = $this->input->post('lat'); $sector->lng = $this->input->post('lng'); $sector->save(); $this->session->set_flashdata('message', 'Sector creado exitosamente! :)'); $respuesta->validacion = TRUE; $respuesta->redirect = site_url('backend/sectores/'); } else { $respuesta->validacion = FALSE; $respuesta->errores = validation_errors('<p class="error">', '</p>'); } echo json_encode($respuesta); }