mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33:49 +00:00
fallback on schedule items when no access to calendar
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user