src/Controller/DashboardController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Contact;
  4. use App\Entity\Customer;
  5. use App\Entity\Status;
  6. use App\Entity\Ticket;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class DashboardController extends AbstractController
  12. {
  13. #[Route('/', name: 'app_dashboard')]
  14. public function index(CustomerController $customerController): Response
  15. {
  16. $em = $this->getDoctrine()->getManager();
  17. if($this->getUser()->getFirstConnexion()){
  18. return $this->redirectToRoute('app_user_profil');
  19. }
  20. $listCustomers = $em->getRepository(Customer::class)->findBy(array(), array("name" => "ASC"));
  21. /**
  22. *? RETRIEVE THE CUSTOMER OF CONTACT
  23. **/
  24. $listContacts = $em->getRepository(Contact::class)->getListContacts()->getQuery()->getArrayResult();
  25. foreach ($listContacts as $key => &$contact) {
  26. $listCustomer = $em->getRepository(Customer::class)->getCustomerByContact($contact['id'])->getQuery()->getResult();
  27. if($listCustomer !== null){
  28. foreach ($listCustomer as $customer){
  29. $contact['listCustomers'][] = array("id" => $customer->getId(), "name" => $customer->getName());
  30. }
  31. }
  32. }
  33. $listTickets = $em->getRepository(Ticket::class)->findBy(array(), array("id" => "DESC"));
  34. $listStatus = $em->getRepository(Status::class)->getListStatus()->getQuery()->getArrayResult();
  35. $dateTime = new \DateTime();
  36. $year = $dateTime->format('Y');
  37. $arrayYear = array(
  38. (int) $year - 3,
  39. (int) $year - 2,
  40. (int) $year - 1,
  41. (int) $year,
  42. );
  43. $today = $year;
  44. if($dateTime->format('m') < 10){
  45. $today .= "-".str_replace("0", "", $dateTime->format('m'));
  46. } else {
  47. $today .= "-".$dateTime->format('m');
  48. }
  49. $numWeek = $dateTime->format("W");
  50. return $this->render('dashboard/index.html.twig', [
  51. "listCustomers" => $listCustomers,
  52. "listContacts" => $listContacts,
  53. "listTickets" => $listTickets,
  54. "listStatus" => $listStatus,
  55. "arrayYear" => $arrayYear,
  56. "today" => $today,
  57. "numWeek" => $numWeek
  58. ]);
  59. }
  60. }