src/Controller/BaseController.php line 20

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 $entityManager, KernelInterface $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. // If support roles are present, we'll check if any users exists with the administrator role.
  26. $owners = $userInstanceRepository->findBySupportRole($ownerSupportRole);
  27. $administrators = $userInstanceRepository->findBySupportRole($administratorSupportRole);
  28. if (!empty($owners) || !empty($administrators)) {
  29. $availableBundles = array_keys($kernel->getBundles());
  30. $websiteRepository = $entityManager->getRepository(Website::class);
  31. // Redirect user to front panel
  32. if (in_array('UVDeskSupportCenterBundle', $availableBundles)) {
  33. $supportCenterWebsite = $websiteRepository->findOneByCode('knowledgebase');
  34. if (!empty($supportCenterWebsite)) {
  35. return $this->redirectToRoute('helpdesk_knowledgebase', [], 301);
  36. }
  37. }
  38. // Redirect user to back panel
  39. $helpdeskWebsite = $websiteRepository->findOneByCode('helpdesk');
  40. if (!empty($helpdeskWebsite)) {
  41. return $this->redirectToRoute('helpdesk_member_handle_login');
  42. }
  43. }
  44. }
  45. } catch (\Exception $e) {
  46. // ...
  47. }
  48. return $this->forward(ConfigureHelpdesk::class . "::load");
  49. }
  50. }