<?php
namespace App\Controller;
use App\Service\SettingsService;
use App\Service\UtilService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use App\Functions\CMIMail;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
use Twig\Environment;
class DashboardController extends AbstractController
{
public $objSettingsService;
public $requestStack;
public $session;
public $mailer;
public $params;
public $em;
private $twig;
public function __construct(ContainerBagInterface $params, SessionInterface $session, RequestStack $requestStack, EntityManagerInterface $em, MailerInterface $mailer, SettingsService $objSettingsService, Environment $twig)
{
$this->objSettingsService = $objSettingsService;
$this->requestStack = $requestStack;
$this->session = $session;
$this->mailer = $mailer;
$this->params = $params;
$this->em = $em;
$this->twig = $twig;
}
/**
* @Route("/dashboard", name="dashboard")
*/
public function dashboard()
{
$intouchbizAdminUser = $_SESSION['intouchbiz_admin_user'] ?? '';
$this->session->set('intouchbiz_admin_user', $intouchbizAdminUser);
return $this->render('dashboard/index.html.twig', [
'em' => $this->em,
'controllerName' => 'DashboardController',
]);
}
/**
* @Route("/dashboard/sendmail", name="dashboard_sendmail")
*/
public function sendmail(Request $request)
{
$objMail = new CMIMail($request, $this->params, $this->objSettingsService);
$options['att'] = ['filename' => 'data/product/img1.jpg', 'name' => 'IMG1'];
$options['embeddedImage'] = ['filename' => 'data/product/drum.jpg', 'ref' => 'drum'];
dd($objMail->send('eduardomaruk@live.com', 'Título de envio de imagem de ação', 'Ta aí as iamgens <img src="cid:drum"> e depois nada', $options));
return $this->render('dashboard/index.html.twig', [
'controllerName' => 'DashboardController',
]);
}
/**
* @Route("/cookieConsent", name="backoffice_cookie_consent", methods={"POST"})
*/
public function cookieConsent(Request $request)
{
$email = $request->request->get('email');
$appVersionBackOffice = $this->objSettingsService->getEnvVars('APP_VERSION_BACKOFFICE');
$appVersionCookiePolicy = $this->objSettingsService->getSettingsVars('APP_VERSION_COOKIE_POLICY');
$backofficeUrl = $this->objSettingsService->getEnvVars('BACKOFFICE_URL');
$objUtilService = new UtilService($this->params, $this->requestStack);
$date = $objUtilService->getDate('now');
$content = 'Privacy Policy ID: ' . $appVersionBackOffice . ' | Agreed in ' . $date;
$objCookieConsentController = new CookieConsentController();
$objCookieConsentController->setConsent($this->em, $backofficeUrl, $email, $appVersionBackOffice, $appVersionCookiePolicy);
$cookie = new Cookie('cookie-consent-' . $appVersionCookiePolicy, $content, strtotime('now + 1 year'));
$response = new Response();
$response->headers->setCookie($cookie);
$response->setContent(json_encode([
'gtmHead' => $this->twig->render('base_gtm_head.html.twig')
]));
$response->headers->set('Content-Type', 'application/json');
$response->send();
exit();
}
/**
* @Route("/privacy-policy", name="backoffice_privacy_policy")
*/
public function privacyPolicy()
{
dd('privacy');
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
}
}