/** * @Route("/student-{id}/wishes", requirements={"id" = "\d+"}, name="admin_student_wishes") * @Template() */ public function studentWishesAction(Student $student) { $wish = new Wish(); $wish->setStudent($student); $wish->setPriority(count($student->getWishes()) + 1); $form = $this->createForm(new WishType(), $wish); $request = $this->get('request'); if ($request->getMethod() == 'POST') { $form->submit($request); if ($form->isValid()) { $already = false; foreach ($student->getWishes() as $w) { if ($w->getUniversity()->getId() == $wish->getUniversity()->getId()) { $already = true; break; } } if (!$already) { $em = $this->getDoctrine()->getManager(); $em->persist($wish); $em->flush(); } else { $this->get('session')->getFlashBag()->add('error', 'Il y a déjà un voeu pour cette université'); } return $this->redirect($this->generateUrl('admin_student_wishes', array('id' => $student->getId()))); } } return array('student' => $student, 'form' => $form->createView()); }
/** * @Route("/student-{id}-{auth}/wishes", requirements={"id" = "\d+"}, name="student_wishes") * @Template() */ public function wishesAction(Student $student, $auth) { if (strtolower($student->getAuth()) != strtolower($auth)) { return $this->redirect($this->generateUrl('student_loginreset')); } else { if ($student->getState() != 0 && $student->getState() != 1) { return $this->redirect($this->generateUrl('student_login', array('id' => $student->getId(), 'auth' => $auth))); } } if ($student->getState() == 0) { $wish = new Wish(); $wish->setStudent($student); $wish->setPriority(count($student->getWishes()) + 1); $form = $this->createForm(new WishType(array('activeOnly' => true)), $wish); $request = $this->get('request'); if ($request->getMethod() == 'POST') { $form->submit($request); if ($form->isValid()) { $already = false; foreach ($student->getWishes() as $w) { if ($w->getUniversity()->getId() == $wish->getUniversity()->getId()) { $already = true; break; } } if (!$already) { $em = $this->getDoctrine()->getManager(); $em->persist($wish); $em->flush(); } else { $this->get('session')->getFlashBag()->add('error', 'Vous avez déjà un voeu pour cette université'); } return $this->redirect($this->generateUrl('student_wishes', array('id' => $student->getId(), 'auth' => $auth))); } } return array('student' => $student, 'form' => $form->createView()); } else { return array('student' => $student); } }