src/Controller/DefaultController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Employee;
  4. use App\Entity\Enterprise;
  5. use App\Entity\Reporting;
  6. use App\Entity\Town;
  7. use App\Repository\CommuneRepository;
  8. use App\Repository\DepartmentRepository;
  9. use App\Repository\EmployeeRepository;
  10. use App\Repository\EnterpriseRepository;
  11. use App\Repository\ReportingRepository;
  12. use App\Repository\ReportingTableRepository;
  13. use App\Repository\TownRepository;
  14. use App\Repository\UserRepository;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use JMS\Serializer\SerializerInterface;
  20. class DefaultController extends AbstractController
  21. {
  22.     public const ID_MENU 1;
  23.     public const TABLE 'table';
  24.     public const GRAPHIC 'graphic';
  25.     #[Route('/'name'app_default')]
  26.     public function index(
  27.         Request $request,
  28.         ReportingRepository $reportingRepository,
  29.         ReportingTableRepository $reportingTableRepository,
  30.         UserRepository $userRepository,
  31.         EnterpriseRepository $enterpriseRepository,
  32.         EmployeeRepository $employeeRepository
  33.     ): Response {
  34.         $id $request->get('id') ?? 0;
  35.         $lastReporting =  $reportingRepository->findOneBy(['state' => 0], ['id' => 'DESC']);
  36.         $numInitiated $enterpriseRepository->countFolderByState($this->getUser(), $lastReporting);
  37.         $numValidate $enterpriseRepository->countFolderByState($this->getUser(), $lastReportingEnterprise::VALIDATED_STATUS);
  38.         $numRejected $enterpriseRepository->countFolderByState($this->getUser(), $lastReportingEnterprise::REJECTED_STATUS);
  39.         $numSubmited $enterpriseRepository->countFolderByState($this->getUser(), $lastReportingEnterprise::SUBMITED_STATUS);
  40.         return $this->render('default/index.html.twig', [
  41.             'numInitiated'    => $numInitiated,
  42.             'numValidated'  => $numValidate,
  43.             'numSubmited'  => $numSubmited,
  44.             'numRejected'   => $numRejected,
  45.             'reportings'    => $reportingRepository->findAll(),
  46.             'tables'        => $reportingTableRepository->findByType(self::TABLE),
  47.             'graphics'        => $reportingTableRepository->findByType(self::GRAPHIC),
  48.             'reporting'     => $reportingRepository->find($id),
  49.             'lastReporting' => $lastReporting,
  50.             'nbUsers'       => sizeof($userRepository->findAll()),
  51.             'stats'         => $lastReporting $reportingRepository->findStatsByTown($lastReporting->getId()) : [],
  52.             'nbEnterprises' => $enterpriseRepository->findBy([
  53.                 'reporting' => $lastReporting,
  54.                 'state'     => Enterprise::VALIDATED_STATUS
  55.             ]),
  56.             'nbEmployees' => $employeeRepository->findEmployees($lastReporting->getId(), nullnull)
  57.         ]);
  58.     }
  59.     #[Route('/departments'name'department_list'methods: ['GET'])]
  60.     public function listDepartment(
  61.         Request $request,
  62.         SerializerInterface $serializerInterface,
  63.         TownRepository $townRepository,
  64.         DepartmentRepository $repos
  65.     ): Response {
  66.         $town $townRepository->find($request->get('town'));
  67.         return new Response(
  68.             $serializerInterface->serialize($repos->findByTown($town), 'json'),
  69.             200,
  70.             ['Content-Type' => 'application/json']
  71.         );
  72.     }
  73.     #[Route('/employee/{id}/{name}'name'employee_info'methods: ['GET'])]
  74.     public function employee(
  75.         Enterprise $enterprise,
  76.         SerializerInterface $serializerInterface,
  77.         string $name,
  78.         EmployeeRepository $employeeRepository
  79.     ): Response {
  80.         $employee $employeeRepository->findByName($name$enterprise->getId());
  81.         
  82.         if ($employee) {
  83.             $employee->getNom();
  84.         }
  85.         return new Response(
  86.             $serializerInterface->serialize($employee'json'),
  87.             200,
  88.             ['Content-Type' => 'application/json']
  89.         );
  90.     }
  91.     #[Route('/communes'name'commune_list'methods: ['GET'])]
  92.     public function listCommune(
  93.         Request $request,
  94.         SerializerInterface $serializerInterface,
  95.         DepartmentRepository $departmentRepository,
  96.         CommuneRepository $repos
  97.     ): Response {
  98.         $dep $departmentRepository->find($request->get('department'));
  99.         return new Response(
  100.             $serializerInterface->serialize($repos->findByDepartment($dep), 'json'),
  101.             200,
  102.             ['Content-Type' => 'application/json']
  103.         );
  104.     }
  105. }