src/Twig/FrontendPartialsRenderer.php line 108

Open in your IDE?
  1. <?php
  2. namespace App\Twig;
  3. use App\Entity\Gos\PortalSettings;
  4. use App\Utils\FrontendSCSSGenerator;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Twig\Extension\AbstractExtension;
  8. use Twig\TwigFunction;
  9. class FrontendPartialsRenderer extends AbstractExtension
  10. {
  11.     private $em;
  12.     private $request;
  13.     private $SCSSGenerator;
  14.     /** @var PortalSettings|null */
  15.     private $portalSettings;
  16.     public function __construct(EntityManagerInterface $_em,
  17.                                 RequestStack $requestStack,
  18.                                 FrontendSCSSGenerator $_SCSSGenerator)
  19.     {
  20.         $this->em $_em;
  21.         $this->request $requestStack->getCurrentRequest();
  22.         $this->SCSSGenerator $_SCSSGenerator;
  23.     }
  24.     public function getFunctions(): array
  25.     {
  26.         return array(
  27.             new TwigFunction('getFrontendSCSS', [$this'getFrontendSCSS']),
  28.             new TwigFunction('getPortalCSS', [$this'getPortalCSS']),
  29.             new TwigFunction('getStyleForNewsletter', [$this'getStyleForNewsletter']),
  30.             new TwigFunction('getPasswordAdditionalContent', [$this'getPasswordAdditionalContent']),
  31.         );
  32.     }
  33.     public function getFrontendSCSS(): string
  34.     {
  35.         $this->getPortalSettings();
  36.         return $this->SCSSGenerator->getPortalSCSS($this->portalSettings);
  37.     }
  38.     public function getPortalCSS(): string
  39.     {
  40.         $this->getPortalSettings();
  41.         if ($this->portalSettings)
  42.         {
  43.             return $this->portalSettings->getPortalCss() ?: '';
  44.         }
  45.         return '';
  46.     }
  47.     public function getStyleForNewsletter(): string
  48.     {
  49.         $this->getPortalSettingsFromCookies();
  50.         if ($this->portalSettings)
  51.         {
  52.             $leadingColor $this->portalSettings->getLeadingColor4();
  53.             if(!empty($leadingColor))
  54.             {
  55.                 return "        
  56.                     .newsletter .newsletter__button {
  57.                         background-color: {$leadingColor} !important;
  58.                     }
  59.                     .newsletter_title > span { color: {$leadingColor} !important; }
  60.             
  61.                     .otp-container .btn { background-color: {$leadingColor}; }
  62.                     .otp-password__save__btn {background: {$leadingColor} !important; border-color: {$leadingColor} !important;}
  63.                     .otp-container a, .newsletter__message-text, .otp-message--success, .otp-message--phone-success, .otp-message--mail-success { color:  {$leadingColor}; }
  64.                     .otp-password .btn-primary:not(:disabled):not(.disabled).active, .otp-container .btn-primary:not(:disabled):not(.disabled):active { background-color: {$leadingColor}; border-color: {$leadingColor};}
  65.                     .login-content-submit { background-color: {$leadingColor}; }
  66.                     .login-content-register > a, .login-show-password, .login-content-forgot-password > span a { color: {$leadingColor}; }
  67.                     .newsletter__message-text { color: {$leadingColor}; }
  68.                 ";
  69.             }
  70.         }
  71.         return '';
  72.     }
  73.     public function getPasswordAdditionalContent(): ?string
  74.     {
  75.         $this->getPortalSettingsFromCookies();
  76.         if($this->portalSettings)
  77.         {
  78.             $additionalContent $this->portalSettings->getPasswordAdditionalContent();
  79.             if($additionalContent) {
  80.                 return $this->portalSettings->getPasswordAdditionalContent();
  81.             }
  82.         }
  83. //        return '<img src="/frontend/img/otp-korzysci.png" style="width: 100%;">';
  84.         return null;
  85.     }
  86.     private function getPortalSettingsFromCookies(): void
  87.     {
  88.         $portalSettingHash $this->request->getSession()->has('portalSettingsHash')
  89.             ? $this->request->getSession()->get('portalSettingsHash')
  90.             : $this->request->cookies->get('gos_portal_settings'null);
  91.         if ($portalSettingHash !== null)
  92.         {
  93.             $this->portalSettings $this->em->getRepository(PortalSettings::class)->findOneByHash($portalSettingHash);
  94.         }
  95.     }
  96.     private function getPortalSettings(): void
  97.     {
  98.         if ($this->portalSettings === null && $this->request)
  99.         {
  100.             $this->portalSettings $this->em->getRepository(PortalSettings::class)
  101.                 ->findOneByHash($this->request->getSession()->get('portalSettingsHash'));
  102.         }
  103.     }
  104. }