Example #1
0
 /**
  * Creates a new Application entity.
  *
  * @Route("/new", name="application_new")
  * @Method({"GET", "POST"})
  */
 public function newAction(Request $request)
 {
     $currentUser = $this->get('security.token_storage')->getToken()->getUser();
     $oportunityId = $this->get('request')->request->get('oportunityId');
     $em = $this->getDoctrine()->getManager();
     if ($em->getRepository('BackendBundle:Application')->itExists($currentUser->getStudent()->getId(), $oportunityId)) {
         $application = $em->getRepository('BackendBundle:Application')->findOneByStudentIdAndOportunityId($currentUser->getStudent()->getId(), $oportunityId);
         return $this->redirectToRoute('application_show', array('id' => $application->getId()));
     }
     $application = new Application();
     $application->setStudent($currentUser->getStudent());
     if (is_null($oportunityId)) {
         $app = $this->get('request')->request->get('application');
         $oportunityId = $app['oportunityResearch'];
     } else {
         $oportunity = $em->getRepository('BackendBundle:OportunityResearch')->find($oportunityId);
         $application->setOportunityResearch($oportunity);
     }
     $form = $this->createForm('BackendBundle\\Form\\ApplicationType', $application, array('choices_array' => array('Postulando' => 1), 'oportunityId' => $oportunityId, 'studentId' => $currentUser->getStudent()->getId()));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         /********** ESTO ES TEMPORAL HASTA QUE SIDING PROVEA RECURSOS 746E ***************/
         /*
           //notificacion de systema a mentor
           $notification1 = new Notification();
           $mentor = $application->getOportunityResearch()->getMainMentor();
           $reciever = $mentor->getUser();
           $message = "Un nuevo alumno ha postulado a su oportunidad de investigación: ".$application->getOportunityResearch()->getName().
           " porfavor pongase en contacto con el para coordinar su reunión.".
           '@<'.$currentUser->getId().'>@';
           $notification1->sendSystemMessage($reciever, $message);  
         
           //notificacion de systema a estudiante
           $notification2 = new Notification();
           $reciever = $application->getStudent()->getUser();
           $message = "Felicitaciones, su postulación a la oportunidad de investigación: ".$application->getOportunityResearch()->getName()." ha sido ingresada y notifiacada al mentor, este se pondrá en contacto con usted para coordinar su reunión";
           $notification2->sendSystemMessage($reciever, $message);  
         */
         $application->setState(10);
         /********** ESTO ES TEMPORAL HASTA QUE SIDING PROVEA RECURSOS ***************/
         $em = $this->getDoctrine()->getManager();
         $em->persist($application);
         /********** ESTO ES TEMPORAL HASTA QUE SIDING PROVEA RECURSOS 746E ***************/
         //$em->persist($notification1);
         //$em->persist($notification2);
         /********** ESTO ES TEMPORAL HASTA QUE SIDING PROVEA RECURSOS ***************/
         $em->flush();
         return $this->redirectToRoute('application_show', array('id' => $application->getId()));
     }
     return $this->render('application/new.html.twig', array('application' => $application, 'form' => $form->createView()));
 }