#243 在前台数据作者的操作界面中添加了评论回复功能

This commit is contained in:
Li Jianxuan 2012-09-19 07:39:04 +00:00
parent 872b31732c
commit 159af19e17
2 changed files with 145 additions and 7 deletions

View File

@ -1046,6 +1046,9 @@ class AuthorController extends Zend_Controller_Action
function commentAction() function commentAction()
{ {
$ac = $this->_request->getParam('ac'); $ac = $this->_request->getParam('ac');
$uuid = $this->_getParam('uuid');
$reply = $this->_getParam('reply');
$replylist = $this->_getParam('replylist');
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
if($auth->hasIdentity()) if($auth->hasIdentity())
@ -1059,7 +1062,7 @@ class AuthorController extends Zend_Controller_Action
$sql = "SELECT md.title,md.uuid,count(c.id) as c FROM comments c $sql = "SELECT md.title,md.uuid,count(c.id) as c FROM comments c
LEFT JOIN metadata md ON md.uuid=c.uuid LEFT JOIN metadata md ON md.uuid=c.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid LEFT JOIN mdauthor a ON md.uuid=a.uuid
WHERE md.title IS NOT NULL AND a.userid=? AND a.status=1 WHERE md.title IS NOT NULL AND a.userid=? AND a.status=1 AND c.reply=0
GROUP BY md.title,md.uuid GROUP BY md.title,md.uuid
"; ";
$sth = $this->db->prepare($sql); $sth = $this->db->prepare($sql);
@ -1082,10 +1085,10 @@ class AuthorController extends Zend_Controller_Action
$uuid = $this->_request->getParam('uuid'); $uuid = $this->_request->getParam('uuid');
if(preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) if(preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{ {
$sql = "SELECT c.author,c.email,c.url,c.ts_created,c.content,m.title FROM comments c $sql = "SELECT c.id,c.author,c.email,c.url,c.ts_created,c.content,m.title,c.uuid FROM comments c
LEFT JOIN mdauthor a ON a.uuid=c.uuid LEFT JOIN mdauthor a ON a.uuid=c.uuid
left join metadata m on m.uuid=c.uuid left join metadata m on m.uuid=c.uuid
WHERE c.uuid=? AND a.userid=? AND a.status=1 WHERE c.uuid=? AND a.userid=? AND a.status=1 AND c.reply=0
ORDER BY ts_created DESC"; ORDER BY ts_created DESC";
$sth = $this->db->prepare($sql); $sth = $this->db->prepare($sql);
@ -1109,7 +1112,7 @@ class AuthorController extends Zend_Controller_Action
$sql = "SELECT md.title,c.author,c.email,c.url,c.ts_created,c.content FROM comments c $sql = "SELECT md.title,c.author,c.email,c.url,c.ts_created,c.content FROM comments c
LEFT JOIN mdauthor a ON a.uuid=c.uuid LEFT JOIN mdauthor a ON a.uuid=c.uuid
LEFT JOIN normalmetadata md ON md.uuid=c.uuid LEFT JOIN normalmetadata md ON md.uuid=c.uuid
WHERE a.userid=? AND a.status=1 WHERE a.userid=? AND a.status=1 AND c.reply=0
ORDER BY ts_created DESC"; ORDER BY ts_created DESC";
$sth = $this->db->prepare($sql); $sth = $this->db->prepare($sql);
@ -1125,6 +1128,75 @@ class AuthorController extends Zend_Controller_Action
$this->_helper->viewRenderer('comment-listall'); $this->_helper->viewRenderer('comment-listall');
} }
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 = "SELECT md.title,c.id,c.author,c.email,c.url,c.ts_created,c.content FROM comments c
LEFT JOIN mdauthor a ON a.uuid=c.uuid
LEFT JOIN normalmetadata md ON md.uuid=c.uuid
WHERE a.userid=? AND a.status=1 AND c.reply=0 AND c.id=?
ORDER BY ts_created DESC";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id,$reply));
$row = $sth->fetch();
if(empty($row['id']))
{
$data = array('error'=>"回复失败,您没有权限进行此操作");
$this->jsonexit($data);
return true;
}
$sql = "INSERT INTO comments (uuid,author,reply,userid,content) VALUES (?,?,?,?,?)";
$sth = $this->db->prepare($sql);
$rs = $sth->execute(array($uuid,$user->username,$reply,$uid,$body));
if($rs)
{
$data = array('status'=>1,'msg'=>'回复成功!');
$this->jsonexit($data);
return true;
}else{
$data = array('error'=>"回复失败,请重试");
$this->jsonexit($data);
return true;
}
return true;
}
if($replylist)
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created FROM comments cr
LEFT JOIN users u ON cr.userid=u.id WHERE cr.reply=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($replylist));
$rows = $sth->fetchAll();
$this->jsonexit($rows);
return true;
}
}// commentAction() 数据反馈 }// commentAction() 数据反馈

