src/Controller/Website/LessonController.php line 208

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Website;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use EADPlataforma\Entity\Course;
  7. use EADPlataforma\Entity\CourseTeam;
  8. use EADPlataforma\Entity\CourseTestimonial;
  9. use EADPlataforma\Entity\LessonModule;
  10. use EADPlataforma\Entity\Lesson;
  11. use EADPlataforma\Entity\Library;
  12. use EADPlataforma\Entity\LessonLog;
  13. use EADPlataforma\Entity\LessonSupport;
  14. use EADPlataforma\Entity\LessonAnnotation;
  15. use EADPlataforma\Entity\Enrollment;
  16. use EADPlataforma\Entity\Exam;
  17. use EADPlataforma\Entity\ExamUser;
  18. use EADPlataforma\Entity\Product;
  19. use EADPlataforma\Entity\ProductOffer;
  20. use EADPlataforma\Entity\ProductSuggestion;
  21. use EADPlataforma\Enum\EnrollmentEnum;
  22. use EADPlataforma\Enum\CourseTeamEnum;
  23. use EADPlataforma\Enum\ProductEnum;
  24. use EADPlataforma\Enum\ProductOfferEnum;
  25. use EADPlataforma\Enum\ProductSuggestionEnum;
  26. use EADPlataforma\Enum\LibraryEnum;
  27. use EADPlataforma\Enum\LessonEnum;
  28. /**
  29.  * @Route(
  30.  *      schemes         = {"http|https"}
  31.  * )
  32.  * @Cache(
  33.  *      maxage          = "0",
  34.  *      smaxage         = "0",
  35.  *      expires         = "now",
  36.  *      public          = false
  37.  * )
  38.  */
  39. class LessonController extends AbstractWebsiteController {
  40.     /**
  41.      * @Route(
  42.      *      path          = "/lesson/detail/{courseId}/{lessonId}",
  43.      *      name          = "lessonPage",
  44.      *      methods       = {"GET"}
  45.      * )
  46.      */
  47.     public function getLessonPage(Request $request) {
  48.         $this->checkUserSession($request);
  49.         return $this->renderEAD('lesson-index.html.twig''lesson');
  50.     }
  51.     /**
  52.      * @Route(
  53.      *      path          = "/quiz/{courseId}/{lessonId}/{examId}",
  54.      *      name          = "quizLessonPage",
  55.      *      methods       = {"GET"}
  56.      * )
  57.      */
  58.     public function getQuizLessonPage(Request $request) {
  59.         $this->checkUserSession($request);
  60.         return $this->renderEAD('lesson-index.html.twig''lesson');
  61.     }
  62.     /**
  63.      * @Route(
  64.      *      path          = "/test/start/{courseId}/{lessonModuleId}/{lessonId}/{examId}",
  65.      *      name          = "examLessonPage",
  66.      *      methods       = {"GET"}
  67.      * )
  68.      */
  69.     public function getExamLessonPage(Request $request) {
  70.         $this->checkUserSession($request);
  71.         return $this->renderEAD('lesson-index.html.twig''lesson');
  72.     }
  73.     /**
  74.      * @Route(
  75.      *      path          = "/test/start/{courseId}/{lessonModuleId}/{examId}",
  76.      *      name          = "examLessonModulePage",
  77.      *      methods       = {"GET"}
  78.      * )
  79.      */
  80.     public function getExamLessonModulePage(Request $request) {
  81.         $this->checkUserSession($request);
  82.         return $this->renderEAD('lesson-index.html.twig''lesson');
  83.     }
  84.     /**
  85.      * @Route(
  86.      *      path          = "/test/start/{courseId}/{examId}",
  87.      *      name          = "examCoursePage",
  88.      *      methods       = {"GET"}
  89.      * )
  90.      */
  91.     public function getExamCoursePage(Request $request) {
  92.         $this->checkUserSession($request);
  93.         return $this->renderEAD('lesson-index.html.twig''lesson');
  94.     }
  95.     /**
  96.      * @Route(
  97.      *      path          = "/course/{courseId}/rate",
  98.      *      name          = "rateCoursePage",
  99.      *      methods       = {"GET"}
  100.      * )
  101.      */
  102.     public function getRateCoursePage(Request $request) {
  103.         $this->checkUserSession($request);
  104.         return $this->renderEAD('lesson-index.html.twig''lesson');
  105.     }
  106.     /**
  107.      * @Route(
  108.      *      path          = "/course/certificate/{courseId}",
  109.      *      name          = "getCourseCertificatePage",
  110.      *      methods       = {"GET"}
  111.      * )
  112.      */
  113.     public function getCourseCertificatePage(Request $request) {
  114.         $this->checkUserSession($request);
  115.         return $this->renderEAD('lesson-index.html.twig''lesson');
  116.     }
  117.     /**
  118.      * @Route(
  119.      *      path          = "/show/content/{lessonId}",
  120.      *      methods       = {"GET"},
  121.      *      name          = "lessonPublicViewContent",
  122.      * )
  123.      */
  124.     public function getShowLessonContent(Request $request) {
  125.         $lessonId = (int)$request->get('lessonId');
  126.         $lessonRepository $this->em->getRepository(Lesson::class);
  127.         $lesson $lessonRepository->getLessonPublicDemoById($lessonId);
  128.         //check lesson exist
  129.         if (!$lesson) {
  130.             //redirect to index or home
  131.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  132.         }
  133.         $library $lesson->getLibrary();
  134.         if (!$library) {
  135.             //redirect to index or home
  136.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  137.         }
  138.         
  139.         $info $this->em->getRepository(Library::class)->getContentInfo($library);
  140.         if(!empty($info->url)){
  141.             return $this->eadResponse($info);
  142.         }
  143.         return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  144.     }
  145.     /**
  146.      * @Route(
  147.      *      path          = "/video/credentials/{lessonId}",
  148.      *      methods       = {"GET"},
  149.      *      name          = "lessonPublicVideoCredentials",
  150.      * )
  151.      */
  152.     public function getLessonVideoCredentials(Request $request){
  153.         $lessonId = (int)$request->get('lessonId');
  154.         $lessonRepository $this->em->getRepository(Lesson::class);
  155.         $lesson $lessonRepository->getLessonPublicDemoById($lessonId);
  156.         
  157.         if (!$lesson) {
  158.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  159.         }
  160.         $annotate = [];
  161.         $libraryRepository $this->em->getRepository(Library::class);
  162.         if($lesson->getControlShowDocument() == LessonEnum::YES){
  163.             $hasFunction $this->configuration->checkModuleIsAbleOnPlan('lessonControlFunction');
  164.             $drmVideo $this->configuration->get("drm_video");
  165.             if($hasFunction && $drmVideo == LibraryEnum::YES){
  166.                 $annotate $libraryRepository->getVideoDRM($this->user);
  167.             }
  168.         }
  169.         $credentials $libraryRepository->getVideoCredentials(
  170.             $lesson->getLibrary(),
  171.             $annotate
  172.         );
  173.         if(!$credentials){
  174.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  175.         }
  176.         return $this->eadResponse([ "credentials" => (array)$credentials ]);
  177.     }
  178.     /**
  179.      * @Route(
  180.      *      path          = "/lesson/demo/{lessonId}/{productOfferId}",
  181.      *      name          = "lessonDemoPage",
  182.      *      methods       = {"GET"}
  183.      * )
  184.      */
  185.     public function getLessonDemoPage(Request $request) {
  186.         
  187.         $lessonId = (int)$request->get('lessonId');
  188.         $productOfferId = (int)$request->get('productOfferId');
  189.         $lessonRepository $this->em->getRepository(Lesson::class);
  190.         $productOfferRepository $this->em->getRepository(ProductOffer::class);
  191.         $lesson $lessonRepository->getLessonPublicDemoById($lessonId);
  192.         if(!$lesson){
  193.             return $this->redirectToRoute('notFound');
  194.         }
  195.         $library $lesson->getLibrary();
  196.         if(!$library){
  197.             return $this->redirectToRoute('notFound');
  198.         }
  199.         if(empty($library->getType())){
  200.             return $this->redirectToRoute('notFound');
  201.         }
  202.         $productOffer $productOfferRepository->getProductOfferById($productOfferId);
  203.         if(!$productOffer){
  204.             return $this->redirectToRoute('notFound');
  205.         }
  206.         $numberUtil $this->generalService->getUtil('NumberUtil');
  207.         $installmentNumberMax $productOffer->getInstallmentNumberMax();
  208.         $freeInstallment $productOfferRepository->getFreeInstallment($productOffer);
  209.         $allowCard $productOfferRepository->produtOfferAllowCard($productOffer);
  210.         if($allowCard == ProductOfferEnum::NO){
  211.             $installmentNumberMax 1;
  212.             $freeInstallment 1;
  213.         }
  214.         $parcelInfo $numberUtil->getNumberMaxParcel(
  215.             $productOffer->getPriceReal(true), 
  216.             $installmentNumberMax,
  217.             $freeInstallment
  218.             $productOffer->getSaleOption(),
  219.             $productOffer->getTypeCheckout(),
  220.             false
  221.         );
  222.         $this->data['parcelInfo'] = $parcelInfo;
  223.         $productSuggestionRepository $this->em->getRepository(ProductSuggestion::class);
  224.         $this->data['productOfferSuggestions'] = $productSuggestionRepository->getProductSuggestionsByOfferOrigin(
  225.             $productOffer
  226.             ProductSuggestionEnum::EXECUTE_IN_PRODUCT_PAGE
  227.         );
  228.         $lessonModuleRepository $this->em->getRepository(LessonModule::class);
  229.         //Lesson modules and lessons
  230.         $lessonModules $lessonModuleRepository->getLessonModulesByCourse(
  231.             $lesson->getCourse()
  232.         );
  233.         
  234.         foreach ($lessonModules as $key => $lessonModule) {
  235.             $lessonModule->lessons $lessonRepository->getLessonByLessonModule(
  236.                 $lessonModule
  237.             );
  238.         }
  239.         $courseTestimonialRepository $this->em->getRepository(CourseTestimonial::class);
  240.         $this->data['courseTestimonials'] = $courseTestimonialRepository->getTestimonialApprovedRandom(
  241.             6
  242.             $productOffer->getProduct()
  243.         );
  244.         $this->data['formName'] = "formFastUserRegister";
  245.         $this->data['lessonModules'] = $lessonModules;
  246.         $this->data['keyCaptcha'] = $this->createCaptchaKey($request);
  247.         $this->data['lesson'] = $lesson;
  248.         $this->data['productOffer'] = $productOffer;
  249.         $annotate = [];
  250.         $libraryRepository $this->em->getRepository(Library::class);
  251.         if($lesson->getControlShowDocument() == LessonEnum::YES){
  252.             $hasFunction $this->configuration->checkModuleIsAbleOnPlan('lessonControlFunction');
  253.             $drmVideo $this->configuration->get("drm_video");
  254.             if($hasFunction && $drmVideo == LibraryEnum::YES){
  255.                 $annotate $libraryRepository->getVideoDRM($this->user);
  256.             }
  257.         }
  258.         $credentials $libraryRepository->getVideoCredentials(
  259.             $lesson->getLibrary(),
  260.             $annotate
  261.         );
  262.         $infoLive $libraryRepository->getContentInfo($library);
  263.         $this->data['credentials'] = $credentials;
  264.         $this->data['infoLive'] = $infoLive;
  265.         return $this->renderEAD('lesson/lesson-demo.html.twig');
  266.     }
  267. }