<?php
namespace App\Controller;
use App\Controller\AppController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
class CourseController extends AppController
{
/**
* @Route("/course", name="app_course")
*/
public function index($courseCode): Response
{
$check = $this->commonCalls();
if(!$check){
return $check;
}
if($this->RedirectHandle!==NULL){
return $this->RedirectHandle;
}
if($this->getUser()!==NULL && $this->getUser()->getEmail()){
$course = $this->ApiCalls->getMyCourse($this->getUser()->getEmail(),$courseCode);
$this->setData('courseCode', $courseCode);
$resTools = $this->ApiCalls->getProfileTools($this->getUser()->getEmail());
$check = $this->handleDbErrors($resTools);
if($check===FALSE){
$this->setData('tools', $resTools);
}
else{
return $check;
}
$resCards = $this->ApiCalls->getHomePageData($this->page, $this->getUser()->getEmail());
$check = $this->handleDbErrors($resCards);
if($check===FALSE){
$this->setData('cards', $resCards);
}
else{
return $check;
}
}
else{
$course = $this->ApiCalls->getMyCourse(NULL,$courseCode);
$this->setData('courseCode', $courseCode);
$resFooter = $this->ApiCalls->getFooter(NULL);
$this->parseFooterData($resFooter);
$this->setData('footer', $this->commonItems["footerItems"]);
}
$this->Breadcrumbs->setGroupName('courses');
$this->setData('breadcrumbsData', $this->Breadcrumbs->get());
$this->setData('course', $course[0]);
return $this->render('course/index.html.twig',
$this->getData()
);
}
public function getCalendar($courseCode){
$calendarData = $this->ApiCalls->getAttendanceCalendar($this->getUser()->getEmail(), $courseCode);
$this->setData('calendar', $calendarData);
return new JsonResponse($this->getData());
}
// public function courseList($catId){
//
// if($this->getUser()){
// $resHomeMenu = $this->ApiCalls->getHomeNav($this->getUser()->getEmail());
// $check = $this->handleDbErrors($resHomeMenu);
// if($check===FALSE){
// $this->setData('mainMenu', $resHomeMenu);
// $this->setData('webenrolPass', $resHomeMenu[0]["webenrolPasscode"]);
// }
// else{
// return $check;
// }
//
// $resFooter = $this->ApiCalls->getFooter($this->getUser()->getEmail());
// $check = $this->handleDbErrors($resFooter);
// if($check===FALSE){
// $this->parseFooterData($resFooter);
// $this->setData('footer', $this->commonItems["footerItems"]);
// }
// else{
// return $check;
// }
//
// $msgData = $this->ApiCalls->getAttentionMessage($this->getUser()->getEmail());
// $check = $this->handleDbErrors($msgData);
// if($check===FALSE){
// $this->setData('alerts', $msgData);
// }
// else{
// return $check;
// }
//
// $resTools = $this->ApiCalls->getProfileTools($this->getUser()->getEmail());
// $check = $this->handleDbErrors($resTools);
// if($check===FALSE){
// $this->setData('tools', $resTools);
// }
// else{
// return $check;
// }
//
// $resCards = $this->ApiCalls->getHomePageData($this->getUser()->getEmail());
// $check = $this->handleDbErrors($resCards);
// if($check===FALSE){
// $this->setData('cards', $resCards);
// }
// else{
// return $check;
// }
//
// $attentionData = $this->ApiCalls->getAttentionCourse($this->getUser()->getEmail(), $catId);
// $check = $this->handleDbErrors($attentionData);
// if($check===FALSE){
// $this->setData('attentionData', $attentionData);
// }
// else{
// return $check;
// }
//
// }
// else{
// $resHomeMenu = $this->ApiCalls->getHomeNav(NULL);
// $this->setData('mainMenu', $resHomeMenu);
//
// $resFooter = $this->ApiCalls->getFooter(NULL);
// $this->parseFooterData($resFooter);
// $this->setData('footer', $this->commonItems["footerItems"]);
// }
//
// $courseList = $this->ApiCalls->getCourseList(NULL, NULL, $catId);
//
// $this->setData('courseList', $courseList);
//
// return $this->render('course/list.html.twig',
// $this->getData()
// );
// }
public function courseDetail($courseCode){
$check = $this->commonCalls(['getHomeNav','getPageTexts','getCards', 'getFooter', 'getSearch']);
if(!$check){
return $check;
}
if($this->RedirectHandle!==NULL){
return $this->RedirectHandle;
}
if($this->getUser()!==NULL && $this->getUser()->getEmail()){
$course = $this->ApiCalls->getCourseDetail($this->page, $courseCode, $this->getUser()->getEmail());
$this->setData('courseCode', $courseCode);
$courseInfo = $this->ApiCalls->getCourseInfo($this->page, $courseCode, $this->getUser()->getEmail());
$courseSessions = $this->ApiCalls->getCourseSessions($courseCode, $this->getUser()->getEmail());
$msgData = $this->ApiCalls->getAttentionMessage('courseDetail',$this->getUser()->getEmail(), $courseCode);
$check = $this->handleDbErrors($msgData);
if($check===FALSE){
$this->setData('alerts', $msgData);
}
else{
return $check;
}
$resTools = $this->ApiCalls->getProfileTools($this->getUser()->getEmail());
$check = $this->handleDbErrors($resTools);
if($check===FALSE){
$this->setData('tools', $resTools);
}
else{
return $check;
}
$this->setData('page', $this->page);
}
else{
$course = $this->ApiCalls->getCourseDetail($this->page, $courseCode, NULL, $this->getAnonymousID());
$this->setData('courseCode', $courseCode);
$courseInfo = $this->ApiCalls->getCourseInfo($this->page, $courseCode, NULL);
$courseSessions = $this->ApiCalls->getCourseSessions($courseCode, NULL);
$msgData = $this->ApiCalls->getAttentionMessage('courseDetail', NULL, $courseCode);
$check = $this->handleDbErrors($msgData);
if($check===FALSE){
$this->setData('alerts', $msgData);
}
else{
return $check;
}
}
$this->setData('course', $course[0]);
$this->setData('courseInfo', $courseInfo[0]);
$this->setData('courseSessions', $courseSessions);
$this->setData('page', $this->page);
$this->Breadcrumbs->setGroupName('courses');
$this->setData('breadcrumbsData', $this->Breadcrumbs->get());
return $this->render('course/detail.html.twig',
$this->getData()
);
}
public function endpoint($action, $courseCode, $pageName){
if($this->getUser()!==NULL && $this->getUser()->getEmail()){
$res = $this->ApiCalls->callEnrolEndpoint($action, $courseCode, $pageName, $this->getUser()->getEmail());
}
else{
$res = $this->ApiCalls->callEnrolEndpoint($action, $courseCode, $pageName);
}
if($res[0]['redirect']){
if($res[0]["return_type"]=='page'){
if(isset($res[0]['return_params']) && !empty($res[0]['return_params'])){
$res[0]['url'] = $this->generateUrl($res[0]["return_route"], json_decode($res[0]['return_params'], TRUE));
}
else{
$res[0]['url'] = $this->generateUrl($res[0]["return_route"]);
}
}
elseif($res[0]["return_type"]=='url'){
$res[0]['url'] = $res[0]["return_url"];
}
}
return new JsonResponse($res);
}
}