<?php
namespace EADPlataforma\Controller\Website;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use EADPlataforma\Entity\Course;
use EADPlataforma\Entity\CourseTeam;
use EADPlataforma\Entity\LessonModule;
use EADPlataforma\Entity\Lesson;
use EADPlataforma\Entity\LessonLog;
use EADPlataforma\Entity\LessonLogOrigin;
use EADPlataforma\Entity\LessonSupport;
use EADPlataforma\Entity\LessonAnnotation;
use EADPlataforma\Entity\Enrollment;
use EADPlataforma\Entity\Exam;
use EADPlataforma\Entity\ExamUser;
use EADPlataforma\Entity\ProductOffer;
use EADPlataforma\Enum\EnrollmentEnum;
use EADPlataforma\Enum\CourseTeamEnum;
use EADPlataforma\Enum\ProductEnum;
use EADPlataforma\Enum\CourseEnum;
/**
* @Route(
* path = "/course",
* schemes = {"http|https"}
* )
* @Cache(
* maxage = "0",
* smaxage = "0",
* expires = "now",
* public = false
* )
*/
class CourseController extends AbstractWebsiteController {
/**
* @Route(
* path = "/index/{id}",
* name = "courseIndex",
* methods = {"GET"}
* )
*/
public function getCourseIndex(Request $request) {
$this->checkUserSession($request);
$courseId = $request->get('id');
$userId = $this->user->getId();
$courseRepository = $this->em->getRepository(Course::class);
$course = $courseRepository->findOneBy([
"id" => $courseId,
"deleted" => CourseEnum::ITEM_NO_DELETED
]);
if (!$course) {
return $this->redirectToRoute('notFound');
}
$enrollmentRepository = $this->em->getRepository(Enrollment::class);
$enrollment = $enrollmentRepository->findOneBy([
"user" => $userId,
"course" => $courseId,
"deleted" => EnrollmentEnum::ITEM_NO_DELETED,
]);
$isInTeam = $this->em->getRepository(CourseTeam::class)->userExistInCourseTeam(
$course,
$this->user
);
$permission = $this->userPermissionUtil->getPermission("course", "see");
if(!$enrollment){
if($course->getFree() == CourseEnum::NO){
if($this->userPermissionUtil->isLow($permission)){
return $this->redirectToRoute('notFound');
}
if(!$isInTeam && $this->userPermissionUtil->isMiddle($permission)){
return $this->redirectToRoute('notFound');
}
}
}
if($this->userPermissionUtil->isLow($permission) && !$isInTeam){
if($course->getStatus() == CourseEnum::DRAFT){
return $this->redirectToRoute('notFound');
}
}
//$lessonLogRepository = $this->em->getRepository(LessonLogOrigin::class);
$lessonLogRepository = $this->emEadmin->getRepository(LessonLog::class);
$lastLessonLog = $lessonLogRepository->getLastLessonLogNew($courseId, $userId);
//$lastLessonLog = $lessonLogRepository->getLastLessonLogOrigin($courseId, $userId);
$lessonActual = ($lastLessonLog ? $lastLessonLog->getLesson() : null);
if($lessonActual){
if(!$lessonActual->isLive()){
$lessonActual = null;
}
}
if(!$lessonActual){
$lessonRepository = $this->em->getRepository(Lesson::class);
$lessonActual = $lessonRepository->getFirstLesson($course);
}
$lessonId = ($lessonActual ? $lessonActual->getId() : 0);
if(empty($lessonId)){
//check has module exam and redirect / check has exam final and redirect !!!
}
return $this->redirectToRoute('lessonPage', [
"courseId" => $course->getId(),
"lessonId" => $lessonId,
]);
}
}