public function buildGroupTreeAaJson($owner)
 {
     $entities = $this->groupRepository->getDataForTree();
     $tree = new NodeTree();
     $tree->setId($owner);
     $tree->buildBranches($entities);
     $returnedArray = $this->prepareGroupTreeForJson($tree);
     return json_encode($returnedArray);
 }
 public function buildBranches($collection)
 {
     if ($this->id == 0) {
         $this->setName('root');
         $this->setIsActive(true);
     } else {
         foreach ($collection as $key => $item) {
             if ($this->id == $item['id']) {
                 $this->_setNodes($item);
                 unset($collection[$key]);
                 break;
             }
         }
     }
     $nodeList = $this->_searchInCollection($collection, 'owner', $this->id);
     foreach ($nodeList as $nodeItem) {
         $node = new NodeTree($this);
         $node->setId($nodeItem['id']);
         $node->buildBranches($collection, $this->id);
         $this->addNode($node);
     }
 }