src/Controller/Admin/DashboardController.php line 53
<?phpnamespace App\Controller\Admin;use App\Entity\User;use App\Repository\CommandeRepository;use App\Repository\FilieresRepository;use App\Repository\UserRepository;use App\Repository\LignecommandeRepository;use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Security\Core\Security;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\RequestStack;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\Console\Helper\ProgressBar;use Symfony\Component\Console\Output\StreamOutput;class DashboardController extends AbstractDashboardController{private $security;private $filieresRepository;private $ligneCommandeRepository;private $commandeRepository;private $userRepository;private $requestStack;public function __construct(Security $security,FilieresRepository $filieresRepository,LignecommandeRepository $ligneCommandeRepository,CommandeRepository $commandeRepository,UserRepository $userRepository,RequestStack $requestStack){$this->security = $security;$this->filieresRepository = $filieresRepository;$this->ligneCommandeRepository = $ligneCommandeRepository;$this->commandeRepository = $commandeRepository;$this->userRepository = $userRepository;$this->requestStack = $requestStack;}#[Route('/', name: 'home')]#[Route('/admin', name: 'admin')]#[Route('/adresses', name: 'adresses')]public function index(): Response{$adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);$url = $adminUrlGenerator->setRoute('adresses', [])->generateUrl();return $this->redirect($url);//return parent::index();// Option 1. You can make your dashboard redirect to some common page of your backend//// $adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);// return $this->redirect($adminUrlGenerator->setController(OneOfYourCrudController::class)->generateUrl());// Option 2. You can make your dashboard redirect to different pages depending on the user//// if ('jane' === $this->getUser()->getUsername()) {// return $this->redirect('...');// }// Option 3. You can render some custom template to display a proper dashboard with widgets, etc.// (tip: it's easier if your template extends from @EasyAdmin/page/content.html.twig)////return $this->render('pages/default/dashboard.html.twig');//return $this->redirectToRoute('adresses');//return $this->render('pages/default/autres_adresses.html.twig');//return parent::index();}public function goListeAdresses(FilieresRepository $filieres, UserRepository $user, Request $request): Response{$login = $request->getSession()->get(Security::LAST_USERNAME);$listeAdresses = $filieres->getListeAdresses($login);$adresseSTA = $filieres->getAdresseParType($login,'STA');$aInfosClient = $user->getInfosUtilisateurParCodeClient($login,false);return $this->render('pages/default/autres_adresses.html.twig', ['$aInfosClient' => $aInfosClient,'listeAdresses' => $listeAdresses,'adresseSTA' => $adresseSTA]);}public function configureDashboard(): Dashboard{return Dashboard::new()->setTitle('Commande MGS')->disableDarkMode()->setFaviconPath('');}public function configureMenuItems(): iterable{$adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);$routeName = $_GET["routeName"];$session = $this->requestStack->getSession();//dd($session->get('code_client_connecte'));// on récupère les infos de la filière$oFilieres = $this->filieresRepository->findOneBy(['commande_par' => $session->get('code_regroupement'),'compte_client_livre' => $session->get('compte_client_choisi'),]);//dd($oFilieres);$oUser = $this->userRepository->findOneBy(['code_client' => $session->get('code_client_connecte'),]);//dd($oUser);// on compte le nombre de commandes dans le panier$aLigneCommande = $this->ligneCommandeRepository->getLigneCommandeEnCoursDerniereCommande($oFilieres);// Liste des adresses de filieres pour afficher ou nom le menu "Autres adresses"//$aListeAdressesFilieres = $this->filieresRepository->getListeAdresses($oFilieres->getCompteClientLivre(),false,true);// on recherche si pour ce client, on a une commande à valider/*$oFilieresCommandeAttente = $this->filieresRepository->findBy(['compte_client_livre' => $session->get('code_client_connecte'),]);*/$oCommandeAttente = $this->commandeRepository->getCommandesByFiliere($session->get('compte_client_choisi'), "V", "");/*if(isset($oFilieresCommandeAttente)){$iCountCommandeEnAttente = 0;foreach($oFilieresCommandeAttente as $filiere){$iCountCommandeEnAttente += $this->commandeRepository->count(['valide' => 'V','filiere' => $filiere->getId()]);}}else{$iCountCommandeEnAttente = 0;}*///if(count($aListeAdressesFilieres) > 1)if($oUser->getCommande() == "C"){yield MenuItem::linkToUrl('Autres adresses', 'fa fa-address-book', $adminUrlGenerator->setRoute('adresses', [])->generateUrl());}if($routeName != "adresses" && $session->get('compte_client_choisi') !== null){yield MenuItem::linkToUrl('Vos tarifs', 'fa fa-euro-sign', $adminUrlGenerator->setRoute('tarifs', [])->generateUrl());}if($routeName != "adresses" && $session->get('compte_client_choisi') !== null){//yield MenuItem::linkToUrl('Panier ('.count($aLigneCommande).')', 'fa fa-cart-shopping', $adminUrlGenerator->setRoute('panier', [])->generateUrl());yield MenuItem::linkToUrl('Panier', 'fa fa-cart-shopping', $adminUrlGenerator->setRoute('panier', [])->generateUrl());}// s'il y a au moins une commande à valider alors on affiche dans le menu "Commande en attente"if($routeName != "adresses" && count($oCommandeAttente) > 0){yield MenuItem::linkToUrl('Commande en attente ('.count($oCommandeAttente).')', 'fa fa-hourglass-half', $adminUrlGenerator->setRoute('commandeenattente', [])->generateUrl());}if($routeName != "adresses" && $session->get('compte_client_choisi') !== null){yield MenuItem::linkToUrl('Suivi de commande', 'fa fa-truck', $adminUrlGenerator->setRoute('suiviCommande', [])->generateUrl());}yield MenuItem::linkToUrl('Statistiques', 'fa fa-area-chart', $adminUrlGenerator->setRoute('statistiques', [])->generateUrl());}}