src/Controller/Admin/CourseIndexController.php line 175

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Admin;
  3. use EADPlataforma\Error\ActionInvalidException;
  4. use EADPlataforma\Error\FieldException;
  5. use EADPlataforma\Error\NotFoundException;
  6. use EADPlataforma\Error\PermissionException;
  7. use EADPlataforma\Error\AuthInvalidException;
  8. use EADPlataforma\Response\HttpCreated;
  9. use EADPlataforma\Response\HttpNoContent;
  10. use EADPlataforma\Response\HttpOk;
  11. use EADPlataforma\Services\EntityServices\CourseIndexService;
  12. use EADPlataforma\Services\EntityServices\ExamUserAnswerService;
  13. use EADPlataforma\Services\EntityServices\LibraryChapterService;
  14. use EADPlataforma\Services\EntityServices\LessonService;
  15. use EADPlataforma\Services\EntityServices\LessonModuleService;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use EADPlataforma\Http\EADResponse;
  21. use EADPlataforma\Entity\Course;
  22. use EADPlataforma\Entity\CourseTeam;
  23. use EADPlataforma\Entity\Category;
  24. use EADPlataforma\Entity\Product;
  25. use EADPlataforma\Entity\ProductOffer;
  26. use EADPlataforma\Entity\ProductTeam;
  27. use EADPlataforma\Entity\Lesson;
  28. use EADPlataforma\Entity\LessonSupport;
  29. use EADPlataforma\Entity\LessonLog;
  30. use EADPlataforma\Entity\LessonLogOrigin;
  31. use EADPlataforma\Entity\LessonModule;
  32. use EADPlataforma\Entity\LessonAnnotation;
  33. use EADPlataforma\Entity\Library;
  34. use EADPlataforma\Entity\LessonXLibrary;
  35. use EADPlataforma\Entity\LikeControl;
  36. use EADPlataforma\Entity\CourseCertificateTemplate;
  37. use EADPlataforma\Entity\Enrollment;
  38. use EADPlataforma\Entity\Exam;
  39. use EADPlataforma\Entity\ExamUser;
  40. use EADPlataforma\Entity\ExamUserAnswer;
  41. use EADPlataforma\Entity\ExamUserAnswerOption;
  42. use EADPlataforma\Entity\Question;
  43. use EADPlataforma\Entity\QuestionOption;
  44. use EADPlataforma\Entity\CourseTestimonial;
  45. use EADPlataforma\Entity\User;
  46. use EADPlataforma\Entity\UserSubscription;
  47. use EADPlataforma\Enum\CourseEnum;
  48. use EADPlataforma\Enum\CourseTeamEnum;
  49. use EADPlataforma\Enum\ProductEnum;
  50. use EADPlataforma\Enum\EnrollmentEnum;
  51. use EADPlataforma\Enum\ExamEnum;
  52. use EADPlataforma\Enum\ExamUserEnum;
  53. use EADPlataforma\Enum\LessonEnum;
  54. use EADPlataforma\Enum\LessonSupportEnum;
  55. use EADPlataforma\Enum\LibraryEnum;
  56. use EADPlataforma\Enum\LikeControlEnum;
  57. use EADPlataforma\Enum\LessonXLibraryEnum;
  58. use EADPlataforma\Enum\LessonAnnotationEnum;
  59. use EADPlataforma\Enum\LessonModuleEnum;
  60. use EADPlataforma\Enum\ExamUserAnswerEnum;
  61. use EADPlataforma\Enum\QuestionEnum;
  62. use EADPlataforma\Enum\QuestionOptionEnum;
  63. use EADPlataforma\Enum\CourseTestimonialEnum;
  64. use EADPlataforma\Enum\NotificationEnum;
  65. use EADPlataforma\Enum\WebhookEnum;
  66. use EADPlataforma\Enum\TrashEnum;
  67. use EADPlataforma\Enum\ErrorEnum;
  68. /**
  69.  * @Route(
  70.  *      path          = "",
  71.  *      schemes         = {"http|https"}
  72.  * )
  73.  * @Cache(
  74.  *      maxage          = "0",
  75.  *      smaxage         = "0",
  76.  *      expires         = "now",
  77.  *      public          = false
  78.  * )
  79.  */
  80. class CourseIndexController extends AbstractController {
  81.     public function getEntityClass(){
  82.         return Course::class;
  83.     }
  84.     /**
  85.      * @Route(
  86.      *      path          = "/admin/v2/general/{id}",
  87.      *      methods       = {"GET"},
  88.      *      requirements  = { "id" = "\d+" }
  89.      * )
  90.      * 
  91.      * @throws NotFoundException
  92.      * @throws ActionInvalidException
  93.      */
  94.     public function getCourseNewGeneral(
  95.         Request $request
  96.         CourseIndexService $courseIndexService
  97.     ): JsonResponse
  98.     {
  99.         $courseId $request->get('id');
  100.         $course $courseIndexService->searchCourse($courseId);
  101.         if(!$course){
  102.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  103.         }
  104.         $enrollment $courseIndexService->searchEnrollment($course);
  105.         if(!$enrollment){
  106.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  107.         }
  108.         $isStudent $courseIndexService->isStudent($course);
  109.         if($isStudent && $course->getStatus() == CourseEnum::DRAFT){
  110.             throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  111.         }
  112.         $data $courseIndexService->getCourseNewGeneral($course$enrollment);
  113.         return new HttpOk($data);
  114.     }
  115.     /**
  116.      * @Route(
  117.      *      path          = "/admin/v2/course/{id}",
  118.      *      methods       = {"GET"},
  119.      *      requirements  = { "id" = "\d+" }
  120.      * )
  121.      * 
  122.      * @throws NotFoundException
  123.      * @throws ActionInvalidException
  124.      */
  125.     public function getCourseNewIndex(
  126.         Request $request,
  127.         CourseIndexService $courseIndexService
  128.     ): JsonResponse
  129.     {
  130.         
  131.         $courseId $request->get('id');
  132.         $course $courseIndexService->searchCourse($courseId);
  133.         if(!$course){
  134.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  135.         }
  136.         $enrollment $courseIndexService->searchEnrollment($course);
  137.         if(!$enrollment){
  138.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  139.         }
  140.         $isStudent $courseIndexService->isStudent($course);
  141.         if($isStudent && $course->getStatus() == CourseEnum::DRAFT){
  142.             throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  143.         }
  144.         $data $courseIndexService->getCourseIndex($enrollment);
  145.         return new HttpOk($data);
  146.     }
  147.     /**
  148.      * @Route(
  149.      *      path          = "/admin/v2/module/{id}",
  150.      *      methods       = {"GET"},
  151.      *      requirements  = { "id" = "\d+" }
  152.      * )
  153.      * 
  154.      * @throws NotFoundException
  155.      * @throws ActionInvalidException
  156.      */
  157.     public function getModuleNewIndex(
  158.         Request $request,
  159.         CourseIndexService $courseIndexService,
  160.         LessonModuleService $lessonModuleService
  161.     ): JsonResponse
  162.     {
  163.         $moduleId $request->get('id');
  164.         $lessonModule $lessonModuleService->searchModule($moduleId);
  165.         if(!$lessonModule){
  166.             throw new NotFoundException($this->configuration->getLanguage('error_module_not_found''lesson_view_error'));
  167.         }
  168.         $course $lessonModule->getCourse();
  169.         $enrollment $courseIndexService->searchEnrollment($course);
  170.         if(!$enrollment){
  171.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  172.         }
  173.         $isStudent $courseIndexService->isStudent($course);
  174.         if($isStudent && $course->getStatus() == CourseEnum::DRAFT){
  175.             throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  176.         }
  177.         $data $lessonModuleService->getModuleIndex(
  178.             $enrollment,
  179.             $lessonModule,
  180.             $isStudent
  181.         );
  182.         return new HttpOk($data);
  183.     }
  184.     /**
  185.      * @Route(
  186.      *      path          = "/admin/v2/course/{id}/modules",
  187.      *      methods       = {"GET"},
  188.      *      requirements  = { "id" = "\d+" }
  189.      * )
  190.      *
  191.      * @throws NotFoundException
  192.      * @throws ActionInvalidException
  193.      */
  194.     public function getModules(
  195.         Request $request,
  196.         CourseIndexService $courseIndexService,
  197.         LessonModuleService $lessonModuleService
  198.     ): JsonResponse
  199.     {
  200.         
  201.         $courseId $request->get('id');
  202.         $course $courseIndexService->searchCourse($courseId);
  203.         if(!$course){
  204.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  205.         }
  206.         $enrollment $courseIndexService->searchEnrollment($course);
  207.         if(!$enrollment){
  208.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  209.         }
  210.         $isStudent $courseIndexService->isStudent($course);
  211.         if($isStudent && $course->getStatus() == CourseEnum::DRAFT){
  212.             throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  213.         }
  214.         $searchText $request->get('search');
  215.         $data $lessonModuleService->getModulesIndex(
  216.             $enrollment,
  217.             $isStudent,
  218.             $searchText
  219.         );
  220.         return new HttpOk($data);
  221.     }
  222.     /**
  223.      * @Route(
  224.      *      path          = "/admin/v2/lesson/{id}",
  225.      *      methods       = {"GET"},
  226.      *      name          = "getViewLessonNew",
  227.      *      requirements  = { "id" = "\d+" }
  228.      * )
  229.      * 
  230.      * @throws NotFoundException
  231.      * @throws ActionInvalidException
  232.      */
  233.     public function getViewLessonNew(
  234.         Request $request,
  235.         CourseIndexService $courseIndexService,
  236.         LessonService $lessonService,
  237.         LibraryChapterService $chapterService
  238.     ): JsonResponse
  239.     {
  240.         $lessonId $request->get('id');
  241.         $chatVersion = (int)$request->get('chatVersion');
  242.         $lesson $lessonService->searchLesson($lessonId);
  243.         if (!$lesson) {
  244.             throw new NotFoundException(
  245.                 $this->configuration->getLanguage('error_lesson_not_found''lesson_view_error')
  246.             );
  247.         }
  248.         $course $lesson->getCourse();
  249.         if(
  250.             $courseIndexService->isEnrollment($course) && 
  251.             !$courseIndexService->isValidEnrollment($course)
  252.         ){
  253.             throw new ActionInvalidException(
  254.                 $this->configuration->getLanguage('error_enrollment_expired''lesson_view_error'), 
  255.                 [
  256.                     "expired" => true,
  257.                 ]
  258.             );
  259.         }
  260.         //check user can access lesson
  261.         if(!$lessonService->isLessonVisibleToStudent($lesson)){
  262.             throw new ActionInvalidException(
  263.                 $this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error')
  264.             );
  265.         }
  266.         
  267.         $enrollment $courseIndexService->searchEnrollment($course);
  268.         if(!$enrollment){
  269.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  270.         }
  271.         $isStudent $courseIndexService->isStudent($course);
  272.         $lessonIsAccessible $lessonService->checkLessonIsAccessibleToUser(
  273.             $lesson,
  274.             $enrollment,
  275.             $isStudent
  276.         );
  277.         if(!$lessonIsAccessible->isAccessible){
  278.             throw new ActionInvalidException($lessonIsAccessible->message);
  279.         }
  280.         $data $lessonService->getLessonIndex(
  281.             $lesson,
  282.             $enrollment,
  283.             $isStudent,
  284.             ($chatVersion == LessonEnum::YES)
  285.         );
  286.         return new HttpOk($data);
  287.     }
  288.     /**
  289.      * @Route(
  290.      *      path          = "/admin/v2/{module}/{id}/{type}",
  291.      *      methods       = {"GET"},
  292.      *      name          = "getExamNewIndex",
  293.      *      requirements  = {"type"="exam|quiz"}
  294.      * )
  295.      */
  296.     public function getExamNewIndex(Request $request)
  297.     {
  298.         
  299.         $idModule = (int)$request->get('id');
  300.         $module $request->get('module');
  301.         $type $request->get('type');
  302.         
  303.         if($type != 'quiz'){
  304.             if(!$this->configuration->isModuleActive("exam_module")){
  305.                 throw new ActionInvalidException(
  306.                     $this->configuration->getLanguage('error_exam_unavailable''lesson_view_error')
  307.                 );
  308.             }
  309.         }
  310.         $class = [
  311.             "lesson" => Lesson::class,
  312.             "module" => LessonModule::class,
  313.             "course" => Course::class,
  314.         ];
  315.         if(!isset($class[$module])){
  316.             throw new NotFoundException(
  317.                 $this->configuration->getLanguage('error_exam_not_found''lesson_view_error')
  318.             );
  319.         }
  320.         $itemRepository $this->em->getRepository($class[$module]);
  321.         $item $itemRepository->findOneBy([
  322.             "id" => $idModule,
  323.             "deleted" => CourseEnum::ITEM_NO_DELETED
  324.         ]);
  325.         //check item exist
  326.         if(!$item){
  327.             //redirect to index or home
  328.             throw new NotFoundException(
  329.                 $this->configuration->getLanguage('error_exam_not_found''lesson_view_error')
  330.             );
  331.         }
  332.         $course $item;
  333.         if(!($course instanceof Course)){
  334.             $course $item->getCourse();
  335.         }
  336.         
  337.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  338.         $enrollment $enrollmentRepository->findOneBy([
  339.             "user" => $this->user->getId(),
  340.             "course" => $course->getId(),
  341.             "deleted" => LessonEnum::ITEM_NO_DELETED
  342.         ], [ "id" => "DESC" ]);
  343.         if(!$enrollment){
  344.             throw new ActionInvalidException(
  345.                 $this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error')
  346.             );
  347.         }
  348.         $filterExam = [
  349.             "course" => $course->getId(),
  350.             "deleted" => ExamEnum::ITEM_NO_DELETED
  351.         ];
  352.         if($item instanceof Course){
  353.             $filterExam["type"] = ExamEnum::COURSE;
  354.         }else if($item instanceof LessonModule){
  355.             $filterExam["lessonModule"] = $item->getId();
  356.             $filterExam["type"] = ExamEnum::MODULE;
  357.         }else if($item instanceof Lesson){
  358.             //check user can access lesson
  359.             if(!$itemRepository->isLessonVisibleToStudent($item)){
  360.                 if($type == 'quiz'){
  361.                     throw new ActionInvalidException(
  362.                         $this->configuration->getLanguage(
  363.                             'error_quiz_unavailable'
  364.                             'lesson_view_error'
  365.                         )
  366.                     );
  367.                 }
  368.                 throw new ActionInvalidException(
  369.                     $this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error')
  370.                 );
  371.             }
  372.             $lessonModule $item->getLessonModule();
  373.             $filterExam["lesson"] = $item->getId();
  374.             $filterExam["lessonModule"] = $lessonModule->getId();
  375.             $filterExam["type"] = ($type == "quiz" ExamEnum::QUIZ ExamEnum::LESSON );
  376.         }
  377.         $isStudent $this->repository->isStudent($course);
  378.         if($isStudent){
  379.             $filterExam["status"] = ExamEnum::PUBLISHED;
  380.         }
  381.         $examRepository $this->em->getRepository(Exam::class);
  382.         $examUserRepository $this->em->getRepository(ExamUser::class);
  383.         $exam $examRepository->findOneBy($filterExam);
  384.         if(!$exam){
  385.             throw new NotFoundException(
  386.                 $this->configuration->getLanguage('error_exam_not_found''lesson_view_error')
  387.             );
  388.         }
  389.         $examUser $examUserRepository->findOneBy([
  390.             "user" => $this->user->getId(),
  391.             "exam" => $exam->getId(),
  392.             "inactive" => ExamUserEnum::NO,
  393.             "deleted" => ExamUserEnum::ITEM_NO_DELETED
  394.         ]);
  395.         $infoAccess $examRepository->checkExamIsAccessible($exam$examUser);
  396.         if(!$infoAccess->isAccessible){
  397.             throw new ActionInvalidException($infoAccess->message);
  398.         }
  399.         $data $examUserRepository->getDataIndexNew($exam$this->user);
  400.         
  401.         return $this->eadResponseNew($data);
  402.     }
  403.     /**
  404.      * @Route(
  405.      *      path          = "/admin/v2/{module}/{id}/exam/start",
  406.      *      methods       = {"PATCH"},
  407.      *      name          = "startExamNewIndex",
  408.      *      requirements  = { "id" = "\d+" }
  409.      * )
  410.      */
  411.     public function startExamNewIndex(Request $request)
  412.     {
  413.         if(!$this->configuration->isModuleActive("exam_module")){
  414.             throw new ActionInvalidException($this->configuration->getLanguage('error_exam_unavailable''lesson_view_error'));
  415.         }
  416.         $idModule = (int)$request->get('id');
  417.         $module $request->get('module');
  418.         $class = [
  419.             "lesson" => Lesson::class,
  420.             "module" => LessonModule::class,
  421.             "course" => Course::class,
  422.         ];
  423.         if(!isset($class[$module])){
  424.             throw new NotFoundException($this->configuration->getLanguage('error_exam_not_found''lesson_view_error'));
  425.         }
  426.         $itemRepository $this->em->getRepository($class[$module]);
  427.         $item $itemRepository->findOneBy([
  428.             "id" => $idModule,
  429.             "deleted" => CourseEnum::ITEM_NO_DELETED
  430.         ]);
  431.         //check item exist
  432.         if(!$item){
  433.             //redirect to index or home
  434.             throw new NotFoundException($this->configuration->getLanguage('error_exam_not_found''lesson_view_error'));
  435.         }
  436.         $course $item;
  437.         if(!($course instanceof Course)){
  438.             $course $item->getCourse();
  439.         }
  440.         $user $this->user;
  441.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  442.         $enrollment $enrollmentRepository->findOneBy([
  443.             "user" => $user->getId(),
  444.             "course" => $course->getId(),
  445.             "deleted" => LessonEnum::ITEM_NO_DELETED
  446.         ], [ "id" => "DESC" ]);
  447.         if(!$enrollment){
  448.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  449.         }
  450.         $filterExam = [
  451.             "course" => $course->getId(),
  452.             "deleted" => ExamEnum::ITEM_NO_DELETED
  453.         ];
  454.         if($item instanceof Course){
  455.             $filterExam["type"] = ExamEnum::COURSE;
  456.         }else if($item instanceof LessonModule){
  457.             $filterExam["lessonModule"] = $item->getId();
  458.             $filterExam["type"] = ExamEnum::MODULE;
  459.         }else if($item instanceof Lesson){
  460.             //check user can access lesson
  461.             if(!$itemRepository->isLessonVisibleToStudent($item)){
  462.                 throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  463.             }
  464.             $lessonModule $item->getLessonModule();
  465.             $filterExam["lesson"] = $item->getId();
  466.             $filterExam["lessonModule"] = $lessonModule->getId();
  467.             $filterExam["type"] = ExamEnum::LESSON;
  468.         }
  469.         $isStudent $this->repository->isStudent($course);
  470.         if($isStudent){
  471.             $filterExam["status"] = ExamEnum::PUBLISHED;
  472.         }
  473.         $examRepository $this->em->getRepository(Exam::class);
  474.         $exam $examRepository->findOneBy($filterExam);
  475.         if(!$exam){
  476.             throw new NotFoundException($this->configuration->getLanguage('error_exam_not_found''lesson_view_error'));
  477.         }
  478.         $examUserRepository $this->em->getRepository(ExamUser::class);
  479.         
  480.         $examUser $examUserRepository->findOneBy([
  481.             "user" => $user->getId(),
  482.             "exam" => $exam->getId(),
  483.             "inactive" => ExamUserEnum::NO,
  484.             "deleted" => ExamUserEnum::ITEM_NO_DELETED
  485.         ]);
  486.         $infoAccess $examRepository->checkExamIsAccessible($exam$examUser);
  487.         if(!$infoAccess->isAccessible){
  488.             throw new ActionInvalidException($infoAccess->message);
  489.         }
  490.         if($examUser){
  491.             if(
  492.                 $examUser->getStatus() == ExamUserEnum::DISAPPROVED || 
  493.                 $examUser->getStatus() == ExamUserEnum::TIMEOUT
  494.             ){
  495.                 $examUser $examUserRepository->getValidExamUserById(
  496.                     $examUser->getId(), 
  497.                     true
  498.                 );
  499.                 
  500.                 $attemptsInfo $examUserRepository->getAttemptsInfo($exam$examUser);
  501.                 
  502.                 if($attemptsInfo->attempts == ExamEnum::YES){
  503.                     $examUser->setInactive(ExamUserEnum::YES);
  504.                     $this->em->flush();
  505.                     $examUser null;
  506.                 }
  507.             }
  508.         }
  509.         if(!$examUser){
  510.             $examUser = new ExamUser();
  511.             $examUser->setExam($exam);
  512.             $examUser->setCourse($exam->getCourse());
  513.             $examUser->setUser($user);
  514.             $this->em->persist($examUser);
  515.             $this->em->flush();
  516.         }else{
  517.             throw new NotFoundException($this->configuration->getLanguage('error_exam_not_found''lesson_view_error'));
  518.         }
  519.         $data $examUserRepository->getDataIndexNew($exam$user);
  520.         return $this->eadResponseNew($data);
  521.     }
  522.     /**
  523.      * @Route(
  524.      *      path          = "/admin/v2/{module}/{id}/exam/{questionId}",
  525.      *      methods       = {"POST"},
  526.      * )
  527.      */
  528.     public function registerAnswerExamQuestion(
  529.         Request $request,
  530.         ExamUserAnswerService $examUserAnswerService
  531.     ) {
  532.         if(!$this->configuration->isModuleActive("exam_module")){
  533.             throw new ActionInvalidException($this->configuration->getLanguage('error_exam_unavailable''lesson_view_error'));
  534.         }
  535.         $this->requestUtil->setRequest($request)->setData();
  536.         $idModule = (int)$request->get('id');
  537.         $module $request->get('module');
  538.         $questionId = (int)$request->get('questionId');
  539.         $class = [
  540.             "lesson" => Lesson::class,
  541.             "module" => LessonModule::class,
  542.             "course" => Course::class,
  543.         ];
  544.         if(!isset($class[$module])){
  545.             throw new NotFoundException($this->configuration->getLanguage('error_exam_not_found''lesson_view_error'));
  546.         }
  547.         $examUserAnswerRepository $this->em->getRepository(ExamUserAnswer::class);
  548.         $examUserRepository $this->em->getRepository(ExamUser::class);
  549.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  550.         $examRepository $this->em->getRepository(Exam::class);
  551.         $questionRepository $this->em->getRepository(Question::class);
  552.         $questionOptionRepository $this->em->getRepository(QuestionOption::class);
  553.         $itemRepository $this->em->getRepository($class[$module]);
  554.         $item $itemRepository->findOneBy([
  555.             "id" => $idModule,
  556.             "deleted" => CourseEnum::ITEM_NO_DELETED
  557.         ]);
  558.         //check item exist
  559.         if(!$item){
  560.             //redirect to index or home
  561.             throw new NotFoundException($this->configuration->getLanguage('error_exam_not_found''lesson_view_error'));
  562.         }
  563.         $course $item;
  564.         if(!($course instanceof Course)){
  565.             $course $item->getCourse();
  566.         }
  567.         $user $this->user;
  568.         $enrollment $enrollmentRepository->findOneBy([
  569.             "user" => $user->getId(),
  570.             "course" => $course->getId(),
  571.             "deleted" => LessonEnum::ITEM_NO_DELETED
  572.         ], [ "id" => "DESC" ]);
  573.         if(!$enrollment){
  574.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  575.         }
  576.         $filterExam = [
  577.             "course" => $course->getId(),
  578.             "deleted" => ExamEnum::ITEM_NO_DELETED
  579.         ];
  580.         if($item instanceof Course){
  581.             $filterExam["type"] = ExamEnum::COURSE;
  582.         }else if($item instanceof LessonModule){
  583.             $filterExam["lessonModule"] = $item->getId();
  584.             $filterExam["type"] = ExamEnum::MODULE;
  585.         }else if($item instanceof Lesson){
  586.             //check user can access lesson
  587.             if(!$itemRepository->isLessonVisibleToStudent($item)){
  588.                 throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  589.             }
  590.             $lessonModule $item->getLessonModule();
  591.             $filterExam["lesson"] = $item->getId();
  592.             $filterExam["lessonModule"] = $lessonModule->getId();
  593.             $filterExam["type"] = ExamEnum::LESSON;
  594.         }
  595.         $isStudent $this->repository->isStudent($course);
  596.         if($isStudent){
  597.             $filterExam["status"] = ExamEnum::PUBLISHED;
  598.         }
  599.         $exam $examRepository->findOneBy($filterExam);
  600.         if(!$exam){
  601.             throw new NotFoundException($this->configuration->getLanguage('error_exam_not_found''lesson_view_error'));
  602.         }
  603.         
  604.         $question $questionRepository->findOneBy([
  605.             "id" => $questionId,
  606.             "deleted" => ExamUserAnswerEnum::ITEM_NO_DELETED
  607.         ]);
  608.         if(!$question){
  609.             throw new NotFoundException($this->configuration->getLanguage('error_question_not_found''lesson_view_error'));
  610.         }
  611.         $examUser $examUserRepository->findOneBy([
  612.             "user" => $user->getId(),
  613.             "exam" => $exam->getId(),
  614.             "inactive" => ExamUserEnum::NO,
  615.             "deleted" => ExamUserEnum::ITEM_NO_DELETED
  616.         ]);
  617.         $examUser $examUserRepository->getValidExamUserById(nulltrue$examUser);
  618.         if (!$examUser) {
  619.             throw new NotFoundException($this->configuration->getLanguage('error_exam_not_found''lesson_view_error'));
  620.         }
  621.         $expired $examUserRepository->examUserIsExpired($examUser);
  622.         if($expired){
  623.             throw new NotFoundException($this->configuration->getLanguage('error_exam_expired''lesson_view_error'));
  624.         }
  625.         //check exist answer to this question
  626.         $questionAnswer $examUserAnswerRepository->findOneBy([
  627.             "deleted" => ExamUserAnswerEnum::ITEM_NO_DELETED,
  628.             "examUser" => $examUser->getId(),
  629.             "question" => $questionId,
  630.         ]);
  631.         if($questionAnswer){
  632.             throw new NotFoundException($this->configuration->getLanguage('error_answer_question_not_found''lesson_view_error'));
  633.         }
  634.         $answer $this->requestUtil->getField('answer');
  635.         if(empty($answer)){
  636.             throw new FieldException(
  637.                 "FieldException",
  638.                 [ 
  639.                     "answer" => "Value not found"
  640.                 ]
  641.             );
  642.         }
  643.         $questionAnswer = new ExamUserAnswer();
  644.         $questionAnswer->setExamUser($examUser);
  645.         $questionAnswer->setAnswered(QuestionEnum::YES);
  646.         $questionAnswer->setQuestion($question);
  647.         if($question->getType() == QuestionEnum::DISSERTATION){
  648.             $questionAnswer->setAnswer($answer);
  649.         }
  650.         $errors $this->validateEntity($questionAnswer);
  651.         if($errors){
  652.             throw new FieldException("FieldException"$errors);
  653.         }
  654.         $this->em->persist($questionAnswer);
  655.         $grade ExamUserAnswerEnum::GRADE_INCORRECT;
  656.         if($question->getType() != QuestionEnum::DISSERTATION){
  657.             $questionAnswer->setEvaluated((int)$question->getAnswered());
  658.             $optionsCorrect $questionOptionRepository->findBy([
  659.                 "question" => $question->getId(),
  660.                 "correct" => QuestionEnum::YES,
  661.                 "deleted" => ExamUserAnswerEnum::ITEM_NO_DELETED,
  662.             ]);
  663.             
  664.             $options json_decode($this->requestUtil->getField('answer'));
  665.             
  666.             foreach ($options as $key => $option) {
  667.                 $questionOption $questionOptionRepository->findOneBy([
  668.                     "id" => $option,
  669.                     "question" => $question->getId(),
  670.                     "deleted" => ExamUserAnswerEnum::ITEM_NO_DELETED,
  671.                 ]);
  672.                 if($questionOption){
  673.                     if($questionOption->getCorrect() == QuestionEnum::YES){
  674.                         if($question->getType() == QuestionEnum::ALTERNATIVE){
  675.                             $grade ExamUserAnswerEnum::GRADE_CORRECT;
  676.                         }
  677.                     }
  678.                     $questionAnswerOption = new ExamUserAnswerOption();
  679.                     $questionAnswerOption->setMarked(QuestionEnum::YES);
  680.                     $questionAnswerOption->setExamUserAnswer($questionAnswer);
  681.                     $questionAnswerOption->setQuestionOption($questionOption);
  682.                     $this->em->persist($questionAnswerOption);
  683.                 }
  684.             }
  685.             if($question->getType() == QuestionEnum::MULTIPLE_ALTERNATIVE){
  686.                 $grade $examUserAnswerService->correctMultipleAlternatives(
  687.                     $options
  688.                     $optionsCorrect
  689.                 );
  690.             }
  691.         }
  692.         $questionAnswer->setGrade($grade);
  693.         $this->em->flush();
  694.         sleep(0.5);
  695.         $questionNumberAnswer $examUserAnswerRepository->count([
  696.             "examUser" => $examUser->getId(),
  697.             "deleted" => ExamUserAnswerEnum::ITEM_NO_DELETED,
  698.             "answered" => QuestionEnum::YES
  699.         ]);
  700.         $questionNumber $exam->getQuestionNumber();
  701.         $questionNumberReal $exam->getQuestionNumberReal();
  702.         if($questionNumber $questionNumberReal){
  703.             $questionNumber $questionNumberReal;
  704.         }
  705.         if($exam->getQuestionOrder() == ExamEnum::SEQUENTIAL){
  706.             $questionNumber count($exam->getLiveQuestion());
  707.         }
  708.         if($questionNumber <= $questionNumberAnswer){
  709.             $examUserRepository->updateExamUser($examUser);
  710.         }
  711.         $data $questionAnswer->toReturn();
  712.         $this->userLogService->logInsert("exam_user_answer"$questionAnswer->getId(), $data);
  713.         $data $examUserRepository->getDataIndexNew($exam$user);
  714.         return $this->eadResponseNew($data);
  715.     }
  716.     /**
  717.      * @Route(
  718.      *      path          = "/admin/v2/{module}/{id}/exam/outside",
  719.      *      methods       = {"PATCH"},
  720.      *      name          = "outsideExam",
  721.      *      requirements  = { "id" = "\d+" }
  722.      * )
  723.      */
  724.     public function outsideExam(Request $request)
  725.     {
  726.         if(!$this->configuration->isModuleActive("exam_module")){
  727.             throw new ActionInvalidException("ActionInvalidException");
  728.         }
  729.         $idModule = (int)$request->get('id');
  730.         $module $request->get('module');
  731.         $class = [
  732.             "lesson" => Lesson::class,
  733.             "module" => LessonModule::class,
  734.             "course" => Course::class,
  735.         ];
  736.         if(!isset($class[$module])){
  737.             throw new NotFoundException("NotFoundException");
  738.         }
  739.         $itemRepository $this->em->getRepository($class[$module]);
  740.         $item $itemRepository->findOneBy([
  741.             "id" => $idModule,
  742.             "deleted" => CourseEnum::ITEM_NO_DELETED
  743.         ]);
  744.         //check item exist
  745.         if(!$item){
  746.             //redirect to index or home
  747.             throw new NotFoundException("NotFoundException");
  748.         }
  749.         $course $item;
  750.         if(!($course instanceof Course)){
  751.             $course $item->getCourse();
  752.         }
  753.         $user $this->user;
  754.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  755.         $enrollment $enrollmentRepository->findOneBy([
  756.             "user" => $user->getId(),
  757.             "course" => $course->getId(),
  758.             "deleted" => LessonEnum::ITEM_NO_DELETED
  759.         ], [ "id" => "DESC" ]);
  760.         if(!$enrollment){
  761.             throw new ActionInvalidException("ActionInvalidException");
  762.         }
  763.         $filterExam = [
  764.             "course" => $course->getId(),
  765.             "deleted" => ExamEnum::ITEM_NO_DELETED
  766.         ];
  767.         if($item instanceof Course){
  768.             $filterExam["type"] = ExamEnum::COURSE;
  769.         }else if($item instanceof LessonModule){
  770.             $filterExam["lessonModule"] = $item->getId();
  771.             $filterExam["type"] = ExamEnum::MODULE;
  772.         }else if($item instanceof Lesson){
  773.             //check user can access lesson
  774.             if(!$itemRepository->isLessonVisibleToStudent($item)){
  775.                 throw new ActionInvalidException("ActionInvalidException");
  776.             }
  777.             $lessonModule $item->getLessonModule();
  778.             $filterExam["lesson"] = $item->getId();
  779.             $filterExam["lessonModule"] = $lessonModule->getId();
  780.             $filterExam["type"] = ExamEnum::LESSON;
  781.         }
  782.         $exam $this->em->getRepository(Exam::class)->findOneBy($filterExam);
  783.         if(!$exam){
  784.             throw new NotFoundException("NotFoundException");
  785.         }
  786.         if($exam->getControlTime() == ExamEnum::NO){
  787.             throw new NotFoundException("ActionInvalidException");
  788.         }
  789.         $examUserRepository $this->em->getRepository(ExamUser::class);
  790.         
  791.         $examUser $examUserRepository->findOneBy([
  792.             "user" => $user->getId(),
  793.             "exam" => $exam->getId(),
  794.             "inactive" => ExamUserEnum::NO,
  795.             "deleted" => ExamUserEnum::ITEM_NO_DELETED
  796.         ]);
  797.         if(!$examUser){
  798.             throw new ActionInvalidException("ActionInvalidException");
  799.         }
  800.         if($examUser->getStatus() !== ExamUserEnum::IN_PROGRESS){
  801.             throw new ActionInvalidException("ActionInvalidException");
  802.         }
  803.         $timeUtil $this->generalService->getUtil('DateTimeUtil');
  804.         $examUser $examUserRepository->getValidExamUserById(
  805.             $examUser->getId(), 
  806.             true
  807.         );
  808.         $this->requestUtil->setRequest($request)->setData();
  809.         $outsideNumber $examUser->getOutsideNumber();
  810.         $newOutsideNumber $outsideNumber 1;
  811.         $examUser->setOutsideNumber($newOutsideNumber);
  812.         $outsideTime '00:00:00';
  813.         if(!empty($examUser->getOutsideTime())){
  814.             $outsideTime $examUser->getOutsideTime();
  815.         }
  816.         if($this->requestUtil->issetField('outsideTime')){
  817.             $newTime $this->requestUtil->getField('outsideTime');
  818.             $newTime $timeUtil->timeToSec($newTime);
  819.             $oldTime $timeUtil->timeToSec($outsideTime);
  820.             $sumTime $oldTime $newTime;
  821.             $time $timeUtil->secToTime($sumTime);
  822.             $examUser->setOutsideTime($time);
  823.         }
  824.         $errors $this->validateEntity($examUser);
  825.         if($errors){
  826.             throw new FieldException("FieldException"$errors);
  827.         }
  828.         
  829.         $this->em->flush();
  830.         return $this->eadResponseNew([ "message" => "Success" ]);
  831.     }
  832.     /**
  833.      * @Route(
  834.      *      path          = "/admin/v2/lesson/{id}/quiz/{questionId}",
  835.      *      methods       = {"POST"}
  836.      * )
  837.      */
  838.     public function getQuestionQuizAnswer(Request $request) {
  839.         $questionRepository $this->em->getRepository(Question::class);
  840.         $questionOptionRepository $this->em->getRepository(QuestionOption::class);
  841.         $libraryRepository $this->em->getRepository(Library::class);
  842.         $this->requestUtil->setRequest($request)->setData();
  843.         $questionId = (int)$request->get('questionId');
  844.         $lessonId = (int)$request->get('id');
  845.         
  846.         $lessonRepository $this->em->getRepository(Lesson::class);
  847.         $lesson $lessonRepository->findOneBy([
  848.             "id" => $lessonId,
  849.             "deleted" => LessonEnum::ITEM_NO_DELETED
  850.         ]);
  851.         //check item exist
  852.         if(!$lesson){
  853.             throw new NotFoundException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  854.         }
  855.         $question $questionRepository->findOneBy([
  856.             "id" => $questionId,
  857.             "deleted" => QuestionEnum::ITEM_NO_DELETED
  858.         ]);
  859.         if(!$question){
  860.             throw new NotFoundException($this->configuration->getLanguage('error_question_not_found''lesson_view_error'));
  861.         }
  862.         $optionCorrect $questionOptionRepository->findOneBy([
  863.             "deleted" => QuestionOptionEnum::ITEM_NO_DELETED,
  864.             "question" => $questionId,
  865.             "correct" => QuestionOptionEnum::YES,
  866.         ]);
  867.         $libraryReturn null;
  868.         $library $question->getLibrary();
  869.         if($library){
  870.             $libraryInfo $libraryRepository->getContentInfo($libraryfalse$lesson);
  871.             $libraryReturn = (object)[
  872.                 "id" => $library->getId(),
  873.                 "title" => $library->getTitle(),
  874.                 "type" => $library->getType(),
  875.                 "link" => $libraryInfo->url,
  876.                 "text" => $library->getText(),
  877.                 "file" => $library->getId(),
  878.                 "fileExtension" => $library->getFileExtension(),
  879.                 "liveStart" => $library->getLiveStart(),
  880.                 "liveEmbedId" => $libraryInfo->embedId,
  881.                 "pagesNumber" => $library->getPagesNumber(),
  882.                 "duration" => $library->getDuration(),
  883.             ];
  884.             $showDocument = ($lesson->getControlShowDocument() == LibraryEnum::YES);
  885.             $drmVideo $this->configuration->get("drm_video");
  886.             $hasLessonControl $this->configuration->checkModuleIsAbleOnPlan(
  887.                 'lessonControlFunction'
  888.             );
  889.             $annotate = [];
  890.             if($hasLessonControl && $showDocument && $drmVideo == LibraryEnum::YES){
  891.                 $annotate $libraryRepository->getVideoDRM($this->user);
  892.             }
  893.             $credentials $libraryRepository->getVideoCredentials(
  894.                 $library,
  895.                 $annotate
  896.             );
  897.             if($credentials){
  898.                 $libraryReturn->credentials $credentials;
  899.             }
  900.         }
  901.         $data = [
  902.             "library" => $libraryReturn,
  903.             "optionCorrect" => ( $optionCorrect $optionCorrect->getId() : null ),
  904.         ];
  905.         return $this->eadResponseNew($data);
  906.     }
  907.     /**
  908.      * @Route(
  909.      *      path          = "/admin/v2/lesson/{lessonId}/files",
  910.      *      methods       = {"GET"}
  911.      * )
  912.      */
  913.     public function getLessonFiles(Request $request) {
  914.         
  915.         $lessonRepository $this->em->getRepository(Lesson::class);
  916.         $lessonXLibraryRepository $this->em->getRepository(LessonXLibrary::class);
  917.         $lessonId $request->get('lessonId');
  918.         $lesson $lessonRepository->findOneBy([
  919.             "id" => $lessonId,
  920.             "deleted" => LessonEnum::ITEM_NO_DELETED
  921.         ]);
  922.         //check lesson exist
  923.         if (!$lesson) {
  924.             //redirect to index or home
  925.             throw new NotFoundException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  926.         }
  927.         //check user can access lesson
  928.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  929.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  930.         }
  931.         $files $lessonXLibraryRepository->getLessonXLibraryFiles($lesson);
  932.         
  933.         $data = [];
  934.         foreach ($files as $key => $file) {
  935.             $file $file->toReturn();
  936.             
  937.             $data[] = (object)[
  938.                 "name" => $file->libraryTitle,
  939.                 "size" => $file->libraryFileSize,
  940.                 "type" => $file->libraryType,
  941.                 "filename" => $file->libraryFile,
  942.                 "id" => $file->id,
  943.             ];
  944.         }
  945.         return $this->eadResponseNew($data);
  946.     }
  947.     /**
  948.      * @Route(
  949.      *      path          = "/admin/v2/lesson/{lessonId}/files/{id}",
  950.      *      methods       = {"GET"},
  951.      *      name          = "downloadLessonLibraryNew",
  952.      *      requirements  = { "id" = "\d+" }
  953.      * )
  954.      */
  955.     public function downloadLessonLibraryNew(Request $request) {
  956.         $lessonXLibraryId $request->get('id');
  957.         $lessonXLibrary $this->em->getRepository(LessonXLibrary::class)->findOneBy([
  958.             "id" => $lessonXLibraryId,
  959.             "type" => LessonXLibraryEnum::DOWNLOAD,
  960.             "deleted" => LessonXLibraryEnum::ITEM_NO_DELETED,
  961.         ]);
  962.         if (!$lessonXLibrary) {
  963.             throw new NotFoundException($this->configuration->getLanguage('error_library_lesson_not_found''lesson_view_error'));
  964.         }
  965.         
  966.         $library $lessonXLibrary->getLibrary();
  967.         $lesson $lessonXLibrary->getLesson();
  968.         $lessonRepository $this->em->getRepository(Lesson::class);
  969.         
  970.         //check user can access lesson
  971.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  972.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  973.         }
  974.         if($library){
  975.             $url null;
  976.             $type $library->getType();
  977.             if($type == LibraryEnum::CONTENT_VIDEO_FILE ||
  978.                 $type == LibraryEnum::CONTENT_AUDIO){
  979.                 $vdocipherService $this->generalService->getService('VdocipherService');
  980.                 $url $vdocipherService->getVideoDownloadLink(
  981.                     $library->getVdocipherVideoId()
  982.                 );
  983.                 
  984.             }else if($type == LibraryEnum::CONTENT_FILES){
  985.                 
  986.                 $isPdf = ($library->getFileExtension() == "pdf");
  987.                 $hasFunction $this->configuration->checkModuleIsAbleOnPlan(
  988.                     'lessonControlFunction'
  989.                 );
  990.                 $showDocument = (
  991.                     $lessonXLibrary->getControlShowDocument() == LibraryEnum::YES
  992.                 );
  993.                 
  994.                 if($isPdf && $hasFunction && $showDocument){
  995.                     
  996.                     $stringUtil $this->generalService->getUtil('StringUtil');
  997.                     $sessionHash $this->user->getSession()->getToken();
  998.                     $sessionHash $stringUtil->encodeHex($sessionHashfalsefalse);
  999.                     $path $this->generalService->generateUrl(
  1000.                         "downloadPdfLessonLibrary"
  1001.                         [ 
  1002.                             "id" => $lessonXLibraryId,
  1003.                             "sessionHash" => $sessionHash
  1004.                         ]
  1005.                     );
  1006.                     $domain = (
  1007.                         $request $request->getHost() : $this->client->getDomainPrimary()
  1008.                     );
  1009.                     $url "https://{$domain}{$path}";
  1010.                 }else{
  1011.                     $fileName LibraryEnum::PATH_LESSON_FILE "/{$library->getFileName()}";
  1012.                     $this->fileService->setFile($fileName);
  1013.                     $url $this->fileService->getFileUrlTemp();
  1014.                 }
  1015.             }
  1016.             if($url){
  1017.                 $oldDownload $library->getDownloadNumber();
  1018.                 $newDownload $oldDownload 1;
  1019.                 $library->setDownloadNumber($newDownload);
  1020.                 $this->em->flush();
  1021.                 return $this->eadResponseNew([ "url" => $url ]);
  1022.             }
  1023.         }
  1024.         throw new NotFoundException($this->configuration->getLanguage('error_library_lesson_not_found''lesson_view_error'));
  1025.     }
  1026.     /**
  1027.      * @Route(
  1028.      *      path          = "/admin/v2/course/{courseId}/notes",
  1029.      *      name          = "getCourseLessonNotesNew",
  1030.      *      methods       = {"GET"},
  1031.      * )
  1032.      */
  1033.     public function getCourseLessonNotesNew(Request $request) {
  1034.         $this->requestUtil->setRequest($request)->setData();
  1035.         $courseId $request->get('courseId');
  1036.         $course $this->repository->findOneBy([
  1037.             "id" => $courseId,
  1038.             "deleted" => CourseEnum::ITEM_NO_DELETED
  1039.         ]);
  1040.         
  1041.         if(!$course){
  1042.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  1043.         }
  1044.         $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  1045.             $course
  1046.             $this->user
  1047.         );
  1048.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1049.         $enrollment $enrollmentRepository->findOneBy([
  1050.             "user" => $this->user->getId(),
  1051.             "course" => $courseId,
  1052.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED,
  1053.         ], [ "id" => "DESC" ]);
  1054.         $permission $this->userPermissionUtil->getPermission("course""see");
  1055.         
  1056.         if(!$enrollment){
  1057.             if($course->getFree() == CourseEnum::NO){
  1058.                 if($this->userPermissionUtil->isLow($permission)){
  1059.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1060.                 }
  1061.                 if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
  1062.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1063.                 }
  1064.             }
  1065.             $enrollmentService $this->generalService->getService('EnrollmentService');
  1066.             $info $enrollmentService->enrollUser($this->user$course);
  1067.             
  1068.             if(!$info->errors){
  1069.                 $enrollment $info->enrollment;
  1070.             }
  1071.         }
  1072.         if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
  1073.             if(!$enrollment){
  1074.                 throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  1075.             }
  1076.             if($course->getStatus() == CourseEnum::DRAFT){
  1077.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  1078.             }
  1079.         }
  1080.         $searchText $this->requestUtil->getField('search');
  1081.         $lessonAnnotationRepository $this->em->getRepository(LessonAnnotation::class);
  1082.         $notes $lessonAnnotationRepository->getLessonAnnotationsByCourse(
  1083.             $course,
  1084.             $this->user
  1085.             $searchText
  1086.         );
  1087.         $aux = [];
  1088.         $auxLessons = [];
  1089.         foreach ($notes as $key => $note) {
  1090.             $lesson $note->getLesson();
  1091.             $lessonModule $lesson->getLessonModule();
  1092.             if(!isset($aux[$lessonModule->getId()])){
  1093.                 $aux[$lessonModule->getId()] = (object)[
  1094.                     "id" => $lessonModule->getId(),
  1095.                     "status" => $lessonModule->getStatus(),
  1096.                     "title" => $lessonModule->getTitle(),
  1097.                     "description" => $lessonModule->getDescription(),
  1098.                     "exam" => null,
  1099.                     "lessons" => [],
  1100.                 ];
  1101.             }
  1102.             $library $lesson->getLibrary();
  1103.             $libraryRepository $this->em->getRepository(Library::class);
  1104.             $timeUtil $this->generalService->getUtil('DateTimeUtil');
  1105.             $duration $library->getDuration();
  1106.             if(!isset($aux[$lesson->getId()])){
  1107.                 $auxLessons[$lesson->getId()] = (object)[
  1108.                     "id" => $lesson->getId(),
  1109.                     "lessonModule" => $lessonModule->getId(),
  1110.                     "title" => $lesson->getTitle(),
  1111.                     "status" => $lesson->getStatus(),
  1112.                     "lessonIsAccessible" => true,
  1113.                     "acessMessage" => null,
  1114.                     "contentPagesNumber" => null,
  1115.                     "contentDuration" => $duration $timeUtil->timeToSec($duration) : null,
  1116.                     "contentType" => null,
  1117.                     "contentThumb" => $libraryRepository->getCover($library),
  1118.                     "notes" => [],
  1119.                     "exam" => null,
  1120.                     "quiz" => null,
  1121.                     "allowCheck" => EnrollmentEnum::YES,
  1122.                 ];
  1123.             }
  1124.             $auxLessons[$lesson->getId()]->notes[] = (object)[
  1125.                 "id" => $note->getId(),
  1126.                 "annotation" => $note->getAnnotation(),
  1127.                 "options" => $note->getOptions(),
  1128.                 "time" => $note->getTime(),
  1129.                 "date" => $note->getDate(),
  1130.             ];
  1131.         }
  1132.         $data = [];
  1133.         foreach ($auxLessons as $key => $value) {
  1134.             if(isset($aux[$value->lessonModule])){
  1135.                 $aux[$value->lessonModule]->lessons[] = $value;
  1136.                 unset($value->lessonModule);
  1137.             }
  1138.         }
  1139.         foreach ($aux as $key => $value) {
  1140.             $data[] = $value;
  1141.         }
  1142.         return $this->eadResponseNew($data);
  1143.     }
  1144.     /**
  1145.      * @Route(
  1146.      *      path          = "/admin/v2/lesson/{lessonId}/notes",
  1147.      *      name          = "lessonAnnotationListNew",
  1148.      *      methods       = {"GET"},
  1149.      * )
  1150.      */
  1151.     public function lessonAnnotationListNew(Request $request) {
  1152.         $lessonId $request->get('lessonId');
  1153.         $lessonRepository $this->em->getRepository(Lesson::class);
  1154.         $lesson $lessonRepository->findOneBy([
  1155.             "id" => $lessonId,
  1156.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1157.         ]);
  1158.         //check lesson exist
  1159.         if (!$lesson) {
  1160.             //redirect to index or home
  1161.              throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1162.         }
  1163.         //check user can access lesson
  1164.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1165.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1166.         }
  1167.         $lessonAnnotationRepository $this->em->getRepository(LessonAnnotation::class);
  1168.         
  1169.         $annotations $lessonAnnotationRepository->findBy([
  1170.             "deleted" => LessonAnnotationEnum::ITEM_NO_DELETED,
  1171.             "lesson" => $lessonId,
  1172.             "user" => $this->user->getId(),
  1173.         ], [ "id" => "DESC" ]);
  1174.         $data = [];
  1175.         foreach ($annotations as $key => $annotation) {
  1176.             $data[] = (object)[
  1177.                 "id" => $annotation->getId(),
  1178.                 "annotation" => $annotation->getAnnotation(),
  1179.                 "options" => $annotation->getOptions(),
  1180.                 "time" => $annotation->getTime(),
  1181.                 "date" => $annotation->getDate(),
  1182.             ];
  1183.         }
  1184.         return $this->eadResponseNew($data);
  1185.     }
  1186.     /**
  1187.      * @Route(
  1188.      *      path          = "/admin/v2/lesson/{lessonId}/notes",
  1189.      *      name          = "registerLessonAnnotationNew",
  1190.      *      methods       = {"POST"},
  1191.      * )
  1192.      */
  1193.     public function registerLessonAnnotationNew(Request $request) {
  1194.         $lessonId $request->get('lessonId');
  1195.         $lessonRepository $this->em->getRepository(Lesson::class);
  1196.         $lesson $lessonRepository->findOneBy([
  1197.             "id" => $lessonId,
  1198.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1199.         ]);
  1200.         //check lesson exist
  1201.         if (!$lesson) {
  1202.             //redirect to index or home
  1203.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1204.         }
  1205.         //check user can access lesson
  1206.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1207.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1208.         }
  1209.         $this->requestUtil->setRequest($request)->setData();
  1210.         $lessonAnnotation = new LessonAnnotation();
  1211.         if($this->requestUtil->issetField('annotation')){
  1212.             $lessonAnnotation->setAnnotation($this->requestUtil->getField('annotation'));
  1213.         }
  1214.         if($this->requestUtil->issetField('options')){
  1215.             $lessonAnnotation->setOptions($this->requestUtil->getField('options'));
  1216.         }
  1217.         if($this->requestUtil->issetField('time')){
  1218.             $lessonAnnotation->setTime($this->requestUtil->getField('time'));
  1219.         }
  1220.         $lessonAnnotation->setLesson($lesson);
  1221.         $lessonAnnotation->setUser($this->user);
  1222.         $errors $this->validateEntity($lessonAnnotation);
  1223.         if($errors){
  1224.             throw new FieldException("FieldException"$errors);
  1225.         }
  1226.         $this->em->persist($lessonAnnotation);
  1227.         $this->em->flush();
  1228.         return $this->eadResponseNew((object)[
  1229.             "id" => $lessonAnnotation->getId(),
  1230.             "annotation" => $lessonAnnotation->getAnnotation(),
  1231.             "options" => $lessonAnnotation->getOptions(),
  1232.             "time" => $lessonAnnotation->getTime(),
  1233.             "date" => $lessonAnnotation->getDate(),
  1234.         ]);
  1235.     }
  1236.     /**
  1237.      * @Route(
  1238.      *      path          = "/admin/v2/lesson/{lessonId}/notes/{id}",
  1239.      *      name          = "lessonAnnotationEditNew",
  1240.      *      methods       = {"PUT"},
  1241.      *      requirements  = { "id" = "\d+" }
  1242.      * )
  1243.      */
  1244.     public function editLessonAnnotationNew(Request $request) {
  1245.         $this->requestUtil->setRequest($request)->setData();
  1246.         $lessonId $request->get('lessonId');
  1247.         $lessonAnnotationId $request->get('id');
  1248.         $lessonRepository $this->em->getRepository(Lesson::class);
  1249.         $lesson $lessonRepository->findOneBy([
  1250.             "id" => $lessonId,
  1251.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1252.         ]);
  1253.         //check lesson exist
  1254.         if (!$lesson) {
  1255.             //redirect to index or home
  1256.              throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1257.         }
  1258.         //check user can access lesson
  1259.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1260.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1261.         }
  1262.         
  1263.         $lessonAnnotationRepository $this->em->getRepository(lessonAnnotation::class);
  1264.         $lessonAnnotation $lessonAnnotationRepository->findOneBy([
  1265.             "id" => $lessonAnnotationId,
  1266.             "deleted" => LessonAnnotationEnum::ITEM_NO_DELETED
  1267.         ]);
  1268.         if (!$lessonAnnotation) {
  1269.             throw new NotFoundException($this->configuration->getLanguage('error_annotation_not_found''lesson_view_error'));
  1270.         }
  1271.         if($this->requestUtil->issetField('annotation')){
  1272.             $lessonAnnotation->setAnnotation($this->requestUtil->getField('annotation'));
  1273.         }
  1274.         if($this->requestUtil->issetField('time')){
  1275.             $lessonAnnotation->setTime($this->requestUtil->getField('time'));
  1276.         }
  1277.         if($this->requestUtil->issetField('options')){
  1278.             $lessonAnnotation->setOptions($this->requestUtil->getField('options'));
  1279.         }
  1280.         $errors $this->validateEntity($lessonAnnotation);
  1281.         if($errors){
  1282.             throw new FieldException("FieldException"$errors);
  1283.         }
  1284.         
  1285.         $this->em->flush();
  1286.         return $this->eadResponseNew((object)[
  1287.             "id" => $lessonAnnotation->getId(),
  1288.             "annotation" => $lessonAnnotation->getAnnotation(),
  1289.             "options" => $lessonAnnotation->getOptions(),
  1290.             "time" => $lessonAnnotation->getTime(),
  1291.             "date" => $lessonAnnotation->getDate(),
  1292.         ]);
  1293.     }
  1294.     /**
  1295.      * @Route(
  1296.      *      path          = "/admin/v2/lesson/{lessonId}/notes/{id}",
  1297.      *      name          = "lessonAnnotationDeleteNew",
  1298.      *      methods       = {"DELETE"},
  1299.      *      requirements  = { "id" = "\d+" }
  1300.      * )
  1301.      */
  1302.     public function deleteLessonAnnotationNew(Request $request) {
  1303.         $lessonId $request->get('lessonId');
  1304.         $lessonAnnotationId $request->get('id');
  1305.         $lessonRepository $this->em->getRepository(Lesson::class);
  1306.         $lesson $lessonRepository->findOneBy([
  1307.             "id" => $lessonId,
  1308.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1309.         ]);
  1310.         //check lesson exist
  1311.         if (!$lesson) {
  1312.             //redirect to index or home
  1313.              throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1314.         }
  1315.         //check user can access lesson
  1316.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1317.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1318.         }
  1319.         
  1320.         $lessonAnnotationRepository $this->em->getRepository(lessonAnnotation::class);
  1321.         $lessonAnnotation $lessonAnnotationRepository->findOneBy([
  1322.             "id" => $lessonAnnotationId,
  1323.             "deleted" => LessonAnnotationEnum::ITEM_NO_DELETED
  1324.         ]);
  1325.         if (!$lessonAnnotation) {
  1326.             throw new NotFoundException($this->configuration->getLanguage('error_annotation_not_found''lesson_view_error'));
  1327.         }
  1328.         $lessonAnnotation->delete();
  1329.         $this->em->flush();
  1330.         return $this->eadResponseNew([ "message" => "Success" ]);
  1331.     }
  1332.     /**
  1333.      * @Route(
  1334.      *      path          = "/admin/v2/lesson/{id}",
  1335.      *      methods       = {"PATCH"},
  1336.      *      name          = "updateLessonLogNew",
  1337.      *      requirements  = { "id" = "\d+" }
  1338.      * )
  1339.      */
  1340.     public function updateLessonLogNew(Request $request) {
  1341.         $this->requestUtil->setRequest($request)->setData();
  1342.         $lessonId $request->get('id');
  1343.         $lessonRepository $this->em->getRepository(Lesson::class);
  1344.         $lesson $lessonRepository->findOneBy([
  1345.             "id" => $lessonId,
  1346.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1347.         ]);
  1348.         //check lesson exist
  1349.         if (!$lesson) {
  1350.             //redirect to index or home
  1351.              throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1352.         }
  1353.         //check user can access lesson
  1354.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1355.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1356.         }
  1357.         $course $lesson->getCourse();
  1358.         $lessonModule $lesson->getLessonModule();
  1359.         $isStudent $this->repository->isStudent($course);
  1360.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1361.         $enrollment $enrollmentRepository->findOneBy([
  1362.             "user" => $this->user->getId(),
  1363.             "course" => $course->getId(),
  1364.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1365.         ], [ "id" => "DESC" ]);
  1366.         if(!$enrollment){
  1367.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  1368.         }
  1369.         $lessonLogRepository $this->emEadmin->getRepository(LessonLog::class);
  1370.         $logId "{$course->getId()}#{$this->user->getId()}#{$lesson->getId()}";
  1371.         $lessonLog $lessonLogRepository->find($logId);
  1372.         $new false;
  1373.         if(!$lessonLog){
  1374.             $new true;
  1375.             $lessonLog = new LessonLog();
  1376.             $lessonLog->setId($logId);
  1377.             $lessonLog->setCourse($course);
  1378.             $lessonLog->setLesson($lesson);
  1379.             $lessonLog->setUser($this->user);
  1380.         }
  1381.         if($this->requestUtil->issetField('timeWatch')){
  1382.             $timeWatch $this->requestUtil->getField('timeWatch');
  1383.             $lessonLog $lessonLogRepository->updateLessonLogNew(
  1384.                 $lessonLog,
  1385.                 $timeWatch
  1386.             );
  1387.         }
  1388.         if($this->requestUtil->issetField('rate')){
  1389.             $rate = (int)$this->requestUtil->getField('rate');
  1390.             $lessonLog->setRate($rate);
  1391.         }
  1392.         if($this->requestUtil->issetField('favorite')){
  1393.             $favorite = (int)$this->requestUtil->getField('favorite');
  1394.             $lessonLog->setFavorite($favorite);
  1395.         }
  1396.         if($this->requestUtil->issetField('completed')){
  1397.             $complete = (int)$this->requestUtil->getField('completed');
  1398.             $today date('Y-m-d H:i:s');
  1399.             $lessonLog->setDateAccess($today);
  1400.             $lessonLog->setViewed($complete);
  1401.             
  1402.             if(empty($lessonLog->getDateConclusion()) && $complete == LessonEnum::YES){
  1403.                 $lessonLog->setComplete($complete);
  1404.                 $lessonLog->setDateConclusion($today);
  1405.             }
  1406.         }
  1407.         if($new){
  1408.             $this->emEadmin->persist($lessonLog);
  1409.         }
  1410.         $this->em->getRepository(LessonLogOrigin::class)->copyFromDynamo($lessonLog);
  1411.         $enrollmentRepository->updateDataAccessLog($enrollment);
  1412.         $this->emEadmin->flush();
  1413.         $this->em->flush();
  1414.         $infoLog $lessonLogRepository->getTimeInfo($lesson$lessonLog);   
  1415.         $hasLessonControl $this->configuration->checkModuleIsAbleOnPlan(
  1416.             'lessonControlFunction'
  1417.         );
  1418.         $data = [
  1419.             "nextContent" => $lessonRepository->getLessonNextContent($lesson$lessonLog),
  1420.             "lastContent" => $lessonRepository->getLessonLastContent($lesson),
  1421.             "id" => $lesson->getId(),
  1422.             "moduleId" => $lessonModule->getId(),
  1423.             "courseId" => $course->getId(),
  1424.             "title" => $lesson->getTitle(),
  1425.             "description" => $lesson->getDescription(),
  1426.             "controlTime" => $hasLessonControl $lesson->getControlTime() : LessonEnum::NO,
  1427.             "controlViewLimit" => (
  1428.                 $hasLessonControl 
  1429.                 $lesson->getControlViewLimit() : 
  1430.                 LessonEnum::NO
  1431.             ),
  1432.             "controlViewNumber" => (
  1433.                 $hasLessonControl 
  1434.                 $lesson->getControlViewNumber() : 
  1435.                 LessonEnum::NO
  1436.             ),
  1437.             "controlPauseNumber" => (
  1438.                 $hasLessonControl 
  1439.                 $lesson->getControlPauseNumber() : 
  1440.                 LessonEnum::NO
  1441.             ),
  1442.             "controlShowDocument" => (
  1443.                 $hasLessonControl 
  1444.                 $lesson->getControlShowDocument() : 
  1445.                 LessonEnum::NO
  1446.             ),
  1447.             "showLiveChat" => $lessonRepository->getShowLiveChat($lesson$isStudent),
  1448.             "teacher" => $lessonRepository->getLessonTeacher($lesson),
  1449.             "rates" => $lessonLogRepository->countLessonLogRate(
  1450.                 $course->getId(),
  1451.                 $lesson->getId()
  1452.             ),
  1453.             "required" => $lesson->getControlRequirement(),
  1454.             "rate" => ($lessonLog $lessonLog->getRate() : LessonEnum::NO),
  1455.             "completed" => ($lessonLog $lessonLog->getViewed() : LessonEnum::NO),
  1456.             "numberAccess" => ($lessonLog $lessonLog->getNumberAccess() : null),
  1457.             "timeToStaySeconds" => $infoLog->timeToStaySeconds,
  1458.             "timeRestToComplete" => $infoLog->timeRestToComplete,
  1459.             "blockContent" => $lessonLogRepository->checkBlockView($lessonLog),
  1460.             "chat" => null,
  1461.             "library" => null,
  1462.             "productOffers" => null,
  1463.             "chapters" => null,
  1464.         ];
  1465.         return $this->eadResponseNew($data);
  1466.     }
  1467.     /**
  1468.      * @Route(
  1469.      *      path          = "/chat/v2/lesson/{id}/{fileName}",
  1470.      *      methods       = {"POST"},
  1471.      *      name          = "getSignedUploadUrlLessonChat",
  1472.      *      requirements  = { "id" = "\d+" }
  1473.      * )
  1474.      */
  1475.     public function getSignedUploadUrlLessonChat(Request $request) {
  1476.         $token $request->headers->get('X-AUTH-TOKEN');
  1477.         if($token != $this->generalService->getTokenCron()){
  1478.             throw new AuthInvalidException("Token Invalid");
  1479.         }
  1480.         $this->requestUtil->setRequest($request)->setData();
  1481.         $lessonId $request->get('id');
  1482.         $fileName $request->get('fileName');
  1483.         if(empty($fileName)){
  1484.             throw new FieldException("Empty Fields", [ "fileName" => "Empty "]);
  1485.         }
  1486.         $pathDefault LessonEnum::PATH_UPLOAD;
  1487.         $clientConnection $this->configuration->getClientConnection();
  1488.         $serverUser $clientConnection->getServerUser();
  1489.         $basekey "client/{$serverUser}{$pathDefault}chat/{$lessonId}/{$fileName}";
  1490.         $s3 $this->generalService->getService('Aws\\AwsS3');
  1491.         $url $s3->uploadItemSignedRequest($basekey$fileName);
  1492.         if(empty($url)){
  1493.         }
  1494.         $data = [
  1495.             "urlUpload" => $url,
  1496.         ];
  1497.         return new HttpOk($data);
  1498.     }
  1499.     /**
  1500.      * @Route(
  1501.      *      path          = "/chat/v2/lesson/{id}/{fileName}",
  1502.      *      methods       = {"DELETE"},
  1503.      *      name          = "deleteFileLessonChat",
  1504.      *      requirements  = { "id" = "\d+" }
  1505.      * )
  1506.      */
  1507.     public function deleteFileLessonChat(Request $request) {
  1508.         $token $request->headers->get('X-AUTH-TOKEN');
  1509.         if($token != $this->generalService->getTokenCron()){
  1510.             throw new AuthInvalidException("Token Invalid");
  1511.         }
  1512.         $this->requestUtil->setRequest($request)->setData();
  1513.         $lessonId $request->get('id');
  1514.         $fileName $request->get('fileName');
  1515.         if(empty($fileName)){
  1516.             throw new FieldException("Empty Fields", [ "fileName" => "Empty "]);
  1517.         }
  1518.         $objectKey "chat/{$lessonId}/{$fileName}";
  1519.         $s3 $this->generalService->getService('Aws\\AwsS3');
  1520.         $s3->deleteObjectS3($objectKey);
  1521.         return new HttpNoContent;
  1522.     }
  1523.     /**
  1524.      * @Route(
  1525.      *      path          = "/admin/v2/course/{courseId}/favorites",
  1526.      *      name          = "getCourseLessonFavoritesNew",
  1527.      *      methods       = {"GET"},
  1528.      * )
  1529.      */
  1530.     public function getCourseLessonFavoritesNew(Request $request) {
  1531.         $this->requestUtil->setRequest($request)->setData();
  1532.         $courseId $request->get('courseId');
  1533.         $course $this->repository->findOneBy([
  1534.             "id" => $courseId,
  1535.             "deleted" => CourseEnum::ITEM_NO_DELETED
  1536.         ]);
  1537.         
  1538.         if(!$course){
  1539.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  1540.         }
  1541.         $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  1542.             $course
  1543.             $this->user
  1544.         );
  1545.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1546.         $enrollment $enrollmentRepository->findOneBy([
  1547.             "user" => $this->user->getId(),
  1548.             "course" => $courseId,
  1549.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED,
  1550.         ], [ "id" => "DESC" ]);
  1551.         $permission $this->userPermissionUtil->getPermission("course""see");
  1552.         
  1553.         if(!$enrollment){
  1554.             if($course->getFree() == CourseEnum::NO){
  1555.                 if($this->userPermissionUtil->isLow($permission)){
  1556.                     throw new \EADPlataforma\Error\PermissionException("PermissionException");
  1557.                 }
  1558.                 if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
  1559.                     throw new \EADPlataforma\Error\PermissionException("PermissionException");
  1560.                 }
  1561.             }
  1562.             $enrollmentService $this->generalService->getService('EnrollmentService');
  1563.             $info $enrollmentService->enrollUser($this->user$course);
  1564.             
  1565.             if(!$info->errors){
  1566.                 $enrollment $info->enrollment;
  1567.             }
  1568.         }
  1569.         if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
  1570.             if(!$enrollment){
  1571.                 throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  1572.             }
  1573.             if($course->getStatus() == CourseEnum::DRAFT){
  1574.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  1575.             }
  1576.         }
  1577.         $searchText $this->requestUtil->getField('search');
  1578.         $lessonLogRepository $this->emEadmin->getRepository(LessonLog::class);
  1579.         $lessonIds $lessonLogRepository->findFavoriteLessonIds(
  1580.             $this->user->getId(), 
  1581.             $course->getId()
  1582.         );
  1583.         $lessonRepository $this->em->getRepository(Lesson::class);
  1584.         $lessons = [];
  1585.         if(!empty($lessonIds) && is_array($lessonIds)){
  1586.             $lessons $lessonRepository->getCourseLessons(
  1587.                 $course
  1588.                 null
  1589.                 $lessonIds
  1590.                 $searchText
  1591.             );
  1592.         }
  1593.         $aux = [];
  1594.         foreach ($lessons as $key => $lesson) {
  1595.             $lessonModule $lesson->getLessonModule();
  1596.             if(!isset($aux[$lessonModule->getId()])){
  1597.                 $aux[$lessonModule->getId()] = (object)[
  1598.                     "id" => $lessonModule->getId(),
  1599.                     "status" => $lessonModule->getStatus(),
  1600.                     "title" => $lessonModule->getTitle(),
  1601.                     "description" => $lessonModule->getDescription(),
  1602.                     "exam" => null,
  1603.                     "lessons" => [],
  1604.                 ];
  1605.             }
  1606.             $library $lesson->getLibrary();
  1607.             $libraryRepository $this->em->getRepository(Library::class);
  1608.             $timeUtil $this->generalService->getUtil('DateTimeUtil');
  1609.             $duration $library->getDuration();
  1610.             $aux[$lessonModule->getId()]->lessons[] = (object)[
  1611.                 "id" => $lesson->getId(),
  1612.                 "title" => $lesson->getTitle(),
  1613.                 "status" => $lesson->getStatus(),
  1614.                 "lessonIsAccessible" => true,
  1615.                 "acessMessage" => null,
  1616.                 "contentPagesNumber" => null,
  1617.                 "contentDuration" => $duration $timeUtil->timeToSec($duration) : null,
  1618.                 "contentType" => null,
  1619.                 "contentThumb" => $libraryRepository->getCover($library) ?? null,
  1620.                 "exam" => null,
  1621.                 "quiz" => null,
  1622.                 "allowCheck" => EnrollmentEnum::YES,
  1623.             ];
  1624.         }
  1625.         $data = [];
  1626.         foreach ($aux as $key => $value) {
  1627.             $data[] = $value;
  1628.         }
  1629.         return $this->eadResponseNew($data);
  1630.     }
  1631.     /**
  1632.      * @Route(
  1633.      *      path          = "/admin/v2/lesson/{id}/supports",
  1634.      *      methods       = {"GET"}
  1635.      * )
  1636.      */
  1637.     public function getLessonSupportNew(Request $request) {
  1638.         $this->requestUtil->setRequest($request)->setData();
  1639.         $lessonId $request->get('id');
  1640.         $lessonRepository $this->em->getRepository(Lesson::class);
  1641.         $lesson $lessonRepository->findOneBy([
  1642.             "id" => $lessonId,
  1643.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1644.         ]);
  1645.         if(!$lesson){
  1646.             throw new NotFoundException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1647.         }
  1648.         //check user can access lesson
  1649.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1650.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1651.         }
  1652.         $course $lesson->getCourse();
  1653.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1654.         $enrollment $enrollmentRepository->findOneBy([
  1655.             "user" => $this->user->getId(),
  1656.             "course" => $course->getId(),
  1657.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1658.         ], [ "id" => "DESC" ]);
  1659.         if(!$enrollment){
  1660.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  1661.         }
  1662.         $orderType = (int)$this->requestUtil->getField('orderType');
  1663.         $searchText $this->requestUtil->getField('searchText');
  1664.         $limit = (int)$this->requestUtil->getField('limit');
  1665.         $offset = (int)$this->requestUtil->getField('offset');
  1666.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1667.         $rows $lessonSupportRepository->getLessonSupportOrderTypeNew(
  1668.             $lesson->getId(), 
  1669.             $orderType,
  1670.             $searchText,
  1671.             $limit,
  1672.             $offset
  1673.         );
  1674.         $total $lessonSupportRepository->countLessonSupportOrderType(
  1675.             $lessonId
  1676.             $orderType
  1677.             $searchText
  1678.         );
  1679.         $permission $this->userPermissionUtil->getPermission(
  1680.             "course""support""delete"
  1681.         );
  1682.         $isLessonTeacher $lessonRepository->isLessonTeacher($lesson$this->user);
  1683.         $data = [
  1684.             "allowDeleteSupport" => (
  1685.                 $isLessonTeacher || $this->userPermissionUtil->isHigh($permission)
  1686.             ),
  1687.             "rowsTotal" => $total,
  1688.             "rowsTotalDisplay" => count($rows),
  1689.             "searchText" => $searchText,
  1690.             "limit" => (!empty($limit) ? $limit 10),
  1691.             "offset" => $offset,
  1692.             "orderType" => $orderType,
  1693.             "rows" => $rows
  1694.         ];
  1695.         $likeControlRepository $this->em->getRepository(LikeControl::class);
  1696.         $typesText = [
  1697.             LessonSupportEnum::LESSON_STUDENT => $this->configuration->getLanguage(
  1698.                 'student''lesson_view_error'
  1699.             ),
  1700.             LessonSupportEnum::COURSE_TEACHER => $this->configuration->getLanguage(
  1701.                 'teacher''lesson_view_error'
  1702.             ),
  1703.             LessonSupportEnum::MODULE_TEACHER => $this->configuration->getLanguage(
  1704.                 'teacher_module''lesson_view_error'
  1705.             ),
  1706.             LessonSupportEnum::LESSON_TEACHER => $this->configuration->getLanguage(
  1707.                 'coordinator''lesson_view_error'
  1708.             ),
  1709.             LessonSupportEnum::LESSON_TUTOR => $this->configuration->getLanguage(
  1710.                 'tutor''lesson_view_error'
  1711.             ),
  1712.         ];
  1713.         foreach ($data['rows'] as $key => $item) {
  1714.             $item = (object)$item;
  1715.             $dataImg = [
  1716.                 "fileName" => $item->photo,
  1717.                 "pathConst" => LessonSupportEnum::PATH_PROFILES,
  1718.                 "option" => "l-user-profile-support",
  1719.                 "addUpload" => true,
  1720.                 "addStream" => true,
  1721.             ];
  1722.             $item->photo $this->fileService->getFilePathObj($dataImg);
  1723.             $item->support html_entity_decode($item->support);
  1724.             $item->answers $lessonSupportRepository->getLessonSupportAnswers($item->id);
  1725.             $item->lessonUserType = (int)$item->lessonUserType;
  1726.             $item->lessonUserTypeText $typesText[$item->lessonUserType];
  1727.             
  1728.             $likeControl $likeControlRepository->findOneByEAD([
  1729.                 "userFrom" => $this->user->getId(),
  1730.                 "element" => $item->id,
  1731.                 "type" => LikeControlEnum::LESSON_SUPPORT,
  1732.             ]);
  1733.             $item->allowLike true;
  1734.             if($likeControl){
  1735.                 $item->allowLike false;
  1736.             }
  1737.             $data['rows'][$key] = $item;
  1738.         }
  1739.         return $this->eadResponseNew($data);
  1740.     }
  1741.     /**
  1742.      * @Route(
  1743.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}/pin",
  1744.      *      methods       = {"PUT"}
  1745.      * )
  1746.      */
  1747.     public function pinLessonSupport(Request $request) {
  1748.         $permission $this->userPermissionUtil->getPermission("course""support""finalize");
  1749.         if($this->userPermissionUtil->isLow($permission)){
  1750.             throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1751.         }
  1752.         
  1753.         $this->requestUtil->setRequest($request)->setData();
  1754.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1755.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1756.         $lessonSupport $lessonSupportRepository->findOneBy([
  1757.             "id" => $lessonSupportId,
  1758.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1759.         ]);
  1760.         
  1761.         if (!$lessonSupport) {
  1762.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1763.         }
  1764.         $lesson $lessonSupport->getLesson();
  1765.         $isLessonTeacher $this->em->getRepository(Lesson::class)->isLessonTeacher(
  1766.             $lesson
  1767.             $this->user
  1768.         );
  1769.         
  1770.         if(!$isLessonTeacher && $this->userPermissionUtil->isMiddle($permission)){
  1771.             throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1772.         }
  1773.         $lessonSupport->setLessonFixed(LessonSupportEnum::YES);
  1774.         $this->em->flush();
  1775.         $data $lessonSupport->toReturn();
  1776.         return $this->eadResponseNew([ "message" => "Success" ]);
  1777.     }
  1778.     /**
  1779.      * @Route(
  1780.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}/unpin",
  1781.      *      methods       = {"DELETE"}
  1782.      * )
  1783.      */
  1784.     public function unpinLessonSupport(Request $request) {
  1785.         $permission $this->userPermissionUtil->getPermission("course""support""finalize");
  1786.         if($this->userPermissionUtil->isLow($permission)){
  1787.             throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1788.         }
  1789.         
  1790.         $this->requestUtil->setRequest($request)->setData();
  1791.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1792.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1793.         $lessonSupport $lessonSupportRepository->findOneBy([
  1794.             "id" => $lessonSupportId,
  1795.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1796.         ]);
  1797.         
  1798.         if (!$lessonSupport) {
  1799.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1800.         }
  1801.         $lesson $lessonSupport->getLesson();
  1802.         $isLessonTeacher $this->em->getRepository(Lesson::class)->isLessonTeacher(
  1803.             $lesson
  1804.             $this->user
  1805.         );
  1806.         
  1807.         if(!$isLessonTeacher && $this->userPermissionUtil->isMiddle($permission)){
  1808.             throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1809.         }
  1810.         $lessonSupport->setLessonFixed(LessonSupportEnum::NO);
  1811.         $this->em->flush();
  1812.         $data $lessonSupport->toReturn();
  1813.         return $this->eadResponseNew([ "message" => "Success" ]);
  1814.     }
  1815.     /**
  1816.      * @Route(
  1817.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}",
  1818.      *      methods       = {"PATCH"}
  1819.      * )
  1820.      */
  1821.     public function likeLessonSupport(Request $request) {
  1822.         $this->requestUtil->setRequest($request)->setData();
  1823.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1824.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1825.         $lessonSupport $lessonSupportRepository->findOneBy([
  1826.             "id" => $lessonSupportId,
  1827.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1828.         ]);
  1829.         
  1830.         if (!$lessonSupport) {
  1831.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1832.         }
  1833.         $lesson $lessonSupport->getLesson();
  1834.         
  1835.         $likeControl = new LikeControl();
  1836.         $type LikeControlEnum::LESSON_SUPPORT;
  1837.         if($lessonSupport->getLessonSupport()){
  1838.             $type LikeControlEnum::LESSON_SUPPORT_ANSWER;
  1839.         }
  1840.         $likeControl->setElement($lessonSupportId);
  1841.         $likeControl->setType($type);
  1842.         $likeControl->setUserTo($lessonSupport->getUser());
  1843.         $likeControl->setUserFrom($this->user);
  1844.         
  1845.         $errors $this->validateEntity($likeControl);
  1846.         if($errors){
  1847.             throw new FieldException("FieldException"$errors);
  1848.         }
  1849.         $lessonSupport->setLikeNumber($lessonSupport->getLikeNumber() + 1);
  1850.         
  1851.         $this->em->persist($likeControl);
  1852.         $this->em->flush();
  1853.         return $this->eadResponseNew([ "message" => "Success" ]);
  1854.     }
  1855.     /**
  1856.      * @Route(
  1857.      *      path          = "/admin/v2/lesson/{id}/supports",
  1858.      *      methods       = {"POST"},
  1859.      * )
  1860.      */
  1861.     public function registerLessonSupport(Request $request) {
  1862.         
  1863.         $this->requestUtil->setRequest($request)->setData();
  1864.         $lessonRepository $this->em->getRepository(Lesson::class);
  1865.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1866.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1867.         $lessonId $request->get('id');
  1868.         $lesson $lessonRepository->findOneBy([
  1869.             "id" => $lessonId,
  1870.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1871.         ]);
  1872.         if(!$lesson){
  1873.             throw new NotFoundException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1874.         }
  1875.         //check user can access lesson
  1876.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1877.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1878.         }
  1879.         $lessonSupport = new LessonSupport();
  1880.         
  1881.         $lessonSupport->setUser($this->user);
  1882.         $lessonSupport->setLesson($lesson);
  1883.         //set LessonSupport in LessonSupport
  1884.         if($this->requestUtil->issetField('lessonSupport')){
  1885.             $lessonSupportId = (int)$this->requestUtil->getField('lessonSupport');
  1886.             $lessonSupportParent $lessonSupportRepository->findOneBy([
  1887.                 "id" => $lessonSupportId,
  1888.                 "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1889.             ]);
  1890.             $lessonSupport->setLessonSupport($lessonSupportParent);
  1891.         }
  1892.         
  1893.         if($this->requestUtil->issetField('support')){
  1894.             $lessonSupport->setSupport($this->requestUtil->getField('support'));
  1895.         }
  1896.         $errors $this->validateEntity($lessonSupport);
  1897.         if($errors){
  1898.             throw new FieldException("FieldException"$errors);
  1899.         }
  1900.         
  1901.         $lessonSupportParent $lessonSupport->getLessonSupport();
  1902.         $lesson $lessonSupport->getLesson();
  1903.         $course $lesson->getCourse();
  1904.         
  1905.         $isLessonTeacher $lessonRepository->isLessonTeacher(
  1906.             $lesson
  1907.             $this->user
  1908.         );
  1909.         $isEnrolled $enrollmentRepository->isValidEnrollmentByUser(
  1910.             $this->user->getId(), 
  1911.             $course->getId()
  1912.         );
  1913.         $permission $this->userPermissionUtil->getPermission("course""support""answer");
  1914.         if($lessonSupportParent){
  1915.             if(!$isEnrolled){
  1916.                 if($this->userPermissionUtil->isLow($permission)){
  1917.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1918.                 }
  1919.                 if(!$isLessonTeacher && $this->userPermissionUtil->isMiddle($permission)){
  1920.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1921.                 }
  1922.             }
  1923.         }else{
  1924.             if($course->getSupport() == LessonSupportEnum::NO){
  1925.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_support''lesson_view_error'));
  1926.             }
  1927.             if(!$isEnrolled && !$isLessonTeacher){
  1928.                 throw new ActionInvalidException($this->configuration->getLanguage('error_unavailable''lesson_view_error'));
  1929.             }
  1930.         }
  1931.         $this->em->persist($lessonSupport);
  1932.         $this->em->flush();
  1933.         $lessonSupportRepository->processNewLessonSupport($lessonSupport);
  1934.          
  1935.         return $this->eadResponseNew([ "message" => "Success" ]);
  1936.     }
  1937.     /**
  1938.      * @Route(
  1939.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}",
  1940.      *      methods       = {"PUT"}
  1941.      * )
  1942.      */
  1943.     public function editLessonSupport(Request $request) {
  1944.         $this->requestUtil->setRequest($request)->setData();
  1945.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1946.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1947.         $lessonSupport $lessonSupportRepository->findOneBy([
  1948.             "id" => $lessonSupportId,
  1949.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1950.         ]);
  1951.         
  1952.         if (!$lessonSupport) {
  1953.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1954.         }
  1955.         $lesson $lessonSupport->getLesson();
  1956.         
  1957.         if($this->requestUtil->issetField('support')){
  1958.             $lessonSupport->setSupport($this->requestUtil->getField('support'));
  1959.         }
  1960.         $lessonSupport->setDateUpdate(date('Y-m-d H:i:s'));
  1961.         
  1962.         $errors $this->validateEntity($lessonSupport);
  1963.         if($errors){
  1964.             throw new FieldException("FieldException"$errors);
  1965.         }
  1966.         $this->em->flush();
  1967.         return $this->eadResponseNew([ "message" => "Success" ]);
  1968.     }
  1969.     /**
  1970.      * @Route(
  1971.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}",
  1972.      *      methods       = {"DELETE"}
  1973.      * )
  1974.      */
  1975.     public function deleteLessonSupport(Request $request) {
  1976.         $this->requestUtil->setRequest($request)->setData();
  1977.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1978.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1979.         $lessonSupport $lessonSupportRepository->findOneBy([
  1980.             "id" => $lessonSupportId,
  1981.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1982.         ]);
  1983.         
  1984.         if (!$lessonSupport) {
  1985.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1986.         }
  1987.         
  1988.         $lessonSupportRepository->delete(
  1989.             $lessonSupport
  1990.             TrashEnum::LESSON_SUPPORT
  1991.             $this->userPermissionUtil->getPermission("course""support""delete"), 
  1992.             TrashEnum::NO
  1993.         );
  1994.         $this->em->flush();
  1995.         return $this->eadResponseNew([ "message" => "Success" ]);
  1996.     }
  1997.     /**
  1998.      * @Route(
  1999.      *      path          = "/admin/v2/course/{id}/testimonial",
  2000.      *      methods       = {"POST"},
  2001.      * )
  2002.      */
  2003.     public function registerCourseTestimonial(Request $request) {
  2004.         $this->requestUtil->setRequest($request)->setData();
  2005.         $courseId $request->get('id');
  2006.         $course $this->repository->findOneBy([
  2007.             "id" => $courseId,
  2008.             "deleted" => CourseEnum::ITEM_NO_DELETED
  2009.         ]);
  2010.         
  2011.         if(!$course){
  2012.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  2013.         }
  2014.         $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  2015.             $course
  2016.             $this->user
  2017.         );
  2018.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  2019.         $enrollment $enrollmentRepository->findOneBy([
  2020.             "user" => $this->user->getId(),
  2021.             "course" => $courseId,
  2022.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED,
  2023.         ], [ "id" => "DESC" ]);
  2024.         $permission $this->userPermissionUtil->getPermission("course""see");
  2025.         
  2026.         if(!$enrollment){
  2027.             if($course->getFree() == CourseEnum::NO){
  2028.                 if($this->userPermissionUtil->isLow($permission)){
  2029.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  2030.                 }
  2031.                 if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
  2032.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  2033.                 }
  2034.             }
  2035.             $enrollmentService $this->generalService->getService('EnrollmentService');
  2036.             $info $enrollmentService->enrollUser($this->user$course);
  2037.             
  2038.             if(!$info->errors){
  2039.                 $enrollment $info->enrollment;
  2040.             }
  2041.         }
  2042.         if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
  2043.             if(!$enrollment){
  2044.                 throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  2045.             }
  2046.             if($course->getStatus() == CourseEnum::DRAFT){
  2047.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  2048.             }
  2049.         }
  2050.         $courseTestimonial = new CourseTestimonial();
  2051.         $courseTestimonial->setDate(date('Y-m-d H:i:s'));
  2052.         $courseTestimonial->setStatus(CourseTestimonialEnum::WAITING);
  2053.         if($this->requestUtil->issetField('score')){
  2054.             $courseTestimonial->setScore((int)$this->requestUtil->getField("score"));
  2055.         }
  2056.         if($this->requestUtil->issetField('testimonial')){
  2057.             $courseTestimonial->setTestimonial($this->requestUtil->getField('testimonial'));
  2058.         }
  2059.         $courseTestimonial->setUser($this->user);
  2060.         $courseTestimonial->setCourse($course);
  2061.         $errors $this->validateEntity($courseTestimonial);
  2062.         if($errors){
  2063.             throw new FieldException("FieldException"$errors);
  2064.         }
  2065.         $this->em->persist($courseTestimonial);
  2066.         $this->em->flush();
  2067.         $userWebhook $this->em->getRepository(User::class)->getToWebhook(
  2068.             $courseTestimonial->getUser()
  2069.         );
  2070.       
  2071.         $dataObj= (object)[
  2072.             "user" => $userWebhook,
  2073.             "course"=> (object)[        
  2074.                 "id" => (string)$courseTestimonial->getCourse()->getId(),
  2075.                 "name" => $courseTestimonial->getCourse()->getTitle(),
  2076.             ],
  2077.             "testimonial"=> (object)[
  2078.                 "stars" => $courseTestimonial->getScore(),
  2079.                 "comment" => $courseTestimonial->getTestimonial(),
  2080.                 "dates" => (object)[
  2081.                     "created" => $courseTestimonial->getDate(),
  2082.                 ],
  2083.             ],
  2084.             "enrollment"=> $enrollment->toWebhook(),
  2085.         ];
  2086.         $webhookService $this->generalService->getService('WebhookService');
  2087.         $webhookService->addItemList(WebhookEnum::TESTIMONIAL$dataObj);
  2088.         $notificationService $this->generalService->getService(
  2089.             'NotificationService'
  2090.         );
  2091.         
  2092.         
  2093.         if($this->user != $course->getUser()){
  2094.             $notificationService->create(
  2095.                 $this->user
  2096.                 $course->getUser(),
  2097.                 NotificationEnum::ORIGIN_COURSE_TESTIMONIAL_NEW,
  2098.                 $courseTestimonial->getId()
  2099.             );
  2100.         }
  2101.         $userCourse $course->getUser();
  2102.         if($userCourse->getAllowNotifyNewSupportMessage() == CourseTestimonialEnum::YES){
  2103.             $emailService $this->generalService->getService('EmailService');
  2104.             if($emailService->checkUserToSend($userCourse)){
  2105.                 $emailService->setToEmail($userCourse->getEmail());
  2106.                 $emailService->setToName($userCourse->getName());
  2107.     
  2108.                 $subText $this->configuration->getLanguage(
  2109.                     'new_course_testimonial.subject''email'
  2110.                 );
  2111.                 
  2112.                 $id $courseTestimonial->getId();
  2113.                 $subject "{$subText} - {$course->getTitle()}";
  2114.                 $emailService->setSubject($subject);
  2115.     
  2116.                 $emailService->setData([
  2117.                     "userName" => $userCourse->getName(),
  2118.                     "btnLink" => "{$this->adminLink}courses/testimonials/{$id}",
  2119.                 ]);
  2120.     
  2121.                 $emailService->setTemplateBody("new_course_testimonial");
  2122.                 $emailService->send();
  2123.             }
  2124.         }
  2125.         $data $courseTestimonial->toReturn();
  2126.         $this->userLogService->logInsert(
  2127.             "course_testimonial"
  2128.             $courseTestimonial->getId(), 
  2129.             $data
  2130.         );
  2131.         $testimonial = (object)[
  2132.             "id" => $courseTestimonial->getId(),
  2133.             "score" => $courseTestimonial->getScore(),
  2134.             "testimonial" => $courseTestimonial->getTestimonial(),
  2135.         ];
  2136.         return $this->eadResponseNew($testimonial);
  2137.     }
  2138.     /**
  2139.      * @Route(
  2140.      *      path          = "/admin/v2/course/{courseId}/testimonial/{id}",
  2141.      *      methods       = {"PUT"}
  2142.      * )
  2143.      */
  2144.     public function editCourseTestimonial(Request $request) {
  2145.         $courseId $request->get('courseId');
  2146.         $course $this->repository->findOneBy([
  2147.             "id" => $courseId,
  2148.             "deleted" => CourseEnum::ITEM_NO_DELETED
  2149.         ]);
  2150.         
  2151.         if(!$course){
  2152.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  2153.         }
  2154.         $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  2155.             $course
  2156.             $this->user
  2157.         );
  2158.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  2159.         $enrollment $enrollmentRepository->findOneBy([
  2160.             "user" => $this->user->getId(),
  2161.             "course" => $courseId,
  2162.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED,
  2163.         ], [ "id" => "DESC" ]);
  2164.         $permission $this->userPermissionUtil->getPermission("course""see");
  2165.         
  2166.         if(!$enrollment){
  2167.             if($course->getFree() == CourseEnum::NO){
  2168.                 if($this->userPermissionUtil->isLow($permission)){
  2169.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  2170.                 }
  2171.                 if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
  2172.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  2173.                 }
  2174.             }
  2175.             $enrollmentService $this->generalService->getService('EnrollmentService');
  2176.             $info $enrollmentService->enrollUser($this->user$course);
  2177.             
  2178.             if(!$info->errors){
  2179.                 $enrollment $info->enrollment;
  2180.             }
  2181.         }
  2182.         if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
  2183.             if(!$enrollment){
  2184.                 throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  2185.             }
  2186.             if($course->getStatus() == CourseEnum::DRAFT){
  2187.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  2188.             }
  2189.         }
  2190.         $testimonialId $request->get('id');
  2191.         $courseTestimonialRepository $this->em->getRepository(CourseTestimonial::class);
  2192.         $courseTestimonial $courseTestimonialRepository->findOneBy([
  2193.             "id" => $testimonialId,
  2194.             "deleted" => CourseTestimonialEnum::ITEM_NO_DELETED
  2195.         ]);
  2196.         if (!$courseTestimonial || empty($testimonialId)) {
  2197.             throw new NotFoundException($this->configuration->getLanguage('error_testimonial_not_found''lesson_view_error'));
  2198.         }
  2199.         $this->requestUtil->setRequest($request)->setData();
  2200.         if($this->requestUtil->issetField('score')){
  2201.             $courseTestimonial->setScore((int)$this->requestUtil->getField("score"));
  2202.         }
  2203.         if($this->requestUtil->issetField('testimonial')){
  2204.             $courseTestimonial->setTestimonial($this->requestUtil->getField('testimonial'));
  2205.         }
  2206.         
  2207.         $courseTestimonial->setDate(date('Y-m-d H:i:s'));
  2208.         $courseTestimonial->setStatus(CourseTestimonialEnum::WAITING);
  2209.         $errors $this->validateEntity($courseTestimonial);
  2210.         
  2211.         if($errors){
  2212.             throw new FieldException("FieldException"$errors);
  2213.         }
  2214.         $this->em->flush();
  2215.         $notificationService $this->generalService->getService('NotificationService');
  2216.         $emailService $this->generalService->getService('EmailService');
  2217.         if($this->user != $course->getUser()){
  2218.             $notificationService->create(
  2219.                 $this->user
  2220.                 $course->getUser(),
  2221.                 NotificationEnum::ORIGIN_COURSE_TESTIMONIAL_CHANGE,
  2222.                 $courseTestimonial->getId()
  2223.             );
  2224.         }
  2225.         $user $course->getUser();
  2226.         if($user->getAllowNotifyNewSupportMessage() == CourseTestimonialEnum::YES){
  2227.             if($emailService->checkUserToSend($user)){
  2228.                 $emailService->setToEmail($user->getEmail());
  2229.                 $emailService->setToName($user->getName());
  2230.                 $subText $this->configuration->getLanguage(
  2231.                     'new_course_testimonial.subject''email'
  2232.                 );
  2233.                 $subject "{$subText} - {$course->getTitle()}";
  2234.                 $emailService->setSubject($subject);
  2235.                 
  2236.                 $emailService->setData([
  2237.                     "userName" => $course->getUser()->getName(),
  2238.                     "btnLink" => "{$this->adminLink}courses/testimonials/{$testimonialId}",
  2239.                 ]);
  2240.                 $emailService->setTemplateBody("new_course_testimonial");
  2241.                 $emailService->send();
  2242.             }
  2243.         }
  2244.         $data $courseTestimonial->toReturn();
  2245.         $this->userLogService->logUpdate(
  2246.             "course_testimonial"
  2247.             $courseTestimonial->getId(),
  2248.             $data
  2249.         );
  2250.         $testimonial = (object)[
  2251.             "id" => $courseTestimonial->getId(),
  2252.             "score" => $courseTestimonial->getScore(),
  2253.             "testimonial" => $courseTestimonial->getTestimonial(),
  2254.         ];
  2255.         return $this->eadResponseNew($testimonial);
  2256.     }
  2257. }