<?php
namespace App\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use App\Entity\Projet;
use App\Entity\{Tache, EtatTache, Alert, Notification, User};
use App\Repository\TacheRepository;
class DefaultController extends AbstractController
{
#[Route('/check', name: 'security.check', methods: ['GET'])]
public function check()
{
if(!$this->getUser()->getEnabled()){
return $this->redirectToRoute('security.logout');
}
/*if ($this->isGranted('ROLE_CLIENT')) {
return $this->redirectToRoute('dashboard.client');
}*/
return $this->redirectToRoute('index');
}
#[Route('/', name: 'index', methods: ['GET', 'POST'])]
public function home(EntityManagerInterface $em, Request $request)
{
/*if ($this->isGranted('ROLE_CLIENT')) {
$tous_les_projets_en_cours = $em->getRepository(Projet::class)->findEnCours();
return $this->redirectToRoute('dashboard.client');
}*/
$tous_les_projets_en_cours = null;
$notifs_by_projet = $em->getRepository(Notification::class)->findNotifNonVuesParUser($this->getUser());
//si vue admin
$notifs = $em->getRepository(Notification::class)->findNonVuesParUser($this->getUser());
$stats = null;
if ($this->isGranted('ROLE_DEV')) {
//si dev pour commencer, les ordonner par priorité
$mes_projets_en_cours = $em->getRepository(Projet::class)->findEnCoursByDevIndexedByClient($this->getUser());
$mes_taches_en_attentes = $em->getRepository(Tache::class)->getTachesEnAttenteByDev($this->getUser());
$mes_taches_a_tester = $em->getRepository(Tache::class)->getTachesATesterByDev($this->getUser());
$mes_taches_a_traiter = $em->getRepository(Tache::class)->getTachesATraiterByDev($this->getUser());
$mes_taches_encours = $em->getRepository(Tache::class)->getTachesEnCoursByDev($this->getUser());
$mes_taches_a_facturer = null;
$mes_taches_en_brouillon = null;
$mes_taches_atester = $em->getRepository(Tache::class)->getTachesATesterByDev($this->getUser());
$mes_taches_resolues = $em->getRepository(Tache::class)->getTachesResoluesByDev($this->getUser());
}else{
if ($this->isGranted('ROLE_ADMIN')) {
$mes_projets_en_cours = $em->getRepository(Projet::class)->findEnCoursByUserIndexedByClient($this->getUser());
}else{
$mes_projets_en_cours = $em->getRepository(Projet::class)->findEnCoursByUserIndexedByClient($this->getUser());
}
$mes_taches_en_attentes = $em->getRepository(Tache::class)->getTachesEnAttenteByUser($this->getUser());
$mes_taches_a_traiter = $em->getRepository(Tache::class)->getTachesATraiterByUser($this->getUser());
$mes_taches_encours = $em->getRepository(Tache::class)->getTachesEnCoursByUser($this->getUser());
$mes_taches_atester = $em->getRepository(Tache::class)->getTachesATesterByUser($this->getUser());
$mes_taches_resolues = $em->getRepository(Tache::class)->getTachesResoluesByUser($this->getUser());
$mes_taches_en_brouillon = $em->getRepository(Tache::class)->getTachesEnBrouillonByUser($this->getUser());
}
if ($this->isGranted('ROLE_ADMIN') OR $this->isGranted('ROLE_CHEF_PROJET')) {
$users = $em->getRepository(User::class)->findDevEnabled();
$stats = $em->getRepository(Tache::class)->getStatsDashboard($users);
}
/* if ($this->isGranted('ROLE_ADMIN')) {
$tous_les_projets_en_cours = $em->getRepository(Projet::class)->findEnCoursIndexedByClient();
}*/
$alert = new Alert();
$form_alerte = $this->createForm('App\Form\AlertType', $alert);
$alertes = $em->getRepository(Alert::class)->getAlertesNonVues($this->getUser());
$etats_taches = $em->getRepository(EtatTache::class)->findAll();
$projets_aux = $em->getRepository(Projet::class)->findAll();
$total_taches_by_etat = $em->getRepository(Tache::class)->getByProjetEtEtats($projets_aux);
$projets_left_open = array();
$projets_right_open = array();
$a_en_attente_non_vues = $em->getRepository(Notification::class)->getTotalNonVuesParTacheEtatModif(EtatTache::EN_ATTENTE, $this->getUser());
$a_traiter_non_vues = $em->getRepository(Notification::class)->getTotalNonVuesParTacheEtatModif(EtatTache::A_TRAITER , $this->getUser());
$a_tester_non_vues = $em->getRepository(Notification::class)->getTotalNonVuesParTacheEtatModif(EtatTache::A_TESTER , $this->getUser() );
$a_encours_non_vues = $em->getRepository(Notification::class)->getTotalNonVuesParTacheEtatModif(EtatTache::EN_COURS, $this->getUser());
if ($request->isMethod('POST')) {
$projets_left_open = $request->request->get('projets_left_open');
$projets_right_open = $request->request->get('projets_right_open');
$tache_id = $request->get('tache');
$projet_id = $request->get('projet');
$em = $this->getDoctrine()->getManager();
$tache = $em->getRepository(Tache::class)->findOneById($tache_id);
$projet = $em->getRepository(Projet::class)->findOneById($projet_id);
$tache->setProjet($projet);
$em->persist($tache);
$em->flush();
}
$etats = Alert::getEtatChoices(true);
return $this->render('default/home_table.html.twig', [
'listes_des_projets' => $mes_projets_en_cours,
// 'suivi_production' => $tous_les_projets_en_cours,
'notifs_by_projet' => $notifs_by_projet,
'notifs' => $notifs,
'alertes' => $alertes,
'etats_taches' => $etats_taches,
'form_alerte' => $form_alerte->createView(),
'total_taches_by_etat' => $total_taches_by_etat,
'mes_taches_a_traiter' => $mes_taches_a_traiter,
'mes_taches_encours' => $mes_taches_encours,
'mes_taches_en_attente' => $mes_taches_en_attentes,
'mes_taches_a_tester' => $mes_taches_atester,
'mes_taches_resolues' => $mes_taches_resolues,
'mes_taches_en_brouillon'=>$mes_taches_en_brouillon,
'projets_left_open' =>$projets_left_open,
'projets_right_open' => $projets_right_open,
'etats' => $etats,
'a_en_attente_non_vues' => $a_en_attente_non_vues,
'a_traiter_non_vues' => $a_traiter_non_vues,
'a_tester_non_vues' => $a_tester_non_vues,
'a_encours_non_vues' => $a_encours_non_vues,
'stats' => $stats
]);
}
#[Route('/home/{vue}', name: 'index_vues', methods: ['GET', 'POST'])]
public function indexAction(Request $request, EntityManagerInterface $em, $vue="projets")
{
$tous_les_projets_en_cours = null;
$mes_projets_en_cours = $em->getRepository(Projet::class)->findEnCoursByUser($this->getUser());
$notifs_by_projet = $em->getRepository(Notification::class)->findNotifNonVuesParUser($this->getUser());
//si vue admin
$notifs = $em->getRepository(Notification::class)->findNonVuesParUser($this->getUser());
if ($this->isGranted('ROLE_DEV')) {
//si dev pour commencer, les ordonner par priorité
$mes_taches_en_attentes = $em->getRepository(Tache::class)->getTachesEnAttenteByDev($this->getUser());
$mes_taches_a_traiter = $em->getRepository(Tache::class)->getTachesATraiterByDev($this->getUser());
$mes_taches_encours = $em->getRepository(Tache::class)->getTachesEnCoursByDev($this->getUser());
$mes_taches_a_facturer = null;
$mes_taches_atester = $em->getRepository(Tache::class)->getTachesATesterByDev($this->getUser());
}else{
//si dev pour commencer, les ordonner par priorité
$mes_taches_en_attentes = $em->getRepository(Tache::class)->getTachesEnAttenteByUser($this->getUser());
$mes_taches_a_traiter = $em->getRepository(Tache::class)->getTachesATraiterByUser($this->getUser());
$mes_taches_encours = $em->getRepository(Tache::class)->getTachesEnCoursByUser($this->getUser());
$mes_taches_a_facturer = $em->getRepository(Tache::class)->getTachesAFactureesByUser($this->getUser());
$mes_taches_atester = $em->getRepository(Tache::class)->getTachesATesterByUser($this->getUser());
}
if ($this->isGranted('ROLE_ADMIN')) {
$tous_les_projets_en_cours = $em->getRepository(Projet::class)->findEnCours();
}
$alert = new Alert();
$form_alerte = $this->createForm('App\Form\AlertType', $alert);
return $this->render('default/index.html.twig', [
'mes_projets_en_cours' => $mes_projets_en_cours,
'tous_les_projets_en_cours' => $tous_les_projets_en_cours,
'notifs_by_projet' => $notifs_by_projet,
'mes_taches_encours' => $mes_taches_encours,
'mes_taches_a_traiter' => $mes_taches_a_traiter,
'mes_taches_en_attentes' => $mes_taches_en_attentes,
'mes_taches_a_facture' => $mes_taches_a_facturer,
'mes_taches_atester' => $mes_taches_atester,
'vue_active' => $vue
]);
}
#[Route('/taches2', name: 'index_taches2', methods: ['GET', 'POST'])]
public function index2Action(Request $request, EntityManagerInterface $em, $vue="projets")
{
$tous_les_projets_en_cours = null;
$mes_projets_en_cours = $em->getRepository(Projet::class)->findEnCoursByUser($this->getUser());
$notifs_by_projet = $em->getRepository(Notification::class)->findNotifNonVuesParUser($this->getUser());
//si vue admin
$notifs = $em->getRepository(Notification::class)->findNonVuesParUser($this->getUser());
if ($this->isGranted('ROLE_DEV')) {
//si dev pour commencer, les ordonner par priorité
$mes_taches_en_attentes = $em->getRepository(Tache::class)->getTachesEnAttenteByDev($this->getUser());
$mes_taches_a_traiter = $em->getRepository(Tache::class)->getTachesATraiterByDev($this->getUser());
$mes_taches_encours = $em->getRepository(Tache::class)->getTachesEnCoursByDev($this->getUser());
$mes_taches_a_facturer = null;
}else{
//si dev pour commencer, les ordonner par priorité
$mes_taches_en_attentes = $em->getRepository(Tache::class)->getTachesEnAttenteByUser($this->getUser());
$mes_taches_a_traiter = $em->getRepository(Tache::class)->getTachesATraiterByUser($this->getUser());
$mes_taches_encours = $em->getRepository(Tache::class)->getTachesEnCoursByUser($this->getUser());
$mes_taches_a_facturer = $em->getRepository(Tache::class)->getTachesAFactureesByUser($this->getUser());
}
if ($this->isGranted('ROLE_ADMIN')) {
$tous_les_projets_en_cours = $em->getRepository(Projet::class)->findEnCours();
}
$alert = new Alert();
$form_alerte = $this->createForm('App\Form\AlertType', $alert);
return $this->render('default/index.html.twig', [
'mes_projets_en_cours' => $mes_projets_en_cours,
'tous_les_projets_en_cours' => $tous_les_projets_en_cours,
'notifs_by_projet' => $notifs_by_projet,
'mes_taches_encours' => $mes_taches_encours,
'mes_taches_a_traiter' => $mes_taches_a_traiter,
'mes_taches_en_attentes' => $mes_taches_en_attentes,
'mes_taches_a_facture' => $mes_taches_a_facturer,
'vue_active' => $vue
]);
}
public function filterLoadAction(TacheRepository $tacheRepository, $projet_id)
{
$etats = [1,5,6];
if ($this->isGranted('ROLE_DEV')) {
$taches = $tacheRepository->getTachesByEtatsDev($projet_id, $etats, $this->getUser());
}else{
$taches = $tacheRepository->getTachesByEtats($projet_id, $etats);
}
return $this->render('default/partials/taches_dash.html.twig', [
'taches' => $taches
]);
}
#[Route('/filter', name: 'dashboard_tache_filter', methods: ['POST'])]
public function filterAction(Request $request, EntityManagerInterface $em)
{
$projet_id = $request->get('projet');
$etats = $request->get('etats');
if ($this->isGranted('ROLE_DEV')) {
$taches = $em->getRepository(Tache::class)->getTachesByEtatsDev($projet_id, $etats, $this->getUser());
}else{
$taches = $em->getRepository(Tache::class)->getTachesByEtats($projet_id, $etats);
}
return $this->render('default/partials/taches_dash.html.twig', [
'taches' => $taches
]);
}
public function totalTacheEnCoursAction(EntityManagerInterface $em, TacheRepository $tacheRepository, Projet $projet)
{
$taches = $tacheRepository->getTotalTachesEnCours($projet);
$total = $taches['total'];
if($total == 1){
return new Response($total." tâche en cours");
}else{
return new Response($total." tâches en cours");
}
}
public function totalTacheResolueesAction(Projet $projet, EntityManagerInterface $em, TacheRepository $tacheRepository)
{
$taches = $tacheRepository->getTotalTachesResoluees($projet);
$total = $taches['total'];
if($total == 1){
return new Response($total." tâche résolue");
}else{
return new Response($total." tâches résolues");
}
}
public function totalTacheATraiterAction(Projet $projet, EntityManagerInterface $em, TacheRepository $tacheRepository)
{
$taches = $tacheRepository->getTotalTachesATraiter($projet);
$total = $taches['total'];
if($total == 1){
return new Response($total." tâche à traiter");
}else{
return new Response($total." tâches à traiter");
}
}
}
/*
UPDATE `user` SET roles = '["ROLE_CLIENT"]' WHERE roles LIKE 'a:1:{i:0;s:11:"ROLE_CLIENT";}';
UPDATE `user` SET roles = '["ROLE_ADMIN"]' WHERE roles LIKE 'a:1:{i:0;s:10:"ROLE_ADMIN";}';
UPDATE `user` SET roles = '["ROLE_DEV"]' WHERE roles LIKE 'a:1:{i:0;s:8:"ROLE_DEV";}';
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";}';
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;
*/