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]['schoolSessions'] = $this->testSessionsService->getSchoolSessions($schoolId);
  87. $response[$schoolId]['studentSchoolSession'] = $this->testSessionsService->getStudentsAndExamsBySessionPerSchool($schoolId);
  88. $response[$schoolId]['schoolPaymentBalance'] = $this->schoolPaymentsService->getCurrentBalance($schoolId);
  89. $response[$schoolId]['schoolPayments'] = $this->schoolPaymentsService->findAllBySchool($schoolId);
  90. $response[$schoolId]['accountReport'] = $this->schoolInvoiceDetailsService->getAccountReport($schoolId);
  91. $response[$schoolId]['schoolAdminUserEmail'] = $this->usersService->getSchoolAdminEmail($schoolId)?:$this->getUser()->getEmail();
  92. $response[$schoolId]['schoolInfo']['logs'] = $this->queryLogService->findAllSchoolsLogs($schoolId);
  93. }
  94. return $this->json($response);
  95. }
  96. /**
  97. * @Route("/api/getSchoolInfo")
  98. */
  99. public function getSchoolInfo(Security $security)
  100. {
  101. $isSchoolAdmin = $this->isSchoolAdmin();
  102. if($isSchoolAdmin){
  103. $schoolId = $this->getUser()->getSchoolId();
  104. $schools = $this->schoolService->getSchoolForSchoolSession($schoolId);
  105. $response['schoolDetails'] = $schools[0];
  106. $response['accountReport'] = $this->schoolInvoiceDetailsService->getAccountReport($schoolId);
  107. $response['schoolBalance'] = $this->schoolPaymentsService->getCurrentBalance($schoolId);
  108. $response['schoolAdminUserEmail'] = $security->getUser()->getEmail();
  109. $response['schoolInfo']['logs'] = $this->queryLogService->findAllSchoolsLogs($schoolId);
  110. // $schools = $this->schoolService->getSchoolForSchoolSession($isSchoolAdmin);
  111. return $this->json($response);
  112. }
  113. else{
  114. $schools = $this->schoolService->getSchools();
  115. }
  116. return $this->json($schools);
  117. }
  118. /**
  119. * @Route("/api/getSchoolDetails")
  120. */
  121. public function getSchoolDetails(Request $request)
  122. {
  123. $schoolId = $request->query->get('schoolId');
  124. $response['schoolStudents'] = $this->studentsService->getStudentsAccordingSchool($schoolId);
  125. $response['schoolSessions'] = $this->testSessionsService->getSchoolSessions($schoolId);
  126. $response['schoolSessionStudents'] = $this->testSessionsService->getStudentsAndExamsBySessionPerSchool($schoolId);
  127. $response['currentSchoolDetails'] =$this->schoolService->getSchoolForSchoolSession($schoolId);
  128. $response['schoolPaymentBalance'] = $this->schoolPaymentsService->getCurrentBalance($schoolId);
  129. $response['schoolInfo']['logs'] = $this->queryLogService->findAllSchoolsLogs($schoolId);
  130. return $this->json($response);
  131. }
  132. /**
  133. * @Route("/api/getAllSchoolStudents")
  134. */
  135. public function getAllSchoolStudents(Request $request)
  136. {
  137. try {
  138. $schoolId = $request->query->get('schoolId');
  139. $response = $this->studentsService->getAllSchoolStudents($schoolId);
  140. } catch (Exception $ex) {
  141. return $this->json(array('error' => $ex->getMessage()));
  142. }
  143. return $this->json($response);
  144. }
  145. /**
  146. * @Route("/api/admin/addEditSchool")
  147. */
  148. public function addEditSchool(Request $request)
  149. {
  150. //$active, $address, $chargeProctorFee, $city, $comments, $contact, $country,$email, $gender, $member_pricePerCredit, $multiple_active_cohorts, $name, $nonmember_pricePerCredit, $phone, $standardOrCustomPricePerCredit, $state, $students_are_members, $zip
  151. $content = $this->getContent($request);
  152. $school = $this->schoolService->AddEditSchool(
  153. $content->get('active'),
  154. $content->get('address'),
  155. $content->get('chargeProctorFee'),
  156. $content->get('city'),
  157. $content->get('comments'),
  158. $content->get('contact'),
  159. $content->get('country'),
  160. ParameterUtil::getRequired($content->get('email')),
  161. ParameterUtil::getRequired($content->get('gender')),
  162. $content->get('member_pricePerCredit'),
  163. $content->get('multiple_active_cohorts'),
  164. ParameterUtil::getRequired($content->get('name')),
  165. $content->get('nonmember_pricePerCredit'),
  166. $content->get('phone'),
  167. $content->get('standardOrCustomPricePerCredit'),
  168. $content->get('state'),
  169. $content->get('students_are_members'),
  170. $content->get('zip'),
  171. $content->get('schoolId')
  172. );
  173. $schoolId = $school[0]['id'];
  174. $response['schoolInfo'] = $school[0];
  175. $response['schoolSessions'] = $this->testSessionsService->getSchoolSessions($schoolId);
  176. $response['studentSchoolSession'] = $this->testSessionsService->getStudentsAndExamsBySessionPerSchool($schoolId);
  177. $response['schoolPaymentBalance'] = $this->schoolPaymentsService->getCurrentBalance($schoolId);
  178. $response['schoolPayments'] = $this->schoolPaymentsService->findAllBySchool($schoolId);
  179. $response['accountReport'] = $this->schoolInvoiceDetailsService->getAccountReport($schoolId);
  180. $response['schoolAdminUserEmail'] = $this->usersService->getSchoolAdminEmail($schoolId)?:$this->getUser()->getEmail();
  181. $response['schoolInfo']['logs'] = $this->queryLogService->findAllSchoolsLogs($schoolId);
  182. return $this->json($response);
  183. }
  184. /**
  185. * @Route("/api/admin/deleteSchool")
  186. */
  187. public function deleteSchool(Request $request)
  188. {
  189. $content = $this->getContent($request);
  190. try{
  191. $response = $this->schoolService->deleteSchool( ParameterUtil::getRequired($content->get('schoolId')));
  192. }
  193. catch (\Exception $e){
  194. return new Response($e->getMessage(), 500);
  195. }
  196. return $this->json($response);
  197. }
  198. }