添加了搜索和排序功能
This commit is contained in:
parent
3f216e98bc
commit
6a9bdd0109
|
@ -1124,6 +1124,8 @@ class Admin_DataController extends Zend_Controller_Action
|
|||
$this->view->ac = $ac = $this->_getParam('ac');
|
||||
$submit = $this->_getParam('submit');
|
||||
$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();
|
||||
|
||||
|
@ -1132,10 +1134,20 @@ class Admin_DataController extends Zend_Controller_Action
|
|||
$reference->keyword = $keyword;
|
||||
}
|
||||
|
||||
if(!empty($order))
|
||||
{
|
||||
$reference->order = $order;
|
||||
}
|
||||
|
||||
if(!empty($sort))
|
||||
{
|
||||
$reference->sort = $sort;
|
||||
}
|
||||
|
||||
//文献首页
|
||||
if(empty($ac))
|
||||
{
|
||||
view::addPaginator($reference->fetchReferences(),$this,10);
|
||||
view::addPaginator($reference->fetchReferences(),$this,12);
|
||||
return true;
|
||||
}
|
||||
else if ($ac == "water")
|
||||
|
|
|
@ -22,8 +22,10 @@ table thead tr th {background:#EBF2F6;}
|
|||
</div>
|
||||
<div>
|
||||
<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="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>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -39,8 +41,14 @@ table thead tr th {background:#EBF2F6;}
|
|||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<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>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -15,6 +15,8 @@ class Reference
|
|||
protected $events = NULL;
|
||||
public $table;
|
||||
public $keyword;
|
||||
public $order;
|
||||
public $sort = "DESC";
|
||||
|
||||
function __construct($db = NULL,$mail = NULL)
|
||||
{
|
||||
|
@ -164,12 +166,29 @@ class Reference
|
|||
//所有文献
|
||||
public function fetchReferences()
|
||||
{
|
||||
$wheresql = array();
|
||||
if(!empty($this->keyword))
|
||||
{
|
||||
$search = new Search();
|
||||
$keyword = $search->splitKeyword($this->keyword);
|
||||
$wheresql[] = " ({$this->table->reference}.title LIKE '%{$this->keyword}%' OR {$this->table->reference}.reference LIKE '%{$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);
|
||||
return $rs->fetchAll();
|
||||
}
|
||||
|
@ -177,10 +196,30 @@ class Reference
|
|||
//获取专题数据的文献
|
||||
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
|
||||
left join datasource ds on r.uuid=ds.uuid left join {$this->table->source} s on s.id=ds.sourceid
|
||||
where s.code='$code'
|
||||
order by ref.year,ref.title";
|
||||
$wheresql
|
||||
ORDER BY $order";
|
||||
$rs=$this->db->query($sql);
|
||||
return $rs->fetchAll();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue