<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\{Request, Response};
use Symfony\Component\Routing\Annotation\Route;
use App\Utils\Ticketing;
use App\Utils\Functions;
class EventController extends AbstractController
{
private $ticketing;
private $functions;
public function __construct(Ticketing $ticketing, Functions $functions)
{
$this->ticketing = $ticketing;
$this->functions = $functions;
}
/**
* @Route("/events", name="events")
*/
public function events(Request $request): Response
{
$session = $request->getSession();
if($request->get("ref")){
$session->set('ref', $request->get("ref"));
}
$events = $this->ticketing->curl("events?orderBy=eventDate&order=ASC", "normal", array(), "GET");
if(!$events || $events["code"]!="200"){
$this->addFlash(
'notice',
'No se han encontrado eventos!'
);
return $this->redirectToRoute('home');
}
return $this->render('events/events.html.twig', [
"events" => $events["events"],
]);
}
/**
* @Route("/event-tickets", name="event-tickets")
*/
public function eventTickets(Request $request): Response
{
$session = $request->getSession();
$filters=array_filter($request->query->all());
if($request->get("ref")){
$session->set('ref', $request->get("ref"));
}
if(!$request->get("event")){
$this->addFlash(
'notice',
'No se puede acceder al evento'
);
return $this->redirectToRoute('home');
}
$eventId=$request->get("event");
$event = $this->ticketing->curl("events/".$eventId, "normal", array(), "GET");
if(!$event || $event["code"]!="200" || !$event["enabled"]){
$this->addFlash(
'notice',
'No se puede acceder al evento'
);
return $this->redirectToRoute('home');
}
if($request->get("format")){
$format=$request->get("format");
}else{
$format=1;
};
if(!$request->get("order") || $request->get("order")==1){
if(!$request->get("format") || $request->get("format")=="1"){
$limit=4;
}
else{
$limit=100;
}
}
else{
$limit=100;
}
$configs=array("limit" => $limit, "small" => 1, "group" => 1, "type" => 2);
foreach($configs as $key => $config){
$request->request->set($key, $config);
$filters[$key]=$config;
}
return $this->render('events/event-tickets.html.twig', [
'filters' => $filters,
'format' => $format,
'event' => $event
]);
}
}