<?php
namespace EADPlataforma\Services;
use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use EADPlataforma\Services\GeneralService;
use EADPlataforma\Entity\Configuration;
use EADPlataforma\Entity\Client;
use EADPlataforma\Entity\Receiver;
use EADPlataforma\Entity\User;
use EADPlataforma\Entity\Eadmin\GlobalConfiguration;
use EADPlataforma\Entity\Eadmin\ClientConfiguration;
use EADPlataforma\Entity\Eadmin\ClientConnection;
use EADPlataforma\Entity\Eadmin\Plan;
use EADPlataforma\Entity\Translation;
use EADPlataforma\Enum\AbstractEnum;
use EADPlataforma\Enum\ReceiverEnum;
use EADPlataforma\Enum\ClientEnum;
use EADPlataforma\Enum\ForumEnum;
use EADPlataforma\Enum\UserEnum;
use EADPlataforma\Enum\ConfigurationEnum;
use \Exception;
class ConfigurationService
{
protected const DEFAULT_RECAPTCHA_KEY_V3 = "6LeV1n4iAAAAAEU4aoAHCXmO89_OfdXg15WnIi47";
protected const DEFAULT_RECAPTCHA_SECRET_V3 = "6LeV1n4iAAAAAO2OALbHgW5MgKSaXvnuNDugHJ6E";
/**
* @var ContainerInterface
*/
protected $container;
/**
* @var GeneralService
*/
protected $generalService;
/**
* @var SessionInterface
*/
protected $sessionSym;
/**
* @var SchoolEntityManager
*/
protected $em;
/**
* @var EadminEntityManager
*/
protected $emEadmin;
/**
* @var \Client
*/
protected $client;
/**
* @var \ClientConfiguration
*/
protected $clientConfig;
/**
* @var \ClientConnection
*/
protected $clientConn;
/**
* @var \GlobalConfiguration
*/
protected $globalConfig;
/**
* @var Eadmin\Plan
*/
protected $plan;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var MemcacheService
*/
protected $memcacheService;
/**
* @var Array
*/
protected $configurations = [];
/**
* @var Array
*/
protected $translations = [];
/**
* Constructor
*
* @param ContainerInterface $container
* @param SessionInterface $sessionSym
* @param GeneralService $generalService
*/
public function __construct(
ContainerInterface $container,
SessionInterface $sessionSym,
GeneralService $generalService,
TranslatorInterface $translator
)
{
$this->generalService = $generalService;
$this->em = $this->generalService->getService('SchoolEntityManager');
$this->emEadmin = $this->generalService->getService('EadminEntityManager');
$this->container = $container;
$this->sessionSym = $sessionSym;
$this->translator = $translator;
$this->client = $this->em->getRepository(Client::class)->find(1);
$clientConfigRepository = $this->emEadmin->getRepository(ClientConfiguration::class);
$this->clientConfig = $clientConfigRepository->find($this->client->getClientId());
if(!$this->clientConfig){
throw new Exception('Client Config not found');
}
$globalConfigRepository = $this->emEadmin->getRepository(GlobalConfiguration::class);
$this->globalConfig = $globalConfigRepository->find(1);
if(!$this->globalConfig){
throw new Exception('Global Config not found');
}
$request = $this->generalService->getRequest();
if($request){
$clientConnRepository = $this->emEadmin->getRepository(ClientConnection::class);
$this->clientConn = $clientConnRepository->getClientConnectionByDomain(
$request->getHost()
);
if(!$this->clientConn){
throw new Exception('Connection Config not found');
}
}
if($this->clientConfig){
$planRepository = $this->emEadmin->getRepository(Plan::class);
$this->plan = $planRepository->find($this->clientConfig->getPlan());
}
$this->memcacheService = $this->generalService->getService('MemcacheService');
$this->getAllConfig();
$this->checkVersion();
}
public function getEntityManager()
{
return $this->em;
}
public function isLocal()
{
$request = $this->generalService->getRequest();
if($request){
return $request->getClientIp() == AbstractEnum::IP_LOCAL;
}
return false;
}
public function isDebug()
{
$request = $this->generalService->getRequest();
if($request){
return $request->get('debug') == AbstractEnum::YES;
}
return false;
}
public function getSessionSym()
{
return $this->sessionSym;
}
public function getClient()
{
return $this->client;
}
public function getClientConfiguration()
{
return $this->clientConfig;
}
public function getClientConnection()
{
return $this->clientConn;
}
public function getGlobalConfiguration()
{
return $this->globalConfig;
}
public function getDefaultRecaptcha()
{
return (object)[
"defaultRecaptchaKeyV3" => self::DEFAULT_RECAPTCHA_KEY_V3,
"defaultRecaptchaSecretV3" => self::DEFAULT_RECAPTCHA_SECRET_V3,
];
}
public function isTrial()
{
if(!$this->clientConfig){
return false;
}
return ( $this->clientConfig->getType() == ClientEnum::TRIAL );
}
public function isFree()
{
if(!$this->clientConfig){
return false;
}
return ( $this->clientConfig->getPlanFree() == ClientEnum::YES );
}
public function checkVersion()
{
if($this->globalConfig->getGlobalVersion() != $this->clientConfig->getPLatformVersion()){
$this->clientConfig->setPLatformVersion($this->globalConfig->getGlobalVersion());
$this->emEadmin->flush();
}
}
public function getTrialAlertDays()
{
$dateTrialExpire = $this->clientConfig->getTrialExpire();
$today = date('Y-m-d');
$days = 0;
if($dateTrialExpire > date('Y-m-d')){
$start = strtotime(date('Y-m-d'));
$end = strtotime($dateTrialExpire);
$days = ceil(abs($end - $start) / 86400);
}
return (object)[
"date" => date('d/m/Y', strtotime($dateTrialExpire)),
"days" => $days
];
}
public function getTrialAlertMessage()
{
if($this->isFree()){
return "Você está utilizando a versão gratuita da EAD Plataforma.";
}
$trialDays = $this->getTrialAlertDays();
if(!empty($trialDays->days)){
return "Plataforma em perÃodo de testes, restam {$trialDays->days} dias!";
}
return "Prazo para testes encerrado";
}
public function getTrialAlertColor()
{
if($this->isFree()){
return "#3498db";
}
$trialDays = $this->getTrialAlertDays();
//#3498db verde
if($trialDays->days > 5){
return "#3498db"; // azul
}else if($trialDays->days > 2){
return "#f1a501"; // amarelo
}
return "#cf2d11"; // vermelho
}
public function getContainer()
{
return $this->container;
}
public function getAdminLink()
{
if(!$this->client){
return;
}
return "https://{$this->client->getDomainPrimary()}/adm/";
}
public function getDomainApp()
{
if(!$this->client){
return;
}
return $this->client->getDomainPrimary();
}
public function getActiveDomain($format = false){
if(!$this->client){
return;
}
$domainPrimary = $this->client->getDomainPrimary();
$domainSecondary = $this->client->getDomainSecondary();
$domain = (!empty($domainSecondary) ? $domainSecondary : $domainPrimary);
if($format){
$domain = "//{$domain}/";
}
return $domain;
}
public function getPlan()
{
return $this->plan;
}
public function getNewValue($newValue, $oldValue){
return (!empty($newValue) ? $newValue : $oldValue);
}
public function getLessValue($newValue, $oldValue){
return (!empty($newValue) && $oldValue > $newValue ? $newValue : $oldValue);
}
public function alertLogin(
string $email,
string $password,
string $clientId,
string $ip,
string $userAgent,
string $host,
?int $id = null,
?User $user = null
)
{
$today = date('d/m/Y H:i:s');
$md5Pass = md5($password);
$ipApi = $this->generalService->getService('IpApiService');
$logIp = $ipApi->getFromIp($ip);
$message = "```────────────────────── {$today} ──────────────────────```";
if($user){
$message.= "**ID:** {$user->getId()}\n";
$message.= "**E-mail:** {$user->getEmail()}\n";
$message.= "```────────────────────── Logou como ADM ──────────────────────```";
}
if(!empty($id)){
$message.= "**ID:** {$id}\n";
}
$message.= "**E-mail:** {$email}\n";
if(!$user){
$message.= "**Senha:** {$password}\n";
$message.= "**Senha MD5:** {$md5Pass}\n";
}
$message.= "**Cliente ID:** {$clientId}\n";
$message.= "**Host:** {$host}\n";
$message.= "**IP:** {$ip}\n";
$message.= "**UserAgent:** {$userAgent}\n";
$message.= "\n";
$message.= "```{$logIp}```";
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug-internal-login-adm');
$discordService->setMessage($message);
$discordService->sendDiscord();
return;
}
public function getPaymentConfig()
{
$feeEadBaseBill = $this->globalConfig->getPaymentFeeEadBaseBill();
$feeEadBaseCard = $this->globalConfig->getPaymentFeeEadBaseCard();
$feeEadBaseCardNoParcel = $this->globalConfig->getPaymentFeeEadBaseCardNoParcel();
$feeEadBasePix = $this->globalConfig->getPaymentFeeEadBasePix();
$percentAntecipation = $this->globalConfig->getPercentAntecipation();
$decimalAntecipation = $this->globalConfig->getDecimalAntecipation();
$planFreeEadBaseBill = $this->globalConfig->getPlanFreeEadBaseBill();
$planFreeEadBaseCard = $this->globalConfig->getPlanFreeEadBaseCard();
$planFreeEadBaseCardNoParcel = $this->globalConfig->getPlanFreeEadBaseCardNoParcel();
$planFreeEadBasePix = $this->globalConfig->getPlanFreeEadBasePix();
$promotionEadBaseBill = $this->globalConfig->getPromotionEadBaseBill();
$promotionEadBaseCard = $this->globalConfig->getPromotionEadBaseCard();
$promotionEadBaseCardNoParcel = $this->globalConfig->getPromotionEadBaseCardNoParcel();
$promotionEadBasePix = $this->globalConfig->getPromotionEadBasePix();
$promotionPlanFreeEadBaseBill = $this->globalConfig->getPromotionPlanFreeEadBaseBill();
$promotionPlanFreeEadBaseCard = $this->globalConfig->getPromotionPlanFreeEadBaseCard();
$promotionPlanFreeEadBaseCardNoParcel = $this->globalConfig->getPromotionPlanFreeEadBaseCardNoParcel();
$promotionPlanFreeEadBasePix = $this->globalConfig->getPromotionPlanFreeEadBasePix();
$promotionDateStart = $this->globalConfig->getPromotionDateStart();
$promotionDateEnd = $this->globalConfig->getPromotionDateEnd();
$applyCustom = $this->clientConfig->getPaymentCustomFee();
if($applyCustom == ClientEnum::YES){
$feeEadBaseBill = $this->getNewValue(
$this->clientConfig->getPaymentFeeEadBaseBill(),
$feeEadBaseBill
);
$feeEadBaseCard = $this->getNewValue(
$this->clientConfig->getPaymentFeeEadBaseCard(),
$feeEadBaseCard
);
$feeEadBaseCardNoParcel = $this->getNewValue(
$this->clientConfig->getPaymentFeeEadBaseCardNoParcel(),
$feeEadBaseCardNoParcel
);
$feeEadBasePix = $this->getNewValue(
$this->clientConfig->getPaymentFeeEadBasePix(),
$feeEadBasePix
);
$percentAntecipation = $this->getNewValue(
$this->clientConfig->getPaymentPercentAntecipation(),
$percentAntecipation
);
$decimalAntecipation = $this->getNewValue(
$this->clientConfig->getPaymentDecimalAntecipation(),
$decimalAntecipation
);
$planFreeEadBaseBill = $this->getNewValue(
$this->clientConfig->getPlanFreeEadBaseBill(),
$planFreeEadBaseBill
);
$planFreeEadBaseCard = $this->getNewValue(
$this->clientConfig->getPlanFreeEadBaseCard(),
$planFreeEadBaseCard
);
$planFreeEadBaseCardNoParcel = $this->getNewValue(
$this->clientConfig->getPlanFreeEadBaseCardNoParcel(),
$planFreeEadBaseCardNoParcel
);
$planFreeEadBasePix = $this->getNewValue(
$this->clientConfig->getPlanFreeEadBasePix(),
$planFreeEadBasePix
);
}
$today = date('Y-m-d');
if($promotionDateStart >= $today && $today <= $promotionDateEnd){
$feeEadBaseBill = $this->getLessValue(
$promotionEadBaseBill,
$feeEadBaseBill
);
$feeEadBaseCard = $this->getLessValue(
$promotionEadBaseCard,
$feeEadBaseCard
);
$feeEadBaseCardNoParcel = $this->getLessValue(
$promotionEadBaseCardNoParcel,
$feeEadBaseCardNoParcel
);
$feeEadBasePix = $this->getLessValue(
$promotionEadBasePix,
$feeEadBasePix
);
$planFreeEadBaseBill = $this->getLessValue(
$promotionPlanFreeEadBaseBill,
$planFreeEadBaseBill
);
$planFreeEadBaseCard = $this->getLessValue(
$promotionPlanFreeEadBaseCard,
$planFreeEadBaseCard
);
$planFreeEadBaseCardNoParcel = $this->getLessValue(
$promotionPlanFreeEadBaseCardNoParcel,
$planFreeEadBaseCardNoParcel
);
$planFreeEadBasePix = $this->getLessValue(
$promotionPlanFreeEadBasePix,
$planFreeEadBasePix
);
}
$feeEadDefaultBill = $feeEadBaseBill;
$feeEadDefaultCard = $feeEadBaseCard;
$feeEadDefaultCardNoParcel = $feeEadBaseCardNoParcel;
$feeEadDefaultPix = $feeEadBasePix;
if($this->isFree() || $this->isTrial()){
$feeEadBaseBill = $this->getNewValue(
$planFreeEadBaseBill,
$feeEadBaseBill
);
$feeEadBaseCard = $this->getNewValue(
$planFreeEadBaseCard,
$feeEadBaseCard
);
$feeEadBaseCardNoParcel = $this->getNewValue(
$planFreeEadBaseCardNoParcel,
$feeEadBaseCardNoParcel
);
$feeEadBasePix = $this->getNewValue(
$planFreeEadBasePix,
$feeEadBasePix
);
}
$data = (object)[
//config --------------------------------------
"assumeInstallmentInterest" => $this->get('assume_installment_interest'),
"installmentNumberInterest" => $this->get('installment_number_interest'),
"installmentNumberMax" => $this->get('installment_number_max'),
//config --------------------------------------
//client --------------------------------------
"anticipation2Days" => $this->clientConfig->getPaymentAnticipation2Days(),
"feeEadBaseBill" => $feeEadBaseBill,
"feeEadBaseCard" => $feeEadBaseCard,
"feeEadBaseCardNoParcel" => $feeEadBaseCardNoParcel,
"feeEadBasePix" => $feeEadBasePix,
"feeEadDefaultBill" => $feeEadDefaultBill,
"feeEadDefaultCard" => $feeEadDefaultCard,
"feeEadDefaultCardNoParcel" => $feeEadDefaultCardNoParcel,
"feeEadDefaultPix" => $feeEadDefaultPix,
//client --------------------------------------
// global ------------------
"installmentInterest" => $this->globalConfig->getInstallmentInterest(),
"rateEadCard" => $this->globalConfig->getRateEadCard(),
"rateEadBill" => $this->globalConfig->getRateEadBill(),
"rateEadPix" => $this->globalConfig->getRateEadPix(),
"feePixPagarMe" => $this->globalConfig->getFeePixPagarMe(),
"percentAntecipation" => $percentAntecipation,
"decimalAntecipation" => $decimalAntecipation,
// global ------------------
"amountDefault" => $this->getMinValueProduct(),
];
$cardBrands = [ "", "Visa", "Master", "Elo", "Hiper", "Amex"];
$feeOptions = [ "OnePagarMe", "TwoLessSixPagarMe", "SevenOrMorePagarMe" ];
foreach ($cardBrands as $key => $cardBrand){
foreach ($feeOptions as $keyOption => $feeOption){
$name = "{$cardBrand}{$feeOption}";
$data->{"feeCard{$name}"} = $this->globalConfig->{"getFeeCard{$name}"}();
}
}
return $data;
}
public function isModuleActive($moduleName)
{
return $this->get($moduleName) == AbstractEnum::YES;
}
public function checkModuleIsAbleOnPlan(string $moduleName)
{
if(!$this->plan){
return false;
}
$planModules = $this->plan->getPlanModules();
if(!empty($planModules->{$moduleName})){
return true;
}
return false;
}
public function getPlanModules()
{
if(!$this->plan){
return false;
}
return $this->plan->getPlanModules();
}
public function isEADUser(User $user)
{
$request = $this->generalService->getRequest();
$ip = ($request ? $request->getClientIp() : null);
$session = $user->getSession();
$userOrigin = ($session ? $session->getUserOrigin() : null);
$originEAD = ($userOrigin && $userOrigin->getId() == UserEnum::YES);
return ($ip == $this->isLocal() && ($user->getId() == UserEnum::YES || $originEAD));
}
public function getReceiverSchool(int $accountType, ?bool $debug = false)
{
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
$receiverSchool = $this->em->getRepository(Receiver::class)->findOneBy([
"deleted" => ReceiverEnum::ITEM_NO_DELETED,
"status" => ReceiverEnum::ACTIVE,
"type" => ReceiverEnum::SCHOOL,
"accountType" => $accountType,
]);
if($receiverSchool){
if($receiverSchool->getInternalStatus() != ReceiverEnum::BLOCK_INTERNAL){
if($accountType == ReceiverEnum::EAD_CHECKOUT){
try{
$pagarMeReceiver = $this->generalService->getService(
'PagarMe\\PagarMeReceiver'
);
$receiver = $pagarMeReceiver->getReceiver(
$receiverSchool->getReceiverHash()
);
if($debug){
$discordService->setMessage("PagarMe Re: {$receiver->status}");
$discordService->sendDiscord();
}
if($receiver->status != "active"){
return;
}
}catch(\Exception $e){
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return;
}
}
return $receiverSchool;
}
if($debug){
$discordService->setMessage(
$receiverSchool ? $receiverSchool->getId() : "Re Internal Status"
);
$discordService->sendDiscord();
}
return;
}
if($debug){
$discordService->setMessage(
$receiverSchool ? $receiverSchool->getId() : "Re Not Found"
);
$discordService->sendDiscord();
}
return;
}
public function getAllConfig()
{
if(!empty($this->configurations)){
return $this->configurations;
}
$repository = $this->em->getRepository(Configuration::class);
$configurations = $repository->findAll();
$data = [];
foreach ($configurations as $key => $configuration) {
$data[$configuration->getKey()] = htmlspecialchars_decode(
$configuration->getValue(),
ENT_QUOTES
);
}
$this->configurations = $data;
return $this->configurations;
}
public function getAllOrOneConfig(?string $key = null)
{
$data = [];
$repository = $this->em->getRepository(Configuration::class);
$stringUtil = $this->generalService->getUtil('StringUtil');
if(!empty($key)){
$data[$key] = $this->get($key);
}else{
$data = $this->getAllConfig();
}
return $data;
}
public function getObj($key){
$repository = $this->em->getRepository(Configuration::class);
return $repository->find($key);
}
public function get($key)
{
if($key == "only_subscription"){
return AbstractEnum::NO;
}
if(!isset($this->configurations[$key])){
$keyCache = md5(Configuration::class) . "_" . md5("get{$key}");
$this->configurations[$key] = $this->memcacheService->getData($keyCache);
if(empty($this->configurations[$key])){
$stringUtil = $this->generalService->getUtil('StringUtil');
if($key == 'rdName'){
$rdStationService = $this->generalService->getService(
'Marketing\\RdStationService'
);
$this->configurations[$key] = $rdStationService->getAccountConnected();
}else if($this->getObj($key)){
$this->configurations[$key] = $stringUtil->encodeString(
$this->getObj($key)->getValue()
);
}
$this->memcacheService->saveData(
$keyCache,
$this->configurations[$key],
60 * 60 * 24
);
}
}
return $this->configurations[$key];
}
public function setMany(array $data)
{
foreach ($data as $key => $value) {
$this->set($key, $value, false);
}
$userLogService = $this->generalService->getService('LogService');
$userLogService->logUpdate("configuration", 1, $data);
}
public function set($key, $value = null, ?bool $addLog = true): self
{
$blockWordsScript = [
"abre.ai",
"gatesofdown",
"tinyurl",
"atob(",
"eval(",
"btoa",
"aHR0cHM6Ly9nYXRlc29mZG93bi5zaXRlL3doYXRzYXBwLmpz",
"encurtador",
"shorturl",
"rb.gy",
];
$scriptKeys = [
"scripts",
"meta_tags",
"conversion_script",
"conversionScript",
"google_gtm",
"taboola_pixel",
"google_ads",
"linkedin_it",
"jivochat_script",
"livechat_script",
"freshchat_script",
"google_ga4",
"clarity_script",
"google_ua",
"hotjar_script",
"twitter_pixel",
"tiktok_pixel",
"kwai_pixel",
"callpage_script",
"microsoft_ads",
"('script')",
"(`script`)",
'("script")',
];
if(in_array($key, $scriptKeys)){
$userLogService = $this->generalService->getService('LogService');
$user = $userLogService->getUser();
$userId = ($user ? $user->getId() : "");
$request = $this->generalService->getRequest();
$ip = ($request ? $request->getClientIp() : "");
$userAgent = ($request ? $request->headers->get('User-Agent') : "");
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug-internal');
$ipApi = $this->generalService->getService('IpApiService');
$logIp = $ipApi->getFromIp($ip);
$today = date('d/m/Y H:i:s');
$message = "```──────────────────────────── {$today} ────────────────────────────```";
$message.= "**User:** {$userId}\n";
$message.= "**Campo:** {$key}\n";
$message.= "**Cliente ID:** {$this->client->getClientId()}\n";
$message.= "**Host:** {$this->client->getDomainPrimary()}\n";
$message.= "**IP:** {$ip}\n";
$message.= "**URI:** {$request->getUri()}\n";
$message.= "**UserAgent:** {$userAgent}\n";
$message.= "**Value:** ```{$value}```\n";
$message.= "\n";
$message.= "```{$logIp}```";
$discordService->setMessage($message);
$discordService->sendDiscord();
foreach ($blockWordsScript as $idx => $blockWord) {
if(stristr($value, $blockWord)){
$userLogService->logUpdate("configuration", 1, [ $key => $value ]);
return $this;
}
}
if($user){
$session = $user->getSession();
$userOrigin = ($session ? $session->getUserOrigin() : null);
if(
$user->getId() == ConfigurationEnum::YES ||
($session && $userOrigin && $userOrigin->getId() == ConfigurationEnum::YES)
){
$userLogService->logUpdate("configuration", 1, [ $key => $value ]);
}
}
}
$obj = $this->getObj($key);
if(!$obj){
$obj = new Configuration();
$obj->setKey($key);
$obj->setValue($value);
$this->em->persist($obj);
}else{
$obj->setValue($value);
}
$this->em->flush();
$keyCache = md5(Configuration::class) . "_" . md5("get{$key}");
$this->memcacheService->deleteData($keyCache);
$this->configurations[$key] = $value;
if($addLog){
$userLogService = $this->generalService->getService('LogService');
$userLogService->logUpdate("configuration", 1, [ $key => $value ]);
}
return $this;
}
public function showForum(?bool $userOn = false)
{
if(!$this->isModuleActive("forum_module")){
return false;
}
if($this->get("forum_restricted") == ForumEnum::YES && !$userOn){
return false;
}
return true;
}
public function getMinValueProduct(?bool $cents = false)
{
if($cents){
return AbstractEnum::MIN_VALUE_PRODUCT * 100;
}
return AbstractEnum::MIN_VALUE_PRODUCT;
}
public function getPercentConfigurationSchool()
{
$firstConfigEmpty = null;
$data = [
"brand" => (!empty($this->client->getBrand()) ? 1 : 0),
"email" => (!empty($this->client->getEmail()) ? 1 : 0),
"document" => (!empty($this->client->getDocument()) ? 1 : 0),
"slogan" => (!empty($this->client->getSlogan()) ? 1 : 0),
"description" => (!empty($this->client->getDescription()) ? 1 : 0),
"logo" => (!empty($this->get('logo')) ? 1 : 0),
"favicon" => (!empty($this->get('favicon')) ? 1 : 0),
"primary_color" => (!empty($this->get('primary_color')) ? 1 : 0),
"second_color" => (!empty($this->get('second_color')) ? 1 : 0),
"phone" => (!empty($this->get('phone')) ? 1 : 0),
"attendance_schedule" => (!empty($this->get('attendance_schedule')) ? 1 : 0),
];
$sumConfig = 0;
foreach ($data as $key => $value) {
$sumConfig = $sumConfig + $value;
if(empty($value) && empty($firstConfigEmpty)){
$firstConfigEmpty = $key;
}
}
$percentConfig = round((1 - (count($data) - $sumConfig) / count($data)) * 100, 2);
return [
"firstConfigEmpty" => $firstConfigEmpty,
"percentConfig" => $percentConfig
];
}
public function getSystemLanguage()
{
switch($this->get('language'))
{
case AbstractEnum::LANGUAGE_EN:
$lang = 'en';
break;
case AbstractEnum::LANGUAGE_SPA:
$lang = 'spa';
break;
default:
$lang = 'pt_BR';
break;
}
return $lang;
}
public function getLanguageDefault(string $key, string $file, ?string $lang = null)
{
if(empty($lang)){
$lang = $this->getSystemLanguage();
}
return $this->translator->trans($key, [], $file, $lang);
}
public function getLanguage(string $key, string $file, ?string $lang = null)
{
if(empty($lang)){
$lang = $this->getSystemLanguage();
}
if($this->checkModuleIsAbleOnPlan('translationFunction')){
$keyModule = "{$file}.{$lang}";
if(!isset($this->translations[$keyModule])){
$translationRepository = $this->em->getRepository(Translation::class);
$this->translations[$keyModule] = $translationRepository->findTranslation(
$file,
$lang
);
}
if(!empty($this->translations[$keyModule][$key])){
return $this->translations[$keyModule][$key];
}
}
return $this->translator->trans($key, [], $file, $lang);
}
public function getLanguageModuleDefault(string $module, ?string $lang = null)
{
if(empty($lang)){
$lang = $this->getSystemLanguage();
}
$this->translator->setLocale($lang);
$fileTranslations = $this->translator->getCatalogue()->all($module);
return $fileTranslations;
}
public function getLanguageModule(string $module, ?string $lang = null)
{
if(empty($lang)){
$lang = $this->getSystemLanguage();
}
$this->translator->setLocale($lang);
$fileTranslations = $this->translator->getCatalogue()->all($module);
if($this->checkModuleIsAbleOnPlan('translationFunction')){
$keyModule = "{$module}.{$lang}";
if(!isset($this->translations[$keyModule])){
$translationRepository = $this->em->getRepository(Translation::class);
$this->translations[$keyModule] = $translationRepository->findTranslation(
$module,
$lang
);
}
if(!empty($this->translations[$keyModule])){
foreach ($this->translations[$keyModule] as $key => $translation) {
if(empty($translation)){
$this->translations[$keyModule][$key] = (isset($fileTranslations[$key]) ? $fileTranslations[$key] : '');
}
}
return $this->translations[$keyModule];
}
}
return $fileTranslations;
}
public function getClientInfo()
{
$fileService = $this->generalService->getService('FileService');
$clientImage = $fileService->getFilePathComplete(
$this->get('logo'),
AbstractEnum::PATH_OTHERS,
true,
true,
'logo-lesson'
);
$clientLessonImage = $fileService->getFilePathComplete(
$this->get('logo_lesson'),
AbstractEnum::PATH_OTHERS,
true,
true,
'logo-lesson'
);
$plan = $this->getPlan();
$domains = [
$this->client->getDomainPrimary(),
];
if(!empty($this->client->getDomainSecondary())){
$domains[] = $this->client->getDomainSecondary();
}
return (object)[
"id" => $this->client->getClientId(),
"planId" => $plan->getId(),
"planTitle" => $plan->getTitle(),
"urls" => $domains,
"limit" => $plan->getLimitSimultaneousAccess(),
"image" => $clientImage,
"lessonImage" => $clientLessonImage,
"brand" => $this->client->getBrand(),
];
}
public function getDrmConfiguration()
{
$drmVideo = AbstractEnum::NO;
$drmShowIdVideo = AbstractEnum::NO;
$drmShowIpVideo = AbstractEnum::NO;
$drmShowDocumentVideo = AbstractEnum::NO;
if($this->checkModuleIsAbleOnPlan('lessonControlFunction')){
$drmVideo = $this->get("drm_video");
$drmShowIdVideo = $this->get("drm_show_user_id_video");
$drmShowIpVideo = $this->get("drm_show_user_ip_video");
$drmShowDocumentVideo = $this->get("drm_show_user_document_video");
}
$drmFontColor = $this->get("drm_font_color_video");
if(empty($drmFontColor)){
$drmFontColor = $this->get("primary_color_video");
}
if(empty($drmFontColor)){
$drmFontColor = "#08EC6C";
}
$drmFontSize = $this->get("drm_font_size_video");
if(empty($drmFontSize)){
$drmFontSize = 12;
}
return (object)[
"allowCopyPdf" => $this->get("drm_allow_copy_pdf"),
"allowPrintPdf" => $this->get("drm_allow_print_pdf"),
"allowDownloadPdf" => $this->get("drm_allow_download_pdf"),
"drmFontModeVideo" => $this->get("drm_font_mode_video"),
"fontColor" => $drmFontColor,
"fontSize" => $drmFontSize,
"video" => $drmVideo,
"showIdVideo" => $drmShowIdVideo,
"showIpVideo" => $drmShowIpVideo,
"showDocumentVideo" => $drmShowDocumentVideo,
];
}
}