Commit dc15f7b677b09036d2d4a0249aeaa9dbf5514986
1 parent
920d3e4181
Exists in
master
ya registra a los nuevos tutores a añadir de parte del coordinador
Showing
2 changed files
with
68 additions
and
0 deletions
Show diff stats
app/Resources/views/cea/ascenso_mostar.html.twig
... | ... | @@ -288,6 +288,27 @@ |
288 | 288 | }); |
289 | 289 | |
290 | 290 | |
291 | + | |
292 | + $( "#añadirJurados" ).click(function() { | |
293 | + alert('hola'); | |
294 | + $.ajax({ | |
295 | + method: "POST", | |
296 | + url: "{{ url('ajax_adicionar_tutor') }}", | |
297 | + async: true, | |
298 | + cache: false, | |
299 | + data: ({ jurados: $("#add_tutor_tutores_ascenso").val(), ascensoId: {{ ascenso.id }} }), | |
300 | + success: function (data) { | |
301 | + console.log(data); | |
302 | + | |
303 | + | |
304 | + }, | |
305 | + error: function (XMLHttpRequest, textStatus, errorThrown) { | |
306 | + console.log(errorThrown); | |
307 | + | |
308 | + } | |
309 | + | |
310 | + }); | |
311 | + }); | |
291 | 312 | |
292 | 313 | |
293 | 314 | </script> | ... | ... |
src/AppBundle/Controller/AjaxController.php
... | ... | @@ -18,6 +18,7 @@ use Symfony\Component\Serializer\Encoder\JsonEncoder; |
18 | 18 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; |
19 | 19 | use Symfony\Component\HttpFoundation\Request; |
20 | 20 | use AppBundle\Entity\TutoresAscenso; |
21 | +use AppBundle\Entity\Ascenso; | |
21 | 22 | |
22 | 23 | |
23 | 24 | |
... | ... | @@ -183,4 +184,50 @@ class AjaxController extends Controller { |
183 | 184 | |
184 | 185 | } |
185 | 186 | |
187 | + | |
188 | + | |
189 | + /** | |
190 | + * @Route("/ajax/adicionar_tutor", name="ajax_adicionar_tutor") | |
191 | + * @Method({"POST"}) | |
192 | + */ | |
193 | + public function adicionarTutorAction(Request $request){ | |
194 | + | |
195 | + if($request->isXmlHttpRequest()){ | |
196 | + $encoders = array(new JsonEncoder()); | |
197 | + $normalizers = array(new ObjectNormalizer()); | |
198 | + | |
199 | + $serializer = new Serializer($normalizers, $encoders); | |
200 | + | |
201 | + $jurados = filter_input(INPUT_POST, 'jurados', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); | |
202 | + $ascensoId = filter_input(INPUT_POST, 'ascensoId', FILTER_SANITIZE_SPECIAL_CHARS); | |
203 | + | |
204 | + | |
205 | + $ascenso = $this->getDoctrine()->getRepository("AppBundle:Ascenso")->findOneById($ascensoId); | |
206 | + | |
207 | + foreach ($jurados as $jurado){ | |
208 | + $adicionar = $this->getDoctrine()->getRepository("AppBundle:TutoresAscenso")->findOneById($jurado); | |
209 | + $ascenso->addTutoresAscenso($adicionar); | |
210 | + } | |
211 | + | |
212 | + | |
213 | + | |
214 | + $em = $this->getDoctrine()->getManager(); | |
215 | + $em->persist($ascenso); | |
216 | + $em->flush(); | |
217 | + | |
218 | + $response = new JsonResponse(); | |
219 | + $response->setStatusCode(200); | |
220 | + $response->setData(array( | |
221 | + 'response' => 'success', | |
222 | + 'jurados' => $jurados, | |
223 | + 'ascenso' => $ascensoId | |
224 | + )); | |
225 | + | |
226 | + return $response; | |
227 | + | |
228 | + | |
229 | + } | |
230 | + | |
231 | + } | |
232 | + | |
186 | 233 | } | ... | ... |