fallback on schedule items when no access to calendar

This commit is contained in:
2022-05-09 16:44:46 +02:00
parent 38d828cf36
commit ba8a2327be
3 changed files with 97 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use Chill\CalendarBundle\RemoteCalendar\Model\RemoteEvent;
use DateTimeImmutable;
use DateTimeZone;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Convert Chill Calendar event to Remote MS Graph event, and MS Graph
@@ -27,10 +28,31 @@ class RemoteEventConverter
private DateTimeZone $remoteDateTimeZone;
public function __construct()
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
$this->defaultDateTimeZone = (new DateTimeImmutable())->getTimezone();
$this->remoteDateTimeZone = new DateTimeZone('UTC');
$this->remoteDateTimeZone = self::getRemoteTimeZone();
}
public function convertAvailabilityToRemoteEvent(array $event): RemoteEvent
{
$startDate =
DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['start']['dateTime'])
->setTimezone($this->defaultDateTimeZone);
$endDate =
DateTimeImmutable::createFromFormat(self::REMOTE_DATE_FORMAT, $event['end']['dateTime'], $this->remoteDateTimeZone)
->setTimezone($this->defaultDateTimeZone);
return new RemoteEvent(
uniqid('generated_'),
$this->translator->trans('remote_ms_graph.freebusy_statuses.' . $event['status']),
'',
$startDate,
$endDate
);
}
public function convertToRemote(array $event): RemoteEvent
@@ -50,4 +72,17 @@ class RemoteEventConverter
$endDate
);
}
/**
* Return a string which format a DateTime to string. To be used in POST requests,.
*/
public static function getRemoteDateTimeSimpleFormat(): string
{
return 'Y-m-d\TH:i:s';
}
public static function getRemoteTimeZone(): DateTimeZone
{
return new DateTimeZone('UTC');
}
}