src\Controller\SignupController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Controller\AppController;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\String\Slugger\AsciiSlugger;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. class SignupController extends AppController
  11. {
  12.     
  13.     public function index($sectionId NULL$sectionNameSlug NULL): Response
  14.     {
  15.         $check $this->commonCalls(['getFooter','getHomeNav','getSearch']);
  16.         if(!$check){
  17.             return $check;
  18.         }
  19.         if($this->RedirectHandle!==NULL){
  20.             return $this->RedirectHandle;
  21.         }
  22.         
  23.         if(!$this->getUser()){
  24.             $sections $this->ApiCalls->businessRulesSectionsOnly();
  25.             if($sectionId === NULL){
  26.                 $sectionId $sections[0]["sectionID"];
  27.             }
  28.             $businessRulesData $this->ApiCalls->businessRules(NULL$sectionId);
  29.             $slugger = new AsciiSlugger('en_GB');
  30.            
  31.             
  32.             foreach($businessRulesData as $key=>$rule){            
  33.                 if($this->Session->get('reg-form')){                 
  34.                     foreach($this->Session->get('reg-form') as $formKey=>$value){ 
  35.                         if($businessRulesData[$key]['fieldname']===$formKey){
  36.                             $businessRulesData[$key]['value'] = $value;
  37.                         }
  38.                     }
  39.                 }
  40.                 /*
  41.                  * refresh and display status if logged in
  42.                  */
  43.                 $businessRulesData[$key]['displayStatus'] = $this->getFieldDisplayStatus($rule);
  44.             }
  45.             $this->setData('sections'$sections);
  46.             $this->setData('businessRulesData'$businessRulesData);
  47.             if($sectionNameSlug===NULL){
  48.                 $sectionName $sections[0]['sectionName'];
  49.                 $sectionNum 1
  50.                 $sectionKey 0;
  51.             }
  52.             else{             
  53.                 foreach($sections as $key=>$section){
  54.                     $sectionNameToSlug trim($section['sectionName']);                
  55.                     $slug $slugger->slug($sectionNameToSlug);
  56.                     if($slug == $sectionNameSlug){
  57.                         $sectionName $section['sectionName'];
  58.                         $sectionKey $key;
  59.                         $sectionNum $key+1;
  60.                     }
  61.                 }
  62.             }            
  63.             
  64.             $this->setData('sectionName'$sectionName);
  65.             $this->setData('sectionId'$sectionId);
  66.             $this->setData('sectionKey'$sectionKey);
  67.             $this->setData('sectionNum'$sectionNum); //counting from 1
  68.             if(isset($sections[$sectionNum]) && ($sectionNum) < count($sections)){ //this is _this_ section, counting from zero
  69.                 $this->setData('nextSectionName'$sections[$sectionNum]["sectionName"]);
  70.                 $this->setData('nextSectionId'$sections[$sectionNum]["sectionID"]);
  71.                 $this->setData('nextSectionSlug',  $slugger->slug($sections[$sectionNum]["sectionName"]));
  72.                 $this->setData('nextSectionNum'$sectionNum 1); //counting from 1
  73.             }
  74.             else{
  75.                 $this->setData('nextSectionName'FALSE);
  76.                 $this->setData('nextSectionId'FALSE);
  77.                 $this->setData('nextSectionSlug'FALSE);
  78.                 $this->setData('nextSectionNum'FALSE);
  79.             }
  80.             
  81.             if(isset($sections[$sectionNum-1]) && ($sectionNum) > 1){ //this is _this_ section, counting from zero
  82.                 $this->setData('prevSectionName'$sections[$sectionNum-2]["sectionName"]);
  83.                 $this->setData('prevSectionId'$sections[$sectionNum-2]["sectionID"]);
  84.                 $this->setData('prevSectionSlug',  $slugger->slug($sections[$sectionNum-2]["sectionName"]));
  85.                 $this->setData('prevSectionNum'$sectionNum-1); //counting from 1
  86.             }
  87.             else{
  88.                 $this->setData('prevSectionName'FALSE);
  89.                 $this->setData('prevSectionId'FALSE);
  90.                 $this->setData('prevSectionSlug'FALSE);
  91.                 $this->setData('prevSectionNum'FALSE);
  92.             }
  93.             
  94. //            var_dump($this->getData('footer')); die();
  95.             return $this->render('signup/index.html.twig'$this->getData());
  96.         }
  97.         else{
  98.             return $this->redirectToRoute('profile');
  99.         }
  100.     }
  101.     
  102.     public function profile($sectionId NULL$sectionNameSlug NULL): Response
  103.     {
  104.         
  105.         $check $this->commonCalls();
  106.         if(!$check){
  107.             return $check;
  108.         }  
  109.         if($this->RedirectHandle!==NULL){
  110.             return $this->RedirectHandle;
  111.         }
  112.        
  113.         if($this->getUser()!==NULL){
  114.             
  115.      
  116.             $userData $this->ApiCalls->getProfile($this->getUser()->getEmail());
  117.             $check $this->handleDbErrors($userData);
  118.             if($check===FALSE){
  119.                 $this->setData('userData'$userData);
  120.             }
  121.             else{
  122.                 return $check;
  123.             }
  124.             
  125.             
  126.             
  127.             $sections $this->ApiCalls->businessRulesSectionsOnly($this->getUser()->getEmail());
  128.             if($sectionId === NULL){
  129.                 $sectionId $sections[0]["sectionID"];
  130.             }
  131.             
  132.             $businessRulesData $this->ApiCalls->businessRules($this->getUser()->getEmail(), $sectionId);
  133.             $slugger = new AsciiSlugger('en_GB');
  134.             
  135.             foreach($businessRulesData as $key=>$rule){            
  136.                 /*
  137.                  * refresh and display status if logged in
  138.                  */
  139.                 $businessRulesData[$key]['displayStatus'] = $this->getFieldDisplayStatus($rule);
  140.             }
  141.             
  142.             $this->setData('sections'$sections);
  143.             $this->setData('businessRulesData'$businessRulesData);
  144.             if($sectionNameSlug===NULL){
  145.                 $sectionName $sections[0]['sectionName'];
  146.                 $sectionNum 1
  147.             }
  148.             else{             
  149.                 foreach($sections as $key=>$section){
  150.                     $sectionNameToSlug trim($section['sectionName']);                
  151.                     $slug $slugger->slug($sectionNameToSlug);
  152.                     if($slug == $sectionNameSlug){
  153.                         $sectionName $section['sectionName'];
  154.                         $sectionNum $key+1;
  155.                     }
  156.                 }
  157.             }
  158.             $this->setData('sectionName'$sectionName);
  159.             $this->setData('sectionId'$sectionId);
  160.             $this->setData('sectionNum'$sectionNum); //counting from 1
  161.             if(isset($sections[$sectionNum]) && ($sectionNum 1) < count($sections)){ //this is the _next_ section, counting from zero
  162.                 $this->setData('nextSectionName'$sections[$sectionNum]["sectionName"]);
  163.                 $this->setData('nextSectionId'$sections[$sectionNum]["sectionID"]);
  164.                 $this->setData('nextSectionSlug',  $slugger->slug($sections[$sectionNum]["sectionName"]));
  165.                 $this->setData('nextSectionNum'$sectionNum 1); //counting from 1
  166.             }
  167.             else{
  168.                 $this->setData('nextSectionName'FALSE);
  169.                 $this->setData('nextSectionId'FALSE);
  170.                 $this->setData('nextSectionSlug'FALSE);
  171.                 $this->setData('nextSectionNum'FALSE);
  172.             }
  173.         }
  174.         else{
  175.             return $this->redirectToRoute('signin');
  176.         }
  177.      
  178.         return $this->render('profile/index.html.twig'$this->getData());
  179.     }
  180.     
  181.     public function success(){
  182.         
  183.         $check $this->commonCalls();
  184.         if(!$check){
  185.             return $check;
  186.         }  
  187.         if($this->RedirectHandle!==NULL){
  188.             return $this->RedirectHandle;
  189.         }
  190.         
  191.         $sections $this->ApiCalls->businessRulesSectionsOnly();
  192.         
  193.         $this->setData('sectionName''');
  194.         $this->setData('sectionId''');
  195.         $this->setData('sectionNum'count($sections)+1); //counting from 1
  196.         
  197.         $this->setData('sections'$sections);
  198.         
  199.         if($this->Session->get('reg-form')){
  200.             $this->Session->remove('reg-form');
  201.         }
  202.         
  203.         return $this->render('signup/success.html.twig'$this->getData());
  204.     }
  205.     
  206.     public function business_rules($sectionId$courseCode NULL){
  207.         if($this->getUser()){
  208.             $businessRulesData $this->ApiCalls->businessRules($this->getUser()->getEmail(), $sectionId, -1'webenrol'NULL$courseCode);            
  209.         }
  210.         else{
  211.             $businessRulesData $this->ApiCalls->businessRules(NULL$sectionId, -1'webenrol'NULL$courseCode);
  212.         }
  213.         return new JsonResponse($businessRulesData);
  214.     }
  215.     
  216.     public function checks($type){
  217.         switch($type){
  218.             case 'email_exists':
  219.                 $email $this->Http->request->get('email');                
  220.                 if($this->getUser()===NULL){
  221.                     $res $this->ApiCalls->emailExists($email);
  222.                 }
  223.                 else{                    
  224.                     $res $this->ApiCalls->emailExists($email$this->getUser()->getEmail());
  225.                 }
  226.         }
  227.         
  228.         return new JsonResponse($res);
  229.     }
  230.     
  231.     public function submit($courseCode NULL){
  232.         $formData $this->Http->request->all();
  233. //        var_dump($formData);
  234.         
  235. //        var_dump($this->Http->query->get('page'));
  236.         if($this->getUser()==NULL || $this->Http->query->get('page')=="application"){
  237.            
  238.             
  239.             if($this->Session->get('reg-form')){
  240.                 
  241.                 $curSession $this->Session->get('reg-form');
  242.                 foreach($formData as $key => $value){ 
  243.                     $curSession[$key] = $value;                
  244.                 }  
  245.                 $this->Session->set('reg-form'$curSession);            
  246.             }
  247.             else{                
  248.                 $this->Session->set('reg-form'$formData);
  249.             }
  250.         }
  251.         
  252.         if($this->Http->query->get('page')!=="application"){
  253.             $username NULL;
  254.         }
  255.         else{
  256.             if($this->getUser()){
  257.                 $username $this->getUser()->getEmail();
  258.             }
  259.             else{
  260.                 $username NULL;
  261.             }
  262.         }
  263.         
  264.         if($this->getUser()==NULL || $this->Http->query->get('page')=="application"){            
  265.             if($this->Http->query->get('finish')){                
  266.                 $finish TRUE;
  267.                 
  268.                 if($this->Http->query->get('page') && $this->Http->query->get('page')=='application'){
  269.                     $res $this->ApiCalls-> submitApplication($this->Session->get('reg-form'), $courseCode$username);
  270.                     
  271.                 }
  272.                 else{
  273.                     
  274.                     $res $this->ApiCalls-> submitSignup($this->Session->get('reg-form')); 
  275.                 }
  276.                 $data = ['finish'=>$finish'res'=>$res];
  277.             }
  278.             else{
  279.                 $finish FALSE;
  280.                 $data = ['finish'=>$finish];
  281.             }
  282.         }
  283.         else{
  284.             $res $this->ApiCalls-> updateProfile($formData$this->getUser()->getEmail());
  285.             $data = ['res'=>$res];
  286.         }
  287.         
  288. //        var_dump($this->Session->get('reg-form'));
  289.         return new JsonResponse($data);
  290.     }
  291.     
  292.     
  293.     
  294.     protected function getFieldDisplayStatus($field){
  295.         if($field['visible']===0){
  296.             return 'hide';
  297.         }
  298.         else if($field['requiresRefresh']===&& $field['required']===&& ($this->getUser()!==NULL)){
  299.             return 'disabled';
  300.         }
  301.         else if($field['requiresRefresh']===&& $field['required']===&& ($this->getUser()!==NULL)){
  302.             return 'hideIfEmpty'
  303.         }        
  304.         else{
  305.             return 'enable';
  306.         }        
  307.     }
  308.     
  309.     public function courseApplication($courseCode$sectionId NULL$sectionNameSlug NULL){       
  310.         $check $this->commonCalls(['getHomeNav','getCards','getFooter','getSearch']);
  311.         if(!$check){
  312.             return $check;
  313.         }
  314.        
  315.         
  316.         if($this->RedirectHandle!==NULL){
  317.             return $this->RedirectHandle;
  318.         }
  319.         
  320.         if($this->getUser()){
  321.             $userData $this->ApiCalls->getProfile($this->getUser()->getEmail());
  322.             $check $this->handleDbErrors($userData);
  323.             if($check===FALSE){
  324.                 $this->setData('userData'$userData);
  325.             }
  326.             else{
  327.                 return $check;
  328.             }
  329.             
  330.             $username $this->getUser()->getEmail();
  331.             $sessionID NULL;
  332.         }
  333.         else{
  334.             $username NULL;
  335.             $sessionID $this->getAnonymousID();
  336.         }
  337.        
  338.         $this->getAttentionMessage($username$courseCode);
  339.         
  340.         
  341.         
  342.         $sections $this->ApiCalls->businessRulesSectionsOnly($username$sectionId, -1'webenrol''webEnrolFlag1'NULL$courseCode);
  343.         if($sectionId === NULL){
  344.             $sectionId $sections[0]["sectionID"];
  345.         }
  346.         $this->getPageTexts($username$sessionID$courseCode$sectionId);
  347.         
  348.         $businessRulesData $this->ApiCalls->businessRules($username$sectionId, -1'webenrol'NULL$courseCode);
  349.         $slugger = new AsciiSlugger('en_GB');
  350.         foreach($businessRulesData as $key=>$rule){            
  351.             if($this->Session->get('reg-form')){                 
  352.                 foreach($this->Session->get('reg-form') as $formKey=>$value){ 
  353.                     if($businessRulesData[$key]['fieldname']===$formKey){
  354.                         $businessRulesData[$key]['value'] = $value;
  355.                     }
  356.                 }
  357.             }
  358.             /*
  359.              * refresh and display status if logged in
  360.              */
  361.             $businessRulesData[$key]['displayStatus'] = $this->getFieldDisplayStatus($rule);
  362.         }
  363.         
  364.         $this->setData('sections'$sections);
  365.         $this->setData('courseCode'$courseCode);
  366.         $this->setData('businessRulesData'$businessRulesData);
  367. //        var_dump($businessRulesData);
  368.         if($sectionNameSlug===NULL){
  369.             $sectionName $sections[0]['sectionName'];
  370.             $sectionNum 1
  371.             $sectionKey 0;
  372.         }
  373.         else{             
  374.             foreach($sections as $key=>$section){
  375.                 $sectionNameToSlug trim($section['sectionName']);                
  376.                 $slug $slugger->slug($sectionNameToSlug);
  377.                 if($slug == $sectionNameSlug){
  378.                     $sectionName $section['sectionName'];
  379.                     $sectionKey $key;
  380.                     $sectionNum $key+1;
  381.                 }
  382.             }
  383.         }            
  384.         $this->setData('sectionName'$sectionName);
  385.         $this->setData('sectionId'$sectionId);
  386.         $this->setData('sectionKey'$sectionKey);
  387.         $this->setData('sectionNum'$sectionNum); //counting from 1
  388.         if(isset($sections[$sectionNum]) && ($sectionNum) < count($sections)){ //this is _this_ section, counting from zero
  389.             $this->setData('nextSectionName'$sections[$sectionNum]["sectionName"]);
  390.             $this->setData('nextSectionId'$sections[$sectionNum]["sectionID"]);
  391.             $this->setData('nextSectionSlug',  $slugger->slug($sections[$sectionNum]["sectionName"]));
  392.             $this->setData('nextSectionNum'$sectionNum 1); //counting from 1
  393.         }
  394.         else{
  395.             $this->setData('nextSectionName'FALSE);
  396.             $this->setData('nextSectionId'FALSE);
  397.             $this->setData('nextSectionSlug'FALSE);
  398.             $this->setData('nextSectionNum'FALSE);
  399.         }
  400.         if(isset($sections[$sectionNum-1]) && ($sectionNum) > 1){ //this is _this_ section, counting from zero
  401.             $this->setData('prevSectionName'$sections[$sectionNum-2]["sectionName"]);
  402.             $this->setData('prevSectionId'$sections[$sectionNum-2]["sectionID"]);
  403.             $this->setData('prevSectionSlug',  $slugger->slug($sections[$sectionNum-2]["sectionName"]));
  404.             $this->setData('prevSectionNum'$sectionNum-1); //counting from 1
  405.         }
  406.         else{
  407.             $this->setData('prevSectionName'FALSE);
  408.             $this->setData('prevSectionId'FALSE);
  409.             $this->setData('prevSectionSlug'FALSE);
  410.             $this->setData('prevSectionNum'FALSE);
  411.         }
  412. //            var_dump($this->getData('footer')); die();
  413.         return $this->render('signup/application.html.twig'$this->getData());
  414.         
  415.     }
  416. }