添加新闻栏目的顺序修改功能

This commit is contained in:
Li Jianxuan 2013-05-21 09:37:33 +00:00
parent b99f34f6d5
commit f602aca71e
5 changed files with 501 additions and 126 deletions

View File

@ -8,6 +8,7 @@ class Admin_NewsController extends Zend_Controller_Action
$this->messenger=$this->_helper->getHelper('FlashMessenger'); $this->messenger=$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->messenger->getMessages(); $this->view->messages = $this->messenger->getMessages();
$this->_helper->layout->setLayout('administry'); $this->_helper->layout->setLayout('administry');
$this->view->theme = new Theme();
} }
function postDispatch() function postDispatch()
{ {
@ -628,7 +629,40 @@ class Admin_NewsController extends Zend_Controller_Action
return $newString; return $newString;
} }
public function moveAction()
{
$up = (int)$this->_getParam('up');
$down = (int)$this->_getParam('down');
include_once('helper/view.php');
include_once('ArchiveCategory.php');
if(empty($up) && empty($down))
{
view::Post("参数错误",$this,-1);
return true;
}
$category = new ArchiveCategory($this->db);
if(!empty($up))
{
$s = $category->move('up',$up);
}
if(!empty($down))
{
$s = $category->move('down',$down);
}
if(is_array($s))
{
$this->view->moved = $s;
}else{
view::Post($this,$s,-1);
}
return true;
}
} }

View File

