Actualizacion

parent 50bdec78
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block head %} {% block head %}
{% if idp == "none" %} {% if idp == "none" %}
<meta property="og:url" content="http://wooadmin.gearlabs.cl/test/sharer?idp={{idp}}&fa={{fa}}" /> <meta property="og:url" content="http://127.0.0.1:8000/nutrapharm/index?idp={{idp}}&fa={{fa}}" />
<meta property="og:type" content="website" /> <meta property="og:type" content="website" />
<meta property="og:title" content="NutraPharm" /> <meta property="og:title" content="NutraPharm" />
<meta property="og:description" content="Producto Nutrapharm" /> <meta property="og:description" content="Producto Nutrapharm" />
<meta property="og:image:type" content="image/jpg"/> <meta property="og:image:type" content="image/png"/>
<meta property="og:image:width" content="1200" /> <meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" /> <meta property="og:image:height" content="630" />
<meta property="og:image" content="https://www.tvn.cl/incoming/esmeralda-fernando-godoyjpg-4187151/alternates/BASE_LANDSCAPE_SMALL/Esmeralda%20fernando%20godoy."/> <meta property="og:image" content="https://www.tvn.cl/incoming/esmeralda-fernando-godoyjpg-4187151/alternates/BASE_LANDSCAPE_SMALL/Esmeralda%20fernando%20godoy."/>
{#<link rel="image_src" href="https://www.tvn.cl/incoming/esmeralda-fernando-godoyjpg-4187151/alternates/BASE_LANDSCAPE_SMALL/Esmeralda%20fernando%20godoy.jpg">#} {#<link rel="image_src" href="https://www.tvn.cl/incoming/esmeralda-fernando-godoyjpg-4187151/alternates/BASE_LANDSCAPE_SMALL/Esmeralda%20fernando%20godoy.jpg">#}
{%else%} {%else%}
<meta property="og:url" content="http://wooadmin.gearlabs.cl/test/sharer?idp={{idp}}&fa={{fa}}" /> <meta property="og:url" content="http://127.0.0.1:8000/nutrapharm/index?idp={{idp}}&fa={{fa}}" />
<meta property="og:type" content="website" /> <meta property="og:type" content="website" />
<meta property="og:title" content="NutraPharm Comparacion" /> <meta property="og:title" content="NutraPharm Comparacion" />
<meta property="og:description" content="Producto Nutrapharm - Foto " /> <meta property="og:description" content="Producto Nutrapharm - Foto " />
<meta property="og:image:type" content="image/jpg"/> <meta property="og:image:type" content="image/png"/>
<meta property="og:image:width" content="1200" /> <meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" /> <meta property="og:image:height" content="630" />
<meta property="og:image" content="https://www.tvn.cl/incoming/esmeralda-fernando-godoyjpg-4187151/alternates/BASE_LANDSCAPE_SMALL/Esmeralda%20fernando%20godoy."> <meta property="og:image" content="http://127.0.0.1:8000/nutrapharm/get/photo?file_name={{idp}}.png"/>
{#<meta property="og:image" content="https://www.tvn.cl/incoming/esmeralda-fernando-godoyjpg-4187151/alternates/BASE_LANDSCAPE_SMALL/Esmeralda%20fernando%20godoy.">#}
{#<link rel="image_src" href="https://www.24horas.cl/noticiasbbc/ilustracion-hombre-en-la-prehistoria-4193967/ALTERNATES/w620h350/Ilustraci%C3%B3n%20hombre%20en%20la%20prehistoria.jpg"/>#} {#<link rel="image_src" href="https://www.24horas.cl/noticiasbbc/ilustracion-hombre-en-la-prehistoria-4193967/ALTERNATES/w620h350/Ilustraci%C3%B3n%20hombre%20en%20la%20prehistoria.jpg"/>#}
{%endif%} {%endif%}
<link href="{{asset('frontend/css/camara.css')}}" rel="stylesheet" /> <link href="{{asset('frontend/css/camara.css')}}" rel="stylesheet" />
...@@ -26,7 +27,7 @@ ...@@ -26,7 +27,7 @@
{% block body %} {% block body %}
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
{%if idp == "none" and fa == 0%} {%if idp == "none" and fa == 1%}
<div class="panel-body"> <div class="panel-body">
<div class="form-group"> <div class="form-group">
<label class="col-md-3 control-label">Nombre</label> <label class="col-md-3 control-label">Nombre</label>
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
</div> </div>
</div> </div>
{%else%} {%else%}
<img src="http://127.0.0.1:8000/nutrapharm/get/photo?file_name=cmauriciodc1.png" />
<div class="form-group"> <div class="form-group">
<label class="col-md-3 control-label">Comentarios</label> <label class="col-md-3 control-label">Comentarios</label>
<div class="col-md-8"> <div class="col-md-8">
...@@ -89,7 +91,7 @@ ...@@ -89,7 +91,7 @@
</div> </div>
</div> </div>
{%if idp == "none" and fa == 0%} {%if idp == "none" and fa == 1%}
<div class="row"> <div class="row">
<div class="form-group"> <div class="form-group">
<button id="btnGuardar">Guardar</button> <button id="btnGuardar">Guardar</button>
...@@ -107,6 +109,8 @@ ...@@ -107,6 +109,8 @@
<script> <script>
var imagenSubida = false; var imagenSubida = false;
var imagenTomada = false; var imagenTomada = false;
var tipoUsuarioFormulario = 1; //Por defecto
var usuarioNutraPharm = null; //por defecto
</script> </script>
<script> <script>
var url = 'http://wooadmin.gearlabs.cl/test/sharer?idp={{idp}}&fa={{fa}}'; var url = 'http://wooadmin.gearlabs.cl/test/sharer?idp={{idp}}&fa={{fa}}';
...@@ -207,15 +211,26 @@ ...@@ -207,15 +211,26 @@
var url = "{{ path('nutrapharm_upload') }}"; var url = "{{ path('nutrapharm_upload') }}";
var formData = new FormData(); var formData = new FormData();
$("#btnGuardar").prop("disabled", true); $("#btnGuardar").prop("disabled", true);
console.log(this.file); console.log(this.file);
if (this.file != null) { if (this.file != null) {
formData.append("imagen", this.file, this.getName()); formData.append("imagen", this.file, this.getName());
} }
{% if idp == "none" and fa == 1%}
formData.append("nombreUsuario", $("#nombreUsuario").val()); formData.append("nombreUsuario", $("#nombreUsuario").val());
formData.append("mailUsuario", $("#mailUsuario").val()); formData.append("mailUsuario", $("#mailUsuario").val());
formData.append("comentarioFotoUsuario", $("#comentarioFotoUsuario").val()); formData.append("comentarioFotoUsuario", $("#comentarioFotoUsuario").val());
formData.append("tipoUsuarioFormulario", tipoUsuarioFormulario);
formData.append("usuarioNutraPharm", usuarioNutraPharm);
formData.append("upload_file", true); formData.append("upload_file", true);
{% elseif idp != "none" and fa == 0 %}
formData.append("usuarioNutraPharm", "{{idp}}");
formData.append("comentarioFotoUsuario", $("#comentarioFotoUsuario").val());
formData.append("usuarioNutraPharm", usuarioNutraPharm);
formData.append("upload_file", true);
{%endif%}
$.ajax $.ajax
({ ({
type: "POST", type: "POST",
...@@ -238,7 +253,9 @@ ...@@ -238,7 +253,9 @@
success: function (data) { success: function (data) {
console.log(data); console.log(data);
console.log("Guardado"); console.log("Guardado");
("#shareButtonContainer").show(); {% if idp != "none" and fa == 0%}
$("#shareButtonContainer").show();
{%endif%}
}, },
complete: function (data) { complete: function (data) {
$("#btnGuardar").prop("disabled", false); $("#btnGuardar").prop("disabled", false);
......
# Learn more about services, parameters and containers at # Learn more about services, parameters and containers at
# https://symfony.com/doc/current/service_container.html # https://symfony.com/doc/current/service_container.html
parameters: parameters:
#parameter_name: value parameters:
upload_dir: '../web/uploads/users'
services: services:
#service_name:
# class: AppBundle\Directory\ClassName
# arguments: ['@another_service_name', 'plain_value', '%parameter_name%']
...@@ -6,4 +6,9 @@ use AppBundle\Model\om\BaseUsuarioNutrapharm; ...@@ -6,4 +6,9 @@ use AppBundle\Model\om\BaseUsuarioNutrapharm;
class UsuarioNutrapharm extends BaseUsuarioNutrapharm class UsuarioNutrapharm extends BaseUsuarioNutrapharm
{ {
const ESTADO_FOTO_INICIAL = 1;
const ESTADO_FOTO_ACTUALIZADA = 2;
const ESTADO_FOTO_FINAL = 3;
const ELIMINADO_TRUE = 1;
const ELIMINADO_FALSE = 0;
} }
...@@ -5,17 +5,23 @@ namespace NutrapharmBundle\Controller; ...@@ -5,17 +5,23 @@ namespace NutrapharmBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Treinetic\ImageArtist\lib\Overlays\Overlay; use Treinetic\ImageArtist\lib\Overlays\Overlay;
use Treinetic\ImageArtist\lib\Text\Color; use Treinetic\ImageArtist\lib\Text\Color;
use Treinetic\ImageArtist\lib\Shapes\PolygonShape; use Treinetic\ImageArtist\lib\Shapes\PolygonShape;
use Treinetic\ImageArtist\lib\Commons\Node; use Treinetic\ImageArtist\lib\Commons\Node;
use Treinetic\ImageArtist\lib\Image; use Treinetic\ImageArtist\lib\Image;
use Treinetic\ImageArtist\lib\Shapes\Square; use Treinetic\ImageArtist\lib\Shapes\Square;
use AppBundle\Model\UsuarioNutrapharm;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\StreamedResponse;
class DefaultController extends Controller { class DefaultController extends Controller {
public function indexAction(Request $request) { public function indexAction(Request $request) {
//$log = Utiles::setLog('NutrapharmBundle\Controller\DefaultController:indexAction', 'nutrapharm/index'); //$log = Utiles::setLog('NutrapharmBundle\Controller\DefaultController:indexAction', 'nutrapharm/index');
$error = 0; $error = 0;
$idPersona = $request->get("idp", null); $idPersona = $request->get("idp", null);
$firstAttempt = $request->get("fa", 1); $firstAttempt = $request->get("fa", 1);
...@@ -31,11 +37,97 @@ class DefaultController extends Controller { ...@@ -31,11 +37,97 @@ class DefaultController extends Controller {
} }
public function uploadAction(Request $request) { public function uploadAction(Request $request) {
print_r($request, true); $log = "";
$jResponse = new JsonResponse(); $ua = $request->headers->get('User-Agent');
$jResponse->setStatusCode(JsonResponse::HTTP_OK, '- OK'); $ip = $request->getClientIp();
$jResponse->setData("OK"); $file = $request->files->get('imagen');
return $jResponse; $tipo = $request->get("tipoUsuarioFormulario", null);
$nombre = $request->get("nombreUsuario", null);
$correo = $request->get("mailUsuario", null);
$comentario = $request->get("comentarioFotoUsuario", null);
$usuarioNutraPharm = $request->get("usuarioNutraPharm", null);
//validacion datos entrada
if (empty($file)) {
return new JsonResponse(array("msg" => "No se subio una imagen", "tipo" => UsuarioNutrapharm::ESTADO_FOTO_INICIAL), Response::HTTP_BAD_REQUEST, ['content-type' => 'text/plain']);
}
if ($tipo == UsuarioNutrapharm::ESTADO_FOTO_INICIAL) { //Usuario Nuevo
//$filename = $file->getClientOriginalName();
$usuarioNutraPharm = new UsuarioNutrapharm();
$usuarioNutraPharm->setUnuNombre($nombre);
$usuarioNutraPharm->setUnuCorreo($correo);
$usuarioNutraPharm->setUnuComentarioInicial($comentario);
$usuarioNutraPharm->setUnuUa($ua);
$usuarioNutraPharm->setUnuIp($ip);
$usuarioNutraPharm->setUnuEstado(UsuarioNutrapharm::ESTADO_FOTO_INICIAL);
$usuarioNutraPharm->setUnuEliminado(UsuarioNutrapharm::ELIMINADO_FALSE);
$usuarioNutraPharm->save();
$uploadDir = $this->getParameter('upload_dir');
$idNutrapharm = explode("@", $usuarioNutraPharm->getUnuCorreo())[0] . $usuarioNutraPharm->getUnuId();
$usuarioNutraPharm->setUnuPathFotoInicial($uploadDir . '/' . $idNutrapharm);
$usuarioNutraPharm->setUnuIdNutrapharm($idNutrapharm);
$usuarioNutraPharm->save();
$filename = $idNutrapharm . ".png";
$file->move($uploadDir, $filename);
return new JsonResponse(array("msg" => "La informacion ha sido ingresada con exito!", "tipo" => UsuarioNutrapharm::ESTADO_FOTO_ACTUALIZADA), Response::HTTP_OK, ['content-type' => 'text/plain']);
} else if ($tipo == UsuarioNutrapharm::ESTADO_FOTO_ACTUALIZADA && $usuarioNutraPharm != null) {
//Actualizar informacion ya existente
} elseif ($tipo == UsuarioNutrapharm::ESTADO_FOTO_FINAL && $usuarioNutraPharm != null) {
//Unir fotos del usuario en base al usuarioNutraPharm
}
} }
public function downloadAction(Request $request) {
$file_name = $request->get("file_name", null);
$base_path = $this->getParameter('upload_dir');
$full_path = $base_path . '/' . $file_name;
$fs = new Filesystem();
if (!$fs->exists($full_path)) {
throw $this->createNotFoundException();
}
$file_name = basename($full_path);
$mime_type = $this->getMimeType($full_path);
$file = readfile($full_path);
$headers = array(
'Content-Type' => $mime_type,
'Content-Disposition' => 'inline; filename="' . $file_name . '"');
return new Response($file, 200, $headers);
}
public function createSendFileResponseAction(Request $request) {
$file_name = $request->get("file_name", null);
$base_path = $this->getParameter('upload_dir');
$full_path = $base_path . '/' . $file_name;
$file = readfile($full_path);
$response = StreamedResponse::create(function() use ($file) {
readfile($file);
});
//$response->headers->set('Content-Type', $file->getMimeType());
return $response;
}
protected function getMimeType($file) {
if ('jpg' === substr($file, -3)) {
$best_guess = 'jpeg';
} else {
$guesser = MimeTypeGuesser::getInstance();
$best_guess = $guesser->guess($file);
}
return $best_guess;
}
} }
\ No newline at end of file
...@@ -5,3 +5,9 @@ nutrapharm_homepage: ...@@ -5,3 +5,9 @@ nutrapharm_homepage:
nutrapharm_upload: nutrapharm_upload:
path: /upload/photo path: /upload/photo
defaults: { _controller: NutrapharmBundle:Default:upload } defaults: { _controller: NutrapharmBundle:Default:upload }
nutrapharm_get_file:
path: /get/photo
defaults: { _controller: NutrapharmBundle:Default:createSendFileResponse }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment