$result['id']), true, true); break; case 'post': $result['href'] = U('Home/Nav/lists', array('id' => $result['id']), true, true); break; } } /** * 查找后置操作 * */ protected function _after_select(&$result, $options) { foreach ($result as &$record) { $this->_after_find($record, $options); } } /** * 导航类型 * */ public function nav_type($id = 0) { $list['link'] = '链接'; $list['module'] = '模块'; $list['page'] = '单页'; $list['post'] = '文章列表'; return $id ? $list[$id] : $list; } /** * 根据导航类型获取值 * */ public function get_value_by_type($value) { if (!$value) { switch (I('post.type')) { case 'link': return I('post.url'); break; case 'module': return I('post.module_name'); break; case 'page': return I('post.content'); break; } } else { return $value; } } /** * 获取参数的所有父级导航 * @param int $id 导航id * @return array 参数导航和父类的信息集合 * */ public function getParentNav($id, $group = 'main') { if (empty($id)) { return false; } $con['status'] = 1; $con['group'] = array('eq', $group); $nav_list = $this->where($con)->field(true)->order('sort asc,id asc')->select(); $current_nav = $this->field(true)->find($cid); //获取当前导航的信息 $result[] = $current_nav; $pid = $current_nav['pid']; while (true) { foreach ($nav_list as $key => $val) { if ($val['id'] == $pid) { $pid = $val['pid']; array_unshift($result, $val); //将父导航插入到第一个元素前 } } // 已找到顶级导航或者没有任何父导航 if ($pid == 0 || count($result) == 1) { break; } } return $result; } /** * 获取导航树,指定导航则返回指定导航的子导航树,不指定则返回所有导航树,指定导航若无子导航则返回同级导航 * @param integer $id 导航ID * @param boolean $field 查询字段 * @return array 导航树 * */ public function getNavTree($id = 0, $group = 'main', $field = true) { if (!in_array(MODULE_NAME, array('Admin', 'Common')) && is_file(APP_PATH . MODULE_NAME . '/Model/NavModel.class.php')) { $module_nav_tree = D(MODULE_NAME . '/Nav')->getNavTree($id, $group, $field); if ($module_nav_tree) { return $module_nav_tree; } } // 开启默认模块并且使用默认模块布局 if (C('DEFAULT_MODULE_LAYOUT') && C('DEFAULT_PUBLIC_LAYOUT') && is_file(APP_PATH . C('DEFAULT_MODULE') . '/Model/NavModel.class.php')) { $module_nav_tree = D(C('DEFAULT_MODULE') . '/Nav')->getNavTree($id, $group, $field); if ($module_nav_tree) { return $module_nav_tree; } } // 获取当前导航信息 if ((int) $id > 0) { $info = $this->find($id); $id = $info['id']; } // 获取所有导航 $map['status'] = array('eq', 1); $map['group'] = array('eq', $group); $tree = new Tree(); $list = $this->field($field)->where($map)->order('sort asc,id asc')->select(); // 返回当前导航的子导航树 $list = $tree->list2tree( $list, $pk = 'id', $pid = 'pid', $child = '_child', $root = (int) $id ); if (!$list) { return $this->getSameLevelNavTree($id); } return $list; } /** * 获取同级导航树 * @param integer $id 导航ID * @return array 导航树 * */ public function getSameLevelNavTree($id = 0, $group = 'main') { //获取当前导航信息 if ((int) $id > 0) { $nav_info = $this->find($id); $parent_info = $this->find($nav_info['pid']); $id = $info['id']; } //获取所有导航 $map['status'] = array('eq', 1); $map['group'] = array('eq', $group); $map['pid'] = array('eq', $nav_info['pid']); $tree = new Tree(); $list = $this->field($field)->where($map)->order('sort asc,id asc')->select(); return $list; } }