mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
104 lines
2.8 KiB
PHP
104 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Chill\PersonBundle\Repository\AccompanyingPeriod;
|
|
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Doctrine\Persistence\ObjectRepository;
|
|
|
|
final class AccompanyingPeriodWorkRepository implements ObjectRepository
|
|
{
|
|
private EntityRepository $repository;
|
|
|
|
public function __construct(EntityManagerInterface $entityManager)
|
|
{
|
|
$this->repository = $entityManager->getRepository(AccompanyingPeriodWork::class);
|
|
}
|
|
|
|
public function find($id): ?AccompanyingPeriodWork
|
|
{
|
|
return $this->repository->find($id);
|
|
}
|
|
|
|
public function findAll(): array
|
|
{
|
|
return $this->repository->findAll();
|
|
}
|
|
|
|
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
|
{
|
|
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
|
}
|
|
|
|
public function findOneBy(array $criteria): ?AccompanyingPeriodWork
|
|
{
|
|
return $this->findOneBy($criteria);
|
|
}
|
|
|
|
public function getClassName()
|
|
{
|
|
return AccompanyingPeriodWork::class;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return AccompanyingPeriodWork[]
|
|
*/
|
|
public function findByAccompanyingPeriod(AccompanyingPeriod $period, $orderBy = null, $limit = null, $offset = null): array
|
|
{
|
|
return $this->repository->findByAccompanyingPeriod($period, $orderBy, $limit, $offset);
|
|
}
|
|
|
|
public function countByAccompanyingPeriod(AccompanyingPeriod $period): int
|
|
{
|
|
return $this->repository->countByAccompanyingPeriod($period);
|
|
}
|
|
|
|
public function toDelete()
|
|
{
|
|
$qb = $this->buildQueryBySocialActionWithDescendants($action);
|
|
$qb->select('g');
|
|
|
|
foreach ($orderBy as $sort => $order) {
|
|
$qb->addOrderBy('g.'.$sort, $order);
|
|
}
|
|
|
|
return $qb
|
|
->setMaxResults($limit)
|
|
->setFirstResult($offset)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function countBySocialActionWithDescendants(SocialAction $action): int
|
|
{
|
|
$qb = $this->buildQueryBySocialActionWithDescendants($action);
|
|
$qb->select('COUNT(g)');
|
|
|
|
return $qb
|
|
->getQuery()
|
|
->getSingleScalarResult()
|
|
;
|
|
}
|
|
|
|
protected function buildQueryBySocialActionWithDescendants(SocialAction $action): QueryBuilder
|
|
{
|
|
$actions = $action->getDescendantsWithThis();
|
|
|
|
$qb = $this->repository->createQueryBuilder('g');
|
|
|
|
$orx = $qb->expr()->orX();
|
|
$i = 0;
|
|
foreach ($actions as $action) {
|
|
$orx->add(":action_{$i} MEMBER OF g.socialActions");
|
|
$qb->setParameter("action_{$i}", $action);
|
|
}
|
|
$qb->where($orx);
|
|
|
|
return $qb;
|
|
}
|
|
}
|