Пример #1
0
 function postPeticion(Request $request, Response $response)
 {
     $response = $response->withHeader('Content-type', 'application/json');
     $data = json_decode($request->getBody(), true);
     try {
         $peticion = new Peticion();
         $peticion->nombre = $data['nombre'];
         $peticion->descripcion = $data['descripcion'];
         $peticion->idCategoria = $data['idCategoria'];
         $peticion->idCliente = $data['idCliente'];
         $peticion->save();
         $respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1, "obj" => $data));
         $response = $response->withStatus(200);
         //ENVIAR NOTIFICACION A EMPRESAS
         $u = new UsuarioControl();
         $dataUsuarios = $u->getIdPushByCategorias($data['idCategoria']);
         if (count($dataUsuarios) > 0) {
             $titulo = "Nueva peticion";
             $mensaje = $data['nombre'];
             $std = 1;
             enviarNotificacion($dataUsuarios, $titulo, $mensaje, $std);
         }
     } catch (Exception $err) {
         $respuesta = json_encode(array('msg' => "Error al guardar peticion", "std" => 0, "err" => $err->getMessage()));
         $response = $response->withStatus(404);
     }
     $response->getBody()->write($respuesta);
     return $response;
 }