<?php
namespace App\Controller;
use App\Entity\Contact;
use App\Entity\Customer;
use App\Entity\Status;
use App\Entity\Ticket;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractController
{
#[Route('/', name: 'app_dashboard')]
public function index(CustomerController $customerController): Response
{
$em = $this->getDoctrine()->getManager();
if($this->getUser()->getFirstConnexion()){
return $this->redirectToRoute('app_user_profil');
}
$listCustomers = $em->getRepository(Customer::class)->findBy(array(), array("name" => "ASC"));
/**
*? RETRIEVE THE CUSTOMER OF CONTACT
**/
$listContacts = $em->getRepository(Contact::class)->getListContacts()->getQuery()->getArrayResult();
foreach ($listContacts as $key => &$contact) {
$listCustomer = $em->getRepository(Customer::class)->getCustomerByContact($contact['id'])->getQuery()->getResult();
if($listCustomer !== null){
foreach ($listCustomer as $customer){
$contact['listCustomers'][] = array("id" => $customer->getId(), "name" => $customer->getName());
}
}
}
$listTickets = $em->getRepository(Ticket::class)->findBy(array(), array("id" => "DESC"));
$listStatus = $em->getRepository(Status::class)->getListStatus()->getQuery()->getArrayResult();
$dateTime = new \DateTime();
$year = $dateTime->format('Y');
$arrayYear = array(
(int) $year - 3,
(int) $year - 2,
(int) $year - 1,
(int) $year,
);
$today = $year;
if($dateTime->format('m') < 10){
$today .= "-".str_replace("0", "", $dateTime->format('m'));
} else {
$today .= "-".$dateTime->format('m');
}
$numWeek = $dateTime->format("W");
return $this->render('dashboard/index.html.twig', [
"listCustomers" => $listCustomers,
"listContacts" => $listContacts,
"listTickets" => $listTickets,
"listStatus" => $listStatus,
"arrayYear" => $arrayYear,
"today" => $today,
"numWeek" => $numWeek
]);
}
}