From f6d270616a5b4622dd6bf8e03b3cbd025a7455c7 Mon Sep 17 00:00:00 2001 From: Naomi Date: Wed, 26 Jan 2011 14:17:52 -0500 Subject: [PATCH] full functionality of media library now available using datatables, advanced search is not done. --- application/configs/navigation.php | 2 +- application/controllers/LibraryController.php | 3 +- application/models/StoredFile.php | 70 +++++++++++++++++-- public/js/airtime/library/library.js | 18 +++-- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/application/configs/navigation.php b/application/configs/navigation.php index 1790e0ac1..35ba0bc2e 100644 --- a/application/configs/navigation.php +++ b/application/configs/navigation.php @@ -37,7 +37,7 @@ $pages = array( 'resource' => 'plupload' ), array( - 'label' => 'Search', + 'label' => 'Search (not working right now)', 'module' => 'default', 'controller' => 'Search', 'action' => 'index', diff --git a/application/controllers/LibraryController.php b/application/controllers/LibraryController.php index 18ca2a2fb..ec9b870cd 100644 --- a/application/controllers/LibraryController.php +++ b/application/controllers/LibraryController.php @@ -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); diff --git a/application/models/StoredFile.php b/application/models/StoredFile.php index 8c47d0047..b6ab13d10 100644 --- a/application/models/StoredFile.php +++ b/application/models/StoredFile.php @@ -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); diff --git a/public/js/airtime/library/library.js b/public/js/airtime/library/library.js index faeed5b78..1f4f44a7c 100644 --- a/public/js/airtime/library/library.js +++ b/public/js/airtime/library/library.js @@ -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']] } ); }