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,8 +348,10 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
public function getLibraryDatatableAction() {
|
public function getLibraryDatatableAction() {
|
||||||
|
|
||||||
$data = Application_Model_Preference::GetValue("library_datatable", true);
|
$data = Application_Model_Preference::GetValue("library_datatable", true);
|
||||||
|
if ($data != "") {
|
||||||
$this->view->settings = unserialize($data);
|
$this->view->settings = unserialize($data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function setTimelineDatatableAction() {
|
public function setTimelineDatatableAction() {
|
||||||
|
|
||||||
|
@ -363,9 +365,11 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
public function getTimelineDatatableAction() {
|
public function getTimelineDatatableAction() {
|
||||||
|
|
||||||
$data = Application_Model_Preference::GetValue("timeline_datatable", true);
|
$data = Application_Model_Preference::GetValue("timeline_datatable", true);
|
||||||
|
if ($data != "") {
|
||||||
$this->view->settings = unserialize($data);
|
$this->view->settings = unserialize($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -582,46 +582,60 @@ class Application_Model_StoredFile {
|
||||||
public static function searchFilesForPlaylistBuilder($datatables) {
|
public static function searchFilesForPlaylistBuilder($datatables) {
|
||||||
global $CC_CONFIG;
|
global $CC_CONFIG;
|
||||||
|
|
||||||
$displayData = array("track_title", "artist_name", "album_title", "genre", "length",
|
$displayColumns = array("id", "track_title", "artist_name", "album_title", "genre", "length",
|
||||||
"year", "utime", "mtime", "ftype", "track_number");
|
"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 ";
|
$plSelect = array();
|
||||||
$fileSelect = "SELECT ";
|
$fileSelect = array();
|
||||||
foreach ($displayData as $key) {
|
foreach ($displayColumns as $key) {
|
||||||
|
|
||||||
if ($key === "track_title") {
|
if ($key === "id") {
|
||||||
$plSelect .= "name AS ".$key.", ";
|
$plSelect[] = "PL.id AS ".$key;
|
||||||
$fileSelect .= $key.", ";
|
$fileSelect[] = $key;
|
||||||
|
} else if ($key === "track_title") {
|
||||||
|
$plSelect[] = "name AS ".$key;
|
||||||
|
$fileSelect[] = $key;
|
||||||
} else if ($key === "ftype") {
|
} else if ($key === "ftype") {
|
||||||
$plSelect .= "'playlist' AS ".$key.", ";
|
$plSelect[] = "'playlist' AS ".$key;
|
||||||
$fileSelect .= $key.", ";
|
$fileSelect[] = $key;
|
||||||
} else if ($key === "artist_name") {
|
} else if ($key === "artist_name") {
|
||||||
$plSelect .= "login AS ".$key.", ";
|
$plSelect[] = "login AS ".$key;
|
||||||
$fileSelect .= $key.", ";
|
$fileSelect[] = $key;
|
||||||
} else if ($key === "length") {
|
} else if ($key === "length") {
|
||||||
$plSelect .= $key.", ";
|
$plSelect[] = $key;
|
||||||
$fileSelect .= $key."::interval, ";
|
$fileSelect[] = $key."::interval";
|
||||||
} else if ($key === "year") {
|
} else if ($key === "year") {
|
||||||
$plSelect .= "CAST(utime AS varchar) AS ".$key.", ";
|
$plSelect[] = "CAST(utime AS varchar) AS ".$key;
|
||||||
$fileSelect .= $key.", ";
|
$fileSelect[] = $key;
|
||||||
} else if ($key === "utime") {
|
} else if ($key === "utime") {
|
||||||
$plSelect .= $key.", ";
|
$plSelect[] = $key;
|
||||||
$fileSelect .= $key.", ";
|
$fileSelect[] = $key;
|
||||||
} else if ($key === "mtime") {
|
} else if ($key === "mtime") {
|
||||||
$plSelect .= $key.", ";
|
$plSelect[] = $key;
|
||||||
$fileSelect .= $key.", ";
|
$fileSelect[] = $key;
|
||||||
} else {
|
} else {
|
||||||
$plSelect .= "NULL AS ".$key.", ";
|
$plSelect[] = "NULL AS ".$key;
|
||||||
$fileSelect .= $key.", ";
|
$fileSelect[] = $key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$fromTable = " ((".$plSelect."PL.id
|
$plSelect = "SELECT ". join(",", $plSelect);
|
||||||
FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))
|
$fileSelect = "SELECT ". join(",", $fileSelect);
|
||||||
|
|
||||||
|
$fromTable = " (({$plSelect} FROM cc_playlist AS PL
|
||||||
|
LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))
|
||||||
UNION
|
UNION
|
||||||
(".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES WHERE file_exists = 'TRUE')) AS RESULTS";
|
({$fileSelect} FROM ".$CC_CONFIG["filesTable"]." AS FILES WHERE file_exists = 'TRUE')) AS RESULTS";
|
||||||
|
|
||||||
$results = Application_Model_StoredFile::searchFiles($fromTable, $datatables);
|
//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) {
|
foreach ($results['aaData'] as &$row) {
|
||||||
|
@ -657,37 +671,36 @@ class Application_Model_StoredFile {
|
||||||
return $results;
|
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"]);
|
$searchTerms = explode(" ", $data["sSearch"]);
|
||||||
|
}
|
||||||
|
|
||||||
$selectorCount = "SELECT COUNT(*)";
|
$selectorCount = "SELECT COUNT(*)";
|
||||||
foreach( $columnsDisplayed as $key=>$col){
|
//$selectorRows = "SELECT ". join(",", $displayColumns);
|
||||||
if($col == ''){
|
|
||||||
unset($columnsDisplayed[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//$selectorRows = "SELECT " . join(',', $columnsDisplayed );
|
|
||||||
$selectorRows = "SELECT *";
|
$selectorRows = "SELECT *";
|
||||||
|
|
||||||
$sql = $selectorCount." FROM ".$fromTable;
|
$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();
|
$searchCols = array();
|
||||||
for ($i = 0; $i < $data["iColumns"]; $i++) {
|
for ($i = 0; $i < $data["iColumns"]; $i++) {
|
||||||
if ($data["bSearchable_".$i] == "true") {
|
if ($data["bSearchable_".$i] == "true") {
|
||||||
$searchCols[] = $columnsDisplayed[$i];
|
$searchCols[] = $data["mDataProp_{$i}"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,31 +722,47 @@ class Application_Model_StoredFile {
|
||||||
// Order By clause
|
// Order By clause
|
||||||
$orderby = array();
|
$orderby = array();
|
||||||
for ($i = 0; $i < $data["iSortingCols"]; $i++){
|
for ($i = 0; $i < $data["iSortingCols"]; $i++){
|
||||||
$orderby[] = $columnsDisplayed[$data["iSortCol_".$i]]." ".$data["sSortDir_".$i];
|
$num = $data["iSortCol_".$i];
|
||||||
|
$orderby[] = $data["mDataProp_{$num}"]." ".$data["sSortDir_".$i];
|
||||||
}
|
}
|
||||||
$orderby[] = "id";
|
$orderby[] = "id";
|
||||||
$orderby = join("," , $orderby);
|
$orderby = join("," , $orderby);
|
||||||
// End Order By clause
|
// End Order By clause
|
||||||
|
|
||||||
if(isset($where)) {
|
if (count($where) > 0) {
|
||||||
$where = join(" AND ", $where);
|
$where = join(" AND ", $where);
|
||||||
$sql = $selectorCount." FROM ".$fromTable." WHERE ".$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"];
|
$sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
||||||
}
|
}
|
||||||
|
|
||||||
//display sql executed in airtime log for testing
|
try {
|
||||||
Logging::log($sql);
|
$r = $con->query($sqlTotalRows);
|
||||||
|
$totalRows = $r->fetchColumn(0);
|
||||||
|
|
||||||
$results = $CC_DBC->getAll($sql);
|
if (isset($sqlTotalDisplayRows)) {
|
||||||
|
$r = $con->query($sqlTotalDisplayRows);
|
||||||
if(!isset($totalDisplayRows)) {
|
$totalDisplayRows = $r->fetchColumn(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
$totalDisplayRows = $totalRows;
|
$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);
|
||||||
|
|
||||||
return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results);
|
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) {
|
public static function getUsersDataTablesInfo($datatables_post) {
|
||||||
|
|
||||||
|
$displayColumns = array("id", "login", "first_name", "last_name", "type");
|
||||||
$fromTable = "cc_subjs";
|
$fromTable = "cc_subjs";
|
||||||
|
|
||||||
// get current user
|
// get current user
|
||||||
|
@ -250,7 +251,7 @@ class Application_Model_User {
|
||||||
$username = $auth->getIdentity()->login;
|
$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
|
// mark record which is for the current user
|
||||||
foreach($res['aaData'] as &$record){
|
foreach($res['aaData'] as &$record){
|
||||||
|
|
|
@ -219,24 +219,36 @@ $(document).ready(function() {
|
||||||
oTable = $('#library_display').dataTable( {
|
oTable = $('#library_display').dataTable( {
|
||||||
|
|
||||||
"aoColumns": [
|
"aoColumns": [
|
||||||
/* Checkbox */ {"sTitle": "<input type='checkbox' name='pl_cb_all'>", "bSortable": false, "bSearchable": false, "mDataProp": "checkbox", "sWidth": "25px", "sClass": "library_checkbox"},
|
/* Checkbox */ {"sTitle": "<input type='checkbox' name='pl_cb_all'>", "mDataProp": "checkbox", "bSortable": false, "bSearchable": false, "sWidth": "25px", "sClass": "library_checkbox"},
|
||||||
/* Type */ {"sName": "ftype", "bSearchable": false, "mDataProp": "image", "sWidth": "25px", "sClass": "library_type"},
|
/* Type */ {"sTitle": "", "mDataProp": "image", "bSearchable": false, "sWidth": "25px", "sClass": "library_type", "iDataSort": 2},
|
||||||
/* Title */ {"sTitle": "Title", "sName": "track_title", "mDataProp": "track_title", "sClass": "library_title"},
|
/* ftype */ {"sTitle": "", "mDataProp": "ftype", "bSearchable": false, "bVisible": false},
|
||||||
/* Creator */ {"sTitle": "Creator", "sName": "artist_name", "mDataProp": "artist_name", "sClass": "library_creator"},
|
/* Title */ {"sTitle": "Title", "mDataProp": "track_title", "sClass": "library_title"},
|
||||||
/* Album */ {"sTitle": "Album", "sName": "album_title", "mDataProp": "album_title", "sClass": "library_album"},
|
/* Creator */ {"sTitle": "Creator", "mDataProp": "artist_name", "sClass": "library_creator"},
|
||||||
/* Genre */ {"sTitle": "Genre", "sName": "genre", "mDataProp": "genre", "sClass": "library_genre"},
|
/* Album */ {"sTitle": "Album", "mDataProp": "album_title", "sClass": "library_album"},
|
||||||
/* Year */ {"sTitle": "Year", "sName": "year", "mDataProp": "year", "sClass": "library_year"},
|
/* Genre */ {"sTitle": "Genre", "mDataProp": "genre", "sClass": "library_genre"},
|
||||||
/* Length */ {"sTitle": "Length", "sName": "length", "mDataProp": "length", "sClass": "library_length"},
|
/* Year */ {"sTitle": "Year", "mDataProp": "year", "sClass": "library_year"},
|
||||||
/* Upload Time */ {"sTitle": "Uploaded", "sName": "utime", "mDataProp": "utime", "sClass": "library_upload_time"},
|
/* Length */ {"sTitle": "Length", "mDataProp": "length", "sClass": "library_length"},
|
||||||
/* Last Modified */ {"sTitle": "Last Modified", "sName": "mtime", "bVisible": false, "mDataProp": "mtime", "sClass": "library_modified_time"},
|
/* Upload Time */ {"sTitle": "Uploaded", "mDataProp": "utime", "sClass": "library_upload_time"},
|
||||||
/* Track Number */ {"sTitle": "Track", "sName": "track_number", "bSearchable": false, "bVisible": false, "mDataProp": "track_number", "sClass": "library_track"}
|
/* 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,
|
"bProcessing": true,
|
||||||
"bServerSide": true,
|
"bServerSide": true,
|
||||||
|
|
||||||
"bStateSave": true,
|
"bStateSave": true,
|
||||||
|
|
||||||
"fnStateSaveParams": function (oSettings, oData) {
|
"fnStateSaveParams": function (oSettings, oData) {
|
||||||
//remove oData components we don't want to save.
|
//remove oData components we don't want to save.
|
||||||
delete oData.oSearch;
|
delete oData.oSearch;
|
||||||
|
@ -356,7 +368,7 @@ $(document).ready(function() {
|
||||||
$(nHead).find("input[type=checkbox]").attr("checked", false);
|
$(nHead).find("input[type=checkbox]").attr("checked", false);
|
||||||
},
|
},
|
||||||
|
|
||||||
"aaSorting": [[2,'asc']],
|
"aaSorting": [[3, 'asc']],
|
||||||
"sPaginationType": "full_numbers",
|
"sPaginationType": "full_numbers",
|
||||||
"bJQueryUI": true,
|
"bJQueryUI": true,
|
||||||
"bAutoWidth": false,
|
"bAutoWidth": false,
|
||||||
|
@ -395,13 +407,12 @@ $(document).ready(function() {
|
||||||
"oColVis": {
|
"oColVis": {
|
||||||
"buttonText": "Show/Hide Columns",
|
"buttonText": "Show/Hide Columns",
|
||||||
"sAlign": "right",
|
"sAlign": "right",
|
||||||
"aiExclude": [0, 1],
|
"aiExclude": [0, 1, 2],
|
||||||
"sSize": "css"
|
"sSize": "css"
|
||||||
},
|
},
|
||||||
|
|
||||||
"oColReorder": {
|
"oColReorder": {
|
||||||
"iFixedColumns": 2,
|
"iFixedColumns": 2
|
||||||
"aiOrder": [ 0,1,2,3,4,5,6,7,8,9,10 ]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue