getChildCategories($category_id); } else { $categories = $this->getFirstLevelCategories(); } foreach ($categories as $category) { $data = array(); $data ["data"]["title"]= $category->title; $data ["data"]["attr"]["id"] = $category->id; $parent_childs = $this->getChildCategories($category->id); if (count($parent_childs) > 0) { $child_data = $this->getCategoriesAsArray($category->id); $data ["children"] = $child_data; } $result []= $data; } return $result; } function getCategoriesForSelect($category_id=0, $level=0) { $result = array(); if ($category_id != 0) { $categories = $this->getChildCategories($category_id); } else { $categories = $this->getFirstLevelCategories(); } foreach ($categories as $category) { if (!$category->parent) {$level = 0;} $data = array(); $spaces = str_repeat("    ", $level); $title = $category->title; if (strlen($title) > 30) { $title = substr($title, 0, 30) . ".."; } $data ["title"]= $spaces . $title; $data ["id"]= $category->id; $data ["full_title"]= $category->title; $result []= $data; $parent_childs = $this->getChildCategories($category->id); if (count($parent_childs) > 0) { $level += 1; $child_data = $this->getCategoriesForSelect($category->id, $level); $result = array_merge($result, $child_data); } } return $result; } function getChildCategoriesForSelect($category_id, $level) { $result = array(); $categories = $this->getChildCategories($category_id); foreach ($categories as $category) { $data = array(); $spaces = str_repeat(" ", $level); $data ["title"]= $spaces . $category->title; $data ["id"] = $category->id; $result []= $data; $parent_childs = $this->getChildCategories($category->id); if (count($parent_childs) > 0) { $level += 1; $child_data = $this->getCategoriesForSelect($category->id, $level); $data ["children"] = $child_data; } } return $result; } } ?>