public function getBody() { $body = $this->request->getBody(); if ($body == '') { return array(); } return json_decode($body, true); }
private function buildParams(array $params = array()) { $body = $this->request->getBody(); if (is_array($body) === false) { $body = array(); } if (array_key_exists(0, $body) === true) { $body = array(self::PARAM_REQUEST_BODY => $body); } return array_replace($this->request->params(), $body, $params); }
public function getPayload() { $payload = json_decode($this->request->getBody(), true); $exception = null; switch (json_last_error()) { case JSON_ERROR_NONE: break; case JSON_ERROR_DEPTH: $exception = 'Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: $exception = 'Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: $exception = 'Unexpected control character found'; break; case JSON_ERROR_SYNTAX: $exception = 'Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: $exception = 'Malformed UTF-8 characters, possibly incorrectly encoded'; break; default: $exception = 'Unknown error'; break; } if ($exception) { throw new \Exception('Error decoding payload: ' . $exception); } return $payload; }
/** * Execute the middleware. * * @param \Slim\Http\Request $req * @param \Slim\Http\Response $res * @param callable $next * @return \Slim\Http\Response */ public function __invoke(Request $req, Response $res, callable $next) { $uri = $req->getUri(); $path = $this->filterTrailingSlash($uri); if ($uri->getPath() !== $path) { return $res->withStatus(301)->withHeader('Location', $path)->withBody($req->getBody()); } // if ($this->filterBaseurl($uri)) { // return $res->withStatus(301) // ->withHeader('Location', (string) $uri) // ->withBody($req->getBody()); // } $server = $req->getServerParams(); if (!isset($server['REQUEST_TIME_FLOAT'])) { $server['REQUEST_TIME_FLOAT'] = microtime(true); } $uri = $uri->withPath($path); $req = $this->filterRequestMethod($req->withUri($uri)); $res = $next($req, $res); $res = $this->filterPrivateRoutes($uri, $res); // Only provide response calculation time in non-production env, tho. if ($this->settings['mode'] !== 'production') { $time = (microtime(true) - $server['REQUEST_TIME_FLOAT']) * 1000; $res = $res->withHeader('X-Response-Time', sprintf('%2.3fms', $time)); } return $res; }
function borrartipoturnosucursal(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $id = $request->getAttribute("id"); $tipo = Tipoturnosucursal::select("*")->where("idsucursal", "=", $id)->delete(); $response->getBody()->write($tipo); return $response; }
function eliminarservicios(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $id = $request->getAttribute("idempleado"); $tipo = ServiciosEmpleado::select("*")->where("idEmpleado", "=", $id)->delete(); $response->getBody()->write($tipo); return $response; }
function promocionesByCategorias(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $data = Promocion::select("promocion.*")->join("categoriaspromocion", "categoriaspromocion.idPromocion", "=", "promocion.id")->whereIn("categoriaspromocion.idCategoria", $data['categorias'])->distinct()->get(); if (count($data) == 0) { $response = $response->withStatus(404); } $response->getBody()->write($data); return $response; }
function putIdPushByUsuario(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $id = $request->getAttribute('id'); $data = json_decode($request->getBody(), true); try { $usuario = Usuario::where('id', '=', $id)->first(); $usuario->idPush = $data['idPush']; $usuario->save(); $respuesta = json_encode(array('msg' => "Modificado correctamente", "std" => 1, "obj" => $cliente)); $response = $response->withStatus(200); } catch (Exception $err) { $respuesta = json_encode(array('msg' => "Error al modificar", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }
function postCalificacion(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $idEmpresa = $request->getAttribute('email'); $data = json_decode($request->getBody(), true); try { $ce = new CalificacionEmpresa(); $ce->calificacion = $data['calificacion']; $ce->idEmpresa = $idEmpresa; $ce->save(); $respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "obj" => $data)); $response = $response->withStatus(200); } catch (Exception $err) { $respuesta = json_encode(array('msg' => "erro al calificar", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }
function post(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); try { $calificacion = new CalificacionCliente(); $calificacion->idCliente = $data['idCliente']; $calificacion->idEmpleado = $data['idEmpleado']; $calificacion->calificacion = $data['calificacion']; $calificacion->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 addgaleria(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); try { $id = $request->getAttribute("id"); $galeria = new Galeria(); $galeria->logo = $data['logo']; $galeria->idSucursal = $data['idsucursal']; $galeria->fecha = fechaHoraActual(); $galeria->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 postSucursales(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); try { $sucursal = new Sucursal(); $sucursal->nombre = $data['nombre']; $sucursal->direccion = $data['direccion']; $sucursal->latitud = $data['latitud']; $sucursal->longitud = $data['longitud']; $sucursal->idEmpresa = $data['idEmpresa']; $sucursal->save(); $respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "obj" => $data)); $response = $response->withStatus(200); } catch (Exception $err) { $respuesta = json_encode(array('msg' => "La sucursal ya existe", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }
function putFoto(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $idOferta = $request->getAttribute('id'); $data = $request->getBody(); try { $fp = fopen($idOferta . '.jpg', 'wb'); fwrite($fp, $data); fclose($fp); $fo = new FotosOferta(); $fo->foto = $rutaServidor . "fotos/" . $idOferta . ".jpg"; $fo->idOferta = $idOferta; $fo->save(); $respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "obj" => $data)); $response = $response->withStatus(200); } catch (Exception $err) { $respuesta = json_encode(array('msg' => "Error al guardar foto oferta", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }
function postCategoriasSucursal(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $id = $request->getAttribute('id'); $data = json_decode($request->getBody(), true); try { $cc = CategoriasSucursal::where('id', '=', $id)->first(); $cc->delete(); for ($i = 0; $i < count($data['categorias']); $i++) { $cc = new CategoriasSucursal(); $cc->idCategoria = $data['categorias'][$i]; $cc->idSucursal = $id; $cc->save(); } $respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "obj" => $data)); $response = $response->withStatus(200); } catch (Exception $err) { $respuesta = json_encode(array('msg' => "La empresa ya existe", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }
public function postTurnoRecurrente(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $fechaReserva = $data['fechaReserva']; $rango = $data["rango"]; $meses = $data["meses"]; $fechaFinal = strtotime("+{$meses} month", strtotime($fechaReserva)); $fechaFinal = date('Y/m/d', $fechaFinal); $datetime1 = new DateTime($fechaReserva); $datetime2 = new DateTime($fechaFinal); $interval = $datetime1->diff($datetime2); $minutosServicio = ServiciosSucursal::select("minutos")->where("idServicio", "=", $data["idServicio"])->where("idSucursal", "=", $data["idSucursal"])->first(); /* Valores de Rangos diario = 1 semanal = 2 mensual = 3 */ switch ($rango) { case '1': $tiempo = floor($interval->format('%a')); break; case '2': $tiempo = floor($interval->format('%a') / 7); break; default: $tiempo = $meses; break; } //echo $tiempo; $fecha = $fechaReserva; for ($i = 0; $i <= $tiempo; $i++) { switch ($rango) { case '1': $fechaReservaFinal = strtotime("+1 day", strtotime($fecha)); $fechaReservaFinal = date('Y/m/d', $fechaReservaFinal); break; case '2': $fechaReservaFinal = strtotime("+7 day", strtotime($fecha)); $fechaReservaFinal = date('Y/m/d', $fechaReservaFinal); break; default: $fechaReservaFinal = strtotime("+1 month", strtotime($fecha)); $fechaReservaFinal = date('Y/m/d', $fechaReservaFinal); break; } $respuesta = null; try { $turno = new Turno(); $turno->idCliente = $data['idCliente']; $turno->idEmpleado = $data['idEmpleado']; $turno->idSucursal = $data['idSucursal']; $turno->idServicio = $data['idServicio']; $turno->tiempo = 0; $turno->turno = 0; $turno->turnoReal = 0; $turno->tipoTurno = 1; $turno->estadoTurno = "SOLICITADO"; $turno->estado = "ACTIVO"; $turno->reserva = "A"; $turno->fechaReserva = $fecha; $turno->horaReserva = $data['horaReserva']; $horaInicial = $data['horaReserva']; for ($j = 0; $j < $data["cupos"]; $j++) { $segundos_horaInicial = strtotime($horaInicial); $segundos_minutoAnadir = $minutosServicio->minutos * 60; $nuevaHora = date("H:i", $segundos_horaInicial + $segundos_minutoAnadir); $horaInicial = $nuevaHora; } $turno->horaFinalReserva = $nuevaHora; $turno->save(); $fecha = $fechaReservaFinal; $respuesta = json_encode(array('msg' => "Su turno ha sido asignado satisfactoriamente.", "std" => 1, 'idTurno' => $turno->id)); $response = $response->withStatus(200); } catch (Exception $err) { $respuesta = json_encode(array('msg' => "error al pedir el turno", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } } $response->getBody()->write($respuesta); return $response; }
function claveupdate(Request $request, Response $response) { try { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $id = $request->getAttribute("id"); //$para = $request->getAttribute("email"); $empleado = Empleado::select("*")->where("id", "=", $id)->first(); $empleado->pass = sha1($data['pass']); $empleado->save(); $respuesta = json_encode(array('msg' => "Clave actualizada correctamente", "std" => 1)); $clave = $data['pass']; $titulo = utf8_encode('Clave actualizada [Turnomovil]'); $mensaje = "" . "<html>\n <head>\n <title>" . utf8_encode("Nueva contraseña registrada") . "</title>\n </head>\n <body> \n <img style='height:60px;' src='http://turnomovil.com/images/turnomovil.png' alt=''/>\n <h1>Has actualizado tu contraseña </h1><br/>\n <h4>Gracias por usar nuestros servicios</h4>\n\n <br/> \n <h4>Tu nueva contraseña es: {$clave}</h4>\n <br/>\n\n \n </body>\n </html>"; $cabeceras = 'MIME-Version: 1.0' . "\r\n"; $cabeceras .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; $cabeceras .= 'To: ' . $empleado->nombres . ' <' . $empleado->email . '>' . "\r\n"; $cabeceras .= 'From: Turnomovil.com' . "\r\n"; mail($para, $titulo, $mensaje, $cabeceras); $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; }
public function postDebug(Request $request, Response $response, $args) { $res = ["body" => $request->getBody(), "pa" => $request->getParsedBody(), "params" => $request->getParams(), "name" => $request->getParam('name')]; return $this->echoJson($response, $res); }
function agregartiempo(Request $request, Response $response) { try { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $id = $request->getAttribute("id"); $servi = ServiciosSucursal::select("*")->where("id", "=", $id)->first(); $servi->minutos = $data['minutos']; $servi->save(); $respuesta = json_encode(array('msg' => "Tiempo modificado 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); } }
function sectoresempresa(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $data = Sucursal::select("administrador.id", "administrador.nombres", "administrador.apellidos", "administrador.identificacion", "administrador.estado", "perfil.nombre as nombreperfil", "perfil.id as idperfil", "administrador.correo", "administrador.idempresa")->join("perfil", "perfil.id", "=", "administrador.idperfil")->join("perfilpermisos", "perfilpermisos.idperfil", "=", "perfil.id")->where("pass", "=", sha1($data['pass']))->where("identificacion", "=", $data['identificacion'])->where("administrador.estado", "=", "ACTIVO")->first(); $respuesta = json_encode(array('admin' => $data, "std" => 1)); if ($data == null) { $respuesta = json_encode(array('admin' => null, "std" => 0)); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }
function updateadminestadodesactivar(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); try { $id = $request->getAttribute("id"); $admin = Administrador::select("*")->where("idempresa", "=", $id)->first(); $admin->estado = $data['estado']; $admin->save(); $respuesta = json_encode(array('msg' => "Actualizado 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 calificarServicio(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $idServicio = $request->getAttribute("idServicio"); $data = json_decode($request->getBody(), true); try { $query = "INSERT INTO " . "calificacionservicio (idServicio,idEmpleado,idSucursal,calificacion) " . "VALUES (" . "{$idServicio}," . "" . $data['idEmpleado'] . "," . "" . $data['idSucursal'] . "," . "" . $data['calificacion'] . ")"; DB::statement(DB::raw($query)); $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 putfotoservidor(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); try { $id = $request->getAttribute("id"); $sector = Sector::find($id); $sector->logo = $data['logo']; $sector->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; }