#243 将评论回复也放在评论表中

This commit is contained in:
Li Jianxuan 2012-09-18 09:14:41 +00:00
parent ca4c0120d4
commit edf2cfca6b
3 changed files with 49 additions and 47 deletions

View File

@ -564,6 +564,7 @@ class Admin_DataController extends Zend_Controller_Action
/* /*
* commentAction() * commentAction()
* 反馈管理 * 反馈管理
* ALTER TABLE comments ADD COLUMN reply integer NOT NULL DEFAULT 0;
*/ */
function commentAction() function commentAction()
{ {
@ -584,6 +585,44 @@ class Admin_DataController extends Zend_Controller_Action
} }
$this->_redirect("/admin/data/comment"); $this->_redirect("/admin/data/comment");
} }
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 (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($uuid) if($uuid)
{ {
@ -611,51 +650,13 @@ 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) if($replylist)
{ {
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
$sql = "SELECT cr.id,cr.body,cr.cid,u.username,cr.ts_created FROM comments_reply cr $sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created FROM comments cr
LEFT JOIN users u ON cr.uid=u.id WHERE cid=?"; LEFT JOIN users u ON cr.userid=u.id WHERE cr.reply=?";
$sth = $this->db->prepare($sql); $sth = $this->db->prepare($sql);
$sth->execute(array($replylist)); $sth->execute(array($replylist));
$rows = $sth->fetchAll(); $rows = $sth->fetchAll();
@ -670,7 +671,7 @@ class Admin_DataController extends Zend_Controller_Action
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
$sql = "DELETE FROM comments_reply WHERE id=?"; $sql = "DELETE FROM comments WHERE id=?";
$sth = $this->db->prepare($sql); $sth = $this->db->prepare($sql);
$rs = $sth->execute(array($delreply)); $rs = $sth->execute(array($delreply));
@ -695,6 +696,7 @@ class Admin_DataController extends Zend_Controller_Action
$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')
->where('reply=0')
->order('comments.ts_created desc') ->order('comments.ts_created desc')
->order('comments.id desc'); ->order('comments.id desc');
$paginator = Zend_Paginator::factory($select); $paginator = Zend_Paginator::factory($select);

View File

@ -40,7 +40,7 @@ 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> <a href="javascript:;" onclick="showreply(<?= $item['id']; ?>)">回复</a></p> 。操作: <a href="/admin/data/comment/delete/<?= $item['id']; ?>">删除</a> <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> <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']; ?>)" class="btn btn-green" style="vertical-align:bottom">提交</button> <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;"> <div style="width:90%; margin:0 auto;">
<ul id="replyList_<?= $item['id']; ?>"> <ul id="replyList_<?= $item['id']; ?>">
</ul> </ul>
@ -56,12 +56,12 @@ EMAIL<?= $item['email']; ?>
</div> </div>
<?= $this->paginator; ?> <?= $this->paginator; ?>
<script> <script>
function reply(id) function reply(id,uuid)
{ {
$.ajax({ $.ajax({
'type':"POST", 'type':"POST",
'url':'/admin/data/comment/reply/'+id, 'url':'/admin/data/comment/reply/'+id,
'data':'content='+$('#reply_'+id).val(), 'data':'content='+$('#reply_'+id).val()+'&uuid='+uuid,
'success':function(data){ 'success':function(data){
if (typeof(data)=='object') if (typeof(data)=='object')
{ {

View File

@ -844,7 +844,7 @@ class DataController extends Zend_Controller_Action
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
$uuid=$this->_request->getParam('uuid'); $uuid=$this->_request->getParam('uuid');
if (empty($uuid)) die(); if (empty($uuid)) die();
$sql="select * from comments where uuid=? order by id desc"; $sql="select * from comments where uuid=? AND reply=0 order by id desc";
$comments=$this->db->fetchAll($sql,array($uuid)); $comments=$this->db->fetchAll($sql,array($uuid));
$paginator = Zend_Paginator::factory($comments); $paginator = Zend_Paginator::factory($comments);
@ -858,8 +858,8 @@ 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 $sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created FROM comments cr
LEFT JOIN users u ON cr.uid=u.id WHERE cid=?"; LEFT JOIN users u ON cr.userid=u.id WHERE cr.reply=?";
$sth = $this->db->prepare($sql); $sth = $this->db->prepare($sql);
$sth->execute(array($c['id'])); $sth->execute(array($c['id']));
$replys = $sth->fetchAll(); $replys = $sth->fetchAll();