src/Controller/Admin/DashboardController.php line 97

  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\Application;
  4. use App\Entity\CurrencyExchangeRate;
  5. use App\Entity\ExportExcel;
  6. use App\Entity\FrontTheme;
  7. use App\Entity\Link;
  8. use App\Entity\LinkType;
  9. use App\Entity\LogHistory;
  10. use App\Entity\Notification;
  11. use App\Entity\Role;
  12. use App\Entity\Settings;
  13. use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
  14. use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
  15. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use App\Entity\User;
  19. use App\Entity\WebsiteTheme;
  20. use App\Flexy\ShopBundle\Entity\Product\Product;
  21. use App\Flexy\ShopBundle\Entity\Store\Store;
  22. use App\Flexy\ShopBundle\Entity\Vendor\Vendor;
  23. use App\Flexy\ShopBundle\Service\FlexyShopStatisticProvider;
  24. use App\Repository\ApplicationRepository;
  25. use App\Service\FlexySettingsProvider;
  26. use Doctrine\Persistence\ManagerRegistry;
  27. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  28. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  29. use Symfony\Component\Filesystem\Filesystem;
  30. use Symfony\Component\Finder\Finder;
  31. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  32. use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
  33. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  34. use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;
  35. use Symfony\Component\HttpFoundation\Request;
  36. class DashboardController extends AbstractDashboardController
  37. {
  38.     
  39.     
  40.     public function __construct(
  41.         private readonly ManagerRegistry $doctrine,
  42.         private readonly FlexyShopStatisticProvider $flexyShopStatisticProvider
  43.         )
  44.     {  
  45.         
  46.     }
  47.     #[Route(path'/admin'name'admin_non_locale')]
  48.     public function indexNonLocale(Request $request): Response
  49.     {        
  50.         return $this->redirectToRoute("admin",["_locale"=>$request->getLocale()]);
  51.     }
  52.     #[Route('/{_locale}/admin/website-theme/grapesjs_edit'name'website_theme_grapesjs_edit')]
  53.     public function website_theme_grapesjs_edit(): Response
  54.     {
  55.         
  56.         return $this->render('@Flexy/FrontBundle/Themes/'.$this->container->get('twig')->getGlobals()["settings"]->get()->getAssetFolderName().'/templates/admin/website-theme/grapesjs.html.twig');
  57.     }
  58.     #[Route(path'/{_locale}/admin/apps-store'name'app_store')]
  59.     public function appStore(Request $request,ApplicationRepository $applicationRepository,FlexySettingsProvider $flexySettingsProvider): Response
  60.     {        
  61.         
  62.         $appsArray = [];
  63.         foreach($applicationRepository->findAll() as $singleApp){
  64.             $appsArray[] = [
  65.                 "id"=>$singleApp->getId(),
  66.                 "name"=>$singleApp->getName(),
  67.                 "image"=>$singleApp->getImage(),
  68.                 "price"=>$singleApp->getPrice(),
  69.                 "pageUrl"=>$singleApp->getPageUrl(),
  70.             ];
  71.         }
  72.         return $this->render("admin/app-store.html.twig",[
  73.             "installedApps"=>$appsArray,
  74.             "JWT"=>$flexySettingsProvider->createJWTForUser($this->getUser())
  75.         ]);
  76.     }
  77.     
  78.     #[Route(path'/{_locale}/admin'name'admin')]
  79.     public function index(): Response
  80.     {        
  81.         return $this->render("bundles/EasyAdminBundle/welcome.html.twig");
  82.     }
  83.     public function configureCrud(): Crud
  84.     {
  85.         return 
  86.         Crud::new()
  87.         ->setDefaultSort(["id"=> 'DESC'])
  88.         ->setPaginatorPageSize(12)
  89.         
  90.         ;
  91.     }
  92.   
  93.     public function configureDashboard(): Dashboard
  94.     {
  95.         $mainSettings $this->doctrine->getManager()->getRepository(Settings::class)->findOneBy(["code"=>"main"]);
  96.         $nameSpaceTrans strtolower($mainSettings->getProjectName())."-admin";
  97.         
  98.         $urlImage "../themes/".strtolower($mainSettings->getAssetFolderName())."/admin/images/logo.png";
  99.         
  100.         
  101.         return Dashboard::new()
  102.             ->setTitle('<img title="Dashboard" src="'.$urlImage.'" />
  103.             
  104.             ')
  105.            //->renderContentMaximized()
  106.            ->setFaviconPath("../themes/".strtolower($mainSettings->getAssetFolderName())."/admin/images/icon.png")
  107.             ->setTranslationDomain($nameSpaceTrans)
  108.             ->disableUrlSignatures()
  109.             
  110.             ->setLocales(
  111.                 
  112.                 [
  113.                     'en' => '🇬🇧 English',
  114.                     'fr' => '🇫🇷 Français',
  115.                     'ar' => '🇸🇦 Ø§Ù„عربية',
  116.                 ]
  117.                 )
  118.             
  119.             
  120.             ;
  121.             
  122.     }
  123.     
  124.     public function configureMenuItems(): iterable
  125.     {
  126.                 
  127.         
  128.         
  129.         
  130.        
  131.         
  132.         
  133.         
  134.         /* START : Les Extensions Flexy */ 
  135.         $applications $this->doctrine->getManager()->getRepository(Application::class)->findBy(["isEnabled"=>true],["menuOrder"=>"ASC"]);
  136.         $settings $this->doctrine->getManager()->getRepository(Settings::class)->findOneBy(["code"=>"main"]);
  137.         //$finder = new Finder();
  138.         $filesystem = new Filesystem();
  139.         //$finder->directories()->in(__DIR__."/../../Flexy")->depth('== 0');
  140.         
  141.         // For Principal Bundles (ShopBundle + FrontBundle + ...) 
  142.         foreach($applications as $singleApplication){
  143.             
  144.             
  145.             $bundleExist $filesystem->exists(__DIR__."/../../Flexy/".$singleApplication->getName()."/Flexy".$singleApplication->getName().".php");
  146.             
  147.             
  148.                if(!$bundleExist){
  149.                     continue;
  150.                }
  151.                
  152.             $bundleName =$singleApplication->getName(); 
  153.             
  154.              // Les themes systemes Flexy (FrontBundle Themes)
  155.             if($bundleName == "FrontBundle"){
  156.                 
  157.                 
  158.                 $bundleDashboardController 'App\Flexy\FrontBundle\Themes\\'.$settings->getFrontTheme().'\Controller\DashboardController';
  159.             }else{
  160.                 $bundleDashboardController 'App\Flexy\\'.$bundleName.'\Controller\DashboardController';
  161.             }
  162.             
  163.             
  164.             $dashboard = new $bundleDashboardController();
  165.             foreach($dashboard->configureMenuItems() as $menu){
  166.                 yield $menu;
  167.             }
  168.         }
  169.        // For Additional Apps Bundles (POSBundle + OtherBundle + ...)
  170.         foreach($applications as $singleApplication){
  171.             
  172.             if($singleApplication->getParentApplication()){
  173.                 continue;
  174.             }
  175.             $menuArray = [];
  176.             $bundleExist $filesystem->exists(__DIR__."/../../Flexy/Apps/".$singleApplication->getName()."/Flexy".$singleApplication->getName().".php");
  177.             
  178.             
  179.                if(!$bundleExist){
  180.                     continue;
  181.                }
  182.                
  183.             $bundleName =$singleApplication->getName(); 
  184.             
  185.             
  186.             $bundleDashboardController 'App\Flexy\Apps\\'.$bundleName.'\Controller\DashboardController';
  187.             
  188.             
  189.             
  190.             $dashboard = new $bundleDashboardController();
  191.             foreach($dashboard->configureMenuItems() as $menu){
  192.                 yield $menu;
  193.             }
  194.                 //SubApplications 
  195.                 foreach($singleApplication->getSubApplications() as $subApplication){
  196.                     $bundleExist $filesystem->exists(__DIR__."/../../Flexy/Apps/".$subApplication->getName()."/Flexy".$subApplication->getName().".php");
  197.             
  198.             
  199.                     if(!$bundleExist){
  200.                             continue;
  201.                     }
  202.                
  203.                     $bundleName =$subApplication->getName(); 
  204.                     
  205.                     
  206.                     $bundleDashboardController 'App\Flexy\Apps\\'.$bundleName.'\Controller\DashboardController';
  207.                     
  208.                     
  209.                     
  210.                     $dashboard = new $bundleDashboardController();
  211.                     foreach($dashboard->configureMenuItems() as $menu){
  212.                         yield $menu;
  213.                     }
  214.                 }
  215.             
  216.         }
  217.         /* END : Les Extensions Flexy */
  218.         yield MenuItem::section('Parametres');
  219.         
  220.         yield MenuItem::linkToRoute('Theme Designer''fas fa-shield-alt'"website_theme_grapesjs_edit")->setPermission("ROLE_ADMIN_DEV");
  221.         yield MenuItem::linkToRoute('Apps Store''fas fa-shield-alt'"app_store")->setPermission("ROLE_ADMIN_DEV");
  222.         yield MenuItem::linkToCrud('Utilisateurs''fas fa-shield-alt'User::class)->setController(UserCrudController::class);
  223.         yield MenuItem::linkToCrud('Passwords''fas fa-shield-alt'User::class)->setController(UserPasswordCrudController::class);
  224.         yield MenuItem::linkToCrud('Roles''fas fa-shield-alt'Role::class);
  225.         yield MenuItem::linkToCrud('LinkType''fas fa-gears'LinkType::class)->setPermission("ROLE_ADMIN_DEV");
  226.         yield MenuItem::linkToCrud('Link''fas fa-gears'Link::class)->setPermission("ROLE_ADMIN_DEV");
  227.         yield MenuItem::linkToCrud('Applications''fas fa-shield-alt'Application::class)->setPermission("ROLE_ADMIN_DEV");
  228.         yield MenuItem::linkToCrud('Notifications''fas fa-shield-alt'Notification::class)->setPermission("ROLE_ADMIN_DEV");
  229.         yield MenuItem::linkToRoute('Text to speech','fas fa-shield-alt',"open_ai_tts")->setPermission("ROLE_ADMIN_DEV");
  230.         yield MenuItem::linkToCrud('LogHistory''fas fa-shield-alt'LogHistory::class)->setPermission("ROLE_ADMIN_DEV");
  231.         yield MenuItem::linkToCrud('Settings''fas fa-shield-alt'Settings::class)
  232.         ->setAction("edit")
  233.         ->setEntityId($settings->getId())
  234.         ;
  235.         yield MenuItem::linkToCrud('Currency Exchange''fas fa-shield-alt'CurrencyExchangeRate::class);
  236.         yield MenuItem::linkToCrud('Web site theme''fas fa-shield-alt'WebsiteTheme::class)->setPermission("ROLE_ADMIN_DEV");
  237.         yield MenuItem::linkToCrud('Front Themes''fas fa-shield-alt'FrontTheme::class)->setPermission("ROLE_ADMIN_DEV");
  238.         yield MenuItem::linkToCrud('Export Excel''fas fa-shield-alt'ExportExcel::class)->setController(ExportExcelCrudController::class)->setPermission("ROLE_ADMIN_DEV");
  239.         
  240.     }
  241. }