src/Services/ConfigurationService.php line 122

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