/** * Get actions list * @return $array */ public function getActions() { if (!$this->_actions->hasChilds(0)) { return array(); } $list = $this->_actions->getChilds(0); $result = array(); if (!empty($list)) { foreach ($list as $k => $v) { $result[$v['id']] = $v['data']; } } return $result; }
/** * Fill childs data array for tree panel * @param Tree $tree * @param mixed $root * @return array */ protected function _fillChilds(Tree $tree, $root = 0) { $result = array(); $childs = $tree->getChilds($root); if (empty($childs)) { return array(); } foreach ($childs as $k => $v) { $row = $v['data']; $obj = new stdClass(); $obj->id = $row['tree_id']; $obj->text = $row['title']; $obj->expanded = true; $obj->leaf = false; $obj->allowDrag = true; $obj->page_id = $row['page_id']; $obj->parent_id = $row['parent_id']; $obj->published = $row['published']; $obj->url = isset($row['url']) ? $row['url'] : ''; $obj->resource_id = isset($row['resource_id']) ? $row['resource_id'] : ''; $obj->link_type = isset($row['link_type']) ? $row['link_type'] : ''; if ($row['published']) { $obj->iconCls = 'pagePublic'; } else { $obj->iconCls = 'pageHidden'; } $cld = array(); if ($tree->hasChilds($row['tree_id'])) { $cld = $this->_fillChilds($tree, $row['tree_id']); } $obj->children = $cld; $result[] = $obj; } return $result; }
/** * Fill childs data array for tree panel * @param Tree $tree * @param mixed $root * @return array */ protected function _fillChilds(Tree $tree, $root = 0) { $result = array(); $childs = $tree->getChilds($root); if (empty($childs)) { return array(); } $appConfig = Registry::get('main', 'config'); foreach ($childs as $k => $v) { $row = $v['data']; $obj = new stdClass(); $obj->id = $row['id']; $obj->text = $row['menu_title'] . ' <i>(' . $row['code'] . $appConfig['urlExtension'] . ')</i>'; $obj->expanded = true; $obj->leaf = false; if ($row['published']) { $obj->qtip = $row['menu_title'] . ' <i>(' . $row['code'] . $appConfig['urlExtension'] . ')</i> published'; $obj->iconCls = 'pagePublic'; } else { $obj->qtip = $row['menu_title'] . ' <i>(' . $row['code'] . $appConfig['urlExtension'] . ')</i> not published'; $obj->iconCls = 'pageHidden'; } if ($row['is_fixed']) { $obj->allowDrag = false; } $cld = array(); if ($tree->hasChilds($row['id'])) { $cld = $this->_fillChilds($tree, $row['id']); } $obj->children = $cld; $result[] = $obj; } return $result; }
/** * Fill childs data array for tree panel * @param Tree $tree * @param mixed $root * @return array */ protected function _fillChilds(Tree $tree, $root = 0) { $result = array(); $childs = $tree->getChilds($root); if (empty($childs)) { return array(); } foreach ($childs as $k => $v) { $row = $v['data']; $obj = new stdClass(); $obj->id = $row['id']; $obj->text = $row['name']; $obj->expanded = false; $obj->isDir = $row['isDir']; $obj->path = $row['path']; $obj->name = $row['name']; $obj->hid = $row['hid']; if ($row['isDir']) { $obj->leaf = false; } else { $obj->leaf = true; } $cld = array(); if ($tree->hasChilds($row['id'])) { $cld = $this->_fillChilds($tree, $row['id']); } $obj->children = $cld; $result[] = $obj; } return $result; }
/** * Move column * @param string $column * @param integer $from * @param integer $to */ public function moveColumn($column, $from, $to) { if (!$this->columnExists($column)) { return; } $this->changeParent($column, 0); $columns = $this->_columns->getChilds(0); $order = 0; if ($to > sizeof($columns) - 1) { $to = sizeof($columns) - 1; } foreach ($columns as $item) { $colName = $item['data']->getName(); if ($order == $to) { $this->setItemOrder($column, $order); $order++; continue; } if ($colName !== $column) { $this->setItemOrder($colName, $order); } $order++; } $this->reindexColumns(); $data = $this->_columns->getChilds(0); }
public static function getValuesNumber($path) { $data = array(); $tree = Tree::getTreeByUrl(); $ids[] = $tree['id']; $ids = array_merge($ids, Tree::getChilds($tree['id'])); $sql = ' SELECT DISTINCT type FROM {{data}} WHERE path=\'' . $path . '\' AND tree IN (' . implode(',', $ids) . ') '; $type = DB::getOne($sql); if ($type) { $sql = ' SELECT MAX(' . Fields::$fieldsName[$type] . ') AS maxv, MIN(' . Fields::$fieldsName[$type] . ') AS minv FROM {{data}} WHERE path=\'' . $path . '\' AND tree IN (' . implode(',', $ids) . ') '; $data = DB::getRow($sql); $data['type'] = substr($type, 0, 1); } if ($data['maxv'] > 0) { return $data; } else { return array(); } }
function del() { $ids = Tree::getChilds($_GET['id']); $ids[] = $_GET['id']; $sql = ' DELETE FROM {{forum}} WHERE id IN (' . implode(',', $ids) . ') '; DB::exec($sql); }
/** * Recursive method * @param string $parent - parent part id * @param Db_Select $sql */ protected function _fillQuery($partId, $sql, $countOnly = false) { $parentItem = $this->_tree->getItem($partId); $childs = $this->_tree->getChilds($partId); foreach ($childs as $child) { $this->_addSqlPart($child['data'], $sql, $parentItem['data'], $countOnly); $part = $child['data']; if ($this->_tree->hasChilds($part->getId())) { $this->_fillQuery($part->getId(), $sql, $countOnly); } } }
/** * Fill childs data array for tree panel * @param Tree $tree * @param mixed $root * @return array */ protected function _fillContainers(Tree $tree, $root = 0, $exceptStorage = true) { $exceptions = array('Store', 'Data_Store', 'Data_Store_Tree', 'Model'); $result = array(); $childs = $tree->getChilds($root); if (empty($childs)) { return array(); } foreach ($childs as $k => $v) { $object = $v['data']; $objectClass = $object->getClass(); $objectName = $object->getName(); if ($exceptStorage && in_array($objectClass, $exceptions, true)) { continue; } $item = new stdClass(); $item->id = $v['id']; $inst = ''; $ext = ''; if ($object->isInstance()) { $inst = ' <span class="extInstanceLabel" data-qtip="Object instance">instance of </span>' . $object->getObject()->getName(); } elseif ($object->isExtendedComponent()) { $ext = ' <span class="extCmpLabel" data-qtip="Extended component">ext</span> '; if ($object->defineOnly) { $objectName = '<span class="extClassLabel" data-qtip="defineOnly:true">' . $objectName . '</span>'; } } $item->text = $ext . $objectName . ' (' . $objectClass . ')' . $inst; $item->expanded = true; $item->objClass = $objectClass; $item->isInstance = $object->isInstance(); $item->leaf = true; $item->iconCls = self::getIconClass($objectClass); $item->allowDrag = Designer_Project::isDraggable($objectClass); if ($objectClass == 'Docked') { $item->iconCls = 'objectDocked'; $item->text = 'Docked Items'; } elseif ($objectClass == 'Menu') { $item->text = 'Menu Items'; $item->iconCls = 'menuItemsIcon'; } if (Designer_Project::isContainer($objectClass) && !$object->isInstance()) { $item->leaf = false; $item->children = array(); } if ($tree->hasChilds($v['id'])) { $item->children = $this->_fillContainers($tree, $v['id'], $exceptStorage); } $result[] = $item; } return $result; }
public function getList($parent) { $data = array(); $ids[] = $parent; $ids = array_merge($ids, Tree::getChilds($parent)); $sql = ' SELECT * FROM {{tree}} WHERE parent=' . $parent . ' AND visible=1 ORDER BY num '; $list = DB::getPagi($sql); foreach ($list as $item) { $fields = Fields::getFieldsByTree($item['id'], 'wide'); $data[] = array('name' => $item['name'], 'path' => $path, 'udate' => date('d.m.Y', strtotime($item['udate'])), 'answer' => $fields['answer']); } return $data; }
/** * Get root panels list * @return array */ public function getRootPanels() { $list = $this->_tree->getChilds(0); $names = array(); if (empty($list)) { return array(); } foreach ($list as $k => $v) { $object = $v['data']; $class = $object->getClass(); if ($class === 'Object_Instance') { $class = $object->getObject()->getClass(); } if (in_array($class, Designer_Project::$_containers, true) && $class !== 'Window' && $class != 'Menu' && !Designer_Project::isWindowComponent($class)) { $names[] = $object->getName(); } } return $names; }
public static function getMarket($id) { $data = array(); $tree = Tree::getInfo($id); if (strpos($tree['modul2'], 'catalog') !== 'false') { $sql = 'SHOW COLUMNS FROM {{catalog}}'; $cols = DB::getAll($sql); $x = 0; foreach ($cols as $item) { if ($item['Field'] == 'market') { $x = 1; } } if ($x) { $ids = Tree::getChilds($id); $ids[] = $id; $sql = ' SELECT COUNT(*) FROM {{catalog}} WHERE tree IN (' . implode(',', $ids) . ') AND market=1 '; $m1 = DB::getOne($sql); $sql = ' SELECT COUNT(*) FROM {{catalog}} WHERE tree IN (' . implode(',', $ids) . ') AND market=0 '; $m2 = DB::getOne($sql); if ($m1 >= $m2) { return 1; } else { return 0; } } else { return 0; } } return 0; }
/** * Fill childs data array for tree panel * @param Tree $tree * @param mixed $root * @return array */ protected function _fillCatChilds(Tree $tree, $root = 0) { $result = array(); $childs = $tree->getChilds($root); if (empty($childs)) { return array(); } foreach ($childs as $k => $v) { $row = $v['data']; $obj = new stdClass(); $obj->id = $row['id']; $obj->text = $row['title']; $obj->expanded = !intval($root); $obj->leaf = false; $obj->allowDrag = true; $cld = array(); if ($tree->hasChilds($row['id'])) { $cld = $this->_fillCatChilds($tree, $row['id']); } $obj->children = $cld; $result[] = $obj; } return $result; }
/** * Fill childs data array for tree panel * @param Tree $tree * @param mixed $root * @return array */ protected function _fillChilds(Tree $tree, $root = 0) { $expanded = array('system', 'system/app', 'system/library'); $result = array(); $childs = $tree->getChilds($root); if (empty($childs)) { return array(); } foreach ($childs as $k => $v) { $obj = new stdClass(); $obj->id = $v['id']; $obj->text = $v['data']; $obj->expanded = false; $cld = array(); if (strpos($obj->text, '.php')) { $obj->leaf = true; } else { if ($tree->hasChilds($v['id'])) { $cld = $this->_fillChilds($tree, $v['id']); if (empty($cld)) { continue; } } else { continue; } $obj->leaf = false; $obj->expanded = in_array($v['id'], $expanded, true); } $obj->checked = false; $obj->allowDrag = false; $obj->children = $cld; $result[] = $obj; } return $result; }
public static function del() { if ($_SESSION['user']) { $ids = Tree::getChilds($_GET['id']); $ids[] = $_GET['id']; $sql = ' DELETE FROM {{forum}} WHERE id IN (' . implode(',', $ids) . ') '; DB::exec($sql); } }
//==================================================== include '../common.inc.php'; include 'global.php'; include ROOT_PATH . 'include/tree.class.php'; function updateMenu() { $menu = $GLOBALS['tree']->getChilds(1); array_splice($menu, -6); foreach ($menu as $k => $v) { $_menu[$v['cid']] = $v; unset($menu[$k]); } writetofile(ROOT_PATH . 'admin/_menu.php', '$MENUS = ' . var_export($_menu, true)); } $tree = new Tree('category'); $cate = $tree->getChilds(1); $menu = $tree->getLayer($cate); if (basename(__FILE__, '.php') == 'menu') { if ($act == 'save') { $sort_order = empty($sort_order) ? 0 : intval($sort_order); $name = addslashes(trim($name)); $content = addslashes(trim($content)); if ($do == 'add') { $tree->addNode($cid, $name, $content, $sort_order); } else { $sql = "UPDATE `" . $tree->tablepre . $tree->table . "` SET name='{$name}',content='{$content}',sort_order='{$sort_order}'" . " WHERE cid={$cid}"; $db->query($sql); } updateMenu(); header("Location: menu.php"); } elseif ($act == 'edit') {
$_query = DB::query($sql); while ($res = DB::fetch($_query)) { $cats[$res['catid']] = $res; } include_once B_ROOT . './source/class/tree.class.php'; $tree = new Tree($type); $miniupid = ''; $space = '|----'; foreach ($cats as $catid => $category) { if ($miniupid === '') { $miniupid = $category['upid']; } $tree->setNode($category['catid'], $category['upid'], $category); } if (count($cats) > 0) { $categoryarr = $tree->getChilds($miniupid); foreach ($categoryarr as $key => $catid) { $cat = $tree->getValue($catid); $cat['pre'] = $tree->getLayer($catid, $space); $cat['havechild'] = $tree->getChild($catid) ? 1 : 0; $listarr[$cat['catid']] = $cat; } } echo '<option value="0" selected="selected">' . lang('please_select') . "</option>\n"; foreach ($listarr as $catinfo) { echo '<option value="' . $catinfo['catid'] . '">' . $catinfo['pre'] . $catinfo['name'] . '</option>'; } } } elseif ($opt == 'search') { //關聯信息中搜索該商舖下的關聯對像 $shopid = intval($_GET['shopid']);
function getMultival($row) { $data = array(); if ($row['module']) { $row['name'] = FieldWidget::getFieldReserve($row, 'name'); $row['params'] = FieldWidget::getFieldReserve($row, 'params'); } $params = explode('-', $row['params']); $module = Module::getModuleByPath($params[0]); if ($module) { if ($module['type'] == 'cat') { if (count($params) == 2) { $sql = ' SELECT {{tree}}.* FROM {{tree}} INNER JOIN {{catalog}} ON {{tree}}.id={{' . $module['path'] . '}}.tree WHERE 1 ORDER BY num '; } else { $sql = 'SELECT id FROM {{tree}} WHERE path=\'' . $params[1] . '\' ORDER BY num'; $id = DB::getOne($sql); if ($id) { $ids = array_merge(array($id), Tree::getChilds($id)); $sql = ' SELECT {{tree}}.* FROM {{tree}} INNER JOIN {{catalog}} ON {{tree}}.id={{' . $module['path'] . '}}.tree WHERE parent IN (' . implode(',', $ids) . ') ORDER BY num '; } } } } else { if (count($params) == 2) { $sql = 'SELECT * FROM {{' . $params[0] . '}} ORDER BY num'; } elseif (count($params) > 2) { $sql = 'SELECT id FROM {{' . $params[0] . '}} WHERE path=\'' . $params[1] . '\' ORDER BY num'; $parent = DB::getOne($sql); if ($parent == '') { $parent = 0; } $sql = 'SELECT * FROM {{' . $params[0] . '}} WHERE parent=' . $parent . ' ORDER BY num'; } else { $sql = ''; } } if ($sql) { $items = DB::getAll($sql); $sql = 'SELECT id2 FROM {{relations}} WHERE modul1=\'data\' AND id1=' . $row['id'] . ''; $result = DB::getAll($sql, 'id2'); foreach ($items as $item) { if ($params[0] == 'tree') { $gal = FieldWidget::getPics($item); } $multival = ''; if (in_array($item['id'], $result)) { $sql = 'SELECT * FROM {{multival}} WHERE relations=' . $item['id'] . ' AND data=' . $row['id'] . ''; $multival = DB::getRow($sql); for ($i = 1; $i < 4; $i++) { $multival[$i] = $multival['value_string' . $i] == '' ? $multival['value_int' . $i] : $multival['value_string' . $i]; } } $data[] = array('name' => $item[$params[count($params) - 1]], 'value' => $item['id'], 'checked' => in_array($item['id'], $result) ? 'checked' : '', 'multival' => $multival, 'gal' => $gal); } $row['list'] = $data; } else { $row['list'] = array(); } View::widget('fields/multival', $row); }
function getmodelcategory($name, $space = '|----') { global $_SGLOBAL; include_once S_ROOT . './class/tree.class.php'; $tree = new Tree($name); $query = $_SGLOBAL['db']->query('SELECT * FROM ' . tname('categories') . ' WHERE `type`=\'' . $name . '\' ORDER BY upid, displayorder'); $miniupid = ''; while ($value = $_SGLOBAL['db']->fetch_array($query)) { if ($miniupid == '') { $miniupid = $value['upid']; } $tree->setNode($value['catid'], $value['upid'], $value); } //¸ùĿ¼ $listarr = array(); if ($_SGLOBAL['db']->num_rows($query) > 0) { $categoryarr = $tree->getChilds($miniupid); foreach ($categoryarr as $key => $catid) { $cat = $tree->getValue($catid); $cat['pre'] = $tree->getLayer($catid, $space); $listarr[$cat['catid']] = $cat; } } return $listarr; }
public function market() { $this->checkRights(); $ids = Tree::getChilds($_POST['id']); $ids[] = $_POST['id']; $sql = ' UPDATE {{catalog}} SET market=' . $_POST['on'] . ' WHERE tree IN (' . implode(',', $ids) . ') '; DB::exec($sql); }
/** * Fill childs data array for tree panel * @param Tree $tree * @param mixed $root * @return array */ protected function _fillChilds(Tree $tree, $root = 0) { $result = array(); $childs = $tree->getChilds($root); if (empty($childs)) { return array(); } foreach ($childs as $k => $v) { $obj = new stdClass(); $obj->id = $v['id']; $obj->text = $v['data']; $obj->expanded = false; $obj->checked = false; $obj->allowDrag = false; if (strpos($obj->text, '.') && !$tree->hasChilds($v['id'])) { $obj->leaf = true; } else { $obj->leaf = false; } $cld = array(); if ($tree->hasChilds($v['id'])) { $cld = $this->_fillChilds($tree, $v['id']); } $obj->children = $cld; $result[] = $obj; } return $result; }
public static function getHits() { $data = array(); $ids = Tree::getChilds(2); $sql = ' SELECT DISTINCT {{tree}}.id FROM {{tree}} INNER JOIN {{catalog}} ON {{catalog}}.tree={{tree}}.id WHERE {{tree}}.visible=1 AND {{tree}}.parent IN (' . implode(',', $ids) . ') AND {{catalog}}.hit=1 ORDER BY {{tree}}.num DESC LIMIT 0,4 '; //print DB::prefix($sql); $list = DB::getAll($sql); foreach ($list as $item) { $data[] = Catalog::getOne($item['id']); } return $data; }
function del() { $ids = Tree::getChilds($_GET['id']); $ids[] = $_GET['id']; foreach ($ids as $id) { Tree::saveSearch($id); $sql = ' SELECT * FROM {{data}} WHERE type=\'gallery\' AND tree=\'' . $id . '\' '; $gals = DB::getAll($sql); foreach ($gals as $item) { if ($item['id']) { $sql = ' SELECT * FROM {{relations}} WHERE modul1=\'data\' AND modul2=\'files\' AND id1=\'' . $item['id'] . '\' '; $files = DB::getAll($sql); foreach ($files as $file) { $sql = ' SELECT id1 FROM {{relations}} WHERE modul1=\'data\' AND modul2=\'files\' AND id1<>\'' . $item['id'] . '\' AND id2=' . $file['id2'] . ' '; $id1 = DB::getOne($sql); if (!$id1) { Fields::removeFile($item['id'], $file['id2']); } } } } $sql = ' DELETE FROM {{relations}} WHERE modul1=\'tree\' AND id1=\'' . $id . '\' '; DB::exec($sql); $sql = ' DELETE FROM {{data}} WHERE tree=\'' . $id . '\' '; DB::exec($sql); $sql = ' DELETE FROM {{tree}} WHERE id=\'' . $id . '\' '; DB::exec($sql); $sql = ' DELETE FROM {{catalog}} WHERE tree=\'' . $id . '\' '; DB::exec($sql); } }
public static function getVendors($parent, $models = array()) { $vendors['list'] = array(); if (Funcs::$uri[2] == '') { $sql = 'SELECT id FROM {{tree}} WHERE path=\'' . Funcs::$uri[1] . '\' AND visible=1'; $id = DB::getOne($sql); $ids = Tree::getChilds($id); $sql = ' SELECT DISTINCT {{reference}}.name, {{reference}}.path, {{reference}}.id FROM {{reference}} INNER JOIN ({{catalog}} INNER JOIN {{tree}} ON {{catalog}}.tree={{tree}}.id) ON {{reference}}.id={{catalog}}.vendor WHERE {{tree}}.id IN (' . implode(',', $ids) . ') AND {{tree}}.visible=1 ORDER BY name '; } else { $sql = ' SELECT DISTINCT {{reference}}.name, {{reference}}.path, {{reference}}.id FROM {{reference}} INNER JOIN ({{catalog}} INNER JOIN {{tree}} ON {{catalog}}.tree={{tree}}.id) ON {{reference}}.id={{catalog}}.vendor WHERE {{tree}}.parent=' . $parent . ' AND {{tree}}.visible=1 ORDER BY name '; } $list = DB::getAll($sql); $vendorIds = array(); $vendorCount = array(); foreach ($models as $items) { foreach ($items as $item) { $vendorIds[] = $item['vendor']; $vendorCount[$item['vendor']]++; } } foreach ($list as $item) { if (in_array($item['id'], $vendorIds) && isset($_GET['opt'])) { $vendors['list'][] = array('id' => $item['id'], 'name' => $item['name'], 'path' => $item['path'], 'count' => $vendorCount[$item['id']]); } elseif (!isset($_GET['opt'])) { $sql = ' SELECT COUNT({{tree}}.id) FROM {{catalog}} INNER JOIN {{tree}} ON {{catalog}}.tree={{tree}}.id WHERE {{tree}}.parent=' . $parent . ' AND {{tree}}.visible=1 AND {{catalog}}.vendor=' . $item['id'] . ' '; $count = DB::getOne($sql); $vendors['list'][] = array('id' => $item['id'], 'name' => $item['name'], 'path' => $item['path'], 'count' => $count); } } return $vendors; }
function getbbsforum($isblog = 0, $space = '|----') { global $_SGLOBAL; dbconnect(1); $forumarr = array(); if ($isblog) { $wheresql = ' AND (type=\'group\' || allowshare=\'1\')'; } else { $wheresql = ''; } include_once S_ROOT . './class/tree.class.php'; $tree = new Tree('blog'); $minfup = ''; $query = $_SGLOBAL['db_bbs']->query('SELECT * FROM ' . tname('forums', 1) . ' WHERE status>0' . $wheresql . ' ORDER BY fup, displayorder'); while ($forum = $_SGLOBAL['db_bbs']->fetch_array($query)) { if ($minfup == '') { $minfup = $forum['fup']; } $tree->setNode($forum['fid'], $forum['fup'], $forum); } //根目录 $listarr = array(); $categoryarr = $tree->getChilds($minfup); foreach ($categoryarr as $key => $catid) { $cat = $tree->getValue($catid); $cat['pre'] = $tree->getLayer($catid, $space); $listarr[$cat['fid']] = $cat; } return $listarr; }
<?php include "common.inc.php"; InitGP(array("action", "tid", "gid", "ps", "page")); //初始化变量全局返回 $goodsobj = new TableClass('shop_goods', 'gid'); $typeobj = new TableClass('shop_gtype', 'typeid'); //读取分类信息 $typearray = $typeobj->getdata('', '', 'typeid asc'); include_once INC_PATH . '/tree.class.php'; $tree = new Tree($typearray, 'typeid', 'node'); //分类处理 $categoryarr = $tree->getChilds(0); $space = '|----'; foreach ($categoryarr as $key => $catid) { $cat = $tree->getValue($catid); $cat['pre'] = $tree->getLayer($catid, $space); $listarr[$cat['typeid']] = $cat; } //读取分类结束 if ($action == 'list') { $tid = GetNum($tid); $gtype = $tree->getValue($tid); if ($gtype['node'] == 0) { $position = "<span>></span><a href='shop.php?action=list&tid=" . $gtype['typeid'] . "'>" . $gtype['typename'] . "</a>"; $typename = $gtype['typename']; } else { $cgtype = $tree->getValue($gtype['node']); $typename = $cgtype['typename']; $position = "<span>></span><a href='shop.php?action=list&tid=" . $cgtype['typeid'] . "'>" . $cgtype['typename'] . "</a>"; $position .= "<span>></span><a href='shop.php?action=list&tid=" . $gtype['typeid'] . "'>" . $gtype['typename'] . "</a>";
/** * 从缓存中获得模型分类 */ function getmodelcachecategory($categoryarr, $space = '|----', $delbase = 0) { include_once S_ROOT . './class/tree.class.php'; $tree = new Tree(''); $miniupid = 0; $delid = array(); if ($delbase) { $delid[] = $delbase; } $listarr = array(); if (!empty($categoryarr)) { foreach ($categoryarr as $value) { $tree->setNode($value['catid'], $value['upid'], $value); } //根目录 $carr = $tree->getChilds($miniupid); foreach ($carr as $key => $catid) { $cat = $tree->getValue($catid); $cat['pre'] = $tree->getLayer($catid, $space); if (!empty($delid) && (in_array($cat['upid'], $delid) || $cat['catid'] == $delbase)) { $delid[] = $cat['catid']; } else { $listarr[$cat['catid']] = $cat; } } } return $listarr; }
public function testGetChilds() { $tree = new Tree(); $item = new stdClass(); $tree->addItem(1, 0, 'item1'); $tree->addItem(2, 1, 100); $tree->addItem(3, 1, 200); $tree->addItem(4, 3, 'item3-1'); $childs = $tree->getChilds(1); $this->assertEquals(count($childs), 2); $this->assertEquals($childs[2]['data'], 100); $this->assertEquals($childs[3]['data'], 200); }