mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
fetch remote calendar and show on FullCalendar frame
This commit is contained in:
@@ -269,6 +269,10 @@ class CalendarController extends AbstractController
|
||||
*/
|
||||
public function newAction(Request $request): Response
|
||||
{
|
||||
if (!$this->remoteCalendarConnector->isReady()) {
|
||||
return $this->remoteCalendarConnector->getMakeReadyResponse($request->getUri());
|
||||
}
|
||||
|
||||
$view = null;
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
|
@@ -13,6 +13,8 @@ namespace Chill\CalendarBundle\Controller;
|
||||
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use DateTimeImmutable;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -30,8 +32,11 @@ class RemoteCalendarProxyController
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
public function __construct(RemoteCalendarConnectorInterface $remoteCalendarConnector, SerializerInterface $serializer)
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
public function __construct(PaginatorFactory $paginatorFactory, RemoteCalendarConnectorInterface $remoteCalendarConnector, SerializerInterface $serializer)
|
||||
{
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
$this->remoteCalendarConnector = $remoteCalendarConnector;
|
||||
$this->serializer = $serializer;
|
||||
}
|
||||
@@ -41,30 +46,38 @@ class RemoteCalendarProxyController
|
||||
*/
|
||||
public function listEventForCalendar(User $user, Request $request): Response
|
||||
{
|
||||
if ($request->query->has('startDate')) {
|
||||
$startDate = DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s', $request->query->get('startDate') . 'T00:00:00');
|
||||
|
||||
if (false === $startDate) {
|
||||
throw new BadRequestHttpException('startDate on bad format');
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestHttpException('startDate not provided');
|
||||
if (!$request->query->has('dateFrom')) {
|
||||
throw new BadRequestHttpException('You must provide a dateFrom parameter');
|
||||
}
|
||||
|
||||
if ($request->query->has('endDate')) {
|
||||
$endDate = DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s', $request->query->get('endDate') . 'T23:59:59');
|
||||
|
||||
if (false === $endDate) {
|
||||
throw new BadRequestHttpException('endDate on bad format');
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestHttpException('endDate not provided');
|
||||
if (false === $dateFrom = DateTimeImmutable::createFromFormat(
|
||||
DateTimeImmutable::ATOM,
|
||||
$request->query->get('dateFrom')
|
||||
)) {
|
||||
throw new BadRequestHttpException('dateFrom not parsable');
|
||||
}
|
||||
|
||||
$events = $this->remoteCalendarConnector->listEventsForUser($user, $startDate, $endDate);
|
||||
if (!$request->query->has('dateTo')) {
|
||||
throw new BadRequestHttpException('You must provide a dateTo parameter');
|
||||
}
|
||||
|
||||
if (false === $dateTo = DateTimeImmutable::createFromFormat(
|
||||
DateTimeImmutable::ATOM,
|
||||
$request->query->get('dateTo')
|
||||
)) {
|
||||
throw new BadRequestHttpException('dateTo not parsable');
|
||||
}
|
||||
|
||||
$events = $this->remoteCalendarConnector->listEventsForUser($user, $dateFrom, $dateTo);
|
||||
$paginator = $this->paginatorFactory->create(count($events));
|
||||
if (count($events) > 0) {
|
||||
$paginator->setItemsPerPage($paginator->getTotalItems());
|
||||
}
|
||||
|
||||
$collection = new Collection($events, $paginator);
|
||||
|
||||
return new JsonResponse(
|
||||
$this->serializer->serialize($events, 'json', ['groups' => ['read']]),
|
||||
$this->serializer->serialize($collection, 'json', ['groups' => ['read']]),
|
||||
JsonResponse::HTTP_OK,
|
||||
[],
|
||||
true
|
||||
|
Reference in New Issue
Block a user