From dc15f7b677b09036d2d4a0249aeaa9dbf5514986 Mon Sep 17 00:00:00 2001 From: wilmer Date: Tue, 7 Feb 2017 10:03:31 -0400 Subject: [PATCH] =?UTF-8?q?ya=20registra=20a=20los=20nuevos=20tutores=20a?= =?UTF-8?q?=20a=C3=B1adir=20de=20parte=20del=20coordinador?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Resources/views/cea/ascenso_mostar.html.twig | 21 +++++++++++ src/AppBundle/Controller/AjaxController.php | 47 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/app/Resources/views/cea/ascenso_mostar.html.twig b/app/Resources/views/cea/ascenso_mostar.html.twig index dfb3a22..6d0273a 100644 --- a/app/Resources/views/cea/ascenso_mostar.html.twig +++ b/app/Resources/views/cea/ascenso_mostar.html.twig @@ -288,6 +288,27 @@ }); + + $( "#aƱadirJurados" ).click(function() { + alert('hola'); + $.ajax({ + method: "POST", + url: "{{ url('ajax_adicionar_tutor') }}", + async: true, + cache: false, + data: ({ jurados: $("#add_tutor_tutores_ascenso").val(), ascensoId: {{ ascenso.id }} }), + success: function (data) { + console.log(data); + + + }, + error: function (XMLHttpRequest, textStatus, errorThrown) { + console.log(errorThrown); + + } + + }); + }); diff --git a/src/AppBundle/Controller/AjaxController.php b/src/AppBundle/Controller/AjaxController.php index 25391f4..93158dc 100644 --- a/src/AppBundle/Controller/AjaxController.php +++ b/src/AppBundle/Controller/AjaxController.php @@ -18,6 +18,7 @@ use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\HttpFoundation\Request; use AppBundle\Entity\TutoresAscenso; +use AppBundle\Entity\Ascenso; @@ -183,4 +184,50 @@ class AjaxController extends Controller { } + + + /** + * @Route("/ajax/adicionar_tutor", name="ajax_adicionar_tutor") + * @Method({"POST"}) + */ + public function adicionarTutorAction(Request $request){ + + if($request->isXmlHttpRequest()){ + $encoders = array(new JsonEncoder()); + $normalizers = array(new ObjectNormalizer()); + + $serializer = new Serializer($normalizers, $encoders); + + $jurados = filter_input(INPUT_POST, 'jurados', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); + $ascensoId = filter_input(INPUT_POST, 'ascensoId', FILTER_SANITIZE_SPECIAL_CHARS); + + + $ascenso = $this->getDoctrine()->getRepository("AppBundle:Ascenso")->findOneById($ascensoId); + + foreach ($jurados as $jurado){ + $adicionar = $this->getDoctrine()->getRepository("AppBundle:TutoresAscenso")->findOneById($jurado); + $ascenso->addTutoresAscenso($adicionar); + } + + + + $em = $this->getDoctrine()->getManager(); + $em->persist($ascenso); + $em->flush(); + + $response = new JsonResponse(); + $response->setStatusCode(200); + $response->setData(array( + 'response' => 'success', + 'jurados' => $jurados, + 'ascenso' => $ascensoId + )); + + return $response; + + + } + + } + } -- 2.0.0