src/Controller/admin/AdminHomeController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller\admin;
  3. use App\Entity\Bursary;
  4. use App\Entity\FundAccount;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class AdminHomeController extends AbstractController {
  12.     /**
  13.      * @Route("/admin", name="adminHomeRoute")
  14.      * @IsGranted("ROLE_ADMIN")
  15.      * @return Response
  16.      */
  17.     public function home(Request $request): Response {
  18.         $em $this->getDoctrine()->getManager();
  19.         $countyId $request->getSession()->get('county_id');
  20.         $currentBursary $em->getRepository(Bursary::class)->findOneBy([
  21.             // 'county' => $countyId
  22.         ],[ 'id' => 'desc']);
  23.         /** @var FundAccount[] $funds */
  24.         $funds $em->getRepository("App:FundAccount")->findBy([
  25.             'isCounty' => true
  26.         ]);
  27.         $countyTotals $em->getRepository('App:Student')
  28.             ->getCountyTotals($currentBursary);
  29.         $perWardTotals $em->getRepository('App:Student')->getPerWardTotals($currentBursary);
  30.         return $this->render('admin/home.html.twig',[
  31.             "totals" => $countyTotals,
  32.             "ward_totals" => $perWardTotals,
  33.             "bursary" => $currentBursary,
  34.             "funds" => $funds
  35.         ]);
  36.     }
  37.     /**
  38.      * @Route("/admin/application_statistics", name="adminDashStatistics")
  39.      * @IsGranted("ROLE_ADMIN")
  40.      * @return Response
  41.      */
  42.     public function dashStatistics(): Response
  43.     {
  44.         $em $this->getDoctrine()->getManager();
  45.         $currentBursary $em->getRepository(Bursary::class)->findOneBy([
  46.             // 'county' => $countyId
  47.         ],[ 'id' => 'desc']);
  48.         $stats  $em->getRepository('App:Student')->getPerWardTotals($currentBursary);
  49.         $categoryStats $em->getRepository('App:Student')->getPerCategoryTotals($currentBursary);
  50.         $data = [
  51.             'gender_stats' => $stats,
  52.             'category_stats' => $categoryStats
  53.         ];
  54.         return new JsonResponse($dataResponse::HTTP_OK, [
  55.             'content-type' => 'application/json'
  56.         ]);
  57.     }
  58.     /**
  59.      * @Route("/admin/fix_users", name="adminHomeUserfixRoute")
  60.      * @IsGranted("ROLE_ADMIN")
  61.      * @return Response
  62.      */
  63.     public function userFixAdmin(Request $request): Response {
  64.         $em $this->getDoctrine()->getManager();
  65.         $countyId $request->getSession()->get('county_id');
  66.         $county $em->getRepository("App:County")->findOneBy([
  67.             'id' => $countyId
  68.         ]);
  69.         $wards $em->getRepository('App:Ward')->findAll();
  70.         foreach ($wards as $index => $ward) {
  71.            $fundAccount = new FundAccount();
  72.            $fundAccount->setAmount(0);
  73.            $fundAccount->setBalance(0);
  74.            $fundAccount->setCounty($county);
  75.            $fundAccount->setCreatedBy($this->getUser());
  76.            $fundAccount->setAccountName($ward->getWardName().' WARD BURSARY FUND ACCOUNT');
  77.            $fundAccount->setIsDefault(false);
  78.            $fundAccount->setCreatedAt(new \DateTimeImmutable());
  79.            $em->persist($fundAccount);
  80.         }
  81.         $em->flush();
  82.          return $this->redirectToRoute('adminHomeRoute');
  83.     }
  84. }