src/Controller/Admin/DashboardController.php line 119
<?php
namespace App\Controller\Admin;
use App\Entity\Application;
use App\Entity\CurrencyExchangeRate;
use App\Entity\ExportExcel;
use App\Entity\FrontTheme;
use App\Entity\Link;
use App\Entity\LinkType;
use App\Entity\LogHistory;
use App\Entity\Notification;
use App\Entity\Role;
use App\Entity\Settings;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\User;
use App\Entity\WebsiteTheme;
use App\Flexy\ShopBundle\Entity\Product\Product;
use App\Flexy\ShopBundle\Entity\Store\Store;
use App\Flexy\ShopBundle\Entity\Vendor\Vendor;
use App\Flexy\ShopBundle\Service\FlexyShopStatisticProvider;
use App\Repository\ApplicationRepository;
use App\Service\FlexySettingsProvider;
use Doctrine\Persistence\ManagerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;
use Symfony\Component\HttpFoundation\Request;
class DashboardController extends AbstractDashboardController
{
public function __construct(
private readonly ManagerRegistry $doctrine,
private readonly FlexyShopStatisticProvider $flexyShopStatisticProvider
)
{
}
#[Route(path: '/admin', name: 'admin_non_locale')]
public function indexNonLocale(Request $request): Response
{
return $this->redirectToRoute("admin",["_locale"=>$request->getLocale()]);
}
#[Route('/{_locale}/admin/website-theme/grapesjs_edit', name: 'website_theme_grapesjs_edit')]
public function website_theme_grapesjs_edit(): Response
{
return $this->render('@Flexy/FrontBundle/Themes/'.$this->container->get('twig')->getGlobals()["settings"]->get()->getAssetFolderName().'/templates/admin/website-theme/grapesjs.html.twig');
}
#[Route(path: '/{_locale}/admin/apps-store', name: 'app_store')]
public function appStore(Request $request,ApplicationRepository $applicationRepository,FlexySettingsProvider $flexySettingsProvider): Response
{
$appsArray = [];
foreach($applicationRepository->findAll() as $singleApp){
$appsArray[] = [
"id"=>$singleApp->getId(),
"name"=>$singleApp->getName(),
"image"=>$singleApp->getImage(),
"price"=>$singleApp->getPrice(),
"pageUrl"=>$singleApp->getPageUrl(),
];
}
return $this->render("admin/app-store.html.twig",[
"installedApps"=>$appsArray,
"JWT"=>$flexySettingsProvider->createJWTForUser($this->getUser())
]);
}
#[Route(path: '/{_locale}/admin', name: 'admin')]
public function index(): Response
{
return $this->render("bundles/EasyAdminBundle/welcome.html.twig");
}
public function configureCrud(): Crud
{
return
Crud::new()
->setDefaultSort(["id"=> 'DESC'])
->setPaginatorPageSize(12)
;
}
public function configureDashboard(): Dashboard
{
$mainSettings = $this->doctrine->getManager()->getRepository(Settings::class)->findOneBy(["code"=>"main"]);
$nameSpaceTrans = strtolower($mainSettings->getProjectName())."-admin";
$urlImage = "../themes/".strtolower($mainSettings->getAssetFolderName())."/admin/images/logo.png";
return Dashboard::new()
->setTitle('<img title="Dashboard" src="'.$urlImage.'" />
')
//->renderContentMaximized()
->setFaviconPath("../themes/".strtolower($mainSettings->getAssetFolderName())."/admin/images/icon.png")
->setTranslationDomain($nameSpaceTrans)
->disableUrlSignatures()
->setLocales(
[
'en' => '🇬🇧 English',
'fr' => '🇫🇷 Français',
'ar' => '🇸🇦 العربية',
]
)
;
}
public function configureMenuItems(): iterable
{
/* START : Les Extensions Flexy */
$applications = $this->doctrine->getManager()->getRepository(Application::class)->findBy(["isEnabled"=>true],["menuOrder"=>"ASC"]);
$settings = $this->doctrine->getManager()->getRepository(Settings::class)->findOneBy(["code"=>"main"]);
//$finder = new Finder();
$filesystem = new Filesystem();
//$finder->directories()->in(__DIR__."/../../Flexy")->depth('== 0');
// For Principal Bundles (ShopBundle + FrontBundle + ...)
foreach($applications as $singleApplication){
$bundleExist = $filesystem->exists(__DIR__."/../../Flexy/".$singleApplication->getName()."/Flexy".$singleApplication->getName().".php");
if(!$bundleExist){
continue;
}
$bundleName =$singleApplication->getName();
// Les themes systemes Flexy (FrontBundle Themes)
if($bundleName == "FrontBundle"){
$bundleDashboardController = 'App\Flexy\FrontBundle\Themes\\'.$settings->getFrontTheme().'\Controller\DashboardController';
}else{
$bundleDashboardController = 'App\Flexy\\'.$bundleName.'\Controller\DashboardController';
}
$dashboard = new $bundleDashboardController();
foreach($dashboard->configureMenuItems() as $menu){
yield $menu;
}
}
// For Additional Apps Bundles (POSBundle + OtherBundle + ...)
foreach($applications as $singleApplication){
if($singleApplication->getParentApplication()){
continue;
}
$menuArray = [];
$bundleExist = $filesystem->exists(__DIR__."/../../Flexy/Apps/".$singleApplication->getName()."/Flexy".$singleApplication->getName().".php");
if(!$bundleExist){
continue;
}
$bundleName =$singleApplication->getName();
$bundleDashboardController = 'App\Flexy\Apps\\'.$bundleName.'\Controller\DashboardController';
$dashboard = new $bundleDashboardController();
foreach($dashboard->configureMenuItems() as $menu){
yield $menu;
}
//SubApplications
foreach($singleApplication->getSubApplications() as $subApplication){
$bundleExist = $filesystem->exists(__DIR__."/../../Flexy/Apps/".$subApplication->getName()."/Flexy".$subApplication->getName().".php");
if(!$bundleExist){
continue;
}
$bundleName =$subApplication->getName();
$bundleDashboardController = 'App\Flexy\Apps\\'.$bundleName.'\Controller\DashboardController';
$dashboard = new $bundleDashboardController();
foreach($dashboard->configureMenuItems() as $menu){
yield $menu;
}
}
}
/* END : Les Extensions Flexy */
yield MenuItem::section('Parametres');
yield MenuItem::linkToRoute('Theme Designer', 'fas fa-shield-alt', "website_theme_grapesjs_edit")->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToRoute('Apps Store', 'fas fa-shield-alt', "app_store")->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToCrud('Utilisateurs', 'fas fa-shield-alt', User::class)->setController(UserCrudController::class);
yield MenuItem::linkToCrud('Passwords', 'fas fa-shield-alt', User::class)->setController(UserPasswordCrudController::class);
yield MenuItem::linkToCrud('Roles', 'fas fa-shield-alt', Role::class);
yield MenuItem::linkToCrud('LinkType', 'fas fa-gears', LinkType::class)->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToCrud('Link', 'fas fa-gears', Link::class)->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToCrud('Applications', 'fas fa-shield-alt', Application::class)->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToCrud('Notifications', 'fas fa-shield-alt', Notification::class)->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToRoute('Text to speech','fas fa-shield-alt',"open_ai_tts")->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToCrud('LogHistory', 'fas fa-shield-alt', LogHistory::class)->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToCrud('Settings', 'fas fa-shield-alt', Settings::class)
->setAction("edit")
->setEntityId($settings->getId())
;
yield MenuItem::linkToCrud('Currency Exchange', 'fas fa-shield-alt', CurrencyExchangeRate::class);
yield MenuItem::linkToCrud('Web site theme', 'fas fa-shield-alt', WebsiteTheme::class)->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToCrud('Front Themes', 'fas fa-shield-alt', FrontTheme::class)->setPermission("ROLE_ADMIN_DEV");
yield MenuItem::linkToCrud('Export Excel', 'fas fa-shield-alt', ExportExcel::class)->setController(ExportExcelCrudController::class)->setPermission("ROLE_ADMIN_DEV");
}
}