mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
send first calendar on ms graph
This commit is contained in:
@@ -11,8 +11,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Handler;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Invite;
|
||||
use Chill\CalendarBundle\Messenger\Message\CalendarMessage;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
|
||||
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
|
||||
use Chill\CalendarBundle\Repository\CalendarRepository;
|
||||
use Chill\CalendarBundle\Repository\InviteRepository;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
@@ -24,9 +29,63 @@ class CalendarToRemoteHandler implements MessageHandlerInterface
|
||||
{
|
||||
private RemoteCalendarConnectorInterface $calendarConnector;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
private CalendarRangeRepository $calendarRangeRepository;
|
||||
|
||||
private CalendarRepository $calendarRepository;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private InviteRepository $inviteRepository;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(
|
||||
CalendarRangeRepository $calendarRangeRepository,
|
||||
CalendarRepository $calendarRepository,
|
||||
EntityManagerInterface $entityManager,
|
||||
InviteRepository $inviteRepository,
|
||||
RemoteCalendarConnectorInterface $calendarConnector,
|
||||
UserRepository $userRepository
|
||||
) {
|
||||
$this->calendarConnector = $calendarConnector;
|
||||
$this->calendarRepository = $calendarRepository;
|
||||
$this->calendarRangeRepository = $calendarRangeRepository;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->inviteRepository = $inviteRepository;
|
||||
}
|
||||
|
||||
public function __invoke(CalendarMessage $calendarMessage)
|
||||
{
|
||||
$calendar = $this->calendarRepository->find($calendarMessage->getCalendarId());
|
||||
|
||||
if (null !== $calendarMessage->getPreviousCalendarRangeId()) {
|
||||
$previousCalendarRange = $this->calendarRangeRepository
|
||||
->find($calendarMessage->getPreviousCalendarRangeId());
|
||||
}
|
||||
|
||||
if (null !== $calendarMessage->getPreviousMainUserId()) {
|
||||
$previousMainUser = $this->userRepository
|
||||
->find($calendarMessage->getPreviousMainUserId());
|
||||
}
|
||||
$newInvites = array_filter(
|
||||
array_map(
|
||||
function ($id) { return $this->inviteRepository->find($id); },
|
||||
$calendarMessage->getNewInvitesIds(),
|
||||
),
|
||||
static function (?Invite $invite) { return null !== $invite; }
|
||||
);
|
||||
|
||||
$this->calendarConnector->syncCalendar(
|
||||
$calendar,
|
||||
$calendarMessage->getAction(),
|
||||
$previousCalendarRange ?? null,
|
||||
$previousMainUser ?? null,
|
||||
$calendarMessage->getOldInvites(),
|
||||
$newInvites
|
||||
);
|
||||
|
||||
$calendar->preventEnqueueChanges = true;
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\CalendarBundle\Messenger\Message;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Entity\Invite;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
class CalendarMessage
|
||||
@@ -26,11 +27,38 @@ class CalendarMessage
|
||||
|
||||
private int $calendarId;
|
||||
|
||||
public function __construct(Calendar $calendar, string $action, User $byUser)
|
||||
{
|
||||
private array $newInvitesIds = [];
|
||||
|
||||
/**
|
||||
* @var array<array{inviteId: int, userId: int, userEmail: int, userLabel: string}>
|
||||
*/
|
||||
private array $oldInvites = [];
|
||||
|
||||
private ?int $previousCalendarRangeId = null;
|
||||
|
||||
private ?int $previousMainUserId = null;
|
||||
|
||||
public function __construct(
|
||||
Calendar $calendar,
|
||||
string $action,
|
||||
User $byUser
|
||||
) {
|
||||
$this->calendarId = $calendar->getId();
|
||||
$this->byUserId = $byUser->getId();
|
||||
$this->action = $action;
|
||||
$this->previousCalendarRangeId = null !== $calendar->previousCalendarRange ?
|
||||
$calendar->previousCalendarRange->getId() : null;
|
||||
$this->previousMainUserId = null !== $calendar->previousMainUser ?
|
||||
$calendar->previousMainUser->getId() : null;
|
||||
$this->newInvitesIds = array_map(static fn (Invite $i) => $i->getId(), $calendar->newInvites);
|
||||
$this->oldInvites = array_map(static function (Invite $i) {
|
||||
return [
|
||||
'inviteId' => $i->getId(),
|
||||
'userId' => $i->getUser()->getId(),
|
||||
'userEmail' => $i->getUser()->getEmail(),
|
||||
'userLabel' => $i->getUser()->getLabel(),
|
||||
];
|
||||
}, $calendar->oldInvites);
|
||||
}
|
||||
|
||||
public function getAction(): string
|
||||
@@ -47,4 +75,30 @@ class CalendarMessage
|
||||
{
|
||||
return $this->calendarId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|int[]|null[]
|
||||
*/
|
||||
public function getNewInvitesIds(): array
|
||||
{
|
||||
return $this->newInvitesIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array{inviteId: int, userId: int, userEmail: int, userLabel: string}>
|
||||
*/
|
||||
public function getOldInvites(): array
|
||||
{
|
||||
return $this->oldInvites;
|
||||
}
|
||||
|
||||
public function getPreviousCalendarRangeId(): ?int
|
||||
{
|
||||
return $this->previousCalendarRangeId;
|
||||
}
|
||||
|
||||
public function getPreviousMainUserId(): ?int
|
||||
{
|
||||
return $this->previousMainUserId;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user