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 (
  24. ! empty($ownerSupportRole)
  25. || ! empty($administratorSupportRole)
  26. ) {
  27. $userInstanceRepository = $entityManager->getRepository(UserInstance::class);
  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 (
  32. ! empty($owners)
  33. || ! empty($administrators)
  34. ) {
  35. $availableBundles = array_keys($kernel->getBundles());
  36. $websiteRepository = $entityManager->getRepository(Website::class);
  37. // Redirect user to front panel
  38. if (in_array('UVDeskSupportCenterBundle', $availableBundles)) {
  39. $supportCenterWebsite = $websiteRepository->findOneByCode('knowledgebase');
  40. if (! empty($supportCenterWebsite)) {
  41. return $this->redirectToRoute('helpdesk_knowledgebase', [], 301);
  42. }
  43. }
  44. // Redirect user to back panel
  45. $helpdeskWebsite = $websiteRepository->findOneByCode('helpdesk');
  46. if (! empty($helpdeskWebsite)) {
  47. return $this->redirectToRoute('helpdesk_member_handle_login');
  48. }
  49. }
  50. }
  51. } catch (\Exception $e) {
  52. // ...
  53. }
  54. return $this->forward(ConfigureHelpdesk::class . "::load");
  55. }
  56. }