Skip to content

Commit

Permalink
chore: Fixed NodeTreeDto with search query
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Nov 19, 2024
1 parent b283c9b commit 38c84fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
32 changes: 16 additions & 16 deletions src/Repository/NodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,21 @@ public function searchByAsNodeTreeDto(
$this->dispatchQueryBuilderEvent($qb, $this->getEntityName());
$this->applyFilterByCriteria($criteria, $qb);

$this->alterQueryBuilderAsNodeTreeDto($qb);
$this->alterQueryBuilderAsNodeTreeDto($qb, $alias);

$query = $qb->getQuery();
$this->dispatchQueryEvent($query);

return $query->getResult();
}

protected function alterQueryBuilderAsNodeTreeDto(QueryBuilder $qb): QueryBuilder
protected function alterQueryBuilderAsNodeTreeDto(QueryBuilder $qb, string $alias = self::NODE_ALIAS): QueryBuilder
{
if (!$this->hasJoinedNodeType($qb, self::NODE_ALIAS)) {
$qb->innerJoin(self::NODE_ALIAS.'.nodeType', self::NODETYPE_ALIAS);
if (!$this->hasJoinedNodeType($qb, $alias)) {
$qb->innerJoin($alias.'.nodeType', self::NODETYPE_ALIAS);
}
if (!$this->hasJoinedNodesSources($qb, self::NODE_ALIAS)) {
$qb->innerJoin(self::NODE_ALIAS.'.nodeSources', self::NODESSOURCES_ALIAS);
if (!$this->hasJoinedNodesSources($qb, $alias)) {
$qb->innerJoin($alias.'.nodeSources', self::NODESSOURCES_ALIAS);
}

$qb->select(sprintf(
Expand Down Expand Up @@ -419,16 +419,16 @@ protected function alterQueryBuilderAsNodeTreeDto(QueryBuilder $qb): QueryBuilde
)
EOT,
NodeTreeDto::class,
self::NODE_ALIAS,
self::NODE_ALIAS,
self::NODE_ALIAS,
self::NODE_ALIAS,
self::NODE_ALIAS,
self::NODE_ALIAS,
self::NODE_ALIAS,
self::NODE_ALIAS,
self::NODE_ALIAS,
self::NODE_ALIAS,
$alias,
$alias,
$alias,
$alias,
$alias,
$alias,
$alias,
$alias,
$alias,
$alias,
self::NODETYPE_ALIAS,
self::NODETYPE_ALIAS,
self::NODETYPE_ALIAS,
Expand Down
12 changes: 6 additions & 6 deletions src/Repository/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function findByAsTagTreeDto(
return $query->getResult();
}

protected function alterQueryBuilderAsTagTreeDto(QueryBuilder $qb): QueryBuilder
protected function alterQueryBuilderAsTagTreeDto(QueryBuilder $qb, string $alias = self::TAG_ALIAS): QueryBuilder
{
$qb->select(sprintf(
<<<EOT
Expand All @@ -293,12 +293,12 @@ protected function alterQueryBuilderAsTagTreeDto(QueryBuilder $qb): QueryBuilder
)
EOT,
TagTreeDto::class,
EntityRepository::TAG_ALIAS,
EntityRepository::TAG_ALIAS,
$alias,
$alias,
'tt',
EntityRepository::TAG_ALIAS,
EntityRepository::TAG_ALIAS,
EntityRepository::TAG_ALIAS,
$alias,
$alias,
$alias,
));

return $qb;
Expand Down

0 comments on commit 38c84fb

Please sign in to comment.