public function replyAction()
 {
     $logger = $this->get('logger');
     $request = $this->getRequest();
     if ($request->isXmlHttpRequest()) {
         try {
             $em = $this->getDoctrine()->getManager();
             $text = $request->request->get('_reply');
             $user = $this->get('security.context')->getToken()->getUser();
             $applicationid = $request->request->get('_application');
             $application = $em->getRepository('MaximModuleApplicationBundle:UserApplication')->findOneBy(array("id" => $applicationid));
             if ($user) {
                 if ($this->isApplicationOwner($application, $user)) {
                     $reply = new ApplicationReply();
                     $reply->setText($text);
                     $reply->setUser($user);
                     $reply->setApplication($application);
                     $em->persist($reply);
                     $em->flush();
                     $output = array("success" => true, "message" => "Your reply has been added");
                 } else {
                     $output = array("success" => false, "message" => "This is not your application");
                 }
             } else {
                 $output = array("success" => false, "message" => "We were unable to find the user account");
             }
         } catch (\Exception $ex) {
             $logger->error("APPLICATION: " . $ex->getMessage());
             $output = array("success" => false, "message" => "An error has occured while adding your reply, please try again later");
         }
         return new Response(json_encode($output));
     }
 }
 public function applicationReplyAction()
 {
     $request = $this->getRequest();
     $logger = $this->get('logger');
     if ($request->isXmlHttpRequest()) {
         try {
             $em = $this->getDoctrine()->getManager();
             $bbcode = $this->get('bbcode.helper');
             $text = $request->request->get('_reply');
             $user = $this->get('security.context')->getToken()->getUser();
             $applicationid = $request->request->get('_application');
             $application = $em->getRepository('MaximModuleApplicationBundle:UserApplication')->findOneBy(array("id" => $applicationid));
             $reply = new ApplicationReply();
             $reply->setText($bbcode->parse($text));
             $reply->setUser($user);
             $reply->setApplication($application);
             //$application->setStatus("Waiting from a response from the ticket owner");
             $em->persist($reply);
             $em->flush();
             $output = array("success" => true, "message" => "Your reply has been added");
         } catch (\Exception $ex) {
             $logger->error("APPLICATION: " . $ex->getMessage());
             $output = array("success" => false, "message" => "An error has occured while adding your reply, please try again later");
         }
         return new Response(json_encode($output));
     }
 }