src/Repository/EnrollmentRepository.php line 1353

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Repository;
  3. use EADPlataforma\Entity\Enrollment;
  4. use EADPlataforma\Entity\Course;
  5. use EADPlataforma\Entity\Library;
  6. use EADPlataforma\Entity\Lesson;
  7. use EADPlataforma\Entity\LessonLog;
  8. use EADPlataforma\Entity\LessonLogOrigin;
  9. use EADPlataforma\Entity\LessonModule;
  10. use EADPlataforma\Entity\LessonSupport;
  11. use EADPlataforma\Entity\LessonAnnotation;
  12. use EADPlataforma\Entity\Exam;
  13. use EADPlataforma\Entity\ExamUser;
  14. use EADPlataforma\Entity\CourseTeam;
  15. use EADPlataforma\Entity\CourseTestimonial;
  16. use EADPlataforma\Entity\CourseCertificate;
  17. use EADPlataforma\Entity\UserSubscription;
  18. use EADPlataforma\Entity\Product;
  19. use EADPlataforma\Entity\ProductOffer;
  20. use EADPlataforma\Entity\User;
  21. use EADPlataforma\Entity\Trash;
  22. use EADPlataforma\Enum\ExamEnum;
  23. use EADPlataforma\Enum\CourseEnum;
  24. use EADPlataforma\Enum\CourseTestimonialEnum;
  25. use EADPlataforma\Enum\CourseCertificateEnum;
  26. use EADPlataforma\Enum\ExamUserEnum;
  27. use EADPlataforma\Enum\GroupEnum;
  28. use EADPlataforma\Enum\LessonEnum;
  29. use EADPlataforma\Enum\EnrollmentEnum;
  30. use EADPlataforma\Enum\UserSubscriptionEnum;
  31. use EADPlataforma\Enum\LessonAnnotationEnum;
  32. use EADPlataforma\Enum\LessonSupportEnum;
  33. use EADPlataforma\Enum\ProductEnum;
  34. use EADPlataforma\Enum\NotificationEnum;
  35. use EADPlataforma\Enum\UserEnum;
  36. use EADPlataforma\Enum\TagsMarketingEnum;
  37. use EADPlataforma\Enum\WebhookEnum;
  38. /**
  39.  * @method Enrollment|null find($id, $lockMode = null, $lockVersion = null)
  40.  * @method Enrollment|null findOneBy(array $criteria, array $orderBy = null)
  41.  * @method Enrollment[]    findAll()
  42.  * @method Enrollment[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  43.  */
  44. class EnrollmentRepository extends AbstractRepository
  45. {
  46.     public function getEntityClass(){
  47.         return Enrollment::class;
  48.     }
  49.     public function getConnectionName(){
  50.         return "school";
  51.     }
  52.     public function findItems()
  53.     {
  54.         return $this->createQueryBuilder('e')->getQuery()->getResult();
  55.     }
  56.     public function getStringStatus($status){
  57.         $string '';
  58.         switch ($status) {
  59.             case EnrollmentEnum::STATUS_ACTIVE:
  60.                 $string $this->configuration->getLanguage('active''enrollments');
  61.                 break;
  62.             case EnrollmentEnum::STATUS_EXPIRED:
  63.                 $string $this->configuration->getLanguage('expired''enrollments');    
  64.                 break;
  65.             case EnrollmentEnum::STATUS_SUSPENDED:
  66.                 $string $this->configuration->getLanguage('suspended''enrollments'); 
  67.                 break;
  68.             case EnrollmentEnum::STATUS_CANCELED:
  69.                 $string $this->configuration->getLanguage('canceled''enrollments'); 
  70.                 break;
  71.         }
  72.         return $string;
  73.     }
  74.     public function getOriginString($origin){
  75.         $string '';
  76.         switch ($origin) {
  77.             case EnrollmentEnum::ORIGIN_FREE:
  78.                 $string $this->configuration->getLanguage('free''enrollments');
  79.             break;
  80.             case EnrollmentEnum::ORIGIN_SALE:
  81.                 $string $this->configuration->getLanguage('sale''enrollments');    
  82.             break;
  83.             case EnrollmentEnum::ORIGIN_SUBSCRIPTION:
  84.                 $string $this->configuration->getLanguage('subscription''enrollments'); 
  85.             break;
  86.             case EnrollmentEnum::ORIGIN_GROUP:
  87.                 $string $this->configuration->getLanguage('group''enrollments'); 
  88.             break;
  89.             case EnrollmentEnum::ORIGIN_COUPOM:
  90.                 $string $this->configuration->getLanguage('coupom''enrollments'); 
  91.             break;
  92.             case EnrollmentEnum::ORIGIN_API:
  93.                 $string 'API'
  94.             break;
  95.             case EnrollmentEnum::ORIGIN_CHARGE:
  96.                 $string $this->configuration->getLanguage('charge''enrollments'); 
  97.             break;
  98.         }
  99.         return $string;
  100.     }
  101.     public function getEnrollmentOrigins(){
  102.         $data = [
  103.             (object)[
  104.                 "id" => EnrollmentEnum::ORIGIN_FREE,
  105.                 "title" => $this->configuration->getLanguage('free''enrollments'),
  106.                 "selected" => EnrollmentEnum::NO,
  107.             ],
  108.             (object)[
  109.                 "id" => EnrollmentEnum::ORIGIN_SALE,
  110.                 "title" => $this->configuration->getLanguage('sale''enrollments'),
  111.                 "selected" => EnrollmentEnum::NO,
  112.             ],
  113.             (object)[
  114.                 "id" => EnrollmentEnum::ORIGIN_SUBSCRIPTION,
  115.                 "title" => $this->configuration->getLanguage('subscription''enrollments'),
  116.                 "selected" => EnrollmentEnum::NO,
  117.             ],
  118.             (object)[
  119.                 "id" => EnrollmentEnum::ORIGIN_GROUP,
  120.                 "title" => $this->configuration->getLanguage('group''enrollments'),
  121.                 "selected" => EnrollmentEnum::NO,
  122.             ],
  123.             (object)[
  124.                 "id" => EnrollmentEnum::ORIGIN_COUPOM,
  125.                 "title" => $this->configuration->getLanguage('coupom''enrollments'),
  126.                 "selected" => EnrollmentEnum::NO,
  127.             ],
  128.             (object)[
  129.                 "id" => EnrollmentEnum::ORIGIN_API,
  130.                 "title" => "API",
  131.                 "selected" => EnrollmentEnum::NO,
  132.             ],
  133.             (object)[
  134.                 "id" => EnrollmentEnum::ORIGIN_CHARGE,
  135.                 "title" => $this->configuration->getLanguage('charge''enrollments'),
  136.                 "selected" => EnrollmentEnum::NO,
  137.             ],
  138.         ];
  139.         return $data;
  140.     }
  141.     public function sendWebhook(Enrollment $enrollment)
  142.     {
  143.         $user $enrollment->getUser();
  144.         $course $enrollment->getCourse();
  145.         $userWebhook $this->em->getRepository(User::class)->getToWebhook($user);
  146.         $dataObj = (object)[
  147.             "user" => $userWebhook,
  148.             "course" => (object)[
  149.                 "id" => (string)$course->getId(),
  150.                 "name" => $course->getTitle(),
  151.                 "workload" => $course->getWorkload(),
  152.             ],
  153.             "enrollment" => $enrollment->toWebhook(),
  154.         ];
  155.         if ($enrollment->getGroup()) {
  156.             $dataObj->group = (object)[
  157.                 "id" => (string)$enrollment->getGroup()->getId(),
  158.                 "name" => $enrollment->getGroup()->getName(),
  159.             ];
  160.         };
  161.         $webhookService $this->generalService->getService('WebhookService');
  162.         $webhookService->addItemList(WebhookEnum::ENROLLMENT$dataObj);
  163.         return;
  164.     }
  165.     public function getPublicEnrollments(
  166.         $userId
  167.         bool $onlyStarted false
  168.         $notCompleted false
  169.     )
  170.     {
  171.         $query $this->createQueryBuilder('e');
  172.         $query->innerJoin(
  173.             'EADPlataforma:Course''c''WITH''e.course = c AND c.deleted = 0'
  174.         );
  175.         $query->andWhere('e.user = :userId');
  176.         $query->andWhere('e.deleted = 0');
  177.         $query->setParameter('userId'$userId);
  178.         if($onlyStarted){
  179.             $query->andWhere('e.lessonNumberComplete != 0');
  180.         }
  181.         $query->addOrderBy('e.id''DESC');
  182.         $data $query->getQuery()->execute();
  183.         if($notCompleted){
  184.             $dataNotCompleted = [];
  185.             foreach ($data as $key => $enrollment) {
  186.                 if($enrollment->getProgress() < 100){
  187.                     $dataNotCompleted[] = $enrollment;
  188.                 }
  189.             }
  190.             $data $dataNotCompleted;
  191.         }
  192.         return $data;
  193.     }
  194.     
  195.     public function getResumeEnrollment(
  196.         int $userId
  197.         ?array $situation = [], 
  198.         ?int $status null,
  199.         ?string $searchText null
  200.         ?string $categories null
  201.         ?int $offset 0
  202.         ?int $limit 10
  203.     )
  204.     {
  205.         $query $this->createQueryBuilder('e');
  206.         $query->innerJoin(
  207.             'EADPlataforma:Course'
  208.             'c'
  209.             'WITH'
  210.             'e.course = c 
  211.             AND c.deleted = :courseDeleted 
  212.             AND c.status = :courseStatus
  213.             AND c.dateRelease <= :now'
  214.         );
  215.         $query->andWhere('e.user = :userId');
  216.         $query->andWhere('e.deleted = 0');
  217.         
  218.         $situationWhere = [];
  219.         if(in_array(EnrollmentEnum::SITUATION_STARTED$situation)){
  220.             $situationWhere[] = '
  221.                 (
  222.                     (e.lessonNumberComplete * 100)/c.numberLesson < 100
  223.                     AND (e.lessonNumberComplete * 100)/c.numberLesson > 0
  224.                 )';
  225.         }
  226.         if(in_array(EnrollmentEnum::SITUATION_NOT_STARTED$situation)){
  227.             $situationWhere[] = '(
  228.                 c.numberLesson = 0 
  229.                 OR (e.lessonNumberComplete * 100)/c.numberLesson <= 0
  230.             )';
  231.         }
  232.         if(in_array(EnrollmentEnum::SITUATION_COMPLETED$situation)){
  233.             $situationWhere[] = '((e.lessonNumberComplete * 100)/c.numberLesson >= 100)';
  234.         }
  235.         $situationWhereString "";
  236.         foreach ($situationWhere as $key => $value) {
  237.             $situationWhereString .= (empty($situationWhereString) ? $value " OR {$value} " );
  238.         }
  239.         if(!empty($situationWhereString)){
  240.             $query->andWhere("({$situationWhereString})");
  241.         }
  242.         
  243.         if(!empty($searchText)){
  244.             $query->andWhere('c.title LIKE :searchText');
  245.             $query->setParameter('searchText''%'.$searchText.'%');
  246.         }
  247.         if(!empty($categories)){
  248.             $query->andWhere('c.category IN (:categories) ');
  249.             $query->setParameter('categories'$categories);
  250.         }
  251.         if(!empty($status)){
  252.             $query->andWhere('e.status = :status');
  253.             $query->andWhere('e.datePeriod >= :now');
  254.     
  255.             $query->setParameter('status'$status);
  256.             $query->setParameter('now'date("Y-m-d H:i:s"));
  257.         }else{
  258.             $query->andWhere('e.status = :status');
  259.             $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  260.             $courseRepository $this->em->getRepository(Course::class);
  261.             
  262.             $subQuery $courseRepository->createQueryBuilder('c1');
  263.             $subQuery->select('c1.id');
  264.             $subQuery->innerJoin(
  265.                 'EADPlataforma:Product'
  266.                 'p'
  267.                 'WITH'
  268.                 'c1 MEMBER OF p.course'
  269.             );
  270.             $subQuery->andWhere('p.deleted = :productDeleted ');
  271.             $subQuery->andWhere('p.status = :productStatus');
  272.             $subQuery->andWhere('(
  273.                 p.type = :productTypePeriod OR p.type = :productTypePeriodSupport
  274.             )');
  275.             $subQuery->andWhere('c1.deleted = :c1Deleted');
  276.             $subQuery->andWhere('c1.status = :c1Status');
  277.             $query->setParameter('c1Deleted'CourseEnum::ITEM_NO_DELETED);
  278.             $query->setParameter('c1Status'CourseEnum::PUBLISHED);
  279.             $query->setParameter('productDeleted'ProductEnum::ITEM_NO_DELETED);
  280.             $query->setParameter('productStatus'ProductEnum::PUBLISHED);
  281.             $query->setParameter('productTypePeriod'ProductEnum::PERIOD);
  282.             $query->setParameter('productTypePeriodSupport'ProductEnum::PERIOD_SUPORT);
  283.             $subQuery $subQuery->getDQL();
  284.             $exp $query->expr()->in('e.course'$subQuery);
  285.             $query->andWhere("(e.datePeriod >= :now OR {$exp})");
  286.             $query->setParameter('now'date("Y-m-d H:i:s"));
  287.         }
  288.         $query->setParameter('userId'$userId);
  289.         $query->setParameter('courseStatus'CourseEnum::PUBLISHED);
  290.         $query->setParameter('courseDeleted'CourseEnum::ITEM_NO_DELETED);
  291.         $query->setFirstResult($offset);
  292.         if($limit != 0){
  293.             $query->setMaxResults($limit);
  294.         }
  295.         $query->addOrderBy('e.dateLastAccess''DESC');
  296.         
  297.         $data $query->getQuery()->execute();
  298.         return $data;
  299.     }
  300.     
  301.     public function countResumeEnrollment(
  302.         int $userId
  303.         ?array $situation = [], 
  304.         ?int $status null
  305.         ?string $searchText null
  306.         ?string $categories null
  307.     )
  308.     {
  309.         $query $this->createQueryBuilder('e');
  310.         $query->select("count(e.id) AS total");
  311.         $query->innerJoin(
  312.             'EADPlataforma:Course'
  313.             'c'
  314.             'WITH'
  315.             'e.course = c 
  316.             AND c.deleted = 0 
  317.             AND c.status = :courseStatus
  318.             AND c.dateRelease <= :now'
  319.         );
  320.         $query->andWhere('e.user = :userId');
  321.         $query->andWhere('e.deleted = 0');
  322.         
  323.         $situationWhere = [];
  324.         if(in_array(EnrollmentEnum::SITUATION_STARTED$situation)){
  325.             $situationWhere[] = '
  326.                 (
  327.                     (e.lessonNumberComplete * 100)/c.numberLesson < 100
  328.                     AND (e.lessonNumberComplete * 100)/c.numberLesson > 0
  329.                 )';
  330.         }
  331.         if(in_array(EnrollmentEnum::SITUATION_NOT_STARTED$situation)){
  332.             $situationWhere[] = '((e.lessonNumberComplete * 100)/c.numberLesson <= 0)';
  333.         }
  334.         if(in_array(EnrollmentEnum::SITUATION_COMPLETED$situation)){
  335.             $situationWhere[] = '((e.lessonNumberComplete * 100)/c.numberLesson >= 100)';
  336.         }
  337.         $situationWhereString "";
  338.         foreach ($situationWhere as $key => $value) {
  339.             $situationWhereString .= (empty($situationWhereString) ? $value " OR {$value} " );
  340.         }
  341.         if(!empty($situationWhereString)){
  342.             $query->andWhere("({$situationWhereString})");
  343.         }
  344.         if(!empty($searchText)){
  345.             $query->andWhere('c.title LIKE :searchText');
  346.             $query->setParameter('searchText''%'.$searchText.'%');
  347.         }
  348.         if(!empty($categories)){
  349.             $query->andWhere('c.category IN (:categories) ');
  350.             $query->setParameter('categories'$categories);
  351.         }
  352.         if(!empty($status)){
  353.             $query->andWhere('e.status = :status');
  354.             $query->andWhere('e.datePeriod >= :now');
  355.     
  356.             $query->setParameter('status'$status);
  357.             $query->setParameter('now'date("Y-m-d H:i:s"));
  358.         }else{
  359.             $query->andWhere('e.status = :status');
  360.             $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  361.             $courseRepository $this->em->getRepository(Course::class);
  362.             
  363.             $subQuery $courseRepository->createQueryBuilder('c1');
  364.             $subQuery->select('c1.id');
  365.             $subQuery->innerJoin(
  366.                 'EADPlataforma:Product'
  367.                 'p'
  368.                 'WITH'
  369.                 'c1 MEMBER OF p.course'
  370.             );
  371.             $subQuery->andWhere('p.deleted = :productDeleted ');
  372.             $subQuery->andWhere('p.status = :productStatus');
  373.             $subQuery->andWhere('(
  374.                 p.type = :productTypePeriod OR p.type = :productTypePeriodSupport
  375.             )');
  376.             $subQuery->andWhere('c1.deleted = :c1Deleted');
  377.             $subQuery->andWhere('c1.status = :c1Status');
  378.             $query->setParameter('c1Deleted'CourseEnum::ITEM_NO_DELETED);
  379.             $query->setParameter('c1Status'CourseEnum::PUBLISHED);
  380.             $query->setParameter('productDeleted'ProductEnum::ITEM_NO_DELETED);
  381.             $query->setParameter('productStatus'ProductEnum::PUBLISHED);
  382.             $query->setParameter('productTypePeriod'ProductEnum::PERIOD);
  383.             $query->setParameter('productTypePeriodSupport'ProductEnum::PERIOD_SUPORT);
  384.             $subQuery $subQuery->getDQL();
  385.             $exp $query->expr()->in('e.course'$subQuery);
  386.             $query->andWhere("(e.datePeriod >= :now OR {$exp})");
  387.             $query->setParameter('now'date("Y-m-d H:i:s"));
  388.         }
  389.         $query->setParameter('userId'$userId);
  390.         $query->setParameter('courseStatus'CourseEnum::PUBLISHED);
  391.         $query->addOrderBy('e.dateLastAccess''DESC');
  392.         $result = (object)$query->getQuery()->getOneOrNullResult();
  393.         return $result->total;
  394.     }
  395.     public function countUserEnrollment(int $userId, ?bool $all false)
  396.     {
  397.         $query $this->createQueryBuilder('e');
  398.         $query->select("count(e.id) AS total");
  399.         $query->innerJoin(
  400.             'EADPlataforma:Course'
  401.             'c'
  402.             'WITH',
  403.             'e.course = c 
  404.             AND c.deleted = 0 
  405.             AND c.status = :courseStatus'
  406.         );
  407.         $query->andWhere('e.user = :userId');
  408.         $query->andWhere('e.deleted = 0');
  409.         if($all){
  410.             $query->andWhere('e.status = :status');
  411.             $query->andWhere('e.datePeriod >= :now');
  412.             $query->andWhere('c.dateRelease <= :now');
  413.         
  414.             $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  415.             $query->setParameter('now'date("Y-m-d H:i:s"));
  416.         }   
  417.         $query->setParameter('userId'$userId);
  418.         $query->setParameter('courseStatus'CourseEnum::PUBLISHED);
  419.         $result = (object)$query->getQuery()->getOneOrNullResult();
  420.         return $result->total;
  421.     }
  422.     public function getEnrollmentNumber(
  423.         ?string $dateStart null
  424.         ?string $dateEnd null
  425.         ?int $userId null
  426.         ?int $status null
  427.     )
  428.     {
  429.         $query $this->createQueryBuilder('e');
  430.         $query->select("COUNT(0) AS total");
  431.         $query->andWhere('e.deleted = :deleted');
  432.         if($userId 0){
  433.             $subQuery $this->createQueryBuilder('course_team');
  434.             $subQuery->select('IDENTITY(ct.course)');
  435.             $subQuery->from('EADPlataforma:CourseTeam''ct');
  436.             $subQuery->andWhere('ct.user = :userId');
  437.             $subQuery $subQuery->getDQL();
  438.             $query->andWhere($query->expr()->in('e.course'$subQuery));
  439.             $query->setParameter('userId'$userId);
  440.         }
  441.         if(!is_null($dateStart) && !is_null($dateEnd)){
  442.             $query->andWhere('DATE(e.dateRegister) BETWEEN :dateStart AND :dateEnd');
  443.             $query->setParameter('dateStart'$dateStart);
  444.             $query->setParameter('dateEnd'$dateEnd);
  445.         }
  446.         if(!empty($status)){
  447.             $query->andWhere('e.status = :status');
  448.             $query->setParameter('status'$status);
  449.         }
  450.         $query->setParameter('deleted'EnrollmentEnum::ITEM_NO_DELETED);
  451.         $query->setMaxResults(1);
  452.         $result = (object)$query->getQuery()->getOneOrNullResult();
  453.         return $result->total;
  454.     }
  455.     public function checkFinishCourseByEnrollment(Enrollment $enrollment)
  456.     {
  457.         if($enrollment->getProgress() < 100 || !empty($enrollment->getDateConclusion())){
  458.             return;
  459.         }
  460.         $user $enrollment->getUser();
  461.         $course $enrollment->getCourse();
  462.         if($course->getStatus() == CourseEnum::DRAFT){
  463.             return;
  464.         }
  465.         $marketingService $this->generalService->getService(
  466.             'Marketing\\MarketingService'
  467.         );
  468.         if(
  469.             $this->configuration->isModuleActive("exam_module") && 
  470.             $this->configuration->checkModuleIsAbleOnPlan("examFunction")
  471.         ){
  472.             $examRepository $this->em->getRepository(Exam::class);
  473.             $examUserRepository $this->em->getRepository(ExamUser::class);
  474.             $numberExamConfig $examRepository->countValidExamByCourse($course->getId());
  475.             $numberExamUserConfig $examUserRepository->countValidExamUserByCourse(
  476.                 $course->getId(),
  477.                 $user->getId()
  478.             );
  479.             if(empty($numberExamConfig)){
  480.                 $enrollment->setDateConclusion(date('Y-m-d H:i:s'));
  481.                 $marketingService->setTag(TagsMarketingEnum::TAG_FINISH_COURSE);
  482.                 $marketingService->setTextComplement($course->getTitle());
  483.                 $marketingService->setUser($this->getUser());
  484.                 $marketingService->send();
  485.             }else if($numberExamConfig == $numberExamUserConfig){
  486.                 $finalAverage $examUserRepository->getFinalAvarege(
  487.                     $user->getId(), 
  488.                     $course->getId()
  489.                 );
  490.                 $certificateAverage $course->getCertificateAverage();
  491.                 if($finalAverage >= $certificateAverage){
  492.                     $enrollment->setDateConclusion(date('Y-m-d H:i:s'));
  493.                     $marketingService->setTag(TagsMarketingEnum::TAG_FINISH_COURSE);
  494.                     $marketingService->setTextComplement($course->getTitle());
  495.                     $marketingService->setUser($this->getUser());
  496.                     $marketingService->send();
  497.                 }
  498.             }
  499.         }else{
  500.             $enrollment->setDateConclusion(date('Y-m-d H:i:s'));
  501.             $marketingService->setTag(TagsMarketingEnum::TAG_FINISH_COURSE);
  502.             $marketingService->setTextComplement($course->getTitle());
  503.             $marketingService->setUser($this->getUser());
  504.             $marketingService->send();
  505.         }
  506.         $this->em->flush();
  507.         return;
  508.     }
  509.     public function checkAndIssueCertificate(Enrollment $enrollment$finalAverage null)
  510.     {
  511.         if(!$this->configuration->isModuleActive("course_certificate_module")){
  512.             return;
  513.         }
  514.         if(!$this->configuration->checkModuleIsAbleOnPlan("certificateFunction")){
  515.             return;
  516.         }
  517.         if($enrollment->getCertificate() == EnrollmentEnum::NO){
  518.             return;
  519.         }
  520.         if($enrollment->getProgress() < 100){
  521.             return;
  522.         }
  523.         $user $enrollment->getUser();
  524.         $course $enrollment->getCourse();
  525.         if($course->getStatus() == CourseEnum::DRAFT){
  526.             return;
  527.         }
  528.         $courseCertificateTemplate $course->getCourseCertificateTemplate();
  529.         if(!$courseCertificateTemplate){
  530.             return;
  531.         }
  532.         $courseCertificateRepository $this->em->getRepository(CourseCertificate::class);
  533.         $certificate $courseCertificateRepository->findOneBy([
  534.             "course" => $enrollment->getCourse()->getId(),
  535.             "user" => $enrollment->getUser()->getId(),
  536.             "deleted" => CourseCertificateEnum::ITEM_NO_DELETED
  537.         ]);
  538.         if($certificate){
  539.             return $certificate;
  540.         }
  541.         $create false;
  542.         if(
  543.             $this->configuration->isModuleActive("exam_module") && 
  544.             $this->configuration->checkModuleIsAbleOnPlan("examFunction")
  545.         ){
  546.             $examUserRepository $this->em->getRepository(ExamUser::class);
  547.             $examRepository $this->em->getRepository(Exam::class);
  548.             $numberExamConfig $examRepository->countValidExamByCourse($course->getId());
  549.             /*$numberExamUserConfig = $examUserRepository->countValidExamUserByCourse(
  550.                 $course->getId(),
  551.                 $user->getId()
  552.             );*/
  553.             if(empty($finalAverage)){
  554.                 $finalAverage $examUserRepository->getFinalAvarege(
  555.                     $user->getId(), 
  556.                     $course->getId()
  557.                 );
  558.             }
  559.             $certificateAverage $course->getCertificateAverage();
  560.             if(empty($numberExamConfig)){
  561.                 $finalAverage 10;
  562.                 $create true;
  563.             }else if($finalAverage >= $certificateAverage){
  564.                 $create true;
  565.             }
  566.         }else{
  567.             $finalAverage 10;
  568.             $create true;
  569.         }
  570.         if($create){
  571.             $info $courseCertificateRepository->createCertificate(
  572.                 $enrollment,
  573.                 $courseCertificateTemplate,
  574.                 $finalAverage
  575.             );
  576.             $certificate $info->courseCertificate;
  577.         }
  578.         $this->em->flush();
  579.         return $certificate;
  580.     }
  581.     public function getCourseIndexByEnrollmentNew(Enrollment $enrollment)
  582.     {   
  583.         $enrollment $this->updateDataAccessLog($enrollment);
  584.         $certificate $this->checkAndIssueCertificate($enrollment);
  585.         $this->checkFinishCourseByEnrollment($enrollment);
  586.         $addExams true;
  587.         if(
  588.             !$this->configuration->isModuleActive("exam_module") || 
  589.             !$this->configuration->checkModuleIsAbleOnPlan("examFunction")
  590.         ){
  591.             $addExams false;
  592.         }
  593.         $course $enrollment->getCourse();
  594.         $user $enrollment->getUser();
  595.         $lessonRepository $this->em->getRepository(Lesson::class);
  596.         $logOriginRepository $this->em->getRepository(LessonLogOrigin::class);
  597.         $courseRepository $this->em->getRepository(Course::class);
  598.         $isStudent $courseRepository->isStudent($course);
  599.         $lessonModules $this->getModulesByEnrollment($enrollment);
  600.         $courseTestimonialRepository $this->em->getRepository(CourseTestimonial::class);
  601.         $courseTestimonial $courseTestimonialRepository->findOneBy([
  602.             "user" => $user->getId(),
  603.             "course" => $course->getId(),
  604.             "deleted" => CourseTestimonialEnum::ITEM_NO_DELETED
  605.         ]);
  606.         $testimonial null;
  607.         if($courseTestimonial){
  608.             $testimonial = (object)[
  609.                 "id" => $courseTestimonial->getId(),
  610.                 "score" => $courseTestimonial->getScore(),
  611.                 "testimonial" => $courseTestimonial->getTestimonial(),
  612.             ];
  613.         }
  614.         $certificateLink null;
  615.         if($certificate){
  616.             $certificateLink $this->generalService->generateUrl("viewCertificate", [
  617.                 "code" => $certificate->getNewCode() ?? $certificate->getCode(),
  618.                 "date" => $certificate->getDateEnd('Y-m-d'),
  619.             ]);
  620.         }
  621.         $allowCertificate true;
  622.         if($enrollment->getCertificate() == EnrollmentEnum::NO){
  623.             $poRepository $this->em->getRepository(ProductOffer::class);
  624.             $certificateOffer $poRepository->getProductOfferCertificateByCourse(
  625.                 $course
  626.             );
  627.             $allowCertificate = ($certificateOffer true false);
  628.         }
  629.         $allowSupport = ($course->getSupport() == CourseEnum::YES);
  630.         $dateSupport $enrollment->getDateSupport();
  631.         $date date('Y-m-d H:i:s');
  632.         $data = (object)[
  633.             "id" => $course->getId(),
  634.             "status" => $course->getStatus(),
  635.             "title" => $course->getTitle(),
  636.             "allowSupport" => $allowSupport,
  637.             "supportDate" => ($allowSupport $dateSupport null),
  638.             "supportExpired" => ($allowSupport && $dateSupport $date false true),
  639.             "exam" => null,
  640.             "testimonial" => $testimonial,
  641.             "modules" => $lessonModules,
  642.             "lessonCompleted" => (int)$logOriginRepository->countLessonLogCompleteByUser(
  643.                 $course,
  644.                 $user
  645.             ),
  646.             "lessonTotal" => (int)$lessonRepository->countCourseLessons($course$user->getId()),
  647.             "allowCertificate" => $allowCertificate,
  648.             "certificateLink" => $certificateLink,
  649.         ];
  650.         if($addExams){
  651.             $examRepository $this->em->getRepository(Exam::class);
  652.             $data->exam $examRepository->getExamToIndexNew(
  653.                 $isStudent
  654.                 ExamEnum::COURSE
  655.                 $course
  656.             );
  657.         }
  658.         return $data;
  659.     }
  660.     public function getCourseIndexByEnrollment(Enrollment $enrollment$addExams false)
  661.     {   
  662.         $enrollment $this->updateDataAccessLog($enrollment);
  663.         $this->checkAndIssueCertificate($enrollment);
  664.         $this->checkFinishCourseByEnrollment($enrollment);
  665.         $addExamsLimited $addExams;
  666.         if($addExams){
  667.             if(
  668.                 !$this->configuration->isModuleActive("exam_module") || 
  669.                 !$this->configuration->checkModuleIsAbleOnPlan("examFunction")
  670.             ){
  671.                 $addExams false;
  672.                 $addExamsLimited false;
  673.             }else{
  674.                 $addExamsLimited $this->configuration->checkModuleIsAbleOnPlan(
  675.                     "unlimitedExamFunction"
  676.                 );
  677.             }
  678.         }
  679.         $certificate $this->checkAndIssueCertificate($enrollment);
  680.         $course $enrollment->getCourse();
  681.         $courseCoord $course->getUser();
  682.         $courseRepository $this->em->getRepository(Course::class);
  683.         $isStudent $courseRepository->isStudent($course);
  684.         $lessonModules $this->getHistoryByEnrollment(
  685.             $enrollment
  686.             $addExamsLimited
  687.             $isStudent
  688.         );
  689.         $today date('Y-m-d H-i-s');
  690.         $courseTestimonialRepository $this->em->getRepository(CourseTestimonial::class);
  691.         $courseTestimonial $courseTestimonialRepository->findOneBy([
  692.             "user" => $enrollment->getUser()->getId(),
  693.             "course" => $course->getId(),
  694.             "deleted" => CourseTestimonialEnum::ITEM_NO_DELETED
  695.         ]);
  696.         $timeToday strtotime(date('Y-m-d H:i:s'));
  697.         $courseDateRelease strtotime($course->getDateRelease());
  698.         $courseHasRelease = !($courseDateRelease >= $timeToday);
  699.         $courseHasCertificate = ($course->getCertificate() == CourseEnum::YES);
  700.         $certificateSale false;
  701.         $linkPdf null;
  702.         $linkBuy null;
  703.         if($courseHasCertificate){
  704.             if(!$certificate && $enrollment->getCertificate() == EnrollmentEnum::NO){
  705.                 $poRepository $this->em->getRepository(ProductOffer::class);
  706.                 $certificateOffer $poRepository->getProductOfferCertificateByCourse(
  707.                     $course
  708.                 );
  709.                 if($certificateOffer){
  710.                     $certificateSale true;
  711.                     $linkBuy $this->generalService->generateUrl("cartAdd", [
  712.                         "poID" => $certificateOffer->getId(),
  713.                         "courseId" => $course->getId(),
  714.                     ]);
  715.                 }
  716.             }
  717.         }
  718.         if($certificate){
  719.             $linkPdf $this->generalService->generateUrl("viewCertificate", [
  720.                 "code" => $certificate->getCode(),
  721.                 "date" => $certificate->getDateEnd('Y-m-d'),
  722.             ]);
  723.         }
  724.         $accessExpired CourseEnum::NO;
  725.         if(strtotime($enrollment->getDatePeriod()) < time()){
  726.             $accessExpired CourseEnum::YES;
  727.         }
  728.         $lessonSupport $course->getSupport();
  729.         $supportExpired CourseEnum::NO;
  730.         //check user has active support
  731.         if($lessonSupport == CourseEnum::YES && $isStudent){
  732.             $userDateSupport $enrollment->getDateSupport();
  733.             $userDateSupport strtotime($userDateSupport);
  734.             if($timeToday $userDateSupport){
  735.                 $supportExpired CourseEnum::YES;
  736.             }
  737.         }
  738.         $data = (object)[
  739.             "id" => $course->getId(),
  740.             "status" => $course->getStatus(),
  741.             "courseTitle" => $course->getTitle(),
  742.             "courseTime" => $course->getWorkload(),
  743.             "courseDateRelease" => $course->getDateRelease(),
  744.             "courseHasRelease" => $courseHasRelease,
  745.             "courseHasCertificate" => $courseHasCertificate,
  746.             "courseAllowSupport" => $course->getSupport(),
  747.             "coorName" => $courseCoord->getName(),
  748.             "coorPhoto" => $courseCoord->getPhoto(),
  749.             "coorUsername" => $courseCoord->getUsername(),
  750.             "courseExam" => null,
  751.             "courseLesstonTotal" => $course->getNumberLesson(),
  752.             "enrollmentPercent" => $enrollment->getProgress(),
  753.             "enrollmentLessonView" => $enrollment->getLessonNumberComplete(),
  754.             "enrollmentDatePeriod" => $enrollment->getDatePeriod(),
  755.             "enrollmentAllowAccess" => ($enrollment->getDatePeriod() >= $today),
  756.             "enrollmentDateSupport" => $enrollment->getDateSupport(),
  757.             "enrollmentAllowSupport" => ($enrollment->getDateSupport() >= $today),
  758.             "courseTestimonial" => (
  759.                 $courseTestimonial $courseTestimonial->toReturn() : null
  760.             ),
  761.             "lessonModules" => $lessonModules,
  762.             "certificateIssue" => ($certificate true false),
  763.             "certificateLink" => $linkPdf,
  764.             "certificateSale" => $certificateSale,
  765.             "certificateLinkBuy" => $linkBuy,
  766.             "isStudent" => $isStudent,
  767.             "accessExpired" => $accessExpired,
  768.             "supportExpired" => $supportExpired,
  769.             "lessonSupport" => $lessonSupport,
  770.         ];
  771.         if($addExams){
  772.             $examRepository $this->em->getRepository(Exam::class);
  773.             $data->courseExam $examRepository->getExamToIndex(ExamEnum::COURSE$course);
  774.         }
  775.         return $data;
  776.     }
  777.     public function getModulesByEnrollmentNew(
  778.         Enrollment $enrollment
  779.         ?bool $isStudent true
  780.         ?string $searchText null
  781.     )
  782.     {
  783.         $addExams false;
  784.         if(
  785.             $this->configuration->isModuleActive("exam_module") &&
  786.             $this->configuration->checkModuleIsAbleOnPlan("examFunction") &&
  787.             $this->configuration->checkModuleIsAbleOnPlan("unlimitedExamFunction")
  788.         ){
  789.             $addExams true;
  790.         }
  791.         $course $enrollment->getCourse();
  792.         $user $enrollment->getUser();
  793.         $data = [];
  794.         $logOriginRepository $this->em->getRepository(LessonLogOrigin::class);
  795.         $lessonRepository $this->em->getRepository(Lesson::class);
  796.         $examRepository $this->em->getRepository(Exam::class);
  797.         $lessonModuleRepository $this->em->getRepository(LessonModule::class);
  798.         $lessonModules $lessonModuleRepository->getCourseLessonModules($course);
  799.         foreach ($lessonModules as $keyModule => $lessonModule) {
  800.             $lessonsSearch $this->getHistoryByEnrollmentModuleNew(
  801.                 $enrollment,
  802.                 $lessonModule,
  803.                 $addExams,
  804.                 $isStudent,
  805.                 $searchText
  806.             );
  807.             if(!empty($lessonsSearch)){
  808.                 $lessonModuleObj = (object)[
  809.                     "id" => $lessonModule->getId(),
  810.                     "title" => $lessonModule->getTitle(),
  811.                     "description" => $lessonModule->getDescription(),
  812.                     "status" => $lessonModule->getStatus(),
  813.                     "lessonCompleted" => (int)$logOriginRepository->countLessonLogCompleteByUser(
  814.                         $course,
  815.                         $user,
  816.                         $lessonModule
  817.                     ),
  818.                     "lessonTotal" => (int)$lessonRepository->countCourseLessons(
  819.                         $course,
  820.                         $user->getId(),
  821.                         $lessonModule
  822.                     ),
  823.                     "exam" => null,
  824.                     "lessons" => $lessonsSearch,
  825.                 ];
  826.                 if($addExams){
  827.                     $lessonModuleObj->exam $examRepository->getExamToIndexNew(
  828.                         $isStudent,
  829.                         ExamEnum::MODULE
  830.                         $course,
  831.                         $lessonModule
  832.                     );
  833.                 }
  834.                 
  835.                 $data[] = $lessonModuleObj;
  836.             }
  837.         }
  838.         return $data;
  839.     }
  840.     public function getModuleIndexByEnrollmentNew(
  841.         Enrollment $enrollment
  842.         LessonModule $lessonModule,
  843.         ?bool $isStudent true
  844.     )
  845.     {
  846.         $addExams false;
  847.         if(
  848.             $this->configuration->isModuleActive("exam_module") &&
  849.             $this->configuration->checkModuleIsAbleOnPlan("examFunction") &&
  850.             $this->configuration->checkModuleIsAbleOnPlan("unlimitedExamFunction")
  851.         ){
  852.             $addExams true;
  853.         }
  854.         $course $enrollment->getCourse();
  855.         $data = (object)[
  856.             "id" => $lessonModule->getId(),
  857.             "title" => $lessonModule->getTitle(),
  858.             "description" => $lessonModule->getDescription(),
  859.             "status" => $lessonModule->getStatus(),
  860.             "exam" => null,
  861.             "lessons" => $this->getHistoryByEnrollmentModuleNew(
  862.                 $enrollment,
  863.                 $lessonModule,
  864.                 $addExams,
  865.                 $isStudent
  866.             ),
  867.         ];
  868.         if($addExams){
  869.             $examRepository $this->em->getRepository(Exam::class);
  870.             $data->exam $examRepository->getExamToIndexNew(
  871.                 $isStudent,
  872.                 ExamEnum::MODULE
  873.                 $course,
  874.                 $lessonModule
  875.             );
  876.         }
  877.         return $data;
  878.     }
  879.     public function getModulesByEnrollment(Enrollment $enrollment)
  880.     {
  881.         $lessonModuleRepository $this->em->getRepository(LessonModule::class);
  882.         $lessonRepository $this->em->getRepository(Lesson::class);
  883.         $logOriginRepository $this->em->getRepository(LessonLogOrigin::class);
  884.         $examRepository $this->em->getRepository(Exam::class);
  885.         
  886.         $course $enrollment->getCourse();
  887.         $user $enrollment->getUser();
  888.         $data = [];
  889.         $lessonModules $lessonModuleRepository->getCourseLessonModules($course);
  890.         foreach ($lessonModules as $keyModule => $lessonModule) {
  891.             $lessonModuleObj = (object)[
  892.                 "id" => $lessonModule->getId(),
  893.                 "title" => $lessonModule->getTitle(),
  894.                 "description" => $lessonModule->getDescription(),
  895.                 "status" => $lessonModule->getStatus(),
  896.                 "lessonCompleted" => (int)$logOriginRepository->countLessonLogCompleteByUser(
  897.                     $course,
  898.                     $user,
  899.                     $lessonModule
  900.                 ),
  901.                 "lessonTotal" => (int)$lessonRepository->countCourseLessons(
  902.                     $course,
  903.                     $user->getId(),
  904.                     $lessonModule
  905.                 ),
  906.             ];
  907.             if($lessonModuleObj->lessonCompleted $lessonModuleObj->lessonTotal){
  908.                 $lessonModuleObj->lessonCompleted $lessonModuleObj->lessonTotal;
  909.             }
  910.             
  911.             $data[] = $lessonModuleObj;
  912.         }
  913.         return $data;
  914.     }
  915.     public function getHistoryByEnrollment(
  916.         Enrollment $enrollment
  917.         ?bool $addExams false
  918.         ?bool $isStudent true
  919.     )
  920.     {
  921.         $lessonModuleRepository $this->em->getRepository(LessonModule::class);
  922.         $lessonRepository $this->em->getRepository(Lesson::class);
  923.         $lessonLogRepository $this->emEadmin->getRepository(LessonLog::class);
  924.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  925.         $lessonAnnotationRepository $this->em->getRepository(LessonAnnotation::class);
  926.         $examRepository $this->em->getRepository(Exam::class);
  927.         
  928.         $stringUtil $this->generalService->getUtil('StringUtil');
  929.         $course $enrollment->getCourse();
  930.         $user $enrollment->getUser();
  931.         $data = [];
  932.         $lessonModules $lessonModuleRepository->getCourseLessonModules($course);
  933.         $lessons $lessonRepository->getCourseLessons($course);
  934.         $auxLogs = [];
  935.         $lessonLogs $lessonLogRepository->findBy(
  936.             [
  937.               "user" => $user->getId(),
  938.               "course" => $course->getId(),
  939.             ],
  940.            null
  941.            null
  942.            null
  943.            [ $course->getId(), "{$user->getId()}#" ]
  944.         );
  945.         foreach ($lessonLogs as $key => $log) {
  946.             $auxLogs[$log->getLesson()->getId()] = $log;
  947.         }
  948.         $examModule $this->configuration->isModuleActive("exam_module");
  949.         $blockNextLesson false;
  950.         $lessonIdBefore null;
  951.         foreach ($lessonModules as $keyModule => $lessonModule) {
  952.             $lessonModuleObj = (object)[
  953.                 "id" => $lessonModule->getId(),
  954.                 "courseId" => $course->getId(),
  955.                 "title" => $lessonModule->getTitle(),
  956.                 "order" => $lessonModule->getOrder(),
  957.                 "status" => $lessonModule->getStatus(),
  958.                 "controlRequirement" => $lessonModule->getControlRequirement(),
  959.                 "controlReleaseType" => $lessonModule->getControlReleaseType(),
  960.                 "controlReleaseAfterType" => $lessonModule->getControlReleaseAfterType(),
  961.                 "controlDateRelease" => $lessonModule->getControlDateRelease(),
  962.                 "controlReleasePeriod" => $lessonModule->getControlReleasePeriod(),
  963.                 "controlClosePeriod" => $lessonModule->getControlClosePeriod(),
  964.                 "moduleIsAccessible" => false,
  965.                 "lessonCompleted" => 0,
  966.                 "lessonTotal" => 0,
  967.                 "exam" => null,
  968.                 "lessons" => [],
  969.             ];
  970.             if($addExams){
  971.                 $lessonModuleObj->exam $examRepository->getExamToIndex(
  972.                     ExamEnum::MODULE$course$lessonModule
  973.                 );
  974.             }
  975.             foreach ($lessons as $keyLesson => $lesson) {
  976.                 if($lessonModuleObj->id == $lesson->getLessonModule()->getId()){
  977.                     if($lesson->getStatus() == LessonEnum::PUBLISHED){
  978.                         $lessonModuleObj->lessonTotal $lessonModuleObj->lessonTotal 1;
  979.                     }
  980.                     $lessonLog = ( 
  981.                         isset($auxLogs[$lesson->getId()]) ?
  982.                         $auxLogs[$lesson->getId()] :
  983.                         null
  984.                     );
  985.                     $lessonIsAccessible $lessonRepository->checkLessonIsAccessibleToUser(
  986.                         $lesson,
  987.                         $enrollment,
  988.                         $lessonLog,
  989.                         $isStudent,
  990.                         $lessonIdBefore,
  991.                         $blockNextLesson
  992.                     );
  993.                     if(
  994.                         !$lessonIsAccessible->isAccessible && 
  995.                         $lesson->getControlRequirement() == LessonEnum::YES
  996.                     ){
  997.                         $blockNextLesson true;
  998.                     }
  999.                     if(empty($lessonModuleObj->lessons)){
  1000.                         $lessonModuleObj->moduleIsAccessible $lessonIsAccessible->isAccessible;
  1001.                     }
  1002.                     $dateReleaseAccess $lessonRepository->getLessonDateReleaseAccess(
  1003.                         $lesson,
  1004.                         $enrollment,
  1005.                         $isStudent,
  1006.                         $lessonIdBefore
  1007.                     );
  1008.                     $lessonIdBefore $lesson->getId();
  1009.                     $contentPagesNumber null;
  1010.                     $contentDuration null;
  1011.                     $contentType null;
  1012.                     $library $lesson->getLibrary();
  1013.                     if($library){
  1014.                         $contentPagesNumber $library->getPagesNumber();
  1015.                         $contentDuration $library->getDuration();
  1016.                         $contentType $library->getType();
  1017.                     }
  1018.                     $lessonObj = (object)[
  1019.                         "id" => $lesson->getId(),
  1020.                         "courseId" => $course->getId(),
  1021.                         "lessonModuleId" => $lessonModuleObj->id,
  1022.                         "title" => $lesson->getTitle(),
  1023.                         "order" => $lesson->getOrder(),
  1024.                         "status" => $lesson->getStatus(),
  1025.                         "lessonIsAccessible" => $lessonIsAccessible->isAccessible,
  1026.                         "dateReleaseAccess" => $dateReleaseAccess,
  1027.                         "exam" => null,
  1028.                         "quiz" => null,
  1029.                         "timeWatch" => null,
  1030.                         "numberAccess" => null,
  1031.                         "numberSupport" => null,
  1032.                         "dateLastAccess" => null,
  1033.                         "dateConclusion" => null,
  1034.                         "contentPagesNumber" => $contentPagesNumber,
  1035.                         "contentDuration" => $contentDuration,
  1036.                         "contentType" => $contentType,
  1037.                         "allowCheck" => EnrollmentEnum::YES,
  1038.                         "controlRequirement" => $lesson->getControlRequirement(),
  1039.                         "controlReleaseType" => $lesson->getControlReleaseType(),
  1040.                         "controlReleaseAfterType" => $lesson->getControlReleaseAfterType(),
  1041.                         "controlDateRelease" => $lesson->getControlDateRelease(),
  1042.                         "controlReleasePeriod" => $lesson->getControlReleasePeriod(),
  1043.                         "controlClosePeriod" => $lesson->getControlClosePeriod(),
  1044.                         "controlTime" => (
  1045.                             $lesson->getControlRequirement() ? 
  1046.                             $lesson->getControlTime() : 
  1047.                             LessonEnum::NO
  1048.                         ),
  1049.                         "controlTimeStay" => $lesson->getControlTimeStay(),
  1050.                         "controlViewLimit" => $lesson->getControlViewLimit(),
  1051.                         "controlViewNumber" => $lesson->getControlViewNumber(),
  1052.                         "controlPauseNumber" => $lesson->getControlPauseNumber(),
  1053.                     ];
  1054.                     if($lesson->getControlRequirement() == LessonEnum::YES){
  1055.                         $lessonObj->allowCheck LessonEnum::NO;
  1056.                     }
  1057.                     if(
  1058.                         !empty($lesson->getControlTimeStay()) && 
  1059.                         $lesson->getControlTimeStay() != '00:00:00'
  1060.                     ){
  1061.                         $lessonObj->allowCheck LessonEnum::NO;
  1062.                     }
  1063.                     if($addExams){
  1064.                         $lessonObj->exam $examRepository->getExamToIndex(
  1065.                             ExamEnum::LESSON
  1066.                             $course
  1067.                             $lessonModule
  1068.                             $lesson
  1069.                         );
  1070.                     }
  1071.                     $lessonObj->quiz $examRepository->getExamToIndex(
  1072.                         ExamEnum::QUIZ,
  1073.                         $course,
  1074.                         $lessonModule,
  1075.                         $lesson
  1076.                     );
  1077.                     $lessonObj->numberSupport $lessonSupportRepository->count([
  1078.                         "user" => $user->getId(),
  1079.                         "lesson" => $lesson->getId(),
  1080.                         "lessonSupport" => null,
  1081.                     ]);
  1082.                     $lessonObj->supports = [];
  1083.                     if(!empty($lessonObj->numberSupport)){
  1084.                         $supports $lessonSupportRepository->findBy([
  1085.                             "user" => $user->getId(),
  1086.                             "lesson" => $lesson->getId(),
  1087.                             "lessonSupport" => null,
  1088.                             "deleted" => LessonSupportEnum::ITEM_NO_DELETED
  1089.                         ]);
  1090.                         foreach ($supports  as $key => $support) {
  1091.                             $txt strip_tags(html_entity_decode($support->getSupport()));
  1092.                             $txt str_replace("\xc2\xa0"''$txt);
  1093.                             
  1094.                             $lessonObj->supports[] = (object)[
  1095.                                 "id" => $support->getId(),
  1096.                                 "date" => $support->getDate(),
  1097.                                 "support" => $stringUtil->shortTextCleanNew($txt),
  1098.                             ];
  1099.                         }
  1100.                     }
  1101.                     $lessonObj->notes = [];
  1102.                     $lessonNotes $lessonAnnotationRepository->findBy([
  1103.                         "user" => $user->getId(),
  1104.                         "lesson" => $lesson->getId(),
  1105.                         "deleted" => LessonAnnotationEnum::ITEM_NO_DELETED
  1106.                     ], [ "id" => "DESC" ]);
  1107.                     if(!empty($lessonNotes)){
  1108.                         foreach ($lessonNotes  as $key => $note) {
  1109.                             $lessonObj->notes[] = (object)[
  1110.                                 "id" => $note->getId(),
  1111.                                 "date" => $note->getDate(),
  1112.                                 "time" => $note->getTime(),
  1113.                                 "note" => $note->getAnnotation(),
  1114.                                 "options" => $note->getOptions()
  1115.                             ];
  1116.                         }
  1117.                     }
  1118.                     if($lessonLog){
  1119.                         if($lessonLog->getComplete() == LessonEnum::YES){
  1120.                             $lessonModuleObj->lessonCompleted $lessonModuleObj->lessonCompleted 1;
  1121.                         }
  1122.                         $lessonObj->complete $lessonLog->getComplete();
  1123.                         $lessonObj->favorite $lessonLog->getFavorite();
  1124.                         $lessonObj->timeWatch $lessonLog->getTimeWatch();
  1125.                         $lessonObj->numberAccess $lessonLog->getNumberAccess();
  1126.                         $lessonObj->dateLastAccess $lessonLog->getDateAccess();
  1127.                         $lessonObj->dateConclusion $lessonLog->getDateConclusion();
  1128.                         if(!empty($lessonObj->dateConclusion)){
  1129.                             $lessonObj->allowCheck LessonEnum::YES;
  1130.                         }
  1131.                     }
  1132.                     $lessonModuleObj->lessons[] = $lessonObj;
  1133.                 }
  1134.             }
  1135.             if($lessonModuleObj->lessonCompleted $lessonModuleObj->lessonTotal){
  1136.                 $lessonModuleObj->lessonCompleted $lessonModuleObj->lessonTotal;
  1137.             }
  1138.             $data[] = $lessonModuleObj;
  1139.         }
  1140.         return $data;
  1141.     }
  1142.     public function getHistoryByEnrollmentModuleNew(
  1143.         Enrollment $enrollment
  1144.         LessonModule $lessonModule,
  1145.         ?bool $addExams false
  1146.         ?bool $isStudent true,
  1147.         ?string $searchText null
  1148.     )
  1149.     {
  1150.         $lessonRepository $this->em->getRepository(Lesson::class);
  1151.         $libraryRepository $this->em->getRepository(Library::class);
  1152.         $lessonLogRepository $this->emEadmin->getRepository(LessonLog::class);
  1153.         $examRepository $this->em->getRepository(Exam::class);
  1154.         
  1155.         $stringUtil $this->generalService->getUtil('StringUtil');
  1156.         $course $enrollment->getCourse();
  1157.         $user $enrollment->getUser();
  1158.         $data = [];
  1159.         $lessons $lessonRepository->getCourseLessons(
  1160.             $course
  1161.             $lessonModule
  1162.             null
  1163.             $searchText
  1164.         );
  1165.         $blockNextLesson false;
  1166.         $lessonIdBefore null;
  1167.         $timeUtil $this->generalService->getUtil('DateTimeUtil');
  1168.         
  1169.         foreach ($lessons as $keyLesson => $lesson) {
  1170.             $logId "{$course->getId()}#{$user->getId()}#{$lesson->getId()}";
  1171.             $lessonLog $lessonLogRepository->find($logId);
  1172.             $lessonIsAccessible $lessonRepository->checkLessonIsAccessibleToUser(
  1173.                 $lesson,
  1174.                 $enrollment,
  1175.                 $lessonLog,
  1176.                 $isStudent,
  1177.                 $lessonIdBefore,
  1178.                 $blockNextLesson
  1179.             );
  1180.             if($lessonIsAccessible->isAccessPeriodExpired){
  1181.                 continue;
  1182.             }
  1183.             if(
  1184.                 !$lessonIsAccessible->isAccessible && 
  1185.                 $lesson->getControlRequirement() == LessonEnum::YES
  1186.             ){
  1187.                 $blockNextLesson true;
  1188.             }
  1189.             /*$dateReleaseAccess = $lessonRepository->getLessonDateReleaseAccess(
  1190.                 $lesson,
  1191.                 $enrollment,
  1192.                 $isStudent,
  1193.                 $lessonIdBefore
  1194.             );*/
  1195.             $lessonIdBefore $lesson->getId();
  1196.             $contentPagesNumber null;
  1197.             $contentDuration null;
  1198.             $contentType null;
  1199.             $contentThumb null;
  1200.             $library $lesson->getLibrary();
  1201.             if($library){
  1202.                 $contentPagesNumber $library->getPagesNumber();
  1203.                 $contentDuration $library->getDuration();
  1204.                 $contentType $library->getType();
  1205.                 $contentThumb $libraryRepository->getCover($library);
  1206.             }
  1207.             $lessonObj = (object)[
  1208.                 "id" => $lesson->getId(),
  1209.                 "title" => $lesson->getTitle(),
  1210.                 "status" => $lesson->getStatus(),
  1211.                 "required" => $lesson->getControlRequirement(),
  1212.                 "lessonIsAccessible" => $lessonIsAccessible->isAccessible,
  1213.                 "acessMessage" => $lessonIsAccessible->message,
  1214.                 "contentPagesNumber" => $contentPagesNumber,
  1215.                 "contentDuration" => (
  1216.                     $contentDuration $timeUtil->timeToSec($contentDuration) : null
  1217.                 ),
  1218.                 "contentType" => $contentType,
  1219.                 "contentThumb" => $contentThumb,
  1220.                 "exam" => null,
  1221.                 "quiz" => null,
  1222.                 "allowCheck" => EnrollmentEnum::YES,
  1223.                 "completed" => LessonEnum::NO,
  1224.             ];
  1225.             if($lessonLog && $lessonLog->getComplete() == LessonEnum::YES){
  1226.                 $lessonObj->completed $lessonLog->getViewed();
  1227.             }
  1228.             if($lesson->getControlRequirement() == LessonEnum::YES){
  1229.                 $lessonObj->allowCheck LessonEnum::NO;
  1230.             }
  1231.             if(
  1232.                 !empty($lesson->getControlTimeStay()) && 
  1233.                 $lesson->getControlTimeStay() != '00:00:00'
  1234.             ){
  1235.                 $lessonObj->allowCheck LessonEnum::NO;
  1236.             }
  1237.             if($addExams){
  1238.                 $lessonObj->exam $examRepository->getExamToIndexNew(
  1239.                     $isStudent,
  1240.                     ExamEnum::LESSON
  1241.                     $course
  1242.                     $lessonModule
  1243.                     $lesson
  1244.                 );
  1245.             }
  1246.             $lessonObj->quiz $examRepository->getExamToIndexNew(
  1247.                 $isStudent,
  1248.                 ExamEnum::QUIZ,
  1249.                 $course,
  1250.                 $lessonModule,
  1251.                 $lesson
  1252.             );
  1253.             
  1254.             $data[] = $lessonObj;
  1255.         }
  1256.         return $data;
  1257.     }
  1258.     public function getExpiredEnrollmentsByDate($date)
  1259.     {
  1260.         $query $this->createQueryBuilder('e');
  1261.         $query->andWhere('e.deleted = 0');
  1262.         $query->andWhere('e.datePeriod = :date');
  1263.         $query->setParameter('date'$date);
  1264.         $query->andWhere('e.status = :status');
  1265.         $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1266.         return $query->getQuery()->execute();
  1267.     }
  1268.     public function isValidEnrollmentByUser($userId$courseId)
  1269.     {
  1270.         $query $this->createQueryBuilder('e');
  1271.         
  1272.         $query->innerJoin(
  1273.             'EADPlataforma:Course''c'
  1274.             'WITH''e.course = c AND c.deleted = :deletedCourse'
  1275.         );
  1276.         $query->andWhere('e.deleted = :deleted');
  1277.         $query->andWhere('e.user = :userId');
  1278.         $query->andWhere('e.course = :courseId');
  1279.         if($userId != EnrollmentEnum::YES){
  1280.             $query->andWhere('e.status = :status');
  1281.             $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1282.             $query->andWhere('e.datePeriod >= :now');
  1283.             $query->setParameter('now'date('Y-m-d H:i:s'));
  1284.         }
  1285.         $query->setParameter('deletedCourse'CourseEnum::ITEM_NO_DELETED);
  1286.         $query->setParameter('deleted'EnrollmentEnum::ITEM_NO_DELETED);
  1287.         $query->setParameter('userId'$userId);
  1288.         $query->setParameter('courseId'$courseId);
  1289.         $query->select('COUNT(0) AS total');
  1290.         $result = (object)$query->getQuery()->getOneOrNullResult();
  1291.         return ($result->total 0);
  1292.     }
  1293.     public function isEnrollment($userId$courseId)
  1294.     {
  1295.         $query $this->createQueryBuilder('e');
  1296.         $query->innerJoin(
  1297.             'EADPlataforma:Course''c'
  1298.             'WITH''e.course = c AND c.deleted = :deletedCourse'
  1299.         );
  1300.         $query->andWhere('e.deleted = :deleted');
  1301.         $query->andWhere('e.user = :userId');
  1302.         $query->andWhere('e.course = :courseId');
  1303.         $query->andWhere('e.status = :status');
  1304.         $query->setParameter('deletedCourse'CourseEnum::ITEM_NO_DELETED);
  1305.         $query->setParameter('deleted'EnrollmentEnum::ITEM_NO_DELETED);
  1306.         $query->setParameter('userId'$userId);
  1307.         $query->setParameter('courseId'$courseId);
  1308.         $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1309.         $query->select('COUNT(0) AS total');
  1310.         $result = (object)$query->getQuery()->getOneOrNullResult();
  1311.         return ($result->total 0);
  1312.     }
  1313.     public function countEnrollmentsByCourse(
  1314.         int $courseId
  1315.         ?int $status null
  1316.         ?int $startType null
  1317.     )
  1318.     {
  1319.         $query $this->createQueryBuilder('e');
  1320.         $query->select("count(e.id) AS total");
  1321.         $query->andWhere('e.deleted = 0');
  1322.         $query->andWhere('e.course = :courseId');
  1323.         $query->setParameter('courseId'$courseId);
  1324.         if(!empty($status)){
  1325.             if($status == EnrollmentEnum::STATUS_EXPIRED){
  1326.                 $query->andWhere('e.status = :status');
  1327.                 $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1328.                 $query->andWhere('e.datePeriod <= :now');
  1329.                 $query->setParameter('now'date('Y-m-d H:i:s'));
  1330.             }else if($status == EnrollmentEnum::STATUS_ACTIVE){
  1331.                 $query->andWhere('e.status = :status');
  1332.                 $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1333.                 $query->andWhere('e.datePeriod >= :now');
  1334.                 $query->setParameter('now'date('Y-m-d H:i:s'));
  1335.             }else{
  1336.                 $query->andWhere('e.status = :status');
  1337.                 $query->setParameter('status'$status);
  1338.             }
  1339.         }
  1340.         if($startType == EnrollmentEnum::SITUATION_STARTED){
  1341.             $query->andWhere('e.dateStart IS NOT NULL');
  1342.         }else if($startType == EnrollmentEnum::SITUATION_NOT_STARTED){
  1343.             $query->andWhere('e.dateStart IS NULL');
  1344.         }
  1345.         $result = (object)$query->getQuery()->getOneOrNullResult();
  1346.         return $result->total;
  1347.     }
  1348.     public function getEnrollmentsByCourse(
  1349.         int $courseId
  1350.         ?int $status null
  1351.         $startType null
  1352.     )
  1353.     {
  1354.         $query $this->createQueryBuilder('e');
  1355.         $query->andWhere('e.deleted = 0');
  1356.         $query->andWhere('e.course = :courseId');
  1357.         $query->setParameter('courseId'$courseId);
  1358.         if(!empty($status)){
  1359.             if($status == EnrollmentEnum::STATUS_EXPIRED){
  1360.                 $query->andWhere('e.status = :status');
  1361.                 $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1362.                 $query->andWhere('e.datePeriod <= :now');
  1363.                 $query->setParameter('now'date('Y-m-d H:i:s'));
  1364.             }else if($status == EnrollmentEnum::STATUS_ACTIVE){
  1365.                 $query->andWhere('e.status = :status');
  1366.                 $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1367.                 $query->andWhere('e.datePeriod >= :now');
  1368.                 $query->setParameter('now'date('Y-m-d H:i:s'));
  1369.             }else{
  1370.                 $query->andWhere('e.status = :status');
  1371.                 $query->setParameter('status'$status);
  1372.             }
  1373.         }
  1374.         if($startType == EnrollmentEnum::SITUATION_STARTED){
  1375.             $query->andWhere('e.dateStart IS NOT NULL');
  1376.         }else if($startType == EnrollmentEnum::SITUATION_NOT_STARTED){
  1377.             $query->andWhere('e.dateStart IS NULL');
  1378.         }
  1379.         return $query->getQuery()->execute();
  1380.     }
  1381.     public function getEnrollmentsByGroup(
  1382.         int $groupId
  1383.         ?int $status null
  1384.         ?int $userId null
  1385.         ?int $courseId null
  1386.     )
  1387.     {
  1388.         $query $this->createQueryBuilder('e');
  1389.         $query->innerJoin(
  1390.             'EADPlataforma:Group''g''WITH'
  1391.             'e.course MEMBER OF g.course AND e.user MEMBER OF g.user'
  1392.         );
  1393.         $query->andWhere('e.deleted = :deleted');
  1394.         $query->andWhere('g.id = :groupId');
  1395.         $query->setParameter('groupId'$groupId);
  1396.         $query->setParameter('deleted'EnrollmentEnum::ITEM_NO_DELETED);
  1397.         if(!empty($status)){
  1398.             if($status == EnrollmentEnum::STATUS_EXPIRED){
  1399.                 $query->andWhere('e.datePeriod < :now');
  1400.                 $query->setParameter('now'date('Y-m-d H:i:s'));
  1401.                 $query->andWhere('e.status = :status');
  1402.                 $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1403.             }else{
  1404.                 $query->andWhere('e.status = :status');
  1405.                 $query->setParameter('status'$status);
  1406.             }
  1407.         }
  1408.         if($userId 0){
  1409.             $query->andWhere('e.user = :userId');
  1410.             $query->setParameter('userId'$userId);
  1411.         }
  1412.         if($courseId 0){
  1413.             $query->andWhere('e.course = :courseId');
  1414.             $query->setParameter('courseId'$courseId);
  1415.         }
  1416.         
  1417.         return $query->getQuery()->execute();
  1418.     }
  1419.     public function getEnrollmentsToEditMany(
  1420.         ?array $users null
  1421.         $courseId null
  1422.         $groupId null
  1423.         $productId null
  1424.         $teacherId null
  1425.         $applyTo null
  1426.     )
  1427.     {
  1428.         $query $this->createQueryBuilder('e');
  1429.         $query->andWhere('e.deleted = 0');
  1430.         if(!empty($users) && is_array($users)){
  1431.             $users implode(','$users);
  1432.             $query->andWhere("e.user IN ({$users})");
  1433.         }
  1434.         if($courseId 0){
  1435.             $query->andWhere('e.course = :courseId')->setParameter('courseId'$courseId);
  1436.         }
  1437.         if($groupId 0){
  1438.             $query->innerJoin(
  1439.                 'EADPlataforma:Group''g''WITH'
  1440.                 'e.course MEMBER OF g.course AND e.user MEMBER OF g.user'
  1441.             );
  1442.             $query->andWhere('g.id = :groupId');
  1443.             $query->setParameter('groupId'$groupId);
  1444.         }
  1445.         if($productId 0){
  1446.             $query->innerJoin(
  1447.                 'EADPlataforma:Product''p''WITH''e.course MEMBER OF p.course '
  1448.             );
  1449.             $query->andWhere('p.id = :productId');
  1450.             $query->setParameter('productId'$productId);
  1451.         }
  1452.         if($teacherId 0){
  1453.             $subQuery $this->createQueryBuilder('course_team');
  1454.             $subQuery->select('IDENTITY(ct.course)');
  1455.             $subQuery->from('EADPlataforma:CourseTeam''ct');
  1456.             $subQuery->andWhere('ct.user = :teacherId');
  1457.             $subQuery $subQuery->getDQL();
  1458.             $query->andWhere($query->expr()->in('e.course'$subQuery));
  1459.             $query->setParameter('teacherId'$teacherId);
  1460.         }
  1461.         if(empty($applyTo)){
  1462.             $apply EnrollmentEnum::APPLY_TO_ALL;
  1463.         }
  1464.         switch ($applyTo) {
  1465.             case EnrollmentEnum::APPLY_TO_EXPIRED
  1466.                 $query->andWhere('e.datePeriod < :now');
  1467.                 $query->setParameter('now'date('Y-m-d H:i:s'));
  1468.                 break;
  1469.             case EnrollmentEnum::APPLY_TO_VALID_PERIOD
  1470.                 $query->andWhere('e.datePeriod >= :now');
  1471.                 $query->setParameter('now'date('Y-m-d H:i:s'));
  1472.                 break;
  1473.             case EnrollmentEnum::APPLY_TO_SUPPORT_EXPIRED
  1474.                 $query->andWhere('e.dateSupport < :now');
  1475.                 $query->setParameter('now'date('Y-m-d H:i:s'));
  1476.                 break;
  1477.             case EnrollmentEnum::APPLY_TO_CANCELED
  1478.                 $query->andWhere('e.status = :statusCanceled');
  1479.                 $query->setParameter('statusCanceled'EnrollmentEnum::STATUS_CANCELED);
  1480.                 break;
  1481.         }
  1482.         return $query->getQuery()->execute();
  1483.     }
  1484.     public function updateEnrollmentMany(
  1485.         array $enrollmentsIds = [],
  1486.         ?int $status null,
  1487.         ?int $access null,
  1488.         ?int $support null,
  1489.         ?int $certificate null
  1490.     )
  1491.     {
  1492.         $upStatus "";
  1493.         if(!is_null($status)){
  1494.             $upStatus " e.status = :status ";
  1495.         }
  1496.         if($access == EnrollmentEnum::ENROLL_ORIGINAL){
  1497.             $lifetimePeriod $enrollment->getCourse()->getLifetimePeriod();
  1498.             if($lifetimePeriod == CourseEnum::YES){
  1499.                 $datePeriod "9999-09-09 00:00:00";
  1500.             }else{
  1501.                 $accessPeriod $enrollment->getCourse()->getAccessPeriod();
  1502.                 $dateRegister $enrollment->getDateRegister();
  1503.     
  1504.                 $datePeriod strtotime("+ {$accessPeriod} day"strtotime($dateRegister));
  1505.                 $datePeriod date('Y-m-d H:i:s'$datePeriod);
  1506.             }
  1507.                 
  1508.             $enrollment->setDatePeriod($datePeriod);
  1509.         }elseif($access == EnrollmentEnum::ENROLL_CHANGE){
  1510.             if(!empty($dateAccess)){
  1511.                 $enrollment->setDatePeriod($dateAccess);
  1512.             }
  1513.         }elseif($access == EnrollmentEnum::ENROLL_LIFETIME){
  1514.             if($accessLifetimePeriod == EnrollmentEnum::YES){
  1515.                 $dateAccess "9999-09-09 00:00:00";
  1516.                 $enrollment->setDatePeriod($dateAccess);
  1517.             }
  1518.         }
  1519.         if($support == EnrollmentEnum::ENROLL_ORIGINAL){
  1520.             $supportCourse $enrollment->getCourse()->getSupport();
  1521.             if($supportCourse == CourseEnum::YES){
  1522.                 $lifetimeSupport $enrollment->getCourse()->getLifetimeSupport();
  1523.                 if($lifetimeSupport == CourseEnum::YES){
  1524.                     $dateSupport "9999-09-09 00:00:00";
  1525.                 }else{
  1526.                     $supportPeriod $enrollment->getCourse()->getSupportPeriod();
  1527.                     $dateRegister $enrollment->getDateRegister();
  1528.         
  1529.                     $dateSupport strtotime("+ {$supportPeriod} day"strtotime($dateRegister));
  1530.                     $dateSupport date('Y-m-d H:i:s'$dateSupport);
  1531.                 }
  1532.             }else{
  1533.                 $dateSupport "0000-00-00 00:00:00";
  1534.             }
  1535.             
  1536.             $enrollment->setDateSupport($dateSupport);
  1537.         }elseif($support == EnrollmentEnum::ENROLL_CHANGE){
  1538.             if(!empty($dateSupport)){
  1539.                 $enrollment->setDateSupport($dateSupport);
  1540.             }
  1541.         }elseif($support == EnrollmentEnum::ENROLL_LIFETIME){
  1542.             if($supportLifetimePeriod == EnrollmentEnum::YES){
  1543.                 $dateSupport "9999-09-09 00:00:00";
  1544.                 $enrollment->setDateSupport($dateSupport);
  1545.             }
  1546.         }
  1547.         if($certificate == EnrollmentEnum::ENROLL_CHANGE){
  1548.             $enrollment->setCertificate(EnrollmentEnum::YES);
  1549.         }elseif($certificate == EnrollmentEnum::ENROLL_ORIGINAL){
  1550.             $enrollment->setCertificate(EnrollmentEnum::NO);
  1551.         }
  1552.         $sql "UPDATE EADPlataforma:Enrollment AS e 
  1553.                 SET e.deleted = :deleted, e.typeDelete = :typeDelete,
  1554.                     e.userDelete = :userDelete, e.dateDelete = :dateNow
  1555.                 WHERE e.deleted = (:deleted - 1)
  1556.                 AND e.user = :userId";
  1557.         $query $this->em->createQuery($sql);
  1558.         $query->setParameter('userId'$userId);
  1559.         $query->setParameter('deleted'$deleted);
  1560.         $query->setParameter('typeDelete'$typeDelete);
  1561.         $query->setParameter('userDelete'$userDelete);
  1562.         $query->setParameter('dateNow'$dateNow);
  1563.         $query->execute();
  1564.     }
  1565.     public function getEnrollmentsByUserSubscription(UserSubscription $userSubscription)
  1566.     {
  1567.         $query $this->createQueryBuilder('e');
  1568.         $query->innerJoin(
  1569.             'EADPlataforma:UserSubscription''us''WITH''e.user = us.user'
  1570.         );
  1571.         $query->innerJoin(
  1572.             'EADPlataforma:Product''p''WITH''e.course MEMBER OF p.course '
  1573.         );
  1574.         $query->andWhere('e.deleted = 0');
  1575.         $query->andWhere('us.id = :userSubscriptionId');
  1576.         $query->andWhere('p.id = :productId');
  1577.         $query->andWhere('e.user = :userId');
  1578.         $query->setParameter('userSubscriptionId'$userSubscription->getId());
  1579.         $query->setParameter('productId'$userSubscription->getProduct()->getId());
  1580.         $query->setParameter('userId'$userSubscription->getUser()->getId());
  1581.         return $query->getQuery()->execute();
  1582.     }
  1583.     public function notify(Enrollment $enrollment)
  1584.     {
  1585.         //send email
  1586.         $emailService $this->generalService->getService('EmailService');
  1587.         $client $this->configuration->getClient();
  1588.         $user $enrollment->getUser();
  1589.         if(!$emailService->checkUserToSend($user)){
  1590.             return;
  1591.         }
  1592.         $emailService->setToEmail($user->getEmail());
  1593.         $emailService->setToName($user->getName());
  1594.         
  1595.         $subText1 $this->configuration->getLanguage('enrollment.subject1''email');
  1596.         $subText2 $this->configuration->getLanguage('enrollment.subject2''email');
  1597.         $subject $subText1 $enrollment->getCourse()->getTitle() . $subText2;
  1598.         $emailService->setSubject($subject);
  1599.         
  1600.         $domain $client->getDomainPrimary();
  1601.         $emailService->setData([
  1602.             "userName" => $user->getName(),
  1603.             "courseTitle" => $enrollment->getCourse()->getTitle(),
  1604.             "btnLink" => "https://{$domain}/enrollment/{$enrollment->getId()}",
  1605.         ]);
  1606.         $emailService->setTemplateBody("enrollment");
  1607.         $emailService->send();
  1608.         //notify user
  1609.         $notificationService $this->generalService->getService('NotificationService');
  1610.         $notificationService->create(
  1611.             $enrollment->getCourse()->getUser(),
  1612.             $user,
  1613.             NotificationEnum::ORIGIN_ENROLLMENT_NEW,
  1614.             $enrollment->getId()
  1615.         );
  1616.     }
  1617.     public function generateCertificate(
  1618.         Enrollment $enrollment
  1619.         bool $download false
  1620.     )
  1621.     {
  1622.         $pdfService $this->generalService->getService('PdfService');
  1623.                                             
  1624.         $user $enrollment->getUser();
  1625.         $course $enrollment->getCourse();
  1626.         $examUserRepository $this->em->getRepository(ExamUser::class);
  1627.         $userExams $examUserRepository->getStudentReportCard($user->getId(), $course->getId());
  1628.         $finalAvarage $examUserRepository->getFinalAvarege($user->getId(), $course->getId());
  1629.         $history $this->getHistoryByEnrollment($enrollment);
  1630.         $data = [
  1631.             "enrollmentUserPhoto" => $user->getPhoto(),
  1632.             "enrollmentUserName" => mb_strtoupper($user->getName()),
  1633.             "enrollmentCourseTitle" => $course->getTitle(),
  1634.             "enrollmentDateStart" => $enrollment->getDateStart(),
  1635.             "enrollmentLastAccess" => $enrollment->getDateLastAccess(),
  1636.             "courseProgress" => $enrollment->getProgress(),
  1637.             "userExams" => $userExams,
  1638.             "finalAvarage" => $finalAvarage,
  1639.             "dataAccessLesson" => $enrollment->getLessonNumberComplete(),
  1640.             "dataAccessLessonTotal" => $enrollment->getNumberLesson(),
  1641.             "dataAccessPreview" => $enrollment->getLessonNumberViews(),
  1642.             "dataAccessSopportRequests" => $enrollment->getSupportNumberRequest(),
  1643.             "dataAccessTimeCourse" => $enrollment->getLessonTimeWatch(),
  1644.             "history" => $history
  1645.         ];
  1646.         $pdfService->setFileName("historico_do_aluno");
  1647.         $pdfService->setTemplateBody("enrollment_history");
  1648.         $pdfService->setData($data);
  1649.         return $pdfService->generate(false$download);
  1650.     }
  1651.     public function export(
  1652.         $courseId null
  1653.         $userId null
  1654.         $groupId null
  1655.         $teacherId null
  1656.         $status null
  1657.         $dateStart null
  1658.         $dateEnd null
  1659.     )
  1660.     {
  1661.         $query $this->createQueryBuilder('e');
  1662.         $query->select("
  1663.             e.id,
  1664.             e.status,
  1665.             e.lessonNumberComplete,
  1666.             DATE_FORMAT(e.dateRegister, '%Y-%m-%d %H:%i:%s') AS dateRegister,
  1667.             DATE_FORMAT(e.dateConclusion, '%Y-%m-%d %H:%i:%s') AS dateConclusion,
  1668.             DATE_FORMAT(e.dateStart, '%Y-%m-%d %H:%i:%s') AS dateStart,
  1669.             DATE_FORMAT(e.dateSupport, '%Y-%m-%d %H:%i:%s') AS dateSupport,
  1670.             DATE_FORMAT(e.datePeriod, '%Y-%m-%d %H:%i:%s') AS datePeriod,
  1671.             DATE_FORMAT(e.dateLastAccess, '%Y-%m-%d %H:%i:%s') AS dateLastAccess,
  1672.             e.lessonNumberViews AS lessonNumberViews,
  1673.             e.supportNumberRequest AS supportNumberRequest,
  1674.             e.couponKey AS couponKey,
  1675.             e.certificate AS certificate,
  1676.             e.origin,
  1677.             e.finalAverage,
  1678.             
  1679.             u.id AS userId,
  1680.             u.status AS userStatus,
  1681.             u.name AS userName,
  1682.             u.email AS userEmail,
  1683.             u.document AS userDocument,
  1684.             DATE_FORMAT(u.birthDate, '%Y-%m-%d') AS userBirthDate,
  1685.             u.phone AS userPhone,
  1686.             u.address AS userAddress,
  1687.             u.addressNumber AS userAddressNumber,
  1688.             u.addressComplement AS userAddressComplement,
  1689.             u.addressNeighborhood AS userAddressNeighborhood,
  1690.             u.zipCode AS userZipCode,
  1691.             u.occupation AS userOccupation,
  1692.             u.notes AS userNotes,
  1693.             u.custom AS userCustom,
  1694.             DATE_FORMAT(u.dateRegister, '%Y-%m-%d %H:%i:%s') AS userDateRegister,
  1695.             u.acceptTerms AS userAcceptTerms,
  1696.             u.customField AS userCustomField,
  1697.             ct.name AS cityName,
  1698.             st.name AS stateName,
  1699.             cty.name AS countryName,
  1700.             c.title,
  1701.             c.numberLesson,
  1702.             c.certificateAverage,
  1703.             ca.category,
  1704.             g.name AS groupName
  1705.         ");
  1706.         $query->innerJoin('EADPlataforma:Course''c''WITH''c.id = e.course');
  1707.         $query->innerJoin('EADPlataforma:Category''ca''WITH''ca.id = c.category');
  1708.         $query->innerJoin('EADPlataforma:User''u''WITH''u.id = e.user');
  1709.         $query->leftJoin('EADPlataforma:City''ct''WITH''ct.id = u.city');
  1710.         $query->leftJoin('EADPlataforma:State''st''WITH''st.id = u.state');
  1711.         $query->leftJoin('EADPlataforma:Country''cty''WITH''cty.id = u.country');
  1712.         
  1713.         $query->andWhere('e.deleted = :deleted');
  1714.         $query->andWhere('u.deleted = :deleted');
  1715.         $query->andWhere('c.deleted = :deleted');
  1716.         $query->andWhere('u.id > 1');
  1717.         $query->andWhere('u.status != :userStatus');
  1718.         $query->setParameter('userStatus'UserEnum::INACTIVE);
  1719.         $query->setParameter('deleted'UserEnum::ITEM_NO_DELETED);
  1720.         if(!is_null($dateStart) && !is_null($dateEnd)){
  1721.             $query->andWhere('DATE(e.dateRegister) BETWEEN :dateStart AND :dateEnd');
  1722.             $query->setParameter('dateStart'$dateStart);
  1723.             $query->setParameter('dateEnd'$dateEnd);
  1724.         }
  1725.         if(!empty($courseId)){
  1726.             $query->andWhere('e.course = :course')->setParameter('course'$courseId);
  1727.         }
  1728.        
  1729.         if(!empty($groupId)){
  1730.             $query->innerJoin(
  1731.                 'EADPlataforma:Group''g''WITH'
  1732.                 'e.course MEMBER OF g.course AND e.user MEMBER OF g.user'
  1733.             );
  1734.             $query->andWhere('g.id = :groupId');
  1735.             $query->setParameter('groupId'$groupId);
  1736.         }else{
  1737.             $query->leftJoin(
  1738.                 'EADPlataforma:Group''g''WITH'
  1739.                 'e.course MEMBER OF g.course AND e.user MEMBER OF g.user'
  1740.             );
  1741.         }
  1742.         
  1743.         if(!empty($userId)){
  1744.             $query->andWhere('e.user = :user')->setParameter('user'$userId);
  1745.         }
  1746.         
  1747.         if(!empty($teacherId)){
  1748.             $subQuery $this->createQueryBuilder('course_team');
  1749.             $subQuery->select('IDENTITY(cteam.course)');
  1750.             $subQuery->from('EADPlataforma:CourseTeam''cteam');
  1751.             $subQuery->andWhere('cteam.user = :teacherId');
  1752.             $subQuery $subQuery->getDQL();
  1753.             $query->andWhere($query->expr()->in('e.course'$subQuery));
  1754.             $query->setParameter('teacherId'$teacherId);
  1755.         }
  1756.         if($status == EnrollmentEnum::STATUS_EXPIRED){
  1757.             $query->andWhere('e.datePeriod < :now');
  1758.             $query->setParameter('now'date('Y-m-d H:i:s'));
  1759.             $query->andWhere('e.status = :status');
  1760.             $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1761.         }else if($status == EnrollmentEnum::STATUS_ACTIVE){
  1762.             $query->andWhere('e.datePeriod >= :now');
  1763.             $query->setParameter('now'date('Y-m-d H:i:s'));
  1764.             $query->andWhere('e.status = :status');
  1765.             $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1766.         }else if(!empty($status)){
  1767.             $query->andWhere('e.status = :status');
  1768.             $query->setParameter('status'$status);
  1769.         }
  1770.         
  1771.         $data $query->getQuery()->execute();
  1772.         return $data;
  1773.     }
  1774.     public function getEnrollmentBeforeExpireByCourse(Course $coursestring $dateExpire)
  1775.     {
  1776.         $query $this->createQueryBuilder('e');
  1777.         $query->andWhere('e.deleted = 0');
  1778.         $query->andWhere('e.course = :course');
  1779.         $query->andWhere('DATE(e.datePeriod) = :datePeriod');
  1780.         $query->setParameter('course'$course->getId());
  1781.         $query->setParameter('datePeriod'$dateExpire);
  1782.         return $query->getQuery()->execute();
  1783.     }
  1784.     public function updateDataAccessLog(Enrollment $enrollment, ?bool $updateDate true){
  1785.         $course $enrollment->getCourse();
  1786.         $courseId $enrollment->getCourse()->getId();
  1787.         $userId $enrollment->getUser()->getId();
  1788.         $courseRepository $this->em->getRepository(Course::class);
  1789.         $lessonSupportRepository $this->em->getRepository(LessonSupport::class);
  1790.         $lessonLogRepository $this->emEadmin->getRepository(LessonLog::class);
  1791.         $lessonLogOriginRepository $this->em->getRepository(LessonLogOrigin::class);
  1792.         $isStudent $courseRepository->isStudent($course);
  1793.         $lessonsNumberComplete $lessonLogRepository->countLessonLogCompleteByUser(
  1794.             $course,
  1795.             $enrollment->getUser()
  1796.         );
  1797.         $lessonsDateLastAccess $lessonLogRepository->getLessonDateLastAccess(
  1798.             $courseId
  1799.             $userId
  1800.         );
  1801.         $lessonsNumberViews $lessonLogRepository->getLessonNumberViews(
  1802.             $courseId
  1803.             $userId
  1804.         );
  1805.         $lessonTimeWatch $lessonLogRepository->userLessonTimeWatch(
  1806.             $course
  1807.             $enrollment->getUser()
  1808.         );
  1809.         $supportNumberRequest $lessonSupportRepository->getSupportNumberRequestByEnrollment(
  1810.             $enrollment
  1811.         );
  1812.         $enrollment->setLessonTimeWatch(
  1813.             !empty($lessonTimeWatch) ? $lessonTimeWatch null
  1814.         );
  1815.         if($this->getUser()){
  1816.             if($this->getUser()->getId() == $userId && $updateDate){
  1817.                 if(empty($lessonsDateLastAccess)){
  1818.                     $lessonsDateLastAccess date('Y-m-d H:i:s');
  1819.                 }
  1820.                 $enrollment->setDateLastAccess(
  1821.                     !empty($lessonsDateLastAccess) ? $lessonsDateLastAccess null
  1822.                 );
  1823.                 if(empty($enrollment->getDateStart()) && !empty($lessonsDateLastAccess)){
  1824.                     if($isStudent){
  1825.                         //send mkt start course
  1826.                         $marketingService $this->generalService->getService(
  1827.                             'Marketing\\MarketingService'
  1828.                         );
  1829.             
  1830.                         $marketingService->setTag(TagsMarketingEnum::TAG_BEGIN_COURSE);
  1831.                         $marketingService->setTextComplement($course->getTitle());
  1832.                         $marketingService->setUser($this->getUser());
  1833.                         $marketingService->send();
  1834.                     }
  1835.                     $enrollment->setDateStart(date('Y-m-d H:i:s'));
  1836.                 }
  1837.             }
  1838.         }
  1839.         
  1840.         $enrollment->setLessonNumberComplete((int)$lessonsNumberComplete);
  1841.         $enrollment->setLessonNumberViews((int)$lessonsNumberViews);
  1842.         $enrollment->setSupportNumberRequest((int)$supportNumberRequest);
  1843.         $this->em->flush();
  1844.         return $enrollment;
  1845.     }
  1846.     public function getEnrollmentForPresence(
  1847.         Course $course
  1848.         ?bool $active true
  1849.         ?int $user null
  1850.         ?int $groupId null
  1851.         ?string $dateStart null
  1852.         ?string $dateEnd null
  1853.     )
  1854.     {
  1855.         $query $this->createQueryBuilder('e');
  1856.         $query->innerJoin('EADPlataforma:User''u''WITH''u.id = e.user');
  1857.         if($active){
  1858.             $query->andWhere('e.datePeriod >= :now');
  1859.             $query->setParameter('now'date('Y-m-d H:i:s'));
  1860.             $query->andWhere('e.status = :status');
  1861.             $query->setParameter('status'EnrollmentEnum::STATUS_ACTIVE);
  1862.         }
  1863.         if(!empty($user)){
  1864.             $query->andWhere('e.user = :user');
  1865.             $query->setParameter('user'$user);
  1866.         }
  1867.         if(!empty($groupId)){
  1868.             $query->innerJoin(
  1869.                 'EADPlataforma:Group''g''WITH'
  1870.                 'e.course MEMBER OF g.course AND e.user MEMBER OF g.user'
  1871.             );
  1872.             $query->andWhere('g.id = :groupId');
  1873.             $query->setParameter('groupId'$groupId);
  1874.         }
  1875.         if(!is_null($dateStart) && !is_null($dateEnd)){
  1876.             $query->andWhere('DATE(e.dateLastAccess) BETWEEN :dateStart AND :dateEnd');
  1877.             $query->setParameter('dateStart'$dateStart);
  1878.             $query->setParameter('dateEnd'$dateEnd);
  1879.         }
  1880.         $query->andWhere('u.status != :userStatus');
  1881.         $query->setParameter('userStatus'UserEnum::INACTIVE);
  1882.         
  1883.         $query->andWhere('e.deleted = 0');
  1884.         $query->andWhere('u.deleted = 0');
  1885.         $query->andWhere('u.id > 1');
  1886.         $query->andWhere('e.course = :course');
  1887.         $query->setParameter('course'$course->getId());
  1888.         return $query->getQuery()->execute();
  1889.     }
  1890.     public function restore(Enrollment $enrollment$typeItem)
  1891.     {
  1892.         $itemId $enrollment->getId();
  1893.         $dateNow date('Y-m-d H:i:s');
  1894.         $enrollment->setUserDelete($this->getUser());
  1895.         $enrollment->setDateDelete(date('Y-m-d H:i:s'));
  1896.         $enrollment->restore();
  1897.         $this->em->getRepository(Trash::class)->deleteTrash($itemId$typeItem);
  1898.         
  1899.         $examUserRepository $this->em->getRepository(ExamUser::class);
  1900.             $examUsers $examUserRepository->findBy([
  1901.                 "course" => $enrollment->getCourse()->getId(),
  1902.                 "user" => $enrollment->getUser()->getId(),
  1903.                 "deleted" => ExamUserEnum::ITEM_ON_TRASH
  1904.             ]);
  1905.             foreach ($examUsers as $examUser) {
  1906.                 $this->em->getRepository(ExamUser::class)->restoreByExamUser(
  1907.                     $examUser->getId(),
  1908.                     EnrollmentEnum::ITEM_NO_DELETED,
  1909.                     EnrollmentEnum::CASCADE
  1910.                     $this->getUser() ?? null
  1911.                     $dateNow
  1912.                 );           
  1913.             }
  1914.     }
  1915.     public function delete(Enrollment $enrollment$typeItem$permission$isTrash)
  1916.     {
  1917.         $userPermissionUtil $this->generalService->getUtil('UserPermissionUtil');
  1918.         if($isTrash == 1){
  1919.             $permission $userPermissionUtil->getPermission("trash""delete");
  1920.         }
  1921.         $isInTeam false;
  1922.         $course $enrollment->getCourse();
  1923.         $dateNow date('Y-m-d H:i:s');
  1924.         if($this->getUser()){
  1925.             $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  1926.                 $course
  1927.                 $this->getUser()
  1928.             );
  1929.         }
  1930.         
  1931.         if($isInTeam || $userPermissionUtil->isHigh($permission)){
  1932.             $enrollment->setUserDelete($this->getUser());
  1933.             $enrollment->setDateDelete(date('Y-m-d H:i:s'));
  1934.             $enrollment->individual();
  1935.             if($enrollment->isOnTrash() || $enrollment->isDeleted()){
  1936.                 $enrollment->delete();
  1937.                 $itemId $enrollment->getId();
  1938.                 $this->em->getRepository(Trash::class)->deleteTrash($itemId$typeItem);
  1939.             }
  1940.             if(!$enrollment->isOnTrash() && !$enrollment->isDeleted()){
  1941.                 $enrollment->trash();
  1942.                 $this->em->getRepository(Trash::class)->insertTrash(
  1943.                     $enrollment
  1944.                     $typeItem
  1945.                     "Aluno: {$enrollment->getUser()->getName()} | Curso: {$enrollment->getCourse()->getTitle()}"
  1946.                 );
  1947.             }
  1948.             $examUserRepository $this->em->getRepository(ExamUser::class);
  1949.             $examUsers $examUserRepository->findBy([
  1950.                 "course" => $enrollment->getCourse()->getId(),
  1951.                 "user" => $enrollment->getUser()->getId(),
  1952.                 "deleted" => ExamUserEnum::ITEM_NO_DELETED
  1953.             ]);
  1954.             foreach ($examUsers as $examUser) {              
  1955.                 $this->em->getRepository(ExamUser::class)->deleteByExamUser(
  1956.                     $examUser->getId(),
  1957.                     EnrollmentEnum::ITEM_ON_TRASH
  1958.                     EnrollmentEnum::CASCADE
  1959.                     ($this->getUser() ? $this->getUser()->getId() : null),
  1960.                     $dateNow
  1961.                 );           
  1962.             }
  1963.         }
  1964.         $this->em->flush();
  1965.     }
  1966.     public function restoreByUser($userId$deleted$typeDelete$userDelete$dateNow){
  1967.         $sql "UPDATE EADPlataforma:Enrollment AS e 
  1968.                 SET e.deleted = :deleted, e.userDelete = :userDelete, 
  1969.                     e.dateDelete = :dateNow
  1970.                 WHERE e.deleted = (1 - :deleted)
  1971.                 AND e.typeDelete = :typeDelete
  1972.                 AND e.user = :userId";
  1973.         $query $this->em->createQuery($sql);
  1974.         $query->setParameter('userId'$userId);
  1975.         $query->setParameter('deleted'$deleted);
  1976.         $query->setParameter('typeDelete'$typeDelete);
  1977.         $query->setParameter('userDelete'$userDelete);
  1978.         $query->setParameter('dateNow'$dateNow);
  1979.         $query->execute();
  1980.         
  1981.         return true;
  1982.     }
  1983.     public function deleteByUser($userId$deleted$typeDelete$userDelete$dateNow){
  1984.         $sql "UPDATE EADPlataforma:Enrollment AS e 
  1985.                 SET e.deleted = :deleted, e.typeDelete = :typeDelete,
  1986.                     e.userDelete = :userDelete, e.dateDelete = :dateNow
  1987.                 WHERE e.deleted = (:deleted - 1)
  1988.                 AND e.user = :userId";
  1989.         $query $this->em->createQuery($sql);
  1990.         $query->setParameter('userId'$userId);
  1991.         $query->setParameter('deleted'$deleted);
  1992.         $query->setParameter('typeDelete'$typeDelete);
  1993.         $query->setParameter('userDelete'$userDelete);
  1994.         $query->setParameter('dateNow'$dateNow);
  1995.         $query->execute();
  1996.         
  1997.         return true;
  1998.     }
  1999.     public function restoreByCourse($courseId$deleted$typeDelete$userDelete$dateNow){
  2000.         $sql "UPDATE EADPlataforma:Enrollment AS e 
  2001.                 SET e.deleted = :deleted, e.userDelete = :userDelete, 
  2002.                     e.dateDelete = :dateNow
  2003.                 WHERE e.deleted = (1 - :deleted)
  2004.                 AND e.typeDelete = :typeDelete
  2005.                 AND e.course = :courseId";
  2006.         $query $this->em->createQuery($sql);
  2007.         $query->setParameter('courseId'$courseId);
  2008.         $query->setParameter('deleted'$deleted);
  2009.         $query->setParameter('typeDelete'$typeDelete);
  2010.         $query->setParameter('userDelete'$userDelete);
  2011.         $query->setParameter('dateNow'$dateNow);
  2012.         $query->execute();
  2013.         
  2014.         return true;
  2015.     }
  2016.     public function deleteByCourse($courseId$deleted$typeDelete$userDelete$dateNow){
  2017.         $sql "UPDATE EADPlataforma:Enrollment AS e 
  2018.                 SET e.deleted = :deleted, e.typeDelete = :typeDelete,
  2019.                     e.userDelete = :userDelete, e.dateDelete = :dateNow
  2020.                 WHERE e.deleted = (:deleted - 1)
  2021.                 AND e.course = :courseId";
  2022.         $query $this->em->createQuery($sql);
  2023.         $query->setParameter('courseId'$courseId);
  2024.         $query->setParameter('deleted'$deleted);
  2025.         $query->setParameter('typeDelete'$typeDelete);
  2026.         $query->setParameter('userDelete'$userDelete);
  2027.         $query->setParameter('dateNow'$dateNow);
  2028.         $query->execute();
  2029.         
  2030.         return true;
  2031.     }
  2032.     public function deleteTrashCron()
  2033.     {
  2034.         $sql "UPDATE EADPlataforma:Enrollment AS e SET e.deleted = 2 
  2035.                 WHERE e.dateDelete <= :date AND e.deleted = 1 ";
  2036.         $query $this->em->createQuery($sql);
  2037.         $query->setParameter('date'date('Y-m-d H:i:s'strtotime('-90 days')));
  2038.         $query->execute();
  2039.     }
  2040.     public function bulkUpdateStatus(array $enrollmentsint $status): array
  2041.     {
  2042.         foreach ($enrollments as $enrollment) {
  2043.             $enrollment->setStatus($status);
  2044.         }
  2045.         $this->em->flush();
  2046.         return $enrollments;
  2047.     }
  2048.     public function updateEnrollmentsWithGroup(array $enrollments, array $data)
  2049.     {
  2050.         $dates $this->verifyDate($data);
  2051.         foreach ($enrollments as $enrollment) {
  2052.             $enrollment->setDatePeriod($dates['dateAccessConclusion']);
  2053.             $enrollment->setDateSupport($dates['dateSupportConclusion']);
  2054.         }
  2055.         $this->em->flush();
  2056.         return $enrollments;
  2057.     }
  2058.     public function verifyDate($data)
  2059.     {
  2060.         $dates = [];
  2061.         if($data["typeDateAccess"] == GroupEnum::TYPE_DATE_FIXED){
  2062.             $dateAccessConclusion $data["dateAccessConclusion"];
  2063.         }
  2064.         if($data["typeDateSupport"] == GroupEnum::TYPE_DATE_FIXED){
  2065.             $dateSupportConclusion $data["dateSupportConclusion"];
  2066.         }
  2067.         if($data["typeDateAccess"] == GroupEnum::TYPE_DATE_PERIOD){
  2068.             $period $data["dateAccessDays"];
  2069.             $dateNow date('Y-m-d H:i:s');
  2070.             $dateSupportConclusion date('Y-m-d H:i:s'strtotime("{$dateNow} + {$period} days"));
  2071.         }
  2072.         if($data["typeDateSupport"] == GroupEnum::TYPE_DATE_PERIOD){
  2073.             $period $data["dateSupportDays"];
  2074.             $dateNow date('Y-m-d H:i:s');
  2075.             $dateSupportConclusion date('Y-m-d H:i:s'strtotime("{$dateNow} + {$period} days"));           
  2076.         }
  2077.         $dates = [
  2078.             "dateAccessConclusion"  => $dateAccessConclusion,
  2079.             "dateSupportConclusion" => $dateSupportConclusion,
  2080.         ];
  2081.         return $dates;
  2082.     }
  2083.     public function getSituation(int $progress, ?float $certificateAverage, ?float $finalAverage)
  2084.     {
  2085.         $situation EnrollmentEnum::SITUATION_NOT_STARTED;
  2086.         if($progress >= 100){
  2087.             $situation EnrollmentEnum::SITUATION_COMPLETED;
  2088.         }else if($progress 0){
  2089.             $situation EnrollmentEnum::SITUATION_STARTED;
  2090.         }
  2091.         if(!empty($finalAverage) && $situation == EnrollmentEnum::SITUATION_COMPLETED){
  2092.             if($finalAverage >= $certificateAverage){
  2093.                 return $this->configuration->getLanguage('approved''enrollments');
  2094.             }else{
  2095.                 return $this->configuration->getLanguage('disapproved''enrollments');
  2096.             }
  2097.         }
  2098.         $situationLabels = [
  2099.             EnrollmentEnum::SITUATION_NOT_STARTED => "not_started",
  2100.             EnrollmentEnum::SITUATION_STARTED => "in_progress",
  2101.             EnrollmentEnum::SITUATION_COMPLETED => "completed",
  2102.         ];
  2103.         $index $situationLabels[$situation];
  2104.         return $this->configuration->getLanguage($index'enrollments');
  2105.     }
  2106. }