src/Controller/BaseController.php line 22

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