src/Controller/ExamController.php line 169

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\ExamRegistrationsService;
  4. use App\Service\ExamsService;
  5. use App\Service\ExamVendorService;
  6. use App\Service\ExamWebhookService;
  7. use App\Service\ProctorService;
  8. use App\Service\StudentsService;
  9. use App\Service\TalService;
  10. use App\Util\ParameterUtil;
  11. use Psr\Log\LoggerInterface;
  12. use Symfony\Component\Config\Definition\Exception\Exception;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. class ExamController extends BaseController
  17. {
  18. /**
  19. * @var ExamsService
  20. */
  21. private $examsService;
  22. /**
  23. * @var ProctorService
  24. */
  25. private $proctorService;
  26. /**
  27. * @var ExamVendorService
  28. */
  29. private $examVendorService;
  30. /**
  31. * @var ExamWebhookService
  32. */
  33. private $examWebhookService;
  34. /**
  35. * @var ExamRegistrationsService
  36. */
  37. private $examRegistrationsService;
  38. /**
  39. * @var TalService
  40. */
  41. private $talService;
  42. private $logger;
  43. public function __construct(
  44. ExamsService $examsService,
  45. ProctorService $proctorService,
  46. ExamVendorService $examVendorService,
  47. ExamWebhookService $examWebhookService,
  48. ExamRegistrationsService $examRegistrationsService,
  49. TalService $talService,
  50. LoggerInterface $logger
  51. ) {
  52. $this->examsService = $examsService;
  53. $this->proctorService = $proctorService;
  54. $this->examVendorService = $examVendorService;
  55. $this->examWebhookService = $examWebhookService;
  56. $this->examRegistrationsService = $examRegistrationsService;
  57. $this->talService = $talService;
  58. $this->logger = $logger;
  59. }
  60. // /**
  61. // * @Route("/api/searchExams")
  62. // */
  63. // public function searchExams(Request $request){
  64. // $content = $this->getContent($request);
  65. // $searchTerm = $content->get('searchTerm');
  66. // $studentId = parent::getStudentId($request);
  67. // try{
  68. // $response = $this->examsService->searchExams($searchTerm,$studentId);
  69. // }
  70. // catch (Exception $exception){
  71. // throw new Exception($exception->getMessage());
  72. // }
  73. // return new Response(json_encode($response));
  74. // }
  75. /**
  76. * @Route("/api/getAllActiveExams")
  77. */
  78. public function getAllActiveExams(Request $request)
  79. {
  80. $studentId = parent::getStudentId($request);
  81. $response = $this->examsService->getAllActiveExams($studentId);
  82. return new Response(json_encode($response));
  83. }
  84. /**
  85. * @Route("/api/getAllActiveExamsByVendorId")
  86. **/
  87. public function getAllActiveExamsByVendorId(Request $request) {
  88. try {
  89. $vendorId = $request->get('vendorId');
  90. $exams = $this->examsService->getAllActiveExamsByVendorId($vendorId);
  91. } catch (Exception $ex) {
  92. return $this->json($ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
  93. }
  94. return $this->json($exams);
  95. }
  96. /**
  97. * @Route("/api/getAllActiveExamsWithRegistrationDetails")
  98. */
  99. public function getAllActiveExamsWithRegistrationDetails(Request $request)
  100. {
  101. $studentId = parent::getStudentId($request);
  102. $response = $this->examsService->getAllActiveExamsWithRegistrationDetails($studentId);
  103. return new Response(json_encode($response));
  104. }
  105. /**
  106. * @Route("/api/getAllActiveExamsWithStudyMaterial")
  107. */
  108. public function getAllActiveExamsWithStudyMaterial(Request $request)
  109. {
  110. $studentId = parent::getStudentId($request);
  111. $response = $this->examsService->getAllActiveExamsWithStudyMaterial($studentId);
  112. return new Response(json_encode($response));
  113. }
  114. /**
  115. * @Route("/api/getAllExamsWithStudyMaterial")
  116. */
  117. public function getAllExamsWithStudyMaterial(Request $request)
  118. {
  119. $response = $this->examsService->getAllExamsWithStudyMaterial();
  120. return $this->json($response);
  121. }
  122. /**
  123. * @Route("/api/getAllSeminaryTestingExams")
  124. */
  125. public function getAllSeminaryTestingExams()
  126. {
  127. $response = $this->examsService->getAllSeminaryTestingExams();
  128. return $this->json(array('exams' => $response));
  129. }
  130. /**
  131. * @Route("/api/getAllExamsAccordingStudent")
  132. */
  133. public function getAllExamsAccordingStudent(Request $request, StudentsService $studentsService)
  134. {
  135. $studentId = parent::getStudentId($request);
  136. $student = $studentsService->find($studentId);
  137. if (!$student) {
  138. return new Response(json_encode('Student not found.'),500);
  139. }
  140. $examsWithProctorCodes = $this->examsService->getAllExamsAccordingStudent($studentId, $student->getCccId());
  141. $memberHasntRegistered2years = $studentsService->memberDidntRegisterOver2Years($studentId);
  142. return new Response(json_encode(['exams' => $examsWithProctorCodes,'memberHasntRegistered2years' => $memberHasntRegistered2years]));
  143. }
  144. /**
  145. * @Route("/api/startExam")
  146. */
  147. public function startExam(Request $request)
  148. {
  149. try {
  150. $content = $this->getContent($request);
  151. $studentId = $content->get('studentId');
  152. $examId = ParameterUtil::getRequired($content->get('examId'));
  153. $registrationId = ParameterUtil::getRequired($content->get('registrationId'));
  154. if(!$studentId)
  155. $studentId = $content->get('student_id');
  156. $this->logger->info("in start exam");
  157. $response = $this->examVendorService->getStartLink(
  158. $studentId,
  159. $examId,
  160. $registrationId
  161. );
  162. $this->examRegistrationsService->setProctorUuid($registrationId);
  163. $this->examRegistrationsService->setOnlineExamRedirect($studentId, $examId);
  164. } catch (Exception $e) {
  165. $this->logger->error('start exam error' . $e->getMessage());
  166. return $this->json(array('error' => $e->getMessage()), 500);
  167. }
  168. return $this->json(array('url' => $response['startExamLink']));
  169. }
  170. /**
  171. * @Route("/api/webhook/examStarted")
  172. */
  173. public function examStarted(Request $request)
  174. {
  175. try {
  176. $response = $this->examWebhookService->examStarted($request);
  177. } catch (Exception $e) {
  178. return $this->json(array('error' => $e->getMessage()));
  179. }
  180. return $this->json($response);
  181. }
  182. /**
  183. * @Route("/api/webhook/examCompleted")
  184. */
  185. public function examCompleted(Request $request)
  186. {
  187. try {
  188. $response = $this->examWebhookService->examCompleted($request);
  189. } catch (Exception $e) {
  190. return $this->json(array('error' => $e->getMessage()));
  191. }
  192. return $this->json($response);
  193. }
  194. /**
  195. * @Route("/api/admin/addUpdateExam")
  196. */
  197. public function addUpdateExam(Request $request)
  198. {
  199. try {
  200. $content = $this->getContent($request);
  201. $examId = $content->get('examId');
  202. $vendorId = $content->get('vendorId');
  203. $active = $content->get('active');
  204. $phoneSystemActive = $content->get('phoneSystemActive');
  205. $examLevel= $content->get('examLevel');
  206. $code = $content->get('code');
  207. $subject = $content->get('subject')?:$content->get('secularTitle');
  208. $secularNumber= $content->get('secularNumber');
  209. $secularTitle = $content->get('secularTitle');
  210. $duration = $content->get('duration');
  211. $credits= (int)$content->get('credits');
  212. $additionalCharge = $content->get('additionalCharge');
  213. $tti_allow = $content->get('tti_allow');
  214. $content_code = $content->get('content_code');
  215. $group_code = $content->get('group_code');
  216. $program_content_code = $content->get('program_content_code');
  217. $program_started_content_code = $content->get('program_started_content_code');
  218. $program_completed_content_code= $content->get('program_completed_content_code');
  219. $alternate_course_version = $content->get('alternate_course_version');
  220. $online_only = $content->get('online_only');
  221. $paper_only = $content->get('paper_only');
  222. $allowed_resources = $content->get('allowed_resources');
  223. $assignments = $content->get('assignments');
  224. $for_seminary_testing = $content->get('for_seminary_testing');
  225. $talFee = $content->get('talFee');
  226. $updatedExam= $this->examsService->addUpdateExam($examId,$vendorId,$active,$phoneSystemActive,$examLevel,$code,$subject,$secularNumber,$secularTitle,
  227. $duration,$credits,$additionalCharge,$tti_allow,
  228. $content_code,$group_code,$program_content_code,$program_started_content_code,
  229. $program_completed_content_code, $allowed_resources,$assignments,$for_seminary_testing,
  230. $alternate_course_version,$online_only,$paper_only,$talFee
  231. );
  232. //$updatedExam['examDuration'] = $updatedExam->getDuration();
  233. $allExams = $this->examsService->getAllExamsWithStudyMaterial();
  234. } catch (Exception $e) {
  235. return $this->json(array('error' => $e->getMessage()),500);
  236. }
  237. return $this->json(['allExams'=>$allExams]);
  238. }
  239. }