From 28bb97acfa0a74dbd0a3a02af8a0b3e2580a87b2 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Fri, 24 Feb 2012 00:55:20 +0100 Subject: [PATCH] CC-3174 : showbuilder allow user to filter library by files/playlists or all. --- airtime_mvc/application/models/StoredFile.php | 73 ++++++++++++------- airtime_mvc/public/css/styles.css | 8 +- .../public/js/airtime/library/library.js | 22 +++++- 3 files changed, 73 insertions(+), 30 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 3c28c5558..6a0539637 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -580,7 +580,6 @@ class Application_Model_StoredFile { } public static function searchFilesForPlaylistBuilder($datatables) { - global $CC_CONFIG; $displayColumns = array("id", "track_title", "artist_name", "album_title", "genre", "length", "year", "utime", "mtime", "ftype", "track_number", "mood", "bpm", "composer", "info_url", @@ -594,29 +593,42 @@ class Application_Model_StoredFile { if ($key === "id") { $plSelect[] = "PL.id AS ".$key; $fileSelect[] = $key; - } else if ($key === "track_title") { + } + else if ($key === "track_title") { $plSelect[] = "name AS ".$key; $fileSelect[] = $key; - } else if ($key === "ftype") { - $plSelect[] = "'playlist' AS ".$key; + } + else if ($key === "ftype") { + $plSelect[] = "'playlist'::varchar AS ".$key; $fileSelect[] = $key; - } else if ($key === "artist_name") { + } + else if ($key === "artist_name") { $plSelect[] = "login AS ".$key; $fileSelect[] = $key; - } else if ($key === "length") { + } + else if ($key === "length") { $plSelect[] = $key; $fileSelect[] = $key."::interval"; - } else if ($key === "year") { + } + else if ($key === "year") { $plSelect[] = "CAST(utime AS varchar) AS ".$key; $fileSelect[] = $key; - } else if ($key === "utime") { + } + else if ($key === "utime") { $plSelect[] = $key; $fileSelect[] = $key; - } else if ($key === "mtime") { + } + else if ($key === "mtime") { $plSelect[] = $key; $fileSelect[] = $key; - } else { - $plSelect[] = "NULL AS ".$key; + } + //need to cast certain data as ints for the union to search on. + else if (in_array($key, array("track_number"))){ + $plSelect[] = "NULL::int AS ".$key; + $fileSelect[] = $key; + } + else { + $plSelect[] = "NULL::text AS ".$key; $fileSelect[] = $key; } } @@ -624,13 +636,28 @@ class Application_Model_StoredFile { $plSelect = "SELECT ". join(",", $plSelect); $fileSelect = "SELECT ". join(",", $fileSelect); - $fromTable = " (({$plSelect} FROM cc_playlist AS PL - LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id)) - UNION - ({$fileSelect} FROM ".$CC_CONFIG["filesTable"]." AS FILES WHERE file_exists = 'TRUE')) AS RESULTS"; + $type = intval($datatables["type"]); + $plTable = "({$plSelect} FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))"; + $fileTable = "({$fileSelect} FROM cc_files AS FILES WHERE file_exists = 'TRUE')"; + $unionTable = "({$plTable} UNION {$fileTable} ) AS RESULTS"; - $results = Application_Model_StoredFile::searchFiles($displayColumns, $fromTable, $datatables); + //choose which table we need to select data from. + switch ($type) { + case 0: + $fromTable = $unionTable; + break; + case 1: + $fromTable = $fileTable." AS File"; //need an alias for the table if it's standalone. + break; + case 2: + $fromTable = $plTable." AS Playlist"; //need an alias for the table if it's standalone. + break; + default: + $fromTable = $unionTable; + } + + $results = Application_Model_StoredFile::searchFiles($displayColumns, $fromTable, $datatables); foreach ($results['aaData'] as &$row) { @@ -671,22 +698,12 @@ class Application_Model_StoredFile { $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME); $where = array(); - /* - $columnsDisplayed = array(); - for ($i = 0; $i < $data["iColumns"]; $i++) { - if (in_array($data["mDataProp_".$i], $displayColumns)) { - $columnsDisplayed[] = $data["mDataProp_".$i]; - } - } - */ - if ($data["sSearch"] !== "") { $searchTerms = explode(" ", $data["sSearch"]); } - $selectorCount = "SELECT COUNT(*)"; - //$selectorRows = "SELECT ". join(",", $displayColumns); - $selectorRows = "SELECT *"; + $selectorCount = "SELECT COUNT(*) "; + $selectorRows = "SELECT ".join(",", $displayColumns)." "; $sql = $selectorCount." FROM ".$fromTable; $sqlTotalRows = $sql; diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index 7a322863d..2ac7289e3 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -559,6 +559,12 @@ dl.inline-list dd { float: left; margin: 0 3px 0 -2px; } +.dataTables_type { + float:right; + margin:0 8px 0 0; + +} + .dataTables_length { float:right; margin:0 8px 0 0; @@ -574,7 +580,7 @@ dl.inline-list dd { margin:8px 0 0 8px; } .dataTables_filter .auto-search { - width:60%; + width:55%; } .dataTables_processing { font-size:11px; diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index ed2a50c20..275c915ec 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -306,7 +306,15 @@ $(document).ready(function() { "sAjaxSource": "/Library/contents", "fnServerData": function ( sSource, aoData, fnCallback ) { + var type; + aoData.push( { name: "format", value: "json"} ); + + //push whether to search files/playlists or all. + type = $("#library_display_type").find("select").val(); + type = (type === undefined) ? 0 : type; + aoData.push( { name: "type", value: type} ); + $.ajax( { "dataType": 'json', "type": "GET", @@ -376,7 +384,7 @@ $(document).ready(function() { }, // R = ColReorder, C = ColVis, T = TableTools - "sDom": 'Rlfr<"H"T<"library_toolbar"C>>t<"F"ip>', + "sDom": 'Rl<"#library_display_type">fr<"H"T<"library_toolbar"C>>t<"F"ip>', "oTableTools": { "sRowSelect": "multi", @@ -418,6 +426,18 @@ $(document).ready(function() { oTable.fnSetFilteringDelay(350); AIRTIME.library.events.setupLibraryToolbar(oTable); + + $("#library_display_type") + .addClass("dataTables_type") + .append('