/** * @param Test $test * @param Explanation $explanation * @return boolean */ public function checkExplanation(Test $test, Explanation $explanation) { if ($this->findExplanation($explanation->getMinRating(), $test) != null or $this->findExplanation($explanation->getMaxRating(), $test) != null) { return true; } return false; }
/** * @Security("has_role('ROLE_SUPER_ADMIN')") * @Route("/testid{id}/test/addExplanation", name="addExplanation") */ public function addExplanationAction(Request $request, $id) { $test = $this->getDoctrine()->getRepository('AppBundle:Test')->find($id); $explanation = new Explanation(); $explanation->setDescription($request->get('_description')); $explanation->setMinRating($request->get('_minRating')); $explanation->setMaxRating($request->get('_maxRating')); if ($this->get('calculate')->checkExplanation($test, $explanation)) { return $this->redirectToRoute('testpage', array('id' => $test->getId())); } $test->addExplanation($explanation); $explanation->setTest($test); $em = $this->getDoctrine()->getManager(); $em->persist($explanation); $em->persist($test); $em->flush(); return $this->redirectToRoute('testpage', array('id' => $test->getId())); }