src/Repository/ExamRepository.php line 1310

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Repository;
  3. use EADPlataforma\Entity\Exam;
  4. use EADPlataforma\Entity\ExamUser;
  5. use EADPlataforma\Entity\ExamUserAnswer;
  6. use EADPlataforma\Entity\Course;
  7. use EADPlataforma\Entity\Product;
  8. use EADPlataforma\Entity\LessonModule;
  9. use EADPlataforma\Entity\Lesson;
  10. use EADPlataforma\Entity\LessonLog;
  11. use EADPlataforma\Entity\LessonLogOrigin;
  12. use EADPlataforma\Entity\Enrollment;
  13. use EADPlataforma\Entity\Question;
  14. use EADPlataforma\Entity\QuestionOption;
  15. use EADPlataforma\Entity\CourseCertificate;
  16. use EADPlataforma\Entity\User;
  17. use EADPlataforma\Entity\Trash;
  18. use EADPlataforma\Enum\ExamEnum;
  19. use EADPlataforma\Enum\ExamUserEnum;
  20. use EADPlataforma\Enum\LessonEnum;
  21. use EADPlataforma\Enum\LessonModuleEnum;
  22. use EADPlataforma\Enum\QuestionEnum;
  23. use EADPlataforma\Enum\TaskQueueEnum;
  24. use EADPlataforma\Enum\UserEnum;
  25. use EADPlataforma\Enum\EnrollmentEnum;
  26. use EADPlataforma\Enum\CourseEnum;
  27. /**
  28.  * @method Exam|null find($id, $lockMode = null, $lockVersion = null)
  29.  * @method Exam|null findOneBy(array $criteria, array $orderBy = null)
  30.  * @method Exam[]    findAll()
  31.  * @method Exam[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  32.  */
  33. class ExamRepository extends AbstractRepository
  34. {
  35.     public function getEntityClass(){
  36.         return Exam::class;
  37.     }
  38.     public function getConnectionName(){
  39.         return "school";
  40.     }
  41.     public function findItems()
  42.     {
  43.         return $this->createQueryBuilder('e')->getQuery()->getResult();
  44.     }
  45.     public function insertExam(
  46.         array $data
  47.         int $type
  48.         Course $course
  49.         ?LessonModule $lessonModule null
  50.         ?Lesson $lesson null
  51.     ): ?Exam
  52.     {
  53.         $exam = new Exam;
  54.         
  55.         $title $data['title'] ?? null;
  56.         $status $data['status'] ?? ExamEnum::DRAFT;
  57.         $requirement $data['requirement'] ?? ExamEnum::NO;
  58.         $questionOrder $data['questionOrder'] ?? ExamEnum::SEQUENTIAL;
  59.         $questionNumber $data['questionNumber'] ?? null;
  60.         $examAverage $data['examAverage'] ?? ExamEnum::DEFAULT_AVERAGE;
  61.         $examWeight $data['examWeight'] ?? ExamEnum::NO;
  62.         $typeRelease $data['typeRelease'] ?? ExamEnum::RELEASED;
  63.         $controlTime $data['controlTime'] ?? ExamEnum::NO;
  64.         $periodStart $data['periodStart'] ?? ExamEnum::NO;
  65.         $periodEnd $data['periodEnd'] ?? ExamEnum::NO;
  66.         $dateStart $data['dateStart'] ?? null;
  67.         $examTime $data['examTime'] ?? null;
  68.         $attempts $data['attempts'] ?? ExamEnum::NO;
  69.         $attemptsNumber $data['attemptsNumber'] ?? ExamEnum::YES;
  70.         $attemptsAutoRelease $data['attemptsAutoRelease'] ?? ExamEnum::YES;
  71.         $attemptsTypeRelease $data['attemptsTypeRelease'] ?? ExamEnum::DAYS;
  72.         $attemptsTime $data['attemptsTime'] ?? null;
  73.         $attemptsPeriod $data['attemptsPeriod'] ?? null;
  74.         $showTemplate $data['showTemplate'] ?? ExamEnum::NO;
  75.         $note $data['note'] ?? null;
  76.         $questions $data['question'] ?? null;
  77.         $notify $data['notify'] ?? ExamEnum::NO;
  78.         if($questionOrder == ExamEnum::SEQUENTIAL){
  79.             $questionNumber count($questions);
  80.         }
  81.         $exam->setTitle($title);
  82.         $exam->setStatus($status);
  83.         $exam->setRequirement($requirement);
  84.         $exam->setQuestionOrder($questionOrder);
  85.         $exam->setQuestionNumber($questionNumber);
  86.         $exam->setExamAverage($examAverage);
  87.         $exam->setExamWeight($examWeight);
  88.         $exam->setTypeRelease($typeRelease);
  89.         $exam->setControlTime($controlTime);
  90.         $exam->setPeriodStart($periodStart);
  91.         $exam->setPeriodEnd($periodEnd);
  92.         $exam->setDateStart($dateStart);
  93.         $exam->setExamTime($examTime);
  94.         $exam->setAttempts($attempts);
  95.         $exam->setAttemptsNumber($attemptsNumber);
  96.         $exam->setAttemptsAutoRelease($attemptsAutoRelease);
  97.         $exam->setAttemptsTypeRelease($attemptsTypeRelease);
  98.         $exam->setAttemptsTime($attemptsTime);
  99.         $exam->setAttemptsPeriod($attemptsPeriod);
  100.         $exam->setShowTemplate($showTemplate);
  101.         $exam->setNote($note);
  102.         if(!empty($questions) && is_array($questions)){
  103.             $questionRepository $this->em->getRepository(Question::class);
  104.             foreach ($questions as $key => $questionId) {
  105.                 $question $questionRepository->findOneBy([
  106.                     "id" => $questionId,
  107.                     "deleted" => ExamEnum::ITEM_NO_DELETED
  108.                 ]);
  109.                 if($question){
  110.                     $exam->addQuestion($question);
  111.                 }
  112.             }
  113.         }
  114.         $exam->setType($type);
  115.         $exam->setCourse($course);
  116.         $exam->setLessonModule($lessonModule);
  117.         $exam->setLesson($lesson);
  118.         $course->setDateUpdate(date('Y-m-d H:i:s'));
  119.         try {
  120.             $this->em->persist($exam);
  121.             $this->em->flush();
  122.         } catch (\Exception $e) {
  123.             return null;
  124.         }
  125.         if($notify == ExamEnum::YES){
  126.             $this->notifyStudentsExam($exam);
  127.         }
  128.         $data $exam->toReturn();
  129.         $this->getLogService()->logInsert("exam"$exam->getId(), $data);
  130.         return $exam;
  131.     }
  132.     public function editExam(
  133.         Exam $exam,
  134.         array $data
  135.     ): ?Exam
  136.     {
  137.         $title $data['title'] ?? null;
  138.         $status $data['status'] ?? ExamEnum::DRAFT;
  139.         $requirement $data['requirement'] ?? ExamEnum::NO;
  140.         $questionOrder $data['questionOrder'] ?? ExamEnum::SEQUENTIAL;
  141.         $questionNumber $data['questionNumber'] ?? null;
  142.         $examAverage $data['examAverage'] ?? ExamEnum::DEFAULT_AVERAGE;
  143.         $examWeight $data['examWeight'] ?? ExamEnum::NO;
  144.         $typeRelease $data['typeRelease'] ?? ExamEnum::RELEASED;
  145.         $controlTime $data['controlTime'] ?? ExamEnum::NO;
  146.         $periodStart $data['periodStart'] ?? ExamEnum::NO;
  147.         $periodEnd $data['periodEnd'] ?? ExamEnum::NO;
  148.         $dateStart $data['dateStart'] ?? null;
  149.         $examTime $data['examTime'] ?? null;
  150.         $attempts $data['attempts'] ?? ExamEnum::NO;
  151.         $attemptsNumber $data['attemptsNumber'] ?? ExamEnum::YES;
  152.         $attemptsAutoRelease $data['attemptsAutoRelease'] ?? ExamEnum::YES;
  153.         $attemptsTypeRelease $data['attemptsTypeRelease'] ?? ExamEnum::DAYS;
  154.         $attemptsTime $data['attemptsTime'] ?? null;
  155.         $attemptsPeriod $data['attemptsPeriod'] ?? null;
  156.         $showTemplate $data['showTemplate'] ?? ExamEnum::NO;
  157.         $note $data['note'] ?? null;
  158.         $questions $data['question'] ?? null;
  159.         $notify $data['notify'] ?? ExamEnum::NO;
  160.         
  161.         if($questionOrder == ExamEnum::SEQUENTIAL){
  162.             $questionNumber count($questions);
  163.         }
  164.         $exam->setTitle($title);
  165.         $exam->setStatus($status);
  166.         $exam->setRequirement($requirement);
  167.         $exam->setQuestionOrder($questionOrder);
  168.         $exam->setQuestionNumber($questionNumber);
  169.         $exam->setExamAverage($examAverage);
  170.         $exam->setExamWeight($examWeight);
  171.         $exam->setTypeRelease($typeRelease);
  172.         $exam->setControlTime($controlTime);
  173.         $exam->setPeriodStart($periodStart);
  174.         $exam->setPeriodEnd($periodEnd);
  175.         $exam->setDateStart($dateStart);
  176.         $exam->setExamTime($examTime);
  177.         $exam->setAttempts($attempts);
  178.         $exam->setAttemptsNumber($attemptsNumber);
  179.         $exam->setAttemptsAutoRelease($attemptsAutoRelease);
  180.         $exam->setAttemptsTypeRelease($attemptsTypeRelease);
  181.         $exam->setAttemptsTime($attemptsTime);
  182.         $exam->setAttemptsPeriod($attemptsPeriod);
  183.         $exam->setShowTemplate($showTemplate);
  184.         $exam->setNote($note);
  185.         if(!empty($questions) && is_array($questions)){
  186.             $questionRepository $this->em->getRepository(Question::class);
  187.             foreach ($questions as $key => $questionId) {
  188.                 $question $questionRepository->findOneBy([
  189.                     "id" => $questionId,
  190.                     "deleted" => ExamEnum::ITEM_NO_DELETED
  191.                 ]);
  192.                 if($question){
  193.                     $exam->addQuestion($question);
  194.                 }
  195.             }
  196.         }
  197.         $course $exam->getCourse();
  198.         $course->setDateUpdate(date('Y-m-d H:i:s'));
  199.         try {
  200.             $this->em->flush();
  201.         } catch (\Exception $e) {
  202.             return null;
  203.         }
  204.         if($notify == ExamEnum::YES){
  205.             $this->notifyStudentsExam($exam);
  206.         }
  207.         $data $exam->toReturn();
  208.         $this->getLogService()->logUpdate("exam"$exam->getId(), $data);
  209.         return $exam;
  210.     }
  211.     public function getExamTypeText($type)
  212.     {
  213.         $examTypeText '';
  214.         switch ($type) {
  215.             case ExamEnum::LESSON:
  216.                 $examTypeText $this->configuration->getLanguage('lesson''export');
  217.                 break;
  218.             case ExamEnum::MODULE:
  219.                 $examTypeText $this->configuration->getLanguage('module''export');
  220.                 break;
  221.             case ExamEnum::COURSE:
  222.                 $examTypeText $this->configuration->getLanguage('course''export');
  223.                 break;
  224.         }
  225.         return $examTypeText;
  226.     }
  227.     public function notifyStudentsExam(Exam $exam)
  228.     {   
  229.         $today date('Y-m-d');
  230.         $dateLastNotify $exam->getDateLastNotify('Y-m-d');
  231.         if($today != $dateLastNotify){
  232.             $course $exam->getCourse();
  233.             $lessonModule $exam->getLessonModule();
  234.             $lesson $exam->getLesson();
  235.             if(
  236.                 $course->getStatus() == CourseEnum::PUBLISHED && 
  237.                 $exam->getStatus() == ExamEnum::PUBLISHED
  238.             ){
  239.                 $taskQueueService $this->generalService->getService('TaskQueueService');
  240.                 $enrollmentRepository $this->em->getRepository(Enrollment::class);
  241.                 
  242.                 $users $this->getUsersNotStartExam($exam);
  243.                 foreach ($users as $key => $user) {
  244.                     if($user->getAllowNotifyNewExam() == ExamEnum::YES){
  245.                         $taskQueueService->insert(TaskQueueEnum::EMAIL_NEW_EXAM$user$exam->getId());
  246.                     }
  247.                 }
  248.                 $exam->setDateLastNotify(date('Y-m-d H:i:s'));
  249.                 $this->em->flush();
  250.             }
  251.         }
  252.     }
  253.     public function getUsersNotStartExam(Exam $exam)
  254.     {
  255.         $userRepository $this->em->getRepository(User::class);
  256.         $query $userRepository->createQueryBuilder('u');
  257.         $query->innerJoin('EADPlataforma:Enrollment''e''WITH''e.user = u.id');
  258.         $query->andWhere('u.deleted = :deleted');
  259.         $query->andWhere('e.course = :course');
  260.         $query->andWhere('e.status = :enrollmentStatus');
  261.         $query->andWhere('e.deleted = :enrollmentDeleted');
  262.         $query->andWhere('e.datePeriod >= :now');
  263.         $subQuery $userRepository->createQueryBuilder('examUser');
  264.         $subQuery->select('IDENTITY(eu.user)');
  265.         $subQuery->from('EADPlataforma:ExamUser''eu');
  266.         $subQuery->andWhere('eu.exam = :exam');
  267.         $subQuery->andWhere('eu.course = :course');
  268.         $subQuery $subQuery->getDQL();
  269.         $query->andWhere($query->expr()->notIn('u.id'$subQuery));
  270.         $subQuery $userRepository->createQueryBuilder('certificate');
  271.         $subQuery->select('IDENTITY(cc.user)');
  272.         $subQuery->from('EADPlataforma:CourseCertificate''cc');
  273.         $subQuery->andWhere('cc.course = :course');
  274.         $subQuery $subQuery->getDQL();
  275.         $query->andWhere($query->expr()->notIn('u.id'$subQuery));
  276.         $query->setParameter('deleted'UserEnum::ITEM_NO_DELETED);
  277.         $query->setParameter('course'$exam->getCourse()->getId());
  278.         $query->setParameter('enrollmentStatus'EnrollmentEnum::STATUS_ACTIVE);
  279.         $query->setParameter('enrollmentDeleted'EnrollmentEnum::ITEM_NO_DELETED);
  280.         $query->setParameter('now'date('Y-m-d H:i:s'));
  281.         $query->setParameter('exam'$exam->getId());
  282.         return $query->getQuery()->execute();
  283.     }
  284.     
  285.     public function isExamTeacher(Exam $examUser $user)
  286.     {
  287.         $lesson $exam->getLesson();
  288.         $lessonModule $exam->getLessonModule();
  289.         $course $exam->getCourse();
  290.         
  291.         return $this->allowUserExam($course$lessonModule$lesson$user);
  292.     }
  293.     public function allowUserExam(
  294.         ?Course $course null
  295.         ?LessonModule $lessonModule null
  296.         ?Lesson $lesson null,
  297.         User $user
  298.     ): bool
  299.     {
  300.         if(!$course){
  301.             return false;
  302.         }
  303.         $uId $user->getId();
  304.         if(($course->getUser()->getId() == $uId)){
  305.             return true;
  306.         }
  307.         if($lessonModule){
  308.             $lessonModuleTeahcerId $lessonModule->getUser()->getId();
  309.             return ($lessonModuleTeahcerId == $uId);
  310.         }else if($lesson){
  311.             $lessonTeahcerId $lesson->getUser()->getId();
  312.             $lessonModuleTeahcerId $lesson->getLessonModule()->getUser()->getId();
  313.             return ($lessonTeahcerId == $uId || $lessonModuleTeahcerId == $uId);
  314.         } 
  315.         return false;
  316.     }
  317.     public function getExamToIndexNew(
  318.         ?bool $isStudent true,
  319.         int $typeCourse $course,
  320.         ?LessonModule $lessonModule null
  321.         ?Lesson $lesson null
  322.     )
  323.     {
  324.         $filter = [
  325.             "course" => $course->getId(),
  326.             "type" => $type,
  327.             "deleted" => ExamEnum::ITEM_NO_DELETED
  328.         ];
  329.         if($isStudent){
  330.             $filter["status"] = ExamEnum::PUBLISHED;
  331.         }
  332.         if(!empty($lessonModule)){
  333.             $filter["lessonModule"] = $lessonModule->getId();
  334.         }
  335.         if(!empty($lesson)){
  336.             $filter["lesson"] = $lesson->getId();
  337.         }
  338.         $e $this->findOneBy($filter);
  339.         $examUser null;
  340.         if($e && !empty($e->getQuestionNumber())){
  341.             $examUserData null;
  342.             if($this->getUser()){
  343.                 $examUserRepository $this->em->getRepository(ExamUser::class);
  344.                 $examUser $examUserRepository->findOneBy([
  345.                     "user" => $this->getUser()->getId(),
  346.                     "exam" => $e->getId(),
  347.                     "inactive" => ExamUserEnum::NO,
  348.                     "deleted" => ExamUserEnum::ITEM_NO_DELETED
  349.                 ]);
  350.             }
  351.             $infoAccess $this->checkExamIsAccessible($e$examUser);
  352.             $data = [
  353.                 "id" => $e->getId(),
  354.                 "title" => $e->getTitle(),
  355.                 "type" => $e->getType(),
  356.                 "status" => (
  357.                     $examUser 
  358.                     $examUser->getStatus() : 
  359.                     ExamUserEnum::NOT_STARTED
  360.                 ),
  361.                 "examStatus" => $e->getStatus(),
  362.                 "examWeight" => $e->getExamWeight(),
  363.                 "examTime" => $e->getExamTime(),
  364.                 "questionNumber" => $e->getQuestionNumber(),
  365.                 "isAccessible" => $infoAccess->isAccessible,
  366.                 "acessMessage" => $infoAccess->message,
  367.                 "dateReleaseAccess" => $infoAccess->dateRelease,
  368.                 "dateCloseAccess" => $infoAccess->dateClose,
  369.             ];
  370.             return $data;
  371.         }
  372.         return;
  373.     }
  374.     public function getExamToIndex(
  375.         int $typeCourse $course
  376.         ?LessonModule $lessonModule null
  377.         ?Lesson $lesson null
  378.     )
  379.     {
  380.         $filter = [
  381.             "course" => $course->getId(),
  382.             "type" => $type,
  383.             "status" => ExamEnum::PUBLISHED,
  384.             "deleted" => ExamEnum::ITEM_NO_DELETED
  385.         ];
  386.         if(!empty($lessonModule)){
  387.             $filter["lessonModule"] = $lessonModule->getId();
  388.         }
  389.         if(!empty($lesson)){
  390.             $filter["lesson"] = $lesson->getId();
  391.         }
  392.         $e $this->findOneBy($filter);
  393.         $examUser null;
  394.         if($e && !empty($e->getQuestionNumber())){
  395.             $examUserData null;
  396.             if($this->getUser()){
  397.                 $examUserRepository $this->em->getRepository(ExamUser::class);
  398.                 $examUser $examUserRepository->findOneBy([
  399.                     "user" => $this->getUser()->getId(),
  400.                     "exam" => $e->getId(),
  401.                     "inactive" => ExamUserEnum::NO,
  402.                     "deleted" => ExamUserEnum::ITEM_NO_DELETED
  403.                 ]);
  404.                 if($examUser){
  405.                     $dateTimeUtil $this->generalService->getUtil('DateTimeUtil');
  406.                     $todaySeconds strtotime(date('Y-m-d H:i:s'));
  407.                     $dateStartSeconds strtotime($examUser->getDateStart());
  408.                     $timeSeconds $dateTimeUtil->timeToSec($e->getExamTime());
  409.                     $dateExamEndSecods $dateStartSeconds $timeSeconds;
  410.                     $timeRestToEndSeconds $timeSeconds;
  411.                     if($examUser->getStatus() == ExamUserEnum::IN_PROGRESS){
  412.                         $timeRestToEndSeconds $dateExamEndSecods $todaySeconds;
  413.                         if($timeRestToEndSeconds 0){
  414.                             $timeRestToEndSeconds 0;
  415.                         }
  416.                     }
  417.                     $progress 100;
  418.                     $qNumber $e->getQuestionNumber();
  419.                     
  420.                     if(
  421.                         $examUser->getStatus() == ExamUserEnum::IN_PROGRESS || 
  422.                         $examUser->getStatus() == ExamUserEnum::TIMEOUT
  423.                     ){
  424.                         $euAnswerRepository $this->em->getRepository(ExamUserAnswer::class);
  425.                         $qNumber $euAnswerRepository->countAsnweredByExamUser(
  426.                             $examUser
  427.                         );
  428.                         $progress round($qNumber 100 $e->getQuestionNumber());
  429.                     }
  430.                     $examUserData = (object)[
  431.                         "id" => $examUser->getId(),
  432.                         "status" => $examUser->getStatus(),
  433.                         "grade" => $examUser->getGrade(),
  434.                         "timeRestToEnd" => $dateTimeUtil->secToTime($timeRestToEndSeconds),
  435.                         "timeRestToEndSeconds" => $timeRestToEndSeconds,
  436.                         "dateStart" => $examUser->getDateStart('Y-m-d H:i:s'),
  437.                         "questionAnswerNumber" => $qNumber,
  438.                         "progress" => $progress
  439.                     ];
  440.                 }
  441.             }
  442.             $infoAccess $this->checkExamIsAccessible($e$examUser);
  443.             $data = [
  444.                 "id" => $e->getId(),
  445.                 "courseId" => $e->getCourse()->getId(),
  446.                 "lessonModuleId" => (
  447.                     $e->getLessonModule() ? $e->getLessonModule()->getId() : null
  448.                 ),
  449.                 "lessonId" => ($e->getLesson() ? $e->getLesson()->getId() : null),
  450.                 "title" => $e->getTitle(),
  451.                 "type" => $e->getType(),
  452.                 "examWeight" => $e->getExamWeight(),
  453.                 "examTime" => $e->getExamTime(),
  454.                 "questionNumber" => $e->getQuestionNumber(),
  455.                 "isAccessible" => $infoAccess->isAccessible,
  456.                 "dateReleaseAccess" => $infoAccess->dateRelease,
  457.                 "dateCloseAccess" => $infoAccess->dateClose,
  458.                 "examUser" => $examUserData,
  459.             ];
  460.             return $data;
  461.         }
  462.         return;
  463.     }
  464.     public function getExamByQuestions(Question $question)
  465.     {
  466.         $questionId $question->getId();
  467.         $query $this->createQueryBuilder('e');
  468.         $query->innerJoin(
  469.             'EADPlataforma:Question'
  470.             'q'
  471.             'WITH'
  472.             'e MEMBER OF q.exam AND q.id = :questionId'
  473.         );
  474.         $query->setParameter('questionId'$questionId);
  475.         $query->andWhere('e.deleted = :deleted');
  476.         $query->setParameter('deleted'ExamEnum::ITEM_NO_DELETED);
  477.         return $query->getQuery()->execute();
  478.     }
  479.     public function counterExamAndQuiz(Question $question){
  480.         $quantityQuiz 0;
  481.         $examIds $question->toReturn()["exam"];
  482.         $quantityExam count($question->toReturn()["exam"]);
  483.         $exams $this->findBy([
  484.             "id" => $examIds
  485.         ]);
  486.         
  487.         foreach ($exams as $exam) {
  488.             if($exam->getType() == ExamEnum::QUIZ) {
  489.                 $quantityQuiz++;
  490.                 $quantityExam--;
  491.             }
  492.         }
  493.         $counters = [
  494.             "quantityQuiz" => $quantityQuiz,
  495.             "quantityExam" => $quantityExam
  496.         ];
  497.         return $counters;
  498.     }
  499.     public function checkExamIsAccessible(Exam $exam, ?ExamUser $examUser null){
  500.         $info = (object)[
  501.             "isAccessible" => false,
  502.             "dateRelease" => null,
  503.             "dateClose" => null,
  504.             "message" => null,
  505.         ];
  506.         $typeRelease $exam->getTypeRelease();
  507.         if($typeRelease == ExamEnum::FIXED_DATE){
  508.             $dateStart $exam->getDateStart();
  509.             $info->dateRelease $dateStart;
  510.         }
  511.         if(!$this->getUser()){
  512.             $info->message $this->configuration->getLanguage('error_auth''lesson_view_error');
  513.             return $info;
  514.         }
  515.         $lessonRepository $this->em->getRepository(Lesson::class);
  516.         $logRepository $this->em->getRepository(LessonLogOrigin::class);
  517.         $lessonLogRepository $this->emEadmin->getRepository(LessonLog::class);
  518.         $courseRepository $this->em->getRepository(Course::class);
  519.         $examUserRepository $this->em->getRepository(ExamUser::class);
  520.         if(empty($examUser)){
  521.             $examUser $examUserRepository->findOneBy([
  522.                 "user" => $this->getUser()->getId(),
  523.                 "exam" => $exam->getId(),
  524.                 "inactive" => ExamUserEnum::NO,
  525.                 "deleted" => ExamUserEnum::ITEM_NO_DELETED
  526.             ]);
  527.         }
  528.         if(!empty($examUser)){
  529.             $info->isAccessible true;
  530.             return $info;
  531.         }
  532.         $today date('Y-m-d');
  533.         $todayDateTime date('Y-m-d H:i:s');
  534.         $course $exam->getCourse();
  535.         $isStudent $courseRepository->isStudent($course);
  536.         if(!$isStudent){
  537.             $info->isAccessible true;
  538.             return $info;
  539.         }
  540.         $lesson null;
  541.         $hasLessonControl $this->configuration->checkModuleIsAbleOnPlan(
  542.             'lessonControlFunction'
  543.         );
  544.         $lessonNumber $lessonRepository->getLessonPublicNumber($course);
  545.         $lessonNumberModule $lessonNumber;
  546.         if(empty($lessonNumber)){
  547.             $info->isAccessible true;
  548.             return $info;
  549.         }
  550.         if(!$hasLessonControl && $exam->getType() != ExamEnum::QUIZ){
  551.             $lessonsNumberComplete $logRepository->count([
  552.                 "complete" => LessonEnum::YES,
  553.                 "course" => $course->getId(),
  554.                 "user" => $this->getUser()->getId()
  555.             ]);
  556.             if($lessonsNumberComplete >= $lessonNumber){
  557.                 $info->isAccessible true;
  558.                 return $info;
  559.             }
  560.         }else if($exam->getType() == ExamEnum::COURSE){
  561.             $lesson $lessonRepository->getLastLesson($course);
  562.             $lessonNumberRequired $lessonRepository->getLessonPublicNumber(
  563.                 $course
  564.                 null
  565.                 true
  566.             );
  567.             $lessonsNumberComplete $logRepository->countLessonLogOriginCompleteRequired(
  568.                 $this->getUser(), 
  569.                 $course
  570.             );
  571.             if($lessonsNumberComplete $lessonNumberRequired){
  572.                 $info->message $this->configuration->getLanguage(
  573.                     'error_required_incomplete'
  574.                     'lesson_view_error'
  575.                 );
  576.                 return $info;
  577.             }
  578.         }else if($exam->getType() == ExamEnum::MODULE){
  579.             $lesson $lessonRepository->getLastLesson($course$exam->getLessonModule());
  580.             $lessonNumberRequired $lessonRepository->getLessonPublicNumber(
  581.                 $course
  582.                 $exam->getLessonModule(), 
  583.                 true
  584.             );
  585.             $lessonNumberModule $lessonRepository->getLessonPublicNumber(
  586.                 $course
  587.                 $exam->getLessonModule(),
  588.                 false,
  589.                 true
  590.             );
  591.             $lessonsNumberComplete $logRepository->countLessonLogOriginCompleteRequired(
  592.                 $this->getUser(), 
  593.                 $course,
  594.                 $exam->getLessonModule()
  595.             );
  596.             if($lessonsNumberComplete $lessonNumberRequired){
  597.                 $info->message $this->configuration->getLanguage(
  598.                     'error_required_incomplete'
  599.                     'lesson_view_error'
  600.                 );
  601.                 return $info;
  602.             }
  603.         }else if($exam->getType() == ExamEnum::LESSON){
  604.             $lesson $exam->getLesson();
  605.         }else if($exam->getType() == ExamEnum::QUIZ){
  606.             $lesson $exam->getLesson();
  607.         }
  608.         if($lesson && $hasLessonControl){
  609.             $currentLesson $lessonRepository->getCurrentLesson($lesson$this->getUser());
  610.             
  611.             if(empty($currentLesson)){
  612.                 if(empty($examUser)){
  613.                     $currentExam $examUserRepository->getCurrentExamOnCourseToUserByLesson(
  614.                         $lesson
  615.                         $this->getUser()
  616.                     );
  617.                     
  618.                     if($currentExam && $currentExam->getId() != $exam->getId()){
  619.                         if($exam->getType() != ExamEnum::QUIZ){
  620.                             $info->message $this->configuration->getLanguage(
  621.                                 'error_required_incomplete'
  622.                                 'lesson_view_error'
  623.                             );
  624.                             return $info;
  625.                         }
  626.                     }
  627.                 }
  628.                 
  629.                 $logId "{$course->getId()}#{$this->getUser()->getId()}#{$lesson->getId()}";
  630.                 $log $lessonLogRepository->find($logId);
  631.                 if($lesson->getControlRequirement() == LessonEnum::YES){
  632.                     if(!$log || ($log && empty($log->getDateConclusion()))){
  633.                         $info->message $this->configuration->getLanguage(
  634.                             'error_required_incomplete'
  635.                             'lesson_view_error'
  636.                         );
  637.                         return $info;
  638.                     }
  639.                 }
  640.                 
  641.                 $dateReference = ($log $log->getDateConclusion() : null);
  642.                 if($typeRelease == ExamEnum::FIXED_DATE){
  643.                     $dateStart $exam->getDateStart();
  644.                     if($dateStart $todayDateTime){
  645.                         $info->dateRelease $dateStart;
  646.                         $info->message "{$this->configuration->getLanguage(
  647.                             'error_date_release'
  648.                             'lesson_view_error'
  649.                         )} {$exam->getDateStart('d/m/Y H:i:s')}";
  650.                         return $info;
  651.                     }
  652.                    
  653.                 }else if($typeRelease == ExamEnum::FLEXIBLE_PERIOD){
  654.                     if(empty($dateReference)){
  655.                         $info->message $this->configuration->getLanguage(
  656.                             'error_required_incomplete'
  657.                             'lesson_view_error'
  658.                         );
  659.                         return $info;
  660.                     }
  661.                     $textDate "{$dateReference} + {$exam->getPeriodStart()} days";
  662.                     $dateStart date('Y-m-d'strtotime($textDate));
  663.                     if($dateStart $today){
  664.                         $info->dateRelease $dateStart;
  665.                         $dateStartText date('d/m/Y H:i:s'strtotime($textDate));
  666.                         $info->message "{$this->configuration->getLanguage(
  667.                             'error_date_release'
  668.                             'lesson_view_error'
  669.                         )} {$dateStartText}";
  670.                         return $info;
  671.                     }
  672.                 }
  673.                 $periodEnd $exam->getPeriodEnd();
  674.                 if(!empty($periodEnd)){
  675.                     if($typeRelease == ExamEnum::FIXED_DATE){
  676.                         $dateReference $exam->getDateStart();
  677.                     }
  678.                     
  679.                     if(empty($dateReference) && $typeRelease != ExamEnum::RELEASED){
  680.                         $info->message $this->configuration->getLanguage(
  681.                             'error_required_incomplete'
  682.                             'lesson_view_error'
  683.                         );
  684.                         return $info;
  685.                     }
  686.                     $textDate "{$dateReference} + {$periodEnd} days";
  687.                     $dateEnd date('Y-m-d'strtotime($textDate));
  688.                     if($dateEnd $today){
  689.                         if(empty($examUser)){
  690.                             $dateEndText date('d/m/Y H:i:s'strtotime($textDate));
  691.                             $info->dateClose $dateEnd;
  692.                             $info->message "{$this->configuration->getLanguage(
  693.                                 'error_date_end'
  694.                                 'lesson_view_error'
  695.                             )} {$dateEndText}";
  696.                             return $info;
  697.                         }
  698.                     }
  699.                 }
  700.                 $info->isAccessible true;
  701.                 return $info;
  702.             }
  703.         }else if(empty($lessonNumber) || empty($lessonNumberModule) || !$hasLessonControl){
  704.             if($typeRelease == ExamEnum::FIXED_DATE){
  705.                 $dateStart $exam->getDateStart();
  706.                 if($dateStart $todayDateTime){
  707.                     $info->dateRelease $dateStart;
  708.                     $info->message "{$this->configuration->getLanguage(
  709.                         'error_date_release'
  710.                         'lesson_view_error'
  711.                     )} {$exam->getDateStart('d/m/Y H:i:s')}";
  712.                     return $info;
  713.                 }
  714.                 $info->isAccessible true;
  715.                 return $info;
  716.             }
  717.             //else if($typeRelease == ExamEnum::FLEXIBLE_PERIOD){
  718.             //}
  719.             $periodEnd $exam->getPeriodEnd();
  720.             if(!empty($periodEnd)){
  721.                 $dateReference null;
  722.                 if($typeRelease == ExamEnum::FIXED_DATE){
  723.                     $dateReference $exam->getDateStart();
  724.                 }
  725.                 
  726.                 if(empty($dateReference) && $typeRelease != ExamEnum::RELEASED){
  727.                     $info->message $this->configuration->getLanguage(
  728.                         'error_required_incomplete'
  729.                         'lesson_view_error'
  730.                     );
  731.                     return $info;
  732.                 }
  733.                 /*$textDate = "{$dateReference} + {$periodEnd} days";
  734.                 $dateEnd = date('Y-m-d', strtotime($textDate));
  735.                 if($dateEnd < $today){
  736.                     if(empty($examUser)){
  737.                         $info->dateClose = $dateEnd;
  738.                         return $info;
  739.                     }
  740.                 }*/
  741.             }
  742.             $info->isAccessible true;
  743.             
  744.             return $info;
  745.         }
  746.         return $info;
  747.     }
  748.     public function getExamNumberByProduct(Product $product)
  749.     {
  750.         $query $this->createQueryBuilder('e');
  751.         $query->select("COUNT(e.id) AS total");
  752.         $query->innerJoin('EADPlataforma:Product''p''WITH''e.course MEMBER OF p.course');
  753.         $query->andWhere('e.deleted = :deleted');
  754.         $query->andWhere('e.status = :examStatus');
  755.         $query->andWhere('p.id = :productId');
  756.         $query->setParameter('deleted'ExamEnum::ITEM_NO_DELETED);
  757.         $query->setParameter('examStatus'ExamEnum::PUBLISHED);
  758.         $query->setParameter('productId'$product->getId());
  759.               
  760.         $result = (object)$query->getQuery()->getOneOrNullResult();
  761.         return $result->total;
  762.     }
  763.     public function getNextExamIdByLesson(Lesson $lessonbool $addTitle false)
  764.     {
  765.         $lessonRepository $this->em->getRepository(Lesson::class);
  766.         $course $lesson->getCourse();
  767.         $lessonModule $lesson->getLessonModule();
  768.         $addExams false;
  769.         $addExamsLimited false;
  770.         if(
  771.             $this->configuration->isModuleActive("exam_module") &&
  772.             $this->configuration->checkModuleIsAbleOnPlan("examFunction")
  773.             
  774.         ){
  775.             $addExams true;
  776.             $addExamsLimited $this->configuration->checkModuleIsAbleOnPlan(
  777.                 "unlimitedExamFunction"
  778.             );
  779.         }
  780.         $exam $this->findOneBy([
  781.             "deleted" => ExamEnum::ITEM_NO_DELETED,
  782.             "course" => $course->getId(),
  783.             "lessonModule" => $lessonModule->getId(),
  784.             "lesson" => $lesson->getId(),
  785.             "status" => ExamEnum::PUBLISHED,
  786.             "type" => ExamEnum::QUIZ
  787.         ]);
  788.         if(!$exam){
  789.             if(!$addExams || !$addExamsLimited){
  790.                 return;
  791.             }
  792.             $exam $this->findOneBy([
  793.                 "deleted" => ExamEnum::ITEM_NO_DELETED,
  794.                 "course" => $course->getId(),
  795.                 "lessonModule" => $lessonModule->getId(),
  796.                 "lesson" => $lesson->getId(),
  797.                 "status" => ExamEnum::PUBLISHED,
  798.                 "type" => ExamEnum::LESSON
  799.             ]);
  800.         }
  801.         if(!$exam && $lessonRepository->isLastModuleLesson($lesson)){
  802.             if(!$addExams || !$addExamsLimited){
  803.                 return;
  804.             }
  805.             $exam $this->findOneBy([
  806.                 "deleted" => ExamEnum::ITEM_NO_DELETED,
  807.                 "course" => $course->getId(),
  808.                 "lessonModule" => $lessonModule->getId(),
  809.                 "status" => ExamEnum::PUBLISHED,
  810.                 "type" => ExamEnum::MODULE
  811.             ]);
  812.         }
  813.         if(!$exam && $lessonRepository->isLastCourseLesson($lesson)){
  814.             if(!$addExams){
  815.                 return;
  816.             }
  817.             $exam $this->findOneBy([
  818.                 "deleted" => ExamEnum::ITEM_NO_DELETED,
  819.                 "course" => $course->getId(),
  820.                 "status" => ExamEnum::PUBLISHED,
  821.                 "type" => ExamEnum::COURSE
  822.             ]);
  823.         }
  824.         if($exam){
  825.             if($addTitle){
  826.                 return (object)[ 
  827.                     "id" => $exam->getId(), 
  828.                     "title" => $exam->getTitle(),
  829.                     "courseId" => $exam->getCourse()->getId(),
  830.                     "moduleId" => (
  831.                         $exam->getLessonModule() ?
  832.                         $exam->getLessonModule()->getId() :
  833.                         null
  834.                     ),
  835.                     "moduleTitle" => (
  836.                         $exam->getLessonModule() ?
  837.                         $exam->getLessonModule()->getTitle() :
  838.                         null
  839.                     ),
  840.                     "lessonId" => (
  841.                         $exam->getLesson() ?
  842.                         $exam->getLesson()->getId() :
  843.                         null
  844.                     ),
  845.                     "type" => $exam->getType(),
  846.                 ];
  847.             }
  848.             return $exam->getId();
  849.         }
  850.         return;
  851.     }
  852.     public function getCurrentNotStartedExamUser(Lesson $lessonBaseUser $user){
  853.         $query $this->createQueryBuilder('e');
  854.         $query->leftJoin(
  855.             'EADPlataforma:LessonModule'
  856.             'lm'
  857.             'WITH'
  858.             'lm.id = e.lessonModule'
  859.         );
  860.         $query->leftJoin(
  861.             'EADPlataforma:Lesson'
  862.             'l'
  863.             'WITH'
  864.             'l.id = e.lesson'
  865.         );
  866.         $query->andWhere('e.course = :course');
  867.         $query->andWhere('e.requirement = :yes');
  868.         $query->andWhere('e.status = :statusExam');
  869.         $query->andWhere('(
  870.             (
  871.                 e.type = :typeLesson 
  872.                 AND l.deleted = :lDeleted 
  873.                 AND l.status = :lStatus
  874.                 AND lm.status = :lmStatus
  875.             ) OR 
  876.             (
  877.                 e.type = :typeModule 
  878.                 AND lm.deleted = :lmDeleted 
  879.                 AND lm.status = :lmStatus
  880.             )
  881.         )');
  882.         $query->andWhere('(
  883.             ( l.order <= :orderL AND lm.order = :orderLM ) OR 
  884.             ( lm.order < :orderLM )
  885.         )');
  886.         $query->andWhere('e.deleted = :deleted');
  887.         $course $lessonBase->getCourse();
  888.         $lessonModule $lessonBase->getLessonModule();
  889.         $subQuery $this->createQueryBuilder('examUser');
  890.         $subQuery->select('IDENTITY(eu.exam)');
  891.         $subQuery->from('EADPlataforma:ExamUser''eu');
  892.         $subQuery->andWhere('eu.course = :course');
  893.         $subQuery->andWhere('eu.deleted = :deletedExamUser');
  894.         $subQuery->andWhere('eu.status = :statusAproved OR eu.releaseAccess = :yes');
  895.         $subQuery->andWhere('eu.user = :user');
  896.         $subQuery $subQuery->getDQL();
  897.         $query->andWhere($query->expr()->notIn('e.id'$subQuery));
  898.         $secondsDay 24 60 60;
  899.         $query->andWhere("
  900.             (e.periodEnd IS NULL OR e.periodEnd = :no) OR
  901.             (
  902.                 ( e.typeRelease = :typeStartReleased )
  903.                 OR
  904.                 (
  905.                     e.typeRelease = :typeStartFixedDate
  906.                     AND TIME_TO_SEC(e.dateStart) <=  TIME_TO_SEC(:now)
  907.                     AND (
  908.                         TIME_TO_SEC(e.dateStart) + (e.periodEnd * {$secondsDay})
  909.                     ) >= TIME_TO_SEC(:now)
  910.                 )
  911.                 OR
  912.                 (
  913.                     e.typeRelease = :typeStartFlexPeriod
  914.                 )
  915.             )
  916.         ");
  917.         /* !!!
  918.             $caseDate = "CASE 
  919.                         WHEN e.type = :typeLesson
  920.                             AND (
  921.                                     SELECT 
  922.                                         lg.id
  923.                                     FROM EADPlataforma:LessonLogOrigin AS lg
  924.                                     WHERE lg.user = :user
  925.                                     AND lg.lesson = e.lesson
  926.                                     AND lg.complete = :completed
  927.                                     LIMIT 1 
  928.                                 ) > 0 
  929.                         THEN
  930.                             (   
  931.                                 SELECT 
  932.                                     lg.dateConclusion 
  933.                                 FROM EADPlataforma:LessonLogOrigin AS lg
  934.                                 WHERE lg.user = :user
  935.                                 AND lg.lesson = e.lesson
  936.                                 AND lg.complete = :completed
  937.                                 LIMIT 1
  938.                             )
  939.                         WHEN e.type = :typeModule
  940.                              AND (   
  941.                                 SELECT 
  942.                                     lg.id
  943.                                 FROM EADPlataforma:LessonLogOrigin AS lg
  944.                                 WHERE lg.user = :user
  945.                                 AND lg.complete = :completed
  946.                                 AND lg.lesson = (
  947.                                     SELECT
  948.                                         le.aula_id 
  949.                                     FROM EADPlataforma:Lesson AS le
  950.                                     WHERE le.lessonModule = e.lessonModule 
  951.                                     AND le.status = :statusL
  952.                                     AND le.deleted = 0
  953.                                     ORDER BY le.order DESC LIMIT 1
  954.                                 )
  955.                                 LIMIT 1
  956.                             ) > 0 
  957.                         THEN
  958.                             (   
  959.                                 SELECT 
  960.                                     lg.dateConclusion
  961.                                 FROM EADPlataforma:LessonLogOrigin AS lg
  962.                                 WHERE lg.user = :user
  963.                                 AND lg.complete = :completed
  964.                                 AND lg.lesson = (
  965.                                     SELECT
  966.                                         le.aula_id 
  967.                                     FROM EADPlataforma:Lesson AS le
  968.                                     WHERE le.lessonModule = e.lessonModule 
  969.                                     AND le.status = :statusL
  970.                                     AND le.deleted = 0
  971.                                     ORDER BY le.order DESC LIMIT 1
  972.                                 )
  973.                                 LIMIT 1
  974.                             )
  975.                         ELSE
  976.                             '0000-00-00 00:00:00'
  977.                     END";
  978.         $caseLogId = "CASE 
  979.                         WHEN e.type = :typeLesson
  980.                         THEN
  981.                             (   
  982.                                 SELECT 
  983.                                     lg.id
  984.                                 FROM EADPlataforma:LessonLogOrigin AS lg
  985.                                 WHERE lg.user = :user
  986.                                 AND lg.lesson = e.lesson
  987.                                 AND lg.complete = :completed
  988.                                 LIMIT 1 
  989.                             )
  990.                         WHEN e.type = :typeModule
  991.                         THEN
  992.                             (   
  993.                                 SELECT 
  994.                                     lg.id
  995.                                 FROM EADPlataforma:LessonLogOrigin AS lg
  996.                                 WHERE lg.user = :user
  997.                                 AND lg.complete = :completed
  998.                                 AND lg.lesson = (
  999.                                     SELECT
  1000.                                         le.aula_id 
  1001.                                     FROM EADPlataforma:Lesson AS le
  1002.                                     WHERE le.lessonModule = e.lessonModule 
  1003.                                     AND le.status = :statusL
  1004.                                     AND le.deleted = 0
  1005.                                     ORDER BY le.order DESC LIMIT 1
  1006.                                 )
  1007.                                 LIMIT 1
  1008.                             )
  1009.                         ELSE 0
  1010.                     END";
  1011.                     
  1012.             AND (1) > 0
  1013.             AND (
  1014.                 TIME_TO_SEC({$caseDate}) + (e.periodStart * {$secondsDay})
  1015.             ) <= TIME_TO_SEC(:now)
  1016.             AND (
  1017.                 TIME_TO_SEC({$caseDate}) + (e.periodEnd * {$secondsDay})
  1018.             ) >= TIME_TO_SEC(:now)
  1019.         */
  1020.         $query->setParameter('lmDeleted'LessonModuleEnum::ITEM_NO_DELETED);
  1021.         $query->setParameter('lmStatus'LessonModuleEnum::PUBLISHED);
  1022.         $query->setParameter('lDeleted'LessonEnum::ITEM_NO_DELETED);
  1023.         $query->setParameter('lStatus'LessonEnum::PUBLISHED);
  1024.         $query->setParameter('now'date('Y-m-d H:i:s'));
  1025.         $query->setParameter('typeStartReleased'ExamEnum::RELEASED);
  1026.         $query->setParameter('typeStartFixedDate'ExamEnum::FIXED_DATE);
  1027.         $query->setParameter('typeStartFlexPeriod'ExamEnum::FLEXIBLE_PERIOD);
  1028.         $query->setParameter('course'$course->getId());
  1029.         $query->setParameter('user'$user->getId());
  1030.         $query->setParameter('yes'ExamEnum::YES);
  1031.         $query->setParameter('no'ExamEnum::NO);
  1032.         $query->setParameter('statusAproved'ExamUserEnum::APPROVED);
  1033.         $query->setParameter('statusExam'ExamEnum::PUBLISHED);
  1034.         $query->setParameter('typeModule'ExamEnum::MODULE);
  1035.         $query->setParameter('typeLesson'ExamEnum::LESSON);
  1036.         $query->setParameter('orderL'$lessonBase->getOrder());
  1037.         $query->setParameter('orderLM'$lessonModule->getOrder());
  1038.         $query->setParameter('deleted'ExamEnum::ITEM_NO_DELETED);
  1039.         $query->setParameter('deletedExamUser'ExamUserEnum::ITEM_NO_DELETED);
  1040.         $query->setMaxResults(1);
  1041.         
  1042.         return $query->getQuery()->getOneOrNullResult();
  1043.     }
  1044.     public function getLastExamIdByLesson(Lesson $lessonBasebool $complete false)
  1045.     {
  1046.         $addExams false;
  1047.         $addExamsLimited false;
  1048.         if(
  1049.             $this->configuration->isModuleActive("exam_module") &&
  1050.             $this->configuration->checkModuleIsAbleOnPlan("examFunction")
  1051.         ){
  1052.             $addExams true;
  1053.             $addExamsLimited $this->configuration->checkModuleIsAbleOnPlan(
  1054.                 "unlimitedExamFunction"
  1055.             );
  1056.         }
  1057.         $lessonRepository $this->em->getRepository(Lesson::class);
  1058.         
  1059.         $lessonIdBefore $lessonRepository->getLessonIdBeforeThat($lessonBase);
  1060.         $lesson $lessonRepository->findOneBy([
  1061.             "id" => $lessonIdBefore,
  1062.             "deleted" => ExamEnum::ITEM_NO_DELETED,
  1063.         ]);
  1064.         if(!$lesson){
  1065.             return;
  1066.         }
  1067.         $course $lesson->getCourse();
  1068.         $lessonModule $lesson->getLessonModule();
  1069.         $exam null;
  1070.         if(!$exam && $lessonRepository->isLastModuleLesson($lesson)){
  1071.             if(!$addExams || !$addExamsLimited){
  1072.                 return;
  1073.             }
  1074.             $exam $this->findOneBy([
  1075.                 "deleted" => ExamEnum::ITEM_NO_DELETED,
  1076.                 "course" => $course->getId(),
  1077.                 "lessonModule" => $lessonModule->getId(),
  1078.                 "status" => ExamEnum::PUBLISHED,
  1079.                 "type" => ExamEnum::MODULE
  1080.             ]);
  1081.         }
  1082.         if(!$exam){
  1083.             if(!$addExams || !$addExamsLimited){
  1084.                 return;
  1085.             }
  1086.             $exam $this->findOneBy([
  1087.                 "deleted" => ExamEnum::ITEM_NO_DELETED,
  1088.                 "course" => $course->getId(),
  1089.                 "lessonModule" => $lessonModule->getId(),
  1090.                 "lesson" => $lesson->getId(),
  1091.                 "status" => ExamEnum::PUBLISHED,
  1092.                 "type" => ExamEnum::LESSON
  1093.             ]);
  1094.         }
  1095.         if(!$exam){
  1096.             $exam $this->findOneBy([
  1097.                 "deleted" => ExamEnum::ITEM_NO_DELETED,
  1098.                 "course" => $course->getId(),
  1099.                 "lessonModule" => $lessonModule->getId(),
  1100.                 "lesson" => $lesson->getId(),
  1101.                 "status" => ExamEnum::PUBLISHED,
  1102.                 "type" => ExamEnum::QUIZ
  1103.             ]);
  1104.         }
  1105.         if($exam){
  1106.             if($complete){
  1107.                 return (object)[ 
  1108.                     "id" => $exam->getId(),
  1109.                     "title" => $exam->getTitle(),
  1110.                     "courseId" => $exam->getCourse()->getId(),
  1111.                     "moduleId" => (
  1112.                         $exam->getLessonModule() ?
  1113.                         $exam->getLessonModule()->getId() :
  1114.                         null
  1115.                     ),
  1116.                     "moduleTitle" => (
  1117.                         $exam->getLessonModule() ?
  1118.                         $exam->getLessonModule()->getTitle() :
  1119.                         null
  1120.                     ),
  1121.                     "lessonId" => (
  1122.                         $exam->getLesson() ?
  1123.                         $exam->getLesson()->getId() :
  1124.                         null
  1125.                     ),
  1126.                     "type" => $exam->getType(),
  1127.                 ];
  1128.             }
  1129.             
  1130.             return $exam->getId();
  1131.         }
  1132.         return;
  1133.     }
  1134.     public function sumCourseWeight($courseId)
  1135.     {
  1136.         $query $this->createQueryBuilder('e');
  1137.         $query->select('SUM(e.examWeight) AS examWeight');
  1138.         $query->andWhere('e.status = :yes');
  1139.         $query->andWhere('e.requirement = :yes');
  1140.         $query->andWhere('e.course = :course');
  1141.         $query->andWhere('e.deleted = :deleted');
  1142.         $query->setParameter('course'$courseId);
  1143.         $query->setParameter('yes'ExamEnum::YES);
  1144.         $query->setParameter('deleted'ExamEnum::ITEM_NO_DELETED);
  1145.         
  1146.         $result = (object)$query->getQuery()->getOneOrNullResult();
  1147.         return $result->examWeight;
  1148.     }
  1149.     public function countCourseWeight($courseId)
  1150.     {
  1151.         $query $this->createQueryBuilder('e');
  1152.         $query->select('COUNT(e.id) AS total');
  1153.         $query->andWhere('e.status = 1');
  1154.         $query->andWhere('e.examWeight > 0');
  1155.         $query->andWhere('e.requirement = 1');
  1156.         $query->andWhere('e.course = :course');
  1157.         $query->setParameter('course'$courseId);
  1158.         
  1159.         $result = (object)$query->getQuery()->getOneOrNullResult();
  1160.         return $result->total;
  1161.     }
  1162.     public function countValidExamByCourse(int $courseId)
  1163.     {
  1164.         $query $this->createQueryBuilder('e');
  1165.         $query->innerJoin('EADPlataforma:Course''c''WITH''c.id = e.course');
  1166.         $query->leftJoin('EADPlataforma:LessonModule''lm''WITH''lm.id = e.lessonModule');
  1167.         $query->leftJoin('EADPlataforma:Lesson''l''WITH''l.id = e.lesson');
  1168.         $query->select('COUNT(e.id) AS total');
  1169.         $query->andWhere('e.deleted = :examDeleted');
  1170.         $query->andWhere('e.status = :examStatus');
  1171.         $query->andWhere('e.examWeight > 0');
  1172.         //$query->andWhere('e.requirement = :yes');
  1173.         $query->andWhere('e.course = :course');
  1174.         $query->andWhere('
  1175.             (
  1176.                 (e.type = :typeCourse AND c.deleted = :courseDeleted)
  1177.                 OR (
  1178.                     e.type = :typeLessonModule
  1179.                     AND lm.status = :lessonModuleStatus 
  1180.                     AND lm.deleted = :lessonModuleDeleted
  1181.                 ) 
  1182.                 OR (
  1183.                     e.type = :typeLesson 
  1184.                     AND l.status = :lessonStatus 
  1185.                     AND l.deleted = :lessonDeleted
  1186.                 )
  1187.             )
  1188.         ');
  1189.         $query->setParameter('typeCourse'ExamEnum::COURSE);
  1190.         $query->setParameter('typeLessonModule'ExamEnum::MODULE);
  1191.         $query->setParameter('typeLesson'ExamEnum::LESSON);
  1192.         $query->setParameter('examDeleted'ExamEnum::ITEM_NO_DELETED);
  1193.         $query->setParameter('courseDeleted'CourseEnum::ITEM_NO_DELETED);
  1194.         $query->setParameter('lessonModuleDeleted'LessonModuleEnum::ITEM_NO_DELETED);
  1195.         $query->setParameter('lessonDeleted'LessonEnum::ITEM_NO_DELETED);
  1196.         
  1197.         $query->setParameter('lessonModuleStatus'LessonModuleEnum::PUBLISHED);
  1198.         $query->setParameter('lessonStatus'LessonEnum::PUBLISHED);
  1199.         $query->setParameter('examStatus'ExamEnum::PUBLISHED);
  1200.         //$query->setParameter('yes', ExamEnum::YES);
  1201.         $query->setParameter('course'$courseId);
  1202.         
  1203.         $result = (object)$query->getQuery()->getOneOrNullResult();
  1204.         return $result->total;
  1205.     }
  1206.     public function copyExamQuestion(Exam $oldExamExam $newExam)
  1207.     {   
  1208.         $questionRepository $this->em->getRepository(Question::class);
  1209.         $questions $oldExam->getQuestion();
  1210.         if($questions){
  1211.             foreach ($questions as $key => $question) {
  1212.                 if($question->isLive()){
  1213.                     if($oldExam->getCourse()->getId() != $newExam->getCourse()->getId()){
  1214.                         $newQuestion $questionRepository->copyQuestionsByCourse(
  1215.                             $question
  1216.                             $newExam->getCourse()
  1217.                         );
  1218.                         
  1219.                         if($newQuestion){
  1220.                             $newExam->addQuestion($newQuestion);
  1221.                         }
  1222.                     }else{
  1223.                         $newExam->addQuestion($question); 
  1224.                     }
  1225.                 }
  1226.             }
  1227.         }
  1228.         return $newExam;
  1229.     }
  1230.     public function copyExamByCourse(Course $oldCourseCourse $newCourse)
  1231.     {
  1232.         $oldExam $this->findOneBy([
  1233.             "course" => $oldCourse->getId(),
  1234.             "type" => ExamEnum::COURSE,
  1235.             "deleted" => ExamEnum::ITEM_NO_DELETED
  1236.         ]);
  1237.         if($oldExam){
  1238.             $newExam = new Exam();
  1239.             
  1240.             $newExam->setTitle($oldExam->getTitle());
  1241.             $newExam->setType($oldExam->getType());
  1242.             $newExam->setStatus($oldExam->getStatus());
  1243.             $newExam->setRequirement($oldExam->getRequirement());
  1244.             $newExam->setQuestionOrder($oldExam->getQuestionOrder());
  1245.             $newExam->setQuestionNumber($oldExam->getQuestionNumber());
  1246.             $newExam->setExamAverage($oldExam->getExamAverage());
  1247.             $newExam->setExamWeight($oldExam->getExamWeight());
  1248.             $newExam->setTypeRelease($oldExam->getTypeRelease());
  1249.             $newExam->setPeriodStart($oldExam->getPeriodStart());
  1250.             $newExam->setPeriodEnd($oldExam->getPeriodEnd());
  1251.             $newExam->setDateStart($oldExam->getDateStart());
  1252.             $newExam->setExamTime($oldExam->getExamTime());
  1253.             $newExam->setAttempts($oldExam->getAttempts());
  1254.             $newExam->setAttemptsNumber($oldExam->getAttemptsNumber());
  1255.             $newExam->setAttemptsAutoRelease($oldExam->getAttemptsAutoRelease());
  1256.             $newExam->setAttemptsTypeRelease($oldExam->getAttemptsTypeRelease());
  1257.             $newExam->setAttemptsTime($oldExam->getAttemptsTime());
  1258.             $newExam->setAttemptsPeriod($oldExam->getAttemptsPeriod());
  1259.             $newExam->setShowTemplate($oldExam->getShowTemplate());
  1260.             $newExam->setNote($oldExam->getNote());
  1261.             $newExam->setDateLastNotify($oldExam->getDateLastNotify());
  1262.             $newExam->setCourse($newCourse);
  1263.             
  1264.             $newExam $this->copyExamQuestion($oldExam$newExam);
  1265.             $this->em->persist($newExam);
  1266.             $this->em->flush();
  1267.         }
  1268.     }
  1269.     public function copyExamByModule(LessonModule $oldModuleLessonModule $newModule)
  1270.     {
  1271.         $oldExam $this->findOneBy([
  1272.             "course" => $oldModule->getCourse()->getId(), 
  1273.             "lessonModule"=> $oldModule->getId(),
  1274.             "type" => ExamEnum::MODULE,
  1275.             "deleted" => ExamEnum::ITEM_NO_DELETED
  1276.         ]);
  1277.         if($oldExam){
  1278.             $newExam = new Exam();
  1279.             
  1280.             $newExam->setTitle($oldExam->getTitle());
  1281.             $newExam->setType($oldExam->getType());
  1282.             $newExam->setStatus($oldExam->getStatus());
  1283.             $newExam->setRequirement($oldExam->getRequirement());
  1284.             $newExam->setQuestionOrder($oldExam->getQuestionOrder());
  1285.             $newExam->setQuestionNumber($oldExam->getQuestionNumber());
  1286.             $newExam->setExamAverage($oldExam->getExamAverage());
  1287.             $newExam->setExamWeight($oldExam->getExamWeight());
  1288.             $newExam->setTypeRelease($oldExam->getTypeRelease());
  1289.             $newExam->setPeriodStart($oldExam->getPeriodStart());
  1290.             $newExam->setPeriodEnd($oldExam->getPeriodEnd());
  1291.             $newExam->setDateStart($oldExam->getDateStart());
  1292.             $newExam->setExamTime($oldExam->getExamTime());
  1293.             $newExam->setAttempts($oldExam->getAttempts());
  1294.             $newExam->setAttemptsNumber($oldExam->getAttemptsNumber());
  1295.             $newExam->setAttemptsAutoRelease($oldExam->getAttemptsAutoRelease());
  1296.             $newExam->setAttemptsTypeRelease($oldExam->getAttemptsTypeRelease());
  1297.             $newExam->setAttemptsTime($oldExam->getAttemptsTime());
  1298.             $newExam->setAttemptsPeriod($oldExam->getAttemptsPeriod());
  1299.             $newExam->setShowTemplate($oldExam->getShowTemplate());
  1300.             $newExam->setNote($oldExam->getNote());
  1301.             $newExam->setDateLastNotify($oldExam->getDateLastNotify());
  1302.             $newExam->setCourse($newModule->getCourse());
  1303.             $newExam->setLessonModule($newModule);
  1304.             
  1305.             $newExam $this->copyExamQuestion($oldExam$newExam);
  1306.             $this->em->persist($newExam);
  1307.             $this->em->flush();
  1308.         }
  1309.     }
  1310.     public function copyExamByLesson(Lesson $oldLessonLesson $newLesson)
  1311.     {
  1312.         $oldExam $this->findOneBy([
  1313.             "course" => $oldLesson->getCourse()->getId(),
  1314.             "lessonModule" => $oldLesson->getLessonModule()->getId(),
  1315.             "lesson"=> $oldLesson->getId(),
  1316.             "type" => ExamEnum::LESSON,
  1317.             "deleted" => ExamEnum::ITEM_NO_DELETED
  1318.         ]);
  1319.         if($oldExam){
  1320.             $newExam = new Exam();
  1321.             
  1322.             $newExam->setTitle($oldExam->getTitle());
  1323.             $newExam->setType($oldExam->getType());
  1324.             $newExam->setStatus($oldExam->getStatus());
  1325.             $newExam->setRequirement($oldExam->getRequirement());
  1326.             $newExam->setQuestionOrder($oldExam->getQuestionOrder());
  1327.             $newExam->setQuestionNumber($oldExam->getQuestionNumber());
  1328.             $newExam->setExamAverage($oldExam->getExamAverage());
  1329.             $newExam->setExamWeight($oldExam->getExamWeight());
  1330.             $newExam->setTypeRelease($oldExam->getTypeRelease());
  1331.             $newExam->setPeriodStart($oldExam->getPeriodStart());
  1332.             $newExam->setPeriodEnd($oldExam->getPeriodEnd());
  1333.             $newExam->setDateStart($oldExam->getDateStart());
  1334.             $newExam->setExamTime($oldExam->getExamTime());
  1335.             $newExam->setAttempts($oldExam->getAttempts());
  1336.             $newExam->setAttemptsNumber($oldExam->getAttemptsNumber());
  1337.             $newExam->setAttemptsAutoRelease($oldExam->getAttemptsAutoRelease());
  1338.             $newExam->setAttemptsTypeRelease($oldExam->getAttemptsTypeRelease());
  1339.             $newExam->setAttemptsTime($oldExam->getAttemptsTime());
  1340.             $newExam->setAttemptsPeriod($oldExam->getAttemptsPeriod());
  1341.             $newExam->setShowTemplate($oldExam->getShowTemplate());
  1342.             $newExam->setNote($oldExam->getNote());
  1343.             $newExam->setDateLastNotify($oldExam->getDateLastNotify());
  1344.             $newExam->setCourse($newLesson->getCourse());
  1345.             $newExam->setLessonModule($newLesson->getLessonModule());
  1346.             $newExam->setLesson($newLesson);
  1347.             
  1348.             $newExam $this->copyExamQuestion($oldExam$newExam);
  1349.             
  1350.             $this->em->persist($newExam);
  1351.             $this->em->flush();
  1352.         }
  1353.     }
  1354.     public function copyQuizByLesson(Lesson $oldLessonLesson $newLesson)
  1355.     {
  1356.         $oldExam $this->findOneBy([
  1357.             "course" => $oldLesson->getCourse()->getId(),
  1358.             "lessonModule" => $oldLesson->getLessonModule()->getId(),
  1359.             "lesson"=> $oldLesson->getId(),
  1360.             "type" => ExamEnum::QUIZ,
  1361.             "deleted" => ExamEnum::ITEM_NO_DELETED
  1362.         ]);
  1363.         if($oldExam){
  1364.             $newExam = new Exam();
  1365.             
  1366.             $newExam->setTitle($oldExam->getTitle());
  1367.             $newExam->setType($oldExam->getType());
  1368.             $newExam->setStatus($oldExam->getStatus());
  1369.             $newExam->setRequirement($oldExam->getRequirement());
  1370.             $newExam->setQuestionOrder($oldExam->getQuestionOrder());
  1371.             $newExam->setQuestionNumber($oldExam->getQuestionNumber());
  1372.             $newExam->setExamAverage($oldExam->getExamAverage());
  1373.             $newExam->setExamWeight($oldExam->getExamWeight());
  1374.             $newExam->setTypeRelease($oldExam->getTypeRelease());
  1375.             $newExam->setPeriodStart($oldExam->getPeriodStart());
  1376.             $newExam->setPeriodEnd($oldExam->getPeriodEnd());
  1377.             $newExam->setDateStart($oldExam->getDateStart());
  1378.             $newExam->setExamTime($oldExam->getExamTime());
  1379.             $newExam->setAttempts($oldExam->getAttempts());
  1380.             $newExam->setAttemptsNumber($oldExam->getAttemptsNumber());
  1381.             $newExam->setAttemptsAutoRelease($oldExam->getAttemptsAutoRelease());
  1382.             $newExam->setAttemptsTypeRelease($oldExam->getAttemptsTypeRelease());
  1383.             $newExam->setAttemptsTime($oldExam->getAttemptsTime());
  1384.             $newExam->setAttemptsPeriod($oldExam->getAttemptsPeriod());
  1385.             $newExam->setShowTemplate($oldExam->getShowTemplate());
  1386.             $newExam->setNote($oldExam->getNote());
  1387.             $newExam->setDateLastNotify($oldExam->getDateLastNotify());
  1388.             $newExam->setCourse($newLesson->getCourse());
  1389.             $newExam->setLessonModule($newLesson->getLessonModule());
  1390.             $newExam->setLesson($newLesson);
  1391.             
  1392.             $newExam $this->copyExamQuestion($oldExam$newExam);
  1393.             
  1394.             $this->em->persist($newExam);
  1395.             $this->em->flush();
  1396.         }
  1397.     }
  1398.     public function editManyStatus(Exam $exam$permission$status)
  1399.     {
  1400.         $userPermissionUtil $this->generalService->getUtil('UserPermissionUtil');
  1401.         $allTypes $this->configuration->checkModuleIsAbleOnPlan('unlimitedExamFunction');
  1402.         if(!$allTypes){
  1403.             if($exam->getType() != ExamEnum::COURSE && $exam->getType() != ExamEnum::QUIZ){
  1404.                 return false;
  1405.             }
  1406.         }
  1407.         if($exam->getType() == ExamEnum::MODULE){
  1408.             $permission $userPermissionUtil->getPermission(
  1409.                 "course"
  1410.                 "lesson_module"
  1411.                 "exam_configuration"
  1412.                 "edit"
  1413.             );
  1414.         }else if($exam->getType() == ExamEnum::LESSON){
  1415.             $permission $userPermissionUtil->getPermission(
  1416.                 "course"
  1417.                 "lesson"
  1418.                 "exam_configuration"
  1419.                 "edit"
  1420.             );
  1421.         }else if($exam->getType() == ExamEnum::QUIZ){
  1422.             $permission $userPermissionUtil->getPermission(
  1423.                 "course"
  1424.                 "lesson"
  1425.                 "quiz_configuration"
  1426.                 "edit"
  1427.             );
  1428.         }
  1429.         $isExamTeacher $this->isExamTeacher($exam$this->getUser());
  1430.         if($isExamTeacher && $userPermissionUtil->isMiddle($permission) || 
  1431.             $userPermissionUtil->isHigh($permission)){
  1432.             $exam->setStatus($status);
  1433.         }
  1434.     }
  1435.     public function deleteExam(Exam $exam): void
  1436.     {
  1437.         $exam->removeAllQuestion();
  1438.         $exam->setTitle(null);
  1439.         $exam->setStatus(ExamEnum::DRAFT);
  1440.         $exam->setRequirement(ExamEnum::NO);
  1441.         $exam->setQuestionOrder(ExamEnum::SEQUENTIAL);
  1442.         $exam->setQuestionNumber(0);
  1443.         $exam->setExamAverage(ExamEnum::DEFAULT_AVERAGE);
  1444.         $exam->setExamWeight(0);
  1445.         $exam->setTypeRelease(ExamEnum::RELEASED);
  1446.         $exam->setControlTime(ExamEnum::NO);
  1447.         $exam->setPeriodStart(0);
  1448.         $exam->setPeriodEnd(0);
  1449.         $exam->setDateStart(null);
  1450.         $exam->setExamTime(null);
  1451.         $exam->setAttempts(ExamEnum::NO);
  1452.         $exam->setAttemptsNumber(1);
  1453.         $exam->setAttemptsAutoRelease(ExamEnum::YES);
  1454.         $exam->setAttemptsTypeRelease(ExamEnum::DAYS);
  1455.         $exam->setAttemptsTime(null);
  1456.         $exam->setAttemptsPeriod(null);
  1457.         $exam->setShowTemplate(ExamEnum::NO);
  1458.         $exam->setNote(null);
  1459.         $exam->setDateLastNotify(null);
  1460.         $this->em->flush();
  1461.     }
  1462.     public function delete(Exam $exam$typeItem$permission$isTrash)
  1463.     {
  1464.         $userPermissionUtil $this->generalService->getUtil('UserPermissionUtil');
  1465.         $allTypes $this->configuration->checkModuleIsAbleOnPlan('unlimitedExamFunction');
  1466.         if(!$allTypes){
  1467.             if($exam->getType() != ExamEnum::COURSE && $exam->getType() != ExamEnum::QUIZ){
  1468.                 return false;
  1469.             }
  1470.         }
  1471.         if($exam->getType() == ExamEnum::MODULE){
  1472.             $permission $userPermissionUtil->getPermission(
  1473.                 "course"
  1474.                 "lesson_module"
  1475.                 "exam_configuration"
  1476.                 "delete"
  1477.             );
  1478.         }else if($exam->getType() == ExamEnum::LESSON){
  1479.             $permission $userPermissionUtil->getPermission(
  1480.                 "course"
  1481.                 "lesson"
  1482.                 "exam_configuration"
  1483.                 "delete"
  1484.             );
  1485.         }else if($exam->getType() == ExamEnum::QUIZ){
  1486.             $permission $userPermissionUtil->getPermission(
  1487.                 "course"
  1488.                 "lesson"
  1489.                 "quiz_configuration"
  1490.                 "delete"
  1491.             );
  1492.         }
  1493.         $isExamTeacher $this->isExamTeacher($exam$this->getUser());
  1494.         if($isExamTeacher || $userPermissionUtil->isHigh($permission)){
  1495.             $questions $exam->getQuestion();
  1496.             if(!empty($questions)){
  1497.                 foreach ($questions as $key => $question) {
  1498.                     $exam->removeQuestion($question);
  1499.                 }
  1500.             }
  1501.             $exam->setTitle(null);
  1502.             $exam->setStatus(ExamEnum::DRAFT);
  1503.             $exam->setRequirement(ExamEnum::NO);
  1504.             $exam->setQuestionOrder(ExamEnum::SEQUENTIAL);
  1505.             $exam->setQuestionNumber(0);
  1506.             $exam->setExamAverage(ExamEnum::DEFAULT_AVERAGE);
  1507.             $exam->setExamWeight(0);
  1508.             $exam->setTypeRelease(ExamEnum::RELEASED);
  1509.             $exam->setControlTime(ExamEnum::NO);
  1510.             $exam->setPeriodStart(0);
  1511.             $exam->setPeriodEnd(0);
  1512.             $exam->setDateStart(null);
  1513.             $exam->setExamTime(null);
  1514.             $exam->setAttempts(ExamEnum::NO);
  1515.             $exam->setAttemptsNumber(1);
  1516.             $exam->setAttemptsAutoRelease(ExamEnum::YES);
  1517.             $exam->setAttemptsTypeRelease(ExamEnum::DAYS);
  1518.             $exam->setAttemptsTime(null);
  1519.             $exam->setAttemptsPeriod(null);
  1520.             $exam->setShowTemplate(ExamEnum::NO);
  1521.             $exam->setNote(null);
  1522.             $exam->setDateLastNotify(null);
  1523.             $this->em->flush();
  1524.         }
  1525.     }
  1526.     public function restoreByCourse($courseId$deleted$typeDelete$userDelete$dateNow){
  1527.         $sql "UPDATE EADPlataforma:Exam AS e 
  1528.                 SET e.deleted = :deleted, e.userDelete = :userDelete, 
  1529.                     e.dateDelete = :dateNow
  1530.                 WHERE e.deleted = (1 - :deleted)
  1531.                 AND e.typeDelete = :typeDelete
  1532.                 AND e.course = :courseId";
  1533.         $query $this->em->createQuery($sql);
  1534.         $query->setParameter('courseId'$courseId);
  1535.         $query->setParameter('deleted'$deleted);
  1536.         $query->setParameter('typeDelete'$typeDelete);
  1537.         $query->setParameter('userDelete'$userDelete);
  1538.         $query->setParameter('dateNow'$dateNow);
  1539.         $query->execute();
  1540.         
  1541.         return true;
  1542.     }
  1543.     public function deleteByCourse($courseId$deleted$typeDelete$userDelete$dateNow){
  1544.         $sql "UPDATE EADPlataforma:Exam AS e 
  1545.                 SET e.deleted = :deleted, e.typeDelete = :typeDelete,
  1546.                     e.userDelete = :userDelete, e.dateDelete = :dateNow
  1547.                 WHERE e.deleted = (:deleted - 1)
  1548.                 AND e.course = :courseId";
  1549.         $query $this->em->createQuery($sql);
  1550.         $query->setParameter('courseId'$courseId);
  1551.         $query->setParameter('deleted'$deleted);
  1552.         $query->setParameter('typeDelete'$typeDelete);
  1553.         $query->setParameter('userDelete'$userDelete);
  1554.         $query->setParameter('dateNow'$dateNow);
  1555.         $query->execute();
  1556.         
  1557.         return true;
  1558.     }
  1559.     public function restoreByLessonModule($lessonModuleId$deleted$typeDelete$userDelete$dateNow){
  1560.         $sql "UPDATE EADPlataforma:Exam AS e 
  1561.                 SET e.deleted = :deleted, e.userDelete = :userDelete, 
  1562.                     e.dateDelete = :dateNow
  1563.                 WHERE e.deleted = (1 - :deleted)
  1564.                 AND e.typeDelete = :typeDelete
  1565.                 AND e.lessonModule = :lessonModuleId";
  1566.         $query $this->em->createQuery($sql);
  1567.         $query->setParameter('lessonModuleId'$lessonModuleId);
  1568.         $query->setParameter('deleted'$deleted);
  1569.         $query->setParameter('typeDelete'$typeDelete);
  1570.         $query->setParameter('userDelete'$userDelete);
  1571.         $query->setParameter('dateNow'$dateNow);
  1572.         $query->execute();
  1573.         
  1574.         return true;
  1575.     }
  1576.     public function deleteByLessonModule($lessonModuleId$deleted$typeDelete$userDelete$dateNow){
  1577.         $sql "UPDATE EADPlataforma:Exam AS e 
  1578.                 SET e.deleted = :deleted, e.typeDelete = :typeDelete,
  1579.                     e.userDelete = :userDelete, e.dateDelete = :dateNow
  1580.                 WHERE e.deleted = (:deleted - 1)
  1581.                 AND e.lessonModule = :lessonModuleId";
  1582.         $query $this->em->createQuery($sql);
  1583.         $query->setParameter('lessonModuleId'$lessonModuleId);
  1584.         $query->setParameter('deleted'$deleted);
  1585.         $query->setParameter('typeDelete'$typeDelete);
  1586.         $query->setParameter('userDelete'$userDelete);
  1587.         $query->setParameter('dateNow'$dateNow);
  1588.         $query->execute();
  1589.         
  1590.         return true;
  1591.     }
  1592.     public function restoreByLesson($lessonId$deleted$typeDelete$userDelete$dateNow){
  1593.         $sql "UPDATE EADPlataforma:Exam AS e 
  1594.                 SET e.deleted = :deleted, e.userDelete = :userDelete, 
  1595.                     e.dateDelete = :dateNow
  1596.                 WHERE e.deleted = (1 - :deleted)
  1597.                 AND e.typeDelete = :typeDelete
  1598.                 AND e.lesson = :lessonId";
  1599.         $query $this->em->createQuery($sql);
  1600.         $query->setParameter('lessonId'$lessonId);
  1601.         $query->setParameter('deleted'$deleted);
  1602.         $query->setParameter('typeDelete'$typeDelete);
  1603.         $query->setParameter('userDelete'$userDelete);
  1604.         $query->setParameter('dateNow'$dateNow);
  1605.         $query->execute();
  1606.         
  1607.         return true;
  1608.     }
  1609.     public function deleteByLesson($lessonId$deleted$typeDelete$userDelete$dateNow){
  1610.         $sql "UPDATE EADPlataforma:Exam AS e 
  1611.                 SET e.deleted = :deleted, e.typeDelete = :typeDelete,
  1612.                     e.userDelete = :userDelete, e.dateDelete = :dateNow
  1613.                 WHERE e.deleted = (:deleted - 1)
  1614.                 AND e.lesson = :lessonId";
  1615.         $query $this->em->createQuery($sql);
  1616.         $query->setParameter('lessonId'$lessonId);
  1617.         $query->setParameter('deleted'$deleted);
  1618.         $query->setParameter('typeDelete'$typeDelete);
  1619.         $query->setParameter('userDelete'$userDelete);
  1620.         $query->setParameter('dateNow'$dateNow);
  1621.         $query->execute();
  1622.         
  1623.         return true;
  1624.     }
  1625.     public function deleteTrashCron()
  1626.     {
  1627.         $sql "UPDATE EADPlataforma:Exam AS e 
  1628.                 SET e.deleted = 2 WHERE e.dateDelete <= :date AND e.deleted = 1 ";
  1629.         $query $this->em->createQuery($sql);
  1630.         $query->setParameter('date'date('Y-m-d H:i:s'strtotime('-90 days')));
  1631.         $query->execute();
  1632.     }
  1633. }