src/Controller/DefaultController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Doctrine\ORM\QueryBuilder;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  10. use App\Entity\Projet;
  11. use App\Entity\{TacheEtatTacheAlertNotificationUser};
  12. use App\Repository\TacheRepository;
  13. class DefaultController extends AbstractController
  14. {
  15.     #[Route('/check'name'security.check'methods: ['GET'])]
  16.     public function check()
  17.     {
  18.         if(!$this->getUser()->getEnabled()){
  19.             return $this->redirectToRoute('security.logout');
  20.         }
  21.         /*if ($this->isGranted('ROLE_CLIENT')) {
  22.             return $this->redirectToRoute('dashboard.client');
  23.         }*/
  24.         return $this->redirectToRoute('index');
  25.     }
  26.     #[Route('/'name'index'methods: ['GET''POST'])]
  27.     public function home(EntityManagerInterface $emRequest $request)
  28.     {
  29.         /*if ($this->isGranted('ROLE_CLIENT')) {
  30.             $tous_les_projets_en_cours = $em->getRepository(Projet::class)->findEnCours();
  31.             return $this->redirectToRoute('dashboard.client');
  32.         }*/
  33.         $tous_les_projets_en_cours null;
  34.         $notifs_by_projet  $em->getRepository(Notification::class)->findNotifNonVuesParUser($this->getUser());
  35.         //si vue admin
  36.         $notifs $em->getRepository(Notification::class)->findNonVuesParUser($this->getUser());
  37.         $stats null;
  38.          if ($this->isGranted('ROLE_DEV')) {
  39.              //si dev pour commencer, les ordonner par priorité
  40.             $mes_projets_en_cours $em->getRepository(Projet::class)->findEnCoursByDevIndexedByClient($this->getUser());
  41.             $mes_taches_en_attentes =  $em->getRepository(Tache::class)->getTachesEnAttenteByDev($this->getUser());
  42.             $mes_taches_a_tester =  $em->getRepository(Tache::class)->getTachesATesterByDev($this->getUser());
  43.             $mes_taches_a_traiter =  $em->getRepository(Tache::class)->getTachesATraiterByDev($this->getUser());
  44.             $mes_taches_encours $em->getRepository(Tache::class)->getTachesEnCoursByDev($this->getUser());
  45.             $mes_taches_a_facturer null;
  46.             $mes_taches_en_brouillon null;
  47.             $mes_taches_atester $em->getRepository(Tache::class)->getTachesATesterByDev($this->getUser());
  48.             $mes_taches_resolues $em->getRepository(Tache::class)->getTachesResoluesByDev($this->getUser());
  49.         }else{
  50.             if ($this->isGranted('ROLE_ADMIN')) {
  51.                 $mes_projets_en_cours $em->getRepository(Projet::class)->findEnCoursByUserIndexedByClient($this->getUser());
  52.             }else{
  53.                 $mes_projets_en_cours $em->getRepository(Projet::class)->findEnCoursByUserIndexedByClient($this->getUser());
  54.             }
  55.             $mes_taches_en_attentes =  $em->getRepository(Tache::class)->getTachesEnAttenteByUser($this->getUser());
  56.             $mes_taches_a_traiter =  $em->getRepository(Tache::class)->getTachesATraiterByUser($this->getUser());
  57.             $mes_taches_encours $em->getRepository(Tache::class)->getTachesEnCoursByUser($this->getUser());
  58.             $mes_taches_atester $em->getRepository(Tache::class)->getTachesATesterByUser($this->getUser());
  59.             $mes_taches_resolues $em->getRepository(Tache::class)->getTachesResoluesByUser($this->getUser());
  60.             $mes_taches_en_brouillon $em->getRepository(Tache::class)->getTachesEnBrouillonByUser($this->getUser());
  61.         }
  62.         if ($this->isGranted('ROLE_ADMIN') OR $this->isGranted('ROLE_CHEF_PROJET')) {
  63.           $users $em->getRepository(User::class)->findDevEnabled();
  64.           $stats $em->getRepository(Tache::class)->getStatsDashboard($users);
  65.         }
  66.        /* if ($this->isGranted('ROLE_ADMIN')) {
  67.             $tous_les_projets_en_cours = $em->getRepository(Projet::class)->findEnCoursIndexedByClient();
  68.         }*/
  69.         $alert = new Alert();
  70.         $form_alerte $this->createForm('App\Form\AlertType'$alert);
  71.         $alertes $em->getRepository(Alert::class)->getAlertesNonVues($this->getUser());
  72.         $etats_taches $em->getRepository(EtatTache::class)->findAll();
  73.         $projets_aux $em->getRepository(Projet::class)->findAll();
  74.         $total_taches_by_etat $em->getRepository(Tache::class)->getByProjetEtEtats($projets_aux);
  75.         $projets_left_open = array();
  76.         $projets_right_open = array();
  77.         $a_en_attente_non_vues =  $em->getRepository(Notification::class)->getTotalNonVuesParTacheEtatModif(EtatTache::EN_ATTENTE$this->getUser());
  78.         $a_traiter_non_vues =  $em->getRepository(Notification::class)->getTotalNonVuesParTacheEtatModif(EtatTache::A_TRAITER $this->getUser());
  79.         $a_tester_non_vues =  $em->getRepository(Notification::class)->getTotalNonVuesParTacheEtatModif(EtatTache::A_TESTER $this->getUser() );
  80.         $a_encours_non_vues =  $em->getRepository(Notification::class)->getTotalNonVuesParTacheEtatModif(EtatTache::EN_COURS$this->getUser());
  81.         if ($request->isMethod('POST')) {
  82.             $projets_left_open $request->request->get('projets_left_open');
  83.             $projets_right_open $request->request->get('projets_right_open');
  84.             $tache_id $request->get('tache');
  85.             $projet_id $request->get('projet');
  86.             $em $this->getDoctrine()->getManager();
  87.             $tache $em->getRepository(Tache::class)->findOneById($tache_id);
  88.             $projet $em->getRepository(Projet::class)->findOneById($projet_id);
  89.             $tache->setProjet($projet);
  90.             $em->persist($tache);
  91.             $em->flush();
  92.         }
  93.         $etats Alert::getEtatChoices(true);
  94.         return $this->render('default/home_table.html.twig', [
  95.             'listes_des_projets' => $mes_projets_en_cours,
  96.           //  'suivi_production' => $tous_les_projets_en_cours,
  97.             'notifs_by_projet' => $notifs_by_projet,
  98.             'notifs' => $notifs,
  99.             'alertes' => $alertes,
  100.             'etats_taches' => $etats_taches,
  101.             'form_alerte' =>  $form_alerte->createView(),
  102.             'total_taches_by_etat' => $total_taches_by_etat,
  103.             'mes_taches_a_traiter' => $mes_taches_a_traiter,
  104.             'mes_taches_encours' => $mes_taches_encours,
  105.             'mes_taches_en_attente' => $mes_taches_en_attentes,
  106.             'mes_taches_a_tester' => $mes_taches_atester,
  107.             'mes_taches_resolues' => $mes_taches_resolues,
  108.             'mes_taches_en_brouillon'=>$mes_taches_en_brouillon,
  109.             'projets_left_open' =>$projets_left_open,
  110.             'projets_right_open' => $projets_right_open,
  111.             'etats' => $etats,
  112.             'a_en_attente_non_vues' => $a_en_attente_non_vues,
  113.             'a_traiter_non_vues' => $a_traiter_non_vues,
  114.             'a_tester_non_vues' => $a_tester_non_vues,
  115.             'a_encours_non_vues' => $a_encours_non_vues,
  116.             'stats' => $stats
  117.         ]);
  118.     }
  119.     #[Route('/home/{vue}'name'index_vues'methods: ['GET''POST'])]
  120.     public function indexAction(Request $requestEntityManagerInterface $em$vue="projets")
  121.     {
  122.         $tous_les_projets_en_cours null;
  123.         $mes_projets_en_cours $em->getRepository(Projet::class)->findEnCoursByUser($this->getUser());
  124.         $notifs_by_projet  $em->getRepository(Notification::class)->findNotifNonVuesParUser($this->getUser());
  125.         //si vue admin
  126.         $notifs $em->getRepository(Notification::class)->findNonVuesParUser($this->getUser());
  127.         if ($this->isGranted('ROLE_DEV')) {
  128.              //si dev pour commencer, les ordonner par priorité
  129.             $mes_taches_en_attentes =  $em->getRepository(Tache::class)->getTachesEnAttenteByDev($this->getUser());
  130.             $mes_taches_a_traiter =  $em->getRepository(Tache::class)->getTachesATraiterByDev($this->getUser());
  131.             $mes_taches_encours $em->getRepository(Tache::class)->getTachesEnCoursByDev($this->getUser());
  132.             $mes_taches_a_facturer null;
  133.             $mes_taches_atester $em->getRepository(Tache::class)->getTachesATesterByDev($this->getUser());
  134.         }else{
  135.             //si dev pour commencer, les ordonner par priorité
  136.             $mes_taches_en_attentes =  $em->getRepository(Tache::class)->getTachesEnAttenteByUser($this->getUser());
  137.             $mes_taches_a_traiter =  $em->getRepository(Tache::class)->getTachesATraiterByUser($this->getUser());
  138.             $mes_taches_encours $em->getRepository(Tache::class)->getTachesEnCoursByUser($this->getUser());
  139.             $mes_taches_a_facturer $em->getRepository(Tache::class)->getTachesAFactureesByUser($this->getUser());
  140.             $mes_taches_atester $em->getRepository(Tache::class)->getTachesATesterByUser($this->getUser());
  141.         }
  142.         if ($this->isGranted('ROLE_ADMIN')) {
  143.             $tous_les_projets_en_cours $em->getRepository(Projet::class)->findEnCours();
  144.         }
  145.         $alert = new Alert();
  146.         $form_alerte $this->createForm('App\Form\AlertType'$alert);
  147.         return $this->render('default/index.html.twig', [
  148.             'mes_projets_en_cours' => $mes_projets_en_cours,
  149.             'tous_les_projets_en_cours' => $tous_les_projets_en_cours,
  150.             'notifs_by_projet' => $notifs_by_projet,
  151.             'mes_taches_encours' => $mes_taches_encours,
  152.             'mes_taches_a_traiter' => $mes_taches_a_traiter,
  153.             'mes_taches_en_attentes' => $mes_taches_en_attentes,
  154.             'mes_taches_a_facture' => $mes_taches_a_facturer,
  155.             'mes_taches_atester' => $mes_taches_atester,
  156.             'vue_active' => $vue
  157.         ]);
  158.     }
  159.     #[Route('/taches2'name'index_taches2'methods: ['GET''POST'])]
  160.     public function index2Action(Request $requestEntityManagerInterface $em$vue="projets")
  161.     {
  162.         $tous_les_projets_en_cours null;
  163.         $mes_projets_en_cours $em->getRepository(Projet::class)->findEnCoursByUser($this->getUser());
  164.         $notifs_by_projet  $em->getRepository(Notification::class)->findNotifNonVuesParUser($this->getUser());
  165.         //si vue admin
  166.         $notifs $em->getRepository(Notification::class)->findNonVuesParUser($this->getUser());
  167.         if ($this->isGranted('ROLE_DEV')) {
  168.              //si dev pour commencer, les ordonner par priorité
  169.             $mes_taches_en_attentes =  $em->getRepository(Tache::class)->getTachesEnAttenteByDev($this->getUser());
  170.             $mes_taches_a_traiter =  $em->getRepository(Tache::class)->getTachesATraiterByDev($this->getUser());
  171.             $mes_taches_encours $em->getRepository(Tache::class)->getTachesEnCoursByDev($this->getUser());
  172.             $mes_taches_a_facturer null;
  173.         }else{
  174.             //si dev pour commencer, les ordonner par priorité
  175.             $mes_taches_en_attentes =  $em->getRepository(Tache::class)->getTachesEnAttenteByUser($this->getUser());
  176.             $mes_taches_a_traiter =  $em->getRepository(Tache::class)->getTachesATraiterByUser($this->getUser());
  177.             $mes_taches_encours $em->getRepository(Tache::class)->getTachesEnCoursByUser($this->getUser());
  178.             $mes_taches_a_facturer $em->getRepository(Tache::class)->getTachesAFactureesByUser($this->getUser());
  179.         }
  180.         if ($this->isGranted('ROLE_ADMIN')) {
  181.             $tous_les_projets_en_cours $em->getRepository(Projet::class)->findEnCours();
  182.         }
  183.         $alert = new Alert();
  184.         $form_alerte $this->createForm('App\Form\AlertType'$alert);
  185.         return $this->render('default/index.html.twig', [
  186.             'mes_projets_en_cours' => $mes_projets_en_cours,
  187.             'tous_les_projets_en_cours' => $tous_les_projets_en_cours,
  188.             'notifs_by_projet' => $notifs_by_projet,
  189.             'mes_taches_encours' => $mes_taches_encours,
  190.             'mes_taches_a_traiter' => $mes_taches_a_traiter,
  191.             'mes_taches_en_attentes' => $mes_taches_en_attentes,
  192.             'mes_taches_a_facture' => $mes_taches_a_facturer,
  193.             'vue_active' => $vue
  194.         ]);
  195.     }
  196.     public function filterLoadAction(TacheRepository $tacheRepository$projet_id)
  197.     {
  198.         $etats = [1,5,6];
  199.         if ($this->isGranted('ROLE_DEV')) {
  200.             $taches $tacheRepository->getTachesByEtatsDev($projet_id$etats$this->getUser());
  201.         }else{
  202.             $taches $tacheRepository->getTachesByEtats($projet_id$etats);
  203.         }
  204.         return $this->render('default/partials/taches_dash.html.twig', [
  205.             'taches' => $taches
  206.         ]);
  207.     }
  208.     #[Route('/filter'name'dashboard_tache_filter'methods: ['POST'])]
  209.     public function filterAction(Request $requestEntityManagerInterface $em)
  210.     {
  211.         $projet_id $request->get('projet');
  212.         $etats $request->get('etats');
  213.         if ($this->isGranted('ROLE_DEV')) {
  214.             $taches $em->getRepository(Tache::class)->getTachesByEtatsDev($projet_id$etats$this->getUser());
  215.         }else{
  216.             $taches $em->getRepository(Tache::class)->getTachesByEtats($projet_id$etats);
  217.         }
  218.         return $this->render('default/partials/taches_dash.html.twig', [
  219.             'taches' => $taches
  220.         ]);
  221.     }
  222.      public function totalTacheEnCoursAction(EntityManagerInterface $emTacheRepository $tacheRepositoryProjet $projet)
  223.     {
  224.         $taches $tacheRepository->getTotalTachesEnCours($projet);
  225.         $total $taches['total'];
  226.         if($total == 1){
  227.             return new Response($total." tâche en cours");
  228.         }else{
  229.             return new Response($total." tâches en cours");
  230.         }
  231.     }
  232.      public function totalTacheResolueesAction(Projet $projetEntityManagerInterface $em,  TacheRepository $tacheRepository)
  233.     {
  234.         $taches $tacheRepository->getTotalTachesResoluees($projet);
  235.         $total $taches['total'];
  236.         if($total == 1){
  237.             return new Response($total." tâche résolue");
  238.         }else{
  239.             return new Response($total." tâches résolues");
  240.         }
  241.     }
  242.     public function totalTacheATraiterAction(Projet $projetEntityManagerInterface $em,  TacheRepository $tacheRepository)
  243.     {
  244.         $taches $tacheRepository->getTotalTachesATraiter($projet);
  245.         $total $taches['total'];
  246.         if($total == 1){
  247.             return new Response($total." tâche à traiter");
  248.         }else{
  249.             return new Response($total." tâches à traiter");
  250.         }
  251.     }
  252. }
  253. /*
  254. UPDATE `user` SET roles = '["ROLE_CLIENT"]' WHERE roles LIKE 'a:1:{i:0;s:11:"ROLE_CLIENT";}';
  255. UPDATE `user` SET roles = '["ROLE_ADMIN"]' WHERE roles LIKE 'a:1:{i:0;s:10:"ROLE_ADMIN";}';
  256. UPDATE `user` SET roles = '["ROLE_DEV"]' WHERE roles LIKE 'a:1:{i:0;s:8:"ROLE_DEV";}';
  257. UPDATE `user` SET roles = '["ROLE_DEV","ROLE_CHEF_PROJET"]' WHERE roles LIKE a:2:{i:0;s:8:"ROLE_DEV";i:1;s:16:"ROLE_CHEF_PROJET";}';
  258. ALTER TABLE `user` CHANGE `username_canonical` `username_canonical` VARCHAR(180) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL, CHANGE `email_canonical` `email_canonical` VARCHAR(180) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL;
  259. */