docgen: improve listing for templates

This commit is contained in:
2021-11-27 01:23:34 +01:00
parent 69e260f0b1
commit 1c18ba20fc
3 changed files with 60 additions and 26 deletions

View File

@@ -25,6 +25,18 @@ final class DocGeneratorTemplateRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(DocGeneratorTemplate::class);
}
public function countByEntity(string $entity): int
{
$builder = $this->repository->createQueryBuilder('t');
$builder
->select('count(t)')
->where('t.entities LIKE :entity')
->setParameter('entity', '%' . addslashes($entity) . '%');
return $builder->getQuery()->getSingleScalarResult();
}
public function find($id, $lockMode = null, $lockVersion = null): ?DocGeneratorTemplate
{
return $this->repository->find($id, $lockMode, $lockVersion);
@@ -49,7 +61,10 @@ final class DocGeneratorTemplateRepository implements ObjectRepository
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function findByEntity($entity)
/**
* @return array|DocGeneratorTemplate[]
*/
public function findByEntity(string $entity, ?int $start = 0, ?int $limit = 50): array
{
$builder = $this->repository->createQueryBuilder('t');
@@ -57,7 +72,11 @@ final class DocGeneratorTemplateRepository implements ObjectRepository
->where('t.entities LIKE :entity')
->setParameter('entity', '%' . addslashes($entity) . '%');
return $builder->getQuery()->execute();
return $builder
->getQuery()
->setFirstResult($start)
->setMaxResults($limit)
->getResult();
}
public function findOneBy(array $criteria, ?array $orderBy = null): ?DocGeneratorTemplate