<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Doctrine\Persistence\ManagerRegistry;
use App\Service\AppService;
use App\Form\WhitelistType;
class DefaultController extends BaseController
{
private $_doctrine;
private $_appService;
public function __construct(
ManagerRegistry $doctrine,
AppService $appService)
{
$this->_doctrine = $doctrine;
$this->_appService = $appService;
}
public function index()
{
if ($this->_appService->isMobileApp())
$view = 'Default/mobileIndex.html.twig';
else
$view = 'Default/index.html.twig';
return $this->render($view);
}
public function whitelistPopupAjax(Request $request)
{
$form = $this->createForm(WhitelistType::class);
$form->handleRequest($request);
if ($form->isSubmitted())
{
if ($form->isValid())
{
$em = $this->_doctrine->getManager();
$em->persist($form->getData());
$em->flush();
$form = $this->createForm(WhitelistType::class);
$status = true;
}
return new JsonResponse(array(
'html' => $this->renderView('Default/partials/whitelistPopupForm.html.twig', array(
'form' => $form->createView(),
'status' => $status ?? false
))
));
}
return new JsonResponse(array(
'html' => $this->renderView('Default/whitelistPopup.html.twig', array(
'form' => $form->createView()
))
));
}
public function tokenAction()
{
return $this->render('Token/tokenPage.html.twig',[]);
}
}