src/Controller/DefaultController.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Main\Tenant;
  4. use App\Entity\Tenant\Agence;
  5. use App\Entity\Tenant\Banque;
  6. use App\Repository\Main\TenantRepository;
  7. use App\Repository\Tenant\UserRepository;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use App\Services\TenantManager;
  12. /**
  13.  * @Route("/")
  14.  */
  15. class DefaultController extends AbstractController
  16. {
  17.     private TenantManager $tenantManager;
  18.     public function __constructTenantManager $tenantManager)
  19.     {
  20.         $this->tenantManager $tenantManager;
  21.     }
  22.     /**
  23.      * @Route("/tenant")
  24.      *
  25.      */
  26.     public function indexUserRepository $userRepository ) {
  27.  
  28.         $this->isGrantedUser('ROLE_ADMIN');
  29.         $tenant $this->tenantManager->getCurrentTenant();
  30.         if (!$this->getUser()) {
  31.             return $this->redirectToRoute('login');
  32.         }
  33.         return $this->render('default/index.html.twig', [
  34.             'users' => $userRepository->findAll(),
  35.             'tenant' => $tenant
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/", name="defaut_index")
  40.      */
  41.     public function globalIndex(
  42.         Request $request,
  43.         TenantRepository $tenantRepository
  44.     ) {
  45.         $server $request->server->get('HTTP_HOST');
  46.         $item explode("."$server);
  47.         $subDomain $item[0];
  48.         if (!$subDomain) {
  49.             throw $this->createNotFoundException('The subdomain parameters is required in the URL');
  50.         }
  51.         /* @var $tenant Tenant */
  52.         $tenant $tenantRepository->findOneBy([
  53.             'subDomain' => $subDomain
  54.         ]);
  55.         if (!$tenant instanceof Tenant) {
  56.             return $this->render('admin/default/app_index.html.twig', [
  57.             ]);
  58.             //  throw $this->createNotFoundException('The tenant for this ID not found');
  59.         }
  60.         /* @var $connection TenantConnection */
  61.         $connection $this->getDoctrine()->getConnection('tenant');
  62.         $connection->changeParams($tenant->getDbName(), $tenant->getDbUser(), $tenant->getDbPassword());
  63.         $connection->reconnect();
  64.         return $this->render('default/tenant_index.html.twig', [
  65.             'tenant' => $tenant
  66.         ]);
  67.     }
  68.     /**
  69.      * @Route("/get/agences", name="get_agences")
  70.      */
  71.     public function getAgences(){
  72.         $em $this->getDoctrine()->getManager('tenant');
  73.         return $this->render('default/get_agences.html.twig', [
  74.             'agences' => $em->getRepository(Agence::class)->findBy(['archived' => false])
  75.         ]);
  76.     }
  77.     /**
  78.      * @Route("/get/banks/{selectedBank}", name="get_banks")
  79.      */
  80.     public function getBanks$selectedBank ){
  81.         $em $this->getDoctrine()->getManager('tenant');
  82.         return $this->render('default/get_banks.html.twig', [
  83.             'banks' => $em->getRepository(Banque::class)->findAll(),
  84.             'selectedBank' => $selectedBank $selectedBank->getId() : null,
  85.         ]);
  86.     }
  87. }