src/Twig/CompanySettingsExtension.php line 68

Open in your IDE?
  1. <?php
  2. namespace App\Twig;
  3. use App\Entity\Gos\Language;
  4. use App\Entity\Gos\PortalSettings;
  5. use App\Entity\Gos\Uniqskills\Cooperator;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. use Twig\Extension\AbstractExtension;
  10. use Twig\TwigFunction;
  11. class CompanySettingsExtension extends AbstractExtension
  12. {
  13.     private EntityManagerInterface $em;
  14.     private ?Request $request;
  15.     public function __construct(EntityManagerInterface $emRequestStack $requestStack)
  16.     {
  17.         $this->em       $em;
  18.         $this->request  $requestStack->getCurrentRequest();
  19.     }
  20.     public function getFunctions(): array
  21.     {
  22.         return [
  23.             new TwigFunction('getFmCompanySettings', [$this'getFmCompanySettings']),
  24.             new TwigFunction('getFooterCooperators', [$this'getFooterCooperators']),
  25.             new TwigFunction('getFooterCooperatorsHeader', [$this'getFooterCooperatorsHeader'])
  26.         ];
  27.     }
  28.     public function getFmCompanySettings()
  29.     {
  30.         $domain $this->request->getSession()->get('domain');
  31.         $portalSettings $this->em->getRepository(PortalSettings::class)->find($domain);
  32.         return $portalSettings->getFmCompanySettings();
  33.     }
  34.     public function getFooterCooperators(): array
  35.     {
  36.         /** @var Language $currentLanguage */
  37.         $currentLanguage $this->em->getRepository(Language::class)->findOneBy(['code' => $this->request->getLocale()]);
  38.         $cooperators $this->em->getRepository(Cooperator::class)->findBy(['visibleInFooter' => true'notForUniqskills' => false]);
  39.         $newCooperators = [];
  40.         foreach ($cooperators as $cooperator)
  41.         {
  42.             foreach ($cooperator->getLanguages() as $language)
  43.             {
  44.                 if($currentLanguage && $language)
  45.                 {
  46.                     if ($language->getId() == $currentLanguage->getId())
  47.                     {
  48.                         $newCooperators[] = $cooperator;
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.         return $newCooperators;
  54.     }
  55.     public function getFooterCooperatorsHeader()
  56.     {
  57.         $domain $this->request->getSession()->get('domain');
  58.         if (!$domain) return false;
  59.         $portalSettings $this->em->getRepository(PortalSettings::class)->find($domain);
  60.         $companySettings $portalSettings->getFmCompanySettings();
  61.         $rows $companySettings->getTextFooterCooperatorHeaders();
  62.         if (isset($rows[$this->request->getLocale()]))
  63.         {
  64.             return $rows[$this->request->getLocale()];
  65.         }
  66.         return false;
  67.     }
  68. }