src/Controller/DashboardController.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\EventData;
  4. use App\Entity\Farm;
  5. use App\Entity\Animal;
  6. use App\Repository\EventDataRepository;
  7. use App\Repository\FarmRepository;
  8. use App\Repository\OrganizationRepository;
  9. use App\Service\DashboardService;
  10. use App\Service\EventDataService;
  11. use App\Repository\LotRepository;
  12. use App\Repository\TreatmentRepository;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\Security\Core\Security;
  18. use App\Controller\Common\MetadataBuilder;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. class DashboardController extends AbstractController
  21. {
  22.     use MetadataBuilder;
  23.     private $security;
  24.     private TranslatorInterface $translator;
  25.     public function __construct(Security $securityTranslatorInterface $translator )
  26.     {
  27.         $this->security $security;
  28.         $this->translator $translator;
  29.     }
  30.     /**
  31.      * @Route("/", name="app_home")
  32.      */
  33.     public function home(): Response
  34.     {/*{{{*/
  35.     $route_name =  ( $this->isGranted('ROLE_ADMIN') ) ? 'organization_index' 'app_dashboard';
  36.         return $this->redirectToRoute($route_name);
  37.     }/*}}}*/
  38.     /**
  39.      * @Route("/dashboard", name="app_dashboard")
  40.      */
  41.     public function index(
  42.         EventDataRepository $eventDataRepository,
  43.         OrganizationRepository $organizationRepository
  44.         FarmRepository $farmRepository
  45.         LotRepository $lotRepository
  46.         Request $request
  47.     ): Response
  48.     {/*{{{*/
  49.         $organization null;
  50.         $organizationId null;
  51.         $addressList = [];
  52.         $listFarm = [];
  53.         $userAux null;
  54.         /* user login */
  55.         $animalRepository $this->getDoctrine()->getRepository(Animal::class);
  56.         if ( ! $this->isGranted('ROLE_ADMIN') ) {
  57.             $this->isGranted('ROLE_MANAGER') or $userAux $this->getUser();
  58.             $organization $this->getUser()->getOrganization();
  59.             $organizationId $organization->getId();
  60.         }
  61.         
  62.         $listFarm $this->getDoctrine()->getRepository(Farm::class)->getListQuery$organizationId )->getQuery()->getResult();
  63.         // dd( $listFarm );
  64.         foreach ($listFarm as $farm) {
  65.             if ( isset($farm['latitude']) and isset($farm['longitude']) ) {
  66.                 $addressList[] = [
  67.                     'name' => $farm['name'],
  68.                     'farmId' => $farm['id'],
  69.                     'position' => [
  70.                         'lat' => $farm['latitude'],
  71.                         'lng' => $farm['longitude']
  72.                 ]];            
  73.             }
  74.         }
  75.         $lots null;
  76.         
  77.         $stats $organizationRepository->getStatsQuery$organizationId )->getQuery()->getSingleResult();
  78.         // dd( $stats );
  79.         $stockMatrix $animalRepository->getAnimalsByCategory($organizationId);
  80.         $allData = [
  81.             'stats' => $stats,
  82.             'stockMatrix' => $stockMatrix,
  83.             'listFarm' => $listFarm,
  84.             'addressList' => $addressList,
  85.             'gridConfig' => [
  86.                 'farm' => $this->getGridConfig($farmRepository$farmRepository->getListQuery($organizationId), 'farm-dashboard'),
  87.                 'event_data' => $this->getGridConfig($eventDataRepository$eventDataRepository->getListQuery($organizationId), 'event_data-dashboard'),
  88.                 'lot' => $this->getGridConfig($lotRepository$lotRepository->getListQuery($organizationId), 'lot-dashboard')
  89.             ]
  90.         ];
  91.         // dd( $allData );
  92.         $request->get('dd') and dd$allData );
  93.         return $this->render('dashboard/index.html.twig'$allData );
  94.     }/*}}}*/
  95.     /**
  96.      * @Route("/ajax/dashboardData", name="ajax_get_dashboard_data")
  97.      */
  98.     public function getDashboardData(Request $requestDashboardService $dashboardService)
  99.     {/*{{{*/
  100.             $user null;
  101.         if ( ! $this->isGranted('ROLE_ADMIN') ) {
  102.             $user $this->getUser();
  103.         }
  104.         $filters $request->query->get('filters');
  105.         $dashboardData $dashboardService->getDashboardData($user$filters);
  106.         return $this->json($dashboardData);
  107.     }/*}}}*/
  108. }