diff --git a/application/controllers/LibraryController.php b/application/controllers/LibraryController.php
index 7af3b62fd..b12a98bbe 100644
--- a/application/controllers/LibraryController.php
+++ b/application/controllers/LibraryController.php
@@ -33,8 +33,7 @@ class LibraryController extends Zend_Controller_Action
$this->_helper->layout->setLayout('library');
unset($this->search_sess->md);
- unset($this->search_sess->order);
-
+
$this->_helper->actionStack('contents', 'library');
$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#'),
- 'title' => 'Info');
+ 'title' => 'Edit Metadata');
}
else if($type === "pl") {
@@ -124,13 +123,40 @@ class LibraryController extends Zend_Controller_Action
$this->_helper->viewRenderer->setResponseSegment('library');
- $order["category"] = $this->_getParam('ob', "dc:creator");
- $order["order"] = $this->_getParam('order', "asc");
+ $cat = $this->_getParam('ob', null);
+ $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();
- $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()
diff --git a/application/controllers/SearchController.php b/application/controllers/SearchController.php
index a96248964..05b218a39 100644
--- a/application/controllers/SearchController.php
+++ b/application/controllers/SearchController.php
@@ -15,7 +15,6 @@ class SearchController extends Zend_Controller_Action
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('newfield', 'html')
- ->addActionContext('display', 'json')
->initContext();
$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->headLink()->appendStylesheet('/css/contextmenu.css');
- $this->_helper->actionStack('display', 'search');
$this->_helper->actionStack('contents', 'library');
+ $this->_helper->actionStack('display', 'search');
$this->_helper->actionStack('index', 'sideplaylist');
}
@@ -46,18 +45,15 @@ class SearchController extends Zend_Controller_Action
$this->form = new Application_Form_AdvancedSearch();
$form = $this->form;
+ $this->view->form = $form;
// Form has not been submitted - displayed using layouts
if (!$request->isPost()) {
- unset($this->search_sess->md);
- unset($this->search_sess->order);
-
$sub = new Application_Form_AdvancedSearchRow(1);
$form->addSubForm($sub, 'row_1');
$form->getSubForm('row_1')->removeDecorator('DtDdWrapper');
- $this->view->form = $form;
return;
}
@@ -65,24 +61,15 @@ class SearchController extends Zend_Controller_Action
$form->preValidation($request->getPost());
if (!$form->isValid($request->getPost())) {
- $this->view->form = $form->__toString();
return;
}
- // form was submitted, send back strings to json response.
+ // valid form was submitted set as search criteria.
$info = $form->getValues();
$this->search_sess->md = $info;
- $order = isset($this->search_sess->order) ? $this->search_sess->order : NULL;
- $this->view->files = StoredFile::searchFiles($info, $order);
-
- if (count($this->view->files) > 0) {
- $this->view->results = $this->view->render('library/update.phtml');
- }
- else {
- $this->view->results = "
No Results
";
- }
- unset($this->view->files);
+ //make sure to start on first page of new results.
+ unset($this->search_sess->page);
}
public function newfieldAction()
diff --git a/application/forms/AdvancedSearch.php b/application/forms/AdvancedSearch.php
index 4c915c38e..a23ebc712 100644
--- a/application/forms/AdvancedSearch.php
+++ b/application/forms/AdvancedSearch.php
@@ -9,6 +9,13 @@ class Application_Form_AdvancedSearch extends Zend_Form
'value' => 2
));
$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) {
@@ -30,6 +37,8 @@ class Application_Form_AdvancedSearch extends Zend_Form
$id = findId($field);
$this->addNewField($data, $id);
}
+
+
}
public function addNewField($data, $id) {
diff --git a/application/models/StoredFile.php b/application/models/StoredFile.php
index 50fca75d7..cab6c3b71 100644
--- a/application/models/StoredFile.php
+++ b/application/models/StoredFile.php
@@ -1741,7 +1741,7 @@ class StoredFile {
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;
@@ -1755,9 +1755,6 @@ class StoredFile {
"6" => "!=",
);
- //$sql = "SELECT * FROM ".$CC_CONFIG['filesTable'];
-
-
$plSelect = "SELECT ";
$fileSelect = "SELECT ";
$_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
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 ";
+ $sql = $selector." ".$from;
+
$cond = array();
foreach(array_keys($md) as $key) {
if(strpos($key, 'row') !== false){
@@ -1817,13 +1823,27 @@ class StoredFile {
$sql = $sql . $where;
}
- if(!is_null($order)) {
- $ob = " ORDER BY ".$g_metadata_xml_to_db_mapping[$order["category"]];
- $sql = $sql . $ob . " " .$order["order"];
+ if($count) {
+ return $CC_DBC->getOne($sql);
}
- //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);
}
}
diff --git a/application/views/scripts/library/contents.phtml b/application/views/scripts/library/contents.phtml
index 4cee3f9bb..a365602df 100644
--- a/application/views/scripts/library/contents.phtml
+++ b/application/views/scripts/library/contents.phtml
@@ -20,3 +20,15 @@
}
?>
+page;
+echo "curr: " . $this->curr;
+
+echo $this->paginationControl($this->paginator,
+ 'Sliding',
+ 'library/paginator.phtml');
+
+
+?>
+
diff --git a/application/views/scripts/library/paginator.phtml b/application/views/scripts/library/paginator.phtml
new file mode 100644
index 000000000..ee091e39c
--- /dev/null
+++ b/application/views/scripts/library/paginator.phtml
@@ -0,0 +1,44 @@
+
+pageCount): ?>
+
+
diff --git a/application/views/scripts/library/update.phtml b/application/views/scripts/library/update.phtml
index 113029e1d..52eb9608b 100644
--- a/application/views/scripts/library/update.phtml
+++ b/application/views/scripts/library/update.phtml
@@ -1,2 +1,3 @@
partialLoop('library/libraryTablePartial.phtml', $this->files);
+
+ echo $this->partialLoop('library/libraryTablePartial.phtml', $this->files);
diff --git a/application/views/scripts/search/display.phtml b/application/views/scripts/search/display.phtml
index d742638df..bfa74f5d0 100644
--- a/application/views/scripts/search/display.phtml
+++ b/application/views/scripts/search/display.phtml
@@ -1,6 +1,6 @@
form->setAction($this->url());
echo $this->form;
?>
Add
-Submit
diff --git a/public/js/campcaster/library/advancedsearch.js b/public/js/campcaster/library/advancedsearch.js
index 07b9ea9cb..7f64090d5 100644
--- a/public/js/campcaster/library/advancedsearch.js
+++ b/public/js/campcaster/library/advancedsearch.js
@@ -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() {
$("#search_add").click(ajaxAddField);
- $("#search_submit").click(searchLibrary);
$('[id^="fieldset-row_"]').each(function(i, el){
addRemove(el);