Skip to content

Instantly share code, notes, and snippets.

@avknor
Last active April 12, 2016 07:32
Show Gist options
  • Save avknor/10481753 to your computer and use it in GitHub Desktop.
Save avknor/10481753 to your computer and use it in GitHub Desktop.
Doctrine2 get all the child records from adjacency list.
public function getSubOrgsForTranspnakl(Entity $topitem)
{
$childrenArray = array();
$iterate = true;
$listOfParents = array();
$listOfParents = array_push($listOfParents, $topitem);
while ($iterate){
$q = $this
->createQueryBuilder('o')
->where('o.parent IN (:parentslist) ')
->setParameter('parentslist', $listOfParents)
->getQuery();
$resultArray = $q->getResult();
$listOfParents = $resulArray;
$childrenArray = array_merge($childrenArray, $resultArray);
if (count($resulArray) == 0) $iterate = false;
}
return $resultArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment