Skip to content

Commit

Permalink
fix(pagination): change query to get children organization list
Browse files Browse the repository at this point in the history
  • Loading branch information
olivmai committed May 10, 2020
1 parent 051404e commit c209d21
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __invoke(Request $request, Organization $organization): Response
/** @var Organization $currentOrganization */
$currentOrganization = $this->getUser();
$assets = $this->paginator->paginate(
$this->assetRepository->findByOrganization($organization),
$this->assetRepository->findByOrganizationAndChildrenQb($organization),
$request->query->getInt('page', $this->getParameter('app.pagination_default_start')),
$this->getParameter('app.pagination_default_limit')
);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Organization/OrganizationListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __invoke(Request $request): Response
}

$organizations = $this->paginator->paginate(
$this->organizationRepository->findByParentQueryBuilder($organization),
$this->organizationRepository->findChildrenQueryBuilder($organization),
$request->query->getInt('page', $this->getParameter('app.pagination_default_start')),
$this->getParameter('app.pagination_default_limit')
);
Expand Down
12 changes: 12 additions & 0 deletions src/Repository/OrganizationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ public function findByParentQueryBuilder(Organization $organization): QueryBuild
return $qb;
}

public function findChildrenQueryBuilder(Organization $organization): QueryBuilder
{
$qb = $this->createQueryBuilder('o');

$qb
->where('o.parent = :orga')
->setParameter('orga', $organization)
->addOrderBy('o.name', 'ASC');

return $qb;
}

public function findByIdOrParentIdQueryBuilder(int $organizationId, QueryBuilder $qb = null): QueryBuilder
{
$alias = 'o';
Expand Down

0 comments on commit c209d21

Please sign in to comment.