完善新闻中心各项功能,添加左右值分类功能

This commit is contained in:
Li Jianxuan 2012-11-28 09:27:53 +00:00
parent 21bd8bf9b6
commit d93828c079
14 changed files with 385 additions and 285 deletions

View File

@ -14,20 +14,15 @@ class Admin_NewsController extends Zend_Controller_Action
}
function indexAction()
{
$sql = "select n.*,c.title as catlog,u.realname as author from news_archives n
left join news_category c on n.typeid=c.id
LEFT JOIN users u ON n.userid=u.id
order by n.ts_created desc limit 10";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
$this->view->news = $rows;
include_once("news.php");
$News = new news($this->db);
$sql = "SELECT count(id) as c FROM news_archives";
$sql = "SELECT count(id) as c FROM ".$News->tbl_archives;
$rs = $this->db->query($sql);
$row = $rs->fetch();
$this->view->totle = $row;
$sql = "SELECT count(id) as c FROM news_category";
$sql = "SELECT count(id) as c FROM ".$News->tbl_categorys;
$rs = $this->db->query($sql);
$row = $rs->fetch();
$this->view->typec = $row;
@ -66,10 +61,10 @@ class Admin_NewsController extends Zend_Controller_Action
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->view->types=$News->getAllCategory();
$category = new Category($this->db);
$this->view->types= $category->GetCategory();
$this->view->type = $type;
$this->view->deepField = $category->DeepTitle;
}//newslistAction 新闻列表
function catlogAction()
@ -89,7 +84,11 @@ class Admin_NewsController extends Zend_Controller_Action
$this->view->ptype = $News->ptype;
$this->_helper->viewRenderer('category-add');
$this->view->categories = $News->getAllCategory();
$category = new Category($this->db);
$catlogs = $category->GetCategory();
$this->view->categories=$catlogs;
$this->view->deepField = $category->DeepTitle;
if(empty($submit)){
@ -103,6 +102,7 @@ class Admin_NewsController extends Zend_Controller_Action
$data['code'] = $this->_request->getParam('code');
$data['fid'] = $this->_request->getParam('fid');
$data['ptype'] = $this->_request->getParam('ptype');
$data['is_pub'] = 1;
$this->view->info = $data;
@ -125,7 +125,13 @@ class Admin_NewsController extends Zend_Controller_Action
return true;
}
if($this->db->insert($News->tbl_categorys,$data))
$LftRgt = $category->Insert($data['fid']);
$data['tid'] = $data['fid'];
$data['lft'] = $LftRgt['left'];
$data['rgt'] = $LftRgt['right'];
unset($data['fid']);
if($this->db->insert($category->CategoryTable,$data))
{
$this->view->msg = '提示信息:栏目添加成功!';
$this->view->jump_url = '/admin/news/catlog';
@ -155,8 +161,10 @@ class Admin_NewsController extends Zend_Controller_Action
$this->_helper->viewRenderer('category-edit');
$this->view->ptype = $News->ptype;
$this->view->info = $News->getCategory($edit);
$this->view->categories = $this->getAllcategory($edit);
$category = new Category($this->db);
$this->view->info = $category->GetOne($edit);
$this->view->categories = $category->GetCategory();
$this->view->deepField = $category->DeepTitle;
if(!empty($submit))
{
@ -165,7 +173,7 @@ class Admin_NewsController extends Zend_Controller_Action
$data['title'] = $this->_request->getParam('ctitle');
$data['code'] = $this->_request->getParam('code');
$data['fid'] = $this->_request->getParam('fid');
//$data['fid'] = $this->_request->getParam('fid');
$data['ptype'] = $this->_request->getParam('ptype');
$data['is_pub'] = $this->_request->getParam('is_pub');
@ -206,20 +214,10 @@ class Admin_NewsController extends Zend_Controller_Action
else
{
include_once("news.php");
$news = new news($this->db);
$catlogs = $news->getAllCategory(-1);
/*
$sql="select * from news_category WHERE fid=0 order by displayorder asc";
$re=$this->db->query($sql);
$catlogs=$re->fetchAll();
foreach($catlogs as $k=>$v)
{
$catlogs[$k]['sub'] = $this->getSubCategory($v['id']);
}
*/
$category = new Category($this->db);
$catlogs = $category->GetCategory();
$this->view->catlogs=$catlogs;
$this->view->deepField = $category->DeepTitle;
}//栏目列表
@ -266,11 +264,46 @@ class Admin_NewsController extends Zend_Controller_Action
function newsaddAction()
{
include_once("news.php");
$News = new news($this->db);
$this->view->types=$News->getAllCategory();
$category = new Category($this->db);
$catlogs = $category->GetCategory();
$this->view->types=$catlogs;
$this->view->deepField = $category->DeepTitle;
}//newsadd 新闻添加
//文档编辑
function newseditAction()
{
include_once("news.php");
$News = new news($this->db);
$id = $this->_request->getParam('id');
$this->view->typeid = $id;
$sql = "select arc.*,ct.cid as typeid from ".$News->tbl_archives." arc
LEFT JOIN ".$News->tbl_catalog." ct ON arc.id=ct.aid
where arc.id=$id";
$rs = $this->db->query($sql);
$row = $rs->fetch();
$this->view->ev = $row;
if(!empty($row['image']))
{
$sql = "SELECT * FROM attachments WHERE filename='".str_replace("/upload/",'',$row['image'])."'";
$rs = $this->db->query($sql);
$row = $rs->fetch();
$this->view->att = $row;
}
$this->view->keywords = join(",",$News->GetTags($id));
$category = new Category($this->db);
$catlogs = $category->GetCategory();
$this->view->types=$catlogs;
$this->view->deepField = $category->DeepTitle;
}
//新闻添加
//文档编辑或者添加
function archivesaddAction()
{
$this->_helper->layout->disableLayout();
@ -351,15 +384,24 @@ class Admin_NewsController extends Zend_Controller_Action
);
$update = $this->_getParam('update');
$aid = $this->_getParam('aid');
if(is_numeric($update) && !empty($update) && !empty($aid))
if(is_numeric($update) && !empty($update))
{
if($this->db->update($News->tbl_archives,$data[],"id=$aid"))
$sql = "UPDATE ".$News->tbl_archives." SET
userid=".$data['userid'].",
title=".$data['title'].",
description=".$data['description'].",
image=".$data['image'].",
source=".$data['source'].",
ts_published=".$data['ts_published'].",
is_pub=".$data['is_pub'].",
body=".$data['body']."
WHERE id=$update";
if($this->db->exec($sql))
{
$News->ChangeCatalog($aid,$typeid);
$News->DeleteTags($aid);
$News->MakeTags($aid,$keyword);
$News->ChangeCatalog($update,$typeid);
$News->DeleteTags($update);
$News->MakeTags($update,$keyword);
echo '<div class="box box-success">修改成功!</div><script>
setTimeout("self.location=\'/admin/news/newslist\'",500);
</script>';
@ -411,37 +453,6 @@ class Admin_NewsController extends Zend_Controller_Action
}
}// 文章发布
//文档编辑
function newseditAction()
{
include_once("news.php");
$News = new news($this->db);
$id = $this->_request->getParam('id');
$sql = "select * from ".$News->tbl_archives." arc where arc.id=$id";
$rs = $this->db->query($sql);
$row = $rs->fetch();
$this->view->ev = $row;
if(!empty($row['image']))
{
$sql = "SELECT * FROM attachments WHERE filename='".str_replace("/upload/",'',$row['image'])."'";
$rs = $this->db->query($sql);
$row = $rs->fetch();
$this->view->att = $row;
}
$this->view->keywords = join(",",$News->GetTags($id));
$sql="select * from ".$News->tbl_categorys." order by displayorder desc";
$re = $this->db->query($sql);
$types = $re->fetchAll();
$this->view->types=$types;
}
function deleteAction(){
$id = $this->_request->getParam('id');

View File

@ -57,11 +57,17 @@
<?php if(!empty($this->categories)) :?>
<?php foreach($this->categories as $v) : ?>
<?php if(empty($this->info['fid'])) {?>
<option value="<?= $v['id'];?>"><?= $v['title'];?></option>
<option value="<?= $v['id'];?>">
<?php if(!empty($v[$this->deepField])) {echo str_repeat('-',$v[$this->deepField]);} ?>
<?=$v['title'];?>
</option>
<?php }else{
if($this->info['fid'] == $v['id'])
{ ?>
<option value="<?= $v['id'];?>" selected="selected"><?= $v['title'];?></option>
<option value="<?= $v['id'];?>" selected="selected">
<?php if(!empty($v[$this->deepField])) {echo str_repeat('-',$v[$this->deepField]);} ?>
<?= $v['title'];?>
</option>
<?php }else{?>
<option value="<?= $v['id'];?>"><?= $v['title'];?></option>
<?php }

View File

@ -55,27 +55,6 @@
</select>
</p>
<p>
<label>父级栏目</label><br />
<select name="fid">
<option value="0"></option>
<?php if(!empty($this->categories)) :?>
<?php foreach($this->categories as $v) : ?>
<?php if(empty($this->info['fid'])) {?>
<option value="<?= $v['id'];?>"><?= $v['title'];?></option>
<?php }else{
if($this->info['fid'] == $v['id'])
{ ?>
<option value="<?= $v['id'];?>" selected="selected"><?= $v['title'];?></option>
<?php }else{?>
<option value="<?= $v['id'];?>"><?= $v['title'];?></option>
<?php }
}?>
<?php endforeach;?>
<?php endif; ?>
</select>
</p>
<p>
<label class="required" for="code">栏目URL</label><br/>
<input type="text" id="code" class="half" value="<?php if(!empty($this->info['code'])) echo $this->info['code'];?>" name="code"/>(仅小写英文字母与数字)

View File

@ -49,12 +49,16 @@
$deep = 0;
foreach($this->catlogs as $k=>$v)
{
if($v['fid']==0)
if($v[$this->deepField]>0)
{
echo '
$style = "text-indent:". $v[$this->deepField]*12 ."px;";
}else{
$style = "";
}
echo '
<tr>
<td>
<div id="paddiv'.$v['id'].'">
<div id="paddiv'.$v['id'].'" style="'.$style.'">
<a id="titlebtn'.$v['id'].'" class="title"><b>'.$v['title'].'</b></a>
</td>
<td>
@ -63,37 +67,6 @@
<a href="/admin/news/catlog/edit/'.$v['id'].'"><b>编辑</b></a>
<a href="/admin/news/catlog/delete/'.$v['id'].'" onclick="return confirm(\'是否确定删除该栏目\')">删除</a></td>
</tr>';
$top = $v['id'];
}
foreach($this->catlogs as $vv)
{
$fid = $vv['fid'];
if(!empty($top) || !empty($fid))
{
if($top != $fid)
{
$deep ++;
}else{
$deep = 1;
}
if($vv['tid']==$top)
{
echo '
<tr>
<td>
<div id="paddiv'.$vv['id'].'" style="text-indent:'.$deep * 6 .'px">';
echo '- <a id="titlebtn'.$vv['id'].'" class="title"><b>'.$vv['title'].'</b></a>
</td>
<td>
<a href="/news/'.$vv['code'].'" target="_blank">浏览</a>
<a href="/admin/news/newslist/type/'.$vv['id'].'">文档</a>
<a href="/admin/news/catlog/edit/'.$vv['id'].'"><b>编辑</b></a>
<a href="/admin/news/catlog/delete/'.$vv['id'].'" onclick="return confirm(\'是否确定删除该栏目\')">删除</a></td>
</tr>';
}
}
}
}
}else{

View File

@ -3,7 +3,7 @@
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('<a href="/admin/news">新闻中心</a>');
@ -25,59 +25,6 @@
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<h3>最新发布的新闻</h3>
<hr/>
<table id="report" class="stylized full">
<thead>
<tr>
<th width="50%">新闻标题</th>
<th width="25%">所属栏目</th>
<th width="25%">新闻管理</th>
</tr>
</thead>
<tbody>
<?php
if(count($this->news))
{
foreach ($this->news as $v)
{
echo '
<tr>
<td>
<div id="paddiv'.$v['id'].'">
<a id="titlebtn'.$v['id'].'" class="title"><b>'.$v['title'].'</b></a>
<div class="listingDetails">
<div class="pad">
<b>详细信息</b> <a href="javascript:;" class="closepad" style="float:right">关闭</a>
<p>作者:'.$v['author'].'</p>
<p>关键词:'.$v['keywords'].'</p>
<p>描述:'.$v['description'].'</p>
<p>添加时间:'.date("Y-m-d H:i",strtotime($v['ts_created'])).'</p>
<p>发布时间:'.date("Y-m-d H:i",strtotime($v['ts_published'])).'</p>
<p>来源:'.$v['source'].'</p>
<p>点击:'.$v['click'].'</p>
</div>
</div></div>
</td>
<td>'.$v['catlog'].'</td>
<td>
<a href="/admin/news/newsedit/id/'.$v['id'].'"><b>编辑</b></a>
<a href="/admin/news/delete/id/'.$v['id'].'" onclick="return confirm(\'是否确定删除该文章\')">删除</a></td>
</tr>
';
}
}
else
{
echo '
<tr><td>暂无数据</td><td></td></tr>
';
}
?>
</tbody>
</table>
<h3>统计</h3>
<hr/>

View File

@ -112,7 +112,9 @@ $(document).ready(function(){
<?php
foreach($this->types as $v)
{
echo '<option value="'.$v['id'].'">'.$v['title'].'</option>';
if(!empty($v[$this->deepField])) {$haed = str_repeat('-',$v[$this->deepField]);}
echo '<option value="'.$v['id'].'">'.$haed.$v['title'].'</option>';
$haed = "";
}
?>

View File

@ -130,10 +130,15 @@ $(document).ready(function(){
<?php
foreach($this->types as $v)
{
$haed = "";
if(!empty($v[$this->deepField])) {$haed = str_repeat('-',$v[$this->deepField]);}
if($this->ev['typeid']==$v['id'])
echo '<option value="'.$v['id'].'" selected="selected">'.$v['title'].'</option>';
echo '<option value="'.$v['id'].'" selected="selected">'.$haed.$v['title'].'</option>';
else
echo '<option value="'.$v['id'].'">'.$v['title'].'</option>';
echo '<option value="'.$v['id'].'">'.$haed.$v['title'].'</option>';
$haed = "";
}
?>
@ -144,9 +149,8 @@ $(document).ready(function(){
<p>
<select id="pub" class="full" name="pub">
<option value="1" <?php if($this->ev['is_pub']>=1) echo 'selected="selected"'; ?>>立即发布</option>
<option value="0" <?php if($this->ev['is_pub']==0) echo 'selected="selected"'; ?>>存草稿</option>
<option value="-1" <?php if($this->ev['is_pub']<0) echo 'selected="selected"'; ?>>不发布</option>
<option value="true" <?php if($this->ev['is_pub']==true) echo 'selected="selected"'; ?>>立即发布</option>
<option value="false" <?php if($this->ev['is_pub']==false) echo 'selected="selected"'; ?>>存草稿</option>
</select>
</p>
</div>
@ -201,7 +205,7 @@ function addon(){
}
}
editor.sync();
var url = "/admin/news/archivesedit/id/<?php echo $this->ev['id']; ?>";
var url = "/admin/news/archivesadd/update/<?php echo $this->ev['id']; ?>";
var data = $("#archivesadd").serialize()+'&keyword='+$('#keyword').val();
$.ajax({
type: "POST",

View File

@ -40,10 +40,13 @@ $('#divFooter').css('position','absolute');
{
foreach($this->types as $v)
{
if(!empty($v[$this->deepField])) {$haed = str_repeat('-',$v[$this->deepField]);}
if($this->type == $v['id'])
echo '<option onclick="self.location=\'/admin/news/newslist/type/'.$v['id'].'\'" selected="selected">'.$v['title'].'</option>';
echo '<option onclick="self.location=\'/admin/news/newslist/type/'.$v['id'].'\'" selected="selected">'
.$haed
.$v['title'].'</option>';
else
echo '<option onclick="self.location=\'/admin/news/newslist/type/'.$v['id'].'\'">'.$v['title'].'</option>';
echo '<option onclick="self.location=\'/admin/news/newslist/type/'.$v['id'].'\'">'.$haed.$v['title'].'</option>';
}
}
?>

View File

@ -14,13 +14,13 @@ class NewsController extends Zend_Controller_Action
{
include_once("news.php");
$News = new news($this->db);
$types = $News->getAllCategory();
$this->view->types=$types;
$category = new Category($this->db);
$this->view->types = $category->GetCategory();
$this->view->deepField = $category->DeepTitle;
$time = date("Y-m-d H:i:s",time());
$sql = "SELECT id,title,code FROM ".$News->tbl_categorys." WHERE fid=0";
$sql = "SELECT id,title,code FROM ".$News->tbl_categorys."";
$sth = $this->db->query($sql);
$rows = $sth->fetchAll();
@ -38,7 +38,7 @@ class NewsController extends Zend_Controller_Action
$rs = $this->db->query($sql);
$archives = $rs->fetchAll();
$newslist[$v['id']] = array("title"=>$v['title'],"url"=>$v['code'],"id"=>$v['id'],"list"=>$archives);
$newslist[$v['id']] = array("title"=>$v['title'],"code"=>$v['code'],"id"=>$v['id'],"list"=>$archives);
}
$this->view->lists = $newslist;
@ -78,12 +78,10 @@ class NewsController extends Zend_Controller_Action
$this->view->url = $row['code'];
$this->view->title = $row['title'];
include_once("news.php");
$news = new news($this->db);
$types = $news->getAllCategory();
$this->view->types=$types;
$category = new Category($this->db);
$this->view->types = $category->GetCategory();
$this->view->deepField = $category->DeepTitle;
$time = date("Y-m-d H:i:s",time());
@ -122,9 +120,9 @@ class NewsController extends Zend_Controller_Action
include_once("news.php");
$News = new news($this->db);
$types = $News->getAllCategory();
$this->view->types=$types;
$category = new Category($this->db);
$this->view->types = $category->GetCategory();
$this->view->deepField = $category->DeepTitle;
$time = date("Y-m-d H:i:s",time());

View File

@ -25,17 +25,10 @@ $this->headMeta()->appendName('description', mb_substr($this->infos['description
{
foreach($this->types as $k=>$v)
{
if($v['fid']==0)
{
echo '<li><a href="/news/'.$v['url'].'">'.$v['title'].'</a></li>';
}
foreach($this->types as $vd)
{
if($vd['fid']==$v['id'])
{
echo '<li> - <a href="/news/'.$vd['url'].'">'.$vd['title'].'</a></li>';
}
}
$haed = "";
if(!empty($v[$this->deepField])) {$haed = str_repeat(' ',$v[$this->deepField]);}
echo '<li><a href="/news/'.$v['code'].'">'.$haed.$v['title'].'</a></li>';
$haed = "";
}
}
?>

View File

@ -19,17 +19,10 @@ $this->breadcrumb()->setSeparator(' > ');
{
foreach($this->types as $k=>$v)
{
if($v['fid']==0)
{
echo '<li><a href="/news/'.$v['url'].'">'.$v['title'].'</a></li>';
}
foreach($this->types as $vd)
{
if($vd['fid']==$v['id'])
{
echo '<li> - <a href="/news/'.$vd['url'].'">'.$vd['title'].'</a></li>';
}
}
$haed = "";
if(!empty($v[$this->deepField])) {$haed = str_repeat(' ',$v[$this->deepField]);}
echo '<li><a href="/news/'.$v['code'].'">'.$haed.$v['title'].'</a></li>';
$haed = "";
}
}
?>
@ -43,12 +36,12 @@ $this->breadcrumb()->setSeparator(' > ');
{?>
<?php if(count($v['list'])>0) {?>
<div class="list-archives">
<div class="list-title"><a href="/news/<?= $v['url'] ?>"><?= $v['title'] ?></a></div>
<div class="list-title"><a href="/news/<?= $v['code'] ?>"><?= $v['title'] ?></a></div>
<div class="list-content">
<ul>
<?php foreach($v['list'] as $arc)
{?>
<li><a href="/news/<?= $arc['url']?>/archive-<?= $arc['id']?>.html"><?= $arc['title'] ?></a></li>
<li><a href="/news/<?= $arc['code']?>/archive-<?= $arc['id']?>.html"><?= $arc['title'] ?></a></li>
<?php }?>
</ul>
</div>

View File

@ -20,17 +20,10 @@ $this->breadcrumb()->setSeparator(' > ');
{
foreach($this->types as $k=>$v)
{
if($v['fid']==0)
{
echo '<li><a href="/news/'.$v['code'].'">'.$v['title'].'</a></li>';
}
foreach($this->types as $vd)
{
if($vd['fid']==$v['id'])
{
echo '<li> - <a href="/news/'.$vd['code'].'">'.$vd['title'].'</a></li>';
}
}
$haed = "";
if(!empty($v[$this->deepField])) {$haed = str_repeat(' ',$v[$this->deepField]);}
echo '<li><a href="/news/'.$v['code'].'">'.$haed.$v['title'].'</a></li>';
$haed = "";
}
}
?>

View File

@ -1,4 +1,13 @@
<?php
/**
* Archives - Category
*
* @link NULL
* @copyright Copyright (c) 2012 Jianxuan Li
* @license http://www.lijianxuan.com/license
* @package Archives
*/
class news
{
private $db; //传入PDO对象
@ -29,47 +38,6 @@ class news
"FAQ" => "faq"
);
}//ptype()
/*
递归获得所有栏目
*/
function getAllCategory($hide = true){
if($hide == -1)
{
$sql = "SELECT c.* FROM ".$this->tbl_categorys." c
ORDER BY displayorder asc";
}else{
$sql = "SELECT c.* FROM ".$this->tbl_categorys." c
WHERE is_pub = $hide
ORDER BY displayorder asc";
}
$re = $this->db->query($sql);
$categorys = $re->fetchAll();
return $categorys;
}
//取得最顶级的栏目
function getTopType(){
$sql = "SELECT c.* FROM ".$this->tbl_categorys." c
WHERE is_pub = true AND fid=0
ORDER BY displayorder asc";
$re = $this->db->query($sql);
$categorys = $re->fetchAll();
return $categorys;
}
//获得栏目
function getCategory($id)
{
$sql = "SELECT * FROM ".$this->tbl_categorys." WHERE id=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($id));
$rows = $sth->fetch();
return $rows;
}
/*
写入关系表
@ -108,9 +76,6 @@ class news
/*
* 更改栏目 ChangeCatalog()
*
*
*
*/
function ChangeCatalog($aid,$cid,$uuid='',$status=0){
@ -134,7 +99,7 @@ class news
$data['uuid'] = $uuid;
}
if($this->db->update($this->tbl_catalog,$data,"id=$aid"))
if($this->db->update($this->tbl_catalog,$data,"aid=$aid"))
{
return true;
}else{
@ -262,5 +227,238 @@ class news
$sql = "DELETE FROM ".$this->tbl_tag." WHERE id=$aid";
@$this->db->exec($sql);
return true;
}//DeleteTags
}
class Category
{
//PDO对象
private $db;
//数据库中分类表
public $CategoryTable;
//分类左值字段名称
private $fld_left;
//分类右值字段名称
private $fld_right;
//顶级栏目标记字段
private $fld_tid;
//输出栏目中的深度信息
public $DeepTitle;
function __construct($db){
$this->db = $db;
$this->CategoryTable = "ar_category";
$this->fld_left = "lft";
$this->fld_right = "rgt";
$this->fld_tid = "tid";
$this->DeepTitle = "DEEP";
}
/**
* GetTree() 获得栏目树
* 用来获得某个栏目下或者所有栏目的树结构
*
* 典型表结构
* (PostgreSql)
*
CREATE TABLE ar_category
(
id serial NOT NULL,
title character varying(80),
tid integer NOT NULL DEFAULT 0,
lft integer NOT NULL DEFAULT 0,
rgt integer NOT NULL DEFAULT 0,
CONSTRAINT ar_category_pkey PRIMARY KEY (id)
)
*
* @param int $tid
*
* @return array;
*/
function GetCategory($tid=0){
$left = $this->fld_left;
$right = $this->fld_right;
$categoryTable = $this->CategoryTable;
$tidField = $this->fld_tid;
$whereSql = array();
if(!empty($tid))
{
$sql = "SELECT $left,$right FROM $categoryTable
WHERE id=$tid";
$sth = $this->db->query($sql);
$row = $sth->fetch();
$whereSql[] = " $left BETWEEN {$row[$left]} AND {$row[$right]} ";
}
if(count($whereSql)>0)
{
$whereSql = " WHERE ".join(" AND ",$whereSql);
}else{
$whereSql = "";
}
$sql = "SELECT *
FROM $categoryTable
$whereSql
ORDER BY $left ASC ";
$sth = $this->db->query($sql);
$rows = $sth->fetchAll();
$stack = array();
$categorys = array();
foreach($rows as $k=>$v)
{
/*
如果它是一个顶级栏目,则为它重置深度
*/
if(empty($v[$tidField]))
{
$stack = array();
}else{
if(count($stack) > 1)
{
/*
在这个循环中必须追溯直至与其平级的分类
while循环无法重写条件中已经改变的变量
第一次max(array_keys($stack))赋值为当前深度
循环中的第一个if里max(array_keys($stack))是重新统计,而非使用一定义的
因为第二次循环到此时可能max(array_keys($stack))已经发生改变
第三处max(array_keys($stack))表示第一个if中没有break掉的深度值所以也不能使用赋过值的变量代替。
加入brake 可使程序追溯至平级栏目即进行下一步操作
必须是倒序循环,多个平级栏目时,如果是正序列循环会到第一个平级的栏目后停止循环
*/
for($i=max(array_keys($stack));$i>=0;$i--)
if($v[$right]>$stack[max(array_keys($stack))])
{
if(count($stack)<1)
{
break;
}
if($v[$right]>$stack[max(array_keys($stack))])
{
array_pop($stack);
}else{
break;
}
}//end if
}//end if
}
//放入输出数组
$rows[$k][$this->DeepTitle] = count($stack);
//将此节点加入栈中
$stack[] = $v[$right];
}// end foreach
return $rows;
}
/**
* Insert() 插入一个栏目
* 返回数组 left=>左值 right=>右值
*
*
* @param int $tid
*
* @return array
*/
function Insert($tid){
$left = $this->fld_left;
$right = $this->fld_right;
$categoryTable = $this->CategoryTable;
//分别处理有上级栏目和没上级栏目的
if(!empty($tid))
{
$sql = "SELECT $right
FROM $categoryTable
WHERE id=$tid";
$sth = $this->db->query($sql);
$row = $sth->fetch();
$right_start = $row[$right]-1;
//更新所有右值
$sql = "UPDATE $categoryTable SET $right=$right+2 WHERE $right>$right_start";
$this->db->exec($sql);
//更新所有左值
$sql = "UPDATE $categoryTable SET $left=$left+2 WHERE $left>$right_start";
$this->db->exec($sql);
//返回应该插入的左右值
$lft = $right_start + 1;
$rgt = $lft + 1;
return array(
'left'=>$lft,
'right'=>$rgt
);
}else{
//取最大的右值
$sql = "SELECT $right
FROM $categoryTable
WHERE tid=0
ORDER BY $left DESC LIMIT 1";
$sth = $this->db->query($sql);
$row = $sth->fetch();
$right_start = $row[$right]-1;
if($right_start<1)
{
return array(
'left'=>1,
'right'=>2
);
}
$lft = $right_start + 2;
$rgt = $lft + 1;
return array(
'left'=>$lft,
'right'=>$rgt
);
}
}//Insert
//获取栏目路径
function GetRouter($lft,$rgt){
$sql = "SELECT * FROM ".$this->CategoryTable."
WHERE ".$this->fld_left." < $lft AND ".$this->fld_right." > $rgt
ORDER BY ".$this->fld_left." ASC;";
$sth = $this->db->query($sql);
$rows = $sth->fetchAll();
return $rows;
}
function GetSunCount($left,$right){
return ($right-$left-1)/2;
}
//获取一个栏目
function GetOne($tid){
$sql = "SELECT * FROM ".$this->CategoryTable." WHERE id=$tid";
$sth = $this->db->query($sql);
return $sth->fetch();
}//GetOne
}

View File

@ -35,7 +35,7 @@
.archive_body div.info{text-align:center;padding:10px 0;}
.archive_body div.content{word-break:break-all;word-wrap:break-word;overflow:hidden;}
.list-archives{width:300px;overflow:hidden;}
.list-archives{width:300px;overflow:hidden;margin:5px;float:left;}
.list-archives .list-title{width:100%;overflow:hidden;background:#F60;text-indent:12px;}
.list-archives .list-title a {color:#FFF;line-height:30px;font-size:14px;}
.list-archives .list-content{border:1px solid #F60;}