<?php
namespace App\Controller;
use App\Entity\Demande;
use DateTime;
use Google_Client;
use Google_Service_Calendar;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Workflow\Registry;
class PageController extends Controller
{
/**
* @Route("/connexion",name="connect")
*/
public function index()
{
$auth_checker = $this->get('security.authorization_checker');
if ($auth_checker->isGranted('ROLE_USER')) {
return $this->redirectToRoute('dashboard');
}
return $this->render('page/page-login.html.twig');
}
/**
* @Route("/logout", name="security_logout")
* @throws \Exception
*/
public function logout()
{
throw new \Exception('Problème de déconnexion');
}
/**
* @Route("/",name="dashboard")
*/
public function rootPage()
{
$soldeOld = $this->getDoctrine()->getRepository('App:Solde')
->findOneBy([
'Annee' => intval((new \DateTime())->format('Y'))-1,
'Employe' => $this->getUser()
]);
if($soldeOld) {
$soldeOld = $soldeOld->getRestant();
} else {
$soldeOld = 0;
}
$soldeNew = $this->getDoctrine()->getRepository('App:Solde')
->findOneBy([
'Annee' => (new \DateTime())->format('Y'),
'Employe' => $this->getUser()
])->getRestant();
$listeCongesCY = $this->getDoctrine()->getRepository('App:Demande')
->findCongesPourAnneeCourante($this->getUser());
$congeParMois = [0,0,0,0,0,0,0,0,0,0,0,0];
foreach ($listeCongesCY as $congeCY) {
$congeParMois[intval($congeCY->getDateDeb()->format('m'))-1] += $congeCY->getNombreJours();
}
return $this->render("page/accueil.html.twig",[
'congesCY' => $congeParMois,
'Sn' => $soldeNew,
'So' => $soldeOld
]);
}
}