<?php
namespace EADPlataforma\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use EADPlataforma\Services\GeneralService;
use EADPlataforma\Services\ConfigurationService;
use EADPlataforma\Entity\Cart;
use EADPlataforma\Entity\Course;
use EADPlataforma\Entity\Product;
use EADPlataforma\Entity\ProductOffer;
use EADPlataforma\Entity\ProductCoupon;
use EADPlataforma\Entity\Whishlist;
use EADPlataforma\Entity\Exam;
use EADPlataforma\Entity\Enrollment;
use EADPlataforma\Entity\User;
use EADPlataforma\Entity\Category;
use EADPlataforma\Entity\CourseTestimonial;
use EADPlataforma\Entity\TransactionItem;
use EADPlataforma\Entity\UserCustomField;
use EADPlataforma\Entity\PageSection;
use EADPlataforma\Entity\UserSubscription;
use EADPlataforma\Enum\ExamEnum;
use EADPlataforma\Enum\CartEnum;
use EADPlataforma\Enum\ClientEnum;
use EADPlataforma\Enum\CourseEnum;
use EADPlataforma\Enum\ProductEnum;
use EADPlataforma\Enum\ProductOfferEnum;
use EADPlataforma\Enum\ReceiverEnum;
use EADPlataforma\Enum\WhishlistEnum;
use EADPlataforma\Enum\EnrollmentEnum;
use EADPlataforma\Enum\UserCustomFieldEnum;
use EADPlataforma\Enum\PageSectionEnum;
use EADPlataforma\Util\DateTimeUtil;
class FunctionsExtension extends AbstractExtension
{
/**
* @var GeneralService
*/
private $generalService;
/**
* @var ConfigurationService
*/
private $configuration;
/**
* @var SchoolEntityManager
*/
protected $em;
/**
* @var User $user
*/
protected $user;
/**
* @var Array $results
*/
protected $results = [];
/**
* @var Array $arrValue
*/
protected $arrValue = [];
// SECTIONS
private $sectionTemplates = [
'headSection' => 'includes/menu-section',
'bannerSection' => 'home/banner-section',
'searchSection' => 'includes/search-section',
'productSpotlightOfferSection' => 'product/product-section',
'enrollmentSection' => 'user/enrollment/enrollment-section',
'productCourseSection' => 'product/product-section',
'productLastCourseSection' => 'product/product-section',
'productBestSellersSection' => 'product/product-section',
'productPlanSection' => [
'light' => 'product/product-section',
'dark' => 'product/product-box-home-section',
],
'productComboSection' => 'product/product-section',
'productUserRecomendationSection' => 'product/product-section',
'productBestSection' => 'product/product-section',
'productRandomWhishlistSection' => 'product/product-section',
'productCategorySection' => 'product/product-category-section',
'teacherSection' => 'teacher/teacher-section',
'schoolNumberSection' => 'home/school-numbers-section',
'faqSection' => 'faq/faq-section',
'testimonialSection' => 'course/course-testimonial-section',
'newsSection' => 'home/newsletter-section',
'socialSection' => 'includes/social-section',
'institutionalSection' => 'institutional/institutional-section',
'stampsSection' => 'includes/stamps-section',
];
/**
* Constructor
*
* @param GeneralService $generalService
*/
public function __construct(GeneralService $generalService)
{
$this->generalService = $generalService;
$this->em = $this->generalService->getService('SchoolEntityManager');
}
public function getConfiguration()
{
if(!$this->configuration){
$this->configuration = $this->generalService->getService('ConfigurationService');
}
return $this->configuration;
}
public function getUser()
{
if(!$this->user){
$this->user = $this->generalService->getService('UserSessionService')->getUser();
}
return $this->user;
}
public function getFunctions()
{
return [
new TwigFunction('getConfig', [$this, 'getConfig']),
new TwigFunction('getCss', [$this, 'getCss']),
new TwigFunction('getScript', [$this, 'getScript']),
new TwigFunction('checkConfigHasScript', [$this, 'checkConfigHasScript']),
new TwigFunction('getMeta', [$this, 'getMeta']),
new TwigFunction('getConfigPayment', [$this, 'getConfigPayment']),
new TwigFunction('isModuleActive', [$this, 'isModuleActive']),
new TwigFunction('isPlanModuleActive', [$this, 'isPlanModuleActive']),
new TwigFunction('getSection', [$this, 'getSection']),
new TwigFunction('getPermission', [$this, 'getPermission']),
new TwigFunction('isLow', [$this, 'isLow']),
new TwigFunction('isMiddle', [$this, 'isMiddle']),
new TwigFunction('isHigh', [$this, 'isHigh']),
new TwigFunction(
'getInfoAccessProductOffer', [$this, 'getInfoAccessProductOffer']
),
new TwigFunction(
'checkProductOfferIsOnSale', [$this, 'checkProductOfferIsOnSale']
),
new TwigFunction(
'getOfferProductSubscription', [$this, 'getOfferProductSubscription']
),
new TwigFunction('getClient', [$this, 'getClient']),
new TwigFunction('getUserCartNumber', [$this, 'getUserCartNumber']),
new TwigFunction('getUserCartSubTotal', [$this, 'getUserCartSubTotal']),
new TwigFunction('getUserCartMenuItems', [$this, 'getUserCartMenuItems']),
new TwigFunction('productIsInCart', [$this, 'productIsInCart']),
new TwigFunction('getExamType', [$this, 'getExamType']),
new TwigFunction('getEnrollmentStatus', [$this, 'getEnrollmentStatus']),
new TwigFunction('getEnrollmentSituation', [$this, 'getEnrollmentSituation']),
new TwigFunction(
'getEnrollmentSituationClass', [$this, 'getEnrollmentSituationClass']
),
new TwigFunction(
'getEnrollmentPeriodLabel', [$this, 'getEnrollmentPeriodLabel']
),
new TwigFunction('printValueOrEmpty', [$this, 'printValueOrEmpty']),
new TwigFunction('isInWhishlist', [$this, 'isInWhishlist']),
new TwigFunction('plural', [$this, 'plural']),
new TwigFunction('installments', [$this, 'installments']),
new TwigFunction('htmlDecode', [$this, 'htmlDecode']),
new TwigFunction('getLanguage', [$this, 'getLanguage']),
new TwigFunction('getLanguageModule', [$this, 'getLanguageModule']),
new TwigFunction('workLoadText', [$this, 'workLoadText']),
new TwigFunction('existReceiverEAD', [$this, 'existReceiverEAD']),
new TwigFunction('getFilePathComplete', [$this, 'getFilePathComplete']),
new TwigFunction('getTextProductType', [$this, 'getTextProductType']),
new TwigFunction('discountPercent', [$this, 'discountPercent']),
new TwigFunction('enum', [$this, 'enum']),
new TwigFunction('getScoreCourse', [$this, 'getScoreCourse']),
new TwigFunction('getScoreProduct', [$this, 'getScoreProduct']),
new TwigFunction('getTimeTotalProduct', [$this, 'getTimeTotalProduct']),
new TwigFunction('getOfferParcelInfo', [$this, 'getOfferParcelInfo']),
new TwigFunction('getOfferContract', [$this, 'getOfferContract']),
new TwigFunction('installmentPeriodText', [$this, 'installmentPeriodText']),
new TwigFunction('courseByProductTotal', [$this, 'courseByProductTotal']),
new TwigFunction('userHasProduct', [$this, 'userHasProduct']),
new TwigFunction('hasInCart', [$this, 'hasInCart']),
new TwigFunction(
'getFirstCourseIdFromProduct', [$this, 'getFirstCourseIdFromProduct']
),
new TwigFunction(
'getProductTypeTextTranslate', [$this, 'getProductTypeTextTranslate']
),
new TwigFunction('encodeHex', [$this, 'encodeHex']),
new TwigFunction('getDefaultRecaptcha', [$this, 'getDefaultRecaptcha']),
new TwigFunction('getFields', [$this, 'getFields']),
new TwigFunction('clearSocialUrl', [$this, 'clearSocialUrl']),
new TwigFunction('checkSection', [$this, 'checkSection']),
new TwigFunction('paintStars', [$this, 'paintStars']),
new TwigFunction('getCategoryOffers', [$this, 'getCategoryOffers']),
new TwigFunction('HEXtoRGB', [$this, 'HEXtoRGB']),
new TwigFunction('RGBtoHSL', [$this, 'RGBtoHSL']),
new TwigFunction('HEXtoHSL', [$this, 'HEXtoHSL']),
new TwigFunction('setValue', [$this, 'setValue']),
new TwigFunction('getValue', [$this, 'getValue']),
new TwigFunction('pageSectionFormat', [$this, 'pageSectionFormat']),
new TwigFunction('pageSectionPosition', [$this, 'pageSectionPosition']),
new TwigFunction('pageSectionTemplateItem', [$this, 'pageSectionTemplateItem']),
new TwigFunction('pageSectionItems', [$this, 'pageSectionItems']),
new TwigFunction('pageSectionLinkAll', [$this, 'pageSectionLinkAll']),
new TwigFunction('isPageSection', [$this, 'isPageSection']),
new TwigFunction('pageSectionShowAll', [$this, 'pageSectionShowAll']),
new TwigFunction('getPlanCycleString', [$this, 'getPlanCycleString']),
new TwigFunction('getPlanCycleStringProductDetail', [
$this, 'getPlanCycleStringProductDetail'
]),
new TwigFunction('getDocumentFormat', [$this, 'getDocumentFormat']),
new TwigFunction('getUserSubscriptionError', [$this, 'getUserSubscriptionError']),
new TwigFunction('getVimeoFormatIframe', [$this, 'getVimeoFormatIframe']),
new TwigFunction('isValidCard', [$this, 'isValidCard']),
new TwigFunction('stringOrigin', [$this, 'stringOrigin']),
new TwigFunction('stringStatus', [$this, 'stringStatus']),
];
}
public function getConfig(string $configName)
{
$value = $this->getConfiguration()->get($configName);
$cleanKeys = [
"contract",
"privacy_policy",
];
if(in_array($configName, $cleanKeys)){
$stringUtil = $this->generalService->getUtil('StringUtil');
$value = $stringUtil->removeScripts($value);
}
return $value;
}
public function getMeta(string $configName)
{
return $this->getConfiguration()->get($configName);
}
public function getCss(string $configName)
{
return $this->getConfiguration()->get($configName);
}
public function getScript(string $configName, ?string $nonceHash = "")
{
$value = $this->getConfiguration()->get($configName);
$scripts = [ 'scripts' ];
if(in_array($configName, $scripts)){
$value = htmlspecialchars_decode($value, ENT_QUOTES);
}
$value = str_replace("<script ", "<script nonce='{$nonceHash}' ", $value);
$value = str_replace("<script>", "<script nonce='{$nonceHash}'>", $value);
return $value;
}
public function checkConfigHasScript(string $configName)
{
$value = $this->getConfiguration()->get($configName);
return stristr($value, 'script');
}
public function getConfigPayment()
{
return $this->getConfiguration()->getPaymentConfig();
}
public function isModuleActive($moduleName)
{
return $this->getConfiguration()->isModuleActive($moduleName);
}
public function isPlanModuleActive($moduleName)
{
return $this->getConfiguration()->checkModuleIsAbleOnPlan($moduleName);
}
public function getPermission($level1 = null, $level2 = null, $level3 = null, $level4 = null)
{
$userPermissionUtil = $this->generalService->getUtil('UserPermissionUtil');
return $userPermissionUtil->getPermission($level1, $level2, $level3, $level4);
}
public function isLow(int $permissionValue)
{
$userPermissionUtil = $this->generalService->getUtil('UserPermissionUtil');
return $userPermissionUtil->isLow($permissionValue);
}
public function isMiddle(int $permissionValue)
{
$userPermissionUtil = $this->generalService->getUtil('UserPermissionUtil');
return $userPermissionUtil->isMiddle($permissionValue);
}
public function isHigh(int $permissionValue)
{
$userPermissionUtil = $this->generalService->getUtil('UserPermissionUtil');
return $userPermissionUtil->isHigh($permissionValue);
}
public function getInfoAccessProductOffer(
ProductOffer $productOffer,
?bool $isNext = false,
?ProductCoupon $productCoupon = null,
?bool $isOfferSpotligth = false
)
{
$data = (object)[
"link" => "#",
"text" => "buy_now",
"allowBuyNow" => false,
"isFree" => false,
"dateSaleOffer" => null,
"userHasProduct" => false,
"saleOfferStart" => false,
"saleChannelOption" => false,
"colorBtnWaitList" => false
];
$product = $productOffer->getProduct();
$productRepository = $this->em->getRepository(Product::class);
if($this->getUser()){
$dataProduct = $productRepository->userHasProduct($this->getUser(), $product);
if($dataProduct){
$data->userHasProduct = true;
$routeName = null;
$routeParams = null;
if($dataProduct->type == ProductEnum::COURSE){
$routeName = 'courseIndex';
$routeParams = [
"id" => $dataProduct->elementId
];
}else if($dataProduct->type == ProductEnum::SUBSCRIPTION){
$routeName = 'resume';
}
if(!empty($routeName)){
$data->link = $this->generalService->generateUrl(
$routeName,
$routeParams
);
$data->text = $this->getConfiguration()->getLanguage(
'access2', 'product'
);
}
}
}
if(!$data->userHasProduct){
$saleIsOpen = $this->checkProductOfferIsOnSale($productOffer);
if(
$productOffer->getSaleOption() == ProductOfferEnum::FREE &&
$saleIsOpen
){
$data->isFree = true;
if($productOffer->getSaleChannel() == ProductOfferEnum::EXTERNAL){
$data->link = $productOffer->getExternalCheckoutLink();
$data->saleChannelOption = true;
}else{
if($this->getUser()){
$data->link = $this->generalService->generateUrl(
'cartCreateEnroll',
[ "productOfferId" => $productOffer->getId() ]
);
}else{
$data->link = '#fast-register-modal';
}
}
$data->text = $this->getConfiguration()->getLanguage(
'enroll', 'product'
);
}else{
if($saleIsOpen){
if($productOffer->getSaleChannel() == ProductOfferEnum::EXTERNAL){
$data->link = $productOffer->getExternalCheckoutLink();
$data->saleChannelOption = true;
}else{
$data->allowBuyNow = true;
$data->link = $this->generalService->generateUrl('cartAdd', [
"poID" => $productOffer->getId(),
"pcID" => ($productCoupon ? $productCoupon->getId() : 0)
]);
if(
$productOffer->getAllowRecurrency() == ProductOfferEnum::YES ||
$product->getType() == ProductEnum::SUBSCRIPTION
){
$data->text = $this->getConfiguration()->getLanguage(
'subscribe_now', 'product'
);
if($productOffer->getAllowTrial() == ProductOfferEnum::YES){
$data->saleChannelOption = true;
}
if(
$product->getType() == ProductEnum::SUBSCRIPTION &&
$isOfferSpotligth
){
$data->link = "#section-plan-cycles";
}else if($productOffer->getAllowTrial() == ProductOfferEnum::YES){
$dataProduct = false;
if($this->getUser()){
$dataProduct = $productRepository->userHasProduct(
$this->getUser(),
$product,
true
);
}
if(!$dataProduct || empty($this->getUser())){
$data->link = $this->generalService->generateUrl(
'cartIndividual', [
"poHash" => $productOffer->getOfferLink(),
"pcKey" => (
$productCoupon ?
$productCoupon->getKey() :
null
)
]);
}
}
}
}
}else{
$next = $productOffer->getNextProductOffer();
if($next && !$isNext){
if(
$next->getStatus() == ProductOfferEnum::PUBLISHED &&
$next->isNotDeleted()
){
return $this->getInfoAccessProductOffer(
$next,
true,
$productCoupon
);
}
}
$getDiffStart = $productOffer->getDiffDuration();
if($getDiffStart['start'] == true) {
$data->dateSaleOffer = $productOffer->getSaleDateStart();
$data->saleOfferStart = true;
}else{
$data->dateSaleOffer = $productOffer->getSaleDateClose();
}
$data->colorBtnWaitList = true;
$data->link = '#wait-list-modal';
$data->text = $this->getConfiguration()->getLanguage(
'join_the_list',
'product'
);
}
}
}
return $data;
}
public function getOfferProductSubscription(ProductOffer $productOfferDefault)
{
$productOfferRepository = $this->em->getRepository(ProductOffer::class);
$product = $productOfferDefault->getProduct();
$monthOffer = $productOfferRepository->getDefaultOrCustomByCycle(
$product,
ProductOfferEnum::CYCLE_MONTHLY
);
$quarterlyOffer = $productOfferRepository->getDefaultOrCustomByCycle(
$product,
ProductOfferEnum::CYCLE_QUARTERLY
);
$semiannualOffer = $productOfferRepository->getDefaultOrCustomByCycle(
$product,
ProductOfferEnum::CYCLE_SEMIANNUAL
);
$yearlyOffer = $productOfferRepository->getDefaultOrCustomByCycle(
$product,
ProductOfferEnum::CYCLE_YEARLY
);
$biennialOffer = $productOfferRepository->getDefaultOrCustomByCycle(
$product,
ProductOfferEnum::CYCLE_BIENNIAL
);
$triennialOffer = $productOfferRepository->getDefaultOrCustomByCycle(
$product,
ProductOfferEnum::CYCLE_TRIENNIAL
);
$weeklyOffer = $productOfferRepository->getDefaultOrCustomByCycle(
$product,
ProductOfferEnum::CYCLE_WEEKLY
);
$biweeklyOffer = $productOfferRepository->getDefaultOrCustomByCycle(
$product,
ProductOfferEnum::CYCLE_BIWEEKLY
);
$productOffers = array_filter([
$monthOffer,
$quarterlyOffer,
$semiannualOffer,
$yearlyOffer,
$biennialOffer,
$triennialOffer,
$weeklyOffer,
$biweeklyOffer,
]);
return $productOfferRepository->returnProductOfferOrProductNextPlan(
$productOfferDefault,
$productOffers
);
}
public function checkProductOfferIsOnSale(ProductOffer $productOffer)
{
$productOfferRepository = $this->em->getRepository(ProductOffer::class);
return $productOfferRepository->checkProductOfferIsOnSale($productOffer);
}
public function getClient()
{
return $this->getConfiguration()->getClient();
}
public function getUserCartNumber()
{
$cartRepository = $this->em->getRepository(Cart::class);
return $cartRepository->countUserOnCart();
}
public function getUserCartSubTotal()
{
$cartRepository = $this->em->getRepository(Cart::class);
if($this->getUser()){
return $cartRepository->getUserSubTotal($this->getUser()->getId());
}else{
$hashIdentify = $this->generalService->getCookie('hashcartoff');
if(!empty($hashIdentify)){
return $cartRepository->getHashSubTotal($hashIdentify);
}
}
return 0;
}
public function getUserCartMenuItems(?int $limit = 2)
{
$cartRepository = $this->em->getRepository(Cart::class);
if($this->getUser()){
return $cartRepository->getUserValidCarts($this->getUser()->getId(), null, $limit);
}else{
$hashIdentify = $this->generalService->getCookie('hashcartoff');
if(!empty($hashIdentify)){
return $cartRepository->getHashValidCarts($hashIdentify, null, $limit);
}
}
return [];
}
public function productIsInCart(int $productId, ?int $productOfferId = null)
{
$cartRepository = $this->em->getRepository(Cart::class);
$hashIdentify = $this->generalService->getCookie('hashcartoff');
if(!$this->getUser() && empty($hashIdentify)){
return false;
}
$filter = [
"product" => $productId,
"deleted" => CartEnum::ITEM_NO_DELETED
];
if($this->getUser()){
$filter["user"] = $this->getUser()->getId();
}else if(!empty($hashIdentify)){
$filter["hashIdentify"] = $hashIdentify;
}
if(!empty($productOfferId)){
$filter["productOffer"] = $productOfferId;
}
$cartSave = $cartRepository->findOneBy($filter);
return ($cartSave ? true : false);
}
public function getExamType(int $examType)
{
$examRepository = $this->em->getRepository(Exam::class);
return $examRepository->getExamTypeText($examType);
}
public function getEnrollmentStatus(int $status)
{
$enrollmentRepository = $this->em->getRepository(Enrollment::class);
return $enrollmentRepository->getStringStatus($status);
}
public function getEnrollmentSituation(?Enrollment $enrollment = null)
{
$situation = EnrollmentEnum::SITUATION_NOT_STARTED;
if($enrollment){
$situation = $enrollment->getSituation();
}
$situationLabels = [
EnrollmentEnum::SITUATION_STARTED => "in_progress",
EnrollmentEnum::SITUATION_NOT_STARTED => "not_started",
EnrollmentEnum::SITUATION_COMPLETED => "completed",
];
$index = $situationLabels[$situation];
return $this->getConfiguration()->getLanguage($index, 'user_resume');
}
public function getEnrollmentSituationClass(?Enrollment $enrollment = null)
{
$situation = EnrollmentEnum::SITUATION_NOT_STARTED;
if($enrollment){
$situation = $enrollment->getSituation();
}
$situationLabels = [
EnrollmentEnum::SITUATION_STARTED => "information",
EnrollmentEnum::SITUATION_NOT_STARTED => "",
EnrollmentEnum::SITUATION_COMPLETED => "success",
];
return $situationLabels[$situation];
}
public function getEnrollmentPeriodLabel(?Enrollment $enrollment = null, ?Course $course = null)
{
if($enrollment){
$datePeriod = $enrollment->getDatePeriod('d/m/Y');
if($datePeriod == "09/09/9999"){
return $this->getConfiguration()->getLanguage('lifetime', 'enrollments');
}
if($enrollment->getStatus(false, true) == EnrollmentEnum::STATUS_EXPIRED){
return $this->getConfiguration()->getLanguage('expired', 'user_resume');
}
$txt = $this->getConfiguration()->getLanguage('access_until', 'user_resume');
if($datePeriod == date('d/m/Y')){
$time = date('H:i:s');
return "{$txt} {$time}";
}
return "{$txt} {$datePeriod}";
}else if($course){
if($course->getLifetimePeriod() == CourseEnum::YES){
return $this->getConfiguration()->getLanguage('lifetime', 'enrollments');
}
$datePeriod = date('d/m/Y', strtotime(" + {$course->getAccessPeriod()} days"));
$txt = $this->getConfiguration()->getLanguage('access_until', 'user_resume');
return "{$txt} {$datePeriod}";
}
return $this->getConfiguration()->getLanguage('expired', 'user_resume');
}
public function isInWhishlist(int $productId)
{
if(!$this->getUser()){
return false;
}
$whishlistRepository = $this->em->getRepository(Whishlist::class);
$whishlistSave = $whishlistRepository->findOneBy([
"product" => $productId,
"user" => $this->getUser()->getId(),
"deleted" => WhishlistEnum::ITEM_NO_DELETED
]);
return ( $whishlistSave ? true : false );
}
public function printValueOrEmpty($value)
{
return (!empty($value) ? $value : '---');
}
public function getSection($sectionName)
{
$theme = $this->getConfiguration()->get('website_theme');
if(empty($theme))
{
$theme = 'light';
}
if(empty($this->sectionTemplates[$sectionName]))
{
return false;
}
$sectionFile = $this->sectionTemplates[$sectionName];
if(is_array($sectionFile))
{
$sectionFile = $sectionFile[$theme];
}
$sectionFile = "website/{$sectionFile}.html.twig";
return $sectionFile;
}
// PLURAL
public function plural($numero, $tx_singular, $tx_plural)
{
return ($numero == 1) ? $tx_singular : $tx_plural;
}
// INSTALLMENTS
public function installmentPeriodText($subscriptionCycleEnum)
{
// Cycle X Months
$installmentMonths = [
ProductOfferEnum::CYCLE_MONTHLY => [
"period" => 1,
"text" => $this->getConfiguration()->getLanguage('monthly', 'product'),
"textPlan" => $this->getConfiguration()->getLanguage('monthly_plan', 'product'),
],
ProductOfferEnum::CYCLE_QUARTERLY => [
"period" => 3,
"text" => $this->getConfiguration()->getLanguage('quarterly', 'product'),
"textPlan" => $this->getConfiguration()->getLanguage('quarterly_plan', 'product'),
],
ProductOfferEnum::CYCLE_SEMIANNUAL => [
"period" => 6,
"text" => $this->getConfiguration()->getLanguage('semiannual', 'product'),
"textPlan" => $this->getConfiguration()->getLanguage('semiannual_plan', 'product'),
],
ProductOfferEnum::CYCLE_YEARLY => [
"period" => 12,
"text" => $this->getConfiguration()->getLanguage('yearly', 'product'),
"textPlan" => $this->getConfiguration()->getLanguage('yearly_plan', 'product'),
],
ProductOfferEnum::CYCLE_WEEKLY => [
"period" => 1,
"text" => $this->getConfiguration()->getLanguage('weekly', 'product'),
"textPlan" => $this->getConfiguration()->getLanguage('weekly_plan', 'product'),
],
ProductOfferEnum::CYCLE_BIWEEKLY => [
"period" => 1,
"text" => $this->getConfiguration()->getLanguage('biweekly', 'product'),
"textPlan" => $this->getConfiguration()->getLanguage('biweekly_plan', 'product'),
],
ProductOfferEnum::CYCLE_BIENNIAL => [
"period" => 24,
"text" => $this->getConfiguration()->getLanguage('biennial', 'product'),
"textPlan" => $this->getConfiguration()->getLanguage('biennial_plan', 'product'),
],
ProductOfferEnum::CYCLE_TRIENNIAL => [
"period" => 36,
"text" => $this->getConfiguration()->getLanguage('triennial', 'product'),
"textPlan" => $this->getConfiguration()->getLanguage('triennial_plan', 'product'),
],
];
if (isset($installmentMonths[$subscriptionCycleEnum])){
return (object)$installmentMonths[$subscriptionCycleEnum];
}
return (object)$installmentMonths[ProductOfferEnum::CYCLE_MONTHLY];
}
public function installments(ProductOffer $productOffer)
{
$months = $this->installmentPeriodText($productOffer->getPlanCycle());
$productOfferRepository = $this->em->getRepository(ProductOffer::class);
$numberUtil = $this->generalService->getUtil('NumberUtil');
$parcelInfo = $numberUtil->getNumberMaxParcel(
$productOffer->getPriceReal(true),
$productOfferRepository->getInstallmentNumberMax($productOffer),
$productOfferRepository->getFreeInstallment($productOffer),
$productOffer->getSaleOption(),
$productOffer->getTypeCheckout(),
false
);
return [
'number'=> $parcelInfo->maxInstallments,
'value' => $parcelInfo->parcelPrice,
'period'=> $months->text,
];
}
// HTML DECODE ENTITIES
public function htmlDecode($txt)
{
return html_entity_decode($txt);
}
// HTML DECODE ENTITIES
public function existReceiverEAD()
{
$receiverSchool = $this->getConfiguration()->getReceiverSchool(ReceiverEnum::EAD_CHECKOUT);
return ($receiverSchool? true : false);
}
// TRANSLATION
public function getLanguage($key, $file){
return $this->getConfiguration()->getLanguage($key, $file);
}
public function getLanguageModule($module){
return $this->getConfiguration()->getLanguageModule($module);
}
public function workLoadText(?string $workload = null)
{
if(empty($workload)){
return;
}
return DateTimeUtil::workloadFormat(
$workload, false, $this->getLanguageModule('util')
);
}
public function getFilePathComplete($config)
{
$fileService = $this->generalService->getService('FileService');
$config = (object)$config;
$config->fileName = (!empty($config->fileName) ? $config->fileName : null);
$config->pathConst = (!empty($config->pathConst) ? $config->pathConst : null);
$config->addUpload = (!empty($config->addUpload) ? $config->addUpload : false);
$config->addStream = (!empty($config->addStream) ? $config->addStream : false);
$config->option = (!empty($config->option) ? $config->option : null);
$pathCdn = $fileService->getFilePathComplete(
$config->fileName,
$config->pathConst,
$config->addUpload,
$config->addStream,
$config->option,
true
);
$pathCreateCrop = $fileService->getFilePathComplete(
$config->fileName,
$config->pathConst,
$config->addUpload,
$config->addStream,
$config->option
);
return (object)[
"pathCdn" => $pathCdn,
"pathCreateCrop" => $pathCreateCrop,
];
}
public function getTextProductType($type)
{
switch ($type) {
case ProductEnum::COURSE:
return 'curso';
break;
case ProductEnum::SUBSCRIPTION:
return 'plano';
break;
case ProductEnum::COMBO:
return 'combo';
break;
case ProductEnum::CERTIFICATE:
return 'certificado';
break;
case ProductEnum::LIVE:
return 'live';
break;
}
}
public function getProductTypeTextTranslate(int $type)
{
switch ($type) {
case ProductEnum::COURSE:
return $this->getConfiguration()->getLanguage('course', 'util');
break;
case ProductEnum::SUBSCRIPTION:
return $this->getConfiguration()->getLanguage('subscription', 'util');
break;
case ProductEnum::COMBO:
return 'Combo';
break;
default:
return $this->getConfiguration()->getLanguage('course', 'util');;
break;
}
return 0;
}
public function discountPercent($priceReal, $priceDisplay)
{
return ($priceDisplay == 0)? false : (1 - $priceReal / $priceDisplay) * 100;
}
public function enum($key)
{
return constant("EADPlataforma\\Enum\\{$key}");
}
public function getScoreCourse(Course $course)
{
$courseTestimonialRepository = $this->em->getRepository(CourseTestimonial::class);
//Course Stars
$scoreCourse = $courseTestimonialRepository->getScoreByCourse(
$course
);
if(empty($scoreCourse->fiveStar)){
$scoreCourse->fiveStar = CourseEnum::NO;
}
if(empty($scoreCourse->fourStar)){
$scoreCourse->fourStar = CourseEnum::NO;
}
if(empty($scoreCourse->threeStar)){
$scoreCourse->threeStar = CourseEnum::NO;
}
if(empty($scoreCourse->twoStar)){
$scoreCourse->twoStar = CourseEnum::NO;
}
if(empty($scoreCourse->oneStar)){
$scoreCourse->oneStar = CourseEnum::NO;
}
$scoreCourse->splitScore = [
$scoreCourse->fiveStar,
$scoreCourse->fourStar,
$scoreCourse->threeStar,
$scoreCourse->twoStar,
$scoreCourse->oneStar,
];
return $scoreCourse;
}
public function getTimeTotalProduct(Product $product)
{
$courseRepository = $this->em->getRepository(Course::class);
$timeTotal = $courseRepository->getAllCourseTimeByProduct($product);
return $timeTotal;
}
public function getScoreProduct(Product $product)
{
$courseTestimonialRepository = $this->em->getRepository(CourseTestimonial::class);
//Course Stars
$scoreProduct = $courseTestimonialRepository->getScoreByProduct(
$product
);
if(empty($scoreProduct->fiveStar)){
$scoreProduct->fiveStar = ProductEnum::NO;
}
if(empty($scoreProduct->fourStar)){
$scoreProduct->fourStar = ProductEnum::NO;
}
if(empty($scoreProduct->threeStar)){
$scoreProduct->threeStar = ProductEnum::NO;
}
if(empty($scoreProduct->twoStar)){
$scoreProduct->twoStar = ProductEnum::NO;
}
if(empty($scoreProduct->oneStar)){
$scoreProduct->oneStar = ProductEnum::NO;
}
$scoreProduct->splitScore = [
$scoreProduct->fiveStar,
$scoreProduct->fourStar,
$scoreProduct->threeStar,
$scoreProduct->twoStar,
$scoreProduct->oneStar,
];
return $scoreProduct;
}
public function getOfferContract(ProductOffer $productOffer)
{
// Product contract
$contract = trim($productOffer->getProduct()->getContract());
if (empty($contract) or preg_match('/^null$/i', $contract))
{
// Config contract
$contract = trim($this->getConfig('contract'));
if (empty($contract) or preg_match('/^null$/i', $contract))
{
$contract = false;
}
}
return $contract;
}
public function getOfferParcelInfo(ProductOffer $productOffer, ?Cart $cart = null)
{
$productOfferRepository = $this->em->getRepository(ProductOffer::class);
$numberUtil = $this->generalService->getUtil('NumberUtil');
$freeInstallments = $productOfferRepository->getFreeInstallment($productOffer);
$parcelInfo = $numberUtil->getNumberMaxParcel(
($cart ? $cart->getPrice(true) : $productOffer->getPriceReal(true)),
$productOfferRepository->getInstallmentNumberMax($productOffer),
$freeInstallments,
$productOffer->getSaleOption(),
$productOffer->getTypeCheckout(),
false
);
$paymentConfig = $this->getConfiguration()->getPaymentConfig();
$pagarMeTransaction = $this->generalService->getService(
'PagarMe\\PagarMeTransaction'
);
$installmentsOptions = $pagarMeTransaction->calculateInstallments([
'amount' => $productOffer->getPriceReal(true),
'free_installments' => $freeInstallments,
'max_installments' => $parcelInfo->maxInstallments,
'interest_rate' => $paymentConfig->installmentInterest
]);
$parcelInfo->installmentsOptions = $installmentsOptions;
return $parcelInfo;
}
public function courseByProductTotal($productId){
$courseRepository = $this->em->getRepository(Course::class);
$courseTotal = $courseRepository->getPublishedCourseNumberByProduct(
$productId
);
return $courseTotal;
}
public function userHasProduct(Product $product, ?bool $ignoreStatus = false){
$hashResult = md5(
(
$this->getUser() ?
$this->getUser()->getId() :
null
) . $product->getId() . (
$ignoreStatus ?
ProductOfferEnum::YES :
ProductOfferEnum::NO
)
);
if(isset($this->results["userHasProduct_{$hashResult}"])){
return $this->results["userHasProduct_{$hashResult}"];
}
if(!$this->getUser()){
$this->results["userHasProduct_{$hashResult}"] = false;
return $this->results["userHasProduct_{$hashResult}"];
}
$productRepository = $this->em->getRepository(Product::class);
$dataProduct = $productRepository->userHasProduct(
$this->getUser(),
$product,
false,
$ignoreStatus
);
$this->results["userHasProduct_{$hashResult}"] = ($dataProduct ? true : false);
return $this->results["userHasProduct_{$hashResult}"];
}
public function hasInCart(array $productOffers)
{
$has = true;
foreach ($productOffers as $key => $productOffer) {
if(!$this->productIsInCart($productOffer->getProduct()->getId())){
$has = false;
}
}
return $has;
}
public function getFirstCourseIdFromProduct(Product $product)
{
$courses = $product->getCourse();
foreach ($courses as $key => $course) {
return $course->getId();
}
return;
}
public function encodeHex($value)
{
$stringUtil = $this->generalService->getUtil('StringUtil');
$hash = $stringUtil->encodeHex($value, false, false);
return $hash;
}
public function getDefaultRecaptcha(){
return $this->getConfiguration()->getDefaultRecaptcha();
}
public function getFields()
{
$fields = [];
if($this->getConfiguration()->checkModuleIsAbleOnPlan('customFormModule')){
$fields = $this->em->getRepository(UserCustomField::class)->findBy([
"deleted" => UserCustomFieldEnum::ITEM_NO_DELETED,
"status" => UserCustomFieldEnum::PUBLISHED,
"showInRegister" => UserCustomFieldEnum::YES,
],
[ "order" => "ASC" ]);
foreach ($fields as $key => $field) {
$field->optionsObj = null;
$options = $field->getOptions();
if(!empty($options)){
$field->optionsObj = json_decode($options);
}
$fields[$key] = $field;
}
}
return $fields;
}
public function clearSocialUrl($slug, $url)
{
$formats = [
// WHATSAPP
'whatsapp' => 'https://api.whatsapp.com/send/?phone=%s',
// LINKEDIN
'linkedin' => 'https://linkedin.com/%s',
// YOUTUBE
'youtube' => 'https://www.youtube.com/%s',
// PINTEREST
'pinterest' => 'https://br.pinterest.com/%s',
// INSTAGRAM
'instagram' => 'https://www.instagram.com/%s/?hl=pt-br',
// SNAPCHAT
'snapchat' => 'https://www.snapchat.com/add/%s',
// FACEBOOK
'facebook' => 'https://www.facebook.com/%s',
// TWITTER
'twitter' => 'https://twitter.com/%s',
// SPOTIFY
'spotify' => 'https://open.spotify.com/show/%s',
// TIKTOK
'tiktok' => 'https://tiktok.com/%s',
];
// WHATSAPP
if ($slug == 'whatsapp')
{
$url = preg_replace("/[^0-9]/", "", $url);
}
// NÃO whatsapp
else
{
$url = preg_replace('/^(.*)\?(.*)$/', '$1', $url);
$url = trim($url, '/');
// LINKEDIN
if ($slug == 'linkedin')
{
$url = preg_replace('/^(.*?)(((company|in)\/)?[^\/]*)$/', '$2', $url);
}
// NÃO linkedin
else
{
$url = preg_replace('/^(.*?)([^\/]*)$/', '$2', $url);
}
}
$url = sprintf($formats[$slug], $url);
return $url;
}
public function checkSection(string $sectionName)
{
$sectionConfigHome = json_decode(
$this->getConfiguration()->get('section_config_home')
);
if(isset($sectionConfigHome->{$sectionName})){
if(isset($sectionConfigHome->{$sectionName}->active)){
return $sectionConfigHome->{$sectionName}->active == ClientEnum::YES;
}
}
return false;
}
public function paintStars($score, $halfStars = true)
{
$score = abs($score);
$frac = array_replace([false, false], explode('.', $score));
$half = [];
if ($halfStars && in_array($frac[1], range(5, 9)))
{
$half = [$frac[0] => 'half'];
}
$base = array_fill(0, 5, 'off');
$full = array_fill(0, floor($score), 'on');
$paint = array_replace($base, $full, $half);
return $paint;
}
public function getCategoryOffers(){
$categoryRepository = $this->em->getRepository(Category::class);
$productOfferRepository = $this->em->getRepository(ProductOffer::class);
$productCategories = $categoryRepository->getCategories();
$categoryOffers = [];
foreach ($productCategories as $key => $category) {
$category = (object)$category;
$category->productOffers = $productOfferRepository->getPublicProductOffers([
"category" => $category->getId(),
"limit" => 6
]);
$categoryOffers[$key] = $category;
}
return $categoryOffers;
}
public function HEXtoRGB($hex)
{
return sscanf($hex, "#%02x%02x%02x");
}
public function RGBtoHSL($r, $g, $b)
{
$oldR = $r;
$oldG = $g;
$oldB = $b;
$r /= 255;
$g /= 255;
$b /= 255;
$max = max($r, $g, $b);
$min = min($r, $g, $b);
$h; $s;
$l = ($max + $min) / 2;
$d = $max - $min;
if ($d == 0){
$h = $s = 0; // achromatic
} else {
$s = $d / (1 - abs(2 * $l - 1));
switch($max){
case $r:
$h = 60 * fmod((($g - $b) / $d), 6);
{
if ($b > $g)
$h += 360;
}
break;
case $g:
$h = 60 * (($b - $r) / $d + 2);
break;
case $b:
$h = 60 * (($r - $g) / $d + 4);
break;
}
}
return [round($h, 2), round($s, 2), round($l, 2)];
}
public function HEXtoHSL($hex)
{
list($r, $g, $b) = $this->HEXtoRGB($hex);
return $this->RGBtoHSL($r, $g, $b);
}
public function setValue(string $key, $value = null)
{
$this->arrValue[$key] = $value;
return;
}
public function getValue(string $key)
{
return (isset($this->arrValue[$key]) ? $this->arrValue[$key] : null);
}
public function pageSectionFormat(int $formatType)
{
$formats = [
PageSectionEnum::BOX_DEFAULT => "default",
PageSectionEnum::BOX_EXPAND => "expand",
PageSectionEnum::BOX_STAND => "stand",
PageSectionEnum::BOX_ROUND => "round",
];
return (!empty($formats[$formatType]) ? $formats[$formatType] : "default");
}
public function pageSectionPosition(int $position)
{
$positions = [
PageSectionEnum::LEFT => "left",
PageSectionEnum::CENTER => "center",
PageSectionEnum::RIGHT => "right",
];
return (!empty($positions[$position]) ? $positions[$position] : "center");
}
public function pageSectionTemplateItem(PageSection $pageSection)
{
$typeItem = $pageSection->getTypeItem();
$type = $pageSection->getTypeItem();
$productType = [
PageSectionEnum::ALL_PRODUCT,
PageSectionEnum::PRODUCT_SPOTLIGHT,
PageSectionEnum::PRODUCT_SUGGESTION,
PageSectionEnum::PRODUCT_COURSE,
PageSectionEnum::PRODUCT_SUBSCRIPTION,
PageSectionEnum::PRODUCT_COMBO,
PageSectionEnum::PRODUCT_LIVE,
PageSectionEnum::PRODUCT_BY_CATEGORY,
PageSectionEnum::PRODUCT_WISHLIST,
];
$slug_format = [
'default' => '-default',
// 'expand' => '-spotlight',
'expand' => '-expand',
'stand' => '-stand',
'round' => '-round',
];
$slug = $slug_format[$this->pageSectionFormat($pageSection->getType())];
$template = null;
if(in_array($typeItem, $productType)){
$template = "website/product/product-item-box{$slug}.html.twig";
}else if($typeItem == PageSectionEnum::COURSE_STARTED){
$template = "website/course/course-item-box{$slug}-home.html.twig";
}
return $template;
}
public function pageSectionItems(PageSection $pageSection)
{
$typeItem = $pageSection->getTypeItem();
$allItem = $pageSection->getAllItem() == PageSectionEnum::YES;
$item = json_decode($pageSection->getItem());
$orderItem = $pageSection->getOrderItem();
$limit = $pageSection->getNumberOfLine() * $pageSection->getNumberPerLine();
$items = [];
$productType = [
PageSectionEnum::ALL_PRODUCT,
PageSectionEnum::PRODUCT_SPOTLIGHT,
PageSectionEnum::PRODUCT_SUGGESTION,
PageSectionEnum::PRODUCT_COURSE,
PageSectionEnum::PRODUCT_SUBSCRIPTION,
PageSectionEnum::PRODUCT_COMBO,
PageSectionEnum::PRODUCT_LIVE,
PageSectionEnum::PRODUCT_BY_CATEGORY,
PageSectionEnum::PRODUCT_WISHLIST,
];
//CATEGORY,
//TEACHER,
//FAQ,
//TESTIMONIAL
if(in_array($typeItem, $productType)){
if($typeItem == PageSectionEnum::PRODUCT_WISHLIST && !$this->user){
return [];
}
$productIds = (
!$allItem && !empty($item) && is_array($item) ?
$item :
null
);
$productRepository = $this->em->getRepository(Product::class);
if(empty($productIds) && $typeItem == PageSectionEnum::PRODUCT_SUGGESTION){
$productIds = $productRepository->getProductsInCache();
}
$typeOriginal = [
PageSectionEnum::PRODUCT_COURSE => ProductEnum::COURSE,
PageSectionEnum::PRODUCT_SUBSCRIPTION => ProductEnum::SUBSCRIPTION,
PageSectionEnum::PRODUCT_COMBO => ProductEnum::COMBO,
PageSectionEnum::PRODUCT_LIVE => ProductEnum::LIVE,
];
$productOfferRepository = $this->em->getRepository(ProductOffer::class);
$items = $productOfferRepository->getPublicProductOffersNew([
"type" => (
isset($typeOriginal[$typeItem]) ?
$typeOriginal[$typeItem] :
null
),
"category" => (
$typeItem == PageSectionEnum::PRODUCT_BY_CATEGORY &&
$pageSection->getCategory() ?
$pageSection->getCategory()->getId() :
null
),
"limit" => $limit,
"spotlight" => (
$typeItem == PageSectionEnum::PRODUCT_SPOTLIGHT ?
PageSectionEnum::YES :
PageSectionEnum::NO
),
"wishlist" => (
$typeItem == PageSectionEnum::PRODUCT_WISHLIST ?
PageSectionEnum::YES :
PageSectionEnum::NO
),
"order" => $pageSection->getOrderItem(),
"productIds" => $productIds,
]);
$user = $this->getUser();
if($user && $pageSection->getShowEnrollment() == PageSectionEnum::NO){
$aux = [];
foreach ($items as $key => $offer) {
if(!$productRepository->userHasProduct($user, $offer->getProduct())){
$aux[] = $offer;
}
}
$items = $aux;
}
}else if($typeItem == PageSectionEnum::COURSE_STARTED && $this->getUser()){
$enrollmentRepository = $this->em->getRepository(Enrollment::class);
$enrollments = $enrollmentRepository->getResumeEnrollment(
$this->getUser()->getId(),
[ EnrollmentEnum::SITUATION_STARTED ],
null,
null,
null,
null,
$limit
);
foreach ($enrollments as $key => $enrollment) {
$items[] = $enrollment->getCourse();
}
}
return $items;
}
public function pageSectionLinkAll(PageSection $pageSection)
{
$typeItem = $pageSection->getTypeItem();
$category = $pageSection->getCategory();
$categoryLink = "/products";
if($typeItem == PageSectionEnum::PRODUCT_BY_CATEGORY && $category){
$categoryLink = "/products/{$category->getSlug()}";
}
$links = [
PageSectionEnum::ALL_PRODUCT => '/products',
PageSectionEnum::PRODUCT_SPOTLIGHT => '/products',
PageSectionEnum::PRODUCT_SUGGESTION => '/products',
PageSectionEnum::PRODUCT_COURSE => '/courses',
PageSectionEnum::PRODUCT_SUBSCRIPTION => '/plans',
PageSectionEnum::PRODUCT_COMBO => '/combos',
PageSectionEnum::PRODUCT_LIVE => '/lives',
PageSectionEnum::PRODUCT_BY_CATEGORY => $categoryLink,
PageSectionEnum::PRODUCT_WISHLIST => '/wishlist',
PageSectionEnum::COURSE_STARTED => '/resume',
];
return isset($links[$typeItem]) ? $links[$typeItem] : "/";
}
public function isPageSection($pageSection) {
return $pageSection instanceof PageSection;
}
public function pageSectionShowAll(PageSection $pageSection)
{
$typeItem = $pageSection->getTypeItem();
$allItem = $pageSection->getAllItem() == PageSectionEnum::YES;
$item = json_decode($pageSection->getItem());
$limit = $pageSection->getNumberOfLine() * $pageSection->getNumberPerLine();
$items = [];
$productType = [
PageSectionEnum::ALL_PRODUCT,
PageSectionEnum::PRODUCT_SPOTLIGHT,
PageSectionEnum::PRODUCT_SUGGESTION,
PageSectionEnum::PRODUCT_COURSE,
PageSectionEnum::PRODUCT_SUBSCRIPTION,
PageSectionEnum::PRODUCT_COMBO,
PageSectionEnum::PRODUCT_LIVE,
PageSectionEnum::PRODUCT_BY_CATEGORY,
PageSectionEnum::PRODUCT_WISHLIST,
];
//CATEGORY,
//TEACHER,
//FAQ,
//TESTIMONIAL
if(in_array($typeItem, $productType)){
if($typeItem == PageSectionEnum::PRODUCT_WISHLIST && !$this->user){
return [];
}
$productIds = (
!$allItem && !empty($item) && is_array($item) ?
$item :
null
);
$productRepository = $this->em->getRepository(Product::class);
if(empty($productIds) && $typeItem == PageSectionEnum::PRODUCT_SUGGESTION){
$productIds = $productRepository->getProductsInCache();
}
$typeOriginal = [
PageSectionEnum::PRODUCT_COURSE => ProductEnum::COURSE,
PageSectionEnum::PRODUCT_SUBSCRIPTION => ProductEnum::SUBSCRIPTION,
PageSectionEnum::PRODUCT_COMBO => ProductEnum::COMBO,
PageSectionEnum::PRODUCT_LIVE => ProductEnum::LIVE,
];
$productOfferRepository = $this->em->getRepository(ProductOffer::class);
$total = $productOfferRepository->countPublicProductOffersNew([
"type" => (
isset($typeOriginal[$typeItem]) ?
$typeOriginal[$typeItem] :
null
),
"category" => (
$typeItem == PageSectionEnum::PRODUCT_BY_CATEGORY &&
$pageSection->getCategory() ?
$pageSection->getCategory()->getId() :
null
),
"spotlight" => (
$typeItem == PageSectionEnum::PRODUCT_SPOTLIGHT ?
PageSectionEnum::YES :
PageSectionEnum::NO
),
"wishlist" => (
$typeItem == PageSectionEnum::PRODUCT_WISHLIST ?
PageSectionEnum::YES :
PageSectionEnum::NO
),
"productIds" => $productIds,
]);
return ($total > $limit);
}else if($typeItem == PageSectionEnum::COURSE_STARTED && $this->getUser()){
return true;
}
return false;
}
public function getPlanCycleString(int $cycleOption){
return $this->em->getRepository(UserSubscription::class)->getPlanCycleString(
$cycleOption
);
}
public function getPlanCycleStringProductDetail(int $cycleOption){
return $this->em->getRepository(UserSubscription::class)->getPlanCycleStringProductDetail(
$cycleOption
);
}
public function getDocumentFormat(int $document){
$cnpj_cpf = preg_replace("/\D/", '', $document);
if (strlen($cnpj_cpf) === 11) {
return preg_replace("/(\d{3})(\d{3})(\d{3})(\d{2})/", "\$1.\$2.\$3-\$4", $cnpj_cpf);
}
return preg_replace("/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/", "\$1.\$2.\$3/\$4-\$5", $cnpj_cpf);
}
public function getUserSubscriptionError($errorMessage){
$errorMessage = explode("MESSAGE: ", $errorMessage);
return $errorMessage[1];
}
public function getVimeoFormatIframe(string $link){
$url = null;
if(strpos($link, '/manage/videos')){
$url = str_replace('/manage/videos', '', $link);
}
return $url;
}
public function isValidCard($dateExpire)
{
$y = (int)date('y');
$m = (int)date('m');
$expire = explode('/', $dateExpire);
$ySave = (int)$expire[1];
$mSave = (int)$expire[0];
if($y > $ySave || ($y == $ySave && $m >= $mSave)){
return false;
}
return true;
}
public function stringOrigin($origin)
{
$string = '';
switch ($origin) {
case EnrollmentEnum::ORIGIN_FREE:
$string = $this->getConfiguration()->getLanguage(
'free', 'enrollments'
);
break;
case EnrollmentEnum::ORIGIN_SALE:
$string = $this->getConfiguration()->getLanguage(
'sale', 'enrollments'
);
break;
case EnrollmentEnum::ORIGIN_SUBSCRIPTION:
$string = $this->getConfiguration()->getLanguage(
'subscription', 'enrollments'
);
break;
case EnrollmentEnum::ORIGIN_GROUP:
$string = $this->getConfiguration()->getLanguage(
'group', 'enrollments'
);
break;
case EnrollmentEnum::ORIGIN_COUPOM:
$string = $this->getConfiguration()->getLanguage(
'coupom', 'enrollments'
);
break;
case EnrollmentEnum::ORIGIN_API:
$string = 'Api';
break;
case EnrollmentEnum::ORIGIN_CHARGE:
$string = $this->getConfiguration()->getLanguage(
'charge', 'enrollments'
);
break;
}
return $string;
}
public function stringStatus(Enrollment $enrollment)
{
$string = '';
switch ($enrollment->getStatus()) {
case EnrollmentEnum::STATUS_ACTIVE:
if(strtotime($enrollment->getDatePeriod('Y-m-d')) < strtotime(date('Y-m-d'))){
$string = $this->getConfiguration()->getLanguage(
'expired', 'enrollments'
);
}else{
$string = $this->getConfiguration()->getLanguage(
'active', 'enrollments'
);
}
break;
case EnrollmentEnum::STATUS_SUSPENDED:
$string = $this->getConfiguration()->getLanguage(
'suspended', 'enrollments'
);
break;
case EnrollmentEnum::STATUS_CANCELED:
$string = $this->getConfiguration()->getLanguage(
'canceled', 'enrollments'
);
break;
}
return $string;
}
}