src/Controller/FrontEndController.php line 188

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. /**
  4.  * Created by PhpStorm.
  5.  * User: C
  6.  * Date: 12/24/2018
  7.  * Time: 1:18 PM
  8.  */
  9. use App\Entity\Company;
  10. use App\Entity\Ebook;
  11. use App\Entity\GridThreeSixtySections;
  12. use App\Entity\GridThreeSixtySurvey;
  13. use App\Entity\GridThreeSixtySurveyResponses;
  14. use App\Entity\Group;
  15. use App\Entity\Pages;
  16. use App\Entity\Question;
  17. use App\Entity\Student;
  18. use App\Entity\Survey;
  19. use App\Entity\SurveySent;
  20. use App\Entity\Team;
  21. use App\Entity\Trainer;
  22. use App\Entity\Users;
  23. use PhpParser\Node\Stmt\Else_;
  24. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\Response;
  27. class FrontEndController extends DefaultController
  28. {
  29.     public function home(Request $request)
  30.     {
  31.         if($this->isGranted('ROLE_SUPER_ADMIN')) {
  32.             $entityManager $this->getDoctrine()->getManager();
  33.             $conn $entityManager->getConnection();
  34.             $countBook  =1;
  35.             $sql 'select count(id) as count  from student ';
  36.             $stmt $conn->prepare($sql);
  37.             $stmt->execute();
  38.             $countstudent =  $stmt->fetchall();
  39.             $sql 'select count(id) as count  from trainer ';
  40.             $stmt $conn->prepare($sql);
  41.             $stmt->execute();
  42.             $countTrainers =  $stmt->fetchall();
  43.             $sql 'select count(id) as count  from group_class ';
  44.             $stmt $conn->prepare($sql);
  45.             $stmt->execute();
  46.             $countClasses =  $stmt->fetchall();
  47.             return $this->render('admin/home.html.twig',array(
  48.                 'countBook'=>$countBook,
  49.                 'countStudent'=>$countstudent[0]['count'],
  50.                 'countClasses'=>$countClasses[0]['count'],
  51.                 'countTrainers'=>$countTrainers[0]['count'],
  52.             ));
  53.         }
  54.         else{
  55.             return $this->redirectToRoute('user_home');
  56.         }
  57.     }
  58.     public function ebookList(Request $request)
  59.     {
  60.         $books $this->getDoctrine()
  61.             ->getRepository(Ebook::class)
  62.             ->findAll();
  63.         return $this->render('admin/ebook-list.html.twig',array('books'=>$books));
  64.     }
  65.     public function ebookPreview(Request $request)
  66.     {
  67.         $id =$request->request->get('id');
  68.         $book $this->getDoctrine()
  69.             ->getRepository(Ebook::class)
  70.             ->find($id);
  71.         $pages $this->getDoctrine()
  72.             ->getRepository(Pages::class)
  73.             ->findBy(array('book'=>$book),array('pageNumber'=>'ASC'));
  74.         return $this->render('admin/ebook-preview.html.twig',array('pages'=>$pages));
  75.     }
  76.     public function classList(Request $request)
  77.     {
  78.         $groups $this->getDoctrine()
  79.             ->getRepository(Group::class)
  80.             ->findAll();
  81.         return $this->render('admin/class-list.html.twig',array('groups'=>$groups));
  82.     }
  83.     public function activeClassList(Request $request)
  84.     {
  85.         if($this->isGranted('ROLE_SUPER_ADMIN')) {
  86.             $groups $this->getDoctrine()
  87.                 ->getRepository(Group::class)
  88.                 ->findAll();
  89.         }else{
  90.             $user$this->getUser();
  91.             $trainer $this->getDoctrine()
  92.                 ->getRepository(Trainer::class)
  93.                 ->findOneBy( array('id'=>$user));
  94.             $groups =$trainer->getGroup();
  95.         }
  96.         return $this->render('admin/active-class-list.html.twig',array('groups'=>$groups ));
  97.     }
  98.     public function activeClassView(Request $request){
  99.         $id =$request->request->get('id');
  100.         $groups $this->getDoctrine()
  101.             ->getRepository(Group::class)
  102.             ->find($id);
  103.         if($request->request->has('bookId')){
  104.             $bookId =$request->request->get('bookId');
  105.             $book $this->getDoctrine()
  106.                 ->getRepository(Pages::class)
  107.                 ->find($bookId);
  108.             $pages $this->getDoctrine()
  109.                 ->getRepository(Pages::class)
  110.                 ->findBy(array('book'=>$book),array('pageNumber'=>'ASC'));
  111.         }
  112.         else{
  113.             $book $groups->getBook()[0];
  114.             $pages $this->getDoctrine()
  115.                 ->getRepository(Pages::class)
  116.                 ->findBy(array('book'=>$book),array('pageNumber'=>'ASC'));
  117.         }
  118.         if($request->request->has('student')) {
  119.             $studentId$request->request->get('student');
  120.         }else{
  121.             $studentId =  $groups->getStudent()[0];
  122.             $studentId$studentId->getId()->getId();
  123.         }
  124.         return $this->render('admin/active-class-View.html.twig',array('groups'=>$groups ,'book'=>$book,'pages'=>$pages,'studentId'=>$studentId));
  125.     }
  126.     public function GridThreeSixtySurveyList($type,Request $request)
  127.     {
  128.         $gridThreeSixtySurveys $this->getDoctrine()
  129.             ->getRepository(GridThreeSixtySurvey::class)
  130.             ->findBy(array(
  131.                 'type'=>$type
  132.             ));
  133.         return $this->render('admin/grid-three-sixty-survey-list.html.twig',array('gridThreeSixtySurveys'=>$gridThreeSixtySurveys,'type'=>$type));
  134.     }
  135.     public function trainerList(Request $request)
  136.     {$trainers $this->getDoctrine()
  137.         ->getRepository(Trainer::class)
  138.         ->findAll();
  139.         return $this->render('admin/trainer-list.html.twig',array('trainers'=>$trainers));
  140.     }
  141.     public function StudentList(Request $request)
  142.     {$students $this->getDoctrine()
  143.         ->getRepository(Student::class)
  144.         ->findAll();
  145.         return $this->render('company/student-list.html.twig',array('students'=>$students));
  146.     }
  147.     public function trainerCreate(Request $request)
  148.     {
  149.         $id =$request->request->get('id');
  150.         if($id!=0){
  151.             $user $this->getDoctrine()
  152.                 ->getRepository(Users::class)
  153.                 ->find($id);
  154.             $trainer $this->getDoctrine()
  155.                 ->getRepository(Trainer::class)
  156.                 ->findOneBy(array('id'=>$user));
  157.         }
  158.         else{
  159.             $trainer null;
  160.         }
  161.         return $this->render('admin/trainer-create.html.twig',array('trainer'=>$trainer));
  162.     }
  163.   public function studentCreate(Request $request)
  164.     {
  165.         $id =$request->request->get('id');
  166.         if($id!=0){
  167.             $user $this->getDoctrine()
  168.                 ->getRepository(Users::class)
  169.                 ->find($id);
  170.             $student $this->getDoctrine()
  171.                 ->getRepository(Student::class)
  172.                 ->findOneBy(array('id'=>$user));
  173.         }
  174.         else{
  175.             $student null;
  176.         }
  177.         $companies $this->getDoctrine()
  178.             ->getRepository(Company::class)
  179.             ->findAll();
  180.         $teams $this->getDoctrine()
  181.             ->getRepository(Team::class)
  182.             ->findAll();
  183.         $students $this->getDoctrine()
  184.             ->getRepository(Student::class)
  185.             ->findAll();
  186.         return $this->render('company/student-create.html.twig',array('student'=>$student,
  187.             'teams'=>$teams,
  188.             'companies'=>$companies,'students'=>$students));
  189.     }
  190.   public function studentCreateBulk(Request $request)
  191.     {
  192.         $id =$request->request->get('id');
  193.         if($id!=0){
  194.             $user $this->getDoctrine()
  195.                 ->getRepository(Users::class)
  196.                 ->find($id);
  197.             $student $this->getDoctrine()
  198.                 ->getRepository(Student::class)
  199.                 ->findOneBy(array('id'=>$user));
  200.         }
  201.         else{
  202.             $student null;
  203.         }
  204.         $companies $this->getDoctrine()
  205.             ->getRepository(Company::class)
  206.             ->findAll();
  207.         $teams $this->getDoctrine()
  208.             ->getRepository(Team::class)
  209.             ->findAll();
  210.         return $this->render('company/student-create-bulk.html.twig',array('student'=>$student,
  211.             'teams'=>$teams,
  212.             'companies'=>$companies));
  213.     }
  214.   public function CompanyList(Request $request)
  215.     {$companies $this->getDoctrine()
  216.         ->getRepository(Company::class)
  217.         ->findAll();
  218.         return $this->render('company/company-list.html.twig',array('companies'=>$companies));
  219.     }
  220.   public function CompanyCreate(Request $request)
  221.     {
  222.         $id =$request->request->get('id');
  223.         if($id!=0){
  224.             $company $this->getDoctrine()
  225.                 ->getRepository(Company::class)
  226.                 ->find($id);
  227.         }
  228.         else{
  229.             $company null;
  230.         }
  231.         return $this->render('company/company-create.html.twig',array('company'=>$company));
  232.     }
  233.   public function TeamList(Request $request)
  234.     {
  235.         $teams $this->getDoctrine()
  236.         ->getRepository(Team::class)
  237.         ->findAll();
  238.         return $this->render('company/team-list.html.twig',array('teams'=>$teams));
  239.     }
  240.   public function TeamCreate(Request $request)
  241.     {
  242.         $companies $this->getDoctrine()
  243.             ->getRepository(Company::class)
  244.             ->findAll();
  245.         $id =$request->request->get('id');
  246.         if($id!=0){
  247.             $team $this->getDoctrine()
  248.                 ->getRepository(Team::class)
  249.                 ->find($id);
  250.         }
  251.         else{
  252.             $team null;
  253.         }
  254.         return $this->render('company/team-create.html.twig',array('team'=>$team,'companies'=>$companies));
  255.     }
  256.   public function classCreate(Request $request)
  257.     {
  258.         $books $this->getDoctrine()
  259.             ->getRepository(Ebook::class)
  260.             ->findAll();
  261.         $trainers $this->getDoctrine()
  262.             ->getRepository(Trainer::class)
  263.             ->findAll();
  264.         $id =$request->request->get('id');
  265.         if($id!=0){
  266.             $group $this->getDoctrine()
  267.                 ->getRepository(Group::class)
  268.                 ->find($id);
  269.         }
  270.         else{
  271.             $group null;
  272.         }
  273.         $companies $this->getDoctrine()
  274.             ->getRepository(Company::class)
  275.             ->findAll();
  276.         $teams $this->getDoctrine()
  277.             ->getRepository(Team::class)
  278.             ->findAll();
  279.         $students $this->getDoctrine()
  280.             ->getRepository(Student::class)
  281.             ->findAll();
  282.         return $this->render('admin/class-create.html.twig',array('group'=>$group,
  283.             'books'=>$books,
  284.             'trainers'=>$trainers,'companies'=>$companies,'teams'=>$teams,'students'=>$students));
  285.     }
  286.   public function GridThreeSixtySurveyCreate(Request $request)
  287.     {
  288.         $id =$request->request->get('id');
  289.         $type =$request->request->get('type');
  290.         if($id!=0){
  291.             $gridThreeSixtySurvey $this->getDoctrine()
  292.                 ->getRepositoryGridThreeSixtySurvey::class)
  293.                 ->find($id);
  294.             $entityManager $this->getDoctrine()->getManager();
  295.             $conn $entityManager->getConnection();
  296.             $sql "SELECT GROUP_CONCAT(grid_three_sixty_survey_response.student_id) AS students ,TYPE as surveyType ,matter_student_id 
  297.                             FROM grid_three_sixty_survey_response WHERE grid_three_sixty_survey_response.survey_id = ".$id." GROUP BY 
  298.                             grid_three_sixty_survey_response.matter_student_id,grid_three_sixty_survey_response.`type` ";
  299.             $stmt $conn->prepare($sql);
  300.             $stmt->execute();
  301.             $gridThreeSixtySurveyResonses =  $stmt->fetchall();
  302.             $gridThreeSixtyRow = array();
  303.             $matterId 0;
  304.             foreach ($gridThreeSixtySurveyResonses as $row){
  305.                 if($row['matter_student_id']!=$matterId){
  306.                     if(isset($newRow) ){
  307.                         $gridThreeSixtyRow[]= $newRow;
  308.                     }
  309.                     $matterId =$row['matter_student_id'];
  310.                     $newRow = array();
  311.                 }
  312.                 $newRow[$row['surveyType']] = $row['students'];
  313.             }
  314.             $gridThreeSixtyRow[]= $newRow;
  315.         }
  316.         else{
  317.             $gridThreeSixtySurvey = new GridThreeSixtySurvey();
  318.             $gridThreeSixtyRow =array();
  319.         }
  320.         $gridThreeSixtySurvey->setType($type);
  321.         $companies $this->getDoctrine()
  322.             ->getRepository(Company::class)
  323.             ->findAll();
  324.         $teams $this->getDoctrine()
  325.             ->getRepository(Team::class)
  326.             ->findAll();
  327.          $students $this->getDoctrine()
  328.                     ->getRepository(Student::class)
  329.                     ->findAll();
  330.         return $this->render('admin/grid-three-sixty-survey-create.html.twig',array('gridThreeSixtySurvey'=>$gridThreeSixtySurvey,
  331.             'companies'=>$companies,'teams'=>$teams,'students'=>$students,'error_list'=>null,'gridThreeSixtyRow'=>$gridThreeSixtyRow));
  332.     }
  333.   public function surveyCreate(Request $request)
  334.     {
  335.         $id =$request->request->get('id');
  336.         if($id!=0){
  337.             $survey $this->getDoctrine()
  338.                 ->getRepository(Survey::class)
  339.                 ->find($id);
  340.         }
  341.         else{
  342.             $survey null;
  343.         }
  344.         $companies $this->getDoctrine()
  345.             ->getRepository(Company::class)
  346.             ->findAll();
  347.         $teams $this->getDoctrine()
  348.             ->getRepository(Team::class)
  349.             ->findAll();
  350.         $students $this->getDoctrine()
  351.             ->getRepository(Student::class)
  352.             ->findAll();
  353.         return $this->render('admin/survey-create.html.twig',array('survey'=>$survey,
  354.            'type'=>$request->request->get('type'), 'companies'=>$companies,'teams'=>$teams,'students'=>$students,'error_list'=>null));
  355.         }
  356.   public function QuestionsList($type,Request $request){
  357.         $questions $this->getDoctrine()
  358.             ->getRepository(Question::class)
  359.             ->findBy (array('type'=>$type));
  360.         return $this->render('admin/question-list.html.twig',array('questions'=>$questions,'type'=>$type));
  361.   }
  362.     public function SurveyList($type,Request $request){
  363.         $surveys $this->getDoctrine()
  364.             ->getRepository(Survey::class)
  365.             ->findBy(array(
  366.                 'type'=>$type
  367.             ));
  368.         return $this->render('admin/survey-list.html.twig',array('surveys'=>$surveys,'type'=>$type));
  369.     }
  370.     public function GridThreeSixtyList($type,Request $request){
  371.         $sections $this->getDoctrine()
  372.             ->getRepository(GridThreeSixtySections::class)
  373.             ->findBy(
  374.                 array('type'=>$type)
  375.             );
  376.         return $this->render('admin/grid-three-sixty-list.html.twig',array('sections'=>$sections));
  377.     }
  378.     public function GridThreeSixtyEditPage(Request $request){
  379.         $id =$request->request->get('id');
  380.         $section $this->getDoctrine()
  381.             ->getRepository(GridThreeSixtySections::class)
  382.             ->find($id);
  383.         return $this->render('admin/grid-three-sixty-create.html.twig',array('section'=>$section));
  384.     }
  385.   public function QuestionEditPage(Request $request){
  386.       $id =$request->request->get('id');
  387.       $question $this->getDoctrine()
  388.             ->getRepository(Question::class)
  389.             ->find($id);
  390.         return $this->render('admin/question-create.html.twig',array('question'=>$question));
  391.     }
  392.     public function QuestionEdit(Request $request){
  393.       $id =$request->request->get('id','');
  394.       $question $this->getDoctrine()
  395.             ->getRepository(Question::class)
  396.             ->find($id);
  397.         return $this->render('admin/question-create.html.twig',array('question'=>$question));
  398.     }
  399.     //UserPages
  400.     public function userHome(Request $request){
  401.         $entityManager $this->getDoctrine()->getManager();
  402.         $conn $entityManager->getConnection();
  403.         $sql 'select DISTINCT(ebook.id)
  404. ,ebook.name 
  405. from ebook,book_group,student_group
  406. where 
  407. ebook.id = book_group.book_id 
  408. and book_group.group_id = student_group.group_id
  409. and student_group.student_id = :student_id ';
  410.         $stmt $conn->prepare($sql);
  411.         $stmt->execute(['student_id'=>$this->getUser()->getId()]);
  412.         $books =  $stmt->fetchall();
  413.         $sql '
  414.             select grid_three_sixty_survey.name , 
  415.                    grid_three_sixty_survey.id ,
  416.                    grid_three_sixty_survey.end_date 
  417.             from grid_three_sixty_survey,grid_three_sixty_survey_response 
  418.             where grid_three_sixty_survey.id = grid_three_sixty_survey_response.survey_id 
  419.             and grid_three_sixty_survey_response.student_id = :student_id 
  420.             group BY grid_three_sixty_survey.name , grid_three_sixty_survey.id ,grid_three_sixty_survey.end_date
  421.  ';
  422.         $stmt $conn->prepare($sql);
  423.         $stmt->execute(['student_id'=>$this->getUser()->getId()]);
  424.         $gridSurveys =  $stmt->fetchall();
  425.         $date = new \DateTime();
  426.         $dateFormated date_format($date'Y-m-d');
  427.         $sql 'select survey.name ,survey.id ,survey.end_date  from survey,student_survey
  428.           where survey.id = student_survey.survey_id
  429.           and student_survey.student_id = :student_id
  430.           and Date(survey.end_date) >= :dateFormated  ';
  431.         $stmt $conn->prepare($sql);
  432.         $stmt->execute(['student_id'=>$this->getUser()->getId(),
  433.             'dateFormated'=>$dateFormated]);
  434.         $surveys =  $stmt->fetchall();
  435.         return $this->render('user/home.html.twig',
  436.             array(
  437.                 'books'=>$books,
  438.                 'gridSurveys'=>$gridSurveys,
  439.                 'surveys'=>$surveys
  440.             ));
  441.     }
  442.     public function userEbookPreview(Request $request)
  443.     {
  444.         $id =$request->request->get('id');
  445.         $book $this->getDoctrine()
  446.             ->getRepository(Ebook::class)
  447.             ->find($id);
  448.         $pages $this->getDoctrine()
  449.             ->getRepository(Pages::class)
  450.             ->findBy(array('book'=>$book),array('pageNumber'=>'ASC'));
  451.         return $this->render('user/ebook-preview.html.twig',array('pages'=>$pages,'book'=>$book));
  452.     }
  453.     public function userGridSuerveyPage(Request $request)
  454.     {
  455.         $id =$request->request->get('id');
  456.         $user  $this->getUser();
  457.         $entityManager $this->getDoctrine()->getManager();
  458.         $conn $entityManager->getConnection();
  459.         $sql 'select grid_three_sixty_survey_response.id,student.first_name,grid_three_sixty_survey_response.status from grid_three_sixty_survey_response , student
  460.                 where grid_three_sixty_survey_response.student_id = :student_id
  461.                 and grid_three_sixty_survey_response.survey_id=:survey_id
  462.                 and student.id = grid_three_sixty_survey_response.matter_student_id
  463.             ';
  464.         $stmt $conn->prepare($sql);
  465.         $stmt->execute(['student_id'=>$this->getUser()->getId(),
  466.             'survey_id'=>$id]);
  467.         $gridSurveys =  $stmt->fetchall();
  468.         if($gridSurveys==null)
  469.             $this->redirectToRoute('user_home');
  470.         $student $entityManager->getRepository(Student::class)
  471.             ->findOneBy(array('id'=>$user));
  472.         $survey $entityManager->getRepository(GridThreeSixtySurvey::class)->find($id);
  473.         $sections =    $this->getDoctrine()
  474.             ->getRepository(GridThreeSixtySections::class)
  475.             ->findby(
  476.                 array('type'=>$survey->getType())
  477.             );
  478.         return $this->render('user/grid-three-sixty-survey.html.twig',array(
  479.             'sections'=>$sections,'gridSurveys'=>$gridSurveys));
  480.     }
  481.     public function userServeyPage(Request $request){
  482.         $entityManager $this->getDoctrine()->getManager();
  483.         $id =$request->request->get('id');
  484.         $user $this->getUser();
  485.         if ($user != null) {
  486.             $survey $entityManager->getRepository(SurveySent::class)
  487.                 ->findOneBy(
  488.                     array('userid' => $user->getId(),
  489.                           'status' => 0,
  490.                           'surveyid'=>$id
  491.                     )
  492.                 );
  493.             if ($survey != null) {
  494.                 $SurveyObject $entityManager->getRepository(Survey::class)
  495.                     ->find($id);
  496.                 $currentdate = new \DateTime();
  497.                 //  get user from token
  498.                 //student survey
  499.                 //betjib el user b aya
  500.                 $question $entityManager->getRepository(Question::class)
  501.                     ->findBy(array(
  502.                         'type'=>$SurveyObject->getType()
  503.                     ));
  504.                 $student $entityManager->getRepository(Student::class)
  505.                     ->findOneBy(array(
  506.                         'id'=>$user
  507.                     ));
  508.                 if ($SurveyObject->getEndDate() > $currentdate and $SurveyObject->getStartDate() < $currentdate) {
  509.                     if($SurveyObject->getType()==3){
  510.                         return $this->render('user/surveyArabic.html.twig', array('questions' => $question'survey' => $survey'SurveyObject' => $SurveyObject));
  511.                     }
  512.                     return $this->render('user/survey.html.twig', array('questions' => $question'survey' => $survey'SurveyObject' => $SurveyObject));
  513.                 } else {
  514.                     return $this->redirectToRoute('home');
  515.                 }
  516.             }
  517.         }
  518.         return $this->redirectToRoute('home');
  519.     }
  520.     public function GridThreeSixtyReportList(Request $request){
  521.         $entityManager $this->getDoctrine()->getManager();
  522.         $conn $entityManager->getConnection();
  523.         $id$request->request->get('id');
  524.         $sql 'SELECT count(`grid_three_sixty_survey_response`.id) as nb_survey,`grid_three_sixty_survey_response`.matter_student_id,survey_id,users.username,student.first_name FROM `grid_three_sixty_survey_response`,`student`,`users`
  525. WHERE `student`.`id` = `grid_three_sixty_survey_response`.`matter_student_id` and  `student`.`id` = `users`.`id`
  526. and `grid_three_sixty_survey_response`.survey_id = :survey_id
  527. group by matter_student_id ';
  528.         $stmt $conn->prepare($sql);
  529.         $stmt->execute([
  530.             'survey_id'=>$id]);
  531.         $UserReportList =  $stmt->fetchall();
  532.         return $this->render('admin/grid-three-sixty-survey-report-list.html.twig',array('userReportList'=>$UserReportList));
  533.     }
  534. }