#243 实现数据评论的回复功能
This commit is contained in:
parent
8c371c4c71
commit
ca4c0120d4
|
@ -7,7 +7,7 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
$this->view->config = Zend_Registry::get('config');
|
$this->view->config = Zend_Registry::get('config');
|
||||||
$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->debug = 0; //1:debug, 0:release
|
$this->debug = 1; //1:debug, 0:release
|
||||||
$this->debug_email='wangliangxu@lzb.ac.cn';
|
$this->debug_email='wangliangxu@lzb.ac.cn';
|
||||||
}
|
}
|
||||||
function postDispatch()
|
function postDispatch()
|
||||||
|
@ -569,6 +569,9 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
{
|
{
|
||||||
$delete=(int)$this->_getParam('delete');
|
$delete=(int)$this->_getParam('delete');
|
||||||
$uuid = $this->_getParam('uuid');
|
$uuid = $this->_getParam('uuid');
|
||||||
|
$reply = $this->_getParam('reply');
|
||||||
|
$replylist = $this->_getParam('replylist');
|
||||||
|
$delreply = $this->_getParam('delreply');
|
||||||
|
|
||||||
if ($delete)
|
if ($delete)
|
||||||
{
|
{
|
||||||
|
@ -608,6 +611,87 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($reply)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->_helper->layout->disableLayout();
|
||||||
|
$this->_helper->viewRenderer->setNoRender();
|
||||||
|
|
||||||
|
$body = $this->_getParam('content');
|
||||||
|
if(empty($body))
|
||||||
|
{
|
||||||
|
$data = array('error'=>"请输入回复内容");
|
||||||
|
$this->jsonexit($data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$auth = Zend_Auth::getInstance();
|
||||||
|
if($auth->hasIdentity())
|
||||||
|
{
|
||||||
|
$user = $auth->getIdentity();
|
||||||
|
$uid = $user->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "INSERT INTO comments_reply (cid,uid,body) VALUES (?,?,?)";
|
||||||
|
$sth = $this->db->prepare($sql);
|
||||||
|
$rs = $sth->execute(array($reply,$uid,$body));
|
||||||
|
|
||||||
|
if($rs)
|
||||||
|
{
|
||||||
|
$data = array('status'=>1,'msg'=>'回复成功!');
|
||||||
|
$this->jsonexit($data);
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
$data = array('error'=>"回复失败,请重试");
|
||||||
|
$this->jsonexit($data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($replylist)
|
||||||
|
{
|
||||||
|
$this->_helper->layout->disableLayout();
|
||||||
|
$this->_helper->viewRenderer->setNoRender();
|
||||||
|
|
||||||
|
$sql = "SELECT cr.id,cr.body,cr.cid,u.username,cr.ts_created FROM comments_reply cr
|
||||||
|
LEFT JOIN users u ON cr.uid=u.id WHERE cid=?";
|
||||||
|
$sth = $this->db->prepare($sql);
|
||||||
|
$sth->execute(array($replylist));
|
||||||
|
$rows = $sth->fetchAll();
|
||||||
|
|
||||||
|
$this->jsonexit($rows);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($delreply)
|
||||||
|
{
|
||||||
|
$this->_helper->layout->disableLayout();
|
||||||
|
$this->_helper->viewRenderer->setNoRender();
|
||||||
|
|
||||||
|
$sql = "DELETE FROM comments_reply WHERE id=?";
|
||||||
|
$sth = $this->db->prepare($sql);
|
||||||
|
$rs = $sth->execute(array($delreply));
|
||||||
|
|
||||||
|
if($rs)
|
||||||
|
{
|
||||||
|
$this->jsonexit(
|
||||||
|
array('deleted'=>1)
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
$this->jsonexit(
|
||||||
|
array('error'=> '处理中出现错误,请重新尝试')
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$select=$this->db->select();
|
$select=$this->db->select();
|
||||||
$select->from('comments')
|
$select->from('comments')
|
||||||
->joinLeft('metadata','metadata.uuid=comments.uuid','title')
|
->joinLeft('metadata','metadata.uuid=comments.uuid','title')
|
||||||
|
@ -620,7 +704,9 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
|
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
|
||||||
$this->view->paginator=$paginator;
|
$this->view->paginator=$paginator;
|
||||||
|
|
||||||
}
|
}//comment
|
||||||
|
|
||||||
|
|
||||||
function newsletterAction()
|
function newsletterAction()
|
||||||
{
|
{
|
||||||
$form=new Zend_Form();
|
$form=new Zend_Form();
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
$this->headTitle('后台管理');
|
$this->headTitle('后台管理');
|
||||||
$this->headTitle()->setSeparator(' - ');
|
$this->headTitle()->setSeparator(' - ');
|
||||||
$this->headLink()->appendStylesheet('/css/admin.css');
|
$this->headLink()->appendStylesheet('/css/admin.css');
|
||||||
|
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
|
||||||
|
$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/data">数据管理</a>');
|
$this->breadcrumb('<a href="/admin/data">数据管理</a>');
|
||||||
|
@ -25,20 +29,113 @@
|
||||||
<?php endforeach;endif; ?>
|
<?php endforeach;endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?= $this->paginator; ?>
|
|
||||||
|
<div id="datalist">
|
||||||
<?php if (count($this->paginator)): ?>
|
<?php if (count($this->paginator)): ?>
|
||||||
<div id="comments">
|
|
||||||
<?php foreach ($this->paginator as $item): ?>
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>用户名:<?php ($item['url'])?print '<a href="'.$item['url'].'">'.$item['author'].'</a>':print $item['author']; ?>,
|
<?php foreach ($this->paginator as $item): ?>
|
||||||
|
<li>
|
||||||
|
<p>用户名:<?php ($item['url'])?print '<a href="'.$item['url'].'">'.$item['author'].'</a>':print $item['author']; ?>,
|
||||||
EMAIL:<?= $item['email']; ?>
|
EMAIL:<?= $item['email']; ?>
|
||||||
[类型:<?= $item['type']; ?>,创建时间:<?= date('Y-m-d',strtotime($item['ts_created'])); ?>
|
[类型:<?= $item['type']; ?>,创建时间:<?= date('Y-m-d',strtotime($item['ts_created'])); ?>
|
||||||
。操作: <a href="/admin/data/comment/delete/<?= $item['id']; ?>">删除</a>]</li>
|
。操作: <a href="/admin/data/comment/delete/<?= $item['id']; ?>">删除</a> <a href="javascript:;" onclick="showreply(<?= $item['id']; ?>)">回复</a>]</p>
|
||||||
<li>元数据:<a href="/data/<?= $item['uuid']; ?>"><?= $item['title']; ?></a></li>
|
<p style="display:none;vertical-align:bottom" id="comment_reply_<?= $item['id']; ?>"><textarea id="reply_<?= $item['id']; ?>" class="middle half"></textarea>
|
||||||
<li><?= $item['content']; ?></li>
|
<button type="button" onclick="reply(<?= $item['id']; ?>)" class="btn btn-green" style="vertical-align:bottom">提交</button>
|
||||||
<li>IP:<?= $item['ip']; ?>,AGENT:<?= $item['agent']; ?></li>
|
<div style="width:90%; margin:0 auto;">
|
||||||
</ul>
|
<ul id="replyList_<?= $item['id']; ?>">
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</p>
|
||||||
|
<p>元数据:<a href="/data/<?= $item['uuid']; ?>"><?= $item['title']; ?></a></p>
|
||||||
|
<p><?= $item['content']; ?></p>
|
||||||
|
<p>IP:<?= $item['ip']; ?>,AGENT:<?= $item['agent']; ?></p>
|
||||||
|
</li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</ul>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
<?= $this->paginator; ?>
|
||||||
|
<script>
|
||||||
|
function reply(id)
|
||||||
|
{
|
||||||
|
$.ajax({
|
||||||
|
'type':"POST",
|
||||||
|
'url':'/admin/data/comment/reply/'+id,
|
||||||
|
'data':'content='+$('#reply_'+id).val(),
|
||||||
|
'success':function(data){
|
||||||
|
if (typeof(data)=='object')
|
||||||
|
{
|
||||||
|
if(typeof(data.error)!='undefined')
|
||||||
|
{Alert(data.error);return false;}
|
||||||
|
if(typeof(data.msg)!='undefined')
|
||||||
|
{Alert(data.msg);}
|
||||||
|
if(typeof(data.status)!='undefined')
|
||||||
|
{$('#comment_reply_'+id).slideToggle();}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Alert('服务器响应出错,请重试');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'timeout': 30000,
|
||||||
|
'error': function(){
|
||||||
|
Alert('出现错误,请稍后再试');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function showreply(id){
|
||||||
|
$('#comment_reply_'+id).slideToggle("slow", function () {
|
||||||
|
if($('#comment_reply_'+id).css('display')!='none')
|
||||||
|
{
|
||||||
|
$.ajax({
|
||||||
|
'type':"POST",
|
||||||
|
'url':'/admin/data/comment/replylist/'+id,
|
||||||
|
'data':'',
|
||||||
|
'success':function(data){
|
||||||
|
if (typeof(data)=='object')
|
||||||
|
{
|
||||||
|
var html=new Array();
|
||||||
|
for(i in data)
|
||||||
|
{
|
||||||
|
html.push('<li id="subReplyList_'+data[i].id+'">'+data[i].body+
|
||||||
|
' ['+data[i].username+' | <a href="javascript:void(0);" onClick="delreply('+data[i].id+')">删除</a>]</li>');
|
||||||
|
}
|
||||||
|
html = html.join('');
|
||||||
|
$('#replyList_'+id).html(html);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'timeout': 30000,
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
$('#replyList_'+id).html('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function delreply(id){
|
||||||
|
$.ajax({
|
||||||
|
'type':"POST",
|
||||||
|
'url':'/admin/data/comment/delreply/'+id,
|
||||||
|
'data':'',
|
||||||
|
'success':function(data){
|
||||||
|
if (typeof(data)=='object')
|
||||||
|
{
|
||||||
|
if(typeof(data.error)!='undefined')
|
||||||
|
{Alert(data.error);return false;}
|
||||||
|
if(typeof(data.msg)!='undefined')
|
||||||
|
{Alert(data.msg);}
|
||||||
|
if(typeof(data.deleted)!='undefined')
|
||||||
|
{$('#subReplyList_'+id).fadeOut('slow',function(){$(this).remove();})}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Alert('服务器响应出错,请重试');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'timeout': 30000,
|
||||||
|
'error': function(){
|
||||||
|
Alert('出现错误,请稍后再试');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function Alert(html){
|
||||||
|
$.colorbox({'innerWidth':'50%','html':'<h4 style="font-size:16px;font-weight:bold;">'+html+'</h4>'});
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -858,10 +858,30 @@ class DataController extends Zend_Controller_Action
|
||||||
foreach($paginator as $c)
|
foreach($paginator as $c)
|
||||||
{
|
{
|
||||||
//$author=$this->view->escape($c['author']);
|
//$author=$this->view->escape($c['author']);
|
||||||
|
$sql = "SELECT cr.id,cr.body,cr.cid,u.username,cr.ts_created FROM comments_reply cr
|
||||||
|
LEFT JOIN users u ON cr.uid=u.id WHERE cid=?";
|
||||||
|
$sth = $this->db->prepare($sql);
|
||||||
|
$sth->execute(array($c['id']));
|
||||||
|
$replys = $sth->fetchAll();
|
||||||
|
$replyhtml = "";
|
||||||
|
if(!empty($replys) || count($replys)>0)
|
||||||
|
{
|
||||||
|
foreach($replys as $v)
|
||||||
|
{
|
||||||
|
$replyhtml .= "
|
||||||
|
<div class='comment-content' style='width:90%;margin:5px auto;'><span class='title'>".$v['username']." 回复于".date('Y-m-d H:i:s',strtotime($v['ts_created']))."</span>
|
||||||
|
<p>".($v['body'])."</p>
|
||||||
|
</div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
$author=$c['author'];
|
$author=$c['author'];
|
||||||
$author=($c['userid'])?"<strong>".$author."</strong>":$author;
|
$author=($c['userid'])?"<strong>".$author."</strong>":$author;
|
||||||
$author=($c['url'])?'<a href="'.$c['url'].'">'.$author.'</a>':$author;
|
$author=($c['url'])?'<a href="'.$c['url'].'">'.$author.'</a>':$author;
|
||||||
print "<div class='comment-content'><span class='title'>".$author." 发表于".date('Y-m-d H:i:s',strtotime($c['ts_created']))."</span><p>".($c['content'])."</p></div>";
|
print "
|
||||||
|
<div class='comment-content'><span class='title'>".$author." 发表于".date('Y-m-d H:i:s',strtotime($c['ts_created']))."</span>
|
||||||
|
<p>".($c['content'])."</p>
|
||||||
|
$replyhtml
|
||||||
|
</div>";
|
||||||
}
|
}
|
||||||
echo '<div class="paginator">'.$paginator.'</div>';
|
echo '<div class="paginator">'.$paginator.'</div>';
|
||||||
}//else echo "<li>No comments.</li>";
|
}//else echo "<li>No comments.</li>";
|
||||||
|
|
Loading…
Reference in New Issue