<?php
namespace App\Controller;
use App\Document\Dsp;
use Doctrine\ODM\MongoDB\DocumentManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class IndexController extends AbstractController
{
/**
* @Route("/", name="app_index")
*/
public function index(): Response
{
if ($this->getUser()->hasRole('ROLE_ADMIN')) {
return $this->redirect('/publisher');
}
return $this->redirect('/inventory');
}
/**
* @Route("/demand", name="app_demand")
* @Route("/demand/{slug}", name="app_demand_slug")
* @Route("/demand/{slug}/{slug2}", name="app_demand_slug_slug2")
* @Route("/demand/{slug}/{slug2}/{slug3}", name="app_demand_slug_slug2_slug3")
* @Route("/demand/{slug}/{slug2}/{slug3}/{slug4}", name="app_demand_slug_slug2_slug3_slug4")
* @Route("/publisher", name="app_publisher")
* @Route("/publisher/{slug}", name="app_publisher_slug")
* @Route("/inventory", name="app_inventory")
* @Route("/inventory/{slug}", name="app_inventory_slug")
*/
public function settings(DocumentManager $dm): Response
{
$dsps = $dm->getRepository(Dsp::class)->findBy([]);
$keys = [
'DBM-live3_cm-enabled' => 0,
'TTD' => 1,
'dspx' => 2,
'Adform_s1' => 3,
'AA' => 4,
'TTD-display' => 5,
'PubMatic' => 6,
'nexx360_stailamedia' => 7
];
$names = [
'DBM-live3_cm-enabled' => 'DV360',
'TTD' => 'TTD',
'TTD-display' => 'TTD (display)',
'dspx' => 'dspX',
'Adform_s1' => 'AdForm',
'AA' => 'Active Agent',
'PubMatic' => 'PubMatic',
'nexx360_stailamedia' => 'stailamedia'
];
$map = [];
foreach ($dsps as $dsp) {
if (isset($keys[$dsp->getGitId()])) {
$map[$keys[$dsp->getGitId()]] = [
'name' => $names[$dsp->getGitId()],
'id' => $dsp->getId()
];
}
}
return $this->render(
'index/settings.html.twig',
[
'dsps' => array_values($map)
]
);
}
/**
* @Route("/dashboard", name="app_dashboard")
*/
public function dashboard(): Response
{
return $this->render('index/dashboard.html.twig');
}
/**
* @Route("/login", name="app_login")
*/
public function login(): Response
{
// Main login page - only shows Google login
return $this->render('index/login.html.twig');
}
/**
* @Route("/login-local", name="app_login_local")
*/
public function loginLocal(AuthenticationUtils $authenticationUtils): Response
{
// Legacy login page with email/password form
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('index/login-local.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout(): void
{
// controller can be blank: it will never be called!
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
}