Files
aux-bieaux-legumes/local/modules/Agenda/Controller/EventController.php

34 lines
1.2 KiB
PHP

<?php
namespace Agenda\Controller;
use Agenda\Model\AgendaContentDate;
use Agenda\Model\AgendaContentDateQuery;
use OpenApi\Controller\Front\BaseFrontOpenApiController;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Model\Lang;
class EventController extends BaseFrontOpenApiController {
public function getEventsAction()
{
$locale = Lang::getDefaultLanguage()->getLocale();
$month = $this->getRequest()->query->get('month', date("m"));
$year = $this->getRequest()->query->get('year', date("Y"));
$startDate = new \DateTime("$year-$month-01");
$endDate = (clone $startDate)->modify("last day of next month");
$events = AgendaContentDateQuery::create()->filterByDateDebut($endDate, Criteria::LESS_EQUAL)->filterByDateFin($startDate, Criteria::GREATER_EQUAL)->find();
$jsonEvents = array_map(static function(AgendaContentDate $event) use ($locale) {
return $event->getJsonArray($locale);
}, iterator_to_array($events->getIterator()));
return $this->jsonResponse($jsonEvents);
// return new JsonResponse(["days" => $totalDays, "events" => $events,"month" => $month, "year" => $year, "startDate" => $startDate, "endDate" => $endDate]);
}
}