mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Repository\SocialWork;
|
||||
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
@@ -19,6 +26,26 @@ final class ResultRepository implements ObjectRepository
|
||||
$this->repository = $entityManager->getRepository(Result::class);
|
||||
}
|
||||
|
||||
public function countByGoal(Goal $goal): int
|
||||
{
|
||||
$qb = $this->buildQueryByGoal($goal);
|
||||
$qb->select('COUNT(r)');
|
||||
|
||||
return $qb
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function countBySocialActionWithDescendants(SocialAction $action): int
|
||||
{
|
||||
$qb = $this->buildQueryBySocialActionWithDescendants($action);
|
||||
$qb->select('COUNT(r)');
|
||||
|
||||
return $qb
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?Result
|
||||
{
|
||||
return $this->repository->find($id, $lockMode, $lockVersion);
|
||||
@@ -33,6 +60,43 @@ final class ResultRepository implements ObjectRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed|null $limit
|
||||
* @param mixed|null $offset
|
||||
*
|
||||
* @return array<int, Result>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed|null $orderBy
|
||||
* @param mixed|null $limit
|
||||
* @param mixed|null $offset
|
||||
*
|
||||
* @return Result[]
|
||||
*/
|
||||
public function findByGoal(Goal $goal, $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
$qb = $this->buildQueryByGoal($goal);
|
||||
|
||||
foreach ($orderBy as $sort => $order) {
|
||||
$qb->addOrderBy('r.' . $sort, $order);
|
||||
}
|
||||
|
||||
return $qb
|
||||
->select('r')
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed|null $orderBy
|
||||
* @param mixed|null $limit
|
||||
* @param mixed|null $offset
|
||||
*
|
||||
* @return Result[]
|
||||
*/
|
||||
@@ -42,92 +106,14 @@ final class ResultRepository implements ObjectRepository
|
||||
$qb->select('r');
|
||||
|
||||
foreach ($orderBy as $sort => $order) {
|
||||
$qb->addOrderBy('r.'.$sort, $order);
|
||||
$qb->addOrderBy('r.' . $sort, $order);
|
||||
}
|
||||
|
||||
return $qb
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function countBySocialActionWithDescendants(SocialAction $action): int
|
||||
{
|
||||
$qb = $this->buildQueryBySocialActionWithDescendants($action);
|
||||
$qb->select('COUNT(r)');
|
||||
|
||||
return $qb
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
protected function buildQueryBySocialActionWithDescendants(SocialAction $action): QueryBuilder
|
||||
{
|
||||
$actions = $action->getDescendantsWithThis();
|
||||
|
||||
$qb = $this->repository->createQueryBuilder('r');
|
||||
|
||||
$orx = $qb->expr()->orX();
|
||||
$i = 0;
|
||||
foreach ($actions as $action) {
|
||||
$orx->add(":action_{$i} MEMBER OF r.socialActions");
|
||||
$qb->setParameter("action_{$i}", $action);
|
||||
}
|
||||
$qb->where($orx);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
protected function buildQueryByGoal(Goal $goal): QueryBuilder
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('r');
|
||||
|
||||
$qb->where(":goal MEMBER OF r.goals")
|
||||
->setParameter('goal', $goal)
|
||||
;
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Result[]
|
||||
*/
|
||||
public function findByGoal(Goal $goal, $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
$qb = $this->buildQueryByGoal($goal);
|
||||
|
||||
foreach ($orderBy as $sort => $order) {
|
||||
$qb->addOrderBy('r.'.$sort, $order);
|
||||
}
|
||||
|
||||
return $qb
|
||||
->select('r')
|
||||
->setMaxResults($limit)
|
||||
->setFirstResult($offset)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function countByGoal(Goal $goal): int
|
||||
{
|
||||
$qb = $this->buildQueryByGoal($goal);
|
||||
$qb->select('COUNT(r)');
|
||||
|
||||
return $qb
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, Result>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
->getResult();
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?Result
|
||||
@@ -142,4 +128,32 @@ final class ResultRepository implements ObjectRepository
|
||||
{
|
||||
return Result::class;
|
||||
}
|
||||
|
||||
private function buildQueryByGoal(Goal $goal): QueryBuilder
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('r');
|
||||
|
||||
$qb->where(':goal MEMBER OF r.goals')
|
||||
->setParameter('goal', $goal);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
private function buildQueryBySocialActionWithDescendants(SocialAction $action): QueryBuilder
|
||||
{
|
||||
$actions = $action->getDescendantsWithThis();
|
||||
|
||||
$qb = $this->repository->createQueryBuilder('r');
|
||||
|
||||
$orx = $qb->expr()->orX();
|
||||
$i = 0;
|
||||
|
||||
foreach ($actions as $action) {
|
||||
$orx->add(":action_{$i} MEMBER OF r.socialActions");
|
||||
$qb->setParameter("action_{$i}", $action);
|
||||
}
|
||||
$qb->where($orx);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user