src/Twig/VariablesExtension.php line 68

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Twig;
  3. use Twig\Extension\AbstractExtension;
  4. use Twig\Extension\GlobalsInterface;
  5. use Twig\TwigFunction;
  6. use EADPlataforma\Services\GeneralService;
  7. use EADPlataforma\Entity\ProductOffer;
  8. use EADPlataforma\Entity\Category;
  9. use EADPlataforma\Entity\Page;
  10. use EADPlataforma\Entity\Notification;
  11. use EADPlataforma\Entity\Enrollment;
  12. use EADPlataforma\Entity\CourseCertificate;
  13. use EADPlataforma\Entity\Configuration;
  14. use EADPlataforma\Entity\User;
  15. use EADPlataforma\Enum\AbstractEnum;
  16. use EADPlataforma\Enum\Eadmin\ClientEnum;
  17. use EADPlataforma\Enum\ClientEnum AS CliEnum;
  18. use EADPlataforma\Enum\NotificationEnum;
  19. use EADPlataforma\Enum\PageEnum;
  20. use EADPlataforma\Enum\ProductEnum;
  21. use EADPlataforma\Enum\EnrollmentEnum;
  22. class VariablesExtension extends AbstractExtension implements GlobalsInterface
  23. {
  24.     /**
  25.      * @var GeneralService
  26.      */
  27.     private $generalService;
  28.     /**
  29.      * @var SchoolEntityManager
  30.      */
  31.     private $em;
  32.     /**
  33.      * @var SchoolEntityManager
  34.      */
  35.     private $emEadmin;
  36.     /**
  37.      * @var string
  38.      */
  39.     private $cdn;
  40.     /**
  41.      * @var SchoolEntityManager
  42.      */
  43.     private $userSessionService;
  44.     /**
  45.      * @var SchoolEntityManager
  46.      */
  47.     private $configuration;
  48.     /**
  49.      * @var SchoolEntityManager
  50.      */
  51.     private $userPermissionUtil;
  52.     /**
  53.      * Constructor
  54.      *
  55.      * @param GeneralService $generalService
  56.      */
  57.     public function __construct(GeneralService $generalService)
  58.     {
  59.         $this->generalService $generalService;
  60.         $this->em $this->generalService->getService('SchoolEntityManager');
  61.         $this->userSessionService $this->generalService->getService('UserSessionService');
  62.         $this->configuration $this->generalService->getService('ConfigurationService');
  63.         
  64.         $container $this->generalService->getContainer();
  65.         $this->cdn "{$container->getParameter('ead-cdn')}assets/";
  66.     }
  67.     public function getUserPermissionUtil()
  68.     {
  69.         if(!$this->userPermissionUtil){
  70.             $this->userPermissionUtil $this->generalService->getUtil('UserPermissionUtil');
  71.         }
  72.         return $this->userPermissionUtil;
  73.     }
  74.     
  75.     public function getGlobals(): array
  76.     {   
  77.         $user $this->userSessionService->getUser();
  78.         $session $this->userSessionService->getSession();
  79.         $client $this->configuration->getClient();
  80.         $domain $this->configuration->getActiveDomain(true);
  81.         
  82.         $poRepository $this->em->getRepository(ProductOffer::class);
  83.         $categoryRepository $this->em->getRepository(Category::class);
  84.         $notificationRepository $this->em->getRepository(Notification::class);
  85.         $pageRepository $this->em->getRepository(Page::class);
  86.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  87.         $certificateRepository $this->em->getRepository(CourseCertificate::class);
  88.         $configurationRepository $this->em->getRepository(Configuration::class);
  89.         $userRepository $this->em->getRepository(User::class);
  90.         $countEnrollment null;
  91.         $countCertificate null;
  92.         $countWish null;
  93.         $whatsapp preg_replace("/[^0-9]/"""$this->configuration->get("whatsapp"));
  94.         $categories $categoryRepository->getCategories();
  95.         $userTeacherSpotlight $userRepository->getUserTeacherSpotlight();
  96.         $pages = [];
  97.         $pagesNavbar count($pages);
  98.         $pagesFooter count($pages);
  99.         if($this->configuration->isModuleActive('pages_module')){
  100.             $pages $pageRepository->findBy(
  101.                 [
  102.                     "deleted" => PageEnum::ITEM_NO_DELETED,
  103.                     "status" => PageEnum::PUBLISHED
  104.                 ], 
  105.                 [ "order" => "ASC"]
  106.             );
  107.             $pagesNavbar $pageRepository->count([ 
  108.                 "deleted" => PageEnum::ITEM_NO_DELETED,
  109.                 "status" => PageEnum::PUBLISHED,
  110.                 "showType" => PageEnum::NAVBAR
  111.             ]);
  112.             $pagesFooter $pageRepository->count([ 
  113.                 "deleted" => PageEnum::ITEM_NO_DELETED,
  114.                 "status" => PageEnum::PUBLISHED,
  115.                 "showType" => PageEnum::FOOTER
  116.             ]);
  117.         }
  118.         $platformType $client->getPlatformType();
  119.         $isRestricted = ($platformType == CliEnum::PLATFORM_TYPE_RESTRICTED);
  120.         $isRestrictedUser = (($isRestricted && $user) || !$isRestricted);
  121.         $eadDomain null;
  122.         if($client){
  123.             $eadDomain $client->getDomainPrimary();
  124.         }
  125.         $menuResume = (object)[
  126.             "text" => $this->configuration->getLanguage('resume''head'),
  127.             "link" => $this->generalService->generateUrl('resume'),
  128.             "show" => ( $user && $isRestrictedUser ),
  129.             "class" => "resume"
  130.         ];
  131.         $menuPages = (object)[
  132.             "text" => $this->configuration->getLanguage('pages''head'),
  133.             "dropdown" => true,
  134.             "show" => (!empty($pagesNavbar) && $isRestrictedUser),
  135.             "class" => "pages"
  136.         ];
  137.         $infoOffer $poRepository->getPublicStoreInfo();
  138.         $offerNumber $infoOffer->offerNumber;
  139.         $offerSubNumber $infoOffer->offerSubNumber;
  140.         $offerComboNumber $infoOffer->offerComboNumber;
  141.         $subModule $infoOffer->subModule;
  142.         $hasProducts $infoOffer->hasProducts;
  143.         //check sell course
  144.         $showCourses false;
  145.         $showPlans false;
  146.         $showCombos false;
  147.         $showForuns false;
  148.         if($isRestricted){
  149.             $showCourses = ($user && $offerNumber 0);
  150.             $showPlans = ($user && ($offerSubNumber && $subModule));
  151.             $showCombos = ($user && $offerComboNumber 0);
  152.             $showForuns = (
  153.                 $user && $this->configuration->showForum(( $user true false ))
  154.             );
  155.         }else{
  156.             $showCourses = ($offerNumber 0);
  157.             $showPlans = ($offerSubNumber && $subModule);
  158.             $showCombos = ($offerComboNumber 0);
  159.             $showForuns $this->configuration->showForum(( $user true false ));
  160.         }
  161.         $menuCourse = (object)[
  162.             "text" => $this->configuration->getLanguage('courses''head'),
  163.             "link" => $this->generalService->generateUrl(
  164.                 'productListCourses'
  165.                 [ "type" => "courses" ]
  166.             ),
  167.             "show" => $showCourses && $isRestrictedUser,
  168.             "class" => "courses"
  169.         ];
  170.         $menuPlan = (object)[
  171.             "text" => $this->configuration->getLanguage('plans''head'),
  172.             "link" => $this->generalService->generateUrl(
  173.                 'productListPlans',
  174.                 [ "type" => "plans" ]
  175.             ),
  176.             "show" => $showPlans && $isRestrictedUser,
  177.             "class" => "plans"
  178.         ];
  179.         $menuCombo = (object)[
  180.             "text" => $this->configuration->getLanguage('combos''head'),
  181.             "link" => $this->generalService->generateUrl('productListCombos'),
  182.             "show" => $showCombos && $isRestrictedUser,
  183.             "class" => "combos"
  184.         ];
  185.     
  186.         $menuForum = (object)[
  187.             "text" => $this->configuration->getLanguage('forum''head'),
  188.             "link" => $this->generalService->generateUrl('forum'),
  189.             "show" => $showForuns && $isRestrictedUser,
  190.             "class" => "forum"
  191.         ];
  192.         // MENU MOBILE
  193.         $menuMobilePages = (object)[
  194.             "text" => $this->configuration->getLanguage('pages''head'),
  195.             "link"  => 'pages',
  196.             "slide" => true,
  197.             "show" => (!empty($pagesNavbar) && $isRestrictedUser),
  198.             "class" => "pages"
  199.         ];
  200.         $menuMobileCategorias = (object)[
  201.             "text"  => $this->configuration->getLanguage('categories''head'),
  202.             "link"  => 'categorias',
  203.             "slide" => true,
  204.             "show"  => (!empty($categories) && $isRestrictedUser),
  205.             "class" => "categories"
  206.         ];
  207.         $menuMobileNotificacoes = (object)[
  208.             "text"  => $this->configuration->getLanguage('notifications''head'),
  209.             "link"  => 'notificacoes',
  210.             "slide" => true,
  211.             "show"  => ( $user && $isRestrictedUser ),
  212.         ];
  213.         $notificationNumber 0;
  214.         if($user){
  215.             $notificationNumber $notificationRepository->count([ 
  216.                 "userTo" => $user->getId(), 
  217.                 "status" => NotificationEnum::NOT_VIEWED,
  218.             ]);
  219.             $countEnrollment $enrollmentRepository->countResumeEnrollment(
  220.                 $user->getId(), 
  221.                 [], 
  222.                 null
  223.             );
  224.     
  225.             $countCertificate $certificateRepository->getCountResumeCourseCertificate(
  226.                 $user->getId()
  227.             );
  228.             $countWish $poRepository->getCountResumeWhishList($user->getId());
  229.     
  230.         }
  231.         $countSocial $configurationRepository->countSocial();
  232.         $request $this->generalService->getRequest();
  233.         $isAppDomain = (strpos($request->getHost(), ".eadplataforma.app") !== false);
  234.         $actualDomain = ($request $request->getHost() : $domain);
  235.         $userId $user $user->getId() : null;
  236.         $upPath AbstractEnum::PATH_UPLOAD;
  237.         $othersPath AbstractEnum::PATH_OTHERS;
  238.         $clientConfig $this->configuration->getClientConfiguration();
  239.         $clientVersion $clientConfig->getClientVersion();
  240.         $activeMetrics $clientConfig->getActiveMetrics();
  241.         $favicon $this->configuration->get('favicon');
  242.         $favicon = (
  243.             !empty($favicon) ? "//{$actualDomain}{$upPath}{$othersPath}/{$favicon}null
  244.         );
  245.         
  246.         $globalConfig $this->configuration->getGlobalConfiguration();
  247.         $platformType $client->getPlatformType();
  248.         $isRestricted = ($platformType == CliEnum::PLATFORM_TYPE_RESTRICTED);
  249.         $clientPathVersion ClientEnum::CLIENT_VERSION_PATH[$clientVersion];
  250.         $assetsVersion $globalConfig->getAssetsVersion();
  251.         $paymentConfig $this->configuration->getPaymentConfig();
  252.         $userToken null;
  253.         if($session){
  254.             $userToken md5($clientConfig->getId()) . md5(
  255.                 $session->getId() . $session->getToken()
  256.             );
  257.         }
  258.         return [
  259.             "activeMetrics" => $activeMetrics,
  260.             "menu" => [
  261.                 $menuResume,
  262.                 $menuPages,
  263.                 $menuCourse,
  264.                 $menuPlan,
  265.                 $menuCombo,
  266.                 $menuForum,
  267.             ],
  268.             "menuMobile" => [
  269.                 $menuResume,
  270.                 $menuMobilePages,
  271.                 $menuMobileCategorias,
  272.                 $menuCourse,
  273.                 $menuPlan,
  274.                 $menuCombo,
  275.                 $menuForum,
  276.             ],
  277.             "user" => $user,
  278.             "userId" => $user $user->getId() : null,
  279.             "userPermissionApi" => $this->getUserPermissionUtil()->getPermission(
  280.                 "appStore"
  281.                 "api"
  282.             ),
  283.             "session" => $session,
  284.             "userToken" => $userToken,
  285.             "canAccessAdm" => $this->getUserPermissionUtil()->canAccessAdm(),
  286.             "categories" => $categories,
  287.             "pages" => $pages,
  288.             "client" => $client,
  289.             "clientVersion" => $clientPathVersion,
  290.             "domain" => $domain,
  291.             "eadDomain" => $eadDomain,
  292.             "actualDomain" => $actualDomain,
  293.             "configuration" => $this->configuration->getAllConfig(),
  294.             "year" => date('Y'),
  295.             "totalNotifications" => $notificationNumber,
  296.             "countEnrollment" => $countEnrollment,
  297.             "countCertificate" => $countCertificate,
  298.             "countWish" => $countWish,
  299.             "versionSite" => $assetsVersion->{"site_{$clientPathVersion}"},
  300.             "versionAdmin" => $assetsVersion->{"admin_{$clientPathVersion}"},
  301.             "versionLesson" => $assetsVersion->{"lesson_{$clientPathVersion}"},
  302.             "countSocial" => $countSocial,
  303.             "cdnVersion" => strtotime(date('Y-m-d H:i:s')),
  304.             "cdn" => $this->cdn,
  305.             "cdnLivestream" => "//livestream.com/assets/plugins/referrer_tracking.js",
  306.             "cdnSambatech" => "//player.sambatech.com.br/stable/js/samba.player.api.js",
  307.             "cdnGoogleFonts" => "//fonts.googleapis.com/css2",
  308.             "favicon" => $favicon,
  309.             "faviconCdn" => "{$this->cdn}img/favicon.ico",
  310.             "whatsapp" => $whatsapp,
  311.             "scHash" => md5($userId $actualDomain strtotime(date('Y-m-d H:i:s'))),
  312.             "menuMobileNotificacoes" => $menuMobileNotificacoes,
  313.             "userTeacherSpotlight" => $userTeacherSpotlight,
  314.             "pagesFooter" => $pagesFooter,
  315.             "hasProducts" => $hasProducts,
  316.             "isRestricted" => $isRestricted,
  317.             "isAppDomain" => $isAppDomain,
  318.             "isBrazilDefault" => true,
  319.             "isForumStatusDefault" => true,
  320.             "isDarkTheme" => ($this->configuration->get('website_theme') == 'dark'),
  321.             "isLocal" => $this->configuration->isLocal(),
  322.             "debug" => $this->configuration->isDebug(),
  323.             "hideBgDeco" => (bool)($this->configuration->get('hide_background_decoration')),
  324.             "feeInstallmentInterest" => $paymentConfig->installmentInterest,
  325.         ];
  326.     }
  327. }