src/Controller/IndexController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Document\Dsp;
  4. use Doctrine\ODM\MongoDB\DocumentManager;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class IndexController extends AbstractController
  10. {
  11. /**
  12. * @Route("/", name="app_index")
  13. */
  14. public function index(): Response
  15. {
  16. if ($this->getUser()->hasRole('ROLE_ADMIN')) {
  17. return $this->redirect('/publisher');
  18. }
  19. return $this->redirect('/inventory');
  20. }
  21. /**
  22. * @Route("/demand", name="app_demand")
  23. * @Route("/demand/{slug}", name="app_demand_slug")
  24. * @Route("/demand/{slug}/{slug2}", name="app_demand_slug_slug2")
  25. * @Route("/demand/{slug}/{slug2}/{slug3}", name="app_demand_slug_slug2_slug3")
  26. * @Route("/demand/{slug}/{slug2}/{slug3}/{slug4}", name="app_demand_slug_slug2_slug3_slug4")
  27. * @Route("/publisher", name="app_publisher")
  28. * @Route("/publisher/{slug}", name="app_publisher_slug")
  29. * @Route("/inventory", name="app_inventory")
  30. * @Route("/inventory/{slug}", name="app_inventory_slug")
  31. */
  32. public function settings(DocumentManager $dm): Response
  33. {
  34. $dsps = $dm->getRepository(Dsp::class)->findBy([]);
  35. $keys = [
  36. 'DBM-live3_cm-enabled' => 0,
  37. 'TTD' => 1,
  38. 'dspx' => 2,
  39. 'Adform_s1' => 3,
  40. 'AA' => 4,
  41. 'TTD-display' => 5,
  42. 'PubMatic' => 6,
  43. 'nexx360_stailamedia' => 7
  44. ];
  45. $names = [
  46. 'DBM-live3_cm-enabled' => 'DV360',
  47. 'TTD' => 'TTD',
  48. 'TTD-display' => 'TTD (display)',
  49. 'dspx' => 'dspX',
  50. 'Adform_s1' => 'AdForm',
  51. 'AA' => 'Active Agent',
  52. 'PubMatic' => 'PubMatic',
  53. 'nexx360_stailamedia' => 'stailamedia'
  54. ];
  55. $map = [];
  56. foreach ($dsps as $dsp) {
  57. if (isset($keys[$dsp->getGitId()])) {
  58. $map[$keys[$dsp->getGitId()]] = [
  59. 'name' => $names[$dsp->getGitId()],
  60. 'id' => $dsp->getId()
  61. ];
  62. }
  63. }
  64. return $this->render(
  65. 'index/settings.html.twig',
  66. [
  67. 'dsps' => array_values($map)
  68. ]
  69. );
  70. }
  71. /**
  72. * @Route("/dashboard", name="app_dashboard")
  73. */
  74. public function dashboard(): Response
  75. {
  76. return $this->render('index/dashboard.html.twig');
  77. }
  78. /**
  79. * @Route("/login", name="app_login")
  80. */
  81. public function login(): Response
  82. {
  83. // Main login page - only shows Google login
  84. return $this->render('index/login.html.twig');
  85. }
  86. /**
  87. * @Route("/login-local", name="app_login_local")
  88. */
  89. public function loginLocal(AuthenticationUtils $authenticationUtils): Response
  90. {
  91. // Legacy login page with email/password form
  92. // get the login error if there is one
  93. $error = $authenticationUtils->getLastAuthenticationError();
  94. // last username entered by the user
  95. $lastUsername = $authenticationUtils->getLastUsername();
  96. return $this->render('index/login-local.html.twig', [
  97. 'last_username' => $lastUsername,
  98. 'error' => $error,
  99. ]);
  100. }
  101. /**
  102. * @Route("/logout", name="app_logout")
  103. */
  104. public function logout(): void
  105. {
  106. // controller can be blank: it will never be called!
  107. throw new \Exception('Don\'t forget to activate logout in security.yaml');
  108. }
  109. }