From b8bf1af377cca7f5f62c9b7916676c39d760cf83 Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Wed, 6 Nov 2013 14:13:46 +0100 Subject: [PATCH] Add possibility to pass extra parameters in getTree It would be usefull to be able to pass parameters that can be retrived in the method addFlatTreeConditions. For example if you need to add conditions depending on the user rights or others... --- src/ORM/Tree/Tree.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ORM/Tree/Tree.php b/src/ORM/Tree/Tree.php index 2e93be34..d2b16743 100644 --- a/src/ORM/Tree/Tree.php +++ b/src/ORM/Tree/Tree.php @@ -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); } @@ -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') @@ -110,7 +112,7 @@ public function getFlatTreeQB($path = '', $rootAlias = 't') ; } - $this->addFlatTreeConditions($qb); + $this->addFlatTreeConditions($qb, $extraParams); return $qb; } @@ -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() ;