src/Controller/TestSessionController.php line 97

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\EmailService;
  4. use App\Service\ExamRegistrationsService;
  5. use App\Service\SchoolSessionsService;
  6. use App\Service\TestSessionsService;
  7. use App\Util\ParameterUtil;
  8. use Doctrine\ORM\Query\Expr\Base;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class TestSessionController extends BaseController
  13. {
  14. /**
  15. * @var TestSessionsService
  16. */
  17. private $sessionsService;
  18. private ExamRegistrationsService $examRegistrationsService;
  19. private EmailService $emailService;
  20. private SchoolSessionsService $schoolSessionsService;
  21. public function __construct(TestSessionsService $sessionsService,
  22. ExamRegistrationsService $examRegistrationsService,
  23. SchoolSessionsService $schoolSessionsService,
  24. EmailService $emailService)
  25. {
  26. $this->sessionsService = $sessionsService;
  27. $this->examRegistrationsService = $examRegistrationsService;
  28. $this->emailService = $emailService;
  29. $this->schoolSessionsService = $schoolSessionsService;
  30. }
  31. /**
  32. * @Route("/api/getOpenedSessions")
  33. */
  34. public function getOpenedSessions(Request $request)
  35. {
  36. $studentId = parent::getStudentId($request);
  37. $response = $this->sessionsService->getOpenedSessions($studentId);
  38. return new Response(json_encode($response));
  39. }
  40. /**
  41. * @Route("/api/getSession")
  42. */
  43. public function getSession(Request $request)
  44. {
  45. $sessionId = $request->query->get('sessionId');
  46. $response = $this->sessionsService->getSession($sessionId);
  47. return $this->json($response);
  48. }
  49. /**
  50. * @Route("/api/getOotSessionInfo")
  51. */
  52. public function getOotSessionInfo(Request $request)
  53. {
  54. $sessionId = $request->query->get('sessionId');
  55. $response = $this->sessionsService->getOotSessionInfo($sessionId);
  56. return $this->json($response);
  57. }
  58. /**
  59. * @Route("/api/admin/getAllSessions")
  60. */
  61. public function getAllSessions(Request $request){
  62. try {
  63. $content = $this->getContent($request);
  64. $startDate = ParameterUtil::getRequired($content->get('startDate'));
  65. $endDate = $content->get('endDate')?:null;
  66. $response = $this->sessionsService->getAllSessions($startDate, $endDate);
  67. }
  68. catch (\Exception $e){
  69. return new Response($e->getMessage(), 500);
  70. }
  71. return $this->json($response);
  72. }
  73. /**
  74. * @Route("/api/getSchoolSessions")
  75. */
  76. public function getSchoolSessions(Request $request)
  77. {
  78. $schoolId = $request->query->get('schoolId');
  79. $response = $this->sessionsService->getSchoolSessions($schoolId);
  80. return $this->json($response);
  81. }
  82. /**
  83. * @Route("/api/getSessionsByStudentId")
  84. */
  85. public function getSessionsByStudentId(Request $request)
  86. {
  87. $studentId = parent::getStudentId($request);
  88. $response = $this->sessionsService->getSessionsByStudentId($studentId);
  89. return new Response(json_encode($response));
  90. }
  91. /**
  92. * @Route("/api/admin/createSchoolSession")
  93. */
  94. public function createSchoolSession(Request $request)
  95. {
  96. $content = $this->getContent($request);
  97. $response = $this->sessionsService->createSchoolSession(
  98. ParameterUtil::getRequired($content->get('schoolId')),
  99. ParameterUtil::getRequired($content->get('gender')),
  100. ParameterUtil::getRequired($content->get('testDate')),
  101. ParameterUtil::getRequired($content->get('startTime')),
  102. ParameterUtil::getRequired($content->get('closingDate')),
  103. ParameterUtil::getRequired($content->get('returnDate')),
  104. $content->get('testSessionId')
  105. );
  106. return $this->json($response);
  107. }
  108. /**
  109. * @Route("/api/admin/addEditTestSession")
  110. */
  111. public function addEditTestSession(Request $request)
  112. {
  113. $content = $this->getContent($request);
  114. $response = $this->sessionsService->AddEditTestSession(
  115. $content->get('schoolId'),
  116. $content->get('locationId'),
  117. ParameterUtil::getRequired($content->get('sessionType')),
  118. ParameterUtil::getRequired($content->get('gender')),
  119. ParameterUtil::getRequired($content->get('testDate')),
  120. ParameterUtil::getRequired($content->get('startTime')),
  121. ParameterUtil::getRequired($content->get('closingDate')),
  122. ParameterUtil::getRequired($content->get('closingTime')), // fixed
  123. ParameterUtil::getRequired($content->get('openingDate')), // fixed
  124. ParameterUtil::getRequired($content->get('returnDate')), // fixed
  125. $content->get('session_last_date'),
  126. $content->get('seats'),
  127. $content->get('proctors'),
  128. $content->get('testSessionId')
  129. );
  130. return $this->json($response);
  131. }
  132. /**
  133. * @Route("/api/admin/deleteSession")
  134. */
  135. public function deleteSession(Request $request)
  136. {
  137. $content = $this->getContent($request);
  138. try{
  139. $response = $this->sessionsService->deleteSession( ParameterUtil::getRequired($content->get('sessionId')));
  140. }
  141. catch (\Exception $e){
  142. return new Response($e->getMessage(), 500);
  143. }
  144. return $this->json($response);
  145. }
  146. /**
  147. * @Route("/api/admin/getStudentsPerSession")
  148. */
  149. public function getStudentsPerSession(Request $request)
  150. {
  151. $content = $this->getContent($request);
  152. $response = $this->sessionsService->getStudentsPerSession(ParameterUtil::getRequired($content->get('sessionId')));
  153. return $this->json($response);
  154. }
  155. /**
  156. * @Route("/api/admin/getStudentsBySessionPerSchool")
  157. */
  158. public function getStudentsBySessionPerSchool(Request $request)
  159. {
  160. $content = $this->getContent($request);
  161. $response = $this->sessionsService->getStudentsAndExamsBySessionPerSchool(ParameterUtil::getRequired($content->get('schoolId')));
  162. return $this->json($response);
  163. }
  164. /**
  165. * @Route("/api/cron/sendNextDaySchoolSessionsList")
  166. */
  167. public function doSchoolSessionDailyProcesses(Request $request)
  168. {
  169. $auth = $request->headers->get('token-auth');
  170. if ($auth == $_ENV['TTI_REQUEST_AUTH']) {
  171. $error = '';
  172. try{
  173. $this->schoolSessionsService->sendCopeSchoolSessionReport();
  174. } catch (\Throwable $ex) {
  175. $this->emailService->sendSchoolSessionReportError($ex->getMessage());
  176. $error = $ex->getMessage();
  177. }
  178. try {
  179. $response = $this->sessionsService->sendNextDaysSchoolSessionsList();
  180. } catch (\Exception $ex) {
  181. $error = $error.' '.$ex->getMessage();
  182. }
  183. try {
  184. $response =$response.'--'.$this->sessionsService->sendYesterdayNonSchoolSessionsReport();
  185. } catch (\Exception $ex) {
  186. return new Response($error.' '.$ex->getMessage(), 500);
  187. }
  188. } else {
  189. return new Response('false authentication', 401);
  190. }
  191. return new Response($error.' '.$response);
  192. }
  193. /**
  194. * @Route("/api/runSchoolSessionDailyProcesses")
  195. */
  196. public function runSchoolSessionDailyProcesses(Request $request)
  197. {
  198. $auth = $request->headers->get('token-auth');
  199. if ($auth == $_ENV['TTI_REQUEST_AUTH']) {
  200. $error = '';
  201. try{
  202. $content = $this->getContent($request);
  203. $date = $content->get('date')?:null;
  204. $this->schoolSessionsService->sendCopeSchoolSessionReport($date);
  205. }catch (\Throwable $ex) {
  206. $this->emailService->sendSchoolSessionReportError($ex->getMessage());
  207. $error = $ex->getMessage();
  208. }
  209. try {
  210. $response = $this->sessionsService->sendNextDaysSchoolSessionsList();
  211. } catch (Exception $ex) {
  212. return new Response($error.' '.$ex->getMessage(), 500);
  213. }
  214. } else {
  215. return new Response('false authentication', 401);
  216. }
  217. return new Response($error.' '.$response);
  218. }
  219. /**
  220. * @Route("/api/cancelUntakenRegistrationsBySessionId")
  221. */
  222. public function cancelUntakenRegistrationsBySessionId(Request $request){
  223. $auth = $request->headers->get('token-auth');
  224. if ($auth == $_ENV['TTI_REQUEST_AUTH']) {
  225. $error = '';
  226. try{
  227. $content = $this->getContent($request);
  228. $sessionId = ParameterUtil::getRequired($content->get('sessionId'));
  229. $this->schoolSessionsService->cancelUntakenRegistrationsBySessionId($sessionId);
  230. }catch (\Throwable $ex) {
  231. $error = $ex->getMessage();
  232. }
  233. } else {
  234. return new Response('false authentication', 401);
  235. }
  236. return new Response($error.' ');
  237. }
  238. /**
  239. * @Route("/api/admin/getSessionLogs")
  240. */
  241. public function getSessionLogs(Request $request): Response
  242. {
  243. try {
  244. $content = $this->getContent($request);
  245. $sessionId = ParameterUtil::getRequired($content->get('testSessionId'));
  246. $logs = $this->sessionsService->getLogsForSession($sessionId);
  247. return $this->json($logs);
  248. } catch (\Exception $e) {
  249. return new Response($e->getMessage(), 500);
  250. }
  251. }
  252. }