search uses pagination

This commit is contained in:
naomiaro 2011-01-03 11:47:21 -05:00
parent c24a152eba
commit 75cd410ba4
9 changed files with 136 additions and 64 deletions

View file

@ -33,8 +33,7 @@ class LibraryController extends Zend_Controller_Action
$this->_helper->layout->setLayout('library'); $this->_helper->layout->setLayout('library');
unset($this->search_sess->md); unset($this->search_sess->md);
unset($this->search_sess->order);
$this->_helper->actionStack('contents', 'library'); $this->_helper->actionStack('contents', 'library');
$this->_helper->actionStack('index', 'sideplaylist'); $this->_helper->actionStack('index', 'sideplaylist');
} }
@ -59,7 +58,7 @@ class LibraryController extends Zend_Controller_Action
} }
$menu[] = array('action' => array('type' => 'gourl', 'url' => '/Library/edit-file-md/id/#id#'), $menu[] = array('action' => array('type' => 'gourl', 'url' => '/Library/edit-file-md/id/#id#'),
'title' => 'Info'); 'title' => 'Edit Metadata');
} }
else if($type === "pl") { else if($type === "pl") {
@ -124,13 +123,40 @@ class LibraryController extends Zend_Controller_Action
$this->_helper->viewRenderer->setResponseSegment('library'); $this->_helper->viewRenderer->setResponseSegment('library');
$order["category"] = $this->_getParam('ob', "dc:creator"); $cat = $this->_getParam('ob', null);
$order["order"] = $this->_getParam('order', "asc"); $or = $this->_getParam('order', null);
$page = $this->_getParam('page', null);
if(!is_null($cat) && !is_null($or)) {
$order["category"] = $cat;
$order["order"] = $or;
$this->search_sess->order = $order;
}
else if(isset($this->search_sess->order)){
$order = $this->search_sess->order;
}
else{
$order = null;
}
if (isset($this->search_sess->page)) {
$last_page = $this->search_sess->page;
}
else{
$last_page = null;
}
$currpage = isset($page) ? $page : $last_page;
$this->search_sess->page = $currpage;
$this->search_sess->order = $order;
$md = isset($this->search_sess->md) ? $this->search_sess->md : array(); $md = isset($this->search_sess->md) ? $this->search_sess->md : array();
$this->view->files = StoredFile::searchFiles($md, $order); $count = StoredFile::searchFiles($md, $order, 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());
} }
public function editFileMdAction() public function editFileMdAction()

View file

@ -15,7 +15,6 @@ class SearchController extends Zend_Controller_Action
$ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('newfield', 'html') $ajaxContext->addActionContext('newfield', 'html')
->addActionContext('display', 'json')
->initContext(); ->initContext();
$this->form = new Application_Form_AdvancedSearch(); $this->form = new Application_Form_AdvancedSearch();
@ -30,8 +29,8 @@ class SearchController extends Zend_Controller_Action
$this->view->headScript()->appendFile('/js/contextmenu/jjmenu.js','text/javascript'); $this->view->headScript()->appendFile('/js/contextmenu/jjmenu.js','text/javascript');
$this->view->headLink()->appendStylesheet('/css/contextmenu.css'); $this->view->headLink()->appendStylesheet('/css/contextmenu.css');
$this->_helper->actionStack('display', 'search');
$this->_helper->actionStack('contents', 'library'); $this->_helper->actionStack('contents', 'library');
$this->_helper->actionStack('display', 'search');
$this->_helper->actionStack('index', 'sideplaylist'); $this->_helper->actionStack('index', 'sideplaylist');
} }
@ -46,18 +45,15 @@ class SearchController extends Zend_Controller_Action
$this->form = new Application_Form_AdvancedSearch(); $this->form = new Application_Form_AdvancedSearch();
$form = $this->form; $form = $this->form;
$this->view->form = $form;
// Form has not been submitted - displayed using layouts // Form has not been submitted - displayed using layouts
if (!$request->isPost()) { if (!$request->isPost()) {
unset($this->search_sess->md);
unset($this->search_sess->order);
$sub = new Application_Form_AdvancedSearchRow(1); $sub = new Application_Form_AdvancedSearchRow(1);
$form->addSubForm($sub, 'row_1'); $form->addSubForm($sub, 'row_1');
$form->getSubForm('row_1')->removeDecorator('DtDdWrapper'); $form->getSubForm('row_1')->removeDecorator('DtDdWrapper');
$this->view->form = $form;
return; return;
} }
@ -65,24 +61,15 @@ class SearchController extends Zend_Controller_Action
$form->preValidation($request->getPost()); $form->preValidation($request->getPost());
if (!$form->isValid($request->getPost())) { if (!$form->isValid($request->getPost())) {
$this->view->form = $form->__toString();
return; return;
} }
// form was submitted, send back strings to json response. // valid form was submitted set as search criteria.
$info = $form->getValues(); $info = $form->getValues();
$this->search_sess->md = $info; $this->search_sess->md = $info;
$order = isset($this->search_sess->order) ? $this->search_sess->order : NULL;
$this->view->files = StoredFile::searchFiles($info, $order); //make sure to start on first page of new results.
unset($this->search_sess->page);
if (count($this->view->files) > 0) {
$this->view->results = $this->view->render('library/update.phtml');
}
else {
$this->view->results = "<tr>No Results</tr>";
}
unset($this->view->files);
} }
public function newfieldAction() public function newfieldAction()

