diff --git a/src/Bundle/ChillCalendarBundle/ChillCalendarBundle.php b/src/Bundle/ChillCalendarBundle/ChillCalendarBundle.php index 11b985224..2e398afe7 100644 --- a/src/Bundle/ChillCalendarBundle/ChillCalendarBundle.php +++ b/src/Bundle/ChillCalendarBundle/ChillCalendarBundle.php @@ -11,8 +11,16 @@ declare(strict_types=1); namespace Chill\CalendarBundle; +use Chill\CalendarBundle\Synchro\DependencyInjection\SynchroCompilerPass; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; class ChillCalendarBundle extends Bundle { + public function build(ContainerBuilder $container) + { + parent::build($container); + + $container->addCompilerPass(new SynchroCompilerPass()); + } } diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 3efae86e9..9af9ad1df 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -14,6 +14,7 @@ namespace Chill\CalendarBundle\Controller; use Chill\CalendarBundle\Entity\Calendar; use Chill\CalendarBundle\Form\CalendarType; use Chill\CalendarBundle\Repository\CalendarRepository; +use Chill\CalendarBundle\Synchro\Connector\RemoteCalendarConnectorInterface; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; @@ -47,20 +48,24 @@ class CalendarController extends AbstractController private CalendarRepository $calendarRepository; + private RemoteCalendarConnectorInterface $remoteCalendarConnector; + public function __construct( - EventDispatcherInterface $eventDispatcher, AuthorizationHelper $authorizationHelper, + CalendarRepository $calendarRepository, + EventDispatcherInterface $eventDispatcher, LoggerInterface $logger, - SerializerInterface $serializer, PaginatorFactory $paginator, - CalendarRepository $calendarRepository + RemoteCalendarConnectorInterface $remoteCalendarConnector, + SerializerInterface $serializer ) { - $this->eventDispatcher = $eventDispatcher; $this->authorizationHelper = $authorizationHelper; - $this->logger = $logger; - $this->serializer = $serializer; - $this->paginator = $paginator; $this->calendarRepository = $calendarRepository; + $this->eventDispatcher = $eventDispatcher; + $this->logger = $logger; + $this->paginator = $paginator; + $this->remoteCalendarConnector = $remoteCalendarConnector; + $this->serializer = $serializer; } /** @@ -183,27 +188,6 @@ class CalendarController extends AbstractController ]); } - /** - * @Route("/{_locale}/calendar/calendar/my", name="chill_calendar_calendar_list_my") - * - * @param Request $request - * @return Response - */ - public function myCalendar(Request $request): Response - { - $this->denyAccessUnlessGranted('ROLE_USER'); - - if (!$this->getUser() instanceof User) { - throw new UnauthorizedHttpException('you are not an user'); - } - - $view = '@ChillCalendar/Calendar/listByUser.html.twig'; - - return $this->render($view, [ - 'user' => $this->getUser(), - ]); - } - /** * Lists all Calendar entities. * @@ -251,6 +235,28 @@ class CalendarController extends AbstractController throw new Exception('Unable to list actions.'); } + /** + * @Route("/{_locale}/calendar/calendar/my", name="chill_calendar_calendar_list_my") + */ + public function myCalendar(Request $request): Response + { + $this->denyAccessUnlessGranted('ROLE_USER'); + + if (!$this->getUser() instanceof User) { + throw new UnauthorizedHttpException('you are not an user'); + } + + if (!$this->remoteCalendarConnector->isReady()) { + return $this->remoteCalendarConnector->getMakeReadyResponse(); + } + + $view = '@ChillCalendar/Calendar/listByUser.html.twig'; + + return $this->render($view, [ + 'user' => $this->getUser(), + ]); + } + /** * Create a new calendar item. * diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php index d0a5c3d94..d0bb84167 100644 --- a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php @@ -36,6 +36,7 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf $loader->load('services/fixtures.yml'); $loader->load('services/form.yml'); $loader->load('services/event.yml'); + $loader->load('services/synchro.yaml'); } public function prepend(ContainerBuilder $container) diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/services/synchro.yaml b/src/Bundle/ChillCalendarBundle/Resources/config/services/synchro.yaml new file mode 100644 index 000000000..7be6ccbec --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/synchro.yaml @@ -0,0 +1,8 @@ +services: + _defaults: + autoconfigure: true + autowire: true + + Chill\CalendarBundle\Synchro\Connector\RemoteCalendarConnectorInterface: ~ + + Chill\CalendarBundle\Synchro\Connector\NullRemoteCalendarConnector: ~ diff --git a/src/Bundle/ChillCalendarBundle/Synchro/Connector/NullRemoteCalendarConnector.php b/src/Bundle/ChillCalendarBundle/Synchro/Connector/NullRemoteCalendarConnector.php new file mode 100644 index 000000000..3eb415e5d --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Synchro/Connector/NullRemoteCalendarConnector.php @@ -0,0 +1,28 @@ +getDefinition(NullRemoteCalendarConnector::class); + $nullConnector->setDecoratedService(RemoteCalendarConnectorInterface::class); + } +}