/**
  * @Route("/session/result/{id}", name="session_result", requirements={"id": "\d+"})
  */
 public function resultAction(Request $request, Session $session)
 {
     $manager = $this->getDoctrine()->getManager();
     $questions = $session->getQuestions();
     $radios = array();
     $texts = array();
     foreach ($questions as $question) {
         if ($question->getScale()->getType() == 'radio') {
             $radios[] = $question;
         } else {
             if ($question->getScale()->getType() == 'text') {
                 $texts['questionTable' . $question->getId()] = $question;
             }
         }
     }
     $resultService = new Results($manager);
     $charts = $resultService->getSimplyCharts($session, $radios);
     return $this->render('SurveyBundle:session:result.html.twig', array('charts' => $charts, 'session' => $session, 'texts' => $texts));
 }
 /**
  * @Route("/ajax/survey/url", name="ajax_survey_url", condition="request.isXmlHttpRequest()")
  */
 public function ajaxSurveyUrl(Request $request)
 {
     $manager = $this->getDoctrine()->getManager();
     $id = $request->request->get('id');
     $survey = $manager->getRepository('SurveyBundle:Survey')->find($id);
     $randomString = RandomString::generate(20);
     $newUrlForSurvey = $request->getScheme() . '://' . $request->getHttpHost() . $this->generateUrl('survey_show', array('url' => $randomString));
     $url = new Session();
     $url->setName($randomString);
     $url->setSurvey($survey);
     $url->setFromDate(new \DateTime());
     $url->setActive(true);
     $url->setUrl($randomString);
     foreach ($survey->getQuestions() as $question) {
         $url->addQuestion($question);
     }
     $manager->persist($url);
     $manager->flush();
     $data = array('url' => $newUrlForSurvey);
     return new Response(json_encode($data), 200);
 }