/** * Build recursive array from a root category * JsTree JSON format * @param Category $category * @return array */ protected function toArray(Category $category) { $children = array(); foreach ($category->getChildren() as $child) { $children[] = $this->toArray($child); } return array('id' => $category->getId(), 'text' => $category->getName(), 'state' => array('opened' => true, 'disabled' => false, 'selected' => false), 'children' => $children); }
/** * @param Category $child * @return $this */ public function addChild(Category $child) { $child->setParent($this); $this->children[] = $child; return $this; }