CC-3174 : showbuilder

changing queries for datatables to use the Datatables model class.
This commit is contained in:
Naomi Aro 2012-03-12 15:32:24 +01:00
parent 41a46b3144
commit 3145c24ba2
4 changed files with 22 additions and 98 deletions

View File

@ -13,7 +13,7 @@ class LibraryController extends Zend_Controller_Action
public function init()
{
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('contents', 'json')
$ajaxContext->addActionContext('contents-feed', 'json')
->addActionContext('delete', 'json')
->addActionContext('delete-group', 'json')
->addActionContext('context-menu', 'json')
@ -194,13 +194,13 @@ class LibraryController extends Zend_Controller_Action
}
}
public function contentsAction()
public function contentsFeedAction()
{
$params = $this->getRequest()->getParams();
$datatables = Application_Model_StoredFile::searchFilesForPlaylistBuilder($params);
$r = Application_Model_StoredFile::searchLibraryFiles($params);
//TODO move this to the datatables row callback.
foreach ($datatables["aaData"] as &$data) {
foreach ($r["aaData"] as &$data) {
if ($data['ftype'] == 'audioclip'){
$file = Application_Model_StoredFile::Recall($data['id']);
@ -217,8 +217,11 @@ class LibraryController extends Zend_Controller_Action
}
}
}
die(json_encode($datatables));
$this->view->sEcho = $r["sEcho"];
$this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
$this->view->iTotalRecords = $r["iTotalRecords"];
$this->view->files = $r["aaData"];
}
public function editFileMdAction()

View File

@ -557,7 +557,9 @@ Logging::log("getting media! - 2");
return $res;
}
public static function searchFilesForPlaylistBuilder($datatables) {
public static function searchLibraryFiles($datatables) {
$con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
$displayColumns = array("id", "track_title", "artist_name", "album_title", "genre", "length",
"year", "utime", "mtime", "ftype", "track_number", "mood", "bpm", "composer", "info_url",
@ -629,8 +631,8 @@ Logging::log("getting media! - 2");
default:
$fromTable = $unionTable;
}
$results = Application_Model_StoredFile::searchFiles($displayColumns, $fromTable, $datatables);
$results = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables);
//Used by the audio preview functionality in the library.
foreach ($results['aaData'] as &$row) {
@ -670,91 +672,6 @@ Logging::log("getting media! - 2");
return $results;
}
public static function searchFiles($displayColumns, $fromTable, $data)
{
$con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
$where = array();
if ($data["sSearch"] !== "") {
$searchTerms = explode(" ", $data["sSearch"]);
}
$selectorCount = "SELECT COUNT(*) ";
$selectorRows = "SELECT ".join(",", $displayColumns)." ";
$sql = $selectorCount." FROM ".$fromTable;
$sqlTotalRows = $sql;
if (isset($searchTerms)) {
$searchCols = array();
for ($i = 0; $i < $data["iColumns"]; $i++) {
if ($data["bSearchable_".$i] == "true") {
$searchCols[] = $data["mDataProp_{$i}"];
}
}
$outerCond = array();
foreach ($searchTerms as $term) {
$innerCond = array();
foreach ($searchCols as $col) {
$escapedTerm = pg_escape_string($term);
$innerCond[] = "{$col}::text ILIKE '%{$escapedTerm}%'";
}
$outerCond[] = "(".join(" OR ", $innerCond).")";
}
$where[] = "(".join(" AND ", $outerCond).")";
}
// End Where clause
// Order By clause
$orderby = array();
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 (count($where) > 0) {
$where = join(" AND ", $where);
$sql = $selectorCount." FROM ".$fromTable." WHERE ".$where;
$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);
return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results);
}
public static function uploadFile($p_targetDir)
{
// HTTP headers for no cache etc

View File

@ -239,7 +239,9 @@ class Application_Model_User {
return Application_Model_User::getUsers(array('H'), $search);
}
public static function getUsersDataTablesInfo($datatables_post) {
public static function getUsersDataTablesInfo($datatables) {
$con = Propel::getConnection(CcSubjsPeer::DATABASE_NAME);
$displayColumns = array("id", "login", "first_name", "last_name", "type");
$fromTable = "cc_subjs";
@ -252,8 +254,8 @@ class Application_Model_User {
$username = $auth->getIdentity()->login;
}
$res = Application_Model_StoredFile::searchFiles($displayColumns, $fromTable, $datatables_post);
$res = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables);
// mark record which is for the current user
foreach($res['aaData'] as &$record){
if($record['login'] == $username){

View File

@ -139,7 +139,9 @@ var AIRTIME = (function(AIRTIME) {
oData.iCreate = parseInt(oData.iCreate, 10);
},
"sAjaxSource": "/Library/contents",
"sAjaxSource": "/Library/contents-feed",
"sAjaxDataProp": "files",
"fnServerData": function ( sSource, aoData, fnCallback ) {
var type;