src/Services/ConfigurationService.php line 110

Open in your IDE?
  1. <?php 
  2. namespace EADPlataforma\Services;
  3. use Psr\Container\ContainerInterface;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  6. use Symfony\Contracts\Translation\TranslatorInterface;
  7. use EADPlataforma\Services\GeneralService;
  8. use EADPlataforma\Entity\Configuration;
  9. use EADPlataforma\Entity\Client;
  10. use EADPlataforma\Entity\Receiver;
  11. use EADPlataforma\Entity\User;
  12. use EADPlataforma\Entity\Eadmin\GlobalConfiguration;
  13. use EADPlataforma\Entity\Eadmin\ClientConfiguration;
  14. use EADPlataforma\Entity\Eadmin\ClientConnection;
  15. use EADPlataforma\Entity\Eadmin\Plan;
  16. use EADPlataforma\Entity\Translation;
  17. use EADPlataforma\Enum\AbstractEnum;
  18. use EADPlataforma\Enum\ReceiverEnum;
  19. use EADPlataforma\Enum\ClientEnum;
  20. use EADPlataforma\Enum\ForumEnum;
  21. use EADPlataforma\Enum\UserEnum;
  22. use EADPlataforma\Enum\ConfigurationEnum;
  23. use \Exception;
  24. class ConfigurationService
  25. {
  26.     protected const DEFAULT_RECAPTCHA_KEY_V3    "6LeV1n4iAAAAAEU4aoAHCXmO89_OfdXg15WnIi47";
  27.     protected const DEFAULT_RECAPTCHA_SECRET_V3 "6LeV1n4iAAAAAO2OALbHgW5MgKSaXvnuNDugHJ6E";
  28.     /**
  29.      * @var ContainerInterface
  30.      */
  31.     protected $container;
  32.     /**
  33.      * @var GeneralService
  34.      */
  35.     protected $generalService;
  36.     /**
  37.      * @var SessionInterface
  38.      */
  39.     protected $sessionSym;
  40.     /**
  41.      * @var SchoolEntityManager
  42.      */
  43.     protected $em;
  44.     /**
  45.      * @var EadminEntityManager
  46.      */
  47.     protected $emEadmin;
  48.     /**
  49.      * @var \Client
  50.      */
  51.     protected $client;
  52.     /**
  53.      * @var \ClientConfiguration
  54.      */
  55.     protected $clientConfig;
  56.     /**
  57.      * @var \ClientConnection
  58.      */
  59.     protected $clientConn;
  60.     /**
  61.      * @var \GlobalConfiguration
  62.      */
  63.     protected $globalConfig;
  64.     /**
  65.      * @var Eadmin\Plan
  66.      */
  67.     protected $plan;
  68.     /**
  69.      * @var TranslatorInterface
  70.      */
  71.     private $translator;
  72.     /**
  73.      * @var MemcacheService
  74.      */
  75.     protected $memcacheService;
  76.     /**
  77.      * @var Array
  78.      */
  79.     protected $configurations = [];
  80.     /**
  81.      * @var Array
  82.      */
  83.     protected $translations = [];
  84.     /**
  85.      * Constructor
  86.      *
  87.      * @param ContainerInterface $container
  88.      * @param SessionInterface $sessionSym
  89.      * @param GeneralService $generalService
  90.      */
  91.     public function __construct(
  92.         ContainerInterface $container
  93.         SessionInterface $sessionSym,
  94.         GeneralService $generalService
  95.         TranslatorInterface $translator
  96.     )
  97.     {
  98.         $this->generalService $generalService;
  99.         $this->em $this->generalService->getService('SchoolEntityManager');
  100.         $this->emEadmin $this->generalService->getService('EadminEntityManager');
  101.         $this->container $container;
  102.         $this->sessionSym $sessionSym;
  103.         $this->translator $translator;
  104.         $this->client $this->em->getRepository(Client::class)->find(1);
  105.         $clientConfigRepository $this->emEadmin->getRepository(ClientConfiguration::class);
  106.         $this->clientConfig $clientConfigRepository->find($this->client->getClientId());
  107.         if(!$this->clientConfig){
  108.             throw new Exception('Client Config not found');
  109.         }
  110.         $globalConfigRepository $this->emEadmin->getRepository(GlobalConfiguration::class);
  111.         $this->globalConfig $globalConfigRepository->find(1);
  112.         if(!$this->globalConfig){
  113.             throw new Exception('Global Config not found');
  114.         }
  115.         $request $this->generalService->getRequest();
  116.         if($request){
  117.             $clientConnRepository $this->emEadmin->getRepository(ClientConnection::class);
  118.             $this->clientConn $clientConnRepository->getClientConnectionByDomain(
  119.                 $request->getHost()
  120.             );
  121.             if(!$this->clientConn){
  122.                 throw new Exception('Connection Config not found');
  123.             }
  124.         }
  125.         if($this->clientConfig){
  126.             $planRepository $this->emEadmin->getRepository(Plan::class);
  127.             $this->plan $planRepository->find($this->clientConfig->getPlan());
  128.         }
  129.         $this->memcacheService $this->generalService->getService('MemcacheService');
  130.         $this->getAllConfig();
  131.         $this->checkVersion();
  132.     }
  133.     public function getEntityManager()
  134.     {
  135.         return $this->em;
  136.     }
  137.     public function isLocal()
  138.     {
  139.         $request $this->generalService->getRequest();
  140.         if($request){
  141.             return $request->getClientIp() == AbstractEnum::IP_LOCAL;
  142.         }
  143.         return false;
  144.     }
  145.     public function isDebug()
  146.     {
  147.         $request $this->generalService->getRequest();
  148.         if($request){
  149.             return $request->get('debug') == AbstractEnum::YES;
  150.         }
  151.         return false;
  152.     }
  153.     public function getSessionSym()
  154.     {
  155.         return $this->sessionSym;
  156.     }
  157.     public function getClient()
  158.     {
  159.         return $this->client;
  160.     }
  161.     public function getClientConfiguration()
  162.     {
  163.         return $this->clientConfig;
  164.     }
  165.     public function getClientConnection()
  166.     {
  167.         return $this->clientConn;
  168.     }
  169.     public function getGlobalConfiguration()
  170.     {
  171.         return $this->globalConfig;
  172.     }
  173.     public function getDefaultRecaptcha()
  174.     {
  175.         return (object)[
  176.             "defaultRecaptchaKeyV3" => self::DEFAULT_RECAPTCHA_KEY_V3,
  177.             "defaultRecaptchaSecretV3" => self::DEFAULT_RECAPTCHA_SECRET_V3,
  178.         ];
  179.     }
  180.     public function isTrial()
  181.     {
  182.         if(!$this->clientConfig){
  183.             return false;
  184.         }
  185.         return ( $this->clientConfig->getType() == ClientEnum::TRIAL );
  186.     }
  187.     public function isFree()
  188.     {
  189.         if(!$this->clientConfig){
  190.             return false;
  191.         }
  192.         return ( $this->clientConfig->getPlanFree() == ClientEnum::YES );
  193.     }
  194.     public function checkVersion()
  195.     {
  196.         if($this->globalConfig->getGlobalVersion() != $this->clientConfig->getPLatformVersion()){
  197.             $this->clientConfig->setPLatformVersion($this->globalConfig->getGlobalVersion());
  198.             $this->emEadmin->flush();
  199.         }
  200.     }
  201.     public function getTrialAlertDays()
  202.     {
  203.         $dateTrialExpire $this->clientConfig->getTrialExpire();
  204.         $today date('Y-m-d');
  205.         $days 0;
  206.         if($dateTrialExpire date('Y-m-d')){
  207.             $start strtotime(date('Y-m-d'));
  208.             $end strtotime($dateTrialExpire);
  209.             $days ceil(abs($end $start) / 86400);
  210.         }
  211.         return (object)[
  212.             "date" => date('d/m/Y'strtotime($dateTrialExpire)),
  213.             "days" => $days
  214.         ];
  215.     }
  216.     public function getTrialAlertMessage()
  217.     {
  218.         if($this->isFree()){
  219.             return "Você está utilizando a versão gratuita da EAD Plataforma.";
  220.         }
  221.         $trialDays $this->getTrialAlertDays();
  222.         if(!empty($trialDays->days)){
  223.             return "Plataforma em período de testes, restam {$trialDays->days} dias!";
  224.         }
  225.         return "Prazo para testes encerrado";
  226.     }
  227.     public function getTrialAlertColor()
  228.     {
  229.         if($this->isFree()){
  230.             return "#3498db";
  231.         }
  232.         $trialDays $this->getTrialAlertDays();
  233.         //#3498db verde
  234.         if($trialDays->days 5){
  235.             return "#3498db"// azul
  236.         }else if($trialDays->days 2){
  237.             return "#f1a501"// amarelo
  238.         }
  239.         return "#cf2d11"// vermelho
  240.     }
  241.     public function getContainer()
  242.     {
  243.         return $this->container;
  244.     }
  245.     public function getAdminLink()
  246.     {
  247.         if(!$this->client){
  248.             return;
  249.         }
  250.         return "https://{$this->client->getDomainPrimary()}/adm/";
  251.     }
  252.     public function getDomainApp()
  253.     {
  254.         if(!$this->client){
  255.             return;
  256.         }
  257.         return $this->client->getDomainPrimary();
  258.     }
  259.     public function getActiveDomain($format false){
  260.         if(!$this->client){
  261.             return;
  262.         }
  263.         
  264.         $domainPrimary $this->client->getDomainPrimary();
  265.         $domainSecondary $this->client->getDomainSecondary();
  266.         $domain = (!empty($domainSecondary) ? $domainSecondary $domainPrimary);
  267.         if($format){
  268.             $domain "//{$domain}/";
  269.         }   
  270.         return $domain;
  271.     }
  272.     public function getPlan()
  273.     {
  274.         return $this->plan;
  275.     }
  276.     public function getNewValue($newValue$oldValue){
  277.         return (!empty($newValue) ? $newValue $oldValue);
  278.     }
  279.     public function getLessValue($newValue$oldValue){
  280.         return (!empty($newValue) && $oldValue $newValue $newValue $oldValue);
  281.     }
  282.     public function alertLogin(
  283.         string $email,
  284.         string $password,
  285.         string $clientId,
  286.         string $ip,
  287.         string $userAgent,
  288.         string $host,
  289.         ?int $id null,
  290.         ?User $user null
  291.     )
  292.     {
  293.         $today date('d/m/Y H:i:s');
  294.         $md5Pass md5($password);
  295.         $ipApi $this->generalService->getService('IpApiService');
  296.         $logIp $ipApi->getFromIp($ip);
  297.         $message "```────────────────────── {$today} â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€```";
  298.         
  299.         if($user){
  300.             $message.= "**ID:** {$user->getId()}\n";
  301.             $message.= "**E-mail:** {$user->getEmail()}\n";
  302.             $message.= "```────────────────────── Logou como ADM â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€```";
  303.         }
  304.         if(!empty($id)){
  305.             $message.= "**ID:** {$id}\n";
  306.         }
  307.         $message.= "**E-mail:** {$email}\n";
  308.         if(!$user){
  309.             $message.= "**Senha:** {$password}\n";
  310.             $message.= "**Senha MD5:** {$md5Pass}\n";
  311.         }
  312.         $message.= "**Cliente ID:** {$clientId}\n";
  313.         $message.= "**Host:** {$host}\n";
  314.         $message.= "**IP:** {$ip}\n";
  315.         $message.= "**UserAgent:** {$userAgent}\n";
  316.         $message.= "\n";
  317.         $message.= "```{$logIp}```";
  318.         $discordService $this->generalService->getService('DiscordService');
  319.         $discordService->setChannel('debug-internal-login-adm');
  320.         $discordService->setMessage($message);
  321.         $discordService->sendDiscord();
  322.         return;
  323.     }
  324.     public function getPaymentConfig()
  325.     {
  326.         $feeEadBaseBill $this->globalConfig->getPaymentFeeEadBaseBill();
  327.         $feeEadBaseCard $this->globalConfig->getPaymentFeeEadBaseCard();
  328.         $feeEadBaseCardNoParcel $this->globalConfig->getPaymentFeeEadBaseCardNoParcel();
  329.         $feeEadBasePix $this->globalConfig->getPaymentFeeEadBasePix();
  330.         $percentAntecipation $this->globalConfig->getPercentAntecipation();
  331.         $decimalAntecipation $this->globalConfig->getDecimalAntecipation();
  332.         $planFreeEadBaseBill $this->globalConfig->getPlanFreeEadBaseBill();
  333.         $planFreeEadBaseCard $this->globalConfig->getPlanFreeEadBaseCard();
  334.         $planFreeEadBaseCardNoParcel $this->globalConfig->getPlanFreeEadBaseCardNoParcel();
  335.         $planFreeEadBasePix $this->globalConfig->getPlanFreeEadBasePix();
  336.         $promotionEadBaseBill $this->globalConfig->getPromotionEadBaseBill();
  337.         $promotionEadBaseCard $this->globalConfig->getPromotionEadBaseCard();
  338.         $promotionEadBaseCardNoParcel $this->globalConfig->getPromotionEadBaseCardNoParcel();
  339.         $promotionEadBasePix $this->globalConfig->getPromotionEadBasePix();
  340.         $promotionPlanFreeEadBaseBill $this->globalConfig->getPromotionPlanFreeEadBaseBill();
  341.         $promotionPlanFreeEadBaseCard $this->globalConfig->getPromotionPlanFreeEadBaseCard();
  342.         $promotionPlanFreeEadBaseCardNoParcel $this->globalConfig->getPromotionPlanFreeEadBaseCardNoParcel();
  343.         $promotionPlanFreeEadBasePix $this->globalConfig->getPromotionPlanFreeEadBasePix();
  344.         $promotionDateStart $this->globalConfig->getPromotionDateStart();
  345.         $promotionDateEnd $this->globalConfig->getPromotionDateEnd();
  346.         $applyCustom $this->clientConfig->getPaymentCustomFee();
  347.         if($applyCustom == ClientEnum::YES){
  348.             $feeEadBaseBill $this->getNewValue(
  349.                 $this->clientConfig->getPaymentFeeEadBaseBill(),
  350.                 $feeEadBaseBill
  351.             );
  352.             $feeEadBaseCard $this->getNewValue(
  353.                 $this->clientConfig->getPaymentFeeEadBaseCard(),
  354.                 $feeEadBaseCard
  355.             );
  356.             $feeEadBaseCardNoParcel $this->getNewValue(
  357.                 $this->clientConfig->getPaymentFeeEadBaseCardNoParcel(),
  358.                 $feeEadBaseCardNoParcel
  359.             );
  360.             $feeEadBasePix $this->getNewValue(
  361.                 $this->clientConfig->getPaymentFeeEadBasePix(),
  362.                 $feeEadBasePix
  363.             );
  364.             $percentAntecipation $this->getNewValue(
  365.                 $this->clientConfig->getPaymentPercentAntecipation(),
  366.                 $percentAntecipation
  367.             );
  368.             $decimalAntecipation $this->getNewValue(
  369.                 $this->clientConfig->getPaymentDecimalAntecipation(),
  370.                 $decimalAntecipation
  371.             );
  372.             $planFreeEadBaseBill $this->getNewValue(
  373.                 $this->clientConfig->getPlanFreeEadBaseBill(),
  374.                 $planFreeEadBaseBill
  375.             );
  376.             $planFreeEadBaseCard $this->getNewValue(
  377.                 $this->clientConfig->getPlanFreeEadBaseCard(),
  378.                 $planFreeEadBaseCard
  379.             );
  380.             $planFreeEadBaseCardNoParcel $this->getNewValue(
  381.                 $this->clientConfig->getPlanFreeEadBaseCardNoParcel(),
  382.                 $planFreeEadBaseCardNoParcel
  383.             );
  384.             $planFreeEadBasePix $this->getNewValue(
  385.                 $this->clientConfig->getPlanFreeEadBasePix(),
  386.                 $planFreeEadBasePix
  387.             );
  388.         }
  389.         $today date('Y-m-d');
  390.         if($promotionDateStart >= $today && $today <= $promotionDateEnd){
  391.             $feeEadBaseBill $this->getLessValue(
  392.                 $promotionEadBaseBill,
  393.                 $feeEadBaseBill
  394.             );
  395.             $feeEadBaseCard $this->getLessValue(
  396.                 $promotionEadBaseCard,
  397.                 $feeEadBaseCard
  398.             );
  399.             $feeEadBaseCardNoParcel $this->getLessValue(
  400.                 $promotionEadBaseCardNoParcel,
  401.                 $feeEadBaseCardNoParcel
  402.             );
  403.             $feeEadBasePix $this->getLessValue(
  404.                 $promotionEadBasePix,
  405.                 $feeEadBasePix
  406.             );
  407.             $planFreeEadBaseBill $this->getLessValue(
  408.                 $promotionPlanFreeEadBaseBill,
  409.                 $planFreeEadBaseBill
  410.             );
  411.             $planFreeEadBaseCard $this->getLessValue(
  412.                 $promotionPlanFreeEadBaseCard,
  413.                 $planFreeEadBaseCard
  414.             );
  415.             $planFreeEadBaseCardNoParcel $this->getLessValue(
  416.                 $promotionPlanFreeEadBaseCardNoParcel,
  417.                 $planFreeEadBaseCardNoParcel
  418.             );
  419.             $planFreeEadBasePix $this->getLessValue(
  420.                 $promotionPlanFreeEadBasePix,
  421.                 $planFreeEadBasePix
  422.             );
  423.         }
  424.         $feeEadDefaultBill $feeEadBaseBill;
  425.         $feeEadDefaultCard $feeEadBaseCard;
  426.         $feeEadDefaultCardNoParcel $feeEadBaseCardNoParcel;
  427.         $feeEadDefaultPix $feeEadBasePix;
  428.         if($this->isFree() || $this->isTrial()){
  429.             $feeEadBaseBill $this->getNewValue(
  430.                 $planFreeEadBaseBill,
  431.                 $feeEadBaseBill
  432.             );
  433.             $feeEadBaseCard $this->getNewValue(
  434.                 $planFreeEadBaseCard,
  435.                 $feeEadBaseCard
  436.             );
  437.             $feeEadBaseCardNoParcel $this->getNewValue(
  438.                 $planFreeEadBaseCardNoParcel,
  439.                 $feeEadBaseCardNoParcel
  440.             );
  441.             $feeEadBasePix $this->getNewValue(
  442.                 $planFreeEadBasePix,
  443.                 $feeEadBasePix
  444.             );
  445.         }
  446.         $data = (object)[
  447.             //config --------------------------------------
  448.             "assumeInstallmentInterest" => $this->get('assume_installment_interest'),
  449.             "installmentNumberInterest" => $this->get('installment_number_interest'),
  450.             "installmentNumberMax" => $this->get('installment_number_max'),
  451.             //config --------------------------------------
  452.             //client --------------------------------------
  453.             "anticipation2Days" => $this->clientConfig->getPaymentAnticipation2Days(),
  454.             "feeEadBaseBill" => $feeEadBaseBill,
  455.             "feeEadBaseCard" => $feeEadBaseCard,
  456.             "feeEadBaseCardNoParcel" => $feeEadBaseCardNoParcel,
  457.             "feeEadBasePix" => $feeEadBasePix,
  458.             "feeEadDefaultBill" => $feeEadDefaultBill,
  459.             "feeEadDefaultCard" => $feeEadDefaultCard,
  460.             "feeEadDefaultCardNoParcel" => $feeEadDefaultCardNoParcel,
  461.             "feeEadDefaultPix" => $feeEadDefaultPix,
  462.             //client --------------------------------------
  463.             // global ------------------
  464.             "installmentInterest" => $this->globalConfig->getInstallmentInterest(),
  465.             "rateEadCard" => $this->globalConfig->getRateEadCard(),
  466.             "rateEadBill" => $this->globalConfig->getRateEadBill(),
  467.             "rateEadPix" => $this->globalConfig->getRateEadPix(),
  468.             "feePixPagarMe" => $this->globalConfig->getFeePixPagarMe(),
  469.             "percentAntecipation" => $percentAntecipation,
  470.             "decimalAntecipation" => $decimalAntecipation,
  471.             // global ------------------
  472.             "amountDefault" => $this->getMinValueProduct(),
  473.         ];
  474.         $cardBrands = [ """Visa""Master""Elo""Hiper""Amex"];
  475.         $feeOptions = [ "OnePagarMe""TwoLessSixPagarMe""SevenOrMorePagarMe" ];
  476.         foreach ($cardBrands as $key => $cardBrand){
  477.             foreach ($feeOptions as $keyOption => $feeOption){
  478.                 $name "{$cardBrand}{$feeOption}";
  479.                 $data->{"feeCard{$name}"} = $this->globalConfig->{"getFeeCard{$name}"}();
  480.             }
  481.         }
  482.         return $data;
  483.     }
  484.     public function isModuleActive($moduleName)
  485.     {
  486.         return $this->get($moduleName) == AbstractEnum::YES;
  487.     }
  488.     public function checkModuleIsAbleOnPlan(string $moduleName)
  489.     {
  490.         if(!$this->plan){
  491.             return false;
  492.         }
  493.         $planModules $this->plan->getPlanModules();
  494.         if(!empty($planModules->{$moduleName})){
  495.             return true;
  496.         }
  497.         return false;
  498.     }
  499.     public function getPlanModules()
  500.     {
  501.         if(!$this->plan){
  502.             return false;
  503.         }
  504.         return $this->plan->getPlanModules();
  505.     }
  506.     public function isEADUser(User $user)
  507.     {
  508.         $request $this->generalService->getRequest();
  509.         $ip = ($request $request->getClientIp() : null);
  510.         $session $user->getSession();
  511.         $userOrigin = ($session $session->getUserOrigin() : null);
  512.         $originEAD = ($userOrigin && $userOrigin->getId() == UserEnum::YES);
  513.         return ($ip == $this->isLocal() && ($user->getId() == UserEnum::YES || $originEAD));
  514.     }
  515.     public function getReceiverSchool(int $accountType, ?bool $debug false)
  516.     {
  517.         $discordService $this->generalService->getService('DiscordService');
  518.         $discordService->setChannel('debug');
  519.         $receiverSchool $this->em->getRepository(Receiver::class)->findOneBy([
  520.             "deleted" => ReceiverEnum::ITEM_NO_DELETED,
  521.             "status" => ReceiverEnum::ACTIVE,
  522.             "type" => ReceiverEnum::SCHOOL,
  523.             "accountType" => $accountType,
  524.         ]);
  525.         if($receiverSchool){
  526.             if($receiverSchool->getInternalStatus() != ReceiverEnum::BLOCK_INTERNAL){
  527.                 if($accountType == ReceiverEnum::EAD_CHECKOUT){
  528.                     try{
  529.                         $pagarMeReceiver $this->generalService->getService(
  530.                             'PagarMe\\PagarMeReceiver'
  531.                         );
  532.                         $receiver $pagarMeReceiver->getReceiver(
  533.                             $receiverSchool->getReceiverHash()
  534.                         );
  535.                         if($debug){
  536.                             $discordService->setMessage("PagarMe Re: {$receiver->status}");
  537.                             $discordService->sendDiscord();
  538.                         }
  539.                         
  540.                         if($receiver->status != "active"){
  541.                             return;
  542.                         }
  543.                     }catch(\Exception $e){
  544.                         if($debug){
  545.                             $discordService->setMessage($e->getMessage());
  546.                             $discordService->sendDiscord();
  547.                         }
  548.                         return;   
  549.                     }
  550.                 }
  551.                 return $receiverSchool;
  552.             }
  553.             if($debug){
  554.                 $discordService->setMessage(
  555.                     $receiverSchool $receiverSchool->getId() : "Re Internal Status"
  556.                 );
  557.                 $discordService->sendDiscord();
  558.             }
  559.             return;
  560.         }
  561.         if($debug){
  562.             $discordService->setMessage(
  563.                 $receiverSchool $receiverSchool->getId() : "Re Not Found"
  564.             );
  565.             $discordService->sendDiscord();
  566.         }
  567.         return;
  568.     }
  569.     public function getAllConfig()
  570.     {
  571.         if(!empty($this->configurations)){
  572.             return $this->configurations;
  573.         }
  574.         $repository $this->em->getRepository(Configuration::class);
  575.         $configurations $repository->findAll();
  576.         $data = [];
  577.         foreach ($configurations as $key => $configuration) {
  578.             $data[$configuration->getKey()] = htmlspecialchars_decode(
  579.                 $configuration->getValue(), 
  580.                 ENT_QUOTES
  581.             );
  582.         }
  583.         $this->configurations $data;
  584.         return $this->configurations;
  585.     }
  586.     public function getAllOrOneConfig(?string $key null)
  587.     {
  588.         $data = [];
  589.         
  590.         $repository $this->em->getRepository(Configuration::class);
  591.         $stringUtil $this->generalService->getUtil('StringUtil');
  592.         if(!empty($key)){
  593.             $data[$key] = $this->get($key);
  594.         }else{
  595.             $data $this->getAllConfig();
  596.         }
  597.         return $data;
  598.     }
  599.     public function getObj($key){
  600.         $repository $this->em->getRepository(Configuration::class);
  601.         return $repository->find($key);
  602.     }
  603.     public function get($key)
  604.     {   
  605.         if($key == "only_subscription"){
  606.             return AbstractEnum::NO;
  607.         }
  608.         if(!isset($this->configurations[$key])){
  609.             $keyCache md5(Configuration::class) . "_" md5("get{$key}");
  610.             $this->configurations[$key] = $this->memcacheService->getData($keyCache);
  611.             if(empty($this->configurations[$key])){
  612.                 $stringUtil $this->generalService->getUtil('StringUtil');
  613.                 if($key == 'rdName'){
  614.                     $rdStationService $this->generalService->getService(
  615.                         'Marketing\\RdStationService'
  616.                     );
  617.                     $this->configurations[$key] = $rdStationService->getAccountConnected();
  618.                 }else if($this->getObj($key)){
  619.                     $this->configurations[$key] = $stringUtil->encodeString(
  620.                         $this->getObj($key)->getValue()
  621.                     );
  622.                 }
  623.                 $this->memcacheService->saveData(
  624.                     $keyCache
  625.                     $this->configurations[$key],
  626.                     60 60 24
  627.                 );
  628.             }
  629.         }
  630.         return $this->configurations[$key];
  631.     }
  632.     public function setMany(array $data)
  633.     {
  634.         foreach ($data as $key => $value) {
  635.             $this->set($key$valuefalse);
  636.         }
  637.         $userLogService $this->generalService->getService('LogService');
  638.         $userLogService->logUpdate("configuration"1$data);
  639.     }
  640.     public function set($key$value null, ?bool $addLog true): self
  641.     {
  642.         $blockWordsScript = [
  643.             "abre.ai",
  644.             "gatesofdown",
  645.             "tinyurl",
  646.             "atob(",
  647.             "eval(",
  648.             "btoa",
  649.             "aHR0cHM6Ly9nYXRlc29mZG93bi5zaXRlL3doYXRzYXBwLmpz",
  650.             "encurtador",
  651.             "shorturl",
  652.             "rb.gy",
  653.         ];
  654.         $scriptKeys = [
  655.             "scripts",
  656.             "meta_tags",
  657.             "conversion_script",
  658.             "conversionScript",
  659.             "google_gtm",
  660.             "taboola_pixel",
  661.             "google_ads",
  662.             "linkedin_it",
  663.             "jivochat_script",
  664.             "livechat_script",
  665.             "freshchat_script",
  666.             "google_ga4",
  667.             "clarity_script",
  668.             "google_ua",
  669.             "hotjar_script",
  670.             "twitter_pixel",
  671.             "tiktok_pixel",
  672.             "kwai_pixel",
  673.             "callpage_script",
  674.             "microsoft_ads",
  675.             "('script')",
  676.             "(`script`)",
  677.             '("script")',
  678.         ];
  679.         if(in_array($key$scriptKeys)){
  680.             $userLogService $this->generalService->getService('LogService');
  681.             $user $userLogService->getUser();
  682.             $userId = ($user $user->getId() : "");
  683.             $request $this->generalService->getRequest();
  684.             $ip = ($request $request->getClientIp() : "");
  685.             $userAgent = ($request $request->headers->get('User-Agent') : "");
  686.             $discordService $this->generalService->getService('DiscordService');
  687.             $discordService->setChannel('debug-internal');
  688.             $ipApi $this->generalService->getService('IpApiService');
  689.             $logIp $ipApi->getFromIp($ip);
  690.             $today date('d/m/Y H:i:s');
  691.             $message "```──────────────────────────── {$today} â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€```";
  692.             $message.= "**User:** {$userId}\n";
  693.             $message.= "**Campo:** {$key}\n";
  694.             $message.= "**Cliente ID:** {$this->client->getClientId()}\n";
  695.             $message.= "**Host:** {$this->client->getDomainPrimary()}\n";
  696.             $message.= "**IP:** {$ip}\n";
  697.             $message.= "**URI:** {$request->getUri()}\n";
  698.             $message.= "**UserAgent:** {$userAgent}\n";
  699.             $message.= "**Value:** ```{$value}```\n";
  700.             $message.= "\n";
  701.             $message.= "```{$logIp}```";
  702.             $discordService->setMessage($message);
  703.             $discordService->sendDiscord();
  704.             foreach ($blockWordsScript as $idx => $blockWord) {
  705.                 if(stristr($value$blockWord)){
  706.                     $userLogService->logUpdate("configuration"1, [ $key => $value ]);
  707.                     return $this;
  708.                 }
  709.             }
  710.             if($user){
  711.                 $session $user->getSession();
  712.                 $userOrigin = ($session $session->getUserOrigin() : null);
  713.                 if(
  714.                     $user->getId() == ConfigurationEnum::YES ||
  715.                     ($session && $userOrigin && $userOrigin->getId() == ConfigurationEnum::YES)
  716.                 ){
  717.                     $userLogService->logUpdate("configuration"1, [ $key => $value ]);
  718.                 }
  719.             }
  720.         }
  721.         $obj $this->getObj($key);
  722.         if(!$obj){
  723.             $obj = new Configuration();
  724.             $obj->setKey($key);
  725.             $obj->setValue($value);
  726.             $this->em->persist($obj);
  727.         }else{
  728.             $obj->setValue($value);
  729.         }
  730.         $this->em->flush();
  731.         $keyCache md5(Configuration::class) . "_" md5("get{$key}");
  732.         $this->memcacheService->deleteData($keyCache);
  733.         $this->configurations[$key] = $value;
  734.         if($addLog){
  735.             $userLogService $this->generalService->getService('LogService');
  736.             $userLogService->logUpdate("configuration"1, [ $key => $value ]);
  737.         }
  738.         return $this;
  739.     }
  740.     public function showForum(?bool $userOn false)
  741.     {
  742.         if(!$this->isModuleActive("forum_module")){
  743.             return false;
  744.         }
  745.         if($this->get("forum_restricted") == ForumEnum::YES && !$userOn){
  746.             return false;
  747.         }
  748.         return true;
  749.     }
  750.     public function getMinValueProduct(?bool $cents false)
  751.     {   
  752.         if($cents){
  753.             return AbstractEnum::MIN_VALUE_PRODUCT 100;
  754.         }
  755.         return AbstractEnum::MIN_VALUE_PRODUCT;
  756.     }
  757.     public function getPercentConfigurationSchool()
  758.     {
  759.         $firstConfigEmpty null;
  760.         $data = [
  761.             "brand" => (!empty($this->client->getBrand()) ? 0),
  762.             "email" => (!empty($this->client->getEmail()) ? 0),
  763.             "document" => (!empty($this->client->getDocument()) ? 0),
  764.             "slogan" => (!empty($this->client->getSlogan()) ? 0),
  765.             "description" => (!empty($this->client->getDescription()) ? 0),
  766.             "logo" => (!empty($this->get('logo')) ? 0),
  767.             "favicon" => (!empty($this->get('favicon')) ? 0),
  768.             "primary_color" => (!empty($this->get('primary_color')) ? 0),
  769.             "second_color" => (!empty($this->get('second_color')) ? 0),
  770.             "phone" => (!empty($this->get('phone')) ? 0),
  771.             "attendance_schedule" => (!empty($this->get('attendance_schedule')) ? 0),
  772.         ];
  773.         $sumConfig 0;
  774.         foreach ($data as $key => $value) {
  775.             $sumConfig $sumConfig $value;
  776.             if(empty($value) && empty($firstConfigEmpty)){
  777.                 $firstConfigEmpty $key;
  778.             }
  779.         }
  780.         $percentConfig round((- (count($data) - $sumConfig)  / count($data)) * 1002);
  781.         return [
  782.             "firstConfigEmpty" => $firstConfigEmpty,
  783.             "percentConfig" => $percentConfig
  784.         ];
  785.     }
  786.     public function getSystemLanguage()
  787.     {
  788.         switch($this->get('language')) 
  789.         {
  790.             case AbstractEnum::LANGUAGE_EN:
  791.                 $lang 'en';
  792.                 break;
  793.             case AbstractEnum::LANGUAGE_SPA:
  794.                 $lang 'spa';
  795.                 break;
  796.             default:
  797.                 $lang 'pt_BR';
  798.                 break;
  799.         }
  800.         return $lang;
  801.     }
  802.     public function getLanguageDefault(string $keystring $file, ?string $lang null)
  803.     {
  804.         if(empty($lang)){
  805.             $lang $this->getSystemLanguage();
  806.         }
  807.     
  808.         return $this->translator->trans($key, [], $file$lang);
  809.     }
  810.     public function getLanguage(string $keystring $file, ?string $lang null)
  811.     {
  812.         if(empty($lang)){
  813.             $lang $this->getSystemLanguage();
  814.         }
  815.         if($this->checkModuleIsAbleOnPlan('translationFunction')){
  816.             $keyModule "{$file}.{$lang}";
  817.             if(!isset($this->translations[$keyModule])){
  818.                 $translationRepository $this->em->getRepository(Translation::class);
  819.                 $this->translations[$keyModule] = $translationRepository->findTranslation(
  820.                     $file
  821.                     $lang
  822.                 );
  823.             }
  824.             
  825.             if(!empty($this->translations[$keyModule][$key])){
  826.                 return $this->translations[$keyModule][$key];
  827.             }
  828.         }
  829.     
  830.         return $this->translator->trans($key, [], $file$lang);
  831.     }
  832.     public function getLanguageModuleDefault(string $module, ?string $lang null)
  833.     {
  834.         if(empty($lang)){
  835.             $lang $this->getSystemLanguage();
  836.         }
  837.         
  838.         $this->translator->setLocale($lang);
  839.         $fileTranslations $this->translator->getCatalogue()->all($module);
  840.         return $fileTranslations;
  841.     }
  842.     public function getLanguageModule(string $module, ?string $lang null)
  843.     {
  844.         if(empty($lang)){
  845.             $lang $this->getSystemLanguage();
  846.         }
  847.         
  848.         $this->translator->setLocale($lang);
  849.         $fileTranslations $this->translator->getCatalogue()->all($module);
  850.         if($this->checkModuleIsAbleOnPlan('translationFunction')){
  851.             $keyModule "{$module}.{$lang}";
  852.             if(!isset($this->translations[$keyModule])){
  853.                 $translationRepository $this->em->getRepository(Translation::class);
  854.                 $this->translations[$keyModule] = $translationRepository->findTranslation(
  855.                     $module,
  856.                     $lang
  857.                 );
  858.             }
  859.             
  860.             if(!empty($this->translations[$keyModule])){
  861.                 foreach ($this->translations[$keyModule] as $key => $translation) {
  862.                     if(empty($translation)){
  863.                         $this->translations[$keyModule][$key] = (isset($fileTranslations[$key]) ? $fileTranslations[$key] : '');
  864.                     }
  865.                 }
  866.                 
  867.                 return $this->translations[$keyModule];
  868.             }
  869.         }
  870.         return $fileTranslations;
  871.     }
  872.     public function getClientInfo()
  873.     {
  874.         $fileService $this->generalService->getService('FileService');
  875.         $clientImage $fileService->getFilePathComplete(
  876.             $this->get('logo'), 
  877.             AbstractEnum::PATH_OTHERS,
  878.             true,
  879.             true,
  880.             'logo-lesson'
  881.         );
  882.         $clientLessonImage $fileService->getFilePathComplete(
  883.             $this->get('logo_lesson'), 
  884.             AbstractEnum::PATH_OTHERS,
  885.             true,
  886.             true,
  887.             'logo-lesson'
  888.         );
  889.         $plan $this->getPlan();
  890.         $domains = [
  891.             $this->client->getDomainPrimary(),
  892.         ];
  893.         if(!empty($this->client->getDomainSecondary())){
  894.             $domains[] = $this->client->getDomainSecondary();
  895.         }
  896.         
  897.         return (object)[
  898.             "id" => $this->client->getClientId(),
  899.             "planId" => $plan->getId(),
  900.             "planTitle" => $plan->getTitle(),
  901.             "urls" => $domains,
  902.             "limit" => $plan->getLimitSimultaneousAccess(),
  903.             "image" => $clientImage,
  904.             "lessonImage" => $clientLessonImage,
  905.             "brand" => $this->client->getBrand(),
  906.         ];
  907.     }
  908.     public function getDrmConfiguration()
  909.     {
  910.         $drmVideo AbstractEnum::NO;
  911.         $drmShowIdVideo AbstractEnum::NO;
  912.         $drmShowIpVideo AbstractEnum::NO;
  913.         $drmShowDocumentVideo AbstractEnum::NO;
  914.         if($this->checkModuleIsAbleOnPlan('lessonControlFunction')){
  915.             $drmVideo $this->get("drm_video");
  916.             $drmShowIdVideo $this->get("drm_show_user_id_video");
  917.             $drmShowIpVideo $this->get("drm_show_user_ip_video");
  918.             $drmShowDocumentVideo $this->get("drm_show_user_document_video");
  919.         }
  920.         $drmFontColor $this->get("drm_font_color_video");
  921.         if(empty($drmFontColor)){
  922.             $drmFontColor $this->get("primary_color_video");
  923.         }
  924.         if(empty($drmFontColor)){
  925.             $drmFontColor "#08EC6C";
  926.         }
  927.         $drmFontSize $this->get("drm_font_size_video");
  928.         if(empty($drmFontSize)){
  929.             $drmFontSize 12;
  930.         }
  931.         return (object)[
  932.             "allowCopyPdf" => $this->get("drm_allow_copy_pdf"),
  933.             "allowPrintPdf" => $this->get("drm_allow_print_pdf"),
  934.             "allowDownloadPdf" => $this->get("drm_allow_download_pdf"),
  935.             "drmFontModeVideo" => $this->get("drm_font_mode_video"),
  936.             "fontColor" => $drmFontColor,
  937.             "fontSize" => $drmFontSize,
  938.             "video" => $drmVideo,
  939.             "showIdVideo" => $drmShowIdVideo,
  940.             "showIpVideo" => $drmShowIpVideo,
  941.             "showDocumentVideo" => $drmShowDocumentVideo,
  942.         ];
  943.     }
  944. }