@ -2,39 +2,38 @@
$this->headTitle($this->config->title->site); $this->headTitle($this->config->title->site);
$this->headTitle('后台管理'); $this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>'); $this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>'); $this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('<a href="/admin/news">新闻中心</a>'); $this->breadcrumb('<a href="/admin/news">新闻中心</a>');
$this->breadcrumb('栏目管理'); $this->breadcrumb('栏目管理');
$this->theme->AppendPlus($this,"colorbox");
?> ?>
<style> <style>
.listingDetails{position:absolute;width:650px;} .listingDetails{position:absolute;width:650px;}
.pad{position:absolute;background:#FFF;border:2px solid #444;border-radius:5px;padding:5px;display:none;} .pad{position:absolute;background:#FFF;border:2px solid #444;border-radius:5px;padding:5px;display:none;}
table thead tr th {background:#EBF2F6;color:#444;}
.high{background:#444;color:#FFF;}
</style> </style>
<div id="leftPanel"> <div class="row-fluid">
<?= $this->partial('news/left.phtml'); ?> <div class="span3">
</div> <?= $this->partial('news/left.phtml'); ?>
<div id="rightPanel"> </div>
<?php if ($this->msg or $this->messages) :?> <div class="span9">
<div id="message"> <?php if ($this->msg or $this->messages) :?>
<?php if ($this->msg) : ?> <div id="message">
<?php if ($this->msg) : ?>
<p><?php echo $this->msg; ?></p> <p><?php echo $this->msg; ?></p>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?> <?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
<p><?php echo $msg; ?></p> <p><?php echo $msg; ?></p>
<?php endforeach;endif; ?> <?php endforeach;endif; ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
<div id="tabs-controller"> <div id="tabs-controller">
<ul> <ul class="unstyled">
<li class="box-shadow active"><a class="text-shadow" href="/admin/news/catlog/add/1">添加新栏目</a></li> <li class="box-shadow active"><a class="btn btn-primary" href="/admin/news/catlog/add/1">添加新栏目</a></li>
</ul> </ul>
</div> </div>
<table id="report" class="stylized full" style="width:650px;"> <table id="report" class="table table-bordered table-hover">
<thead> <thead>
<tr> <tr>
<th width="50%">栏目名称</th> <th width="50%">栏目名称</th>
@ -42,7 +41,7 @@
<th width="30%" style="vertical-align:top;">栏目管理</th> <th width="30%" style="vertical-align:top;">栏目管理</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php <?php
if(is_array($this->catlogs)) if(is_array($this->catlogs))
{ {
@ -67,6 +66,8 @@
</td> </td>
<td> <td>
<a href="'.$v['url'].'" target="_blank">浏览</a> <a href="'.$v['url'].'" target="_blank">浏览</a>
<a href="/admin/news/move/up/'.$v['id'].'">上移</a>
<a href="/admin/news/move/down/'.$v['id'].'">下移</a>
<a href="/admin/news/newslist/type/'.$v['id'].'">文档</a> <a href="/admin/news/newslist/type/'.$v['id'].'">文档</a>
<a href="/admin/news/catlog/edit/'.$v['id'].'"><b>编辑</b></a> <a href="/admin/news/catlog/edit/'.$v['id'].'"><b>编辑</b></a>
<a href="/admin/news/catlog/delete/'.$v['id'].'" onclick="return confirm(\'是否确定删除该栏目\')">删除</a></td> <a href="/admin/news/catlog/delete/'.$v['id'].'" onclick="return confirm(\'是否确定删除该栏目\')">删除</a></td>
@ -78,9 +79,9 @@
} }
?> ?>
</tbody> </tbody>
</table> </table>
</div> </div>
<div style="width:500px;display:none;" id="categoryForm"> <div style="width:500px;display:none;" id="categoryForm">
<form id="category" style="width:500px;"> <form id="category" style="width:500px;">
<p> <p>
<label class="required" for="ctitle">栏目标题:</label><br/> <label class="required" for="ctitle">栏目标题:</label><br/>
@ -122,6 +123,7 @@
<p id="formStatus" style="display:block;">&nbsp;</p> <p id="formStatus" style="display:block;">&nbsp;</p>
</form> </form>
</div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){

View File

@ -0,0 +1,33 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('<a href="/admin/news">新闻中心</a>');
$this->breadcrumb('栏目管理');
$this->theme->AppendPlus($this,"colorbox");
?>
<div class="row-fluid">
<div class="span3">
<?= $this->partial('news/left.phtml'); ?>
</div>
<div class="span9">
<?php if(!empty($this->moved)) {?>
<h3>成功消息:</h3>
<?php if(count($this->moved['success']) < 1) {?>
移动失败!
<?php } ?>
<?php foreach($this->moved['success'] as $k=>$v) { ?>
<li><?= $v ?></li>
<?php } ?>
<h3>错误消息:</h3>
<?php if(count($this->moved['error']) < 1) {?>
无错误
<?php } ?>
<?php foreach($this->moved['error'] as $k=>$v) { ?>
<li><?= $v ?></li>
<?php } ?>
<?php } ?>
</div>
</div>

View File

@ -220,16 +220,6 @@ class ArchiveCategory
}//Insert }//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){ function GetSunCount($left,$right){
return ($right-$left-1)/2; return ($right-$left-1)/2;
} }
@ -252,4 +242,320 @@ class ArchiveCategory
}//GetOne }//GetOne
//获得子栏目
function getSubNode($left,$right,$data = NULL)
{
if(empty($data))
{
$sql = "SELECT * FROM ".$this->CategoryTable." WHERE ".$this->fld_left.">$left AND ".$this->fld_right."<$right ORDER BY ".$this->fld_left." ASC";
$rs = $this->db->query($sql);
$SN = $rs->fetchAll();
}else{
$SN = array();
foreach($data as $k=>$v)
{
if($left < $v[$this->fld_left] && $v[$this->fld_right] < $right)
$SN[] = $data[$k];
}
}
return $SN;
}
//获取子栏目中的最大右值
function getMaxSubRight($left,$right){
$sql = "SELECT max(".$this->fld_right.") as mx FROM ".$this->CategoryTable." WHERE ".$this->fld_left.">".$left." AND ".$this->fld_right."<".$right;
$rs = $this->db->query($sql);
$row = $rs->fetch();
return $row['mx'];
}
//获取平级栏目中的上一个栏目
function prevnode($tid,$left,$right)
{
$sql = "SELECT * FROM ".$this->CategoryTable." WHERE
".$this->fld_tid."=$tid AND
".$this->fld_left."<$left AND
".$this->fld_right."<$right
ORDER BY ".$this->fld_left." DESC
LIMIT 1
";
$rs = $this->db->query($sql);
$row = $rs->fetch();
if(empty($row))
{
return NULL;
}
return $row;
}
//获取平级栏目中的下一个栏目
function nextnode($tid,$left,$right)
{
$sql = "SELECT * FROM ".$this->CategoryTable." WHERE
".$this->fld_tid."=$tid AND
".$this->fld_left.">$left AND
".$this->fld_right.">$right
ORDER BY ".$this->fld_left." ASC
LIMIT 1
";
$rs = $this->db->query($sql);
$row = $rs->fetch();
if(empty($row))
{
return NULL;
}
return $row;
}
//移动栏目
function move($action,$id){
if($action == 'up')
{
return $this->moveup($id);
}
if($action == "down")
{
return $this->movedown($id);
}
}
//栏目上移
function moveup($id){
$info = $this->GetOne($id);
$tid = $info[$this->fld_tid];
$left = $info[$this->fld_left];
$right = $info[$this->fld_right];
$prev = $this->prevnode($tid,$left,$right);
if($prev === NULL )
{
return "此栏目已位于平级栏目的顶端";
}
if(is_array($prev))
{
$this_fd = $right-$left;
$this_ft = $left - $prev[$this->fld_left];
$prve_fd = $prev[$this->fld_right] - $prev[$this->fld_left];
$new_right = $prev[$this->fld_left] + $this_fd;
$new_left = $right - $prve_fd;
$prev_ft = $new_left - $prev[$this->fld_left];
$exec = array(
'success' => array(),
'error' => array()
);
$sql_1 = "UPDATE ".$this->CategoryTable." SET
".$this->fld_left."=".$prev[$this->fld_left].",".$this->fld_right."=".$new_right.
" WHERE id=$id";
$sql_2 = "UPDATE ".$this->CategoryTable." SET
".$this->fld_left."=".$new_left.",".$this->fld_right."=".$right.
" WHERE id=".$prev['id'];
if($this->db->exec($sql_1))
{
$exec['success'][] = $info['title']."[$id] :移动成功!";
}else{
$exec['error'][] = $info['title']."[$id] :移动失败! 请手动在数据库中修改,目标左右值 ".$prev[$this->fld_left].":".$new_right;
}
if($this->db->exec($sql_2))
{
$exec['success'][] = $prev['title']."[".$prev['id']."] :移动成功!";
}else{
$exec['error'][] = $prev['title']."[".$prev['id']."] :移动失败! 请手动在数据库中修改,目标左右值 ".$new_left.":".$right;
}
$thisnode = $this->getSubNode($left,$right);
$prevnode = $this->getSubNode($prev[$this->fld_left],$prev[$this->fld_right]);
/*
$a = array();
echo $prev[$this->fld_left].':'.$prev[$this->fld_right]." - ".$left.":".$right;
echo "<br />";
echo $prev[$this->fld_left].':'.$new_right." - ".$new_left.":".$right;
echo "<br />";
*/
if(!empty($thisnode))
{
foreach($thisnode as $k=>$v)
{
$node_new_left = ($v[$this->fld_left]-$this_ft);
$fd = $v[$this->fld_right] - $v[$this->fld_left];
$node_new_right = $node_new_left + $fd;
/*
echo ($v['lft']) .":". ($v['rgt'])."<br />";
echo $node_new_left .":". $node_new_right."<br />";
echo "<br />";
*/
$sql = "UPDATE ".$this->CategoryTable." SET
".$this->fld_left."=".$node_new_left.",".$this->fld_right."=".$node_new_right.
" WHERE id=".$v['id'];
if($this->db->exec($sql))
{
$exec['success'][] = $info['title']."的子栏目".$v['title']."[".$v['id']."] :移动成功!";
}else{
$exec['error'][] = $info['title']."的子栏目".$v['title']."[".$v['id']."] :移动失败! 请手动在数据库中修改,目标左右值 ".$node_new_left.":".$node_new_right;
}
}
}
if(!empty($prevnode))
{
foreach($prevnode as $k=>$v)
{
$node_new_left = ($v[$this->fld_left]+$prev_ft);
$fd = $v[$this->fld_right] - $v[$this->fld_left];
$node_new_right = $node_new_left + $fd;
/*
echo ($v['lft']) .":". ($v['rgt'])."<br />";
echo $node_new_left .":". $node_new_right."<br />";
echo "<br />";
*/
$sql = "UPDATE ".$this->CategoryTable." SET
".$this->fld_left."=".$node_new_left.",".$this->fld_right."=".$node_new_right.
" WHERE id=".$v['id'];
if($this->db->exec($sql))
{
$exec['success'][] = $prev['title']."的子栏目".$v['title']."[".$v['id']."] :移动成功!";
}else{
$exec['error'][] = $prev['title']."的子栏目".$v['title']."[".$v['id']."] :移动失败! 请手动在数据库中修改,目标左右值 ".$node_new_left.":".$node_new_right;
}
}
}
return $exec;
}
if(is_string($prev))
{
return $prev;
}
}//栏目上移
//栏目下移
function movedown($id){
$info = $this->GetOne($id);
$tid = $info[$this->fld_tid];
$left = $info[$this->fld_left];
$right = $info[$this->fld_right];
$next = $this->nextnode($tid,$left,$right);
if($next === NULL )
{
return "此栏目已位于平级栏目的末端";
}
if(is_array($next))
{
$this_fd = $right-$left;
$next_fd = $next[$this->fld_right] - $next[$this->fld_left];
$new_right = $left + $next_fd;
$new_left = $next[$this->fld_right] - $this_fd;
$this_ft = $new_left - $left;
$next_ft = $next[$this->fld_left] - $left;
//echo $id."[".$left .":".$right ."]-".$next['id']."[".$next[$this->fld_left].":".$next[$this->fld_right] . "]<br />";
//echo $next['id']."[".$left .":".$new_right ."]-".$id."[".$new_left.":".$next[$this->fld_right]."]<br /><br />";
$exec = array(
'success' => array(),
'error' => array()
);
$sql_1 = "UPDATE ".$this->CategoryTable." SET
".$this->fld_left."=".$new_left.",".$this->fld_right."=".$next[$this->fld_right].
" WHERE id=$id";
$sql_2 = "UPDATE ".$this->CategoryTable." SET
".$this->fld_left."=".$left.",".$this->fld_right."=".$new_right.
" WHERE id=".$next['id'];
if($this->db->exec($sql_1))
{
$exec['success'][] = $info['title']."[$id] :移动成功!";
}else{
$exec['error'][] = $info['title']."[$id] :移动失败! 请手动在数据库中修改,目标左右值 ".$new_left.":".$next[$this->fld_right];
}
if($this->db->exec($sql_2))
{
$exec['success'][] = $next['title']."[".$next['id']."] :移动成功!";
}else{
$exec['error'][] = $next['title']."[".$next['id']."] :移动失败! 请手动在数据库中修改,目标左右值 ".$left.":".$this->fld_right;
}
$thisnode = $this->getSubNode($left,$right);
$nextnode = $this->getSubNode($next[$this->fld_left],$next[$this->fld_right]);
if(!empty($thisnode))
{
foreach($thisnode as $k=>$v)
{
$node_new_left = ($v[$this->fld_left]+$this_ft);
$fd = $v[$this->fld_right] - $v[$this->fld_left];
$node_new_right = $node_new_left + $fd;
/*echo ($v['lft']) .":". ($v['rgt'])."<br />";
echo $node_new_left .":". $node_new_right."<br />";
echo "<br />";*/
$sql = "UPDATE ".$this->CategoryTable." SET
".$this->fld_left."=".$node_new_left.",".$this->fld_right."=".$node_new_right.
" WHERE id=".$v['id'];
if($this->db->exec($sql))
{
$exec['success'][] = $info['title']."的子栏目".$v['title']."[".$v['id']."] :移动成功!";
}else{
$exec['error'][] = $info['title']."的子栏目".$v['title']."[".$v['id']."] :移动失败! 请手动在数据库中修改,目标左右值 ".$node_new_left.":".$node_new_right;
}
}
}
if(!empty($nextnode))
{
foreach($nextnode as $k=>$v)
{
$node_new_left = ($v[$this->fld_left] - $next_ft);
$fd = $v[$this->fld_right] - $v[$this->fld_left];
$node_new_right = $node_new_left + $fd;
/*echo ($v['lft']) .":". ($v['rgt'])."<br />";
echo $node_new_left .":". $node_new_right."<br />";
echo "<br />";*/
$sql = "UPDATE ".$this->CategoryTable." SET
".$this->fld_left."=".$node_new_left.",".$this->fld_right."=".$node_new_right.
" WHERE id=".$v['id'];
if($this->db->exec($sql))
{
$exec['success'][] = $info['title']."的子栏目".$v['title']."[".$v['id']."] :移动成功!";
}else{
$exec['error'][] = $info['title']."的子栏目".$v['title']."[".$v['id']."] :移动失败! 请手动在数据库中修改,目标左右值 ".$node_new_left.":".$node_new_right;
}
}
}
return $exec;
}
if(is_string($next))
{
return $next;
}
}//栏目下移
} }

View File

@ -80,21 +80,21 @@ class view extends Zend_Controller_Plugin_Abstract
} }
} }
static function Post(Zend_Controller_Action $ctl,$msg){ static function Post(Zend_Controller_Action $ctl,$msg,$url=""){
if(empty($msg)) if(empty($msg))
{ {
return false; return false;
} }
if(!array($msg)) if(!is_array($msg))
{ {
$msg = array('content'=>$msg); $msg = array('content'=>$msg,'url'=>$url);
} }
$helper = new Zend_Controller_Action_HelperBroker($ctl); $helper = new Zend_Controller_Action_HelperBroker($ctl);
$helper->layout->setLayout('layout');
$helper->viewRenderer->setNoRender(); $helper->viewRenderer->setNoRender();
echo $ctl->view->partial('post-message.phtml', $msg); echo $ctl->view->partial('post-message.phtml', $msg);
return true; return true;
} }
} }