mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
Syncer for user absence, from the msgraph reader
This commit is contained in:
@@ -21,7 +21,7 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
readonly class MSUserAbsenceReader
|
||||
final readonly class MSUserAbsenceReader implements MSUserAbsenceReaderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private HttpClientInterface $machineHttpClient,
|
||||
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
interface MSUserAbsenceReaderInterface
|
||||
{
|
||||
/**
|
||||
* @throw UserAbsenceSyncException when the data cannot be reached or is not valid from microsoft
|
||||
*/
|
||||
public function isUserAbsent(User $user): bool|null;
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
|
||||
readonly class MSUserAbsenceSync
|
||||
{
|
||||
public function __construct(
|
||||
private MSUserAbsenceReaderInterface $absenceReader,
|
||||
private ClockInterface $clock,
|
||||
) {
|
||||
}
|
||||
|
||||
public function syncUserAbsence(User $user): void
|
||||
{
|
||||
$absence = $this->absenceReader->isUserAbsent($user);
|
||||
|
||||
if (null === $absence) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($absence === $user->isAbsent()) {
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
if ($absence) {
|
||||
$user->setAbsenceStart($this->clock->now());
|
||||
} else {
|
||||
$user->setAbsenceStart(null);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user