src/Controller/Website/CourseController.php line 46

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Website;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use EADPlataforma\Entity\Course;
  7. use EADPlataforma\Entity\CourseTeam;
  8. use EADPlataforma\Entity\LessonModule;
  9. use EADPlataforma\Entity\Lesson;
  10. use EADPlataforma\Entity\LessonLog;
  11. use EADPlataforma\Entity\LessonLogOrigin;
  12. use EADPlataforma\Entity\LessonSupport;
  13. use EADPlataforma\Entity\LessonAnnotation;
  14. use EADPlataforma\Entity\Enrollment;
  15. use EADPlataforma\Entity\Exam;
  16. use EADPlataforma\Entity\ExamUser;
  17. use EADPlataforma\Entity\ProductOffer;
  18. use EADPlataforma\Enum\EnrollmentEnum;
  19. use EADPlataforma\Enum\CourseTeamEnum;
  20. use EADPlataforma\Enum\ProductEnum;
  21. use EADPlataforma\Enum\CourseEnum;
  22. /**
  23.  * @Route(
  24.  *      path            = "/course",
  25.  *      schemes         = {"http|https"}
  26.  * )
  27.  * @Cache(
  28.  *      maxage          = "0",
  29.  *      smaxage         = "0",
  30.  *      expires         = "now",
  31.  *      public          = false
  32.  * )
  33.  */
  34. class CourseController extends AbstractWebsiteController {
  35.     /**
  36.      * @Route(
  37.      *      path          = "/index/{id}",
  38.      *      name          = "courseIndex",
  39.      *      methods       = {"GET"}
  40.      * )
  41.      */
  42.     public function getCourseIndex(Request $request) {
  43.        
  44.         $this->checkUserSession($request);
  45.         $courseId $request->get('id');
  46.         $userId $this->user->getId();
  47.         $courseRepository $this->em->getRepository(Course::class);
  48.         $course $courseRepository->findOneBy([
  49.             "id" => $courseId,
  50.             "deleted" => CourseEnum::ITEM_NO_DELETED
  51.         ]);
  52.         
  53.         if (!$course) {
  54.             return $this->redirectToRoute('notFound');
  55.         }
  56.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  57.         $enrollment $enrollmentRepository->findOneBy([
  58.             "user" => $userId,
  59.             "course" => $courseId,
  60.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED,
  61.         ]);
  62.         $isInTeam $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
  63.             $course
  64.             $this->user
  65.         );
  66.         $permission $this->userPermissionUtil->getPermission("course""see");
  67.         
  68.         if(!$enrollment){
  69.             if($course->getFree() == CourseEnum::NO){
  70.                 if($this->userPermissionUtil->isLow($permission)){
  71.                     return $this->redirectToRoute('notFound');
  72.                 }
  73.                 if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
  74.                     return $this->redirectToRoute('notFound');
  75.                 }
  76.             }
  77.         }
  78.         if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
  79.             if($course->getStatus() == CourseEnum::DRAFT){
  80.                 return $this->redirectToRoute('notFound');
  81.             }
  82.         }
  83.         //$lessonLogRepository = $this->em->getRepository(LessonLogOrigin::class);
  84.         $lessonLogRepository $this->emEadmin->getRepository(LessonLog::class);
  85.         $lastLessonLog $lessonLogRepository->getLastLessonLogNew($courseId$userId);
  86.         //$lastLessonLog = $lessonLogRepository->getLastLessonLogOrigin($courseId, $userId);
  87.         $lessonActual = ($lastLessonLog $lastLessonLog->getLesson() : null);
  88.         if($lessonActual){
  89.             if(!$lessonActual->isLive()){
  90.                 $lessonActual null;
  91.             }
  92.         }
  93.         if(!$lessonActual){
  94.             $lessonRepository $this->em->getRepository(Lesson::class);
  95.             $lessonActual $lessonRepository->getFirstLesson($course);
  96.         }
  97.        
  98.         $lessonId = ($lessonActual $lessonActual->getId() : 0);
  99.         if(empty($lessonId)){
  100.             //check has module exam and redirect / check has exam final and redirect !!!
  101.         }
  102.         return $this->redirectToRoute('lessonPage', [ 
  103.             "courseId" => $course->getId(),
  104.             "lessonId" => $lessonId,
  105.         ]);
  106.     }
  107. }