View file

@ -9,6 +9,13 @@ class Application_Form_AdvancedSearch extends Zend_Form
'value' => 2 'value' => 2
)); ));
$this->getElement('search_next_id')->removeDecorator('Label')->removeDecorator('HtmlTag'); $this->getElement('search_next_id')->removeDecorator('Label')->removeDecorator('HtmlTag');
// Add the submit button
$this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Submit',
'order' => '-1'
));
} }
public function preValidation(array $data) { public function preValidation(array $data) {
@ -30,6 +37,8 @@ class Application_Form_AdvancedSearch extends Zend_Form
$id = findId($field); $id = findId($field);
$this->addNewField($data, $id); $this->addNewField($data, $id);
} }
} }
public function addNewField($data, $id) { public function addNewField($data, $id) {

View file

@ -1741,7 +1741,7 @@ class StoredFile {
return $CC_CONFIG['accessDir']."/$p_token.$p_ext"; return $CC_CONFIG['accessDir']."/$p_token.$p_ext";
} }
public static function searchFiles($md, $order=NULL) public static function searchFiles($md, $order=NULL, $count=false, $page=null, $limit=null)
{ {
global $CC_CONFIG, $CC_DBC, $g_metadata_xml_to_db_mapping; global $CC_CONFIG, $CC_DBC, $g_metadata_xml_to_db_mapping;
@ -1755,9 +1755,6 @@ class StoredFile {
"6" => "!=", "6" => "!=",
); );
//$sql = "SELECT * FROM ".$CC_CONFIG['filesTable'];
$plSelect = "SELECT "; $plSelect = "SELECT ";
$fileSelect = "SELECT "; $fileSelect = "SELECT ";
$_SESSION["br"] = ""; $_SESSION["br"] = "";
@ -1785,7 +1782,14 @@ class StoredFile {
} }
} }
$sql = "SELECT * FROM ((".$plSelect."PL.id, 'playlist' AS ftype if($count) {
$selector = "SELECT COUNT(*)";
}
else {
$selector = "SELECT *";
}
$from = " FROM ((".$plSelect."PL.id, 'playlist' AS ftype
FROM ".$CC_CONFIG["playListTable"]." AS PL FROM ".$CC_CONFIG["playListTable"]." AS PL
LEFT JOIN ".$CC_CONFIG['playListTimeView']." PLT ON PL.id = PLT.id) LEFT JOIN ".$CC_CONFIG['playListTimeView']." PLT ON PL.id = PLT.id)
@ -1793,6 +1797,8 @@ class StoredFile {
(".$fileSelect."id, ftype FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS "; (".$fileSelect."id, ftype FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS ";
$sql = $selector." ".$from;
$cond = array(); $cond = array();
foreach(array_keys($md) as $key) { foreach(array_keys($md) as $key) {
if(strpos($key, 'row') !== false){ if(strpos($key, 'row') !== false){
@ -1817,13 +1823,27 @@ class StoredFile {
$sql = $sql . $where; $sql = $sql . $where;
} }
if(!is_null($order)) { if($count) {
$ob = " ORDER BY ".$g_metadata_xml_to_db_mapping[$order["category"]]; return $CC_DBC->getOne($sql);
$sql = $sql . $ob . " " .$order["order"];
} }
//echo $sql;
return $CC_DBC->getAll($sql); if(!is_null($order)) {
$ob = " ORDER BY ".$g_metadata_xml_to_db_mapping[$order["category"]]. ", id " .$order["order"];
$sql = $sql . $ob;
}
else{
$ob = " ORDER BY artist_name, id asc";
$sql = $sql . $ob;
}
if(!is_null($page) && !is_null($limit)) {
$offset = $page * $limit - ($limit);
$paginate = " LIMIT ".$limit. " OFFSET " .$offset;
$sql = $sql . $paginate;
}
echo $sql;
return $CC_DBC->getAll($sql);
} }
} }

View file

@ -20,3 +20,15 @@
} }
?> ?>
<?php
echo "page: " . $this->page;
echo "curr: " . $this->curr;
echo $this->paginationControl($this->paginator,
'Sliding',
'library/paginator.phtml');
?>

