src/Service/StatistiquesService.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use App\Repository\SubscriptionRepository;
  5. use App\Repository\ClassRoomRepository;
  6. use App\Repository\SchoolYearRepository;
  7. use App\Repository\UserRepository;
  8. use App\Service\SchoolYearService;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. class StatistiquesService
  11. {
  12. private SubscriptionRepository $subRepo;
  13. private SchoolYearRepository $scRepo;
  14. private ClassRoomRepository $roomRepo;
  15. private UserRepository $userRepo;
  16. private SessionInterface $session;
  17. private SchoolYearService $schoolYearService;
  18. private EntityManagerInterface $em;
  19. public function __construct( SchoolYearService $schoolYearService, EntityManagerInterface $em, UserRepository $userRepo, SchoolYearRepository $scRepo, ClassRoomRepository $rmRepo, SubscriptionRepository $subRepo, SessionInterface $session)
  20. {
  21. $this->em = $em;
  22. $this->userRepo = $userRepo;
  23. $this->scRepo = $scRepo;
  24. $this->roomRepo = $rmRepo;
  25. $this->subRepo = $subRepo;
  26. $this->session = $session;
  27. $this->schoolYearService = $schoolYearService;
  28. }
  29. public function teachers()
  30. {
  31. $users = $this->userRepo->findAllOfCurrentYear($this->schoolYearService->sessionYearById());
  32. return count($users);
  33. }
  34. public function students()
  35. {
  36. $students = $this->subRepo->findBy(array("schoolYear" => $this->schoolYearService->sessionYearById()));
  37. return count($students);
  38. }
  39. public function rooms()
  40. {
  41. $roomsEnabled = $this->roomRepo->countEnabledClassRoom($this->schoolYearService->sessionYearById());
  42. return count($roomsEnabled);
  43. }
  44. public function insolvents()
  45. {
  46. $year = $this->schoolYearService->sessionYearById();
  47. $paymentPlan = $year->getPaymentPlan();
  48. $subscriptions = $this->subRepo->findBy(array("schoolYear" => $year));
  49. $students = [];
  50. foreach($subscriptions as $sub){
  51. if($year->paymentThresholdAmount($sub->getClassRoom()) > $sub->getStudent()->getPaymentsSum($year) ){
  52. $students[] = $sub->getStudent() ;
  53. }
  54. }
  55. return count( $students);
  56. }
  57. }