src/Controller/BaseController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpKernel\KernelInterface;
  6. use Webkul\UVDesk\CoreFrameworkBundle\Entity\Website;
  7. use Webkul\UVDesk\CoreFrameworkBundle\Entity\SupportRole;
  8. use Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. class BaseController extends AbstractController
  11. {
  12.     /**
  13.      * Forward request to other controllers based on application state.
  14.      *
  15.      * @Route("/", name="base_route")
  16.      */
  17.     public function base(EntityManagerInterface $entityManagerKernelInterface $kernel)
  18.     {
  19.         try {
  20.             // For a quick check we'll just see if support roles have been defined.
  21.             $ownerSupportRole $entityManager->getRepository(SupportRole::class)->findOneByCode('ROLE_SUPER_ADMIN');
  22.             $administratorSupportRole $entityManager->getRepository(SupportRole::class)->findOneByCode('ROLE_ADMIN');
  23.             if (!empty($ownerSupportRole) || !empty($administratorSupportRole)) {
  24.                 $userInstanceRepository $entityManager->getRepository(UserInstance::class);
  25.                 
  26.                 // If support roles are present, we'll check if any users exists with the administrator role.
  27.                 $owners $userInstanceRepository->findBySupportRole($ownerSupportRole);
  28.                 $administrators $userInstanceRepository->findBySupportRole($administratorSupportRole);
  29.                 if (!empty($owners) || !empty($administrators)) {
  30.                     $availableBundles array_keys($kernel->getBundles());
  31.                     $websiteRepository $entityManager->getRepository(Website::class);
  32.                     // Redirect user to front panel
  33.                     if (in_array('UVDeskSupportCenterBundle'$availableBundles)) {
  34.                         $supportCenterWebsite $websiteRepository->findOneByCode('knowledgebase');
  35.                         if (!empty($supportCenterWebsite)) {
  36.                             return $this->redirectToRoute('helpdesk_knowledgebase', [], 301);
  37.                         }
  38.                     }
  39.                     // Redirect user to back panel
  40.                     $helpdeskWebsite $websiteRepository->findOneByCode('helpdesk');
  41.                     if (!empty($helpdeskWebsite)) {
  42.                         return $this->redirectToRoute('helpdesk_member_handle_login');
  43.                     }
  44.                 }
  45.             }
  46.         } catch (\Exception $e) {
  47.             // ...
  48.         }
  49.         
  50.         return $this->forward(ConfigureHelpdesk::class . "::load");
  51.     }
  52. }