View file

@ -0,0 +1,44 @@
<?php if ($this->pageCount): ?>
<div class="paginationControl">
<?php echo $this->firstItemNumber; ?> - <?php echo $this->lastItemNumber; ?>
of <?php echo $this->totalItemCount; ?>
<!-- First page link -->
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('page' => $this->first)); ?>">
First
</a> |
<?php else: ?>
<span class="disabled">First</span> |
<?php endif; ?>
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('page' => $this->previous)); ?>">
&lt; Previous
</a> |
<?php else: ?>
<span class="disabled">&lt; Previous</span> |
<?php endif; ?>
<!-- Next page link -->
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('page' => $this->next)); ?>">
Next &gt;
</a> |
<?php else: ?>
<span class="disabled">Next &gt;</span> |
<?php endif; ?>
<!-- Last page link -->
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('page' => $this->last)); ?>">
Last
</a>
<?php else: ?>
<span class="disabled">Last</span>
<?php endif; ?>
</div>
<?php endif; ?>

View file

@ -1,2 +1,3 @@
<?php <?php
echo $this->partialLoop('library/libraryTablePartial.phtml', $this->files);
echo $this->partialLoop('library/libraryTablePartial.phtml', $this->files);

View file

@ -1,6 +1,6 @@
<?php <?php
$this->form->setAction($this->url());
echo $this->form; echo $this->form;
?> ?>
<span id="search_add">Add</span> <span id="search_add">Add</span>
<span id="search_submit">Submit</span>

View file

@ -28,36 +28,9 @@ function ajaxAddField() {
}); });
} }
function searchLibrary() {
var url, data;
url = '/Search/display/format/json';
data = $("form").serializeArray();
$.post(url, data, function(json){
if(json.form) {
$("#search")
.empty()
.append(json.form);
}
if(json.results) {
$("#library_display tr:not(:first-child)").remove();
$("#library_display tbody").append(json.results);
//in campcaster/library.js
addLibraryItemEvents();
}
});
}
function setUpSearch() { function setUpSearch() {
$("#search_add").click(ajaxAddField); $("#search_add").click(ajaxAddField);
$("#search_submit").click(searchLibrary);
$('[id^="fieldset-row_"]').each(function(i, el){ $('[id^="fieldset-row_"]').each(function(i, el){
addRemove(el); addRemove(el);