View File

@ -4,6 +4,8 @@ $this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js'); $this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headLink()->appendStylesheet('/css/author.css'); $this->headLink()->appendStylesheet('/css/author.css');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>'); $this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>'); $this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('数据反馈管理'); $this->breadcrumb('数据反馈管理');
@ -27,14 +29,22 @@ $this->breadcrumb()->setSeparator(' > ');
</div> </div>
<div id="datalist"> <div id="datalist">
<?php <?php
if (count($this->paginator)): if (count($this->paginator)):
echo "<h2>数据标题:".$this->mdtitle."</h2>"; echo "<h2>数据标题:".$this->mdtitle."</h2>";
echo "<ul>"; echo "<ul>";
$autoindex=0; $autoindex=0;
foreach ($this->paginator as $item): foreach ($this->paginator as $item):
$autoindex++;?> $autoindex++;?>
<li> <li>
<p>评论者:<?php echo $item['author'] ?> <?php echo $item['email'];?>) 评论时间:<?php echo date("Y-m-d H:i",strtotime($item['ts_created']));?></p> <p>评论者:<?php echo $item['author'] ?> <?php echo $item['email'];?>) 评论时间:<?php echo date("Y-m-d H:i",strtotime($item['ts_created']));?> <a href="javascript:;" onclick="showreply(<?= $item['id']; ?>)">回复</a></p>
<p style="display:none;vertical-align:bottom" id="comment_reply_<?= $item['id']; ?>">
<textarea id="reply_<?= $item['id']; ?>" class="middle half"></textarea>
<button type="button" onclick="reply(<?= $item['id']; ?>,'<?= $item['uuid']; ?>')" class="btn btn-green" style="vertical-align:bottom">提交</button>
<div style="width:90%; margin:0 auto;">
<ul id="replyList_<?= $item['id']; ?>">
</ul>
</div>
</p>
<p>  <?php echo $item['content'] ?></p> <p>  <?php echo $item['content'] ?></p>
</li> </li>
<?php endforeach; <?php endforeach;
@ -44,6 +54,62 @@ $this->breadcrumb()->setSeparator(' > ');
</div> </div>
</div> </div>
<!-- //页面内容 --> <!-- //页面内容 -->
<script>$('#wapper').width($('body').width()-300);</script>
<script> <script>
$('#wapper').width($('body').width()-300); function reply(id,uuid)
{
$.ajax({
'type':"POST",
'url':'/author/comment/reply/'+id,
'data':'content='+$('#reply_'+id).val()+'&uuid='+uuid,
'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':'/author/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+ '</li>');
}
html = html.join('');
$('#replyList_'+id).html(html);
}
},
'timeout': 30000,
});
}else{
$('#replyList_'+id).html('');
}
});
}
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4 style="font-size:16px;font-weight:bold;">'+html+'</h4>'});
}
</script> </script>