full functionality of media library now available using datatables, advanced search is not done.
This commit is contained in:
parent
a0ecbecf3b
commit
f6d270616a
4 changed files with 80 additions and 13 deletions
|
@ -37,7 +37,7 @@ $pages = array(
|
|||
'resource' => 'plupload'
|
||||
),
|
||||
array(
|
||||
'label' => 'Search',
|
||||
'label' => 'Search (not working right now)',
|
||||
'module' => 'default',
|
||||
'controller' => 'Search',
|
||||
'action' => 'index',
|
||||
|
|
|
@ -133,11 +133,12 @@ class LibraryController extends Zend_Controller_Action
|
|||
$echo = $this->_getParam('sEcho');
|
||||
$offset = $this->_getParam('iDisplayStart');
|
||||
$limit = $this->_getParam('iDisplayLength');
|
||||
$post = $this->getRequest()->getPost();
|
||||
|
||||
if($format == "json") {
|
||||
|
||||
$datatables = array("sEcho" => $echo);
|
||||
$files = StoredFile::searchFiles($offset, $limit);
|
||||
$files = StoredFile::searchFiles($offset, $limit, $post);
|
||||
|
||||
$datatables = array_merge($datatables, $files);
|
||||
|
||||
|
|
|
@ -1742,11 +1742,14 @@ class StoredFile {
|
|||
return $CC_CONFIG['accessDir']."/$p_token.$p_ext";
|
||||
}
|
||||
|
||||
public static function searchFiles($offset, $limit, $md=NULL, $order=NULL, $quick=false)
|
||||
public static function searchFiles($offset, $limit, $data)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC, $g_metadata_xml_to_db_mapping;
|
||||
|
||||
$columnsDisplayed = array("id", "track_title", "artist_name", "album_title", "track_number", "length", "ftype");
|
||||
$columnsDisplayed = explode(",", $data["sColumns"]);
|
||||
|
||||
if($data["sSearch"] !== "")
|
||||
$searchTerms = explode(" ", $data["sSearch"]);
|
||||
|
||||
$plSelect = "SELECT ";
|
||||
$fileSelect = "SELECT ";
|
||||
|
@ -1788,14 +1791,67 @@ class StoredFile {
|
|||
|
||||
UNION
|
||||
|
||||
(".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS ";
|
||||
(".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS";
|
||||
|
||||
$sql = $selectorCount." ".$fromTable;
|
||||
$totalRows = $CC_DBC->getOne($sql);
|
||||
|
||||
// Where clause
|
||||
|
||||
if(isset($searchTerms)) {
|
||||
|
||||
$searchCols = array();
|
||||
|
||||
for($i=0; $i<$data["iColumns"]; $i++) {
|
||||
|
||||
if($data["bSearchable_".$i] == "true") {
|
||||
$searchCols[] = $columnsDisplayed[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$outerCond = array();
|
||||
|
||||
foreach($searchTerms as $term) {
|
||||
|
||||
$innerCond = array();
|
||||
|
||||
foreach($searchCols as $col) {
|
||||
|
||||
$innerCond[] = "{$col}::text ILIKE '%{$term}%'";
|
||||
}
|
||||
|
||||
$outerCond[] = join(" OR ", $innerCond);
|
||||
}
|
||||
|
||||
$where = join(" AND ", $outerCond);
|
||||
|
||||
$sql = $selectorCount." ".$fromTable." WHERE ".$where;
|
||||
$totalDisplayRows = $CC_DBC->getOne($sql);
|
||||
}
|
||||
|
||||
// End Where clause
|
||||
|
||||
// Order By clause
|
||||
|
||||
$orderby = array();
|
||||
for($i=0; $i<$data["iSortingCols"]; $i++){
|
||||
$orderby[] = $columnsDisplayed[$data["iSortCol_".$i]]." ".$data["sSortDir_".$i];
|
||||
}
|
||||
$orderby[] = "id";
|
||||
$orderby = join("," , $orderby);
|
||||
|
||||
// End Order By clause
|
||||
|
||||
//ordered by integer as expected by datatables.
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ORDERED);
|
||||
$sql = $selectorRows." ".$fromTable." ORDER BY id OFFSET ".$offset." LIMIT ".$limit;
|
||||
|
||||
if(isset($where)) {
|
||||
$sql = $selectorRows." ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$offset." LIMIT ".$limit;
|
||||
}
|
||||
else {
|
||||
$sql = $selectorRows." ".$fromTable." ORDER BY ".$orderby." OFFSET ".$offset." LIMIT ".$limit;
|
||||
}
|
||||
|
||||
$results = $CC_DBC->getAll($sql);
|
||||
//echo $results;
|
||||
//echo $sql;
|
||||
|
@ -1803,7 +1859,11 @@ class StoredFile {
|
|||
//put back to default fetch mode.
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
return array("iTotalDisplayRecords" => $totalRows, "iTotalRecords" => $totalRows, "aaData" => $results);
|
||||
if(!isset($totalDisplayRows)) {
|
||||
$totalDisplayRows = $totalRows;
|
||||
}
|
||||
|
||||
return array("iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//used by jjmenu
|
||||
function getId() {
|
||||
var tr_id = $(this.triggerElement).attr("id");
|
||||
tr_id = tr_id.split("_");
|
||||
|
@ -11,15 +12,19 @@ function getType() {
|
|||
|
||||
return tr_id[0];
|
||||
}
|
||||
//end functions used by jjmenu
|
||||
|
||||
function deleteItem(type, id) {
|
||||
var tr_id;
|
||||
var tr_id, tr, dt;
|
||||
|
||||
tr_id = type+"_"+id;
|
||||
tr = $("#"+tr_id);
|
||||
|
||||
$("#library_display tr#" +tr_id).remove();
|
||||
dt = $("#library_display").dataTable();
|
||||
dt.fnDeleteRow( tr );
|
||||
}
|
||||
|
||||
//callbacks called by jjmenu
|
||||
function deleteAudioClip(json) {
|
||||
if(json.message) {
|
||||
alert(json.message);
|
||||
|
@ -37,6 +42,7 @@ function deletePlaylist(json) {
|
|||
|
||||
deleteItem("pl", json.id);
|
||||
}
|
||||
//end callbacks called by jjmenu
|
||||
|
||||
function addLibraryItemEvents() {
|
||||
|
||||
|
@ -45,7 +51,7 @@ function addLibraryItemEvents() {
|
|||
helper: 'clone'
|
||||
});
|
||||
|
||||
$('#library_display tr:not(:first-child)')
|
||||
$('#library_display tbody tr')
|
||||
.jjmenu("rightClick",
|
||||
[{get:"/Library/context-menu/format/json/id/#id#/type/#type#"}],
|
||||
{id: getId, type: getType},
|
||||
|
@ -89,8 +95,8 @@ function setUpLibrary() {
|
|||
/* Album */ { "sName": "album_title" },
|
||||
/* Track */ { "sName": "track_number" },
|
||||
/* Length */ { "sName": "length" },
|
||||
/* Type */ { "sName": "type" }
|
||||
]
|
||||
|
||||
/* Type */ { "sName": "ftype", "bSearchable": false }
|
||||
],
|
||||
"aaSorting": [[2,'asc']]
|
||||
} );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue