<?php
namespace App\Controller;
use App\Services\ExpedienteService;
use App\Services\FGJEMService;
use Pimcore\Controller\FrontendController;
use Pimcore\Log\ApplicationLogger;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use DateTime;
use DateTimeZone;
class HomeController extends FrontendController
{
/**
* @var ApplicationLogger
*/
private $logger;
public function __construct(ApplicationLogger $logger)
{
$this->logger = $logger;
}
/**
* @Route("/es", name="home-index", methods={"GET"})
*
* @param Request $request
*
* @return Response|RedirectResponse
*
* @throws \Exception
*/
public function indexAction(Request $request, ExpedienteService $serviceCOBUPEM, FGJEMService $serviceFGJEM)
{
$cobupem = array();
$fgjem = array();
$fechaTimezone = $this->convertDateFromTimezone(null, 'UTC', 'America/Mexico_City', 'Y-m-d');
$fechaAnterior = date('d/m/Y', strtotime('-1 day', strtotime($fechaTimezone)));
$fechaActual = date('d/m/Y', strtotime($fechaTimezone));
$cobupemWS = $serviceCOBUPEM->obtenerRegistros('', '', '', '', '');
$fiscalia = $serviceFGJEM->obtenerRegistros('', '', '', '', '', $fechaAnterior, $fechaActual);
if ($cobupemWS) {
// $this->logger->info(json_encode($cobupemWS));
$cobupem = $cobupemWS;
}
if ($fiscalia) {
// $this->logger->info(json_encode($fiscalia));
$fgjem = $fiscalia;
}
return $this->render('home/index.html.twig', [
'cobupem' => $cobupem,
'fgjem' => $fgjem,
]);
}
private function convertDateFromTimezone($date, $timezone, $timezone_to, $format) {
$date = new DateTime($date, new DateTimeZone($timezone));
$date->setTimezone(new DateTimeZone($timezone_to));
return $date->format($format);
}
}