<?php
namespace App\Utils;
use App\Entity\Gos\Country;
use App\Entity\Gos\Coupon;
use App\Entity\Gos\PortalSettings;
use App\Entity\Gos\ProductPack;
use App\Entity\Gos\ProductVariant;
use App\Entity\Gos\User;
use App\Utils\Region\CountryService;
use App\Entity\Gos\Uniqskills\Course;
use App\Entity\Gos\Uniqskills\Landing\Landing;
use App\Entity\Gos\Uniqskills\Landing\LandingModule;
use App\Entity\Gos\Uniqskills\Landing\LandingModuleBoolean;
use App\Entity\Gos\Uniqskills\Landing\LandingModuleFile;
use App\Entity\Gos\Uniqskills\Landing\LandingModuleItem;
use App\Entity\Gos\Uniqskills\Landing\LandingModuleJson;
use App\Entity\Gos\Uniqskills\Landing\LandingModuleText;
use Psr\Log\LoggerInterface;
use DOMDocument;
use Symfony\Component\Filesystem\Filesystem;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\RouterInterface;
class LandingCourse
{
protected EntityManagerInterface $em;
private ?Request $request;
private LoggerInterface $logger;
private RouterInterface $router;
private Geolocation $geolocation;
private CountryService $countryService;
private KernelInterface $kernel;
function __construct(
EntityManagerInterface $em,
RequestStack $requestStack,
LoggerInterface $logger,
RouterInterface $router,
Geolocation $geolocation,
CountryService $countryService,
KernelInterface $kernel
) {
$this->em = $em;
$this->request = $requestStack->getCurrentRequest();
$this->logger = $logger;
$this->router = $router;
$this->geolocation = $geolocation;
$this->countryService = $countryService;
$this->kernel = $kernel;
}
/**
* Prepare all data for displaying on landing page
*/
public function prepareLandingData(Course $course, User $user = null): array
{
if (!$myCountryCode = $this->request->getSession()->get('myCountryCode'))
{
$myCountryCode = $this->geolocation->geolocation()['countryCode'];
$this->request->getSession()->set('myCountryCode', $myCountryCode);
}
$productVariants = $this->em->getRepository(ProductVariant::class)->findAllByCourseAndCountryCode(
$course->getSlug(),
$myCountryCode
);
$productPacks = $this->em->getRepository(ProductPack::class)->findAllWithCourses();
$config = $this->em->getRepository(PortalSettings::class)->find($this->request->getSession()->get('domain', 0));
if (empty($productVariants))
{
$this->logger->error(
'NO_COUNTRY: Nie znaleziono wariantów dla kursu '
. $course->getSlug()
. ' dla kraju '
. $myCountryCode
. ' ip:'
. $this->request->server->get('HTTP_X_FORWARDED_FOR')
);
}
if (empty($user) || empty($user->getCountry()))
{
$userCountry = $this->countryService->getCountry($this->request);
if (!empty($userCountry))
{
$userCountry = $userCountry->getId();
}
}
else
{
$userCountry = $user->getCountry()->getId();
}
if (!empty($productVariants))
{
$countryEntity = $productVariants[0]->getCountry();
}
else
{
$countryEntity = $this->em->getRepository(Country::class)->findOneBySlug('united-states');
}
$courseOrderLinkSub = [];
$courseGiftLinkSub = [];
$productVariantInfo = [];
/** @var ProductVariant $productVariant */
foreach ($productVariants as $productVariant)
{
$locale = $this->request->getSession()->get('userLocale', 'pl');
$courseOrderLinkSub[$productVariant->getProductVariantNoComplete()] = $this->router->generate('fmProductCartFrontendAdd', [
'productVariantNoComplete' => $productVariant->getProductVariantNoComplete(),
'returnCart' => true,
'source' => 'uniqskills',
'_locale' => $locale
]);
if ($productVariant->getIsGiftable())
{
$courseGiftLinkSub[$productVariant->getProductVariantNoComplete()] = $this->router->generate('fmProductCartFrontendAdd', [
'productVariantNoComplete' => $productVariant->getProductVariantNoComplete(),
'returnCart' => true,
'source' => 'uniqskills'
]);
}
$productVariantInfo[$productVariant->getId()] = array();
$productVariantInfo[$productVariant->getId()]['net'] = $productVariant->getFullPrice('net');
$productVariantInfo[$productVariant->getId()]['gross'] = $productVariant->getFullPrice('gross');
$productVariantInfo[$productVariant->getId()]['country'] = $productVariant->getCountry()->getId();
$productVariantInfo[$productVariant->getId()]['currency'] = $productVariant->getCountry()->getCurrency()->getCode();
$productVariantInfo[$productVariant->getId()]['access'] = $productVariant->getCountry()->getId() == $userCountry;
}
return [
'config' => $config,
'countryEntity' => $countryEntity,
'productVariants' => $productVariants,
'productPacks' => $productPacks,
'courseOrderLinkSub' => $courseOrderLinkSub,
'courseGiftLinkSub' => $courseGiftLinkSub,
'productVariantInfo' => $productVariantInfo
];
}
private function getModuleClassIcon($moduleName): string
{
$icons = [
'basicDescription',
'description',
'courseContent',
'courseProgram',
'faq',
'finishCourse',
'payment',
'tutors',
'contact'
];
if (in_array($moduleName, $icons))
{
return 'bgs2-' . $moduleName;
}
else
{
return '';
}
}
/**
* Build array with landing data for displaying in frontend
*/
public function buildLandingData(Landing $landing): array
{
/** @var LandingModule $landingModule */
/** @var LandingModuleFile|LandingModuleJson|LandingModuleBoolean|LandingModuleText $landingModuleItem */
$landingData = [];
$landingData['landing'] = $landing;
//sort by landing module position
$landingModules = [];
foreach ($landing->getLandingModules() as $landingModule)
{
$landingModules[intval($landingModule->getPosition())] = $landingModule;
}
ksort($landingModules);
foreach ($landingModules as $key => $landingModule)
{
$type = $landingModule->getLandingModuleType()->getName();
$landingData['modules'][$key]['showModule'] = $landingModule->getIsVisible();
$landingData['modules'][$key]['type'] = $type;
$landingData['modules'][$key]['inSecondMenu'] = $landingModule->getInSecondMenu();
$landingData['modules'][$key]['id'] = $landingModule->getId();
$landingData['modules'][$key]['linkIconClass'] = $this->getModuleClassIcon($type);
foreach ($landingModule->getLandingModuleItems() as $landingModuleItem)
{
$variableName = $landingModuleItem->getVariableName();
$variableType = $landingModuleItem->getVariableType();
if ($variableType == 'file')
{
$landingData['modules'][$key][$variableName] = $landingModuleItem;
}
elseif ($variableType == 'json')
{
$landingData['modules'][$key][$variableName] = $landingModuleItem->getVariableValueDecoded();
}
else
{
$landingData['modules'][$key][$variableName] = $landingModuleItem->getVariableValue();
}
}
}
return $landingData;
}
/**
* Generate landing page twig template from index.html
*/
public function landingCourseGenerationTemplate($course): void
{
$path = $this->kernel->getProjectDir() . '/public/landing/' . $course->getCategory()->getLanguage()->getCode() . '/' . $course->getSlug();
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$html = file_get_contents($path . '/index.html' );
// it's a fix to disable moving {{ codeHead }} into a <p> tag
$html = str_replace('{{ codeHead|raw }}', '<!-- {{ codeHead|raw }} -->', $html);
$doc->loadHTML($html);
$doc = $this->editUrlTags($doc, $course, 'script', 'src');
$doc = $this->editUrlTags($doc, $course, 'link', 'href');
$doc = $this->editUrlTags($doc, $course, 'img', 'src');
$doc = $this->editCourseOrderLinkSub($doc, $course);
$outputHtml = $doc->saveHTML();
$outputHtml = str_replace('<!-- {{ codeHead|raw }} -->', '{{ codeHead|raw }}', $outputHtml);
$body = rawurldecode($outputHtml);
$twigPage = fopen($path . '/index.html.twig', "w");
fwrite($twigPage, $body);
fclose($twigPage);
}
private function editCourseOrderLinkSub($doc, Course $course)
{
$exists = [];
foreach ($course->getProductVariants() as $prod)
{
$exists[] = $prod->getProductVariantNoComplete();
}
$scriptTags = $doc->getElementsByTagName('a');
foreach ($scriptTags as $scriptTag)
{
if ($scriptTagSrc = $scriptTag->getAttribute('href'))
{
if (preg_match('/courseOrderLinkSub\./', $scriptTagSrc))
{
$element = explode('.', str_replace(['{{', '}}', ' '], '', $scriptTagSrc));
$index = $element[1];
$fromOldIndex = $this->getSubscriptionFromOldUS($index);
if ($fromOldIndex and in_array($fromOldIndex, $exists))
{
$scriptTag->setAttribute('href', '{{ courseOrderLinkSub[\'' . $fromOldIndex . '\'] }}');
}
else
{
$scriptTag->setAttribute('href', '#');
}
}
}
}
return $doc;
}
/**
* Replace url in landing page
*/
private function editUrlTags($doc, $course, $tagName, $tagAttribute)
{
$scriptTags = $doc->getElementsByTagName($tagName);
foreach ($scriptTags as $scriptTag)
{
if ($scriptTagSrc = $scriptTag->getAttribute($tagAttribute))
{
if (!preg_match_all('/^http/', $scriptTagSrc))
{
$scriptTagSrc = trim($scriptTagSrc, '/');
$scriptTag->setAttribute($tagAttribute,
'https://' . $this->request->getHost() . '/landing/' . $course->getCategory()->getLanguage()->getCode() . '/' . $course->getSlug() . '/' . $scriptTagSrc);
}
}
}
return $doc;
}
/**
* Replace old variables price to new
*/
public function replaceOldVariablesPriceToNew(Course $course): void
{
$projectDir = $this->kernel->getProjectDir();
$courseLanguage = $course->getCategory()->getLanguage()->getCode();
$path = $projectDir . '/public/landing/' . $courseLanguage . '/' . $course->getSlug() . '/index.html.twig';
$body = file_get_contents($path);
$newPrice = '{% include \'/uniqskills/frontend/price.html.twig\' with {
\'price\': $2,
\'country\': countryEntity,
\'type\': 0} %}';
$body = preg_replace('/(\$*)\{\{( (\(*)subscription.grossPrice(.*?) )\}\}/', $newPrice, $body);
$body = preg_replace('/(\$*)\{\{( (\(*)course.defaultPrice(.*?) )\}\}/', $newPrice, $body);
(new Filesystem())->dumpFile($path, $body);
}
public function appendScriptToBody(Course $course): void
{
$projectDir = $this->kernel->getProjectDir();
$courseLanguage = $course->getCategory()->getLanguage()->getCode();
$path = $projectDir . '/public/landing/' . $courseLanguage . '/' . $course->getSlug() . '/index.html.twig';
$body = file_get_contents($path);
$content = '<script>window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
\'course\': ' . $course->getId() . '
});</script></body>';
if (!strpos($body, $content))
{
$body = str_replace('</body>', $content, $body);
(new Filesystem())->dumpFile($path, $body);
}
}
/**
* Returns redirect data for course landing
*/
public function landingRedirect(array $urlParams, Course $course, $locale)
{
$slug = $urlParams['slug'];
$categorySlug = $urlParams['categorySlug'];
$subCategory = $urlParams['subCategory'];
$keyword = $urlParams['keyword'];
if (($courseLocale = $course->getCategory()->getLanguage()->getCode()) != $locale)
{
return [
'route' => 'fmUniqskillsCourseLandingNoCategory',
'parameters' => [
'slug' => $slug,
'_locale' => $courseLocale
]
];
}
if ($course)
{
$parentCategory = $course->getCategory()->getParent();
$category = $course->getCategory();
$mainKeyword = $course->getMainKeyword();
// hard to redirect it in a different way
// 301 redirect
if (
(!($subCategory && $keyword) && $parentCategory && $mainKeyword) ||
(($parentCategory && $category && $mainKeyword) &&
($categorySlug != $parentCategory->getCategorySlug() || $subCategory != $category->getCategorySlug() ||
$keyword != $mainKeyword->getName())
)
)
{
$parameters = [
'categorySlug' => $parentCategory->getCategorySlug(),
'subCategory' => $category->getCategorySlug(),
'keyword' => $mainKeyword->getName(),
'slug' => $course->getSlug()
];
//redirect to /main-category/sub-category/course-keyword/slug url format if all needed data is set for course
return [
'parameters' => $parameters,
'route' => 'fmUniqskillsCourseLandingExpanded'
];
}
elseif
(
(
!$parentCategory
|| !$mainKeyword
)
&& $categorySlug != $course->getCategory()->getCategorySlug()
)
{
$parameters = [
'categorySlug' => $category->getCategorySlug(),
'slug' => $course->getSlug()
];
return [
'parameters' => $parameters,
'route' => 'fmUniqskillsCourseLanding'
];
}
}
if (!$course)
{
if ($locale == 'pl')
{
return [
'route' => 'fmUniqskillsFrontendPlCourseCataloguePage',
'parameters' => []
];
}
else
{
return [
'route' => 'fmUniqskillsFrontendCourseCataloguePage',
'parameters' => []
];
}
}
elseif (!empty($course->getRedirectToUrl()))
{
return $course->getRedirectToUrl();
}
elseif (!empty($course->getNextCourse()))
{
$nextCourse = $course->getNextCourse();
return [
'parameters' => [
'categorySlug' => $nextCourse->getCategory()->getCategorySlug(),
'slug' => $nextCourse->getSlug()
],
'route' => 'fmUniqskillsCourseLanding'
];
}
elseif (
!file_exists($this->kernel->getProjectDir() . '/public/landing/' .
$course->getCategory()->getLanguage()->getCode() . '/' . $course->getSlug() . '/index.html.twig')
&& (
$course->getNewLandingPage() === null
|| !$course->getNewLandingPage()->getIsActive()
)
)
{
// TODO: kiedyś przenosiło na formularz zamówienia ale teraz taki nie istnieje
return '404';
}
return false;
}
public function getPromotionBar(Course $course): ?string
{
$landing = $course->getNewLandingPage();
$landingPackagePath = $this->kernel->getProjectDir() . '/public/landing/' .
$course->getCategory()->getLanguage()->getCode() . '/' . $course->getSlug() . '/index.html.twig';
if ($landing)
{
$promotionBar = null;
foreach ($landing->getLandingModules() as $landingModule)
{
/** @var LandingModule $landingModule */
if ($landingModule->getLandingModuleType()->getName() == 'promotionBar')
{
foreach ($landingModule->getLandingModuleItems() as $landingModuleItem)
{
/** @var LandingModuleItem $landingModuleItem */
if ($landingModuleItem->getVariableName() == 'text')
{
return $landingModuleItem->getVariableValue();
}
}
}
}
}
elseif (file_exists($landingPackagePath))
{
try
{
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTMLFile($landingPackagePath);
$xpath = new \DOMXPath($dom);
$html = null;
$element = $xpath->query('//div[@class="promotionBar-content"]')->item(0);
if ($element)
{
$html = $element->textContent;
}
if ($html == '')
return null;
else
return $html;
}
catch (\Exception $e)
{
return null;
}
}
return null;
}
/**
* Remove all doms recursivly and returns pure text
*/
private function packageDomPureText($node, $dom)
{
$html = '';
if ($node->childNodes)
{
foreach ($node->childNodes as $childNode)
{
$html = $this->packageDomPureText($childNode, $dom);
}
}
else
{
$html = $dom->saveXML($node);
}
return $html;
}
private function getSubscriptionFromOldUS($index)
{
$old = [
1 => '9101/2',
2 => '9101/1',
3 => '9301/1',
4 => '9302/1',
5 => '9303/1',
6 => '9304/1',
7 => '9306/1',
8 => '9307/1',
9 => '9305/1',
10 => '9308/1',
11 => '9103/1',
12 => '9103/9',
13 => '9103/5',
14 => '9103/12',
15 => '9301/2',
16 => '9302/2',
17 => '9304/2',
18 => '9303/2',
19 => '9308/2',
20 => '9306/2',
21 => '9307/2',
22 => '9305/2',
23 => '9309/1',
24 => '9310/1',
25 => '9311/1',
26 => '9312/1',
27 => '9313/1',
28 => '9314/1',
29 => '9315/1',
30 => '9316/1',
31 => '9317/1',
32 => '9318/1',
33 => '9319/1',
34 => '9320/4',
35 => '9321/4',
36 => '9322/4',
37 => '9401/2',
38 => '9402/2',
39 => '9403/2',
40 => '9404/2',
41 => '9405/2',
42 => '9406/2',
43 => '9407/2',
44 => '9408/2',
45 => '9301/3',
46 => '9302/3',
47 => '9304/3',
48 => '9303/3',
49 => '9313/2',
50 => '9314/2',
51 => '9315/2',
52 => '9316/2',
53 => '9317/2',
60 => '9308/3',
61 => '9306/3',
62 => '9307/3',
63 => '9305/3',
64 => '9318/2',
65 => '9319/2',
66 => '9320/2',
67 => '9321/2',
68 => '9322/2',
75 => '9201/1',
76 => '9201/2',
77 => '9409/1',
78 => '9410/1',
79 => '9411/1',
80 => '9412/1',
81 => '9413/1',
82 => '9414/1',
83 => '9415/1',
84 => '9416/1',
85 => '8671/1',
86 => '9105/1',
87 => '9305/4',
88 => '9306/4',
89 => '9307/4',
90 => '9308/4',
91 => '9318/3',
93 => '9320/3',
94 => '9321/3',
95 => '9322/3',
96 => '9301/4',
97 => '9302/4',
98 => '9304/4',
99 => '9303/4',
100 => '9313/3',
101 => '9314/3',
102 => '9315/3',
103 => '9316/3',
104 => '9317/3',
106 => '8673/1',
107 => '9502/1',
108 => '9501/1',
109 => '9507/1',
110 => '9509/1',
111 => '9505/1',
112 => '9106/1',
113 => '9504/1',
114 => '9503/1',
115 => '9105/3',
116 => '9319/3',
117 => '9508/1',
118 => '9323/1',
119 => '9324/1',
120 => '9325/1',
121 => '9326/1',
122 => '9327/1',
123 => '9328/1',
124 => '9329/1',
125 => '9330/1',
126 => '9331/1',
127 => '9350/1',
128 => '9351/1',
129 => '9352/1',
130 => '9353/1',
131 => '9354/1',
132 => '9355/1',
133 => '9356/1',
134 => '9357/1',
135 => '9358/1',
136 => '9417/1',
137 => '9418/1',
138 => '9419/1',
139 => '9420/1',
140 => '9421/1',
141 => '9422/1',
142 => '9423/1',
143 => '9424/1',
146 => '9341/1',
147 => '9342/1',
148 => '9343/1',
149 => '9344/1',
150 => '9345/1',
151 => '9346/1',
152 => '9347/1',
153 => '9348/1',
154 => '9349/1',
155 => '9107/1',
156 => '9506/1',
157 => '9332/1',
158 => '9333/1',
159 => '9334/1',
160 => '9335/1',
161 => '9336/1',
162 => '9337/1',
163 => '9338/1',
164 => '9339/1',
165 => '9340/1',
166 => '9301/5',
167 => '9302/5',
168 => '9303/5',
169 => '9304/5',
170 => '9313/4',
171 => '9314/4',
172 => '9315/4',
173 => '9316/4',
174 => '9317/4',
175 => '9401/2',
176 => '9402/2',
177 => '9403/2',
178 => '9404/2',
179 => '9405/2',
180 => '9435/1',
181 => '9407/2',
182 => '9408/2',
183 => '9432/1',
184 => '9431/1',
185 => '9406/2',
186 => '9434/1',
187 => '9436/1',
188 => '9429/1',
189 => '9428/1',
190 => '9427/1',
191 => '9426/1',
192 => '9425/1',
193 => '9430/1',
194 => '9510/1',
195 => '9107/9',
196 => '9106/9',
197 => '9105/9',
198 => '9512/1',
199 => '9320/4',
200 => '9305/5',
201 => '9322/4',
202 => '9321/4',
203 => '9318/4',
204 => '9308/5',
205 => '9307/5',
206 => '9306/5',
207 => '9319/4',
208 => '9511/1',
209 => '9513/1',
210 => '9433/1',
211 => '9410/2',
212 => '9411/2',
213 => '9412/2',
214 => '9413/2',
215 => '9415/2',
216 => '9416/2',
217 => '9409/2',
218 => '9414/2',
219 => '9514/1',
220 => '9515/1',
221 => '9109/1',
222 => '9109/2',
223 => '9111/1',
224 => '9111/2',
225 => '9516/1',
226 => '9108/1',
227 => '9108/2',
228 => '9110/1',
229 => '9110/2',
230 => '9359/1',
231 => '9360/1',
232 => '9361/1',
233 => '9362/1',
234 => '9363/1',
235 => '9364/1',
236 => '9365/1',
237 => '9366/1',
238 => '9367/1',
239 => '9517/1',
242 => '9518/1',
243 => '9377/1',
244 => '9378/1',
245 => '9379/1',
246 => '9380/1',
247 => '9381/1',
248 => '9382/1',
249 => '9383/1',
250 => '9384/1',
251 => '9385/1',
252 => '9368/1',
253 => '9369/1',
254 => '9370/1',
255 => '9371/1',
256 => '9372/1',
257 => '9373/1',
258 => '9374/1',
259 => '9375/1',
260 => '9376/1',
261 => '9120/1',
262 => '9120/2',
263 => '9120/3',
264 => '9114/1',
265 => '9114/2',
266 => '9114/5',
267 => '9437/1',
268 => '9438/1',
269 => '9439/1',
270 => '9440/1',
271 => '9441/1',
272 => '9445/1',
273 => '9442/1',
274 => '9443/1',
275 => '9444/1',
276 => '9112/1',
277 => '9112/2',
278 => '9114/6',
279 => '9115/1',
280 => '9115/2',
281 => '9521/1',
282 => '9446/1',
283 => '9447/1',
284 => '9448/1',
285 => '9449/1',
286 => '9450/1',
287 => '9451/1',
288 => '9452/1',
289 => '9453/1',
290 => '9454/1',
291 => '9519/1',
292 => '9118/1',
293 => '9118/2',
294 => '9116/1',
295 => '9116/2',
296 => '9386/1',
297 => '9387/1',
298 => '9388/1',
299 => '9389/1',
300 => '9390/1',
301 => '9391/1',
302 => '9392/1',
303 => '9393/1',
304 => '9394/1',
305 => '9522',
306 => '9523',
307 => '9395/1',
308 => '9396/1',
309 => '9397/1',
310 => '9398/1',
311 => '9399/1',
312 => '93100/1',
313 => '93101/1',
314 => '93102/1',
315 => '93103/1',
316 => '9524/1',
317 => '9117/1',
318 => '9117/2',
319 => '9123/2',
320 => '9123/3',
321 => '9123/4',
322 => '9122/1',
323 => '9122/2',
324 => '91120/1',
325 => '9119/1',
326 => '9119/2',
327 => '9127/1',
328 => '9127/2',
329 => '9128/1',
330 => '9128/2',
331 => '9415/1',
332 => '9129/1',
333 => '9129 /2',
334 => '9121/1',
335 => '9126/1',
336 => '9126/2',
337 => '9130/1',
338 => '9130/2',
339 => '9124/1',
340 => '9124/2',
343 => '9132/1',
344 => '9132',
345 => '9131/1',
346 => '9131/2',
347 => '9464/1',
348 => '9465/1',
349 => '9466/1',
350 => '9467/1',
351 => '9468/1',
352 => '9469/1',
353 => '9470/1',
354 => '9471/1',
355 => '9472/1',
356 => '9153/1',
357 => '9153/2',
358 => '9455/1',
359 => '9456/1',
360 => '9457/1',
361 => '9458/1',
362 => '9459/1',
363 => '9460/1',
364 => '9461/1',
365 => '9462/1',
366 => '9463/1',
367 => '9133/1',
368 => '9133/2',
371 => '9134/1',
372 => '9134/2',
373 => '9137/1',
374 => '9125/1',
375 => '9125/2',
376 => '9475/1',
377 => '9474/1',
378 => '9476/1',
379 => '9477/1',
380 => '9478/1',
381 => '9479/1',
382 => '9480/1',
383 => '9481/1',
384 => '9482/1',
385 => '9137/4',
386 => '9139/1',
387 => '9139/2',
389 => '93104/1',
390 => '93105/1',
391 => '93106/1',
392 => '93107/1',
393 => '93108/1',
394 => '93109/1',
395 => '93110/1',
396 => '93111/1',
397 => '93112/1',
398 => '96001/1',
399 => '96201/1',
400 => '96101/1',
401 => '96002/1',
402 => '96202/1',
403 => '96102/1',
404 => '96003/1',
405 => '96203/1',
406 => '96103/1',
407 => '9136/1',
408 => '9136/2',
409 => '9135/1',
410 => '9135/2',
411 => '9140/1',
412 => '9140/2',
413 => '9141/1',
414 => '9141/2',
416 => '9142/1',
417 => '9142/2',
418 => '9483/1',
419 => '9484/1',
420 => '9485/1',
421 => '9486/1',
422 => '9487/1',
423 => '9488/1',
424 => '9489/1',
425 => '9490/1',
426 => '9491/1',
427 => '9143/1',
428 => '9143/2',
429 => '9144/2',
430 => '9144/1',
431 => '9154/1',
432 => '9137/5',
435 => '96104',
436 => '9492/1',
437 => '9493/1',
438 => '9494/1',
439 => '9495/1',
440 => '9496/1',
441 => '9497/1',
442 => '9498/1',
443 => '9499/1',
444 => '94100/1',
445 => '9150/1',
446 => '9150/2',
447 => '9147/1',
448 => '9147/2',
449 => '9148/1',
450 => '9151',
451 => '93113/1',
452 => '93114/1',
453 => '93115/1',
454 => '93116/1',
455 => '93117/1',
456 => '93118/1',
457 => '93119/1',
458 => '93120/1',
459 => '93121/1',
460 => '9151/2',
461 => '9149/1',
462 => '9149/2',
463 => '9152/1',
464 => '93122/1',
465 => '93123/1',
466 => '93124/1',
467 => '93125/1',
468 => '93126/1',
469 => '93127/1',
470 => '93128/1',
471 => '93129/1',
472 => '93130/1',
473 => '9155/1',
474 => '9155/2',
475 => '7916',
476 => '1761/1',
477 => '1761/2',
478 => '93131/1',
479 => '93132/1',
480 => '93133/1',
481 => '93134/1',
482 => '93135/1',
483 => '93136/1',
484 => '93137/1',
485 => '93138/1',
487 => '93140/1',
488 => '93141/1',
489 => '93142/1',
490 => '93143/1',
491 => '93144/1',
492 => '93145/1',
493 => '93146/1',
494 => '93147/1',
495 => '93148/1',
496 => '93139/1',
497 => '9113/1',
498 => '9113/2',
499 => '9128/5',
500 => '93149/1',
501 => '93150/1',
502 => '93151/1',
503 => '93152/1',
504 => '93153/1',
505 => '93154/1',
506 => '93155/1',
507 => '93156/1',
508 => '93157/1',
509 => '9157/1',
510 => 'product/0',
511 => '9158/1',
512 => '9162/2',
513 => '9162/1',
514 => '93158/1',
515 => '93159/1',
516 => '93160/1',
517 => '93161/1',
518 => '93162/1',
519 => '93163/1',
520 => '93164/1',
521 => '93165/1',
522 => '93166/1',
525 => '9165/1',
526 => '9165/2',
527 => '9164/1',
528 => '9164/2',
529 => '9163/1',
530 => '9163/2',
531 => '9166/1',
532 => '9166/2',
533 => '9159/1',
534 => '9160/1',
535 => '9167/1',
536 => '9167/2',
537 => '9168111/1',
538 => '9168111/2',
539 => '9161/1',
540 => '9161/2',
541 => '9146/1',
542 => '9171',
543 => '9172/1',
544 => '9173/1',
545 => '9173/2',
546 => '96004/1',
547 => '96105/1',
548 => '96204/1',
549 => '96005/1',
550 => '96205/1',
551 => '96106/1',
552 => '9174/1',
553 => 'errrr',
555 => '96006/1',
556 => '96107/1',
557 => '96206/1',
558 => '96007/1',
559 => '96108/1',
560 => '96207',
561 => '9170/1',
562 => '9170/2',
563 => '9176/1',
564 => '93167/1',
565 => '93168/1',
566 => '93169/1',
567 => '93170/1',
568 => '93171/1',
569 => '93172/1',
570 => '93173/1',
571 => '93174/1',
572 => '93175/1',
573 => '9179/1',
574 => '9179/2',
575 => '9175/1',
576 => '93176/1',
577 => '93177/1',
578 => '93178/1',
579 => '93179/1',
580 => '93180/1',
581 => '93181/1',
582 => '93182/1',
583 => '93183/1',
584 => '93184/1',
585 => '9182/1',
586 => '9182/2',
587 => '9181/1',
588 => '9156/1',
589 => '9156/2',
590 => '9180/1',
591 => '9180/2',
592 => '96109',
593 => '96008',
594 => '96110',
595 => '96009',
596 => '96111',
597 => '96010',
598 => '9185/1',
599 => '9185/3',
600 => '9185/4',
601 => '9185/5',
602 => '9184/1',
603 => '9184/2',
605 => '9186/1',
606 => '9187/1',
608 => '9202/1',
609 => '9202/2',
610 => '9169/1',
611 => '9203/1',
612 => '9203/2',
613 => '1766/2',
614 => '9204/1',
615 => '9204/2',
616 => '1766/1',
617 => '9205/1',
618 => '9205/2',
619 => '93185/1',
620 => '93186/1',
621 => '93187/1',
622 => '93188/1',
623 => '93189/1',
624 => '93190/1',
625 => '93191/1',
626 => '93192/1',
627 => '93193/1',
628 => '91100/1',
629 => '96112/1',
630 => '96011',
631 => '96012/1',
632 => '96113/1',
633 => '93203/1',
634 => '93204/1',
635 => '93205/1',
636 => '93206/1',
637 => '93207/1',
638 => '93208/1',
639 => '93209/1',
640 => '93210/1',
641 => '93211/1',
642 => '96017/1',
643 => '96118/1',
644 => '93194/1',
645 => '93195/1',
646 => '93196/1',
647 => '93197/1',
648 => '93198/1',
649 => '93199/1',
650 => '93200/1',
651 => '93201/1',
652 => '93202/1',
653 => '96013/1',
654 => '96114/1',
655 => '96015/1',
656 => '96116',
657 => '96016/1',
658 => '96117/1',
659 => '96014/1',
660 => '96115/1',
661 => '91101/1',
662 => '9206/1',
663 => '9206/2',
664 => '93221/1',
665 => '93222/1',
666 => '93223/1',
667 => '93224/1',
668 => '93225/1',
669 => '93226/1',
670 => '93227/1',
671 => '93228/1',
672 => '93229/1',
673 => '91131/1',
674 => '91131/2',
675 => '9207/1',
676 => '9207/2',
677 => '9188/1',
678 => '9188/2',
679 => '9190/1',
680 => '9190/2',
681 => '91102/1',
682 => '9138/2',
683 => '9138/1',
684 => '93239/1',
685 => '93240/1',
686 => '93241/1',
687 => '93242/1',
688 => '93243/1',
689 => '93244/1',
690 => '93245/1',
691 => '93246/1',
692 => '93247/1',
693 => '9999/1',
694 => '9191/1',
695 => '9191/2',
698 => '91132/1',
699 => '91132/2',
700 => '9189/1',
701 => '9189/2',
702 => '9185/2',
703 => '91133/1',
704 => '91133/2',
705 => '91135/1',
706 => '91135/2',
707 => '91103/1',
708 => '9193/1',
709 => '9193/2',
710 => '93248/1',
711 => '93249/1',
712 => '93250/1',
713 => '93251/1',
714 => '93252/1',
715 => '93253/1',
716 => '93254/1',
717 => '93255/1',
718 => '93256/1',
719 => '93212/1',
720 => '93213/1',
721 => '93214/1',
722 => '93215/1',
723 => '93216/1',
724 => '93217/1',
725 => '93218/1',
726 => '93219/1',
727 => '93220/1',
728 => '91137/1',
729 => '91137/2',
730 => '91136/1',
731 => '91136/2',
732 => '91138/1',
733 => '91138/2',
734 => '9401',
735 => '9188/5',
736 => '9188/6',
737 => '9188/7',
738 => '9188/8',
739 => '9188/9',
740 => '93257/1',
741 => '93258/1',
742 => '93259/1',
743 => '93260/1',
744 => '93261/1',
745 => '93262/1',
746 => '93263/1',
747 => '93264/1',
748 => '93265/1',
749 => '93212',
750 => '93213',
751 => '93214',
752 => '93215',
753 => '93216',
754 => '93217',
755 => '93218',
756 => '93219',
757 => '93220',
758 => '9192/1',
759 => '9192/2',
760 => '91140/1',
761 => '91140/2',
762 => '91139/1',
763 => '91139/2',
764 => '9195/1',
765 => '91144/1',
766 => '91144/2',
767 => '9208/1',
768 => '9208/2',
769 => '96301/1',
770 => '96401/1',
771 => '96501/1',
772 => '96601/1',
773 => '96701/1',
774 => '96801/1',
775 => '96901/1',
776 => '96302/1',
777 => '96402/1',
778 => '96502/1',
779 => '96602/1',
780 => '96702/1',
781 => '96802/1',
782 => '96902/1',
783 => '91141/1',
784 => '9196/1',
785 => '9196/2',
786 => '91104/1',
787 => '91143/1',
788 => '91143/2',
789 => '91142/1',
790 => '91142/2',
791 => '96303/1',
792 => '96403/1',
793 => '96503/1',
794 => '96603/1',
795 => '96703/1',
796 => '96803/1',
797 => '96903/1',
798 => '93275/1',
799 => '93276/1',
800 => '93277/1',
801 => '93278/1',
802 => '93279/1',
803 => '93280/1',
804 => '93281/1',
805 => '93282/1',
806 => '93283/1',
807 => '93266/1',
808 => '93267/1',
809 => '93268/1',
810 => '93269/1',
811 => '93270/1',
812 => '93271/1',
813 => '93272/1',
814 => '93273/1',
815 => '93274/1',
816 => '9197/1',
817 => '96702/1',
818 => '97102',
819 => '97003/1',
820 => '97103',
821 => '97001/1',
822 => '97101/1',
823 => '93293/1',
824 => '93294/1',
825 => '93295/1',
826 => '93296/1',
827 => '93297/1',
828 => '93298/1',
829 => '93299/1',
830 => '93300/1',
831 => '93301/1',
832 => '9209/1',
833 => '9209/2',
834 => '91105/1',
835 => '91145/5',
836 => '91145/6',
837 => '91146/1',
838 => '91146/2',
839 => '7921',
840 => '91147/1',
841 => '91147/2',
842 => '91148/1',
843 => '91148/2',
844 => '91170/1',
845 => '9210/1',
846 => '9210/2',
847 => '91150/1',
848 => '91150/2',
849 => '91106/1',
850 => '93284/1',
851 => '93285/1',
852 => '93286/1',
853 => '93287/1',
854 => '93288/1',
855 => '93289/1',
856 => '93290/1',
857 => '93291/1',
858 => '93292/1',
859 => '91153/1',
860 => '91153/2',
861 => '91107/1',
862 => '91108/1',
863 => '91108/2',
864 => '91149/1',
865 => '91149/2',
866 => '93302/1',
867 => '93303/1',
868 => '93304/1',
869 => '93305/1',
870 => '93306/1',
871 => '93307/1',
872 => '93308/1',
873 => '93309/1',
874 => '93310/1',
875 => '9211/1',
876 => '9211/2',
877 => '91154/1',
878 => '91154/2',
879 => '96906/1',
880 => '97006/1',
881 => '97106/1',
882 => '93311/1',
883 => '93312/1',
884 => '93313/1',
885 => '93314/1',
886 => '93315/1',
887 => '93316/1',
888 => '93317/1',
889 => '93318/1',
890 => '93319/1',
891 => '96904/1',
892 => '97004/1',
893 => '97104/1',
894 => '96909/1',
895 => '97009/1',
896 => '97109/1',
897 => '96905/1',
898 => '97005/1',
899 => '97105/1',
900 => '9212/1',
901 => '9212/2',
902 => '9213/1',
903 => '9213/2',
904 => '9214/1',
905 => '9214/2',
906 => '1768',
907 => '1771',
908 => '91110/1',
909 => '91151/1',
910 => '91151/2',
911 => '91165/1',
912 => '91165/2',
913 => '97205/1',
914 => '93320/1',
915 => '93321/1',
916 => '93322/1',
917 => '93323/1',
918 => '93324/1',
919 => '93325/1',
920 => '93326/1',
921 => '93327/1',
922 => '93328/1',
923 => '91155/1',
924 => '91155/2',
925 => '97107/1',
926 => '91112/1',
927 => '97201/1',
928 => '91111/1',
929 => '91111/2',
930 => '7926',
931 => '91156/1',
932 => '91156/2',
933 => '91113/1',
934 => '91157/1',
935 => '91157/2',
936 => '97202',
937 => '97203',
938 => '97204',
939 => '97205',
940 => '97206',
941 => '97207',
942 => '97208',
943 => '97209',
944 => '97210',
945 => '97211',
946 => '97212',
947 => '97213',
948 => '97214',
949 => '97215',
950 => '97216',
951 => '97217',
952 => '97218',
953 => '97219',
954 => '97220',
955 => '97221',
956 => '97222',
957 => '97223',
958 => '97103/2',
959 => '93329/1',
960 => '93330/1',
961 => '93331/1',
962 => '93332/1',
963 => '93333/1',
964 => '93334/1',
965 => '93335/1',
966 => '93336/1',
967 => '93337/1',
968 => '97224',
969 => '6300',
970 => '91116/1',
971 => '1767/1',
972 => '93338/1',
973 => '93339/1',
974 => '93340/1',
975 => '93341/1',
976 => '93342/1',
977 => '93343/1',
978 => '93344/1',
979 => '93345/1',
980 => '93346/1',
981 => '1772/1',
982 => '1772/2',
983 => '7927',
984 => '93347/1',
985 => '93348/1',
986 => '93349/1',
987 => '93350/1',
988 => '93351/1',
989 => '93352/1',
990 => '93353/1',
991 => '93354/1',
992 => '93355/1',
993 => '91117/1',
994 => '91166/1',
995 => '91166/2',
996 => '91167/1',
997 => '91167/2',
998 => '91114/1',
999 => '91118/1',
1000 => '91171/1',
1001 => '91171/2',
1002 => '91168/1',
1003 => '91168/2',
1004 => '7923',
1005 => '9168/1',
1006 => '9168/2',
1007 => '91169/1',
1008 => '91169/2',
1009 => '91192/1',
1010 => '91192/2',
1011 => '91195/1',
1012 => '91195/2',
1013 => '91194/1',
1014 => '91194/2',
1015 => '91198/1',
1016 => '91198/2',
1017 => '91193/1',
1018 => '91193/2',
1019 => '91199/1',
1020 => '91199/2',
1021 => '97225/1',
1022 => '91196/1',
1023 => '91196/2',
1024 => '91191/1',
1025 => '1770/1',
1026 => '1770/3',
1027 => '1770/2',
1028 => '91115/1',
1029 => '91197/1',
1030 => '91197/2',
1031 => '6301',
1032 => '6301\\2',
1033 => '91163/1',
1034 => '91163/2',
1035 => '91152/1',
1036 => '91152/2',
1037 => '97402/1',
1038 => '91158/1',
1039 => '91158/2',
1040 => '91159/1',
1041 => '91159/2',
1042 => '97401/1',
1043 => '97405/1',
1044 => '97403/1',
1045 => '97404/1',
1046 => '97406/1',
1047 => '97409/1',
1048 => '91119/1',
1049 => '91119/2',
1050 => '9199/1',
1051 => '9199/2',
1052 => '91201/1',
1053 => '97407/1',
1054 => '97408/1',
1055 => '9198/1',
1056 => '9198/2',
1057 => '97410/1',
1058 => '9122/6',
1059 => '9122/7',
1060 => '9215/1',
1061 => '9215/2',
1062 => '91172/1',
1063 => '91172/2',
1064 => '9128/6',
1065 => '9128/7',
1066 => '91203/1',
1067 => '91203/2',
1068 => '93356/1',
1069 => '93357/1',
1070 => '93358/1',
1071 => '93359/1',
1072 => '93360/1',
1073 => '93361/1',
1074 => '93362/1',
1075 => '93363/1',
1076 => '93364/1',
1077 => '9164/1',
1078 => '9164/2',
1079 => '9165/1',
1080 => '9165/2',
1081 => '91205/1',
1082 => '91205/2',
1083 => '97403/2',
1084 => '9153/5',
1085 => '9153/6',
1086 => '91192/6',
1087 => '91192/5',
1088 => '91195/7',
1089 => '91195/6',
1090 => '91211/1',
1091 => '91211/2',
1095 => '91148/6',
1096 => '91148/5',
1097 => '91208/1',
1098 => '91208/2',
1099 => '91149/6',
1100 => '91149/5',
1101 => '91151/6',
1102 => '91151/5',
1103 => '91159/6',
1104 => '91159/5',
1105 => '91206/6',
1106 => '91206/7',
1107 => '9163/5',
1108 => '9163/6',
1109 => '9167/4',
1110 => '9167/5',
1111 => '9179/5',
1112 => '9179/6',
1113 => '91111/5',
1114 => '91111/6',
1115 => '91152/5',
1116 => '91152/6',
1117 => '91165/5',
1118 => '91165/6',
1119 => '91166/5',
1120 => '91166/6',
1121 => '91169/5',
1122 => '91169/6',
1124 => '91212/1',
1125 => '91212/2',
1126 => '91173/1',
1127 => '91173/2',
1128 => '97411/1',
1129 => '97401/1',
1130 => '9216/1',
1131 => '9216/2',
1132 => '91121/1',
1133 => '91121/2',
1134 => '91198/6',
1135 => '91198/7',
1136 => '97226',
1137 => '91175/1',
1138 => '91175/2',
1139 => '91164/5',
1140 => '91164/6',
1141 => '97227',
1142 => '91161/1',
1143 => '91161/2',
1144 => '91162/1',
1145 => '91162/2',
1146 => '91213/1',
1147 => '91213/2',
1148 => '91160/1',
1149 => '91160/2',
1150 => '91214/1',
1151 => '91214/2',
1152 => '91177/1',
1153 => '91177/2',
1154 => '91215/1',
1155 => '91215/2',
1156 => '91216/1',
1157 => '91216/2',
1158 => '91217/1',
1159 => '91217/2',
1160 => '93365/1',
1161 => '93366/1',
1162 => '93367/1',
1163 => '93368/1',
1164 => '93369/1',
1165 => '93370/1',
1166 => '93371/1',
1167 => '93372/1',
1168 => '93373/1',
1169 => '91180/1',
1170 => '91180/2',
1171 => '6302/1',
1172 => '6302/2',
1173 => '91179/1',
1174 => '91179/2',
1175 => '91122/1',
1176 => '93369/1',
1177 => '91221/1',
1178 => '91221/2',
1179 => '91223/1',
1180 => '91223/2',
1181 => '93374/1',
1182 => '93375/1',
1183 => '93376/1',
1184 => '93377/1',
1185 => '93378/1',
1186 => '93379/1',
1187 => '93380/1',
1188 => '93381/1',
1189 => '93382/1',
1190 => '91222/1',
1191 => '91222/2',
1192 => '97229/1',
1193 => '97228/1',
1194 => '1769',
1195 => '91224/1',
1196 => '1111',
1197 => '93363/1',
1198 => '97231/1',
1199 => '93342/1',
1200 => '7931',
1201 => '91178/1',
1202 => '91178/2',
1203 => '91250/1',
1204 => '91250/2',
1205 => '91251/1',
1206 => '91251/2',
1207 => '91182/1',
1208 => '91182/2',
1209 => '91219/1',
1210 => '91219/2',
1211 => '7928',
1212 => '91181/1',
1213 => '91181/2',
1214 => '91220/1',
1215 => '91220/2',
1216 => '91123/1',
1217 => '91183/1',
1218 => '91183/2',
1219 => '9217/1',
1220 => '9217/2',
1221 => '91225/1',
1222 => '91225/2',
1223 => '91225/2',
1224 => '91125/1',
1225 => '91250/6',
1226 => '91250/7',
1227 => '91251/7',
1228 => '91251/6',
1229 => '91182/7',
1230 => '91182/6',
1231 => '91226/1',
1232 => '91226/2',
1233 => '97230/1',
1234 => '93383/1',
1235 => '93384/1',
1236 => '93385/1',
1237 => '93386/1',
1238 => '93387/1',
1239 => '93388/1',
1240 => '93389/1',
1241 => '93390/1',
1242 => '93391/1',
1243 => '97234/1'
];
if(isset($old[$index]))
{
return $old[$index];
}
return false;
}
public function calcDateDiff(?\DateTimeInterface $date1, ?\DateTimeInterface $date2)
{
if ($date1 === null || $date2 === null)
{
return false;
}
return $date1->getTimestamp() - $date2->getTimestamp();
}
public function dateInBetween(\DateTimeInterface $date, \DateTimeInterface $startDate, \DateTimeInterface $endDate): bool
{
return ($this->calcDateDiff($date, $startDate) > 0) && ($this->calcDateDiff($endDate, $date) > 0);
}
public function getFreeLessonsInCourse($modules): array
{
$freeLessonsInCourse = [];
foreach ($modules as $module)
{
if (isset($module['list']))
{
foreach ($module['list'] as $list)
{
if (isset($list['list']))
{
foreach ($list['list'] as $item)
{
if (isset($item['free']))
{
$freeLessonsInCourse[] = [
'link' => $item['free'],
'title' => $item['title'],
'isVimeo' => (strpos($item['free'], 'vimeo.com') === false) ? false : true,
'isBbVideo' => !((strpos($item['free'], 'bbvms.com') === false)),
];
}
}
}
}
}
}
return $freeLessonsInCourse;
}
public function getCouponDataStartFromCourse(ProductVariant $productVariant, Course $course)
{
$dateTo = null;
$subscriptionInfoFromLanding = $this->em->getRepository(LandingModuleItem::class)
->findOneByCourseAndVariableName($course,'subscriptions', 'payment');
if (isset($subscriptionInfoFromLanding['variableValue']) && !empty($subscriptionInfoFromLanding['variableValue']))
{
$data = json_decode($subscriptionInfoFromLanding['variableValue'], true);
foreach ($data as $item)
{
if (isset($item['subscription']) && $item['subscription'] == $productVariant->getId())
{
if (isset($item['discountCode']) && !empty($item['discountCode']))
{
$coupon = $this->em->getRepository(Coupon::class)->find($item['discountCode']);
if ($coupon) $dateTo = clone $coupon->getDateFrom();
}
break;
}
}
}
return $dateTo;
}
}