public function userRegisterAction(Request $request)
 {
     $categories = $this->getDoctrine()->getRepository('JobPortalAdminBundle:Categories')->findBy(array('isDeleted' => '1', 'status' => '1'));
     if ($request->getMethod() == 'POST') {
         if ($_POST['g-recaptcha-response'] != '') {
             $user = new Users();
             $password = chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90));
             $user->setName($_POST['name']);
             $user->setEmail($_POST['email']);
             $user->setPhone($_POST['phone']);
             $user->setPassword(md5($password));
             $user->setStatus(1);
             $user->setIsDeleted(1);
             $em = $this->getDoctrine()->getManager();
             $em->persist($user);
             $em->flush();
             /* User mail password */
             $to = $_POST['email'];
             $subject = 'Inscription Courrier';
             $message = 'Merci pour linscription dans notre site Web. Votre mot de passe une fois de connexion est ' . $password;
             $headers = 'From: info@jobportal.com' . "\r\n" . 'Reply-To: info@jobportal.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
             mail($to, $subject, $message, $headers);
             /* User mail password end */
             foreach ($_POST['category'] as $catg) {
                 $CategoryUserMappings = new CategoryUserMappings();
                 $CategoryUserMappings->setUserId($user->getId());
                 $CategoryUserMappings->setCategoryId($catg);
                 $em->persist($CategoryUserMappings);
             }
             $em->flush();
             /* candidate Session Data Set */
             $candidate_session_array = array('login_candidate_id' => $user->getId(), 'login_candidate_name' => $_POST['name']);
             $this->get('session')->set('candidatedata', $candidate_session_array);
             /* candidate Session Data Set End */
             return new RedirectResponse($this->generateUrl('chage_password'));
         } else {
             return $this->render('JobPortalFrontBundle:Users:userRegister.html.php', array('categories' => $categories, 'captach_code' => 'Captcha Invalide'));
         }
     } else {
         /* Get Cookies Value */
         $user_remember_data = unserialize($this->getRequest()->cookies->get('user_remember_cookies'));
         /* Get Cookies Value End */
         return $this->render('JobPortalFrontBundle:Users:userRegister.html.php', array('categories' => $categories, 'user_cookies_remember' => $user_remember_data));
     }
 }
 public function testScoreAction(Request $request)
 {
     $candateDetails = $this->get('session')->get('candidatedata');
     $login_user_id = $candateDetails['login_candidate_id'];
     $conn = $this->get('database_connection');
     if ($request->getMethod() == "POST") {
         $answer_arr = $request->request->all();
         $score = 0;
         $total_marks = 0;
         $total_questions = 0;
         $correct_answer = 0;
         if (!empty($answer_arr['given_question_answer'])) {
             foreach ($answer_arr['given_question_answer'] as $key => $data) {
                 $answer_status = $conn->fetchAll('SELECT q.*, a.* FROM questions q LEFT JOIN answers a ON a.question_id = q.id where q.id = "' . $data['question'] . '" AND a.id = "' . $data['answer'] . '" ');
                 $total_marks = $total_marks + $answer_status[0]['marks_positive'];
                 if ($answer_status[0]['answer_status']) {
                     $score = $score + $answer_status[0]['marks_positive'];
                     $correct_answer = $correct_answer + 1;
                 } else {
                     $score = $score - $answer_status[0]['marks_negative'];
                 }
                 $array_question[] = $data['question'];
             }
         }
         if (!empty($answer_arr['total_question_id'])) {
             foreach ($answer_arr['total_question_id'] as $question_key) {
                 $total_questions = $total_questions + 1;
                 if (in_array($question_key, $array_question)) {
                 } else {
                     $not_attend_answer = $conn->fetchAll('SELECT q.* FROM questions q where q.id = "' . $question_key . '" ');
                     $total_marks = $total_marks + $not_attend_answer[0]['marks_positive'];
                     $score = $score - $not_attend_answer[0]['marks_negative'];
                 }
             }
         }
         $em = $this->getDoctrine()->getManager();
         $exam_name = $conn->fetchAll('SELECT id,category FROM categories WHERE id = ' . $answer_status[0]['category_id']);
         $question_string = implode(",", $array_question);
         $date = date("Y-m-d H:i:s");
         $exam_category = $conn->fetchAll('SELECT * FROM category_user_mappings WHERE user_id = ' . $login_user_id . ' AND category_id = ' . $answer_status[0]['category_id']);
         if (empty($exam_category)) {
             $CategoryUserMappings = new CategoryUserMappings();
             $CategoryUserMappings->setUserId($login_user_id);
             $CategoryUserMappings->setCategoryId($answer_status[0]['category_id']);
             $em->persist($CategoryUserMappings);
             $em->flush();
         }
         $scores = new Scores();
         $scores->setCategoryType($answer_status[0]['category_id']);
         $scores->setUserId($login_user_id);
         $scores->setDate($date);
         $scores->setScore($score);
         $scores->setTotalMarks($total_marks);
         $scores->setQuestion($question_string);
         $em->persist($scores);
         $em->flush();
     }
     $data_output = array('correct_answer' => $correct_answer, 'total_questions' => $total_questions, 'score' => $score, 'total_marks' => $total_marks, 'exam_name' => $exam_name[0]['category'], 'exam_id' => $exam_name[0]['id']);
     $this->get('session')->set('exam_data', $data_output);
     return new Response();
 }