<?php
namespace EADPlataforma\Controller\Website;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use EADPlataforma\Entity\Course;
use EADPlataforma\Entity\CourseTeam;
use EADPlataforma\Entity\CourseTestimonial;
use EADPlataforma\Entity\LessonModule;
use EADPlataforma\Entity\Lesson;
use EADPlataforma\Entity\Library;
use EADPlataforma\Entity\LessonLog;
use EADPlataforma\Entity\LessonSupport;
use EADPlataforma\Entity\LessonAnnotation;
use EADPlataforma\Entity\Enrollment;
use EADPlataforma\Entity\Exam;
use EADPlataforma\Entity\ExamUser;
use EADPlataforma\Entity\Product;
use EADPlataforma\Entity\ProductOffer;
use EADPlataforma\Entity\ProductSuggestion;
use EADPlataforma\Enum\EnrollmentEnum;
use EADPlataforma\Enum\CourseTeamEnum;
use EADPlataforma\Enum\ProductEnum;
use EADPlataforma\Enum\ProductOfferEnum;
use EADPlataforma\Enum\ProductSuggestionEnum;
use EADPlataforma\Enum\LibraryEnum;
use EADPlataforma\Enum\LessonEnum;
/**
* @Route(
* schemes = {"http|https"}
* )
* @Cache(
* maxage = "0",
* smaxage = "0",
* expires = "now",
* public = false
* )
*/
class LessonController extends AbstractWebsiteController {
/**
* @Route(
* path = "/lesson/detail/{courseId}/{lessonId}",
* name = "lessonPage",
* methods = {"GET"}
* )
*/
public function getLessonPage(Request $request) {
$this->checkUserSession($request);
return $this->renderEAD('lesson-index.html.twig', 'lesson');
}
/**
* @Route(
* path = "/quiz/{courseId}/{lessonId}/{examId}",
* name = "quizLessonPage",
* methods = {"GET"}
* )
*/
public function getQuizLessonPage(Request $request) {
$this->checkUserSession($request);
return $this->renderEAD('lesson-index.html.twig', 'lesson');
}
/**
* @Route(
* path = "/test/start/{courseId}/{lessonModuleId}/{lessonId}/{examId}",
* name = "examLessonPage",
* methods = {"GET"}
* )
*/
public function getExamLessonPage(Request $request) {
$this->checkUserSession($request);
return $this->renderEAD('lesson-index.html.twig', 'lesson');
}
/**
* @Route(
* path = "/test/start/{courseId}/{lessonModuleId}/{examId}",
* name = "examLessonModulePage",
* methods = {"GET"}
* )
*/
public function getExamLessonModulePage(Request $request) {
$this->checkUserSession($request);
return $this->renderEAD('lesson-index.html.twig', 'lesson');
}
/**
* @Route(
* path = "/test/start/{courseId}/{examId}",
* name = "examCoursePage",
* methods = {"GET"}
* )
*/
public function getExamCoursePage(Request $request) {
$this->checkUserSession($request);
return $this->renderEAD('lesson-index.html.twig', 'lesson');
}
/**
* @Route(
* path = "/course/{courseId}/rate",
* name = "rateCoursePage",
* methods = {"GET"}
* )
*/
public function getRateCoursePage(Request $request) {
$this->checkUserSession($request);
return $this->renderEAD('lesson-index.html.twig', 'lesson');
}
/**
* @Route(
* path = "/course/certificate/{courseId}",
* name = "getCourseCertificatePage",
* methods = {"GET"}
* )
*/
public function getCourseCertificatePage(Request $request) {
$this->checkUserSession($request);
return $this->renderEAD('lesson-index.html.twig', 'lesson');
}
/**
* @Route(
* path = "/show/content/{lessonId}",
* methods = {"GET"},
* name = "lessonPublicViewContent",
* )
*/
public function getShowLessonContent(Request $request) {
$lessonId = (int)$request->get('lessonId');
$lessonRepository = $this->em->getRepository(Lesson::class);
$lesson = $lessonRepository->getLessonPublicDemoById($lessonId);
//check lesson exist
if (!$lesson) {
//redirect to index or home
return $this->eadResponse(null, ErrorEnum::NOT_FOUND);
}
$library = $lesson->getLibrary();
if (!$library) {
//redirect to index or home
return $this->eadResponse(null, ErrorEnum::NOT_FOUND);
}
$info = $this->em->getRepository(Library::class)->getContentInfo($library);
if(!empty($info->url)){
return $this->eadResponse($info);
}
return $this->eadResponse(null, ErrorEnum::NOT_FOUND);
}
/**
* @Route(
* path = "/video/credentials/{lessonId}",
* methods = {"GET"},
* name = "lessonPublicVideoCredentials",
* )
*/
public function getLessonVideoCredentials(Request $request){
$lessonId = (int)$request->get('lessonId');
$lessonRepository = $this->em->getRepository(Lesson::class);
$lesson = $lessonRepository->getLessonPublicDemoById($lessonId);
if (!$lesson) {
return $this->eadResponse(null, ErrorEnum::NOT_FOUND);
}
$annotate = [];
$libraryRepository = $this->em->getRepository(Library::class);
if($lesson->getControlShowDocument() == LessonEnum::YES){
$hasFunction = $this->configuration->checkModuleIsAbleOnPlan('lessonControlFunction');
$drmVideo = $this->configuration->get("drm_video");
if($hasFunction && $drmVideo == LibraryEnum::YES){
$annotate = $libraryRepository->getVideoDRM($this->user);
}
}
$credentials = $libraryRepository->getVideoCredentials(
$lesson->getLibrary(),
$annotate
);
if(!$credentials){
return $this->eadResponse(null, ErrorEnum::NOT_FOUND);
}
return $this->eadResponse([ "credentials" => (array)$credentials ]);
}
/**
* @Route(
* path = "/lesson/demo/{lessonId}/{productOfferId}",
* name = "lessonDemoPage",
* methods = {"GET"}
* )
*/
public function getLessonDemoPage(Request $request) {
$lessonId = (int)$request->get('lessonId');
$productOfferId = (int)$request->get('productOfferId');
$lessonRepository = $this->em->getRepository(Lesson::class);
$productOfferRepository = $this->em->getRepository(ProductOffer::class);
$lesson = $lessonRepository->getLessonPublicDemoById($lessonId);
if(!$lesson){
return $this->redirectToRoute('notFound');
}
$library = $lesson->getLibrary();
if(!$library){
return $this->redirectToRoute('notFound');
}
if(empty($library->getType())){
return $this->redirectToRoute('notFound');
}
$productOffer = $productOfferRepository->getProductOfferById($productOfferId);
if(!$productOffer){
return $this->redirectToRoute('notFound');
}
$numberUtil = $this->generalService->getUtil('NumberUtil');
$installmentNumberMax = $productOffer->getInstallmentNumberMax();
$freeInstallment = $productOfferRepository->getFreeInstallment($productOffer);
$allowCard = $productOfferRepository->produtOfferAllowCard($productOffer);
if($allowCard == ProductOfferEnum::NO){
$installmentNumberMax = 1;
$freeInstallment = 1;
}
$parcelInfo = $numberUtil->getNumberMaxParcel(
$productOffer->getPriceReal(true),
$installmentNumberMax,
$freeInstallment,
$productOffer->getSaleOption(),
$productOffer->getTypeCheckout(),
false
);
$this->data['parcelInfo'] = $parcelInfo;
$productSuggestionRepository = $this->em->getRepository(ProductSuggestion::class);
$this->data['productOfferSuggestions'] = $productSuggestionRepository->getProductSuggestionsByOfferOrigin(
$productOffer,
ProductSuggestionEnum::EXECUTE_IN_PRODUCT_PAGE
);
$lessonModuleRepository = $this->em->getRepository(LessonModule::class);
//Lesson modules and lessons
$lessonModules = $lessonModuleRepository->getLessonModulesByCourse(
$lesson->getCourse()
);
foreach ($lessonModules as $key => $lessonModule) {
$lessonModule->lessons = $lessonRepository->getLessonByLessonModule(
$lessonModule
);
}
$courseTestimonialRepository = $this->em->getRepository(CourseTestimonial::class);
$this->data['courseTestimonials'] = $courseTestimonialRepository->getTestimonialApprovedRandom(
6,
$productOffer->getProduct()
);
$this->data['formName'] = "formFastUserRegister";
$this->data['lessonModules'] = $lessonModules;
$this->data['keyCaptcha'] = $this->createCaptchaKey($request);
$this->data['lesson'] = $lesson;
$this->data['productOffer'] = $productOffer;
$annotate = [];
$libraryRepository = $this->em->getRepository(Library::class);
if($lesson->getControlShowDocument() == LessonEnum::YES){
$hasFunction = $this->configuration->checkModuleIsAbleOnPlan('lessonControlFunction');
$drmVideo = $this->configuration->get("drm_video");
if($hasFunction && $drmVideo == LibraryEnum::YES){
$annotate = $libraryRepository->getVideoDRM($this->user);
}
}
$credentials = $libraryRepository->getVideoCredentials(
$lesson->getLibrary(),
$annotate
);
$infoLive = $libraryRepository->getContentInfo($library);
$this->data['credentials'] = $credentials;
$this->data['infoLive'] = $infoLive;
return $this->renderEAD('lesson/lesson-demo.html.twig');
}
}