quick search is working, with small paginator ajax url hack
This commit is contained in:
parent
101b6fafa6
commit
ff02a42514
|
@ -37,6 +37,10 @@ class LibraryController extends Zend_Controller_Action
|
|||
|
||||
unset($this->search_sess->page);
|
||||
unset($this->search_sess->md);
|
||||
|
||||
if ($this->getRequest()->isGet()) {
|
||||
unset($this->search_sess->quick);
|
||||
}
|
||||
|
||||
$this->_helper->actionStack('contents', 'library');
|
||||
$this->_helper->actionStack('quick-search', 'library');
|
||||
|
@ -154,14 +158,25 @@ class LibraryController extends Zend_Controller_Action
|
|||
$currpage = isset($page) ? $page : $last_page;
|
||||
$this->search_sess->page = $currpage;
|
||||
|
||||
$md = isset($this->search_sess->md) ? $this->search_sess->md : array();
|
||||
|
||||
$count = StoredFile::searchFiles($md, $order, true);
|
||||
if(isset($this->search_sess->md)){
|
||||
$md = $this->search_sess->md;
|
||||
$quick = false;
|
||||
}
|
||||
else if(isset($this->search_sess->quick)) {
|
||||
$md = $this->search_sess->quick;
|
||||
$quick = true;
|
||||
}
|
||||
else {
|
||||
$md = array();
|
||||
$quick = false;
|
||||
}
|
||||
|
||||
$count = StoredFile::searchFiles($md, $order, true, null, null, $quick);
|
||||
|
||||
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Null($count));
|
||||
$paginator->setCurrentPageNumber($currpage);
|
||||
$this->view->paginator = $paginator;
|
||||
$this->view->files = StoredFile::searchFiles($md, $order, false, $paginator->getCurrentPageNumber(), $paginator->getItemCountPerPage());
|
||||
$this->view->files = StoredFile::searchFiles($md, $order, false, $paginator->getCurrentPageNumber(), $paginator->getItemCountPerPage(), $quick);
|
||||
}
|
||||
|
||||
public function editFileMdAction()
|
||||
|
@ -193,6 +208,9 @@ class LibraryController extends Zend_Controller_Action
|
|||
|
||||
$this->_helper->viewRenderer->setResponseSegment('quick_search');
|
||||
|
||||
//$this->view->urlparams = array("route" => array("controller"=> "Library", "action"=> "index", "module"=> "default"));
|
||||
$this->route = 'quick_search';
|
||||
|
||||
$search = $this->_getParam('search', null);
|
||||
$format = $this->_getParam('format', 'layout');
|
||||
|
||||
|
@ -204,26 +222,26 @@ class LibraryController extends Zend_Controller_Action
|
|||
|
||||
$md = array();
|
||||
|
||||
$i = 0;
|
||||
foreach($keywords as $word) {
|
||||
|
||||
foreach($categories as $cat) {
|
||||
$md["row_".$i]["metadata_".$i] = $cat;
|
||||
$md["row_".$i]["match_".$i] = 0;
|
||||
$md["row_".$i]["search_".$i] = $word;
|
||||
|
||||
$i = $i + 1;
|
||||
}
|
||||
}
|
||||
for($group_id=1; $group_id <= count($keywords); $group_id++) {
|
||||
|
||||
for($row_id=1; $row_id <= count($categories); $row_id++) {
|
||||
|
||||
$md["group_".$group_id]["row_".$row_id]["metadata"] = $categories[$row_id-1];
|
||||
$md["group_".$group_id]["row_".$row_id]["match"] = "0";
|
||||
$md["group_".$group_id]["row_".$row_id]["search"] = $keywords[$group_id-1];
|
||||
}
|
||||
}
|
||||
|
||||
$this->search_sess->quick = $md;
|
||||
|
||||
$currpage = isset($this->search_sess->page) ? $this->search_sess->page : null;
|
||||
$order = isset($this->search_sess->order) ? $this->search_sess->order : null;
|
||||
$count = StoredFile::searchFiles($md, $order, true);
|
||||
$count = StoredFile::searchFiles($md, $order, true, null, null, true);
|
||||
|
||||
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Null($count));
|
||||
$paginator->setCurrentPageNumber($currpage);
|
||||
$this->view->paginator = $paginator;
|
||||
$this->view->files = StoredFile::searchFiles($md, $order, false, $paginator->getCurrentPageNumber(), $paginator->getItemCountPerPage());
|
||||
$this->view->files = StoredFile::searchFiles($md, $order, false, $paginator->getCurrentPageNumber(), $paginator->getItemCountPerPage(), true);
|
||||
|
||||
$this->view->html = $this->view->render('library/contents.phtml');
|
||||
unset($this->view->files);
|
||||
|
|
|
@ -1741,7 +1741,7 @@ class StoredFile {
|
|||
return $CC_CONFIG['accessDir']."/$p_token.$p_ext";
|
||||
}
|
||||
|
||||
public static function searchFiles($md, $order=NULL, $count=false, $page=null, $limit=null)
|
||||
public static function searchFiles($md, $order=NULL, $count=false, $page=null, $limit=null, $quick=false)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC, $g_metadata_xml_to_db_mapping;
|
||||
|
||||
|
@ -1800,6 +1800,8 @@ class StoredFile {
|
|||
$sql = $selector." ".$from;
|
||||
|
||||
$or_cond = array();
|
||||
$inner = $quick ? 'OR':'AND';
|
||||
$outer = $quick ? 'AND':'OR';
|
||||
foreach (array_keys($md) as $group) {
|
||||
|
||||
if(strpos($group, 'group') === false) {
|
||||
|
@ -1822,12 +1824,12 @@ class StoredFile {
|
|||
}
|
||||
|
||||
if(count($and_cond) > 0) {
|
||||
$or_cond[] = "(".join(" AND ", $and_cond).")";
|
||||
$or_cond[] = "(".join(" ".$inner." ", $and_cond).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(count($or_cond) > 0) {
|
||||
$where = " WHERE ". join(" OR ", $or_cond);
|
||||
$where = " WHERE ". join(" ".$outer." ", $or_cond);
|
||||
$sql = $sql . $where;
|
||||
}
|
||||
|
||||
|
@ -1850,7 +1852,7 @@ class StoredFile {
|
|||
$sql = $sql . $paginate;
|
||||
}
|
||||
//echo var_dump($md);
|
||||
echo $sql;
|
||||
//echo $sql;
|
||||
|
||||
return $CC_DBC->getAll($sql);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,15 @@ function setUpQuickSearch() {
|
|||
string = $(this).val();
|
||||
|
||||
$.post(url, {search: string}, function(json){
|
||||
var x;
|
||||
var html;
|
||||
//hacky way until I can figure out paginator better.
|
||||
html = json.html.replace(/quick-search\/format\/json/g, "index");
|
||||
|
||||
$("#library_content")
|
||||
.empty()
|
||||
.append(html);
|
||||
|
||||
setUpLibrary();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue