mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33:49 +00:00
wip: continue sync to remote
This commit is contained in:
@@ -19,7 +19,9 @@ use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* Convert Chill Calendar event to Remote MS Graph event, and MS Graph
|
||||
@@ -39,8 +41,11 @@ class RemoteEventConverter
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(PersonRenderInterface $personRender, TranslatorInterface $translator)
|
||||
private EngineInterface $engine;
|
||||
|
||||
public function __construct(EngineInterface $engine, PersonRenderInterface $personRender, TranslatorInterface $translator)
|
||||
{
|
||||
$this->engine = $engine;
|
||||
$this->translator = $translator;
|
||||
$this->personRender = $personRender;
|
||||
$this->defaultDateTimeZone = (new DateTimeImmutable())->getTimezone();
|
||||
@@ -79,38 +84,59 @@ class RemoteEventConverter
|
||||
}
|
||||
|
||||
public function calendarToEvent(Calendar $calendar): array
|
||||
{
|
||||
return array_merge(
|
||||
[
|
||||
'subject' => '[Chill] ' .
|
||||
implode(
|
||||
', ',
|
||||
$calendar->getPersons()->map(function (Person $p) {
|
||||
return $this->personRender->renderString($p, []);
|
||||
})->toArray()
|
||||
),
|
||||
'start' => [
|
||||
'dateTime' => $calendar->getStartDate()->setTimezone($this->remoteDateTimeZone)
|
||||
->format(self::REMOTE_DATE_FORMAT),
|
||||
'timeZone' => 'UTC',
|
||||
],
|
||||
'end' => [
|
||||
'dateTime' => $calendar->getEndDate()->setTimezone($this->remoteDateTimeZone)
|
||||
->format(self::REMOTE_DATE_FORMAT),
|
||||
'timeZone' => 'UTC',
|
||||
],
|
||||
'allowNewTimeProposals' => false,
|
||||
'transactionId' => 'calendar_' . $calendar->getId(),
|
||||
'body' => [
|
||||
'contentType' => 'text',
|
||||
'content' => $this->engine->render(
|
||||
'@ChillCalendar/MSGraph/calendar_event_body.html.twig',
|
||||
['calendar' => $calendar]
|
||||
),
|
||||
]
|
||||
],
|
||||
$this->calendarToEventAttendeesOnly($calendar)
|
||||
);
|
||||
}
|
||||
|
||||
public function calendarToEventAttendeesOnly(Calendar $calendar): array
|
||||
{
|
||||
return [
|
||||
'subject' => '[Chill] ' .
|
||||
implode(
|
||||
', ',
|
||||
$calendar->getPersons()->map(function (Person $p) {
|
||||
return $this->personRender->renderString($p, []);
|
||||
})->toArray()
|
||||
),
|
||||
'start' => [
|
||||
'dateTime' => $calendar->getStartDate()->setTimezone($this->remoteDateTimeZone)
|
||||
->format(self::REMOTE_DATE_FORMAT),
|
||||
'timeZone' => 'UTC',
|
||||
],
|
||||
'end' => [
|
||||
'dateTime' => $calendar->getEndDate()->setTimezone($this->remoteDateTimeZone)
|
||||
->format(self::REMOTE_DATE_FORMAT),
|
||||
'timeZone' => 'UTC',
|
||||
],
|
||||
'allowNewTimeProposals' => false,
|
||||
'attendees' => $calendar->getInvites()->map(
|
||||
static function (Invite $i) {
|
||||
return [
|
||||
'emailAddress' => [
|
||||
'address' => $i->getUser()->getEmail(),
|
||||
'name' => $i->getUser()->getLabel(),
|
||||
],
|
||||
'type' => 'Required',
|
||||
];
|
||||
}
|
||||
function (Invite $i) {
|
||||
return $this->buildInviteToAttendee($i);
|
||||
}
|
||||
)->toArray(),
|
||||
'transactionId' => 'calendar_' . $calendar->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
private function buildInviteToAttendee(Invite $invite): array
|
||||
{
|
||||
return [
|
||||
'emailAddress' => [
|
||||
'address' => $invite->getUser()->getEmail(),
|
||||
'name' => $invite->getUser()->getLabel(),
|
||||
],
|
||||
'type' => 'Required',
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user