Skip to content

Instantly share code, notes, and snippets.

@billhance
Forked from avknor/getchildren
Created April 12, 2016 07:32
Show Gist options
  • Save billhance/986db278ef9de9ed2d6d1e82c86a4fe7 to your computer and use it in GitHub Desktop.
Save billhance/986db278ef9de9ed2d6d1e82c86a4fe7 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