/** * @Route("/student-{id}/remove-wish-{wish}", requirements={"id" = "\d+", "wish" = "\d+"}, name="admin_student_removewish") */ public function studentRemoveWishAction(Student $student, $wish) { $em = $this->getDoctrine()->getManager(); foreach ($student->getWishes() as $w) { $p = $w->getPriority(); if ($p == $wish) { $em->remove($w); } else { if ($p > $wish) { $w->setPriority($p - 1); } } } $em->flush(); return $this->redirect($this->generateUrl('admin_student_wishes', array('id' => $student->getId()))); }
/** * @Route("/student-{id}-{auth}/remove-wish-{wish}", requirements={"id" = "\d+", "wish" = "\d+"}, name="student_removewish") */ public function removeWishAction(Student $student, $auth, $wish) { if (strtolower($student->getAuth()) != strtolower($auth)) { return $this->redirect($this->generateUrl('student_loginreset')); } else { if ($student->getState() != 0) { return $this->redirect($this->generateUrl('student_login', array('id' => $student->getId(), 'auth' => $auth))); } } $em = $this->getDoctrine()->getManager(); foreach ($student->getWishes() as $w) { $p = $w->getPriority(); if ($p == $wish) { $em->remove($w); } else { if ($p > $wish) { $w->setPriority($p - 1); } } } $em->flush(); return $this->redirect($this->generateUrl('student_wishes', array('id' => $student->getId(), 'auth' => $auth))); }