Skip to content

Commit

Permalink
Merge pull request #358 from KnpLabs/add-extraparameters-to-tree
Browse files Browse the repository at this point in the history
[Tree] Add possibility to pass extra parameters in getTree
  • Loading branch information
AlucardleVash authored Nov 13, 2018
2 parents 0045953 + b8bf1af commit 212ecec
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/ORM/Tree/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ public function getRootNodes($rootAlias = 't')
*
* @param string $path
* @param string $rootAlias
* @param array $extraParams To be used in addFlatTreeConditions
*
* @return NodeInterface a node
*/
public function getTree($path = '', $rootAlias = 't')
public function getTree($path = '', $rootAlias = 't', $extraParams = array())
{
$results = $this->getFlatTree($path, $rootAlias);
$results = $this->getFlatTree($path, $rootAlias, $extraParams);

return $this->buildTree($results);
}
Expand Down Expand Up @@ -91,10 +92,11 @@ public function buildTree($results)
*
* @param string $path
* @param string $rootAlias
* @param array $extraParams To be used in addFlatTreeConditions
*
* @return QueryBuilder
*/
public function getFlatTreeQB($path = '', $rootAlias = 't')
public function getFlatTreeQB($path = '', $rootAlias = 't', $extraParams = array())
{
$qb = $this->createQueryBuilder($rootAlias)
->andWhere($rootAlias.'.materializedPath LIKE :path')
Expand All @@ -110,7 +112,7 @@ public function getFlatTreeQB($path = '', $rootAlias = 't')
;
}

$this->addFlatTreeConditions($qb);
$this->addFlatTreeConditions($qb, $extraParams);

return $qb;
}
Expand All @@ -120,20 +122,25 @@ public function getFlatTreeQB($path = '', $rootAlias = 't')
* Override this method to customize the tree query
*
* @param QueryBuilder $qb
* @param array $extraParams
*/
protected function addFlatTreeConditions(QueryBuilder $qb)
protected function addFlatTreeConditions(QueryBuilder $qb, $extraParams)
{
}

/**
* Executes the flat tree query builder
*
* @param string $path
* @param string $rootAlias
* @param array $extraParams To be used in addFlatTreeConditions
*
* @return array the flat resultset
*/
public function getFlatTree($path, $rootAlias = 't')
public function getFlatTree($path, $rootAlias = 't', $extraParams = array())
{
return $this
->getFlatTreeQB($path, $rootAlias)
->getFlatTreeQB($path, $rootAlias, $extraParams)
->getQuery()
->execute()
;
Expand Down

0 comments on commit 212ecec

Please sign in to comment.