diff --git a/application/controllers/LibraryController.php b/application/controllers/LibraryController.php index 3fdc4a394..297ddbe31 100644 --- a/application/controllers/LibraryController.php +++ b/application/controllers/LibraryController.php @@ -132,20 +132,14 @@ class LibraryController extends Zend_Controller_Action $this->_helper->viewRenderer->setResponseSegment('library'); $format = $this->_getParam('format'); - $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, $post); - - $datatables = array_merge($datatables, $files); + $datatables = StoredFile::searchFilesForPlaylistBuilder($post); die(json_encode($datatables)); - } } diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index d7409eeb6..a8162da65 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -22,7 +22,7 @@ class ScheduleController extends Zend_Controller_Action ->addActionContext('schedule-show-dialog', 'json') ->addActionContext('clear-show', 'json') ->addActionContext('get-current-playlist', 'json') - ->addActionContext('find-playlists', 'html') + ->addActionContext('find-playlists', 'json') ->addActionContext('remove-group', 'json') ->initContext(); @@ -33,6 +33,7 @@ class ScheduleController extends Zend_Controller_Action { $this->view->headScript()->appendFile('/js/fullcalendar/fullcalendar.min.js','text/javascript'); $this->view->headScript()->appendFile('/js/contextmenu/jquery.contextMenu.js','text/javascript'); + $this->view->headScript()->appendFile('/js/datatables/js/jquery.dataTables.js','text/javascript'); //$this->view->headScript()->appendFile('/js/qtip/jquery.qtip-1.0.0.min.js','text/javascript'); $this->view->headScript()->appendFile('/js/airtime/schedule/full-calendar-functions.js','text/javascript'); $this->view->headScript()->appendFile('/js/airtime/schedule/schedule.js','text/javascript'); @@ -198,18 +199,13 @@ class ScheduleController extends Zend_Controller_Action $show->scheduleShow($start_timestamp, array($plId)); - $this->view->playlists = $show->searchPlaylistsForShow($start_timestamp, $search); $this->view->showContent = $show->getShowContent($start_timestamp); - $this->view->timeFilled = $show->getTimeScheduled($start_timestamp, $end_timestamp); - $this->view->showLength = $show->getShowLength($start_timestamp, $end_timestamp); $this->view->percentFilled = Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp); - $this->view->choice = $this->view->render('schedule/find-playlists.phtml'); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); unset($this->view->showContent); - unset($this->view->playlists); } public function clearShowAction() @@ -234,13 +230,16 @@ class ScheduleController extends Zend_Controller_Action public function findPlaylistsAction() { - $search = $this->_getParam('search'); $show_id = $this->sched_sess->showId; $start_timestamp = $this->sched_sess->showStart; + $post = $this->getRequest()->getPost(); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $show = new Show(new User($userInfo->id, $userInfo->type), $show_id); - $this->view->playlists = $show->searchPlaylistsForShow($start_timestamp, $search); + $playlists = $show->searchPlaylistsForShow($start_timestamp, $post); + + //for datatables + die(json_encode($playlists)); } public function removeGroupAction() @@ -256,18 +255,13 @@ class ScheduleController extends Zend_Controller_Action $show->removeGroupFromShow($start_timestamp, $group_id); - $this->view->playlists = $show->searchPlaylistsForShow($start_timestamp, $search); $this->view->showContent = $show->getShowContent($start_timestamp); - $this->view->timeFilled = $show->getTimeScheduled($start_timestamp, $end_timestamp); - $this->view->showLength = $show->getShowLength($start_timestamp, $end_timestamp); $this->view->percentFilled = Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp); - $this->view->choice = $this->view->render('schedule/find-playlists.phtml'); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); unset($this->view->showContent); - unset($this->view->playlists); } public function scheduleShowDialogAction() @@ -285,19 +279,15 @@ class ScheduleController extends Zend_Controller_Action $user = new User($userInfo->id, $userInfo->type); $show = new Show($user, $showId); - $this->view->playlists = $show->searchPlaylistsForShow($start_timestamp); $this->view->showContent = $show->getShowContent($start_timestamp); - $this->view->timeFilled = $show->getTimeScheduled($start_timestamp, $end_timestamp); $this->view->showLength = $show->getShowLength($start_timestamp, $end_timestamp); $this->view->percentFilled = Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp); - $this->view->choice = $this->view->render('schedule/find-playlists.phtml'); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); $this->view->dialog = $this->view->render('schedule/schedule-show-dialog.phtml'); unset($this->view->showContent); - unset($this->view->playlists); } diff --git a/application/models/Playlist.php b/application/models/Playlist.php index f158056bc..dee382093 100644 --- a/application/models/Playlist.php +++ b/application/models/Playlist.php @@ -151,71 +151,6 @@ class Playlist { return $res; } - public static function findPlaylistMaxLength($p_length) - { - $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); - - $sql = "SELECT sub.login, plt.length, pl.state, pl.creator, pl.description, pl.name, pl.id - FROM cc_playlist AS pl LEFT JOIN cc_playlisttimes AS plt USING(id) LEFT JOIN cc_subjs AS sub ON pl.editedby = sub.id - WHERE plt.length <= '{$p_length}' "; - - $r = $con->query($sql); - return $r->fetchAll(); - } - - public static function searchPlaylists($p_length, $search=null) - { - $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME); - - $sql = "SELECT sub.login, plt.length, pl.state, pl.creator, pl.description, pl.name, pl.id - FROM cc_playlist AS pl LEFT JOIN cc_playlisttimes AS plt USING(id) LEFT JOIN cc_subjs AS sub ON pl.editedby = sub.id - WHERE plt.length <= '{$p_length}' "; - - - if(!is_null($search)) { - $keywords = explode(" ", $search); - - $categories = array("pl.description", "pl.name", "pl.creator", "sub.login"); - - for($group_id=1; $group_id <= count($keywords); $group_id++) { - - for($row_id=1; $row_id <= count($categories); $row_id++) { - - $md["group_".$group_id]["row_".$row_id]["metadata"] = $categories[$row_id-1]; - $md["group_".$group_id]["row_".$row_id]["match"] = "ILIKE"; - $md["group_".$group_id]["row_".$row_id]["search"] = $keywords[$group_id-1]; - } - } - - $and_cond = array(); - foreach (array_keys($md) as $group) { - - $or_cond = array(); - foreach (array_keys($md[$group]) as $row) { - - $string = $md[$group][$row]["metadata"]; - $string = $string ." ".$md[$group][$row]["match"]; - $string = $string." '%". $md[$group][$row]["search"]."%'"; - - $or_cond[] = $string; - } - - if(count($or_cond) > 0) { - $and_cond[] = "(".join(" OR ", $or_cond).")"; - } - } - - $where_search = " AND ". join(" AND ", $and_cond); - $sql = $sql . $where_search; - } - - //echo $sql; - - $r = $con->query($sql); - return $r->fetchAll(); - } - - /** * Fetch instance of Playlist object.
* diff --git a/application/models/Shows.php b/application/models/Shows.php index 55414ac12..6e769606a 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -638,7 +638,7 @@ class Show { return $length; } - public function searchPlaylistsForShow($start_timestamp, $search=null){ + public function searchPlaylistsForShow($start_timestamp, $datatables){ global $CC_DBC; $sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$start_timestamp}')"; @@ -655,7 +655,6 @@ class Show { $length = $this->getTimeUnScheduled($start_date, $start_date, $start_time, $end_time); - return Playlist::searchPlaylists($length, $search); - + return StoredFile::searchPlaylistsForSchedule($length, $datatables); } } diff --git a/application/models/StoredFile.php b/application/models/StoredFile.php index b6ab13d10..e25e54ebf 100644 --- a/application/models/StoredFile.php +++ b/application/models/StoredFile.php @@ -1742,14 +1742,9 @@ class StoredFile { return $CC_CONFIG['accessDir']."/$p_token.$p_ext"; } - public static function searchFiles($offset, $limit, $data) - { - global $CC_CONFIG, $CC_DBC, $g_metadata_xml_to_db_mapping; + public static function searchFilesForPlaylistBuilder($datatables) { - $columnsDisplayed = explode(",", $data["sColumns"]); - - if($data["sSearch"] !== "") - $searchTerms = explode(" ", $data["sSearch"]); + global $CC_CONFIG, $g_metadata_xml_to_db_mapping; $plSelect = "SELECT "; $fileSelect = "SELECT "; @@ -1781,23 +1776,50 @@ class StoredFile { } } + $fromTable = " ((".$plSelect."PL.id + FROM ".$CC_CONFIG["playListTable"]." AS PL + LEFT JOIN ".$CC_CONFIG['playListTimeView']." AS PLT USING(id)) + + UNION + + (".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS"; + + return StoredFile::searchFiles($fromTable, $datatables); + } + + public static function searchPlaylistsForSchedule($p_length, $datatables) { + + $fromTable = "cc_playlist AS pl LEFT JOIN cc_playlisttimes AS plt USING(id) LEFT JOIN cc_subjs AS sub ON pl.editedby = sub.id"; + + $datatables["optWhere"][] = "plt.length <= '{$p_length}'"; + + + return StoredFile::searchFiles($fromTable, $datatables); + } + + private static function searchFiles($fromTable, $data) + { + global $CC_CONFIG, $CC_DBC; + + $columnsDisplayed = explode(",", $data["sColumns"]); + + if($data["sSearch"] !== "") + $searchTerms = explode(" ", $data["sSearch"]); + $selectorCount = "SELECT COUNT(*)"; $selectorRows = "SELECT ". join("," , $columnsDisplayed); - $fromTable = " FROM ((".$plSelect."PL.id - FROM ".$CC_CONFIG["playListTable"]." AS PL - LEFT JOIN ".$CC_CONFIG['playListTimeView']." AS PLT USING(id)) - - UNION - - (".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS"; - - $sql = $selectorCount." ".$fromTable; + $sql = $selectorCount." FROM ".$fromTable; $totalRows = $CC_DBC->getOne($sql); // Where clause + if(isset($data["optWhere"])) { + + $where[] = join(" AND ", $data["optWhere"]); + } + if(isset($searchTerms)) { $searchCols = array(); @@ -1819,14 +1841,9 @@ class StoredFile { $innerCond[] = "{$col}::text ILIKE '%{$term}%'"; } - - $outerCond[] = join(" OR ", $innerCond); + $outerCond[] = "(".join(" OR ", $innerCond).")"; } - - $where = join(" AND ", $outerCond); - - $sql = $selectorCount." ".$fromTable." WHERE ".$where; - $totalDisplayRows = $CC_DBC->getOne($sql); + $where[] = "(".join(" AND ", $outerCond).")"; } // End Where clause @@ -1846,10 +1863,16 @@ class StoredFile { $CC_DBC->setFetchMode(DB_FETCHMODE_ORDERED); if(isset($where)) { - $sql = $selectorRows." ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$offset." LIMIT ".$limit; + + $where = join(" AND ", $where); + + $sql = $selectorCount." FROM ".$fromTable." WHERE ".$where; + $totalDisplayRows = $CC_DBC->getOne($sql); + + $sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"]; } else { - $sql = $selectorRows." ".$fromTable." ORDER BY ".$orderby." OFFSET ".$offset." LIMIT ".$limit; + $sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"]; } $results = $CC_DBC->getAll($sql); @@ -1863,7 +1886,7 @@ class StoredFile { $totalDisplayRows = $totalRows; } - return array("iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results); + return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results); diff --git a/application/views/scripts/schedule/schedule-show-dialog.phtml b/application/views/scripts/schedule/schedule-show-dialog.phtml index ecde98bcc..30b300b32 100644 --- a/application/views/scripts/schedule/schedule-show-dialog.phtml +++ b/application/views/scripts/schedule/schedule-show-dialog.phtml @@ -1,7 +1,18 @@
- - + + + + + + + + + + + + +
IdDescriptionTitleCreatorLengthEditing
Items In This Show:
diff --git a/public/js/airtime/schedule/schedule.js b/public/js/airtime/schedule/schedule.js index 7c8e621a8..4fa332aaa 100644 --- a/public/js/airtime/schedule/schedule.js +++ b/public/js/airtime/schedule/schedule.js @@ -11,14 +11,10 @@ function closeDialog(event, ui) { function setScheduleDialogHtml(json) { + var dt; - $("#schedule_playlist_choice") - .empty() - .append(json.choice) - .find('li') - .draggable({ - helper: 'clone' - }); + dt = $('#schedule_playlists').dataTable(); + dt.fnDraw(); $("#schedule_playlist_chosen") .empty() @@ -70,6 +66,26 @@ function setScheduleDialogEvents(dialog) { }); } +function dtRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { + var id = "pl_" + aData[0]; + + $(nRow).attr("id", id); + + return nRow; +} + +function addDtPlaylistEvents() { + + $('#schedule_playlists tbody tr') + .draggable({ + helper: 'clone' + }); +} + +function dtDrawCallback() { + addDtPlaylistEvents(); +} + function makeScheduleDialog(dialog, json) { dialog.find("#schedule_playlist_search").keyup(function(){ @@ -91,12 +107,34 @@ function makeScheduleDialog(dialog, json) { }); }); - dialog.find('#schedule_playlist_choice') - .append(json.choice) - .find('li') - .draggable({ - helper: 'clone' - }); + dialog.find('#schedule_playlists').dataTable( { + "bProcessing": true, + "bServerSide": true, + "sAjaxSource": "/Schedule/find-playlists/format/json", + "fnServerData": function ( sSource, aoData, fnCallback ) { + $.ajax( { + "dataType": 'json', + "type": "POST", + "url": sSource, + "data": aoData, + "success": fnCallback + } ); + }, + "fnRowCallback": dtRowCallback, + "fnDrawCallback": dtDrawCallback, + "aoColumns": [ + /* Id */ { "sName": "pl.id", "bSearchable": false, "bVisible": false }, + /* Description */ { "sName": "pl.description", "bVisible": false }, + /* Name */ { "sName": "pl.name" }, + /* Creator */ { "sName": "pl.creator" }, + /* Length */ { "sName": "plt.length" }, + /* Editing */ { "sName": "sub.login" } + ], + "aaSorting": [[2,'asc']], + "sPaginationType": "full_numbers", + "bJQueryUI": true, + "bAutoWidth": false + }); dialog.find("#schedule_playlist_chosen") .append(json.chosen)