src\Controller\CourseController.php line 227

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Controller\AppController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. class CourseController extends AppController
  8. {
  9.     /**
  10.      * @Route("/course", name="app_course")
  11.      */
  12.     public function index($courseCode): Response
  13.     {        
  14.         
  15.         $check $this->commonCalls();
  16.         if(!$check){
  17.             return $check;
  18.         }
  19.         if($this->RedirectHandle!==NULL){
  20.             return $this->RedirectHandle;
  21.         }
  22.         
  23.         if($this->getUser()!==NULL && $this->getUser()->getEmail()){
  24.             $course $this->ApiCalls->getMyCourse($this->getUser()->getEmail(),$courseCode);
  25.             $this->setData('courseCode'$courseCode);
  26.             
  27.             
  28.             $resTools $this->ApiCalls->getProfileTools($this->getUser()->getEmail());
  29.             $check $this->handleDbErrors($resTools);
  30.             if($check===FALSE){           
  31.                 $this->setData('tools'$resTools);
  32.             }
  33.             else{
  34.                 return $check;
  35.             }
  36.             
  37.             $resCards $this->ApiCalls->getHomePageData($this->page$this->getUser()->getEmail());
  38.             $check $this->handleDbErrors($resCards);
  39.             if($check===FALSE){           
  40.                 $this->setData('cards'$resCards);
  41.             }
  42.             else{
  43.                 return $check;
  44.             }
  45.             
  46.         }
  47.         else{
  48.             $course $this->ApiCalls->getMyCourse(NULL,$courseCode);
  49.             $this->setData('courseCode'$courseCode);
  50.             
  51.             $resFooter $this->ApiCalls->getFooter(NULL);
  52.             $this->parseFooterData($resFooter);
  53.             $this->setData('footer'$this->commonItems["footerItems"]);
  54.         }
  55.         
  56.         $this->Breadcrumbs->setGroupName('courses');        
  57.         $this->setData('breadcrumbsData'$this->Breadcrumbs->get());
  58.         
  59.      
  60.         $this->setData('course'$course[0]);
  61.         
  62.         
  63.         return $this->render('course/index.html.twig'
  64.                 $this->getData()
  65.         );
  66.     }
  67.     
  68.     public function getCalendar($courseCode){
  69.         
  70.         $calendarData $this->ApiCalls->getAttendanceCalendar($this->getUser()->getEmail(), $courseCode);
  71.         $this->setData('calendar'$calendarData);
  72.         
  73.         return new JsonResponse($this->getData());
  74.     } 
  75.     
  76.     
  77. //    public function courseList($catId){  
  78. //        
  79. //        if($this->getUser()){
  80. //            $resHomeMenu = $this->ApiCalls->getHomeNav($this->getUser()->getEmail()); 
  81. //            $check = $this->handleDbErrors($resHomeMenu);
  82. //            if($check===FALSE){
  83. //                $this->setData('mainMenu', $resHomeMenu);
  84. //                $this->setData('webenrolPass', $resHomeMenu[0]["webenrolPasscode"]); 
  85. //            }
  86. //            else{
  87. //                return $check;
  88. //            }
  89. //            
  90. //            $resFooter = $this->ApiCalls->getFooter($this->getUser()->getEmail());  
  91. //            $check = $this->handleDbErrors($resFooter);
  92. //            if($check===FALSE){
  93. //                $this->parseFooterData($resFooter);            
  94. //                $this->setData('footer', $this->commonItems["footerItems"]);
  95. //            }
  96. //            else{
  97. //                return $check;
  98. //            }
  99. //            
  100. //            $msgData = $this->ApiCalls->getAttentionMessage($this->getUser()->getEmail()); 
  101. //            $check = $this->handleDbErrors($msgData);
  102. //            if($check===FALSE){           
  103. //                $this->setData('alerts', $msgData);
  104. //            }
  105. //            else{
  106. //                return $check;
  107. //            }
  108. //            
  109. //            $resTools = $this->ApiCalls->getProfileTools($this->getUser()->getEmail());
  110. //            $check = $this->handleDbErrors($resTools);
  111. //            if($check===FALSE){           
  112. //                $this->setData('tools', $resTools);
  113. //            }
  114. //            else{
  115. //                return $check;
  116. //            }
  117. //            
  118. //            $resCards = $this->ApiCalls->getHomePageData($this->getUser()->getEmail());
  119. //            $check = $this->handleDbErrors($resCards);
  120. //            if($check===FALSE){           
  121. //                $this->setData('cards', $resCards);
  122. //            }
  123. //            else{
  124. //                return $check;
  125. //            }
  126. //            
  127. //            $attentionData = $this->ApiCalls->getAttentionCourse($this->getUser()->getEmail(), $catId);
  128. //            $check = $this->handleDbErrors($attentionData);
  129. //            if($check===FALSE){           
  130. //                $this->setData('attentionData', $attentionData);
  131. //            }
  132. //            else{
  133. //                return $check;
  134. //            }
  135. //            
  136. //        }
  137. //        else{
  138. //            $resHomeMenu = $this->ApiCalls->getHomeNav(NULL);
  139. //            $this->setData('mainMenu', $resHomeMenu);
  140. //                        
  141. //            $resFooter = $this->ApiCalls->getFooter(NULL);
  142. //            $this->parseFooterData($resFooter);
  143. //            $this->setData('footer', $this->commonItems["footerItems"]);
  144. //        }
  145. //        
  146. //        $courseList = $this->ApiCalls->getCourseList(NULL, NULL, $catId);
  147. //
  148. //        $this->setData('courseList', $courseList);
  149. //        
  150. //        return $this->render('course/list.html.twig', 
  151. //                $this->getData()
  152. //        );
  153. //    }
  154.     
  155.     public function courseDetail($courseCode){
  156.         $check $this->commonCalls(['getHomeNav','getPageTexts','getCards''getFooter''getSearch']);
  157.         if(!$check){
  158.             return $check;
  159.         }
  160.         if($this->RedirectHandle!==NULL){
  161.             return $this->RedirectHandle;
  162.         }
  163.         
  164.         if($this->getUser()!==NULL && $this->getUser()->getEmail()){
  165.             $course $this->ApiCalls->getCourseDetail($this->page$courseCode$this->getUser()->getEmail());
  166.             
  167.             $this->setData('courseCode'$courseCode);
  168.             $courseInfo $this->ApiCalls->getCourseInfo($this->page$courseCode$this->getUser()->getEmail());
  169.             $courseSessions $this->ApiCalls->getCourseSessions($courseCode$this->getUser()->getEmail());
  170.           
  171.            
  172.             $msgData $this->ApiCalls->getAttentionMessage('courseDetail',$this->getUser()->getEmail(), $courseCode); 
  173.             $check $this->handleDbErrors($msgData);
  174.             if($check===FALSE){           
  175.                 $this->setData('alerts'$msgData);
  176.             }
  177.             else{
  178.                 return $check;
  179.             }
  180.             
  181.             $resTools $this->ApiCalls->getProfileTools($this->getUser()->getEmail());
  182.             $check $this->handleDbErrors($resTools);
  183.             if($check===FALSE){           
  184.                 $this->setData('tools'$resTools);
  185.             }
  186.             else{
  187.                 return $check;
  188.             }
  189.             
  190.             $this->setData('page'$this->page);
  191.  
  192.             
  193.         }
  194.         else{
  195.             $course $this->ApiCalls->getCourseDetail($this->page$courseCodeNULL$this->getAnonymousID());            
  196.             $this->setData('courseCode'$courseCode);            
  197.             
  198.             
  199.             $courseInfo $this->ApiCalls->getCourseInfo($this->page$courseCodeNULL);
  200.             $courseSessions $this->ApiCalls->getCourseSessions($courseCodeNULL);
  201.             
  202.             $msgData $this->ApiCalls->getAttentionMessage('courseDetail'NULL$courseCode); 
  203.             $check $this->handleDbErrors($msgData);
  204.             if($check===FALSE){           
  205.                 $this->setData('alerts'$msgData);
  206.             }
  207.             else{
  208.                 return $check;
  209.             }
  210.             
  211.         }
  212.         
  213.         $this->setData('course'$course[0]);
  214.         $this->setData('courseInfo'$courseInfo[0]);
  215.         $this->setData('courseSessions'$courseSessions);
  216.         $this->setData('page'$this->page);
  217.         
  218.         $this->Breadcrumbs->setGroupName('courses');       
  219.         $this->setData('breadcrumbsData'$this->Breadcrumbs->get());
  220.         
  221.         return $this->render('course/detail.html.twig'
  222.                 $this->getData()
  223.         );
  224.     }
  225.     
  226.     public function endpoint($action$courseCode$pageName){
  227.         if($this->getUser()!==NULL && $this->getUser()->getEmail()){
  228.             $res $this->ApiCalls->callEnrolEndpoint($action$courseCode$pageName$this->getUser()->getEmail());
  229.         }
  230.         else{
  231.             $res $this->ApiCalls->callEnrolEndpoint($action$courseCode$pageName); 
  232.         } 
  233.         if($res[0]['redirect']){
  234.             if($res[0]["return_type"]=='page'){
  235.                 if(isset($res[0]['return_params']) && !empty($res[0]['return_params'])){
  236.                     $res[0]['url'] = $this->generateUrl($res[0]["return_route"], json_decode($res[0]['return_params'], TRUE));
  237.                 }
  238.                 else{
  239.                     $res[0]['url'] = $this->generateUrl($res[0]["return_route"]);
  240.                 }                
  241.             }
  242.             elseif($res[0]["return_type"]=='url'){
  243.                 $res[0]['url'] = $res[0]["return_url"];
  244.             }
  245.         }
  246.         return new JsonResponse($res);
  247.     }
  248. }