mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
wip: synchro of calendar range
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Doctrine;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
|
||||
class CalendarEntityListener
|
||||
{
|
||||
public function postPersistCalendar(Calendar $calendar, LifecycleEventArgs $args): void
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Doctrine;
|
||||
|
||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||
use Chill\CalendarBundle\Messenger\Message\CalendarRangeMessage;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class CalendarRangeEntityListener
|
||||
{
|
||||
private MessageBusInterface $messageBus;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(MessageBusInterface $messageBus, Security $security)
|
||||
{
|
||||
$this->messageBus = $messageBus;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function postPersist(CalendarRange $calendarRange, LifecycleEventArgs $eventArgs): void
|
||||
{
|
||||
$this->messageBus->dispatch(
|
||||
new CalendarRangeMessage(
|
||||
$calendarRange,
|
||||
CalendarRangeMessage::CALENDAR_RANGE_PERSIST,
|
||||
$this->security->getUser()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function postUpdate(CalendarRange $calendarRange, LifecycleEventArgs $eventArgs): void
|
||||
{
|
||||
$this->messageBus->dispatch(
|
||||
new CalendarRangeMessage(
|
||||
$calendarRange,
|
||||
CalendarRangeMessage::CALENDAR_RANGE_UPDATE,
|
||||
$this->security->getUser()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Handler;
|
||||
|
||||
use Chill\CalendarBundle\Messenger\Message\CalendarRangeMessage;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
|
||||
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
/**
|
||||
* @AsMessageHandler
|
||||
*/
|
||||
class CalendarRangeToRemoteHandler implements MessageHandlerInterface
|
||||
{
|
||||
private CalendarRangeRepository $calendarRangeRepository;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private RemoteCalendarConnectorInterface $remoteCalendarConnector;
|
||||
|
||||
public function __construct(
|
||||
CalendarRangeRepository $calendarRangeRepository,
|
||||
RemoteCalendarConnectorInterface $remoteCalendarConnector,
|
||||
EntityManagerInterface $entityManager
|
||||
) {
|
||||
$this->calendarRangeRepository = $calendarRangeRepository;
|
||||
$this->remoteCalendarConnector = $remoteCalendarConnector;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function __invoke(CalendarRangeMessage $calendarRangeMessage): void
|
||||
{
|
||||
$range = $this->calendarRangeRepository->find($calendarRangeMessage->getCalendarRangeId());
|
||||
|
||||
$this->remoteCalendarConnector->syncCalendarRange($range);
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Handler;
|
||||
|
||||
use Chill\CalendarBundle\Messenger\Message\CalendarMessage;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
/**
|
||||
* @AsMessageHandler
|
||||
*/
|
||||
class CalendarToRemoteHandler implements MessageHandlerInterface
|
||||
{
|
||||
private RemoteCalendarConnectorInterface $calendarConnector;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __invoke(CalendarMessage $calendarMessage)
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Message;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
|
||||
class CalendarMessage
|
||||
{
|
||||
public const CALENDAR_PERSIST = 'CHILL_CALENDAR_CALENDAR_PERSIST';
|
||||
|
||||
public const CALENDAR_UPDATE = 'CHILL_CALENDAR_CALENDAR_UPDATE';
|
||||
|
||||
private string $action;
|
||||
|
||||
private int $calendarId;
|
||||
|
||||
public function __construct(Calendar $calendar, string $action)
|
||||
{
|
||||
$this->calendarId = $calendar->getId();
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
public function getAction(): string
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function getCalendarId(): ?int
|
||||
{
|
||||
return $this->calendarId;
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Message;
|
||||
|
||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
class CalendarRangeMessage
|
||||
{
|
||||
public const CALENDAR_RANGE_PERSIST = 'CHILL_CALENDAR_CALENDAR_RANGE_PERSIST';
|
||||
|
||||
public const CALENDAR_RANGE_UPDATE = 'CHILL_CALENDAR_CALENDAR_RANGE_UPDATE';
|
||||
|
||||
private string $action;
|
||||
|
||||
private ?int $byUserId = null;
|
||||
|
||||
private int $calendarRangeId;
|
||||
|
||||
public function __construct(CalendarRange $calendarRange, string $action, ?User $byUser)
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->calendarRangeId = $calendarRange->getId();
|
||||
|
||||
if (null !== $byUser) {
|
||||
$this->byUserId = $byUser->getId();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAction(): string
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function getByUserId(): ?int
|
||||
{
|
||||
return $this->byUserId;
|
||||
}
|
||||
|
||||
public function getCalendarRangeId(): ?int
|
||||
{
|
||||
return $this->calendarRangeId;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user