添加了搜索和排序功能

This commit is contained in:
Li Jianxuan 2013-09-30 03:09:21 +00:00
parent 3f216e98bc
commit 6a9bdd0109
3 changed files with 68 additions and 9 deletions

View File

@ -1124,6 +1124,8 @@ class Admin_DataController extends Zend_Controller_Action
$this->view->ac = $ac = $this->_getParam('ac'); $this->view->ac = $ac = $this->_getParam('ac');
$submit = $this->_getParam('submit'); $submit = $this->_getParam('submit');
$keyword = $this->view->q = trim($this->_getParam('q')); $keyword = $this->view->q = trim($this->_getParam('q'));
$order = $this->view->search_order = trim($this->_getParam('order'));
$sort = $this->view->search_sort = trim($this->_getParam('sort'));
$reference = new Reference(); $reference = new Reference();
@ -1132,10 +1134,20 @@ class Admin_DataController extends Zend_Controller_Action
$reference->keyword = $keyword; $reference->keyword = $keyword;
} }
if(!empty($order))
{
$reference->order = $order;
}
if(!empty($sort))
{
$reference->sort = $sort;
}
//文献首页 //文献首页
if(empty($ac)) if(empty($ac))
{ {
view::addPaginator($reference->fetchReferences(),$this,10); view::addPaginator($reference->fetchReferences(),$this,12);
return true; return true;
} }
else if ($ac == "water") else if ($ac == "water")

View File

@ -22,8 +22,10 @@ table thead tr th {background:#EBF2F6;}
</div> </div>
<div> <div>
<div class="input-append"> <div class="input-append">
<form id="datasearch" class="search_form" action=""> <form id="datasearch" class="search_form" action="?<?php echo $_SERVER["QUERY_STRING"];?>">
<input type="text" id="keyword" name="q" value="<?php if(!empty($this->q)) echo $this->q; ?>" /> <input type="text" id="keyword" name="q" value="<?php if(!empty($this->q)) echo $this->q; ?>" />
<input type="hidden" name="order" value="<?php if(!empty($this->search_order)) echo $this->search_order; ?>" />
<input type="hidden" name="sort" value="<?php if(!empty($this->search_sort)) echo $this->search_sort; ?>" />
<button type="submit" class="btn" id="search_btn">搜索</button> <button type="submit" class="btn" id="search_btn">搜索</button>
</form> </form>
</div> </div>
@ -39,8 +41,14 @@ table thead tr th {background:#EBF2F6;}
<table class="table table-bordered table-striped"> <table class="table table-bordered table-striped">
<thead> <thead>
<tr> <tr>
<th>标题</th> <th>标题
<th>年份</th> <a href="?order=title&sort=ASC&q=<?php if(!empty($this->q)) echo $this->q; ?>"><i class="icon-arrow-up"></i></a>
<a href="?order=title&sort=DESC&q=<?php if(!empty($this->q)) echo $this->q; ?>"><i class="icon-arrow-down"></i></a>
</th>
<th>年份
<a href="?order=year&sort=ASC&q=<?php if(!empty($this->q)) echo $this->q; ?>"><i class="icon-arrow-up"></i></a>
<a href="?order=year&sort=DESC&q=<?php if(!empty($this->q)) echo $this->q; ?>"><i class="icon-arrow-down"></i></a>
</th>
<th width="140">操作</th> <th width="140">操作</th>
</tr> </tr>
</thead> </thead>

View File

@ -15,6 +15,8 @@ class Reference
protected $events = NULL; protected $events = NULL;
public $table; public $table;
public $keyword; public $keyword;
public $order;
public $sort = "DESC";
function __construct($db = NULL,$mail = NULL) function __construct($db = NULL,$mail = NULL)
{ {
@ -164,12 +166,29 @@ class Reference
//所有文献 //所有文献
public function fetchReferences() public function fetchReferences()
{ {
$wheresql = array();
if(!empty($this->keyword)) if(!empty($this->keyword))
{ {
$search = new Search(); $wheresql[] = " ({$this->table->reference}.title LIKE '%{$this->keyword}%' OR {$this->table->reference}.reference LIKE '%{$this->keyword}%') ";
$keyword = $search->splitKeyword($this->keyword);
} }
$sql = "SELECT * FROM {$this->table->reference} ORDER BY id DESC"; if(count($wheresql)>0)
{
$wheresql = " WHERE ".join(" AND ",$wheresql);
}else{
$wheresql = "";
}
if(empty($this->order))
{
$order = "{$this->table->reference}.title";
}else{
$order = "{$this->table->reference}.{$this->order}";
}
$sql = "SELECT {$this->table->reference}.* FROM
{$this->table->reference}
$wheresql
ORDER BY $order {$this->sort}";
$rs = $this->db->query($sql); $rs = $this->db->query($sql);
return $rs->fetchAll(); return $rs->fetchAll();
} }
@ -177,10 +196,30 @@ class Reference
//获取专题数据的文献 //获取专题数据的文献
public function fetchThemeReferences($code) public function fetchThemeReferences($code)
{ {
$wheresql = array();
$wheresql[] = " s.code='$code' ";
if(!empty($this->keyword))
{
$wheresql[] = " (ref.title LIKE '%{$this->keyword}%' OR ref.reference LIKE '%{$this->keyword}%') ";
}
if(count($wheresql)>0)
{
$wheresql = " WHERE ".join(" AND ",$wheresql);
}else{
$wheresql = "";
}
if(empty($this->order))
{
$order = "ref.year,ref.title";
}else{
$order = "ref.{$this->order} {$this->sort}";
}
$sql="select distinct ref.* from mdref r left join {$this->table->reference} ref on r.refid=ref.id $sql="select distinct ref.* from mdref r left join {$this->table->reference} ref on r.refid=ref.id
left join datasource ds on r.uuid=ds.uuid left join {$this->table->source} s on s.id=ds.sourceid left join datasource ds on r.uuid=ds.uuid left join {$this->table->source} s on s.id=ds.sourceid
where s.code='$code' $wheresql
order by ref.year,ref.title"; ORDER BY $order";
$rs=$this->db->query($sql); $rs=$this->db->query($sql);
return $rs->fetchAll(); return $rs->fetchAll();
} }