src/Controller/DashboardController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  8. use App\Notification\Notification;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. use App\Repository\NotificationRepository;
  11. use App\Service\StatService;
  12. use App\Form\ExportType;
  13. use App\Service\ExportDataStat;
  14. /**
  15. * @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_AGENT') or is_granted('ROLE_ADMINISTRATOR') or is_granted('ROLE_CONSULTANT')")
  16. */
  17. class DashboardController extends AbstractController
  18. {
  19.     private $manager;
  20.     private $notificationRepository;
  21.     private $stats;
  22.     private $exportDataStat;
  23.     public function __construct(StatService $stats,ManagerRegistry $doctrineNotificationRepository $notificationRepository,ExportDataStat $exportDataStat)
  24.     {
  25.         $this->manager $doctrine->getManager();
  26.         $this->notificationRepository=$notificationRepository;
  27.         $this->stats $stats;
  28.         $this->exportDataStat $exportDataStat;
  29.     }
  30.     #[Route('/'name'app_dashboard')]
  31.     public function index(Notification $notification,Request $request): Response
  32.     {
  33.         /*$notification->sendNotification();*/
  34.         $exportForm $this->createForm(ExportType::class);
  35.         $exportForm->handleRequest($request);
  36.         if($exportForm->isSubmitted())
  37.         {
  38.             $this->exportDataStat->export();
  39.         }
  40.         $stats $this->stats->getStats();
  41.         return $this->render('dashboard/index.html.twig', [
  42.             'stats' => $stats,
  43.             'exportForm'=>$exportForm->createView()
  44.         ]);
  45.     }
  46.     #[Route('/save/token'name'app_token')]
  47.     public function saveToken(Request $request)
  48.     {
  49.        $user=$this->getUser();
  50.        try{
  51.         $user->setToken($request->request->get('token'));
  52.         $this->manager->persist($user);
  53.         $this->manager->flush();
  54.        }catch(\Exeption $e){
  55.           
  56.        }
  57.        
  58.        return $this->json(['message'=>'succes']);
  59.        
  60.     }
  61.     #[Route('/notif/number'name'app_notif')]
  62.     public function getNotif()
  63.     {
  64.         $notifCount=count($this->notificationRepository->findBy(['direction'=>'agent','status'=>0]));
  65.         return $this->json(['number'=> $notifCount]);
  66.     }
  67. }