Example #1
0
 /**
  * Creates a new Leave entity.
  *
  * @Secure(roles="ROLE_SUPER_USER,ROLE_RECORD_CREATE")
  * @Route("/addleave", name="leave_create")
  * @Method("POST")
  * @Template("HrisLeaveBundle:Leave:new.html.twig")
  */
 public function createAction(Request $request)
 {
     $entity = new LeaveType();
     $form = $this->createForm(new LeaveTypeType(), $entity);
     $form->bind($request);
     $user = $this->container->get('security.context')->getToken()->getUser();
     $field = $this->getDoctrine()->getManager()->getRepository('HrisFormBundle:Field')->findOneBy(array('id' => 136));
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $fieldoption = new FieldOption();
         $formData = $form->getData();
         $fieldoption->setDescription($formData->getDescription());
         $fieldoption->setField($field);
         $fieldoption->setHasTraining(True);
         $fieldoption->setValue($formData->getName());
         $entity->setRecord($fieldoption);
         $em->persist($fieldoption);
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('new_leave', array('message' => 'Added Successful')));
     }
     return array('message' => '', 'form' => $form->createView());
 }