mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix cs
This commit is contained in:
parent
5ea12a581b
commit
b22f361368
@ -96,7 +96,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
]
|
||||
)->toArray();
|
||||
|
||||
$ids = array_map(function ($item) { return $item['id']; }, $bareEvents['value']);
|
||||
$ids = array_map(static function ($item) { return $item['id']; }, $bareEvents['value']);
|
||||
$existingIdsInRange = $this->calendarRangeRepository->findRemoteIdsPresent($ids);
|
||||
|
||||
return array_values(
|
||||
@ -107,7 +107,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
// filter all event to keep only the one not in range
|
||||
array_filter(
|
||||
$bareEvents['value'],
|
||||
function ($item) use ($existingIdsInRange) {
|
||||
static function ($item) use ($existingIdsInRange) {
|
||||
return (!$existingIdsInRange[$item['id']]) ?? true;
|
||||
}
|
||||
)
|
||||
|
@ -13,26 +13,28 @@ namespace Chill\CalendarBundle\Repository;
|
||||
|
||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use function count;
|
||||
|
||||
class CalendarRangeRepository implements ObjectRepository
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private EntityRepository $repository;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->em = $entityManager;
|
||||
$this->repository = $entityManager->getRepository(CalendarRange::class);
|
||||
}
|
||||
|
||||
public function countByAvailableRangesForUser(User $user, \DateTimeImmutable $from, \DateTimeImmutable $to): int
|
||||
public function countByAvailableRangesForUser(User $user, DateTimeImmutable $from, DateTimeImmutable $to): int
|
||||
{
|
||||
return $this->buildQueryAvailableRangesForUser($user, $from, $to)
|
||||
->select('COUNT(cr)')
|
||||
@ -65,8 +67,8 @@ class CalendarRangeRepository implements ObjectRepository
|
||||
*/
|
||||
public function findByAvailableRangesForUser(
|
||||
User $user,
|
||||
\DateTimeImmutable $from,
|
||||
\DateTimeImmutable $to,
|
||||
DateTimeImmutable $from,
|
||||
DateTimeImmutable $to,
|
||||
?int $limit = null,
|
||||
?int $offset = null
|
||||
): array {
|
||||
@ -88,12 +90,63 @@ class CalendarRangeRepository implements ObjectRepository
|
||||
return $this->repository->findOneBy($criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of remote ids, return an array where
|
||||
* keys are the remoteIds, and value is a boolean, true if the
|
||||
* id is present in database.
|
||||
*
|
||||
* @param array<int, string>|list<string> $remoteIds
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*/
|
||||
public function findRemoteIdsPresent(array $remoteIds): array
|
||||
{
|
||||
if (0 === count($remoteIds)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$sql = 'SELECT
|
||||
sq.remoteId as remoteid,
|
||||
EXISTS (SELECT 1 FROM chill_calendar.calendar_range cr WHERE cr.remoteId = sq.remoteId) AS present
|
||||
FROM
|
||||
(
|
||||
VALUES %remoteIds%
|
||||
) AS sq(remoteId);
|
||||
';
|
||||
|
||||
$remoteIdsStr = implode(
|
||||
', ',
|
||||
array_fill(0, count($remoteIds), '((?))')
|
||||
);
|
||||
|
||||
$rsm = new ResultSetMapping();
|
||||
$rsm
|
||||
->addScalarResult('remoteid', 'remoteId', Types::STRING)
|
||||
->addScalarResult('present', 'present', Types::BOOLEAN);
|
||||
|
||||
$rows = $this->em
|
||||
->createNativeQuery(
|
||||
strtr($sql, ['%remoteIds%' => $remoteIdsStr]),
|
||||
$rsm
|
||||
)
|
||||
->setParameters(array_values($remoteIds))
|
||||
->getResult();
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ($rows as $r) {
|
||||
$results[$r['remoteId']] = $r['present'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getClassName(): string
|
||||
{
|
||||
return CalendarRange::class;
|
||||
}
|
||||
|
||||
private function buildQueryAvailableRangesForUser(User $user, \DateTimeImmutable $from, \DateTimeImmutable $to): QueryBuilder
|
||||
private function buildQueryAvailableRangesForUser(User $user, DateTimeImmutable $from, DateTimeImmutable $to): QueryBuilder
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('cr');
|
||||
|
||||
@ -112,54 +165,4 @@ class CalendarRangeRepository implements ObjectRepository
|
||||
'endDate' => $to,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of remote ids, return an array where
|
||||
* keys are the remoteIds, and value is a boolean, true if the
|
||||
* id is present in database.
|
||||
*
|
||||
* @param array<int, string>|list<string> $remoteIds
|
||||
* @return array<string, bool>
|
||||
*/
|
||||
public function findRemoteIdsPresent(array $remoteIds): array
|
||||
{
|
||||
if (0 === count($remoteIds)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
sq.remoteId as remoteid,
|
||||
EXISTS (SELECT 1 FROM chill_calendar.calendar_range cr WHERE cr.remoteId = sq.remoteId) AS present
|
||||
FROM
|
||||
(
|
||||
VALUES %remoteIds%
|
||||
) AS sq(remoteId);
|
||||
";
|
||||
|
||||
$remoteIdsStr = \implode(
|
||||
', ',
|
||||
array_fill(0, count($remoteIds), '((?))')
|
||||
);
|
||||
|
||||
$rsm = new ResultSetMapping();
|
||||
$rsm
|
||||
->addScalarResult('remoteid', 'remoteId', Types::STRING)
|
||||
->addScalarResult('present', 'present', Types::BOOLEAN);
|
||||
|
||||
$rows = $this->em
|
||||
->createNativeQuery(
|
||||
\strtr($sql, ['%remoteIds%' => $remoteIdsStr]),
|
||||
$rsm
|
||||
)
|
||||
->setParameters(array_values($remoteIds))
|
||||
->getResult();
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ($rows as $r) {
|
||||
$results[$r['remoteId']] = $r['present'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user