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; + + + } + + } + }