Recettes : BO, rajout de l'ajax
This commit is contained in:
33
local/modules/Agenda/Controller/EventController.php
Normal file
33
local/modules/Agenda/Controller/EventController.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user