本文整理汇总了PHP中Tree类的典型用法代码示例。如果您正苦于以下问题:PHP Tree类的具体用法?PHP Tree怎么用?PHP Tree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gettree
function gettree()
{
$model = new Tree();
$tree = $model->getTree();
View::$layout = 'empty';
View::render('fields/parenttree', array('tree' => $tree));
}
示例2: _get_data
function _get_data()
{
$cache_server =& cache_server();
$key = $this->_get_cache_id();
$data = $cache_server->get($key);
if ($data === false) {
$gcategory_mod =& bm('gcategory', array('_store_id' => 0));
$gcategories = array();
$brand_mod =& m('brand');
if (empty($this->options['amount'])) {
$gcategories = $gcategory_mod->get_list(-1, true);
} else {
$gcategory = $gcategory_mod->get_list(0, true);
$gcategories = $gcategory;
foreach ($gcategory as $val) {
$result = $gcategory_mod->get_list($val['cate_id'], true);
$result = array_slice($result, 0, $this->options['amount']);
$gcategories = array_merge($gcategories, $result);
}
}
import('tree.lib');
$tree = new Tree();
$tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name');
$data = array('gcategories' => $tree->getArrayList(0), 'model_name' => $this->options['model_name'], 'brands' => $brand_mod->find(array('conditions' => "recommended = 1 AND if_show = 1", 'order' => 'sort_order', 'limit' => $this->_num)));
$cache_server->set($key, $data, $this->_ttl);
}
return $data;
}
示例3: doSearch
function doSearch()
{
$keyword = $_REQUEST['keyword'];
$filter_keyword = '%' . $keyword . '%';
$page_num = $_REQUEST['page_num'] ? $_REQUEST['page_num'] : 1;
//get ids
$q = "select id from trees where title like ? or description like ? ";
$st = $this->dbconn->Prepare($q);
$r1 = $this->dbconn->getAll($st, array($filter_keyword, $filter_keyword));
$q = "select tree_id from tree_parameters where value like ? or node like ? ";
$st = $this->dbconn->Prepare($q);
$r2 = $this->dbconn->getAll($st, array($filter_keyword, $filter_keyword));
$q = "select t.id from trees t LEFT JOIN users u ON u.id= t.user_id where u.name like ? or u.description like ? or u.email like ? ";
$st = $this->dbconn->Prepare($q);
$r3 = $this->dbconn->getAll($st, array($filter_keyword, $filter_keyword, $filter_keyword));
$r = array_merge($r1, $r2, $r3);
$r_ids = array();
foreach ($r as $row) {
$r_ids[] = $row[0];
}
rsort($r_ids);
$pages_count = round(count($r_ids) / 10 + 0.4);
$tree_model = new Tree($this->dbconn);
$trees = $tree_model->fetchAll(array('filter' => " WHERE id in (" . implode(",", $r_ids) . ") LIMIT " . ($page_num - 1) * 10 . ",10", 'values' => array()), 'all');
$this->smarty->Assign('keyword', $keyword);
$this->smarty->Assign('trees', $trees);
$this->smarty->Assign('page_num', $page_num);
$this->smarty->Assign('pages_count', $pages_count);
$this->display('Search/result.tpl');
}
示例4: _get_data
function _get_data()
{
$this->options['amount'] = intval($this->options['amount']);
$cache_server =& cache_server();
$key = $this->_get_cache_id();
$data = $cache_server->get($key);
if ($data === false) {
$gcategory_mod =& bm('gcategory', array('_store_id' => 0));
$gcategories = array();
if (empty($this->options['amount'])) {
$gcategories = $gcategory_mod->get_list(-1, true);
} else {
$gcategory = $gcategory_mod->get_list(0, true);
$gcategories = $gcategory;
foreach ($gcategory as $val) {
$result = $gcategory_mod->get_list($val['cate_id'], true);
$result = array_slice($result, 0, $this->options['amount']);
$gcategories = array_merge($gcategories, $result);
}
}
import('tree.lib');
$tree = new Tree();
//LLL 商品分类挂件根据语言选择分类字段
$lang2 = get_lang2();
//like fr,sc etc...
$gcategories = chg_array2_string($gcategories, 'cate_name', $lang2);
$tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name');
$data = $tree->getArrayList(0);
$cache_server->set($key, $data, $this->_ttl);
}
return $data;
}
示例5: index
function index()
{
$result = $this->terms_obj->order(array("listorder" => "asc"))->select();
/* $tree = new PathTree();
$tree->icon = array(' │ ', ' ├─ ', ' └─ ');
$tree->nbsp = '---';
$tree->init($result);
$tree=$tree->get_tree();
$this->assign("terms",$tree); */
$tree = new \Tree();
$tree->icon = array(' │ ', ' ├─ ', ' └─ ');
$tree->nbsp = ' ';
foreach ($result as $r) {
$r['str_manage'] = '<a href="' . U("AdminTerm/add", array("parent" => $r['term_id'])) . '">添加子类</a> | <a href="' . U("AdminTerm/edit", array("id" => $r['term_id'])) . '">修改</a> | <a class="J_ajax_del" href="' . U("AdminTerm/delete", array("id" => $r['term_id'])) . '">删除</a> ';
$url = U('portal/list/index', array('id' => $r['term_id']));
$r['url'] = $url;
$r['taxonomys'] = $this->taxonomys[$r['taxonomy']];
$r['id'] = $r['term_id'];
$r['parentid'] = $r['parent'];
$array[] = $r;
}
$tree->init($array);
$str = "<tr>\r\n\t\t\t\t\t<td><input name='listorders[\$id]' type='text' size='3' value='\$listorder' class='input input-order'></td>\r\n\t\t\t\t\t<td>\$id</td>\r\n\t\t\t\t\t<td>\$spacer <a href='\$url' target='_blank'>\$name</a></td>\r\n\t \t\t\t<td>\$taxonomys</td>\r\n\t\t\t\t\t<td align='center'><a href='\$url' target='_blank'>访问</a></td>\r\n\t\t\t\t\t<td>\$str_manage</td>\r\n\t\t\t\t</tr>";
$taxonomys = $tree->get_tree(0, $str);
$this->assign("taxonomys", $taxonomys);
$this->display();
//$this->display();
}
示例6: index
public function index()
{
$map['status'] = array('lt', 2);
$list = $this->_list(MODULE_NAME, $map);
foreach ($list as $key => $v) {
$adata = M($v["mx"])->field("title")->getByid($v["mid"]);
if ($v["status"] == 1) {
$list[$key]["title"] = $adata["title"];
} else {
$list[$key]["title"] = "<font color=red>" . $adata["title"] . "--未处理</font>";
}
$list[$key]["url"] = "/index.php?m=" . $v["mx"] . "&a=show&id=" . $v["mid"];
}
/*获得分类*/
if ($this->categorys) {
$arrx = explode(",", "1,4,33");
foreach ((array) $arrx as $key => $v) {
$array[$v] = $this->categorys[$v];
$arr = explode(",", $this->categorys[$v]["arrchildid"]);
}
//print_r($array);
import('@.ORG.Tree');
$str = "<option value='\$id' \$disabled \$selected>\$spacer \$catname</option>";
$tree = new Tree($array);
$select_categorys = $tree->get_tree(0, $str);
$this->assign('select_categorys', $select_categorys);
$this->assign('categorys', $this->categorys);
}
$this->assign('list', $list);
$this->display();
}
示例7: isManager
/**
* Is the specified/current user a manager of a tree?
*
* @param Tree $tree
* @param User|null $user
*
* @return bool
*/
public static function isManager(Tree $tree, User $user = null)
{
if ($user === null) {
$user = self::user();
}
return self::isAdmin($user) || $user && $tree->getUserPreference($user, 'canedit') === 'admin';
}
示例8: edit
function edit()
{
if (IS_POST) {
$post = I('post.');
$data['parent'] = $post['parent'];
$data['title'] = $post['title'];
$data['listorder'] = $post['listorder'];
$map['user_id'] = $this->uid;
$map['id'] = $post['id'];
if ($this->categories->where($map)->save($data) !== false) {
$this->success('类别修改成功!');
} else {
$this->error('类别修改失败!');
}
} else {
$id = I('id');
$map_categories['id'] = $id;
$map_categories['user_id'] = $this->uid;
$data = $this->categories->where($map_categories)->field(true)->find();
if ($data == null) {
$this->error('没有这个类别!');
}
$map['user_id'] = $this->uid;
$list = $this->categories->where($map)->order('listorder')->select();
import('@.Rover.Tree');
$tree = new Tree();
$tree->init($list);
$str = "<option \$css value=\$id \$selected>\$spacer\$title</option>";
$selected = $tree->get_tree(0, $str, $data['parent']);
$this->assign('selected', $selected);
$this->assign('data', $data);
$this->display('mod');
}
}
示例9: get_header_gcategories
function get_header_gcategories($amount, $position, $brand_is_recommend = 1)
{
$gcategory_mod =& bm('gcategory', array('_store_id' => 0));
$gcategories = array();
if (!$amount) {
$gcategories = $gcategory_mod->get_list(-1, true);
} else {
$gcategory = $gcategory_mod->get_list(0, true);
$gcategories = $gcategory;
foreach ($gcategory as $val) {
$result = $gcategory_mod->get_list($val['cate_id'], true);
$result = array_slice($result, 0, $amount);
$gcategories = array_merge($gcategories, $result);
}
}
import('tree.lib');
$tree = new Tree();
$tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name');
$gcategory_list = $tree->getArrayList(0);
$i = 0;
$brand_mod =& m('brand');
foreach ($gcategory_list as $k => $v) {
$gcategory_list[$k]['top'] = isset($position[$i]) ? $position[$i] : '0px';
$i++;
$gcategory_list[$k]['brands'] = $brand_mod->find(array('conditions' => "tag = '" . $v['value'] . "' AND recommended=" . $brand_is_recommend, 'order' => 'sort_order asc,brand_id desc'));
}
return array('gcategories' => $gcategory_list);
}
示例10: index
public function index()
{
$sort = $this->_get("sort", 'trim', 'ordid');
$order = $this->_get("order", 'trim', 'ASC');
$tree = new Tree();
$tree->icon = array('│ ', '├─ ', '└─ ');
$tree->nbsp = ' ';
$result = $this->_mod->where(array('lang' => $this->lang))->order($sort, $order)->select();
$array = array();
foreach ($result as $r) {
$r['str_type'] = L('type_' . $r['type']);
$r['str_manage'] = '<a href="' . U('home/content/index', array('cid' => $r['id'])) . '" target="_blank">' . L('lable_browse') . '</a> |
' . ($r['type'] == 0 ? '<a href="' . U('content/index', array('cat_id' => $r['id'])) . '">' . L('tabs_content') . '</a> | ' : '') . '
<a href="' . U('category/add', array('pid' => $r['id'])) . '">' . L('lable_addsoncate') . '</a> |
<a href="' . U('category/edit', array('id' => $r['id'])) . '">' . L('lable_edit') . '</a> |
<a href="javascript:;" class="J_confirmurl" data-acttype="ajax" data-uri="' . U('category/delete', array('id' => $r['id'])) . '" data-msg="' . sprintf(L('confirm_delete_one'), $r['name']) . '分类下的文章也会删除">' . L('lable_del') . '</a>';
$r['parentid_node'] = $r['pid'] ? ' class="child-of-node-' . $r['pid'] . '"' : '';
$array[] = $r;
}
$str = "<tr id='node-\$id' \$parentid_node>\n <td class='text-c'>\$id</td>\n\t\t\t\t\t\t\t\t<td class='text-c'><span data-tdtype='edit' data-field='ordid' data-id='\$id' class='tdedit'>\$ordid</span></td>\n <td>\$spacer<span data-tdtype='edit' data-field='name' data-id='\$id' class='tdedit'>\$name</span></td>\n\t\t\t\t\t\t\t\t<td align='center' class='type_\$type'>\$str_type</td>\n <td class='text-c'>\$str_manage</td>\n </tr>";
$tree->init($array);
$list = $tree->get_tree(0, $str);
$this->assign('curr_name', 'index');
$this->assign('list', $list);
$this->assign('list_table', true);
$this->display();
}
示例11: _fillChilds
/**
* 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;
}
示例12: index
public function index()
{
$tree = new Tree();
$tree->icon = array('│ ', '├─ ', '└─ ');
$tree->nbsp = ' ';
$result = $this->_mod->select();
$array = array();
foreach ($result as $arr) {
$arr['status'] = '<i data-editid="' . $arr['id'] . '" data-editype="single" data-editfield="status" data-toggle="AJAXedit" data-editurl="' . U('admin/ajax_edit') . '" class="' . ($arr['status'] == 0 ? 'icon-remove' : 'icon-ok') . '" data-value="' . $arr['status'] . '"></i>';
$arr['mangers'] = '<a class="editing" data-id="' . $arr['id'] . '" href="#editing" data-orgurl="' . U('admin/edit') . '" data-url="' . U('admin/edit', array('id' => $arr['id'])) . '" data-toggle="modal">' . L('edit') . '</a>
<a data-toggle="AJAXdelete" data-url="' . U('admin/delete', array('id' => $arr['id'])) . '" >' . L('del') . '</a>
';
$arr['p_node'] = $arr['pid'] ? ' class="child-node-' . $arr['pid'] . '"' : '';
$array[] = $arr;
}
$auth = array();
$auth = session('admin');
if ($auth['role_id'] > 1) {
$str = "<tr id='node-\$id' \$p_node >\r\n <td align='center'><input type='checkbox' value='\$id' class='J_checkitem'></td>\r\n <td align='center'>\$id</td>\r\n <td>\$spacer<span data-toggle='AJAXedit' data-value='\$name' data-editype='word' data-editurl='" . U('admin/ajax_edit') . "' data-editfield='name' data-editid='\$id'>\$username</span></td>\r\n <td>\$status</td>\r\n \t<td>\$mangers</td>\r\n </tr>";
} else {
}
$str = "<tr id='node-\$id' \$p_node >\r\n <td align='center'><input type='checkbox' value='\$id' class='J_checkitem'></td>\r\n <td align='center'>\$id</td>\r\n <td>\$spacer<span data-toggle='AJAXedit' data-value='\$name' data-editype='word' data-editurl='" . U('admin/ajax_edit') . "' data-editfield='name' data-editid='\$id'>\$username</span></td>\r\n <td>\$status</td>\r\n \t<td>\$mangers</td>\r\n </tr>";
$tree->init($array);
$list = $tree->get_tree(0, $str);
$this->assign('list', $list);
$add_menu = array('title' => L('admin_add'), 'url' => U('admin/add'), 'id' => 'admin_add', 'width' => '500', 'height' => '350', 'btn' => 'save', 'getajax' => U('admin/ajax_getroles'));
$this->assign('add_menu', $add_menu);
$this->display();
}
示例13: get_tpl_slotz
function get_tpl_slotz($tpl_name)
{
$tpl_tree = new Tree($_DB['DB_NAME'], 'template_container');
if ($tpl_id = $tpl_tree->FindbyBasic(1, $tpl_name)) {
return $tpl_slotz = $tpl_tree->GetChildsParam($tpl_id[0], array('SlotAlias'), true);
}
}
示例14: info
public function info($type = 'admin')
{
parent::info();
$cid = intval($this->input->get_post('cid'));
$options = array();
if ($cid > 0) {
$options['where'] = array('cid' => $cid);
}
$item = $this->model->getOne($options, true);
$this->parameters->fromArray(json_to_array($item['params']));
$item['params'] = $this->parameters;
$parents = array('顶级栏目');
$where = array();
if ($this->user_info->key != 'root') {
$where = array('status >=' => 0);
}
$item['type'] = $item['type'] ? $item['type'] : $type;
$options = array('type' => $item['type'], 'where' => $where, 'order' => " order_id desc,cid desc");
$tree = new Tree();
$tree->init($this->model->getAll2Array($options));
foreach ($tree->getValueOptions() as $k => $tmp) {
$parents[$k] = $tmp['title'];
}
$data = array('parents' => $parents, 'item' => $item);
$this->_template('admin/setting/columinfo', $data);
}
示例15: info
public function info()
{
$infoid = I('get.infoid');
$this->assign('infoid', $infoid);
//获取车型列表
$info_db = D('Info');
$infoList = $info_db->getInfoList();
$this->assign('infoList', $infoList);
//题图
$topPicList = getPicMetaArr($infoid, 91);
//print_r($topPicList);exit;
$this->assign('topPicList', $topPicList);
$classself_db = D('ClassSelf');
$data_class = array();
$data_class = $classself_db->getClassSelfList($infoid);
foreach ($data_class as $key => &$row) {
if ($row['classid'] == 91) {
unset($data_class[$key]);
}
if ($row['parentid'] == 91) {
unset($data_class[$key]);
}
$row['cid'] = $row['id'];
$row['id'] = $row['classid'];
}
$tree = new \Tree();
$tree->init($data_class);
$menuList = $tree->get_tree_array(0);
$this->assign('menuList', $menuList);
$this->display(":info");
}