src/Twig/FunctionsExtension.php line 880

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Twig;
  3. use Twig\Extension\AbstractExtension;
  4. use Twig\TwigFunction;
  5. use EADPlataforma\Services\GeneralService;
  6. use EADPlataforma\Services\ConfigurationService;
  7. use EADPlataforma\Entity\Cart;
  8. use EADPlataforma\Entity\Course;
  9. use EADPlataforma\Entity\Product;
  10. use EADPlataforma\Entity\ProductOffer;
  11. use EADPlataforma\Entity\ProductCoupon;
  12. use EADPlataforma\Entity\Whishlist;
  13. use EADPlataforma\Entity\Exam;
  14. use EADPlataforma\Entity\Enrollment;
  15. use EADPlataforma\Entity\User;
  16. use EADPlataforma\Entity\Category;
  17. use EADPlataforma\Entity\CourseTestimonial;
  18. use EADPlataforma\Entity\TransactionItem;
  19. use EADPlataforma\Entity\UserCustomField;
  20. use EADPlataforma\Entity\PageSection;
  21. use EADPlataforma\Entity\UserSubscription;
  22. use EADPlataforma\Enum\ExamEnum;
  23. use EADPlataforma\Enum\CartEnum;
  24. use EADPlataforma\Enum\ClientEnum;
  25. use EADPlataforma\Enum\CourseEnum;
  26. use EADPlataforma\Enum\ProductEnum;
  27. use EADPlataforma\Enum\ProductOfferEnum;
  28. use EADPlataforma\Enum\ReceiverEnum;
  29. use EADPlataforma\Enum\WhishlistEnum;
  30. use EADPlataforma\Enum\EnrollmentEnum;
  31. use EADPlataforma\Enum\UserCustomFieldEnum;
  32. use EADPlataforma\Enum\PageSectionEnum;
  33. use EADPlataforma\Util\DateTimeUtil;
  34. class FunctionsExtension extends AbstractExtension
  35. {   
  36.     /**
  37.      * @var GeneralService
  38.      */
  39.     private $generalService;
  40.     /**
  41.      * @var ConfigurationService
  42.      */
  43.     private $configuration;
  44.     /**
  45.      * @var SchoolEntityManager
  46.      */
  47.     protected $em;
  48.     /**
  49.      * @var User $user
  50.      */
  51.     protected $user;
  52.     /**
  53.      * @var Array $results
  54.      */
  55.     protected $results = [];
  56.     
  57.     /**
  58.      * @var Array $arrValue
  59.      */
  60.     protected $arrValue = [];
  61.     // SECTIONS
  62.     private $sectionTemplates = [
  63.         'headSection' => 'includes/menu-section',
  64.         'bannerSection' => 'home/banner-section',
  65.         'searchSection' => 'includes/search-section',
  66.         'productSpotlightOfferSection' => 'product/product-section',
  67.         'enrollmentSection' => 'user/enrollment/enrollment-section',
  68.         'productCourseSection' => 'product/product-section',
  69.         'productLastCourseSection' => 'product/product-section',
  70.         'productBestSellersSection' => 'product/product-section',
  71.         'productPlanSection' => [
  72.             'light' => 'product/product-section',
  73.             'dark'  => 'product/product-box-home-section',
  74.         ],
  75.         'productComboSection' => 'product/product-section',
  76.         'productUserRecomendationSection' => 'product/product-section',
  77.         'productBestSection' => 'product/product-section',
  78.         'productRandomWhishlistSection' => 'product/product-section',
  79.         'productCategorySection' => 'product/product-category-section',
  80.         'teacherSection' => 'teacher/teacher-section',
  81.         'schoolNumberSection' => 'home/school-numbers-section',
  82.         'faqSection' => 'faq/faq-section',
  83.         'testimonialSection' => 'course/course-testimonial-section',
  84.         'newsSection' => 'home/newsletter-section',
  85.         'socialSection' => 'includes/social-section',
  86.         'institutionalSection' => 'institutional/institutional-section',
  87.         'stampsSection' => 'includes/stamps-section',
  88.     ];
  89.     /**
  90.      * Constructor
  91.      *
  92.      * @param GeneralService $generalService
  93.      */
  94.     public function __construct(GeneralService $generalService)
  95.     {
  96.         $this->generalService $generalService;
  97.         $this->em $this->generalService->getService('SchoolEntityManager');
  98.     }
  99.     public function getConfiguration()
  100.     {   
  101.         if(!$this->configuration){
  102.             $this->configuration $this->generalService->getService('ConfigurationService');
  103.         }
  104.         return $this->configuration;
  105.     }
  106.     public function getUser()
  107.     {
  108.         if(!$this->user){
  109.             $this->user $this->generalService->getService('UserSessionService')->getUser();
  110.         }
  111.         return $this->user;
  112.     }
  113.     public function getFunctions()
  114.     {
  115.         return [
  116.             new TwigFunction('getConfig', [$this'getConfig']),
  117.             new TwigFunction('getCss', [$this'getCss']),
  118.             new TwigFunction('getScript', [$this'getScript']),
  119.             new TwigFunction('checkConfigHasScript', [$this'checkConfigHasScript']),
  120.             new TwigFunction('getMeta', [$this'getMeta']),
  121.             new TwigFunction('getConfigPayment', [$this'getConfigPayment']),
  122.             new TwigFunction('isModuleActive', [$this'isModuleActive']),
  123.             new TwigFunction('isPlanModuleActive', [$this'isPlanModuleActive']),
  124.             new TwigFunction('getSection', [$this'getSection']),
  125.             new TwigFunction('getPermission', [$this'getPermission']),
  126.             new TwigFunction('isLow', [$this'isLow']),
  127.             new TwigFunction('isMiddle', [$this'isMiddle']),
  128.             new TwigFunction('isHigh', [$this'isHigh']),
  129.             new TwigFunction(
  130.                 'getInfoAccessProductOffer', [$this'getInfoAccessProductOffer']
  131.             ),
  132.             new TwigFunction(
  133.                 'checkProductOfferIsOnSale', [$this'checkProductOfferIsOnSale']
  134.             ),
  135.             new TwigFunction(
  136.                 'getOfferProductSubscription', [$this'getOfferProductSubscription']
  137.             ),
  138.             new TwigFunction('getClient', [$this'getClient']),
  139.             new TwigFunction('getUserCartNumber', [$this'getUserCartNumber']),
  140.             new TwigFunction('getUserCartSubTotal', [$this'getUserCartSubTotal']),
  141.             new TwigFunction('getUserCartMenuItems', [$this'getUserCartMenuItems']),
  142.             new TwigFunction('productIsInCart', [$this'productIsInCart']),
  143.             new TwigFunction('getExamType', [$this'getExamType']),
  144.             new TwigFunction('getEnrollmentStatus', [$this'getEnrollmentStatus']),
  145.             new TwigFunction('getEnrollmentSituation', [$this'getEnrollmentSituation']),
  146.             new TwigFunction(
  147.                 'getEnrollmentSituationClass', [$this'getEnrollmentSituationClass']
  148.             ),
  149.             new TwigFunction(
  150.                 'getEnrollmentPeriodLabel', [$this'getEnrollmentPeriodLabel']
  151.             ),
  152.             new TwigFunction('printValueOrEmpty', [$this'printValueOrEmpty']),
  153.             new TwigFunction('isInWhishlist', [$this'isInWhishlist']),
  154.             new TwigFunction('plural', [$this'plural']),
  155.             new TwigFunction('installments', [$this'installments']),
  156.             new TwigFunction('htmlDecode', [$this'htmlDecode']),
  157.             new TwigFunction('getLanguage', [$this'getLanguage']),
  158.             new TwigFunction('getLanguageModule', [$this'getLanguageModule']),
  159.             new TwigFunction('workLoadText', [$this'workLoadText']),
  160.             new TwigFunction('existReceiverEAD', [$this'existReceiverEAD']),
  161.             new TwigFunction('getFilePathComplete', [$this'getFilePathComplete']),
  162.             new TwigFunction('getTextProductType', [$this'getTextProductType']),
  163.             new TwigFunction('discountPercent', [$this'discountPercent']),
  164.             new TwigFunction('enum', [$this'enum']),
  165.             new TwigFunction('getScoreCourse', [$this'getScoreCourse']),
  166.             new TwigFunction('getScoreProduct', [$this'getScoreProduct']),
  167.             new TwigFunction('getTimeTotalProduct', [$this'getTimeTotalProduct']),
  168.             new TwigFunction('getOfferParcelInfo', [$this'getOfferParcelInfo']),
  169.             new TwigFunction('getOfferContract', [$this'getOfferContract']),
  170.             new TwigFunction('installmentPeriodText', [$this'installmentPeriodText']),
  171.             new TwigFunction('courseByProductTotal', [$this'courseByProductTotal']),
  172.             new TwigFunction('userHasProduct', [$this'userHasProduct']),
  173.             new TwigFunction('hasInCart', [$this'hasInCart']),
  174.             new TwigFunction(
  175.                 'getFirstCourseIdFromProduct', [$this'getFirstCourseIdFromProduct']
  176.             ),
  177.             new TwigFunction(
  178.                 'getProductTypeTextTranslate', [$this'getProductTypeTextTranslate']
  179.             ),
  180.             new TwigFunction('encodeHex', [$this'encodeHex']),
  181.             new TwigFunction('getDefaultRecaptcha', [$this'getDefaultRecaptcha']),
  182.             new TwigFunction('getFields', [$this'getFields']),
  183.             new TwigFunction('clearSocialUrl', [$this'clearSocialUrl']),
  184.             new TwigFunction('checkSection', [$this'checkSection']),
  185.             new TwigFunction('paintStars', [$this'paintStars']),
  186.             new TwigFunction('getCategoryOffers', [$this'getCategoryOffers']),
  187.             new TwigFunction('HEXtoRGB', [$this'HEXtoRGB']),
  188.             new TwigFunction('RGBtoHSL', [$this'RGBtoHSL']),
  189.             new TwigFunction('HEXtoHSL', [$this'HEXtoHSL']),
  190.             new TwigFunction('setValue', [$this'setValue']),
  191.             new TwigFunction('getValue', [$this'getValue']),
  192.             new TwigFunction('pageSectionFormat', [$this'pageSectionFormat']),
  193.             new TwigFunction('pageSectionPosition', [$this'pageSectionPosition']),
  194.             new TwigFunction('pageSectionTemplateItem', [$this'pageSectionTemplateItem']),
  195.             new TwigFunction('pageSectionItems', [$this'pageSectionItems']),
  196.             new TwigFunction('pageSectionLinkAll', [$this'pageSectionLinkAll']),
  197.             new TwigFunction('isPageSection', [$this'isPageSection']),
  198.             new TwigFunction('pageSectionShowAll', [$this'pageSectionShowAll']),
  199.             new TwigFunction('getPlanCycleString', [$this'getPlanCycleString']),
  200.             new TwigFunction('getPlanCycleStringProductDetail', [
  201.                 $this'getPlanCycleStringProductDetail'
  202.             ]),
  203.             new TwigFunction('getDocumentFormat', [$this'getDocumentFormat']),
  204.             new TwigFunction('getUserSubscriptionError', [$this'getUserSubscriptionError']),
  205.             new TwigFunction('getVimeoFormatIframe', [$this'getVimeoFormatIframe']),
  206.             new TwigFunction('isValidCard', [$this'isValidCard']),
  207.             new TwigFunction('stringOrigin', [$this'stringOrigin']),
  208.             new TwigFunction('stringStatus', [$this'stringStatus']),
  209.         ];
  210.     }
  211.     public function getConfig(string $configName)
  212.     {
  213.         $value $this->getConfiguration()->get($configName);
  214.         $cleanKeys = [
  215.             "contract",
  216.             "privacy_policy",
  217.         ];
  218.         if(in_array($configName$cleanKeys)){
  219.             $stringUtil $this->generalService->getUtil('StringUtil');
  220.             $value $stringUtil->removeScripts($value);
  221.         }
  222.         return $value;
  223.     }
  224.     public function getMeta(string $configName)
  225.     {
  226.         return $this->getConfiguration()->get($configName);
  227.     }
  228.     public function getCss(string $configName)
  229.     {
  230.         return $this->getConfiguration()->get($configName);
  231.     }
  232.     public function getScript(string $configName, ?string $nonceHash "")
  233.     {
  234.         $value $this->getConfiguration()->get($configName);
  235.         $scripts = [ 'scripts' ];
  236.         if(in_array($configName$scripts)){
  237.             $value htmlspecialchars_decode($valueENT_QUOTES);
  238.         }
  239.         $value str_replace("<script ""<script nonce='{$nonceHash}' "$value);
  240.         $value str_replace("<script>""<script nonce='{$nonceHash}'>"$value);
  241.         return $value;
  242.     }
  243.     public function checkConfigHasScript(string $configName)
  244.     {
  245.         $value $this->getConfiguration()->get($configName);
  246.         
  247.         return stristr($value'script');
  248.     }
  249.     public function getConfigPayment()
  250.     {
  251.         return $this->getConfiguration()->getPaymentConfig();
  252.     }
  253.     public function isModuleActive($moduleName)
  254.     {
  255.         return $this->getConfiguration()->isModuleActive($moduleName);
  256.     }
  257.     public function isPlanModuleActive($moduleName)
  258.     {
  259.         return $this->getConfiguration()->checkModuleIsAbleOnPlan($moduleName);
  260.     }
  261.     public function getPermission($level1 null$level2 null$level3 null$level4 null)
  262.     {
  263.         $userPermissionUtil $this->generalService->getUtil('UserPermissionUtil');
  264.         return $userPermissionUtil->getPermission($level1$level2$level3$level4);
  265.     }
  266.     public function isLow(int $permissionValue)
  267.     {
  268.         $userPermissionUtil $this->generalService->getUtil('UserPermissionUtil');
  269.         return $userPermissionUtil->isLow($permissionValue);
  270.     }
  271.     public function isMiddle(int $permissionValue)
  272.     {
  273.         $userPermissionUtil $this->generalService->getUtil('UserPermissionUtil');
  274.         return $userPermissionUtil->isMiddle($permissionValue);
  275.     }
  276.     public function isHigh(int $permissionValue)
  277.     {
  278.         $userPermissionUtil $this->generalService->getUtil('UserPermissionUtil');
  279.         return $userPermissionUtil->isHigh($permissionValue);
  280.     }
  281.     public function getInfoAccessProductOffer(
  282.         ProductOffer $productOffer
  283.         ?bool $isNext false
  284.         ?ProductCoupon $productCoupon null
  285.         ?bool $isOfferSpotligth false
  286.     )
  287.     {
  288.         $data = (object)[
  289.             "link" => "#",
  290.             "text" => "buy_now",
  291.             "allowBuyNow" => false,
  292.             "isFree" => false,
  293.             "dateSaleOffer" => null,
  294.             "userHasProduct" => false,
  295.             "saleOfferStart" => false,
  296.             "saleChannelOption" => false,
  297.             "colorBtnWaitList" => false
  298.         ];
  299.         $product $productOffer->getProduct();
  300.         $productRepository $this->em->getRepository(Product::class);
  301.         if($this->getUser()){
  302.             $dataProduct $productRepository->userHasProduct($this->getUser(), $product);
  303.             if($dataProduct){
  304.                 $data->userHasProduct true;
  305.                 $routeName null;
  306.                 $routeParams null;
  307.                 if($dataProduct->type == ProductEnum::COURSE){
  308.                     $routeName 'courseIndex';
  309.                     $routeParams = [ 
  310.                         "id" => $dataProduct->elementId 
  311.                     ];
  312.                 }else if($dataProduct->type == ProductEnum::SUBSCRIPTION){
  313.                     $routeName 'resume';
  314.                 }
  315.                 if(!empty($routeName)){
  316.                     $data->link $this->generalService->generateUrl(
  317.                         $routeName
  318.                         $routeParams
  319.                     );
  320.                     $data->text $this->getConfiguration()->getLanguage(
  321.                         'access2''product'
  322.                     );
  323.                 }
  324.             }
  325.         }
  326.         if(!$data->userHasProduct){
  327.             $saleIsOpen $this->checkProductOfferIsOnSale($productOffer);
  328.             if(
  329.                 $productOffer->getSaleOption() == ProductOfferEnum::FREE && 
  330.                 $saleIsOpen
  331.             ){
  332.                 $data->isFree true;
  333.                 if($productOffer->getSaleChannel() == ProductOfferEnum::EXTERNAL){
  334.                     $data->link $productOffer->getExternalCheckoutLink();
  335.                     $data->saleChannelOption true;
  336.                 }else{
  337.                     if($this->getUser()){
  338.                         $data->link $this->generalService->generateUrl(
  339.                             'cartCreateEnroll'
  340.                             [ "productOfferId" => $productOffer->getId() ]
  341.                         );
  342.                     }else{
  343.                         $data->link '#fast-register-modal';
  344.                     }
  345.                 }
  346.                 $data->text $this->getConfiguration()->getLanguage(
  347.                     'enroll''product'
  348.                 );
  349.                 
  350.             }else{
  351.                 if($saleIsOpen){
  352.                     if($productOffer->getSaleChannel() == ProductOfferEnum::EXTERNAL){
  353.                         $data->link $productOffer->getExternalCheckoutLink();
  354.                         $data->saleChannelOption true;
  355.                     }else{
  356.                         $data->allowBuyNow true;
  357.                         $data->link $this->generalService->generateUrl('cartAdd', [ 
  358.                             "poID" => $productOffer->getId(),
  359.                             "pcID" => ($productCoupon $productCoupon->getId() : 0)
  360.                         ]);
  361.                         if(
  362.                             $productOffer->getAllowRecurrency() == ProductOfferEnum::YES || 
  363.                             $product->getType() == ProductEnum::SUBSCRIPTION
  364.                         ){
  365.                             $data->text $this->getConfiguration()->getLanguage(
  366.                                 'subscribe_now''product'
  367.                             );
  368.                             if($productOffer->getAllowTrial() == ProductOfferEnum::YES){
  369.                                 $data->saleChannelOption true;
  370.                             }
  371.                                 
  372.                             if(
  373.                                 $product->getType() == ProductEnum::SUBSCRIPTION && 
  374.                                 $isOfferSpotligth
  375.                             ){
  376.                                 $data->link "#section-plan-cycles";
  377.                             }else if($productOffer->getAllowTrial() == ProductOfferEnum::YES){
  378.                                 $dataProduct false;
  379.                                 if($this->getUser()){
  380.                                     $dataProduct $productRepository->userHasProduct(
  381.                                         $this->getUser(), 
  382.                                         $product,
  383.                                         true
  384.                                     );
  385.                                 }
  386.                                 if(!$dataProduct || empty($this->getUser())){
  387.                                     $data->link $this->generalService->generateUrl(
  388.                                         'cartIndividual', [ 
  389.                                         "poHash" => $productOffer->getOfferLink(),
  390.                                         "pcKey" => (
  391.                                             $productCoupon 
  392.                                             $productCoupon->getKey() : 
  393.                                             null
  394.                                         )
  395.                                     ]);
  396.                                 }
  397.                             }
  398.                         }
  399.                     }
  400.                 }else{
  401.                     $next $productOffer->getNextProductOffer();
  402.                     if($next && !$isNext){
  403.                         if(
  404.                             $next->getStatus() == ProductOfferEnum::PUBLISHED && 
  405.                             $next->isNotDeleted()
  406.                         ){
  407.                             return $this->getInfoAccessProductOffer(
  408.                                 $next
  409.                                 true
  410.                                 $productCoupon
  411.                             );
  412.                         }
  413.                     }
  414.                     $getDiffStart $productOffer->getDiffDuration();
  415.                     if($getDiffStart['start'] == true) {
  416.                         $data->dateSaleOffer $productOffer->getSaleDateStart();
  417.                         $data->saleOfferStart true;
  418.                     }else{
  419.                         $data->dateSaleOffer $productOffer->getSaleDateClose();
  420.                     }
  421.                     $data->colorBtnWaitList true;
  422.                     $data->link '#wait-list-modal';
  423.                     $data->text $this->getConfiguration()->getLanguage(
  424.                         'join_the_list',
  425.                         'product'
  426.                     );
  427.                 }
  428.             }
  429.         }
  430.         return $data;
  431.     }
  432.     public function getOfferProductSubscription(ProductOffer $productOfferDefault)
  433.     {
  434.         $productOfferRepository $this->em->getRepository(ProductOffer::class);
  435.         $product $productOfferDefault->getProduct();
  436.         $monthOffer $productOfferRepository->getDefaultOrCustomByCycle(
  437.             $product,
  438.             ProductOfferEnum::CYCLE_MONTHLY
  439.         );
  440.         $quarterlyOffer $productOfferRepository->getDefaultOrCustomByCycle(
  441.             $product,
  442.             ProductOfferEnum::CYCLE_QUARTERLY
  443.         );
  444.         $semiannualOffer $productOfferRepository->getDefaultOrCustomByCycle(
  445.             $product,
  446.             ProductOfferEnum::CYCLE_SEMIANNUAL
  447.         );
  448.         $yearlyOffer $productOfferRepository->getDefaultOrCustomByCycle(
  449.             $product,
  450.             ProductOfferEnum::CYCLE_YEARLY
  451.         );
  452.         $biennialOffer $productOfferRepository->getDefaultOrCustomByCycle(
  453.             $product,
  454.             ProductOfferEnum::CYCLE_BIENNIAL
  455.         );
  456.         $triennialOffer $productOfferRepository->getDefaultOrCustomByCycle(
  457.             $product,
  458.             ProductOfferEnum::CYCLE_TRIENNIAL
  459.         );
  460.         $weeklyOffer $productOfferRepository->getDefaultOrCustomByCycle(
  461.             $product,
  462.             ProductOfferEnum::CYCLE_WEEKLY
  463.         );
  464.         $biweeklyOffer $productOfferRepository->getDefaultOrCustomByCycle(
  465.             $product,
  466.             ProductOfferEnum::CYCLE_BIWEEKLY
  467.         );
  468.         $productOffers array_filter([
  469.             $monthOffer,
  470.             $quarterlyOffer,
  471.             $semiannualOffer,
  472.             $yearlyOffer,
  473.             $biennialOffer,
  474.             $triennialOffer,
  475.             $weeklyOffer,
  476.             $biweeklyOffer,
  477.         ]);
  478.         return $productOfferRepository->returnProductOfferOrProductNextPlan(
  479.             $productOfferDefault
  480.             $productOffers
  481.         );
  482.     }
  483.     public function checkProductOfferIsOnSale(ProductOffer $productOffer)
  484.     {
  485.         $productOfferRepository $this->em->getRepository(ProductOffer::class);
  486.         return $productOfferRepository->checkProductOfferIsOnSale($productOffer);
  487.     }
  488.     public function getClient()
  489.     {
  490.         return $this->getConfiguration()->getClient();
  491.     }
  492.     public function getUserCartNumber()
  493.     {
  494.         $cartRepository $this->em->getRepository(Cart::class);
  495.         return $cartRepository->countUserOnCart();
  496.     }
  497.     public function getUserCartSubTotal()
  498.     {
  499.         $cartRepository $this->em->getRepository(Cart::class);
  500.         if($this->getUser()){
  501.             return $cartRepository->getUserSubTotal($this->getUser()->getId());
  502.         }else{
  503.             $hashIdentify $this->generalService->getCookie('hashcartoff');
  504.             if(!empty($hashIdentify)){
  505.                 return $cartRepository->getHashSubTotal($hashIdentify);
  506.             }
  507.         }
  508.         return 0;
  509.     }
  510.     public function getUserCartMenuItems(?int $limit 2)
  511.     {
  512.         $cartRepository $this->em->getRepository(Cart::class);
  513.         if($this->getUser()){
  514.             return $cartRepository->getUserValidCarts($this->getUser()->getId(), null$limit);
  515.         }else{
  516.             $hashIdentify $this->generalService->getCookie('hashcartoff');
  517.             if(!empty($hashIdentify)){
  518.                 return $cartRepository->getHashValidCarts($hashIdentifynull$limit);
  519.             }
  520.         }
  521.         return [];
  522.     }
  523.     public function productIsInCart(int $productId, ?int $productOfferId null)
  524.     {
  525.         $cartRepository $this->em->getRepository(Cart::class);
  526.         $hashIdentify $this->generalService->getCookie('hashcartoff');
  527.         if(!$this->getUser() && empty($hashIdentify)){
  528.             return false;
  529.         }
  530.         $filter = [
  531.             "product" => $productId
  532.             "deleted" => CartEnum::ITEM_NO_DELETED
  533.         ];
  534.         if($this->getUser()){
  535.             $filter["user"] = $this->getUser()->getId();
  536.         }else if(!empty($hashIdentify)){
  537.             $filter["hashIdentify"] = $hashIdentify;
  538.         }
  539.         if(!empty($productOfferId)){
  540.             $filter["productOffer"] = $productOfferId;
  541.         }
  542.         $cartSave $cartRepository->findOneBy($filter);
  543.         return ($cartSave true false);
  544.     }
  545.     public function getExamType(int $examType)
  546.     {
  547.         $examRepository $this->em->getRepository(Exam::class);
  548.         return $examRepository->getExamTypeText($examType);
  549.     }
  550.     public function getEnrollmentStatus(int $status)
  551.     {
  552.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  553.         return $enrollmentRepository->getStringStatus($status);
  554.     }
  555.     public function getEnrollmentSituation(?Enrollment $enrollment null)
  556.     {
  557.         $situation EnrollmentEnum::SITUATION_NOT_STARTED;
  558.         if($enrollment){
  559.             $situation $enrollment->getSituation();
  560.         }
  561.         $situationLabels = [
  562.             EnrollmentEnum::SITUATION_STARTED => "in_progress",
  563.             EnrollmentEnum::SITUATION_NOT_STARTED => "not_started",
  564.             EnrollmentEnum::SITUATION_COMPLETED => "completed",
  565.         ];
  566.         $index $situationLabels[$situation];
  567.         return $this->getConfiguration()->getLanguage($index'user_resume');
  568.     }
  569.     public function getEnrollmentSituationClass(?Enrollment $enrollment null)
  570.     {
  571.         $situation EnrollmentEnum::SITUATION_NOT_STARTED;
  572.         if($enrollment){
  573.             $situation $enrollment->getSituation();
  574.         }
  575.         $situationLabels = [
  576.             EnrollmentEnum::SITUATION_STARTED => "information",
  577.             EnrollmentEnum::SITUATION_NOT_STARTED => "",
  578.             EnrollmentEnum::SITUATION_COMPLETED => "success",
  579.         ];
  580.         return $situationLabels[$situation];
  581.     }
  582.     public function getEnrollmentPeriodLabel(?Enrollment $enrollment null, ?Course $course null)
  583.     {
  584.         if($enrollment){
  585.             $datePeriod $enrollment->getDatePeriod('d/m/Y');
  586.             if($datePeriod == "09/09/9999"){
  587.                 return $this->getConfiguration()->getLanguage('lifetime''enrollments');
  588.             }
  589.             if($enrollment->getStatus(falsetrue) == EnrollmentEnum::STATUS_EXPIRED){
  590.                 return $this->getConfiguration()->getLanguage('expired''user_resume');
  591.             }
  592.             $txt $this->getConfiguration()->getLanguage('access_until''user_resume');
  593.             if($datePeriod == date('d/m/Y')){
  594.                 $time date('H:i:s');
  595.                 return "{$txt} {$time}";
  596.             }
  597.             return "{$txt} {$datePeriod}";
  598.         }else if($course){
  599.             if($course->getLifetimePeriod() == CourseEnum::YES){
  600.                 return $this->getConfiguration()->getLanguage('lifetime''enrollments');
  601.             }
  602.             $datePeriod date('d/m/Y'strtotime(" + {$course->getAccessPeriod()} days"));
  603.             $txt $this->getConfiguration()->getLanguage('access_until''user_resume');
  604.             
  605.             return "{$txt} {$datePeriod}";
  606.         }
  607.         return $this->getConfiguration()->getLanguage('expired''user_resume');
  608.     }
  609.     public function isInWhishlist(int $productId)
  610.     {
  611.         if(!$this->getUser()){
  612.             return false;
  613.         }
  614.         $whishlistRepository $this->em->getRepository(Whishlist::class);
  615.         $whishlistSave $whishlistRepository->findOneBy([
  616.             "product" => $productId
  617.             "user" => $this->getUser()->getId(),
  618.             "deleted" => WhishlistEnum::ITEM_NO_DELETED
  619.         ]);
  620.         return ( $whishlistSave true false );
  621.     }
  622.     public function printValueOrEmpty($value)
  623.     {
  624.         return (!empty($value) ? $value '---');
  625.     }
  626.     public function getSection($sectionName)
  627.     {
  628.         $theme $this->getConfiguration()->get('website_theme');
  629.         if(empty($theme))
  630.         {
  631.             $theme 'light';
  632.         }
  633.         if(empty($this->sectionTemplates[$sectionName]))
  634.         {
  635.             return false;
  636.         }
  637.         $sectionFile $this->sectionTemplates[$sectionName];
  638.         if(is_array($sectionFile))
  639.         {
  640.             $sectionFile $sectionFile[$theme];
  641.         }
  642.         $sectionFile "website/{$sectionFile}.html.twig";
  643.         return $sectionFile;
  644.     }
  645.     // PLURAL
  646.     public function plural($numero$tx_singular$tx_plural)
  647.     {
  648.         return ($numero == 1) ? $tx_singular $tx_plural;
  649.     }
  650.     // INSTALLMENTS
  651.     public function installmentPeriodText($subscriptionCycleEnum)
  652.     {
  653.         // Cycle X Months
  654.         $installmentMonths = [
  655.             ProductOfferEnum::CYCLE_MONTHLY => [
  656.                 "period" => 1,
  657.                 "text" => $this->getConfiguration()->getLanguage('monthly''product'),
  658.                 "textPlan" => $this->getConfiguration()->getLanguage('monthly_plan''product'),
  659.             ],
  660.             ProductOfferEnum::CYCLE_QUARTERLY => [
  661.                 "period" => 3,
  662.                 "text" => $this->getConfiguration()->getLanguage('quarterly''product'),
  663.                 "textPlan" => $this->getConfiguration()->getLanguage('quarterly_plan''product'),
  664.             ],
  665.             ProductOfferEnum::CYCLE_SEMIANNUAL => [
  666.                 "period" => 6,
  667.                 "text" => $this->getConfiguration()->getLanguage('semiannual''product'),
  668.                 "textPlan" => $this->getConfiguration()->getLanguage('semiannual_plan''product'),
  669.             ],
  670.             ProductOfferEnum::CYCLE_YEARLY => [
  671.                 "period" => 12,
  672.                 "text" => $this->getConfiguration()->getLanguage('yearly''product'),
  673.                 "textPlan" => $this->getConfiguration()->getLanguage('yearly_plan''product'),
  674.             ],
  675.             ProductOfferEnum::CYCLE_WEEKLY => [
  676.                 "period" => 1,
  677.                 "text" => $this->getConfiguration()->getLanguage('weekly''product'),
  678.                 "textPlan" => $this->getConfiguration()->getLanguage('weekly_plan''product'),
  679.             ],
  680.             ProductOfferEnum::CYCLE_BIWEEKLY => [
  681.                 "period" => 1,
  682.                 "text" => $this->getConfiguration()->getLanguage('biweekly''product'),
  683.                 "textPlan" => $this->getConfiguration()->getLanguage('biweekly_plan''product'),
  684.             ],
  685.             ProductOfferEnum::CYCLE_BIENNIAL => [
  686.                 "period" => 24,
  687.                 "text" => $this->getConfiguration()->getLanguage('biennial''product'),
  688.                 "textPlan" => $this->getConfiguration()->getLanguage('biennial_plan''product'),
  689.             ],
  690.             ProductOfferEnum::CYCLE_TRIENNIAL => [
  691.                 "period" => 36,
  692.                 "text" => $this->getConfiguration()->getLanguage('triennial''product'),
  693.                 "textPlan" => $this->getConfiguration()->getLanguage('triennial_plan''product'),
  694.             ],
  695.         ];
  696.         if (isset($installmentMonths[$subscriptionCycleEnum])){
  697.             return (object)$installmentMonths[$subscriptionCycleEnum];
  698.         }
  699.         return (object)$installmentMonths[ProductOfferEnum::CYCLE_MONTHLY];
  700.     }
  701.     public function installments(ProductOffer $productOffer)
  702.     {
  703.         $months $this->installmentPeriodText($productOffer->getPlanCycle());
  704.         $productOfferRepository $this->em->getRepository(ProductOffer::class);
  705.         $numberUtil $this->generalService->getUtil('NumberUtil');
  706.         
  707.         $parcelInfo $numberUtil->getNumberMaxParcel(
  708.             $productOffer->getPriceReal(true),
  709.             $productOfferRepository->getInstallmentNumberMax($productOffer),
  710.             $productOfferRepository->getFreeInstallment($productOffer),
  711.             $productOffer->getSaleOption(),
  712.             $productOffer->getTypeCheckout(),
  713.             false
  714.         );
  715.         return [
  716.             'number'=> $parcelInfo->maxInstallments,
  717.             'value' => $parcelInfo->parcelPrice,
  718.             'period'=> $months->text,
  719.         ];
  720.     }
  721.     // HTML DECODE ENTITIES
  722.     public function htmlDecode($txt)
  723.     {
  724.         return html_entity_decode($txt);
  725.     }
  726.     // HTML DECODE ENTITIES
  727.     public function existReceiverEAD()
  728.     {
  729.         $receiverSchool $this->getConfiguration()->getReceiverSchool(ReceiverEnum::EAD_CHECKOUT);
  730.         return ($receiverSchooltrue false);
  731.     }
  732.     // TRANSLATION
  733.     public function getLanguage($key$file){
  734.         return $this->getConfiguration()->getLanguage($key$file);
  735.     }
  736.     public function getLanguageModule($module){
  737.         return $this->getConfiguration()->getLanguageModule($module);
  738.     }
  739.     public function workLoadText(?string $workload null)
  740.     {
  741.         if(empty($workload)){
  742.             return;
  743.         }
  744.         return DateTimeUtil::workloadFormat(
  745.             $workloadfalse$this->getLanguageModule('util')
  746.         );
  747.     }
  748.     public function getFilePathComplete($config)
  749.     {
  750.         $fileService $this->generalService->getService('FileService');
  751.         $config = (object)$config;
  752.         $config->fileName = (!empty($config->fileName) ? $config->fileName null);
  753.         $config->pathConst = (!empty($config->pathConst) ? $config->pathConst null);
  754.         $config->addUpload = (!empty($config->addUpload) ? $config->addUpload false);
  755.         $config->addStream = (!empty($config->addStream) ? $config->addStream false);
  756.         $config->option = (!empty($config->option) ? $config->option null);
  757.         $pathCdn $fileService->getFilePathComplete(
  758.             $config->fileName,
  759.             $config->pathConst,
  760.             $config->addUpload,
  761.             $config->addStream,
  762.             $config->option,
  763.             true
  764.         );
  765.         $pathCreateCrop $fileService->getFilePathComplete(
  766.             $config->fileName,
  767.             $config->pathConst,
  768.             $config->addUpload,
  769.             $config->addStream,
  770.             $config->option
  771.         );
  772.         return (object)[
  773.             "pathCdn" => $pathCdn,
  774.             "pathCreateCrop" => $pathCreateCrop,
  775.         ];
  776.     }
  777.     public function getTextProductType($type)
  778.     {
  779.         switch ($type) {
  780.             case ProductEnum::COURSE:
  781.                 return 'curso';
  782.                 break;
  783.             case ProductEnum::SUBSCRIPTION:
  784.                 return 'plano';
  785.                 break;
  786.             case ProductEnum::COMBO:
  787.                 return 'combo';
  788.                 break;
  789.             case ProductEnum::CERTIFICATE:
  790.                 return 'certificado';
  791.                 break;
  792.             case ProductEnum::LIVE:
  793.                 return 'live';
  794.                 break;
  795.         }
  796.     }
  797.     public function getProductTypeTextTranslate(int $type)
  798.     {
  799.         switch ($type) {
  800.             case ProductEnum::COURSE:
  801.                 return $this->getConfiguration()->getLanguage('course''util');
  802.                 break;
  803.             case ProductEnum::SUBSCRIPTION:
  804.                 return $this->getConfiguration()->getLanguage('subscription''util');
  805.                 break;
  806.             case ProductEnum::COMBO:
  807.                 return 'Combo';
  808.                 break;
  809.             default:
  810.                 return $this->getConfiguration()->getLanguage('course''util');;
  811.                 break;
  812.         }
  813.         
  814.         return 0;
  815.     }
  816.     public function discountPercent($priceReal$priceDisplay)
  817.     {
  818.         return ($priceDisplay == 0)? false : ($priceReal $priceDisplay) * 100;
  819.     }
  820.     public function enum($key)
  821.     {
  822.         return constant("EADPlataforma\\Enum\\{$key}");
  823.     }
  824.     public function getScoreCourse(Course $course)
  825.     {
  826.         $courseTestimonialRepository $this->em->getRepository(CourseTestimonial::class);
  827.         //Course Stars
  828.         $scoreCourse $courseTestimonialRepository->getScoreByCourse(
  829.             $course
  830.         );
  831.         if(empty($scoreCourse->fiveStar)){
  832.             $scoreCourse->fiveStar CourseEnum::NO;
  833.         }
  834.           
  835.         if(empty($scoreCourse->fourStar)){
  836.             $scoreCourse->fourStar CourseEnum::NO;
  837.         }
  838.         
  839.         if(empty($scoreCourse->threeStar)){
  840.             $scoreCourse->threeStar CourseEnum::NO;
  841.         }
  842.         
  843.         if(empty($scoreCourse->twoStar)){
  844.             $scoreCourse->twoStar CourseEnum::NO;
  845.         }
  846.         
  847.         if(empty($scoreCourse->oneStar)){
  848.             $scoreCourse->oneStar CourseEnum::NO;
  849.         }
  850.         $scoreCourse->splitScore = [
  851.             $scoreCourse->fiveStar,
  852.             $scoreCourse->fourStar,
  853.             $scoreCourse->threeStar,
  854.             $scoreCourse->twoStar,
  855.             $scoreCourse->oneStar,
  856.         ];
  857.         return $scoreCourse;
  858.     }
  859.     public function getTimeTotalProduct(Product $product)
  860.     {
  861.         $courseRepository $this->em->getRepository(Course::class);
  862.         $timeTotal $courseRepository->getAllCourseTimeByProduct($product);
  863.         return $timeTotal;
  864.     }
  865.     public function getScoreProduct(Product $product)
  866.     {
  867.         $courseTestimonialRepository $this->em->getRepository(CourseTestimonial::class);
  868.         //Course Stars
  869.         $scoreProduct $courseTestimonialRepository->getScoreByProduct(
  870.             $product
  871.         );
  872.         
  873.         if(empty($scoreProduct->fiveStar)){
  874.             $scoreProduct->fiveStar ProductEnum::NO;
  875.         }
  876.           
  877.         if(empty($scoreProduct->fourStar)){
  878.             $scoreProduct->fourStar ProductEnum::NO;
  879.         }
  880.         
  881.         if(empty($scoreProduct->threeStar)){
  882.             $scoreProduct->threeStar ProductEnum::NO;
  883.         }
  884.         
  885.         if(empty($scoreProduct->twoStar)){
  886.             $scoreProduct->twoStar ProductEnum::NO;
  887.         }
  888.         
  889.         if(empty($scoreProduct->oneStar)){
  890.             $scoreProduct->oneStar ProductEnum::NO;
  891.         }
  892.         $scoreProduct->splitScore = [
  893.             $scoreProduct->fiveStar,
  894.             $scoreProduct->fourStar,
  895.             $scoreProduct->threeStar,
  896.             $scoreProduct->twoStar,
  897.             $scoreProduct->oneStar,
  898.         ];
  899.         return $scoreProduct;
  900.     }
  901.     public function getOfferContract(ProductOffer $productOffer)
  902.     {
  903.         // Product contract
  904.         $contract trim($productOffer->getProduct()->getContract());
  905.         if (empty($contract) or preg_match('/^null$/i'$contract))
  906.         {
  907.             // Config contract
  908.             $contract trim($this->getConfig('contract'));
  909.             if (empty($contract) or preg_match('/^null$/i'$contract))
  910.             {
  911.                 $contract false;
  912.             }
  913.         }
  914.         return $contract;
  915.     }
  916.     public function getOfferParcelInfo(ProductOffer $productOffer, ?Cart $cart null)
  917.     {
  918.         $productOfferRepository $this->em->getRepository(ProductOffer::class);
  919.         $numberUtil $this->generalService->getUtil('NumberUtil');
  920.         $freeInstallments $productOfferRepository->getFreeInstallment($productOffer);
  921.         $parcelInfo $numberUtil->getNumberMaxParcel(
  922.             ($cart $cart->getPrice(true) : $productOffer->getPriceReal(true)),
  923.             $productOfferRepository->getInstallmentNumberMax($productOffer),
  924.             $freeInstallments,
  925.             $productOffer->getSaleOption(),
  926.             $productOffer->getTypeCheckout(),
  927.             false
  928.         );
  929.         $paymentConfig $this->getConfiguration()->getPaymentConfig();
  930.         $pagarMeTransaction $this->generalService->getService(
  931.             'PagarMe\\PagarMeTransaction'
  932.         );
  933.         $installmentsOptions $pagarMeTransaction->calculateInstallments([
  934.             'amount' => $productOffer->getPriceReal(true),
  935.             'free_installments' => $freeInstallments,
  936.             'max_installments' => $parcelInfo->maxInstallments,
  937.             'interest_rate' => $paymentConfig->installmentInterest
  938.         ]);
  939.         $parcelInfo->installmentsOptions $installmentsOptions;
  940.         return $parcelInfo;
  941.     }
  942.     public function courseByProductTotal($productId){
  943.         $courseRepository $this->em->getRepository(Course::class);
  944.         $courseTotal $courseRepository->getPublishedCourseNumberByProduct(
  945.             $productId
  946.         );
  947.         return $courseTotal;
  948.     }
  949.     public function userHasProduct(Product $product, ?bool $ignoreStatus false){
  950.         $hashResult md5(
  951.             (
  952.                 $this->getUser() ? 
  953.                 $this->getUser()->getId() : 
  954.                 null
  955.             ) . $product->getId() . (
  956.                 $ignoreStatus ?
  957.                 ProductOfferEnum::YES :
  958.                 ProductOfferEnum::NO
  959.             )
  960.         );
  961.         if(isset($this->results["userHasProduct_{$hashResult}"])){
  962.             return $this->results["userHasProduct_{$hashResult}"];
  963.         }
  964.         if(!$this->getUser()){
  965.             $this->results["userHasProduct_{$hashResult}"] = false;
  966.             return $this->results["userHasProduct_{$hashResult}"];
  967.         }
  968.         $productRepository $this->em->getRepository(Product::class);
  969.         $dataProduct $productRepository->userHasProduct(
  970.             $this->getUser(),
  971.             $product,
  972.             false,
  973.             $ignoreStatus
  974.         );
  975.         $this->results["userHasProduct_{$hashResult}"] = ($dataProduct true false);
  976.         return $this->results["userHasProduct_{$hashResult}"];
  977.     }
  978.     public function hasInCart(array $productOffers)
  979.     {
  980.         $has true;
  981.         foreach ($productOffers as $key => $productOffer) {
  982.             if(!$this->productIsInCart($productOffer->getProduct()->getId())){
  983.                 $has false;
  984.             }
  985.         }
  986.         return $has;
  987.     }
  988.     public function getFirstCourseIdFromProduct(Product $product)
  989.     {
  990.         $courses $product->getCourse();
  991.         foreach ($courses as $key => $course) {
  992.             return $course->getId();
  993.         }
  994.         return;
  995.     }
  996.     public function encodeHex($value)
  997.     {
  998.         $stringUtil $this->generalService->getUtil('StringUtil');
  999.         $hash $stringUtil->encodeHex($valuefalsefalse);
  1000.         return $hash;
  1001.     }
  1002.     public function getDefaultRecaptcha(){
  1003.         return $this->getConfiguration()->getDefaultRecaptcha();
  1004.     }
  1005.     public function getFields()
  1006.     {
  1007.         $fields = [];
  1008.         if($this->getConfiguration()->checkModuleIsAbleOnPlan('customFormModule')){
  1009.             $fields $this->em->getRepository(UserCustomField::class)->findBy([
  1010.                 "deleted" => UserCustomFieldEnum::ITEM_NO_DELETED,
  1011.                 "status" => UserCustomFieldEnum::PUBLISHED,
  1012.                 "showInRegister" => UserCustomFieldEnum::YES,
  1013.             ],
  1014.             [ "order" => "ASC" ]);
  1015.             foreach ($fields as $key => $field) {
  1016.                 
  1017.                 $field->optionsObj null;
  1018.                 
  1019.                 $options $field->getOptions();
  1020.                 if(!empty($options)){
  1021.                     $field->optionsObj json_decode($options);
  1022.                 }
  1023.                 $fields[$key] = $field;
  1024.             }
  1025.         }
  1026.         return $fields;
  1027.     }
  1028.     public function clearSocialUrl($slug$url)
  1029.     {
  1030.         $formats = [
  1031.             // WHATSAPP
  1032.             'whatsapp'  => 'https://api.whatsapp.com/send/?phone=%s',
  1033.             // LINKEDIN
  1034.             'linkedin'  => 'https://linkedin.com/%s',
  1035.             // YOUTUBE
  1036.             'youtube'   => 'https://www.youtube.com/%s',
  1037.             // PINTEREST
  1038.             'pinterest' => 'https://br.pinterest.com/%s',
  1039.             // INSTAGRAM
  1040.             'instagram' => 'https://www.instagram.com/%s/?hl=pt-br',
  1041.             // SNAPCHAT
  1042.             'snapchat'  => 'https://www.snapchat.com/add/%s',
  1043.             // FACEBOOK
  1044.             'facebook'  => 'https://www.facebook.com/%s',
  1045.             // TWITTER
  1046.             'twitter'   => 'https://twitter.com/%s',
  1047.             // SPOTIFY
  1048.             'spotify'   => 'https://open.spotify.com/show/%s',
  1049.             // TIKTOK
  1050.             'tiktok'   => 'https://tiktok.com/%s',
  1051.         ];
  1052.         // WHATSAPP
  1053.         if ($slug == 'whatsapp')
  1054.         {
  1055.             $url preg_replace("/[^0-9]/"""$url);
  1056.         }
  1057.         // NÃO whatsapp
  1058.         else
  1059.         {
  1060.             $url preg_replace('/^(.*)\?(.*)$/''$1'$url);
  1061.             $url trim($url'/');
  1062.             // LINKEDIN
  1063.             if ($slug == 'linkedin')
  1064.             {
  1065.                 $url preg_replace('/^(.*?)(((company|in)\/)?[^\/]*)$/''$2'$url);
  1066.             }
  1067.             // NÃO linkedin
  1068.             else
  1069.             {
  1070.                 $url preg_replace('/^(.*?)([^\/]*)$/''$2'$url);
  1071.             }
  1072.         }
  1073.         $url sprintf($formats[$slug], $url);
  1074.         return $url;
  1075.     }
  1076.     public function checkSection(string $sectionName)
  1077.     {
  1078.         $sectionConfigHome json_decode(
  1079.             $this->getConfiguration()->get('section_config_home')
  1080.         );
  1081.         if(isset($sectionConfigHome->{$sectionName})){
  1082.             if(isset($sectionConfigHome->{$sectionName}->active)){
  1083.                 return $sectionConfigHome->{$sectionName}->active == ClientEnum::YES;
  1084.             }
  1085.         }
  1086.         return false;
  1087.     }
  1088.     public function paintStars($score$halfStars true)
  1089.     {
  1090.         $score abs($score);
  1091.         $frac array_replace([falsefalse], explode('.'$score));
  1092.         $half = [];
  1093.         if ($halfStars && in_array($frac[1], range(59)))
  1094.         {
  1095.             $half = [$frac[0] => 'half'];
  1096.         }
  1097.         $base array_fill(05'off');
  1098.         $full array_fill(0floor($score), 'on');
  1099.         $paint array_replace($base$full$half);
  1100.         return $paint;
  1101.     }
  1102.     public function getCategoryOffers(){
  1103.         $categoryRepository $this->em->getRepository(Category::class);
  1104.         $productOfferRepository $this->em->getRepository(ProductOffer::class);
  1105.         $productCategories $categoryRepository->getCategories();
  1106.         $categoryOffers = [];
  1107.         foreach ($productCategories as $key => $category) {
  1108.             $category = (object)$category;
  1109.             $category->productOffers $productOfferRepository->getPublicProductOffers([
  1110.                 "category" => $category->getId(),
  1111.                 "limit" => 6
  1112.             ]);
  1113.             $categoryOffers[$key] = $category;
  1114.         }
  1115.         return $categoryOffers;
  1116.     }
  1117.     public function HEXtoRGB($hex)
  1118.     {
  1119.         return sscanf($hex"#%02x%02x%02x");
  1120.     }
  1121.     public function RGBtoHSL($r$g$b)
  1122.     {
  1123.         $oldR $r;
  1124.         $oldG $g;
  1125.         $oldB $b;
  1126.         $r /= 255;
  1127.         $g /= 255;
  1128.         $b /= 255;
  1129.         $max max($r$g$b);
  1130.         $min min($r$g$b);
  1131.         $h$s;
  1132.         $l = ($max $min) / 2;
  1133.         $d $max $min;
  1134.             if ($d == 0){
  1135.                 $h $s 0// achromatic
  1136.             } else {
  1137.                 $s $d / (abs($l 1));
  1138.                 switch($max){
  1139.                     case $r:
  1140.                         $h 60 fmod((($g $b) / $d), 6);
  1141.                         {
  1142.                             if ($b $g)
  1143.                             $h += 360;
  1144.                         }
  1145.                         break;
  1146.                     case $g:
  1147.                         $h 60 * (($b $r) / $d 2);
  1148.                         break;
  1149.                     case $b
  1150.                         $h 60 * (($r $g) / $d 4);
  1151.                         break;
  1152.                 }                               
  1153.         }
  1154.         return [round($h2), round($s2), round($l2)];
  1155.     }
  1156.     public function HEXtoHSL($hex)
  1157.     {
  1158.         list($r$g$b) = $this->HEXtoRGB($hex);
  1159.         return $this->RGBtoHSL($r$g$b);
  1160.     }
  1161.     public function setValue(string $key$value null)
  1162.     {
  1163.         $this->arrValue[$key] = $value;
  1164.         return;
  1165.     }
  1166.     public function getValue(string $key)
  1167.     {
  1168.         return (isset($this->arrValue[$key]) ? $this->arrValue[$key] : null);
  1169.     }
  1170.     public function pageSectionFormat(int $formatType)
  1171.     {
  1172.         $formats = [
  1173.             PageSectionEnum::BOX_DEFAULT => "default",
  1174.             PageSectionEnum::BOX_EXPAND => "expand",
  1175.             PageSectionEnum::BOX_STAND => "stand",
  1176.             PageSectionEnum::BOX_ROUND => "round",
  1177.         ];
  1178.         return (!empty($formats[$formatType]) ? $formats[$formatType] : "default");
  1179.     }
  1180.     public function pageSectionPosition(int $position)
  1181.     {
  1182.         $positions = [
  1183.             PageSectionEnum::LEFT => "left",
  1184.             PageSectionEnum::CENTER => "center",
  1185.             PageSectionEnum::RIGHT => "right",
  1186.         ];
  1187.         return (!empty($positions[$position]) ? $positions[$position] : "center");
  1188.     }
  1189.     public function pageSectionTemplateItem(PageSection $pageSection)
  1190.     {
  1191.         $typeItem $pageSection->getTypeItem();
  1192.         $type $pageSection->getTypeItem();
  1193.         $productType = [
  1194.             PageSectionEnum::ALL_PRODUCT,
  1195.             PageSectionEnum::PRODUCT_SPOTLIGHT,
  1196.             PageSectionEnum::PRODUCT_SUGGESTION,
  1197.             PageSectionEnum::PRODUCT_COURSE,
  1198.             PageSectionEnum::PRODUCT_SUBSCRIPTION,
  1199.             PageSectionEnum::PRODUCT_COMBO,
  1200.             PageSectionEnum::PRODUCT_LIVE,
  1201.             PageSectionEnum::PRODUCT_BY_CATEGORY,
  1202.             PageSectionEnum::PRODUCT_WISHLIST,
  1203.         ];
  1204.         $slug_format = [
  1205.             'default' => '-default',
  1206.             // 'expand'  => '-spotlight',
  1207.             'expand'  => '-expand',
  1208.             'stand'   => '-stand',
  1209.             'round'   => '-round',
  1210.         ];
  1211.         $slug $slug_format[$this->pageSectionFormat($pageSection->getType())];
  1212.         $template null;
  1213.         if(in_array($typeItem$productType)){
  1214.             $template "website/product/product-item-box{$slug}.html.twig";
  1215.         }else if($typeItem == PageSectionEnum::COURSE_STARTED){
  1216.             $template "website/course/course-item-box{$slug}-home.html.twig";
  1217.         }
  1218.         return $template;
  1219.     }
  1220.     public function pageSectionItems(PageSection $pageSection)
  1221.     {
  1222.         $typeItem $pageSection->getTypeItem();
  1223.         $allItem $pageSection->getAllItem() == PageSectionEnum::YES;
  1224.         $item json_decode($pageSection->getItem());
  1225.         $orderItem $pageSection->getOrderItem();
  1226.         $limit $pageSection->getNumberOfLine() * $pageSection->getNumberPerLine();
  1227.         $items = [];
  1228.         $productType = [
  1229.             PageSectionEnum::ALL_PRODUCT,
  1230.             PageSectionEnum::PRODUCT_SPOTLIGHT,
  1231.             PageSectionEnum::PRODUCT_SUGGESTION,
  1232.             PageSectionEnum::PRODUCT_COURSE,
  1233.             PageSectionEnum::PRODUCT_SUBSCRIPTION,
  1234.             PageSectionEnum::PRODUCT_COMBO,
  1235.             PageSectionEnum::PRODUCT_LIVE,
  1236.             PageSectionEnum::PRODUCT_BY_CATEGORY,
  1237.             PageSectionEnum::PRODUCT_WISHLIST,
  1238.         ];
  1239.         //CATEGORY,
  1240.         //TEACHER,
  1241.         //FAQ,
  1242.         //TESTIMONIAL
  1243.         if(in_array($typeItem$productType)){
  1244.             if($typeItem == PageSectionEnum::PRODUCT_WISHLIST && !$this->user){
  1245.                 return [];
  1246.             }
  1247.             $productIds = (
  1248.                 !$allItem && !empty($item) && is_array($item) ? 
  1249.                 $item 
  1250.                 null
  1251.             );
  1252.             $productRepository $this->em->getRepository(Product::class);
  1253.             if(empty($productIds) && $typeItem == PageSectionEnum::PRODUCT_SUGGESTION){
  1254.                 $productIds $productRepository->getProductsInCache();
  1255.             }
  1256.             $typeOriginal = [
  1257.                 PageSectionEnum::PRODUCT_COURSE => ProductEnum::COURSE,
  1258.                 PageSectionEnum::PRODUCT_SUBSCRIPTION => ProductEnum::SUBSCRIPTION,
  1259.                 PageSectionEnum::PRODUCT_COMBO => ProductEnum::COMBO,
  1260.                 PageSectionEnum::PRODUCT_LIVE => ProductEnum::LIVE,
  1261.             ];
  1262.             $productOfferRepository $this->em->getRepository(ProductOffer::class);
  1263.             $items $productOfferRepository->getPublicProductOffersNew([
  1264.                 "type" => (
  1265.                     isset($typeOriginal[$typeItem]) ? 
  1266.                     $typeOriginal[$typeItem] : 
  1267.                     null
  1268.                 ),
  1269.                 "category" => (
  1270.                     $typeItem == PageSectionEnum::PRODUCT_BY_CATEGORY && 
  1271.                     $pageSection->getCategory() ? 
  1272.                     $pageSection->getCategory()->getId() : 
  1273.                     null
  1274.                 ),
  1275.                 "limit" => $limit,
  1276.                 "spotlight" => (
  1277.                     $typeItem == PageSectionEnum::PRODUCT_SPOTLIGHT 
  1278.                     PageSectionEnum::YES 
  1279.                     PageSectionEnum::NO
  1280.                 ),
  1281.                 "wishlist" => (
  1282.                     $typeItem == PageSectionEnum::PRODUCT_WISHLIST 
  1283.                     PageSectionEnum::YES 
  1284.                     PageSectionEnum::NO
  1285.                 ),
  1286.                 "order" => $pageSection->getOrderItem(),
  1287.                 "productIds" => $productIds,
  1288.             ]);
  1289.             $user $this->getUser();
  1290.             if($user && $pageSection->getShowEnrollment() == PageSectionEnum::NO){
  1291.                 $aux = [];
  1292.                 foreach ($items as $key => $offer) {
  1293.                     if(!$productRepository->userHasProduct($user$offer->getProduct())){
  1294.                         $aux[] = $offer;
  1295.                     }
  1296.                 }
  1297.                 $items =  $aux;
  1298.             }
  1299.         }else if($typeItem == PageSectionEnum::COURSE_STARTED && $this->getUser()){
  1300.             $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1301.             $enrollments $enrollmentRepository->getResumeEnrollment(
  1302.                 $this->getUser()->getId(),
  1303.                 [ EnrollmentEnum::SITUATION_STARTED ],
  1304.                 null,
  1305.                 null,
  1306.                 null,
  1307.                 null,
  1308.                 $limit
  1309.             );
  1310.             foreach ($enrollments as $key => $enrollment) {
  1311.                 $items[] = $enrollment->getCourse();
  1312.             }
  1313.         }
  1314.         return $items;
  1315.     }
  1316.     public function pageSectionLinkAll(PageSection $pageSection)
  1317.     {
  1318.         $typeItem $pageSection->getTypeItem();
  1319.         $category $pageSection->getCategory();
  1320.         $categoryLink "/products";
  1321.         if($typeItem == PageSectionEnum::PRODUCT_BY_CATEGORY && $category){
  1322.             $categoryLink "/products/{$category->getSlug()}";
  1323.         }
  1324.         $links = [
  1325.             PageSectionEnum::ALL_PRODUCT          => '/products',
  1326.             PageSectionEnum::PRODUCT_SPOTLIGHT    => '/products',
  1327.             PageSectionEnum::PRODUCT_SUGGESTION   => '/products',
  1328.             PageSectionEnum::PRODUCT_COURSE       => '/courses',
  1329.             PageSectionEnum::PRODUCT_SUBSCRIPTION => '/plans',
  1330.             PageSectionEnum::PRODUCT_COMBO        => '/combos',
  1331.             PageSectionEnum::PRODUCT_LIVE         => '/lives',
  1332.             PageSectionEnum::PRODUCT_BY_CATEGORY  => $categoryLink,
  1333.             PageSectionEnum::PRODUCT_WISHLIST     => '/wishlist',
  1334.             PageSectionEnum::COURSE_STARTED       => '/resume',
  1335.         ];
  1336.         return isset($links[$typeItem]) ? $links[$typeItem] : "/";
  1337.     }
  1338.     public function isPageSection($pageSection) {
  1339.         return  $pageSection instanceof PageSection;
  1340.     }
  1341.     public function pageSectionShowAll(PageSection $pageSection)
  1342.     {
  1343.         $typeItem $pageSection->getTypeItem();
  1344.         $allItem $pageSection->getAllItem() == PageSectionEnum::YES;
  1345.         $item json_decode($pageSection->getItem());
  1346.         $limit $pageSection->getNumberOfLine() * $pageSection->getNumberPerLine();
  1347.         $items = [];
  1348.         $productType = [
  1349.             PageSectionEnum::ALL_PRODUCT,
  1350.             PageSectionEnum::PRODUCT_SPOTLIGHT,
  1351.             PageSectionEnum::PRODUCT_SUGGESTION,
  1352.             PageSectionEnum::PRODUCT_COURSE,
  1353.             PageSectionEnum::PRODUCT_SUBSCRIPTION,
  1354.             PageSectionEnum::PRODUCT_COMBO,
  1355.             PageSectionEnum::PRODUCT_LIVE,
  1356.             PageSectionEnum::PRODUCT_BY_CATEGORY,
  1357.             PageSectionEnum::PRODUCT_WISHLIST,
  1358.         ];
  1359.         //CATEGORY,
  1360.         //TEACHER,
  1361.         //FAQ,
  1362.         //TESTIMONIAL
  1363.         if(in_array($typeItem$productType)){
  1364.             if($typeItem == PageSectionEnum::PRODUCT_WISHLIST && !$this->user){
  1365.                 return [];
  1366.             }
  1367.             $productIds = (
  1368.                 !$allItem && !empty($item) && is_array($item) ? 
  1369.                 $item 
  1370.                 null
  1371.             );
  1372.             $productRepository $this->em->getRepository(Product::class);
  1373.             if(empty($productIds) && $typeItem == PageSectionEnum::PRODUCT_SUGGESTION){
  1374.                 $productIds $productRepository->getProductsInCache();
  1375.             }
  1376.             $typeOriginal = [
  1377.                 PageSectionEnum::PRODUCT_COURSE => ProductEnum::COURSE,
  1378.                 PageSectionEnum::PRODUCT_SUBSCRIPTION => ProductEnum::SUBSCRIPTION,
  1379.                 PageSectionEnum::PRODUCT_COMBO => ProductEnum::COMBO,
  1380.                 PageSectionEnum::PRODUCT_LIVE => ProductEnum::LIVE,
  1381.             ];
  1382.             $productOfferRepository $this->em->getRepository(ProductOffer::class);
  1383.             $total $productOfferRepository->countPublicProductOffersNew([
  1384.                 "type" => (
  1385.                     isset($typeOriginal[$typeItem]) ? 
  1386.                     $typeOriginal[$typeItem] : 
  1387.                     null
  1388.                 ),
  1389.                 "category" => (
  1390.                     $typeItem == PageSectionEnum::PRODUCT_BY_CATEGORY && 
  1391.                     $pageSection->getCategory() ? 
  1392.                     $pageSection->getCategory()->getId() : 
  1393.                     null
  1394.                 ),
  1395.                 "spotlight" => (
  1396.                     $typeItem == PageSectionEnum::PRODUCT_SPOTLIGHT 
  1397.                     PageSectionEnum::YES 
  1398.                     PageSectionEnum::NO
  1399.                 ),
  1400.                 "wishlist" => (
  1401.                     $typeItem == PageSectionEnum::PRODUCT_WISHLIST 
  1402.                     PageSectionEnum::YES 
  1403.                     PageSectionEnum::NO
  1404.                 ),
  1405.                 "productIds" => $productIds,
  1406.             ]);
  1407.             return ($total $limit);
  1408.         }else if($typeItem == PageSectionEnum::COURSE_STARTED && $this->getUser()){
  1409.             return true;
  1410.         }
  1411.         return false;
  1412.     }
  1413.     public function getPlanCycleString(int $cycleOption){
  1414.         return $this->em->getRepository(UserSubscription::class)->getPlanCycleString(
  1415.             $cycleOption
  1416.         );
  1417.     }
  1418.     public function getPlanCycleStringProductDetail(int $cycleOption){
  1419.         return $this->em->getRepository(UserSubscription::class)->getPlanCycleStringProductDetail(
  1420.             $cycleOption
  1421.         );
  1422.     }
  1423.     public function getDocumentFormat(int $document){
  1424.         $cnpj_cpf preg_replace("/\D/"''$document);
  1425.   
  1426.         if (strlen($cnpj_cpf) === 11) {
  1427.           return preg_replace("/(\d{3})(\d{3})(\d{3})(\d{2})/""\$1.\$2.\$3-\$4"$cnpj_cpf);
  1428.         } 
  1429.         
  1430.         return preg_replace("/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/""\$1.\$2.\$3/\$4-\$5"$cnpj_cpf);
  1431.     }
  1432.   
  1433.     public function getUserSubscriptionError($errorMessage){
  1434.         $errorMessage explode("MESSAGE: "$errorMessage);
  1435.         return $errorMessage[1];
  1436.     }
  1437.     public function getVimeoFormatIframe(string $link){
  1438.         $url null;
  1439.         if(strpos($link'/manage/videos')){
  1440.             $url str_replace('/manage/videos'''$link);
  1441.         }
  1442.         
  1443.         return $url;
  1444.     }
  1445.     public function isValidCard($dateExpire)
  1446.     {
  1447.         $y = (int)date('y');
  1448.         $m = (int)date('m');
  1449.         $expire explode('/'$dateExpire);
  1450.         $ySave = (int)$expire[1];
  1451.         $mSave = (int)$expire[0];
  1452.         if($y $ySave || ($y == $ySave && $m >= $mSave)){
  1453.             return false;
  1454.         }
  1455.         return true;
  1456.     }
  1457.     public function stringOrigin($origin)
  1458.     {
  1459.         $string '';
  1460.         switch ($origin) {
  1461.             case EnrollmentEnum::ORIGIN_FREE:
  1462.                 $string $this->getConfiguration()->getLanguage(
  1463.                     'free''enrollments'
  1464.                 );
  1465.             break;
  1466.             case EnrollmentEnum::ORIGIN_SALE:
  1467.                 $string $this->getConfiguration()->getLanguage(
  1468.                     'sale''enrollments'
  1469.                 );
  1470.             break;
  1471.             case EnrollmentEnum::ORIGIN_SUBSCRIPTION:
  1472.                 $string $this->getConfiguration()->getLanguage(
  1473.                     'subscription''enrollments'
  1474.                 );
  1475.             break;
  1476.             case EnrollmentEnum::ORIGIN_GROUP:
  1477.                 $string $this->getConfiguration()->getLanguage(
  1478.                     'group''enrollments'
  1479.                 );
  1480.             break;
  1481.             case EnrollmentEnum::ORIGIN_COUPOM:
  1482.                 $string $this->getConfiguration()->getLanguage(
  1483.                     'coupom''enrollments'
  1484.                 );
  1485.             break;
  1486.             case EnrollmentEnum::ORIGIN_API:
  1487.                 $string 'Api';
  1488.             break;
  1489.             case EnrollmentEnum::ORIGIN_CHARGE:
  1490.                 $string $this->getConfiguration()->getLanguage(
  1491.                     'charge''enrollments'
  1492.                 );
  1493.             break;
  1494.         }
  1495.         return $string;
  1496.     }
  1497.     public function stringStatus(Enrollment $enrollment)
  1498.     {
  1499.         $string '';
  1500.         switch ($enrollment->getStatus()) {
  1501.             case EnrollmentEnum::STATUS_ACTIVE:
  1502.                 if(strtotime($enrollment->getDatePeriod('Y-m-d')) < strtotime(date('Y-m-d'))){
  1503.                     $string $this->getConfiguration()->getLanguage(
  1504.                         'expired''enrollments'
  1505.                     ); 
  1506.                 }else{
  1507.                     $string $this->getConfiguration()->getLanguage(
  1508.                         'active''enrollments'
  1509.                     ); 
  1510.                 }
  1511.             break;
  1512.             case EnrollmentEnum::STATUS_SUSPENDED:
  1513.                 $string $this->getConfiguration()->getLanguage(
  1514.                     'suspended''enrollments'
  1515.                 ); 
  1516.             break;
  1517.             case EnrollmentEnum::STATUS_CANCELED:
  1518.                 $string $this->getConfiguration()->getLanguage(
  1519.                     'canceled''enrollments'
  1520.                 );
  1521.             break;
  1522.         }
  1523.         return $string;
  1524.     }
  1525. }