<?php
namespace App\Controller;
use App\Constante\AppContante;
use App\Services\ApiService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use DateTime;
class HomeController extends AbstractController
{
private $apiService;
public function __construct(ApiService $apiService)
{
$this->apiService = $apiService;
}
/**
* @Route("/", name="app_home")
*/
public function index(): Response
{
$data = $this->apiService->getDataHomePage();
//dd($data);
return $this->render('pages/index.html.twig', array(
"data"=>$data,
"months"=>AppContante::MONTH_YEAR
));
}
/**
* @Route("/job-post", name="app_job_post")
*/
public function jobList(Request $request): Response
{
$contentRequest = $request->query->all();
//dd($contentRequest);
$data = $this->apiService->getListOffre($contentRequest);
//dd($data);
return $this->render('pages/job/job_post.html.twig',[
"data"=>$data
]);
}
/**
* @Route("/job-single/{refererence}", name="app_job_single")
*/
public function jobSingle($refererence): Response
{
$data = $this->apiService->getSingleOffre($refererence);
//dd($data);
$periods = [];
$current_period = [['jour'=> $data[0]["date"]["date"],'designation'=> $data[0]["designation"]]];
$data[0]["num_mission"]=1;
for ($i = 1; $i < count($data); $i++) {
$data[$i]["num_mission"]=$i+1;
$designation1 = $data[$i-1]["designation"];
$designation2 = $data[$i]["designation"];
$date1 = new DateTime($data[$i-1]["date"]["date"]);
$date2 = new DateTime($data[$i]["date"]["date"]);
$diff = $date1->diff($date2);
if ($diff->days === 1 && $designation1 === $designation2) {
$current_period[] = ['jour'=> $data[$i]["date"]["date"],'designation'=> $designation2];
} else {
$periods[] = $current_period;
$current_period = [['jour'=> $data[$i]["date"]["date"],'designation'=> $designation2]];
}
}
$periods[] = $current_period;
//dd($periods);
return $this->render('pages/job/job_single.html.twig',
array(
"data"=>$data,
"periods"=>$periods
));
}
/**
* @Route("/job-recrut", name="app_job_recrut")
*/
public function jobRecrut(): Response
{
return $this->render('pages/job/job_recrut.html.twig');
}
}