src/Controller/Admin/CourseIndexController.php line 1097

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.                         $questionAnswer->setEvaluated(QuestionEnum::YES);
  675.                         $question->setAnswered(QuestionEnum::YES);
  676.                         if($question->getType() == QuestionEnum::ALTERNATIVE){
  677.                             $grade ExamUserAnswerEnum::GRADE_CORRECT;
  678.                         }
  679.                     }
  680.                     $questionAnswerOption = new ExamUserAnswerOption();
  681.                     $questionAnswerOption->setMarked(QuestionEnum::YES);
  682.                     $questionAnswerOption->setExamUserAnswer($questionAnswer);
  683.                     $questionAnswerOption->setQuestionOption($questionOption);
  684.                     $this->em->persist($questionAnswerOption);
  685.                 }
  686.             }
  687.             if($question->getType() == QuestionEnum::MULTIPLE_ALTERNATIVE){
  688.                 $grade $examUserAnswerService->correctMultipleAlternatives(
  689.                     $options
  690.                     $optionsCorrect
  691.                 );
  692.             }
  693.         }
  694.         $questionAnswer->setGrade($grade);
  695.         $this->em->flush();
  696.         sleep(0.5);
  697.         $questionNumberAnswer $examUserAnswerRepository->count([
  698.             "examUser" => $examUser->getId(),
  699.             "deleted" => ExamUserAnswerEnum::ITEM_NO_DELETED,
  700.             "answered" => QuestionEnum::YES
  701.         ]);
  702.         $questionNumber $exam->getQuestionNumber();
  703.         $questionNumberReal $exam->getQuestionNumberReal();
  704.         if($questionNumber $questionNumberReal){
  705.             $questionNumber $questionNumberReal;
  706.         }
  707.         if($exam->getQuestionOrder() == ExamEnum::SEQUENTIAL){
  708.             $questionNumber count($exam->getLiveQuestion());
  709.         }
  710.         if($questionNumber <= $questionNumberAnswer){
  711.             $examUserRepository->updateExamUser($examUser);
  712.         }
  713.         $data $questionAnswer->toReturn();
  714.         $this->userLogService->logInsert("exam_user_answer"$questionAnswer->getId(), $data);
  715.         $data $examUserRepository->getDataIndexNew($exam$user);
  716.         return $this->eadResponseNew($data);
  717.     }
  718.     /**
  719.      * @Route(
  720.      *      path          = "/admin/v2/{module}/{id}/exam/outside",
  721.      *      methods       = {"PATCH"},
  722.      *      name          = "outsideExam",
  723.      *      requirements  = { "id" = "\d+" }
  724.      * )
  725.      */
  726.     public function outsideExam(Request $request)
  727.     {
  728.         if(!$this->configuration->isModuleActive("exam_module")){
  729.             throw new ActionInvalidException("ActionInvalidException");
  730.         }
  731.         $idModule = (int)$request->get('id');
  732.         $module $request->get('module');
  733.         $class = [
  734.             "lesson" => Lesson::class,
  735.             "module" => LessonModule::class,
  736.             "course" => Course::class,
  737.         ];
  738.         if(!isset($class[$module])){
  739.             throw new NotFoundException("NotFoundException");
  740.         }
  741.         $itemRepository $this->em->getRepository($class[$module]);
  742.         $item $itemRepository->findOneBy([
  743.             "id" => $idModule,
  744.             "deleted" => CourseEnum::ITEM_NO_DELETED
  745.         ]);
  746.         //check item exist
  747.         if(!$item){
  748.             //redirect to index or home
  749.             throw new NotFoundException("NotFoundException");
  750.         }
  751.         $course $item;
  752.         if(!($course instanceof Course)){
  753.             $course $item->getCourse();
  754.         }
  755.         $user $this->user;
  756.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  757.         $enrollment $enrollmentRepository->findOneBy([
  758.             "user" => $user->getId(),
  759.             "course" => $course->getId(),
  760.             "deleted" => LessonEnum::ITEM_NO_DELETED
  761.         ], [ "id" => "DESC" ]);
  762.         if(!$enrollment){
  763.             throw new ActionInvalidException("ActionInvalidException");
  764.         }
  765.         $filterExam = [
  766.             "course" => $course->getId(),
  767.             "deleted" => ExamEnum::ITEM_NO_DELETED
  768.         ];
  769.         if($item instanceof Course){
  770.             $filterExam["type"] = ExamEnum::COURSE;
  771.         }else if($item instanceof LessonModule){
  772.             $filterExam["lessonModule"] = $item->getId();
  773.             $filterExam["type"] = ExamEnum::MODULE;
  774.         }else if($item instanceof Lesson){
  775.             //check user can access lesson
  776.             if(!$itemRepository->isLessonVisibleToStudent($item)){
  777.                 throw new ActionInvalidException("ActionInvalidException");
  778.             }
  779.             $lessonModule $item->getLessonModule();
  780.             $filterExam["lesson"] = $item->getId();
  781.             $filterExam["lessonModule"] = $lessonModule->getId();
  782.             $filterExam["type"] = ExamEnum::LESSON;
  783.         }
  784.         $exam $this->em->getRepository(Exam::class)->findOneBy($filterExam);
  785.         if(!$exam){
  786.             throw new NotFoundException("NotFoundException");
  787.         }
  788.         if($exam->getControlTime() == ExamEnum::NO){
  789.             throw new NotFoundException("ActionInvalidException");
  790.         }
  791.         $examUserRepository $this->em->getRepository(ExamUser::class);
  792.         
  793.         $examUser $examUserRepository->findOneBy([
  794.             "user" => $user->getId(),
  795.             "exam" => $exam->getId(),
  796.             "inactive" => ExamUserEnum::NO,
  797.             "deleted" => ExamUserEnum::ITEM_NO_DELETED
  798.         ]);
  799.         if(!$examUser){
  800.             throw new ActionInvalidException("ActionInvalidException");
  801.         }
  802.         if($examUser->getStatus() !== ExamUserEnum::IN_PROGRESS){
  803.             throw new ActionInvalidException("ActionInvalidException");
  804.         }
  805.         $timeUtil $this->generalService->getUtil('DateTimeUtil');
  806.         $examUser $examUserRepository->getValidExamUserById(
  807.             $examUser->getId(), 
  808.             true
  809.         );
  810.         $this->requestUtil->setRequest($request)->setData();
  811.         $outsideNumber $examUser->getOutsideNumber();
  812.         $newOutsideNumber $outsideNumber 1;
  813.         $examUser->setOutsideNumber($newOutsideNumber);
  814.         $outsideTime '00:00:00';
  815.         if(!empty($examUser->getOutsideTime())){
  816.             $outsideTime $examUser->getOutsideTime();
  817.         }
  818.         if($this->requestUtil->issetField('outsideTime')){
  819.             $newTime $this->requestUtil->getField('outsideTime');
  820.             $newTime $timeUtil->timeToSec($newTime);
  821.             $oldTime $timeUtil->timeToSec($outsideTime);
  822.             $sumTime $oldTime $newTime;
  823.             $time $timeUtil->secToTime($sumTime);
  824.             $examUser->setOutsideTime($time);
  825.         }
  826.         $errors $this->validateEntity($examUser);
  827.         if($errors){
  828.             throw new FieldException("FieldException"$errors);
  829.         }
  830.         
  831.         $this->em->flush();
  832.         return $this->eadResponseNew([ "message" => "Success" ]);
  833.     }
  834.     /**
  835.      * @Route(
  836.      *      path          = "/admin/v2/lesson/{id}/quiz/{questionId}",
  837.      *      methods       = {"POST"}
  838.      * )
  839.      */
  840.     public function getQuestionQuizAnswer(Request $request) {
  841.         $questionRepository $this->em->getRepository(Question::class);
  842.         $questionOptionRepository $this->em->getRepository(QuestionOption::class);
  843.         $libraryRepository $this->em->getRepository(Library::class);
  844.         $this->requestUtil->setRequest($request)->setData();
  845.         $questionId = (int)$request->get('questionId');
  846.         $lessonId = (int)$request->get('id');
  847.         
  848.         $lessonRepository $this->em->getRepository(Lesson::class);
  849.         $lesson $lessonRepository->findOneBy([
  850.             "id" => $lessonId,
  851.             "deleted" => LessonEnum::ITEM_NO_DELETED
  852.         ]);
  853.         //check item exist
  854.         if(!$lesson){
  855.             throw new NotFoundException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  856.         }
  857.         $question $questionRepository->findOneBy([
  858.             "id" => $questionId,
  859.             "deleted" => QuestionEnum::ITEM_NO_DELETED
  860.         ]);
  861.         if(!$question){
  862.             throw new NotFoundException($this->configuration->getLanguage('error_question_not_found''lesson_view_error'));
  863.         }
  864.         $optionCorrect $questionOptionRepository->findOneBy([
  865.             "deleted" => QuestionOptionEnum::ITEM_NO_DELETED,
  866.             "question" => $questionId,
  867.             "correct" => QuestionOptionEnum::YES,
  868.         ]);
  869.         $libraryReturn null;
  870.         $library $question->getLibrary();
  871.         if($library){
  872.             $libraryInfo $libraryRepository->getContentInfo($libraryfalse$lesson);
  873.             $libraryReturn = (object)[
  874.                 "id" => $library->getId(),
  875.                 "title" => $library->getTitle(),
  876.                 "type" => $library->getType(),
  877.                 "link" => $libraryInfo->url,
  878.                 "text" => $library->getText(),
  879.                 "file" => $library->getId(),
  880.                 "fileExtension" => $library->getFileExtension(),
  881.                 "liveStart" => $library->getLiveStart(),
  882.                 "liveEmbedId" => $libraryInfo->embedId,
  883.                 "pagesNumber" => $library->getPagesNumber(),
  884.                 "duration" => $library->getDuration(),
  885.             ];
  886.             $showDocument = ($lesson->getControlShowDocument() == LibraryEnum::YES);
  887.             $drmVideo $this->configuration->get("drm_video");
  888.             $hasLessonControl $this->configuration->checkModuleIsAbleOnPlan(
  889.                 'lessonControlFunction'
  890.             );
  891.             $annotate = [];
  892.             if($hasLessonControl && $showDocument && $drmVideo == LibraryEnum::YES){
  893.                 $annotate $libraryRepository->getVideoDRM($this->user);
  894.             }
  895.             $credentials $libraryRepository->getVideoCredentials(
  896.                 $library,
  897.                 $annotate
  898.             );
  899.             if($credentials){
  900.                 $libraryReturn->credentials $credentials;
  901.             }
  902.         }
  903.         $data = [
  904.             "library" => $libraryReturn,
  905.             "optionCorrect" => ( $optionCorrect $optionCorrect->getId() : null ),
  906.         ];
  907.         return $this->eadResponseNew($data);
  908.     }
  909.     /**
  910.      * @Route(
  911.      *      path          = "/admin/v2/lesson/{lessonId}/files",
  912.      *      methods       = {"GET"}
  913.      * )
  914.      */
  915.     public function getLessonFiles(Request $request) {
  916.         
  917.         $lessonRepository $this->em->getRepository(Lesson::class);
  918.         $lessonXLibraryRepository $this->em->getRepository(LessonXLibrary::class);
  919.         $lessonId $request->get('lessonId');
  920.         $lesson $lessonRepository->findOneBy([
  921.             "id" => $lessonId,
  922.             "deleted" => LessonEnum::ITEM_NO_DELETED
  923.         ]);
  924.         //check lesson exist
  925.         if (!$lesson) {
  926.             //redirect to index or home
  927.             throw new NotFoundException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  928.         }
  929.         //check user can access lesson
  930.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  931.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  932.         }
  933.         $files $lessonXLibraryRepository->getLessonXLibraryFiles($lesson);
  934.         
  935.         $data = [];
  936.         foreach ($files as $key => $file) {
  937.             $file $file->toReturn();
  938.             
  939.             $data[] = (object)[
  940.                 "name" => $file->libraryTitle,
  941.                 "size" => $file->libraryFileSize,
  942.                 "type" => $file->libraryType,
  943.                 "filename" => $file->libraryFile,
  944.                 "id" => $file->id,
  945.             ];
  946.         }
  947.         return $this->eadResponseNew($data);
  948.     }
  949.     /**
  950.      * @Route(
  951.      *      path          = "/admin/v2/lesson/{lessonId}/files/{id}",
  952.      *      methods       = {"GET"},
  953.      *      name          = "downloadLessonLibraryNew",
  954.      *      requirements  = { "id" = "\d+" }
  955.      * )
  956.      */
  957.     public function downloadLessonLibraryNew(Request $request) {
  958.         $lessonXLibraryId $request->get('id');
  959.         $lessonXLibrary $this->em->getRepository(LessonXLibrary::class)->findOneBy([
  960.             "id" => $lessonXLibraryId,
  961.             "type" => LessonXLibraryEnum::DOWNLOAD,
  962.             "deleted" => LessonXLibraryEnum::ITEM_NO_DELETED,
  963.         ]);
  964.         if (!$lessonXLibrary) {
  965.             throw new NotFoundException($this->configuration->getLanguage('error_library_lesson_not_found''lesson_view_error'));
  966.         }
  967.         
  968.         $library $lessonXLibrary->getLibrary();
  969.         $lesson $lessonXLibrary->getLesson();
  970.         $lessonRepository $this->em->getRepository(Lesson::class);
  971.         
  972.         //check user can access lesson
  973.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  974.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  975.         }
  976.         if($library){
  977.             $url null;
  978.             $type $library->getType();
  979.             if($type == LibraryEnum::CONTENT_VIDEO_FILE ||
  980.                 $type == LibraryEnum::CONTENT_AUDIO){
  981.                 $vdocipherService $this->generalService->getService('VdocipherService');
  982.                 $url $vdocipherService->getVideoDownloadLink(
  983.                     $library->getVdocipherVideoId()
  984.                 );
  985.                 
  986.             }else if($type == LibraryEnum::CONTENT_FILES){
  987.                 
  988.                 $isPdf = ($library->getFileExtension() == "pdf");
  989.                 $hasFunction $this->configuration->checkModuleIsAbleOnPlan(
  990.                     'lessonControlFunction'
  991.                 );
  992.                 $showDocument = (
  993.                     $lessonXLibrary->getControlShowDocument() == LibraryEnum::YES
  994.                 );
  995.                 
  996.                 if($isPdf && $hasFunction && $showDocument){
  997.                     
  998.                     $stringUtil $this->generalService->getUtil('StringUtil');
  999.                     $sessionHash $this->user->getSession()->getToken();
  1000.                     $sessionHash $stringUtil->encodeHex($sessionHashfalsefalse);
  1001.                     $path $this->generalService->generateUrl(
  1002.                         "downloadPdfLessonLibrary"
  1003.                         [ 
  1004.                             "id" => $lessonXLibraryId,
  1005.                             "sessionHash" => $sessionHash
  1006.                         ]
  1007.                     );
  1008.                     $domain = (
  1009.                         $request $request->getHost() : $this->client->getDomainPrimary()
  1010.                     );
  1011.                     $url "https://{$domain}{$path}";
  1012.                 }else{
  1013.                     $fileName LibraryEnum::PATH_LESSON_FILE "/{$library->getFileName()}";
  1014.                     $this->fileService->setFile($fileName);
  1015.                     $url $this->fileService->getFileUrlTemp();
  1016.                 }
  1017.             }
  1018.             if($url){
  1019.                 $oldDownload $library->getDownloadNumber();
  1020.                 $newDownload $oldDownload 1;
  1021.                 $library->setDownloadNumber($newDownload);
  1022.                 $this->em->flush();
  1023.                 return $this->eadResponseNew([ "url" => $url ]);
  1024.             }
  1025.         }
  1026.         throw new NotFoundException($this->configuration->getLanguage('error_library_lesson_not_found''lesson_view_error'));
  1027.     }
  1028.     /**
  1029.      * @Route(
  1030.      *      path          = "/admin/v2/course/{courseId}/notes",
  1031.      *      name          = "getCourseLessonNotesNew",
  1032.      *      methods       = {"GET"},
  1033.      * )
  1034.      */
  1035.     public function getCourseLessonNotesNew(Request $request) {
  1036.         $this->requestUtil->setRequest($request)->setData();
  1037.         $courseId $request->get('courseId');
  1038.         $course $this->repository->findOneBy([
  1039.             "id" => $courseId,
  1040.             "deleted" => CourseEnum::ITEM_NO_DELETED
  1041.         ]);
  1042.         
  1043.         if(!$course){
  1044.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  1045.         }
  1046.         $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  1047.             $course
  1048.             $this->user
  1049.         );
  1050.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1051.         $enrollment $enrollmentRepository->findOneBy([
  1052.             "user" => $this->user->getId(),
  1053.             "course" => $courseId,
  1054.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED,
  1055.         ], [ "id" => "DESC" ]);
  1056.         $permission $this->userPermissionUtil->getPermission("course""see");
  1057.         
  1058.         if(!$enrollment){
  1059.             if($course->getFree() == CourseEnum::NO){
  1060.                 if($this->userPermissionUtil->isLow($permission)){
  1061.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1062.                 }
  1063.                 if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
  1064.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1065.                 }
  1066.             }
  1067.             $enrollmentService $this->generalService->getService('EnrollmentService');
  1068.             $info $enrollmentService->enrollUser($this->user$course);
  1069.             
  1070.             if(!$info->errors){
  1071.                 $enrollment $info->enrollment;
  1072.             }
  1073.         }
  1074.         if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
  1075.             if(!$enrollment){
  1076.                 throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  1077.             }
  1078.             if($course->getStatus() == CourseEnum::DRAFT){
  1079.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  1080.             }
  1081.         }
  1082.         $searchText $this->requestUtil->getField('search');
  1083.         $lessonAnnotationRepository $this->em->getRepository(LessonAnnotation::class);
  1084.         $notes $lessonAnnotationRepository->getLessonAnnotationsByCourse(
  1085.             $course,
  1086.             $this->user
  1087.             $searchText
  1088.         );
  1089.         $aux = [];
  1090.         $auxLessons = [];
  1091.         foreach ($notes as $key => $note) {
  1092.             $lesson $note->getLesson();
  1093.             $lessonModule $lesson->getLessonModule();
  1094.             if(!isset($aux[$lessonModule->getId()])){
  1095.                 $aux[$lessonModule->getId()] = (object)[
  1096.                     "id" => $lessonModule->getId(),
  1097.                     "status" => $lessonModule->getStatus(),
  1098.                     "title" => $lessonModule->getTitle(),
  1099.                     "description" => $lessonModule->getDescription(),
  1100.                     "exam" => null,
  1101.                     "lessons" => [],
  1102.                 ];
  1103.             }
  1104.             $library $lesson->getLibrary();
  1105.             $libraryRepository $this->em->getRepository(Library::class);
  1106.             $timeUtil $this->generalService->getUtil('DateTimeUtil');
  1107.             $duration $library->getDuration();
  1108.             if(!isset($aux[$lesson->getId()])){
  1109.                 $auxLessons[$lesson->getId()] = (object)[
  1110.                     "id" => $lesson->getId(),
  1111.                     "lessonModule" => $lessonModule->getId(),
  1112.                     "title" => $lesson->getTitle(),
  1113.                     "status" => $lesson->getStatus(),
  1114.                     "lessonIsAccessible" => true,
  1115.                     "acessMessage" => null,
  1116.                     "contentPagesNumber" => null,
  1117.                     "contentDuration" => $duration $timeUtil->timeToSec($duration) : null,
  1118.                     "contentType" => null,
  1119.                     "contentThumb" => $libraryRepository->getCover($library),
  1120.                     "notes" => [],
  1121.                     "exam" => null,
  1122.                     "quiz" => null,
  1123.                     "allowCheck" => EnrollmentEnum::YES,
  1124.                 ];
  1125.             }
  1126.             $auxLessons[$lesson->getId()]->notes[] = (object)[
  1127.                 "id" => $note->getId(),
  1128.                 "annotation" => $note->getAnnotation(),
  1129.                 "options" => $note->getOptions(),
  1130.                 "time" => $note->getTime(),
  1131.                 "date" => $note->getDate(),
  1132.             ];
  1133.         }
  1134.         $data = [];
  1135.         foreach ($auxLessons as $key => $value) {
  1136.             if(isset($aux[$value->lessonModule])){
  1137.                 $aux[$value->lessonModule]->lessons[] = $value;
  1138.                 unset($value->lessonModule);
  1139.             }
  1140.         }
  1141.         foreach ($aux as $key => $value) {
  1142.             $data[] = $value;
  1143.         }
  1144.         return $this->eadResponseNew($data);
  1145.     }
  1146.     /**
  1147.      * @Route(
  1148.      *      path          = "/admin/v2/lesson/{lessonId}/notes",
  1149.      *      name          = "lessonAnnotationListNew",
  1150.      *      methods       = {"GET"},
  1151.      * )
  1152.      */
  1153.     public function lessonAnnotationListNew(Request $request) {
  1154.         $lessonId $request->get('lessonId');
  1155.         $lessonRepository $this->em->getRepository(Lesson::class);
  1156.         $lesson $lessonRepository->findOneBy([
  1157.             "id" => $lessonId,
  1158.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1159.         ]);
  1160.         //check lesson exist
  1161.         if (!$lesson) {
  1162.             //redirect to index or home
  1163.              throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1164.         }
  1165.         //check user can access lesson
  1166.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1167.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1168.         }
  1169.         $lessonAnnotationRepository $this->em->getRepository(LessonAnnotation::class);
  1170.         
  1171.         $annotations $lessonAnnotationRepository->findBy([
  1172.             "deleted" => LessonAnnotationEnum::ITEM_NO_DELETED,
  1173.             "lesson" => $lessonId,
  1174.             "user" => $this->user->getId(),
  1175.         ], [ "id" => "DESC" ]);
  1176.         $data = [];
  1177.         foreach ($annotations as $key => $annotation) {
  1178.             $data[] = (object)[
  1179.                 "id" => $annotation->getId(),
  1180.                 "annotation" => $annotation->getAnnotation(),
  1181.                 "options" => $annotation->getOptions(),
  1182.                 "time" => $annotation->getTime(),
  1183.                 "date" => $annotation->getDate(),
  1184.             ];
  1185.         }
  1186.         return $this->eadResponseNew($data);
  1187.     }
  1188.     /**
  1189.      * @Route(
  1190.      *      path          = "/admin/v2/lesson/{lessonId}/notes",
  1191.      *      name          = "registerLessonAnnotationNew",
  1192.      *      methods       = {"POST"},
  1193.      * )
  1194.      */
  1195.     public function registerLessonAnnotationNew(Request $request) {
  1196.         $lessonId $request->get('lessonId');
  1197.         $lessonRepository $this->em->getRepository(Lesson::class);
  1198.         $lesson $lessonRepository->findOneBy([
  1199.             "id" => $lessonId,
  1200.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1201.         ]);
  1202.         //check lesson exist
  1203.         if (!$lesson) {
  1204.             //redirect to index or home
  1205.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1206.         }
  1207.         //check user can access lesson
  1208.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1209.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1210.         }
  1211.         $this->requestUtil->setRequest($request)->setData();
  1212.         $lessonAnnotation = new LessonAnnotation();
  1213.         if($this->requestUtil->issetField('annotation')){
  1214.             $lessonAnnotation->setAnnotation($this->requestUtil->getField('annotation'));
  1215.         }
  1216.         if($this->requestUtil->issetField('options')){
  1217.             $lessonAnnotation->setOptions($this->requestUtil->getField('options'));
  1218.         }
  1219.         if($this->requestUtil->issetField('time')){
  1220.             $lessonAnnotation->setTime($this->requestUtil->getField('time'));
  1221.         }
  1222.         $lessonAnnotation->setLesson($lesson);
  1223.         $lessonAnnotation->setUser($this->user);
  1224.         $errors $this->validateEntity($lessonAnnotation);
  1225.         if($errors){
  1226.             throw new FieldException("FieldException"$errors);
  1227.         }
  1228.         $this->em->persist($lessonAnnotation);
  1229.         $this->em->flush();
  1230.         return $this->eadResponseNew((object)[
  1231.             "id" => $lessonAnnotation->getId(),
  1232.             "annotation" => $lessonAnnotation->getAnnotation(),
  1233.             "options" => $lessonAnnotation->getOptions(),
  1234.             "time" => $lessonAnnotation->getTime(),
  1235.             "date" => $lessonAnnotation->getDate(),
  1236.         ]);
  1237.     }
  1238.     /**
  1239.      * @Route(
  1240.      *      path          = "/admin/v2/lesson/{lessonId}/notes/{id}",
  1241.      *      name          = "lessonAnnotationEditNew",
  1242.      *      methods       = {"PUT"},
  1243.      *      requirements  = { "id" = "\d+" }
  1244.      * )
  1245.      */
  1246.     public function editLessonAnnotationNew(Request $request) {
  1247.         $this->requestUtil->setRequest($request)->setData();
  1248.         $lessonId $request->get('lessonId');
  1249.         $lessonAnnotationId $request->get('id');
  1250.         $lessonRepository $this->em->getRepository(Lesson::class);
  1251.         $lesson $lessonRepository->findOneBy([
  1252.             "id" => $lessonId,
  1253.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1254.         ]);
  1255.         //check lesson exist
  1256.         if (!$lesson) {
  1257.             //redirect to index or home
  1258.              throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1259.         }
  1260.         //check user can access lesson
  1261.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1262.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1263.         }
  1264.         
  1265.         $lessonAnnotationRepository $this->em->getRepository(lessonAnnotation::class);
  1266.         $lessonAnnotation $lessonAnnotationRepository->findOneBy([
  1267.             "id" => $lessonAnnotationId,
  1268.             "deleted" => LessonAnnotationEnum::ITEM_NO_DELETED
  1269.         ]);
  1270.         if (!$lessonAnnotation) {
  1271.             throw new NotFoundException($this->configuration->getLanguage('error_annotation_not_found''lesson_view_error'));
  1272.         }
  1273.         if($this->requestUtil->issetField('annotation')){
  1274.             $lessonAnnotation->setAnnotation($this->requestUtil->getField('annotation'));
  1275.         }
  1276.         if($this->requestUtil->issetField('time')){
  1277.             $lessonAnnotation->setTime($this->requestUtil->getField('time'));
  1278.         }
  1279.         if($this->requestUtil->issetField('options')){
  1280.             $lessonAnnotation->setOptions($this->requestUtil->getField('options'));
  1281.         }
  1282.         $errors $this->validateEntity($lessonAnnotation);
  1283.         if($errors){
  1284.             throw new FieldException("FieldException"$errors);
  1285.         }
  1286.         
  1287.         $this->em->flush();
  1288.         return $this->eadResponseNew((object)[
  1289.             "id" => $lessonAnnotation->getId(),
  1290.             "annotation" => $lessonAnnotation->getAnnotation(),
  1291.             "options" => $lessonAnnotation->getOptions(),
  1292.             "time" => $lessonAnnotation->getTime(),
  1293.             "date" => $lessonAnnotation->getDate(),
  1294.         ]);
  1295.     }
  1296.     /**
  1297.      * @Route(
  1298.      *      path          = "/admin/v2/lesson/{lessonId}/notes/{id}",
  1299.      *      name          = "lessonAnnotationDeleteNew",
  1300.      *      methods       = {"DELETE"},
  1301.      *      requirements  = { "id" = "\d+" }
  1302.      * )
  1303.      */
  1304.     public function deleteLessonAnnotationNew(Request $request) {
  1305.         $lessonId $request->get('lessonId');
  1306.         $lessonAnnotationId $request->get('id');
  1307.         $lessonRepository $this->em->getRepository(Lesson::class);
  1308.         $lesson $lessonRepository->findOneBy([
  1309.             "id" => $lessonId,
  1310.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1311.         ]);
  1312.         //check lesson exist
  1313.         if (!$lesson) {
  1314.             //redirect to index or home
  1315.              throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1316.         }
  1317.         //check user can access lesson
  1318.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1319.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1320.         }
  1321.         
  1322.         $lessonAnnotationRepository $this->em->getRepository(lessonAnnotation::class);
  1323.         $lessonAnnotation $lessonAnnotationRepository->findOneBy([
  1324.             "id" => $lessonAnnotationId,
  1325.             "deleted" => LessonAnnotationEnum::ITEM_NO_DELETED
  1326.         ]);
  1327.         if (!$lessonAnnotation) {
  1328.             throw new NotFoundException($this->configuration->getLanguage('error_annotation_not_found''lesson_view_error'));
  1329.         }
  1330.         $lessonAnnotation->delete();
  1331.         $this->em->flush();
  1332.         return $this->eadResponseNew([ "message" => "Success" ]);
  1333.     }
  1334.     /**
  1335.      * @Route(
  1336.      *      path          = "/admin/v2/lesson/{id}",
  1337.      *      methods       = {"PATCH"},
  1338.      *      name          = "updateLessonLogNew",
  1339.      *      requirements  = { "id" = "\d+" }
  1340.      * )
  1341.      */
  1342.     public function updateLessonLogNew(Request $request) {
  1343.         $this->requestUtil->setRequest($request)->setData();
  1344.         $lessonId $request->get('id');
  1345.         $lessonRepository $this->em->getRepository(Lesson::class);
  1346.         $lesson $lessonRepository->findOneBy([
  1347.             "id" => $lessonId,
  1348.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1349.         ]);
  1350.         //check lesson exist
  1351.         if (!$lesson) {
  1352.             //redirect to index or home
  1353.              throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1354.         }
  1355.         //check user can access lesson
  1356.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1357.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1358.         }
  1359.         $course $lesson->getCourse();
  1360.         $lessonModule $lesson->getLessonModule();
  1361.         $isStudent $this->repository->isStudent($course);
  1362.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1363.         $enrollment $enrollmentRepository->findOneBy([
  1364.             "user" => $this->user->getId(),
  1365.             "course" => $course->getId(),
  1366.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1367.         ], [ "id" => "DESC" ]);
  1368.         if(!$enrollment){
  1369.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  1370.         }
  1371.         $lessonLogRepository $this->emEadmin->getRepository(LessonLog::class);
  1372.         $logId "{$course->getId()}#{$this->user->getId()}#{$lesson->getId()}";
  1373.         $lessonLog $lessonLogRepository->find($logId);
  1374.         $new false;
  1375.         if(!$lessonLog){
  1376.             $new true;
  1377.             $lessonLog = new LessonLog();
  1378.             $lessonLog->setId($logId);
  1379.             $lessonLog->setCourse($course);
  1380.             $lessonLog->setLesson($lesson);
  1381.             $lessonLog->setUser($this->user);
  1382.         }
  1383.         if($this->requestUtil->issetField('timeWatch')){
  1384.             $timeWatch $this->requestUtil->getField('timeWatch');
  1385.             $lessonLog $lessonLogRepository->updateLessonLogNew(
  1386.                 $lessonLog,
  1387.                 $timeWatch
  1388.             );
  1389.         }
  1390.         if($this->requestUtil->issetField('rate')){
  1391.             $rate = (int)$this->requestUtil->getField('rate');
  1392.             $lessonLog->setRate($rate);
  1393.         }
  1394.         if($this->requestUtil->issetField('favorite')){
  1395.             $favorite = (int)$this->requestUtil->getField('favorite');
  1396.             $lessonLog->setFavorite($favorite);
  1397.         }
  1398.         if($this->requestUtil->issetField('completed')){
  1399.             $complete = (int)$this->requestUtil->getField('completed');
  1400.             $today date('Y-m-d H:i:s');
  1401.             $lessonLog->setDateAccess($today);
  1402.             $lessonLog->setViewed($complete);
  1403.             
  1404.             if(empty($lessonLog->getDateConclusion()) && $complete == LessonEnum::YES){
  1405.                 $lessonLog->setComplete($complete);
  1406.                 $lessonLog->setDateConclusion($today);
  1407.             }
  1408.         }
  1409.         if($new){
  1410.             $this->emEadmin->persist($lessonLog);
  1411.         }
  1412.         $this->em->getRepository(LessonLogOrigin::class)->copyFromDynamo($lessonLog);
  1413.         $enrollmentRepository->updateDataAccessLog($enrollment);
  1414.         $this->emEadmin->flush();
  1415.         $this->em->flush();
  1416.         $infoLog $lessonLogRepository->getTimeInfo($lesson$lessonLog);   
  1417.         $hasLessonControl $this->configuration->checkModuleIsAbleOnPlan(
  1418.             'lessonControlFunction'
  1419.         );
  1420.         $data = [
  1421.             "nextContent" => $lessonRepository->getLessonNextContent($lesson$lessonLog),
  1422.             "lastContent" => $lessonRepository->getLessonLastContent($lesson),
  1423.             "id" => $lesson->getId(),
  1424.             "moduleId" => $lessonModule->getId(),
  1425.             "courseId" => $course->getId(),
  1426.             "title" => $lesson->getTitle(),
  1427.             "description" => $lesson->getDescription(),
  1428.             "controlTime" => $hasLessonControl $lesson->getControlTime() : LessonEnum::NO,
  1429.             "controlViewLimit" => (
  1430.                 $hasLessonControl 
  1431.                 $lesson->getControlViewLimit() : 
  1432.                 LessonEnum::NO
  1433.             ),
  1434.             "controlViewNumber" => (
  1435.                 $hasLessonControl 
  1436.                 $lesson->getControlViewNumber() : 
  1437.                 LessonEnum::NO
  1438.             ),
  1439.             "controlPauseNumber" => (
  1440.                 $hasLessonControl 
  1441.                 $lesson->getControlPauseNumber() : 
  1442.                 LessonEnum::NO
  1443.             ),
  1444.             "controlShowDocument" => (
  1445.                 $hasLessonControl 
  1446.                 $lesson->getControlShowDocument() : 
  1447.                 LessonEnum::NO
  1448.             ),
  1449.             "showLiveChat" => $lessonRepository->getShowLiveChat($lesson$isStudent),
  1450.             "teacher" => $lessonRepository->getLessonTeacher($lesson),
  1451.             "rates" => $lessonLogRepository->countLessonLogRate(
  1452.                 $course->getId(),
  1453.                 $lesson->getId()
  1454.             ),
  1455.             "required" => $lesson->getControlRequirement(),
  1456.             "rate" => ($lessonLog $lessonLog->getRate() : LessonEnum::NO),
  1457.             "completed" => ($lessonLog $lessonLog->getViewed() : LessonEnum::NO),
  1458.             "numberAccess" => ($lessonLog $lessonLog->getNumberAccess() : null),
  1459.             "timeToStaySeconds" => $infoLog->timeToStaySeconds,
  1460.             "timeRestToComplete" => $infoLog->timeRestToComplete,
  1461.             "blockContent" => $lessonLogRepository->checkBlockView($lessonLog),
  1462.             "chat" => null,
  1463.             "library" => null,
  1464.             "productOffers" => null,
  1465.             "chapters" => null,
  1466.         ];
  1467.         return $this->eadResponseNew($data);
  1468.     }
  1469.     /**
  1470.      * @Route(
  1471.      *      path          = "/chat/v2/lesson/{id}/{fileName}",
  1472.      *      methods       = {"POST"},
  1473.      *      name          = "getSignedUploadUrlLessonChat",
  1474.      *      requirements  = { "id" = "\d+" }
  1475.      * )
  1476.      */
  1477.     public function getSignedUploadUrlLessonChat(Request $request) {
  1478.         $token $request->headers->get('X-AUTH-TOKEN');
  1479.         if($token != $this->generalService->getTokenCron()){
  1480.             throw new AuthInvalidException("Token Invalid");
  1481.         }
  1482.         $this->requestUtil->setRequest($request)->setData();
  1483.         $lessonId $request->get('id');
  1484.         $fileName $request->get('fileName');
  1485.         if(empty($fileName)){
  1486.             throw new FieldException("Empty Fields", [ "fileName" => "Empty "]);
  1487.         }
  1488.         $pathDefault LessonEnum::PATH_UPLOAD;
  1489.         $clientConnection $this->configuration->getClientConnection();
  1490.         $serverUser $clientConnection->getServerUser();
  1491.         $basekey "client/{$serverUser}{$pathDefault}chat/{$lessonId}/{$fileName}";
  1492.         $s3 $this->generalService->getService('Aws\\AwsS3');
  1493.         $url $s3->uploadItemSignedRequest($basekey$fileName);
  1494.         if(empty($url)){
  1495.         }
  1496.         $data = [
  1497.             "urlUpload" => $url,
  1498.         ];
  1499.         return new HttpOk($data);
  1500.     }
  1501.     /**
  1502.      * @Route(
  1503.      *      path          = "/chat/v2/lesson/{id}/{fileName}",
  1504.      *      methods       = {"DELETE"},
  1505.      *      name          = "deleteFileLessonChat",
  1506.      *      requirements  = { "id" = "\d+" }
  1507.      * )
  1508.      */
  1509.     public function deleteFileLessonChat(Request $request) {
  1510.         $token $request->headers->get('X-AUTH-TOKEN');
  1511.         if($token != $this->generalService->getTokenCron()){
  1512.             throw new AuthInvalidException("Token Invalid");
  1513.         }
  1514.         $this->requestUtil->setRequest($request)->setData();
  1515.         $lessonId $request->get('id');
  1516.         $fileName $request->get('fileName');
  1517.         if(empty($fileName)){
  1518.             throw new FieldException("Empty Fields", [ "fileName" => "Empty "]);
  1519.         }
  1520.         $objectKey "chat/{$lessonId}/{$fileName}";
  1521.         $s3 $this->generalService->getService('Aws\\AwsS3');
  1522.         $s3->deleteObjectS3($objectKey);
  1523.         return new HttpNoContent;
  1524.     }
  1525.     /**
  1526.      * @Route(
  1527.      *      path          = "/admin/v2/course/{courseId}/favorites",
  1528.      *      name          = "getCourseLessonFavoritesNew",
  1529.      *      methods       = {"GET"},
  1530.      * )
  1531.      */
  1532.     public function getCourseLessonFavoritesNew(Request $request) {
  1533.         $this->requestUtil->setRequest($request)->setData();
  1534.         $courseId $request->get('courseId');
  1535.         $course $this->repository->findOneBy([
  1536.             "id" => $courseId,
  1537.             "deleted" => CourseEnum::ITEM_NO_DELETED
  1538.         ]);
  1539.         
  1540.         if(!$course){
  1541.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  1542.         }
  1543.         $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  1544.             $course
  1545.             $this->user
  1546.         );
  1547.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1548.         $enrollment $enrollmentRepository->findOneBy([
  1549.             "user" => $this->user->getId(),
  1550.             "course" => $courseId,
  1551.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED,
  1552.         ], [ "id" => "DESC" ]);
  1553.         $permission $this->userPermissionUtil->getPermission("course""see");
  1554.         
  1555.         if(!$enrollment){
  1556.             if($course->getFree() == CourseEnum::NO){
  1557.                 if($this->userPermissionUtil->isLow($permission)){
  1558.                     throw new \EADPlataforma\Error\PermissionException("PermissionException");
  1559.                 }
  1560.                 if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
  1561.                     throw new \EADPlataforma\Error\PermissionException("PermissionException");
  1562.                 }
  1563.             }
  1564.             $enrollmentService $this->generalService->getService('EnrollmentService');
  1565.             $info $enrollmentService->enrollUser($this->user$course);
  1566.             
  1567.             if(!$info->errors){
  1568.                 $enrollment $info->enrollment;
  1569.             }
  1570.         }
  1571.         if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
  1572.             if(!$enrollment){
  1573.                 throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  1574.             }
  1575.             if($course->getStatus() == CourseEnum::DRAFT){
  1576.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  1577.             }
  1578.         }
  1579.         $searchText $this->requestUtil->getField('search');
  1580.         $lessonLogRepository $this->emEadmin->getRepository(LessonLog::class);
  1581.         $lessonIds $lessonLogRepository->findFavoriteLessonIds(
  1582.             $this->user->getId(), 
  1583.             $course->getId()
  1584.         );
  1585.         $lessonRepository $this->em->getRepository(Lesson::class);
  1586.         $lessons = [];
  1587.         if(!empty($lessonIds) && is_array($lessonIds)){
  1588.             $lessons $lessonRepository->getCourseLessons(
  1589.                 $course
  1590.                 null
  1591.                 $lessonIds
  1592.                 $searchText
  1593.             );
  1594.         }
  1595.         $aux = [];
  1596.         foreach ($lessons as $key => $lesson) {
  1597.             $lessonModule $lesson->getLessonModule();
  1598.             if(!isset($aux[$lessonModule->getId()])){
  1599.                 $aux[$lessonModule->getId()] = (object)[
  1600.                     "id" => $lessonModule->getId(),
  1601.                     "status" => $lessonModule->getStatus(),
  1602.                     "title" => $lessonModule->getTitle(),
  1603.                     "description" => $lessonModule->getDescription(),
  1604.                     "exam" => null,
  1605.                     "lessons" => [],
  1606.                 ];
  1607.             }
  1608.             $library $lesson->getLibrary();
  1609.             $libraryRepository $this->em->getRepository(Library::class);
  1610.             $timeUtil $this->generalService->getUtil('DateTimeUtil');
  1611.             $duration $library->getDuration();
  1612.             $aux[$lessonModule->getId()]->lessons[] = (object)[
  1613.                 "id" => $lesson->getId(),
  1614.                 "title" => $lesson->getTitle(),
  1615.                 "status" => $lesson->getStatus(),
  1616.                 "lessonIsAccessible" => true,
  1617.                 "acessMessage" => null,
  1618.                 "contentPagesNumber" => null,
  1619.                 "contentDuration" => $duration $timeUtil->timeToSec($duration) : null,
  1620.                 "contentType" => null,
  1621.                 "contentThumb" => $libraryRepository->getCover($library) ?? null,
  1622.                 "exam" => null,
  1623.                 "quiz" => null,
  1624.                 "allowCheck" => EnrollmentEnum::YES,
  1625.             ];
  1626.         }
  1627.         $data = [];
  1628.         foreach ($aux as $key => $value) {
  1629.             $data[] = $value;
  1630.         }
  1631.         return $this->eadResponseNew($data);
  1632.     }
  1633.     /**
  1634.      * @Route(
  1635.      *      path          = "/admin/v2/lesson/{id}/supports",
  1636.      *      methods       = {"GET"}
  1637.      * )
  1638.      */
  1639.     public function getLessonSupportNew(Request $request) {
  1640.         $this->requestUtil->setRequest($request)->setData();
  1641.         $lessonId $request->get('id');
  1642.         $lessonRepository $this->em->getRepository(Lesson::class);
  1643.         $lesson $lessonRepository->findOneBy([
  1644.             "id" => $lessonId,
  1645.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1646.         ]);
  1647.         if(!$lesson){
  1648.             throw new NotFoundException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1649.         }
  1650.         //check user can access lesson
  1651.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1652.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1653.         }
  1654.         $course $lesson->getCourse();
  1655.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1656.         $enrollment $enrollmentRepository->findOneBy([
  1657.             "user" => $this->user->getId(),
  1658.             "course" => $course->getId(),
  1659.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1660.         ], [ "id" => "DESC" ]);
  1661.         if(!$enrollment){
  1662.             throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  1663.         }
  1664.         $orderType = (int)$this->requestUtil->getField('orderType');
  1665.         $searchText $this->requestUtil->getField('searchText');
  1666.         $limit = (int)$this->requestUtil->getField('limit');
  1667.         $offset = (int)$this->requestUtil->getField('offset');
  1668.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1669.         $rows $lessonSupportRepository->getLessonSupportOrderTypeNew(
  1670.             $lesson->getId(), 
  1671.             $orderType,
  1672.             $searchText,
  1673.             $limit,
  1674.             $offset
  1675.         );
  1676.         $total $lessonSupportRepository->countLessonSupportOrderType(
  1677.             $lessonId
  1678.             $orderType
  1679.             $searchText
  1680.         );
  1681.         $permission $this->userPermissionUtil->getPermission(
  1682.             "course""support""delete"
  1683.         );
  1684.         $isLessonTeacher $lessonRepository->isLessonTeacher($lesson$this->user);
  1685.         $data = [
  1686.             "allowDeleteSupport" => (
  1687.                 $isLessonTeacher || $this->userPermissionUtil->isHigh($permission)
  1688.             ),
  1689.             "rowsTotal" => $total,
  1690.             "rowsTotalDisplay" => count($rows),
  1691.             "searchText" => $searchText,
  1692.             "limit" => (!empty($limit) ? $limit 10),
  1693.             "offset" => $offset,
  1694.             "orderType" => $orderType,
  1695.             "rows" => $rows
  1696.         ];
  1697.         $likeControlRepository $this->em->getRepository(LikeControl::class);
  1698.         $typesText = [
  1699.             LessonSupportEnum::LESSON_STUDENT => $this->configuration->getLanguage(
  1700.                 'student''lesson_view_error'
  1701.             ),
  1702.             LessonSupportEnum::COURSE_TEACHER => $this->configuration->getLanguage(
  1703.                 'teacher''lesson_view_error'
  1704.             ),
  1705.             LessonSupportEnum::MODULE_TEACHER => $this->configuration->getLanguage(
  1706.                 'teacher_module''lesson_view_error'
  1707.             ),
  1708.             LessonSupportEnum::LESSON_TEACHER => $this->configuration->getLanguage(
  1709.                 'coordinator''lesson_view_error'
  1710.             ),
  1711.             LessonSupportEnum::LESSON_TUTOR => $this->configuration->getLanguage(
  1712.                 'tutor''lesson_view_error'
  1713.             ),
  1714.         ];
  1715.         foreach ($data['rows'] as $key => $item) {
  1716.             $item = (object)$item;
  1717.             $dataImg = [
  1718.                 "fileName" => $item->photo,
  1719.                 "pathConst" => LessonSupportEnum::PATH_PROFILES,
  1720.                 "option" => "l-user-profile-support",
  1721.                 "addUpload" => true,
  1722.                 "addStream" => true,
  1723.             ];
  1724.             $item->photo $this->fileService->getFilePathObj($dataImg);
  1725.             $item->support html_entity_decode($item->support);
  1726.             $item->answers $lessonSupportRepository->getLessonSupportAnswers($item->id);
  1727.             $item->lessonUserType = (int)$item->lessonUserType;
  1728.             $item->lessonUserTypeText $typesText[$item->lessonUserType];
  1729.             
  1730.             $likeControl $likeControlRepository->findOneByEAD([
  1731.                 "userFrom" => $this->user->getId(),
  1732.                 "element" => $item->id,
  1733.                 "type" => LikeControlEnum::LESSON_SUPPORT,
  1734.             ]);
  1735.             $item->allowLike true;
  1736.             if($likeControl){
  1737.                 $item->allowLike false;
  1738.             }
  1739.             $data['rows'][$key] = $item;
  1740.         }
  1741.         return $this->eadResponseNew($data);
  1742.     }
  1743.     /**
  1744.      * @Route(
  1745.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}/pin",
  1746.      *      methods       = {"PUT"}
  1747.      * )
  1748.      */
  1749.     public function pinLessonSupport(Request $request) {
  1750.         $permission $this->userPermissionUtil->getPermission("course""support""finalize");
  1751.         if($this->userPermissionUtil->isLow($permission)){
  1752.             throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1753.         }
  1754.         
  1755.         $this->requestUtil->setRequest($request)->setData();
  1756.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1757.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1758.         $lessonSupport $lessonSupportRepository->findOneBy([
  1759.             "id" => $lessonSupportId,
  1760.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1761.         ]);
  1762.         
  1763.         if (!$lessonSupport) {
  1764.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1765.         }
  1766.         $lesson $lessonSupport->getLesson();
  1767.         $isLessonTeacher $this->em->getRepository(Lesson::class)->isLessonTeacher(
  1768.             $lesson
  1769.             $this->user
  1770.         );
  1771.         
  1772.         if(!$isLessonTeacher && $this->userPermissionUtil->isMiddle($permission)){
  1773.             throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1774.         }
  1775.         $lessonSupport->setLessonFixed(LessonSupportEnum::YES);
  1776.         $this->em->flush();
  1777.         $data $lessonSupport->toReturn();
  1778.         return $this->eadResponseNew([ "message" => "Success" ]);
  1779.     }
  1780.     /**
  1781.      * @Route(
  1782.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}/unpin",
  1783.      *      methods       = {"DELETE"}
  1784.      * )
  1785.      */
  1786.     public function unpinLessonSupport(Request $request) {
  1787.         $permission $this->userPermissionUtil->getPermission("course""support""finalize");
  1788.         if($this->userPermissionUtil->isLow($permission)){
  1789.             throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1790.         }
  1791.         
  1792.         $this->requestUtil->setRequest($request)->setData();
  1793.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1794.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1795.         $lessonSupport $lessonSupportRepository->findOneBy([
  1796.             "id" => $lessonSupportId,
  1797.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1798.         ]);
  1799.         
  1800.         if (!$lessonSupport) {
  1801.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1802.         }
  1803.         $lesson $lessonSupport->getLesson();
  1804.         $isLessonTeacher $this->em->getRepository(Lesson::class)->isLessonTeacher(
  1805.             $lesson
  1806.             $this->user
  1807.         );
  1808.         
  1809.         if(!$isLessonTeacher && $this->userPermissionUtil->isMiddle($permission)){
  1810.             throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1811.         }
  1812.         $lessonSupport->setLessonFixed(LessonSupportEnum::NO);
  1813.         $this->em->flush();
  1814.         $data $lessonSupport->toReturn();
  1815.         return $this->eadResponseNew([ "message" => "Success" ]);
  1816.     }
  1817.     /**
  1818.      * @Route(
  1819.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}",
  1820.      *      methods       = {"PATCH"}
  1821.      * )
  1822.      */
  1823.     public function likeLessonSupport(Request $request) {
  1824.         $this->requestUtil->setRequest($request)->setData();
  1825.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1826.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1827.         $lessonSupport $lessonSupportRepository->findOneBy([
  1828.             "id" => $lessonSupportId,
  1829.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1830.         ]);
  1831.         
  1832.         if (!$lessonSupport) {
  1833.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1834.         }
  1835.         $lesson $lessonSupport->getLesson();
  1836.         
  1837.         $likeControl = new LikeControl();
  1838.         $type LikeControlEnum::LESSON_SUPPORT;
  1839.         if($lessonSupport->getLessonSupport()){
  1840.             $type LikeControlEnum::LESSON_SUPPORT_ANSWER;
  1841.         }
  1842.         $likeControl->setElement($lessonSupportId);
  1843.         $likeControl->setType($type);
  1844.         $likeControl->setUserTo($lessonSupport->getUser());
  1845.         $likeControl->setUserFrom($this->user);
  1846.         
  1847.         $errors $this->validateEntity($likeControl);
  1848.         if($errors){
  1849.             throw new FieldException("FieldException"$errors);
  1850.         }
  1851.         $lessonSupport->setLikeNumber($lessonSupport->getLikeNumber() + 1);
  1852.         
  1853.         $this->em->persist($likeControl);
  1854.         $this->em->flush();
  1855.         return $this->eadResponseNew([ "message" => "Success" ]);
  1856.     }
  1857.     /**
  1858.      * @Route(
  1859.      *      path          = "/admin/v2/lesson/{id}/supports",
  1860.      *      methods       = {"POST"},
  1861.      * )
  1862.      */
  1863.     public function registerLessonSupport(Request $request) {
  1864.         
  1865.         $this->requestUtil->setRequest($request)->setData();
  1866.         $lessonRepository $this->em->getRepository(Lesson::class);
  1867.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1868.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  1869.         $lessonId $request->get('id');
  1870.         $lesson $lessonRepository->findOneBy([
  1871.             "id" => $lessonId,
  1872.             "deleted" => LessonEnum::ITEM_NO_DELETED
  1873.         ]);
  1874.         if(!$lesson){
  1875.             throw new NotFoundException($this->configuration->getLanguage('error_lesson_not_found''lesson_view_error'));
  1876.         }
  1877.         //check user can access lesson
  1878.         if(!$lessonRepository->isLessonVisibleToStudent($lesson)){
  1879.             throw new ActionInvalidException($this->configuration->getLanguage('error_lesson_unavailable''lesson_view_error'));
  1880.         }
  1881.         $lessonSupport = new LessonSupport();
  1882.         
  1883.         $lessonSupport->setUser($this->user);
  1884.         $lessonSupport->setLesson($lesson);
  1885.         //set LessonSupport in LessonSupport
  1886.         if($this->requestUtil->issetField('lessonSupport')){
  1887.             $lessonSupportId = (int)$this->requestUtil->getField('lessonSupport');
  1888.             $lessonSupportParent $lessonSupportRepository->findOneBy([
  1889.                 "id" => $lessonSupportId,
  1890.                 "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1891.             ]);
  1892.             $lessonSupport->setLessonSupport($lessonSupportParent);
  1893.         }
  1894.         
  1895.         if($this->requestUtil->issetField('support')){
  1896.             $lessonSupport->setSupport($this->requestUtil->getField('support'));
  1897.         }
  1898.         $errors $this->validateEntity($lessonSupport);
  1899.         if($errors){
  1900.             throw new FieldException("FieldException"$errors);
  1901.         }
  1902.         
  1903.         $lessonSupportParent $lessonSupport->getLessonSupport();
  1904.         $lesson $lessonSupport->getLesson();
  1905.         $course $lesson->getCourse();
  1906.         
  1907.         $isLessonTeacher $lessonRepository->isLessonTeacher(
  1908.             $lesson
  1909.             $this->user
  1910.         );
  1911.         $isEnrolled $enrollmentRepository->isValidEnrollmentByUser(
  1912.             $this->user->getId(), 
  1913.             $course->getId()
  1914.         );
  1915.         $permission $this->userPermissionUtil->getPermission("course""support""answer");
  1916.         if($lessonSupportParent){
  1917.             if(!$isEnrolled){
  1918.                 if($this->userPermissionUtil->isLow($permission)){
  1919.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1920.                 }
  1921.                 if(!$isLessonTeacher && $this->userPermissionUtil->isMiddle($permission)){
  1922.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  1923.                 }
  1924.             }
  1925.         }else{
  1926.             if($course->getSupport() == LessonSupportEnum::NO){
  1927.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_support''lesson_view_error'));
  1928.             }
  1929.             if(!$isEnrolled && !$isLessonTeacher){
  1930.                 throw new ActionInvalidException($this->configuration->getLanguage('error_unavailable''lesson_view_error'));
  1931.             }
  1932.         }
  1933.         $this->em->persist($lessonSupport);
  1934.         $this->em->flush();
  1935.         $lessonSupportRepository->processNewLessonSupport($lessonSupport);
  1936.          
  1937.         return $this->eadResponseNew([ "message" => "Success" ]);
  1938.     }
  1939.     /**
  1940.      * @Route(
  1941.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}",
  1942.      *      methods       = {"PUT"}
  1943.      * )
  1944.      */
  1945.     public function editLessonSupport(Request $request) {
  1946.         $this->requestUtil->setRequest($request)->setData();
  1947.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1948.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1949.         $lessonSupport $lessonSupportRepository->findOneBy([
  1950.             "id" => $lessonSupportId,
  1951.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1952.         ]);
  1953.         
  1954.         if (!$lessonSupport) {
  1955.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1956.         }
  1957.         $lesson $lessonSupport->getLesson();
  1958.         
  1959.         if($this->requestUtil->issetField('support')){
  1960.             $lessonSupport->setSupport($this->requestUtil->getField('support'));
  1961.         }
  1962.         $lessonSupport->setDateUpdate(date('Y-m-d H:i:s'));
  1963.         
  1964.         $errors $this->validateEntity($lessonSupport);
  1965.         if($errors){
  1966.             throw new FieldException("FieldException"$errors);
  1967.         }
  1968.         $this->em->flush();
  1969.         return $this->eadResponseNew([ "message" => "Success" ]);
  1970.     }
  1971.     /**
  1972.      * @Route(
  1973.      *      path          = "/admin/v2/lesson/{id}/supports/{lessonSupportId}",
  1974.      *      methods       = {"DELETE"}
  1975.      * )
  1976.      */
  1977.     public function deleteLessonSupport(Request $request) {
  1978.         $this->requestUtil->setRequest($request)->setData();
  1979.         $lessonSupportId = (int)$request->get('lessonSupportId');
  1980.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1981.         $lessonSupport $lessonSupportRepository->findOneBy([
  1982.             "id" => $lessonSupportId,
  1983.             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1984.         ]);
  1985.         
  1986.         if (!$lessonSupport) {
  1987.             throw new NotFoundException($this->configuration->getLanguage('error_support_not_found''lesson_view_error'));
  1988.         }
  1989.         
  1990.         $lessonSupportRepository->delete(
  1991.             $lessonSupport
  1992.             TrashEnum::LESSON_SUPPORT
  1993.             $this->userPermissionUtil->getPermission("course""support""delete"), 
  1994.             TrashEnum::NO
  1995.         );
  1996.         $this->em->flush();
  1997.         return $this->eadResponseNew([ "message" => "Success" ]);
  1998.     }
  1999.     /**
  2000.      * @Route(
  2001.      *      path          = "/admin/v2/course/{id}/testimonial",
  2002.      *      methods       = {"POST"},
  2003.      * )
  2004.      */
  2005.     public function registerCourseTestimonial(Request $request) {
  2006.         $this->requestUtil->setRequest($request)->setData();
  2007.         $courseId $request->get('id');
  2008.         $course $this->repository->findOneBy([
  2009.             "id" => $courseId,
  2010.             "deleted" => CourseEnum::ITEM_NO_DELETED
  2011.         ]);
  2012.         
  2013.         if(!$course){
  2014.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  2015.         }
  2016.         $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  2017.             $course
  2018.             $this->user
  2019.         );
  2020.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  2021.         $enrollment $enrollmentRepository->findOneBy([
  2022.             "user" => $this->user->getId(),
  2023.             "course" => $courseId,
  2024.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED,
  2025.         ], [ "id" => "DESC" ]);
  2026.         $permission $this->userPermissionUtil->getPermission("course""see");
  2027.         
  2028.         if(!$enrollment){
  2029.             if($course->getFree() == CourseEnum::NO){
  2030.                 if($this->userPermissionUtil->isLow($permission)){
  2031.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  2032.                 }
  2033.                 if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
  2034.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  2035.                 }
  2036.             }
  2037.             $enrollmentService $this->generalService->getService('EnrollmentService');
  2038.             $info $enrollmentService->enrollUser($this->user$course);
  2039.             
  2040.             if(!$info->errors){
  2041.                 $enrollment $info->enrollment;
  2042.             }
  2043.         }
  2044.         if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
  2045.             if(!$enrollment){
  2046.                 throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  2047.             }
  2048.             if($course->getStatus() == CourseEnum::DRAFT){
  2049.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  2050.             }
  2051.         }
  2052.         $courseTestimonial = new CourseTestimonial();
  2053.         $courseTestimonial->setDate(date('Y-m-d H:i:s'));
  2054.         $courseTestimonial->setStatus(CourseTestimonialEnum::WAITING);
  2055.         if($this->requestUtil->issetField('score')){
  2056.             $courseTestimonial->setScore((int)$this->requestUtil->getField("score"));
  2057.         }
  2058.         if($this->requestUtil->issetField('testimonial')){
  2059.             $courseTestimonial->setTestimonial($this->requestUtil->getField('testimonial'));
  2060.         }
  2061.         $courseTestimonial->setUser($this->user);
  2062.         $courseTestimonial->setCourse($course);
  2063.         $errors $this->validateEntity($courseTestimonial);
  2064.         if($errors){
  2065.             throw new FieldException("FieldException"$errors);
  2066.         }
  2067.         $this->em->persist($courseTestimonial);
  2068.         $this->em->flush();
  2069.         $userWebhook $this->em->getRepository(User::class)->getToWebhook(
  2070.             $courseTestimonial->getUser()
  2071.         );
  2072.       
  2073.         $dataObj= (object)[
  2074.             "user" => $userWebhook,
  2075.             "course"=> (object)[        
  2076.                 "id" => (string)$courseTestimonial->getCourse()->getId(),
  2077.                 "name" => $courseTestimonial->getCourse()->getTitle(),
  2078.             ],
  2079.             "testimonial"=> (object)[
  2080.                 "stars" => $courseTestimonial->getScore(),
  2081.                 "comment" => $courseTestimonial->getTestimonial(),
  2082.                 "dates" => (object)[
  2083.                     "created" => $courseTestimonial->getDate(),
  2084.                 ],
  2085.             ],
  2086.             "enrollment"=> $enrollment->toWebhook(),
  2087.         ];
  2088.         $webhookService $this->generalService->getService('WebhookService');
  2089.         $webhookService->addItemList(WebhookEnum::TESTIMONIAL$dataObj);
  2090.         $notificationService $this->generalService->getService(
  2091.             'NotificationService'
  2092.         );
  2093.         
  2094.         
  2095.         if($this->user != $course->getUser()){
  2096.             $notificationService->create(
  2097.                 $this->user
  2098.                 $course->getUser(),
  2099.                 NotificationEnum::ORIGIN_COURSE_TESTIMONIAL_NEW,
  2100.                 $courseTestimonial->getId()
  2101.             );
  2102.         }
  2103.         $userCourse $course->getUser();
  2104.         if($userCourse->getAllowNotifyNewSupportMessage() == CourseTestimonialEnum::YES){
  2105.             $emailService $this->generalService->getService('EmailService');
  2106.             if($emailService->checkUserToSend($userCourse)){
  2107.                 $emailService->setToEmail($userCourse->getEmail());
  2108.                 $emailService->setToName($userCourse->getName());
  2109.     
  2110.                 $subText $this->configuration->getLanguage(
  2111.                     'new_course_testimonial.subject''email'
  2112.                 );
  2113.                 
  2114.                 $id $courseTestimonial->getId();
  2115.                 $subject "{$subText} - {$course->getTitle()}";
  2116.                 $emailService->setSubject($subject);
  2117.     
  2118.                 $emailService->setData([
  2119.                     "userName" => $userCourse->getName(),
  2120.                     "btnLink" => "{$this->adminLink}courses/testimonials/{$id}",
  2121.                 ]);
  2122.     
  2123.                 $emailService->setTemplateBody("new_course_testimonial");
  2124.                 $emailService->send();
  2125.             }
  2126.         }
  2127.         $data $courseTestimonial->toReturn();
  2128.         $this->userLogService->logInsert(
  2129.             "course_testimonial"
  2130.             $courseTestimonial->getId(), 
  2131.             $data
  2132.         );
  2133.         $testimonial = (object)[
  2134.             "id" => $courseTestimonial->getId(),
  2135.             "score" => $courseTestimonial->getScore(),
  2136.             "testimonial" => $courseTestimonial->getTestimonial(),
  2137.         ];
  2138.         return $this->eadResponseNew($testimonial);
  2139.     }
  2140.     /**
  2141.      * @Route(
  2142.      *      path          = "/admin/v2/course/{courseId}/testimonial/{id}",
  2143.      *      methods       = {"PUT"}
  2144.      * )
  2145.      */
  2146.     public function editCourseTestimonial(Request $request) {
  2147.         $courseId $request->get('courseId');
  2148.         $course $this->repository->findOneBy([
  2149.             "id" => $courseId,
  2150.             "deleted" => CourseEnum::ITEM_NO_DELETED
  2151.         ]);
  2152.         
  2153.         if(!$course){
  2154.             throw new NotFoundException($this->configuration->getLanguage('error_course_not_found''lesson_view_error'));
  2155.         }
  2156.         $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  2157.             $course
  2158.             $this->user
  2159.         );
  2160.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  2161.         $enrollment $enrollmentRepository->findOneBy([
  2162.             "user" => $this->user->getId(),
  2163.             "course" => $courseId,
  2164.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED,
  2165.         ], [ "id" => "DESC" ]);
  2166.         $permission $this->userPermissionUtil->getPermission("course""see");
  2167.         
  2168.         if(!$enrollment){
  2169.             if($course->getFree() == CourseEnum::NO){
  2170.                 if($this->userPermissionUtil->isLow($permission)){
  2171.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  2172.                 }
  2173.                 if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
  2174.                     throw new PermissionException($this->configuration->getLanguage('error_user_not_permission''lesson_view_error'));
  2175.                 }
  2176.             }
  2177.             $enrollmentService $this->generalService->getService('EnrollmentService');
  2178.             $info $enrollmentService->enrollUser($this->user$course);
  2179.             
  2180.             if(!$info->errors){
  2181.                 $enrollment $info->enrollment;
  2182.             }
  2183.         }
  2184.         if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
  2185.             if(!$enrollment){
  2186.                 throw new ActionInvalidException($this->configuration->getLanguage('error_enrollment_not_found''lesson_view_error'));
  2187.             }
  2188.             if($course->getStatus() == CourseEnum::DRAFT){
  2189.                 throw new ActionInvalidException($this->configuration->getLanguage('error_course_not_published''lesson_view_error'));
  2190.             }
  2191.         }
  2192.         $testimonialId $request->get('id');
  2193.         $courseTestimonialRepository $this->em->getRepository(CourseTestimonial::class);
  2194.         $courseTestimonial $courseTestimonialRepository->findOneBy([
  2195.             "id" => $testimonialId,
  2196.             "deleted" => CourseTestimonialEnum::ITEM_NO_DELETED
  2197.         ]);
  2198.         if (!$courseTestimonial || empty($testimonialId)) {
  2199.             throw new NotFoundException($this->configuration->getLanguage('error_testimonial_not_found''lesson_view_error'));
  2200.         }
  2201.         $this->requestUtil->setRequest($request)->setData();
  2202.         if($this->requestUtil->issetField('score')){
  2203.             $courseTestimonial->setScore((int)$this->requestUtil->getField("score"));
  2204.         }
  2205.         if($this->requestUtil->issetField('testimonial')){
  2206.             $courseTestimonial->setTestimonial($this->requestUtil->getField('testimonial'));
  2207.         }
  2208.         
  2209.         $courseTestimonial->setDate(date('Y-m-d H:i:s'));
  2210.         $courseTestimonial->setStatus(CourseTestimonialEnum::WAITING);
  2211.         $errors $this->validateEntity($courseTestimonial);
  2212.         
  2213.         if($errors){
  2214.             throw new FieldException("FieldException"$errors);
  2215.         }
  2216.         $this->em->flush();
  2217.         $notificationService $this->generalService->getService('NotificationService');
  2218.         $emailService $this->generalService->getService('EmailService');
  2219.         if($this->user != $course->getUser()){
  2220.             $notificationService->create(
  2221.                 $this->user
  2222.                 $course->getUser(),
  2223.                 NotificationEnum::ORIGIN_COURSE_TESTIMONIAL_CHANGE,
  2224.                 $courseTestimonial->getId()
  2225.             );
  2226.         }
  2227.         $user $course->getUser();
  2228.         if($user->getAllowNotifyNewSupportMessage() == CourseTestimonialEnum::YES){
  2229.             if($emailService->checkUserToSend($user)){
  2230.                 $emailService->setToEmail($user->getEmail());
  2231.                 $emailService->setToName($user->getName());
  2232.                 $subText $this->configuration->getLanguage(
  2233.                     'new_course_testimonial.subject''email'
  2234.                 );
  2235.                 $subject "{$subText} - {$course->getTitle()}";
  2236.                 $emailService->setSubject($subject);
  2237.                 
  2238.                 $emailService->setData([
  2239.                     "userName" => $course->getUser()->getName(),
  2240.                     "btnLink" => "{$this->adminLink}courses/testimonials/{$testimonialId}",
  2241.                 ]);
  2242.                 $emailService->setTemplateBody("new_course_testimonial");
  2243.                 $emailService->send();
  2244.             }
  2245.         }
  2246.         $data $courseTestimonial->toReturn();
  2247.         $this->userLogService->logUpdate(
  2248.             "course_testimonial"
  2249.             $courseTestimonial->getId(),
  2250.             $data
  2251.         );
  2252.         $testimonial = (object)[
  2253.             "id" => $courseTestimonial->getId(),
  2254.             "score" => $courseTestimonial->getScore(),
  2255.             "testimonial" => $courseTestimonial->getTestimonial(),
  2256.         ];
  2257.         return $this->eadResponseNew($testimonial);
  2258.     }
  2259. }