Example #1
0
 /**
  * Changes status to accepted by student and displays the application
  *
  * @Route("/{id}/acceptByStudent", name="application_accept_by_student")
  * @Method({"GET", "POST"})
  */
 public function acceptByStudentAction(Request $request, Application $application)
 {
     //double check mentor is doing this
     $currentUser = $this->get('security.token_storage')->getToken()->getUser();
     if ($application->getStudent()->getId() == $currentUser->getStudent()->getId()) {
         $application->setState(3);
         //aceptado por el estudiante
         $application->setLastUpdateDate(new \DateTime());
         $em = $this->getDoctrine()->getManager();
         $notification = new Notification();
         $mentor = $application->getOportunityResearch()->getMainMentor();
         $reciever = $mentor->getUser();
         $sender = $application->getStudent()->getUser();
         $message = "Felicitaciones, su aplicacion a la oportunidad " . $application->getOportunityResearch()->getName() . " ha sido aceptada por el alumno, feliz investigación";
         $notification->sendNotification($sender, $reciever, $message);
         $em = $this->getDoctrine()->getManager();
         //como fue aceptado por ambos, creamos la investigación oficial en el sistema
         $research = new Research();
         //cargamos los datos existentes
         $research->populateFromOportunity($application->getOportunityResearch());
         $research->setStudent($application->getStudent());
         $research->setApplication($application);
         //calculamos la sigla
         $em = $this->getDoctrine()->getManager();
         $classCodeArray = $em->getRepository('BackendBundle:Application')->getClassCode($application->getOportunityResearch(), $application->getStudent());
         $research->setInitialsCode($classCodeArray['initialsCode']);
         $research->setnumbersCode($classCodeArray['numbersCode']);
         /* si encontramos un ERR0000, enviamos un mail al administrador */
         if ($classCodeArray['initialsCode'] == "ERR" && $classCodeArray['numbersCode'] == "0000") {
             $application->setState(9);
             //aceptado por el estudiante
             $emailsArray = $em->getRepository('BackendBundle:User')->getAdminsMailArray();
             //enviar por email
             $today = date("d-M-Y");
             $url = $this->getParameter('web_dir') . '/research/' . $research->getId() . '/edit';
             $url2 = $this->getParameter('web_dir') . '/application/' . $application->getId() . '/edit';
             $message = \Swift_Message::newInstance()->setSubject('Error en una nueva sigla')->setFrom('*****@*****.**')->setTo($emailsArray)->setBody('<html>' . ' <head></head>' . ' <body>' . 'Hola, se acaba de crear una investigación con error en su sigla, por favor revisar' . ' <br> ' . 'Para revisar la investigación, haz click <a href="' . $url . '">aquí</a><br>' . 'Luego revise la aplicacion y dejela en el estado 3 "Confirmado por ambos, en proceso", haz click <a href="' . $url2 . '">aquí</a> para ver la aplicacion<br>' . 'Atte. <br> Gestión IPre' . '<br><br><br>Por favor, no responda este email</body>' . '</html>', 'text/html');
             $this->get('mailer')->send($message);
         }
         /* fin email */
         $section = $em->getRepository('BackendBundle:Research')->getSection($classCodeArray, $research);
         $research->setSection($section);
         $em = $this->getDoctrine()->getManager();
         $em->persist($application);
         $em->persist($notification);
         $em->persist($research);
         $em->flush();
     }
     return $this->redirectToRoute('application_show', array('id' => $application->getId()));
 }