mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 06:14:23 +00:00
124 lines
3.3 KiB
PHP
124 lines
3.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\CalendarBundle\Repository;
|
|
|
|
use Chill\CalendarBundle\Entity\Calendar;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
use DateTimeImmutable;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Doctrine\Persistence\ObjectRepository;
|
|
|
|
class CalendarRepository implements ObjectRepository
|
|
{
|
|
private EntityRepository $repository;
|
|
|
|
public function __construct(EntityManagerInterface $entityManager)
|
|
{
|
|
$this->repository = $entityManager->getRepository(Calendar::class);
|
|
}
|
|
|
|
public function countByAccompanyingPeriod(AccompanyingPeriod $period): int
|
|
{
|
|
return $this->repository->count(['accompanyingPeriod' => $period]);
|
|
}
|
|
|
|
public function find($id): ?Calendar
|
|
{
|
|
return $this->repository->find($id);
|
|
}
|
|
|
|
/**
|
|
* @return array|Calendar[]
|
|
*/
|
|
public function findAll(): array
|
|
{
|
|
return $this->repository->findAll();
|
|
}
|
|
|
|
/**
|
|
* @return array|Calendar[]
|
|
*/
|
|
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
|
|
{
|
|
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
|
}
|
|
|
|
/**
|
|
* @return array|Calendar[]
|
|
*/
|
|
public function findByAccompanyingPeriod(AccompanyingPeriod $period, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
|
|
{
|
|
return $this->findBy(
|
|
[
|
|
'accompanyingPeriod' => $period,
|
|
],
|
|
$orderBy,
|
|
$limit,
|
|
$orderBy
|
|
);
|
|
}
|
|
|
|
public function findByNotificationAvailable(DateTimeImmutable $startDate, DateTimeImmutable $endDate, ?int $limit = null, ?int $offset = null): array
|
|
{
|
|
$qb = $this->queryByNotificationAvailable($startDate, $endDate)->select('c');
|
|
|
|
if (null !== $limit) {
|
|
$qb->setMaxResults($limit);
|
|
}
|
|
|
|
if (null !== $offset) {
|
|
$qb->setFirstResult($offset);
|
|
}
|
|
|
|
return $qb->getQuery()->getResult();
|
|
}
|
|
|
|
public function findOneBy(array $criteria): ?Calendar
|
|
{
|
|
return $this->repository->findOneBy($criteria);
|
|
}
|
|
|
|
public function getClassName()
|
|
{
|
|
return Calendar::class;
|
|
}
|
|
|
|
private function queryByNotificationAvailable(DateTimeImmutable $startDate, DateTimeImmutable $endDate): QueryBuilder
|
|
{
|
|
$qb = $this->repository->createQueryBuilder('c');
|
|
|
|
$qb->where(
|
|
$qb->expr()->andX(
|
|
$qb->expr()->eq('c.sendSMS', ':true'),
|
|
$qb->expr()->gte('c.startDate', ':startDate'),
|
|
$qb->expr()->lt('c.startDate', ':endDate'),
|
|
$qb->expr()->orX(
|
|
$qb->expr()->eq('c.smsStatus', ':pending'),
|
|
$qb->expr()->eq('c.smsStatus', ':cancel_pending')
|
|
)
|
|
)
|
|
);
|
|
|
|
$qb->setParameters([
|
|
'true' => true,
|
|
'startDate' => $startDate,
|
|
'endDate' => $endDate,
|
|
'pending' => Calendar::SMS_PENDING,
|
|
'cancel_pending' => Calendar::SMS_CANCEL_PENDING,
|
|
]);
|
|
|
|
return $qb;
|
|
}
|
|
}
|