src/Controller/SchoolController.php line 61

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\SchoolInvoiceDetailsService;
  4. use App\Service\SchoolPaymentsService;
  5. use App\Service\SchoolService;
  6. use App\Service\StudentsService;
  7. use App\Service\TestSessionsService;
  8. use App\Service\UsersService;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Security\Core\Security;
  12. use App\Util\ParameterUtil;
  13. use App\Service\QueryLogService;
  14. use Symfony\Component\HttpFoundation\Response;
  15. class SchoolController extends BaseController
  16. {
  17. /**
  18. * @var SchoolService
  19. */
  20. private $schoolService;
  21. /**
  22. * @var TestSessionsService
  23. */
  24. private $testSessionsService;
  25. /**
  26. * @var StudentsService
  27. */
  28. private $studentsService;
  29. /**
  30. * @var SchoolPaymentsService
  31. */
  32. private SchoolPaymentsService $schoolPaymentsService;
  33. private SchoolInvoiceDetailsService $schoolInvoiceDetailsService;
  34. private UsersService $usersService;
  35. private QueryLogService $queryLogService;
  36. public function __construct(
  37. SchoolService $schoolService,
  38. TestSessionsService $testSessionsService,
  39. StudentsService $studentsService,
  40. SchoolPaymentsService $schoolPaymentsService,
  41. SchoolInvoiceDetailsService $schoolInvoiceDetailsService,
  42. UsersService $usersService,
  43. QueryLogService $queryLogService
  44. ) {
  45. $this->schoolService = $schoolService;
  46. $this->testSessionsService = $testSessionsService;
  47. $this->studentsService = $studentsService;
  48. $this->schoolPaymentsService = $schoolPaymentsService;
  49. $this->schoolInvoiceDetailsService = $schoolInvoiceDetailsService;
  50. $this->usersService = $usersService;
  51. $this->queryLogService = $queryLogService;
  52. }
  53. /**
  54. * @Route("/api/getActiveSchools")
  55. */
  56. public function getActiveSchools()
  57. {
  58. return $this->json($this->schoolService->getActiveSchools());
  59. }
  60. /**
  61. * @Route("/api/getSchoolCohorts")
  62. */
  63. public function getSchoolCohorts(Request $request)
  64. {
  65. $schoolId = $request->query->get('schoolId');
  66. $schoolCohorts = $this->schoolService->getSchoolCohorts($schoolId);
  67. return $this->json($schoolCohorts ? $schoolCohorts[0] : null);
  68. }
  69. /**
  70. * @Route("/api/getSchools")
  71. */
  72. public function getSchools()
  73. {
  74. $isSchoolAdmin = $this->isSchoolAdmin();
  75. if($isSchoolAdmin){
  76. $schoolId = $this->getUser()->getSchoolId();
  77. $schools = $this->schoolService->getSchoolForSchoolSession($schoolId);
  78. }
  79. else{
  80. $schools = $this->schoolService->getSchools();
  81. }
  82. foreach ($schools as $school) {
  83. $schoolId = $school['id'];
  84. $response[$schoolId]['schoolInfo'] = $school;
  85. // $response[$schoolId]['students'] = $this->studentsService->getStudentsAccordingSchool($schoolId);
  86. $response[$schoolId]['schoolProctors'] = $this->schoolService->getProctorsBySchool($schoolId); // 👈 new
  87. $response[$schoolId]['schoolSessions'] = $this->testSessionsService->getSchoolSessions($schoolId);
  88. $response[$schoolId]['studentSchoolSession'] = $this->testSessionsService->getStudentsAndExamsBySessionPerSchool($schoolId);
  89. $response[$schoolId]['schoolPaymentBalance'] = $this->schoolPaymentsService->getCurrentBalance($schoolId);
  90. $response[$schoolId]['schoolPayments'] = $this->schoolPaymentsService->findAllBySchool($schoolId);
  91. $response[$schoolId]['accountReport'] = $this->schoolInvoiceDetailsService->getAccountReport($schoolId);
  92. $response[$schoolId]['schoolAdminUserEmail'] = $this->usersService->getSchoolAdminEmail($schoolId)?:$this->getUser()->getEmail();
  93. $response[$schoolId]['schoolInfo']['logs'] = $this->queryLogService->findAllSchoolsLogs($schoolId);
  94. }
  95. return $this->json($response);
  96. }
  97. /**
  98. * @Route("/api/getSchoolInfo")
  99. */
  100. public function getSchoolInfo(Security $security)
  101. {
  102. $isSchoolAdmin = $this->isSchoolAdmin();
  103. if($isSchoolAdmin){
  104. $schoolId = $this->getUser()->getSchoolId();
  105. $schools = $this->schoolService->getSchoolForSchoolSession($schoolId);
  106. $response['schoolDetails'] = $schools[0];
  107. $response['accountReport'] = $this->schoolInvoiceDetailsService->getAccountReport($schoolId);
  108. $response['schoolBalance'] = $this->schoolPaymentsService->getCurrentBalance($schoolId);
  109. $response['schoolAdminUserEmail'] = $security->getUser()->getEmail();
  110. $response['schoolInfo']['logs'] = $this->queryLogService->findAllSchoolsLogs($schoolId);
  111. // $schools = $this->schoolService->getSchoolForSchoolSession($isSchoolAdmin);
  112. return $this->json($response);
  113. }
  114. else{
  115. $schools = $this->schoolService->getSchools();
  116. }
  117. return $this->json($schools);
  118. }
  119. /**
  120. * @Route("/api/getSchoolDetails")
  121. */
  122. public function getSchoolDetails(Request $request)
  123. {
  124. $schoolId = $request->query->get('schoolId');
  125. $response['schoolStudents'] = $this->studentsService->getStudentsAccordingSchool($schoolId);
  126. $response['schoolSessions'] = $this->testSessionsService->getSchoolSessions($schoolId);
  127. $response['schoolSessionStudents'] = $this->testSessionsService->getStudentsAndExamsBySessionPerSchool($schoolId);
  128. $response['currentSchoolDetails'] =$this->schoolService->getSchoolForSchoolSession($schoolId);
  129. $response['schoolPaymentBalance'] = $this->schoolPaymentsService->getCurrentBalance($schoolId);
  130. $response['schoolInfo']['logs'] = $this->queryLogService->findAllSchoolsLogs($schoolId);
  131. return $this->json($response);
  132. }
  133. /**
  134. * @Route("/api/getAllSchoolStudents")
  135. */
  136. public function getAllSchoolStudents(Request $request)
  137. {
  138. try {
  139. $schoolId = $request->query->get('schoolId');
  140. $response = $this->studentsService->getAllSchoolStudents($schoolId);
  141. } catch (Exception $ex) {
  142. return $this->json(array('error' => $ex->getMessage()));
  143. }
  144. return $this->json($response);
  145. }
  146. /**
  147. * @Route("/api/admin/addEditSchool")
  148. */
  149. public function addEditSchool(Request $request)
  150. {
  151. //$active, $address, $chargeProctorFee, $city, $comments, $contact, $country,$email, $gender, $member_pricePerCredit, $multiple_active_cohorts, $name, $nonmember_pricePerCredit, $phone, $standardOrCustomPricePerCredit, $state, $students_are_members, $zip
  152. $content = $this->getContent($request);
  153. $school = $this->schoolService->AddEditSchool(
  154. $content->get('active'),
  155. $content->get('address'),
  156. $content->get('chargeProctorFee'),
  157. $content->get('city'),
  158. $content->get('comments'),
  159. $content->get('contact'),
  160. $content->get('country'),
  161. ParameterUtil::getRequired($content->get('email')),
  162. ParameterUtil::getRequired($content->get('gender')),
  163. $content->get('member_pricePerCredit'),
  164. $content->get('multiple_active_cohorts'),
  165. ParameterUtil::getRequired($content->get('name')),
  166. $content->get('nonmember_pricePerCredit'),
  167. $content->get('phone'),
  168. $content->get('standardOrCustomPricePerCredit'),
  169. $content->get('state'),
  170. $content->get('students_are_members'),
  171. $content->get('zip'),
  172. $content->get('schoolId')
  173. );
  174. $schoolId = $school[0]['id'];
  175. $response['schoolInfo'] = $school[0];
  176. $response['schoolSessions'] = $this->testSessionsService->getSchoolSessions($schoolId);
  177. $response['studentSchoolSession'] = $this->testSessionsService->getStudentsAndExamsBySessionPerSchool($schoolId);
  178. $response['schoolPaymentBalance'] = $this->schoolPaymentsService->getCurrentBalance($schoolId);
  179. $response['schoolPayments'] = $this->schoolPaymentsService->findAllBySchool($schoolId);
  180. $response['accountReport'] = $this->schoolInvoiceDetailsService->getAccountReport($schoolId);
  181. $response['schoolAdminUserEmail'] = $this->usersService->getSchoolAdminEmail($schoolId)?:$this->getUser()->getEmail();
  182. $response['schoolInfo']['logs'] = $this->queryLogService->findAllSchoolsLogs($schoolId);
  183. return $this->json($response);
  184. }
  185. /**
  186. * @Route("/api/admin/deleteSchool")
  187. */
  188. public function deleteSchool(Request $request)
  189. {
  190. $content = $this->getContent($request);
  191. try{
  192. $response = $this->schoolService->deleteSchool( ParameterUtil::getRequired($content->get('schoolId')));
  193. }
  194. catch (\Exception $e){
  195. return new Response($e->getMessage(), 500);
  196. }
  197. return $this->json($response);
  198. }
  199. }