CC-3174 : showbuilder
fixing up library table to include all interesting columns if a user would like to choose to see them. query is done with propel.
This commit is contained in:
parent
2ac4940fd5
commit
d4c7b832c9
|
@ -348,7 +348,9 @@ class PreferenceController extends Zend_Controller_Action
|
|||
public function getLibraryDatatableAction() {
|
||||
|
||||
$data = Application_Model_Preference::GetValue("library_datatable", true);
|
||||
$this->view->settings = unserialize($data);
|
||||
if ($data != "") {
|
||||
$this->view->settings = unserialize($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function setTimelineDatatableAction() {
|
||||
|
@ -363,7 +365,9 @@ class PreferenceController extends Zend_Controller_Action
|
|||
public function getTimelineDatatableAction() {
|
||||
|
||||
$data = Application_Model_Preference::GetValue("timeline_datatable", true);
|
||||
$this->view->settings = unserialize($data);
|
||||
if ($data != "") {
|
||||
$this->view->settings = unserialize($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -582,46 +582,60 @@ class Application_Model_StoredFile {
|
|||
public static function searchFilesForPlaylistBuilder($datatables) {
|
||||
global $CC_CONFIG;
|
||||
|
||||
$displayData = array("track_title", "artist_name", "album_title", "genre", "length",
|
||||
"year", "utime", "mtime", "ftype", "track_number");
|
||||
$displayColumns = array("id", "track_title", "artist_name", "album_title", "genre", "length",
|
||||
"year", "utime", "mtime", "ftype", "track_number", "mood", "bpm", "composer", "info_url",
|
||||
"bit_rate", "sample_rate", "isrc_number", "encoded_by", "label", "copyright", "mime", "language"
|
||||
);
|
||||
|
||||
$plSelect = "SELECT ";
|
||||
$fileSelect = "SELECT ";
|
||||
foreach ($displayData as $key) {
|
||||
$plSelect = array();
|
||||
$fileSelect = array();
|
||||
foreach ($displayColumns as $key) {
|
||||
|
||||
if ($key === "track_title") {
|
||||
$plSelect .= "name AS ".$key.", ";
|
||||
$fileSelect .= $key.", ";
|
||||
if ($key === "id") {
|
||||
$plSelect[] = "PL.id AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
} else if ($key === "track_title") {
|
||||
$plSelect[] = "name AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
} else if ($key === "ftype") {
|
||||
$plSelect .= "'playlist' AS ".$key.", ";
|
||||
$fileSelect .= $key.", ";
|
||||
$plSelect[] = "'playlist' AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
} else if ($key === "artist_name") {
|
||||
$plSelect .= "login AS ".$key.", ";
|
||||
$fileSelect .= $key.", ";
|
||||
$plSelect[] = "login AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
} else if ($key === "length") {
|
||||
$plSelect .= $key.", ";
|
||||
$fileSelect .= $key."::interval, ";
|
||||
$plSelect[] = $key;
|
||||
$fileSelect[] = $key."::interval";
|
||||
} else if ($key === "year") {
|
||||
$plSelect .= "CAST(utime AS varchar) AS ".$key.", ";
|
||||
$fileSelect .= $key.", ";
|
||||
$plSelect[] = "CAST(utime AS varchar) AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
} else if ($key === "utime") {
|
||||
$plSelect .= $key.", ";
|
||||
$fileSelect .= $key.", ";
|
||||
$plSelect[] = $key;
|
||||
$fileSelect[] = $key;
|
||||
} else if ($key === "mtime") {
|
||||
$plSelect .= $key.", ";
|
||||
$fileSelect .= $key.", ";
|
||||
$plSelect[] = $key;
|
||||
$fileSelect[] = $key;
|
||||
} else {
|
||||
$plSelect .= "NULL AS ".$key.", ";
|
||||
$fileSelect .= $key.", ";
|
||||
$plSelect[] = "NULL AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$fromTable = " ((".$plSelect."PL.id
|
||||
FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))
|
||||
UNION
|
||||
(".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES WHERE file_exists = 'TRUE')) AS RESULTS";
|
||||
$plSelect = "SELECT ". join(",", $plSelect);
|
||||
$fileSelect = "SELECT ". join(",", $fileSelect);
|
||||
|
||||
$results = Application_Model_StoredFile::searchFiles($fromTable, $datatables);
|
||||
$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";
|
||||
|
||||
//TODO see Allan's reply about iDataSort working for serverside processing.
|
||||
//hack to sort on ftype when image "type" col selected for sorting.
|
||||
if ($datatables["iSortCol_0"] == 1) {
|
||||
$datatables["iSortCol_0"] = 2;
|
||||
}
|
||||
|
||||
$results = Application_Model_StoredFile::searchFiles($displayColumns, $fromTable, $datatables);
|
||||
|
||||
|
||||
foreach ($results['aaData'] as &$row) {
|
||||
|
@ -657,46 +671,45 @@ class Application_Model_StoredFile {
|
|||
return $results;
|
||||
}
|
||||
|
||||
public static function searchFiles($fromTable, $data)
|
||||
public static function searchFiles($displayColumns, $fromTable, $data)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
|
||||
$where = array();
|
||||
|
||||
$columnsDisplayed = explode(",", $data["sColumns"]);
|
||||
/*
|
||||
$columnsDisplayed = array();
|
||||
for ($i = 0; $i < $data["iColumns"]; $i++) {
|
||||
if (in_array($data["mDataProp_".$i], $displayColumns)) {
|
||||
$columnsDisplayed[] = $data["mDataProp_".$i];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if($data["sSearch"] !== "")
|
||||
if ($data["sSearch"] !== "") {
|
||||
$searchTerms = explode(" ", $data["sSearch"]);
|
||||
}
|
||||
|
||||
$selectorCount = "SELECT COUNT(*)";
|
||||
foreach( $columnsDisplayed as $key=>$col){
|
||||
if($col == ''){
|
||||
unset($columnsDisplayed[$key]);
|
||||
}
|
||||
}
|
||||
//$selectorRows = "SELECT " . join(',', $columnsDisplayed );
|
||||
$selectorRows = "SELECT * ";
|
||||
//$selectorRows = "SELECT ". join(",", $displayColumns);
|
||||
$selectorRows = "SELECT *";
|
||||
|
||||
$sql = $selectorCount." FROM ".$fromTable;
|
||||
$totalRows = $CC_DBC->getOne($sql);
|
||||
$sqlTotalRows = $sql;
|
||||
|
||||
// Where clause
|
||||
if(isset($data["optWhere"])) {
|
||||
$where[] = join(" AND ", $data["optWhere"]);
|
||||
}
|
||||
|
||||
if(isset($searchTerms)) {
|
||||
if (isset($searchTerms)) {
|
||||
$searchCols = array();
|
||||
for($i=0; $i<$data["iColumns"]; $i++) {
|
||||
if($data["bSearchable_".$i] == "true") {
|
||||
$searchCols[] = $columnsDisplayed[$i];
|
||||
for ($i = 0; $i < $data["iColumns"]; $i++) {
|
||||
if ($data["bSearchable_".$i] == "true") {
|
||||
$searchCols[] = $data["mDataProp_{$i}"];
|
||||
}
|
||||
}
|
||||
|
||||
$outerCond = array();
|
||||
|
||||
foreach($searchTerms as $term) {
|
||||
foreach ($searchTerms as $term) {
|
||||
$innerCond = array();
|
||||
|
||||
foreach($searchCols as $col) {
|
||||
foreach ($searchCols as $col) {
|
||||
$escapedTerm = pg_escape_string($term);
|
||||
$innerCond[] = "{$col}::text ILIKE '%{$escapedTerm}%'";
|
||||
}
|
||||
|
@ -708,32 +721,48 @@ class Application_Model_StoredFile {
|
|||
|
||||
// Order By clause
|
||||
$orderby = array();
|
||||
for($i=0; $i<$data["iSortingCols"]; $i++){
|
||||
$orderby[] = $columnsDisplayed[$data["iSortCol_".$i]]." ".$data["sSortDir_".$i];
|
||||
for ($i = 0; $i < $data["iSortingCols"]; $i++){
|
||||
$num = $data["iSortCol_".$i];
|
||||
$orderby[] = $data["mDataProp_{$num}"]." ".$data["sSortDir_".$i];
|
||||
}
|
||||
$orderby[] = "id";
|
||||
$orderby = join("," , $orderby);
|
||||
// End Order By clause
|
||||
|
||||
if(isset($where)) {
|
||||
if (count($where) > 0) {
|
||||
$where = join(" AND ", $where);
|
||||
$sql = $selectorCount." FROM ".$fromTable." WHERE ".$where;
|
||||
$totalDisplayRows = $CC_DBC->getOne($sql);
|
||||
$sqlTotalDisplayRows = $sql;
|
||||
|
||||
$sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
||||
}
|
||||
else {
|
||||
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
||||
}
|
||||
|
||||
try {
|
||||
$r = $con->query($sqlTotalRows);
|
||||
$totalRows = $r->fetchColumn(0);
|
||||
|
||||
if (isset($sqlTotalDisplayRows)) {
|
||||
$r = $con->query($sqlTotalDisplayRows);
|
||||
$totalDisplayRows = $r->fetchColumn(0);
|
||||
}
|
||||
else {
|
||||
$totalDisplayRows = $totalRows;
|
||||
}
|
||||
|
||||
$r = $con->query($sql);
|
||||
$r->setFetchMode(PDO::FETCH_ASSOC);
|
||||
$results = $r->fetchAll();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::log($e->getMessage());
|
||||
}
|
||||
|
||||
//display sql executed in airtime log for testing
|
||||
Logging::log($sql);
|
||||
|
||||
$results = $CC_DBC->getAll($sql);
|
||||
|
||||
if(!isset($totalDisplayRows)) {
|
||||
$totalDisplayRows = $totalRows;
|
||||
}
|
||||
|
||||
return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results);
|
||||
}
|
||||
|
||||
|
|
|
@ -240,6 +240,7 @@ class Application_Model_User {
|
|||
|
||||
public static function getUsersDataTablesInfo($datatables_post) {
|
||||
|
||||
$displayColumns = array("id", "login", "first_name", "last_name", "type");
|
||||
$fromTable = "cc_subjs";
|
||||
|
||||
// get current user
|
||||
|
@ -250,7 +251,7 @@ class Application_Model_User {
|
|||
$username = $auth->getIdentity()->login;
|
||||
}
|
||||
|
||||
$res = Application_Model_StoredFile::searchFiles($fromTable, $datatables_post);
|
||||
$res = Application_Model_StoredFile::searchFiles($displayColumns, $fromTable, $datatables_post);
|
||||
|
||||
// mark record which is for the current user
|
||||
foreach($res['aaData'] as &$record){
|
||||
|
|
|
@ -219,24 +219,36 @@ $(document).ready(function() {
|
|||
oTable = $('#library_display').dataTable( {
|
||||
|
||||
"aoColumns": [
|
||||
/* Checkbox */ {"sTitle": "<input type='checkbox' name='pl_cb_all'>", "bSortable": false, "bSearchable": false, "mDataProp": "checkbox", "sWidth": "25px", "sClass": "library_checkbox"},
|
||||
/* Type */ {"sName": "ftype", "bSearchable": false, "mDataProp": "image", "sWidth": "25px", "sClass": "library_type"},
|
||||
/* Title */ {"sTitle": "Title", "sName": "track_title", "mDataProp": "track_title", "sClass": "library_title"},
|
||||
/* Creator */ {"sTitle": "Creator", "sName": "artist_name", "mDataProp": "artist_name", "sClass": "library_creator"},
|
||||
/* Album */ {"sTitle": "Album", "sName": "album_title", "mDataProp": "album_title", "sClass": "library_album"},
|
||||
/* Genre */ {"sTitle": "Genre", "sName": "genre", "mDataProp": "genre", "sClass": "library_genre"},
|
||||
/* Year */ {"sTitle": "Year", "sName": "year", "mDataProp": "year", "sClass": "library_year"},
|
||||
/* Length */ {"sTitle": "Length", "sName": "length", "mDataProp": "length", "sClass": "library_length"},
|
||||
/* Upload Time */ {"sTitle": "Uploaded", "sName": "utime", "mDataProp": "utime", "sClass": "library_upload_time"},
|
||||
/* Last Modified */ {"sTitle": "Last Modified", "sName": "mtime", "bVisible": false, "mDataProp": "mtime", "sClass": "library_modified_time"},
|
||||
/* Track Number */ {"sTitle": "Track", "sName": "track_number", "bSearchable": false, "bVisible": false, "mDataProp": "track_number", "sClass": "library_track"}
|
||||
/* Checkbox */ {"sTitle": "<input type='checkbox' name='pl_cb_all'>", "mDataProp": "checkbox", "bSortable": false, "bSearchable": false, "sWidth": "25px", "sClass": "library_checkbox"},
|
||||
/* Type */ {"sTitle": "", "mDataProp": "image", "bSearchable": false, "sWidth": "25px", "sClass": "library_type", "iDataSort": 2},
|
||||
/* ftype */ {"sTitle": "", "mDataProp": "ftype", "bSearchable": false, "bVisible": false},
|
||||
/* Title */ {"sTitle": "Title", "mDataProp": "track_title", "sClass": "library_title"},
|
||||
/* Creator */ {"sTitle": "Creator", "mDataProp": "artist_name", "sClass": "library_creator"},
|
||||
/* Album */ {"sTitle": "Album", "mDataProp": "album_title", "sClass": "library_album"},
|
||||
/* Genre */ {"sTitle": "Genre", "mDataProp": "genre", "sClass": "library_genre"},
|
||||
/* Year */ {"sTitle": "Year", "mDataProp": "year", "sClass": "library_year"},
|
||||
/* Length */ {"sTitle": "Length", "mDataProp": "length", "sClass": "library_length"},
|
||||
/* Upload Time */ {"sTitle": "Uploaded", "mDataProp": "utime", "sClass": "library_upload_time"},
|
||||
/* Last Modified */ {"sTitle": "Last Modified", "mDataProp": "mtime", "bVisible": false, "sClass": "library_modified_time"},
|
||||
/* Track Number */ {"sTitle": "Track", "mDataProp": "track_number", "bSearchable": false, "bVisible": false, "sClass": "library_track"},
|
||||
/* Mood */ {"sTitle": "Mood", "mDataProp": "mood", "bSearchable": false, "bVisible": false, "sClass": "library_mood"},
|
||||
/* BPM */ {"sTitle": "BPM", "mDataProp": "bpm", "bSearchable": false, "bVisible": false, "sClass": "library_bpm"},
|
||||
/* Composer */ {"sTitle": "Composer", "mDataProp": "composer", "bSearchable": false, "bVisible": false, "sClass": "library_composer"},
|
||||
/* Website */ {"sTitle": "Website", "mDataProp": "info_url", "bSearchable": false, "bVisible": false, "sClass": "library_url"},
|
||||
/* Bit Rate */ {"sTitle": "Bit Rate", "mDataProp": "bit_rate", "bSearchable": false, "bVisible": false, "sClass": "library_bitrate"},
|
||||
/* Sameple Rate */ {"sTitle": "Sample Rate", "mDataProp": "sample_rate", "bSearchable": false, "bVisible": false, "sClass": "library_sr"},
|
||||
/* ISRC Number */ {"sTitle": "ISRC", "mDataProp": "isrc_number", "bSearchable": false, "bVisible": false, "sClass": "library_isrc"},
|
||||
/* Encoded */ {"sTitle": "Encoded", "mDataProp": "encoded_by", "bSearchable": false, "bVisible": false, "sClass": "library_encoded"},
|
||||
/* Label */ {"sTitle": "Label", "mDataProp": "label", "bSearchable": false, "bVisible": false, "sClass": "library_label"},
|
||||
/* Copyright */ {"sTitle": "Copyright", "mDataProp": "copyright", "bSearchable": false, "bVisible": false, "sClass": "library_copyright"},
|
||||
/* Mime */ {"sTitle": "Mime", "mDataProp": "mime", "bSearchable": false, "bVisible": false, "sClass": "library_mime"},
|
||||
/* Language */ {"sTitle": "Language", "mDataProp": "language", "bSearchable": false, "bVisible": false, "sClass": "library_language"}
|
||||
],
|
||||
|
||||
"bProcessing": true,
|
||||
"bServerSide": true,
|
||||
|
||||
"bStateSave": true,
|
||||
|
||||
"fnStateSaveParams": function (oSettings, oData) {
|
||||
//remove oData components we don't want to save.
|
||||
delete oData.oSearch;
|
||||
|
@ -356,7 +368,7 @@ $(document).ready(function() {
|
|||
$(nHead).find("input[type=checkbox]").attr("checked", false);
|
||||
},
|
||||
|
||||
"aaSorting": [[2,'asc']],
|
||||
"aaSorting": [[3, 'asc']],
|
||||
"sPaginationType": "full_numbers",
|
||||
"bJQueryUI": true,
|
||||
"bAutoWidth": false,
|
||||
|
@ -395,13 +407,12 @@ $(document).ready(function() {
|
|||
"oColVis": {
|
||||
"buttonText": "Show/Hide Columns",
|
||||
"sAlign": "right",
|
||||
"aiExclude": [0, 1],
|
||||
"aiExclude": [0, 1, 2],
|
||||
"sSize": "css"
|
||||
},
|
||||
|
||||
"oColReorder": {
|
||||
"iFixedColumns": 2,
|
||||
"aiOrder": [ 0,1,2,3,4,5,6,7,8,9,10 ]
|
||||
"iFixedColumns": 2
|
||||
}
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue