Ticket #302 增加了“我的数据”功能

This commit is contained in:
Li Jianxuan 2012-03-07 07:43:37 +00:00
parent 5c685f4a16
commit bda9552187
2 changed files with 111 additions and 67 deletions

View File

@ -32,9 +32,10 @@ class AuthorController extends Zend_Controller_Action
/*
* acceptAction() 我的数据
*
* param string $ac // list|search
* param string $keyword
*
*
*
* return view
*/
function acceptAction()
{
@ -72,15 +73,8 @@ class AuthorController extends Zend_Controller_Action
//搜索
if($ac == "search")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
//数据处理代码 EOH<<<<<<<<<<<<<<<<
try{
$keyword = trim($this->_request->getParam('q'));
$this->view->q = $keyword;
if (!preg_match_all("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u",$keyword,$matchs))
{
$data = array('error'=>'搜索关键字中只能包含汉字、英文、数字');
@ -90,56 +84,20 @@ class AuthorController extends Zend_Controller_Action
//搜索标题和描述两个字段
$sql = "SELECT m.uuid,m.title,m.description,a.status,a.userid FROM metadata m
LEFT JOIN mdauthor a ON m.uuid=a.uuid
WHERE m.title like ? OR m.description like ?";
WHERE (m.title like ? OR m.description like ?) AND a.userid=?";
$sth = $this->db->prepare($sql);
$sth->execute(array("%$keyword%","%$keyword%"));
$sth->execute(array("%$keyword%","%$keyword%",$u_id));
$rows = $sth->fetchAll();
if(is_array($rows) && count($rows)>0)
$data = $rows;
else
$data = "";
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(5);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
}catch(Exception $e){
if(empty($data['error']))
{
$data = array("error"=>"处理过程中遇到错误,请重新尝试");
//$data = array("error"=>$e->getMessage());
}
}
// >>>>>>>>>>> F
$this ->getResponse()
->setHeader('Content-Type', 'application/json')
->appendBody(Zend_Json::encode($data));
}// search
if($ac == 'sendmail')
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
//数据处理代码 EOH<<<<<<<<<<<<<<<<
try{
}catch(Exception $e){
if(empty($data['error']))
{
$data = array("error"=>"处理过程中遇到错误,请重新尝试");
//$data = array("error"=>$e->getMessage());
}
}
// >>>>>>>>>>> F
$this ->getResponse()
->setHeader('Content-Type', 'application/json')
->appendBody(Zend_Json::encode($data));
}
}//acceptAction() 我的数据

View File

@ -0,0 +1,86 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('我的数据');
$this->breadcrumb()->setSeparator(' > ');
?>
<!-- 左侧导航 -->
<div id='sidebar'>
<div id='leftnavi'>
<?= $this->partial('author/navi.phtml'); ?>
</div>
</div>
<!-- //左侧导航 -->
<!-- 页面内容 -->
<div id="wapper">
<p>请输入元数据标题关键字进行搜索</p>
<form id="datasearch" class="search_form" action="/author/accept/ac/search">
<input type="text" id="keyword" name="q" value="<?php if(!empty($this->q)) echo $this->q; ?>" />
<button type="submit" class="btn" id="search_btn">搜索</button>
</form>
<div id="datalist">
<?php
if (count($this->paginator)):
echo "<ul>";
$autoindex=0;
foreach ($this->paginator as $item):
$autoindex++;?>
<li>
<a href="/data/<?php echo $item['uuid'];?>" target="_blank"><?php echo $item['title'];?></a>
<p><?php echo $item['description'] ?></p>
<p>
<?php
if($item['status']==1)
{
echo '';
}//已经是自己的数据
if ($item['status']==0)
{
echo '<img src="/images/list_extensions.gif" />您已经申请该数据,请到邮箱查看激活邮件(如果没有收到请 <a href="javascript:;" onclick="apply(\''.$item['uuid'].'\')">点击这里</a>)';
}
?>
<span id="data_<?php echo $item['uuid'];?>"></span>
</p>
</li>
<?php endforeach;
echo "</ul>";
endif; ?>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
</div>
<!-- //页面内容 -->
<script>
$('#wapper').width($('body').width()-300);
function apply(uuid){
$.ajax({
'type':"POST",
'url':'/author/apply',
'data':'ac=apply&m=send&uuid='+uuid,
'success':function(data){
if (isObject(data))
{
if(typeof(data.error)!='undefined')
{alert(data.error);}
else{alert('请重试');}
}
else{ alert('出现错误,请稍候');}
$('#data_'+uuid).html('');
},
'beforeSend':function(){
$('#data_'+uuid).html('<img src="/images/ajax-load-small.gif" />正在处理...');
},
'timeout': 20000,
'error': function(){
alert('处理中出现问题,请重试');
$('#data_'+uuid).html('');
}
});
}
function isObject(obj){if(typeof(obj)=='object'){return true;}else if(typeof(obj)!='object'){return false;}else{return false;}}
</script>