src/Controller/HomeController.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Constante\AppContante;
  4. use App\Services\ApiService;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use DateTime;
  10. class HomeController extends AbstractController
  11. {
  12.     private  $apiService;
  13.     public function __construct(ApiService $apiService)
  14.     {
  15.         $this->apiService $apiService;
  16.     }
  17.     /**
  18.      * @Route("/", name="app_home")
  19.      */
  20.     public function index(): Response
  21.     {
  22.         $data $this->apiService->getDataHomePage();
  23.         //dd($data);
  24.         return $this->render('pages/index.html.twig', array(
  25.             "data"=>$data,
  26.             "months"=>AppContante::MONTH_YEAR
  27.         ));
  28.     }
  29.     /**
  30.      * @Route("/job-post", name="app_job_post")
  31.      */
  32.     public function jobList(Request $request): Response
  33.     {
  34.         $contentRequest $request->query->all();
  35.         //dd($contentRequest);
  36.         $data $this->apiService->getListOffre($contentRequest);
  37.         //dd($data);
  38.         return $this->render('pages/job/job_post.html.twig',[
  39.             "data"=>$data
  40.         ]);
  41.     }
  42.     /**
  43.      * @Route("/job-single/{refererence}", name="app_job_single")
  44.      */
  45.     public function jobSingle($refererence): Response
  46.     {
  47.         $data $this->apiService->getSingleOffre($refererence);
  48.         //dd($data);
  49.         $periods = [];
  50.         $current_period = [['jour'=> $data[0]["date"]["date"],'designation'=> $data[0]["designation"]]];
  51.         $data[0]["num_mission"]=1;
  52.         for ($i 1$i count($data); $i++) {
  53.             $data[$i]["num_mission"]=$i+1;
  54.             $designation1 $data[$i-1]["designation"];
  55.             $designation2 $data[$i]["designation"];
  56.             $date1 = new DateTime($data[$i-1]["date"]["date"]);
  57.             $date2 = new DateTime($data[$i]["date"]["date"]);
  58.             $diff $date1->diff($date2);
  59.         
  60.             if ($diff->days === && $designation1 === $designation2) {
  61.                 
  62.                 $current_period[] = ['jour'=> $data[$i]["date"]["date"],'designation'=> $designation2];
  63.             } else {
  64.                
  65.                 $periods[] = $current_period;
  66.                 $current_period = [['jour'=> $data[$i]["date"]["date"],'designation'=> $designation2]];
  67.             }
  68.         }
  69.         
  70.     
  71.         $periods[] = $current_period;
  72.         
  73.         //dd($periods);
  74.         return $this->render('pages/job/job_single.html.twig',
  75.         array(
  76.             "data"=>$data,
  77.             "periods"=>$periods
  78.         ));
  79.     }
  80.     /**
  81.      * @Route("/job-recrut", name="app_job_recrut")
  82.      */
  83.     public function jobRecrut(): Response
  84.     {
  85.         return $this->render('pages/job/job_recrut.html.twig');
  86.     }
  87. }