-began adding basic foundation for show list-view.

This commit is contained in:
martin 2011-01-28 11:18:12 -05:00
commit c673b12046
7 changed files with 220 additions and 222 deletions

View file

@ -132,20 +132,14 @@ class LibraryController extends Zend_Controller_Action
$this->_helper->viewRenderer->setResponseSegment('library'); $this->_helper->viewRenderer->setResponseSegment('library');
$format = $this->_getParam('format'); $format = $this->_getParam('format');
$echo = $this->_getParam('sEcho');
$offset = $this->_getParam('iDisplayStart');
$limit = $this->_getParam('iDisplayLength');
$post = $this->getRequest()->getPost(); $post = $this->getRequest()->getPost();
if($format == "json") { if($format == "json") {
$datatables = array("sEcho" => $echo); $datatables = StoredFile::searchFilesForPlaylistBuilder($post);
$files = StoredFile::searchFiles($offset, $limit, $post);
$datatables = array_merge($datatables, $files);
die(json_encode($datatables)); die(json_encode($datatables));
} }
} }

View file

@ -8,53 +8,53 @@ class ScheduleController extends Zend_Controller_Action
public function init() public function init()
{ {
if(!Zend_Auth::getInstance()->hasIdentity()) if(!Zend_Auth::getInstance()->hasIdentity())
{ {
$this->_redirect('login/index'); $this->_redirect('login/index');
} }
$ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('event-feed', 'json') $ajaxContext->addActionContext('event-feed', 'json')
->addActionContext('add-show-dialog', 'json') ->addActionContext('add-show-dialog', 'json')
->addActionContext('add-show', 'json') ->addActionContext('add-show', 'json')
->addActionContext('move-show', 'json') ->addActionContext('move-show', 'json')
->addActionContext('resize-show', 'json') ->addActionContext('resize-show', 'json')
->addActionContext('delete-show', 'json') ->addActionContext('delete-show', 'json')
->addActionContext('schedule-show', 'json') ->addActionContext('schedule-show', 'json')
->addActionContext('schedule-show-dialog', 'json') ->addActionContext('schedule-show-dialog', 'json')
->addActionContext('clear-show', 'json') ->addActionContext('clear-show', 'json')
->addActionContext('get-current-playlist', 'json') ->addActionContext('get-current-playlist', 'json')
->addActionContext('find-playlists', 'html') ->addActionContext('find-playlists', 'json')
->addActionContext('remove-group', 'json') ->addActionContext('remove-group', 'json')
->addActionContext('get-show-data', 'json') ->initContext();
->initContext();
$this->sched_sess = new Zend_Session_Namespace("schedule"); $this->sched_sess = new Zend_Session_Namespace("schedule");
} }
public function indexAction() public function indexAction()
{ {
$this->view->headScript()->appendFile('/js/fullcalendar/fullcalendar.min.js','text/javascript'); $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/contextmenu/jquery.contextMenu.js','text/javascript');
//$this->view->headScript()->appendFile('/js/qtip/jquery.qtip-1.0.0.min.js','text/javascript'); $this->view->headScript()->appendFile('/js/datatables/js/jquery.dataTables.js','text/javascript');
$this->view->headScript()->appendFile('/js/airtime/schedule/full-calendar-functions.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/schedule.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');
$this->view->headLink()->appendStylesheet('/css/jquery.contextMenu.css'); $this->view->headLink()->appendStylesheet('/css/jquery.contextMenu.css');
$this->view->headLink()->appendStylesheet('/css/fullcalendar.css'); $this->view->headLink()->appendStylesheet('/css/fullcalendar.css');
$this->view->headLink()->appendStylesheet('/css/schedule.css'); $this->view->headLink()->appendStylesheet('/css/schedule.css');
$this->view->headLink()->appendStylesheet('/css/pro_dropdown_3.css'); $this->view->headLink()->appendStylesheet('/css/pro_dropdown_3.css');
$this->view->headLink()->appendStylesheet('/css/styles.css'); $this->view->headLink()->appendStylesheet('/css/styles.css');
$eventDefaultMenu = array(); $eventDefaultMenu = array();
//$eventDefaultMenu[] = array('action' => '/Schedule/delete-show', 'text' => 'Delete'); //$eventDefaultMenu[] = array('action' => '/Schedule/delete-show', 'text' => 'Delete');
$this->view->eventDefaultMenu = $eventDefaultMenu; $this->view->eventDefaultMenu = $eventDefaultMenu;
$eventHostMenu[] = array('action' => '/Schedule/delete-show', 'text' => 'Delete'); $eventHostMenu[] = array('action' => '/Schedule/delete-show', 'text' => 'Delete');
$eventHostMenu[] = array('action' => '/Schedule/schedule-show', 'text' => 'Schedule'); $eventHostMenu[] = array('action' => '/Schedule/schedule-show', 'text' => 'Schedule');
$eventHostMenu[] = array('action' => '/Schedule/clear-show', 'text' => 'Clear'); $eventHostMenu[] = array('action' => '/Schedule/clear-show', 'text' => 'Clear');
$this->view->eventHostMenu = $eventHostMenu; $this->view->eventHostMenu = $eventHostMenu;
} }
public function eventFeedAction() public function eventFeedAction()
@ -183,35 +183,30 @@ class ScheduleController extends Zend_Controller_Action
public function scheduleShowAction() public function scheduleShowAction()
{ {
$start_timestamp = $this->sched_sess->showStart; $start_timestamp = $this->sched_sess->showStart;
$end_timestamp = $this->sched_sess->showEnd; $end_timestamp = $this->sched_sess->showEnd;
$showId = $this->sched_sess->showId; $showId = $this->sched_sess->showId;
$search = $this->_getParam('search', null); $search = $this->_getParam('search', null);
$plId = $this->_getParam('plId'); $plId = $this->_getParam('plId');
if($search == "") { if($search == "") {
$search = null; $search = null;
} }
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id, $userInfo->type); $user = new User($userInfo->id, $userInfo->type);
$show = new Show($user, $showId); $show = new Show($user, $showId);
$show->scheduleShow($start_timestamp, array($plId)); $show->scheduleShow($start_timestamp, array($plId));
$this->view->playlists = $show->searchPlaylistsForShow($start_timestamp, $search); $this->view->showContent = $show->getShowContent($start_timestamp);
$this->view->showContent = $show->getShowContent($start_timestamp); $this->view->timeFilled = $show->getTimeScheduled($start_timestamp, $end_timestamp);
$this->view->percentFilled = Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp);
$this->view->timeFilled = $show->getTimeScheduled($start_timestamp, $end_timestamp); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
$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'); unset($this->view->showContent);
$this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
unset($this->view->showContent);
unset($this->view->playlists);
} }
public function clearShowAction() public function clearShowAction()
@ -236,40 +231,38 @@ class ScheduleController extends Zend_Controller_Action
public function findPlaylistsAction() public function findPlaylistsAction()
{ {
$search = $this->_getParam('search'); $show_id = $this->sched_sess->showId;
$show_id = $this->sched_sess->showId; $start_timestamp = $this->sched_sess->showStart;
$start_timestamp = $this->sched_sess->showStart; $post = $this->getRequest()->getPost();
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$show = new Show(new User($userInfo->id, $userInfo->type), $show_id); $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() public function removeGroupAction()
{ {
$group_id = $this->_getParam('groupId'); $group_id = $this->_getParam('groupId');
$start_timestamp = $this->sched_sess->showStart; $start_timestamp = $this->sched_sess->showStart;
$end_timestamp = $this->sched_sess->showEnd; $end_timestamp = $this->sched_sess->showEnd;
$show_id = $this->sched_sess->showId; $show_id = $this->sched_sess->showId;
$search = $this->_getParam('search', null); $search = $this->_getParam('search', null);
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$show = new Show(new User($userInfo->id, $userInfo->type), $show_id); $show = new Show(new User($userInfo->id, $userInfo->type), $show_id);
$show->removeGroupFromShow($start_timestamp, $group_id); $show->removeGroupFromShow($start_timestamp, $group_id);
$this->view->playlists = $show->searchPlaylistsForShow($start_timestamp, $search); $this->view->showContent = $show->getShowContent($start_timestamp);
$this->view->showContent = $show->getShowContent($start_timestamp); $this->view->timeFilled = $show->getTimeScheduled($start_timestamp, $end_timestamp);
$this->view->percentFilled = Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp);
$this->view->timeFilled = $show->getTimeScheduled($start_timestamp, $end_timestamp); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
$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'); unset($this->view->showContent);
$this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
unset($this->view->showContent);
unset($this->view->playlists);
} }
public function scheduleShowDialogAction() public function scheduleShowDialogAction()
@ -315,11 +308,16 @@ class ScheduleController extends Zend_Controller_Action
public function getShowDataAction() public function getShowDataAction()
{ {
$this->view->data = Show::getShows("2011-01-27"); $this->view->data = Show::getShows("2011-01-27");
$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->chosen = $this->view->render('schedule/scheduled-content.phtml');
$this->view->dialog = $this->view->render('schedule/schedule-show-dialog.phtml');
unset($this->view->showContent);
} }
} }

View file

@ -151,71 +151,6 @@ class Playlist {
return $res; 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.<br> * Fetch instance of Playlist object.<br>
* *

View file

@ -639,7 +639,7 @@ class Show {
return $length; return $length;
} }
public function searchPlaylistsForShow($start_timestamp, $search=null){ public function searchPlaylistsForShow($start_timestamp, $datatables){
global $CC_DBC; global $CC_DBC;
$sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$start_timestamp}')"; $sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$start_timestamp}')";
@ -656,7 +656,6 @@ class Show {
$length = $this->getTimeUnScheduled($start_date, $start_date, $start_time, $end_time); $length = $this->getTimeUnScheduled($start_date, $start_date, $start_time, $end_time);
return Playlist::searchPlaylists($length, $search); return StoredFile::searchPlaylistsForSchedule($length, $datatables);
} }
} }

View file

@ -1742,14 +1742,9 @@ class StoredFile {
return $CC_CONFIG['accessDir']."/$p_token.$p_ext"; return $CC_CONFIG['accessDir']."/$p_token.$p_ext";
} }
public static function searchFiles($offset, $limit, $data) public static function searchFilesForPlaylistBuilder($datatables) {
{
global $CC_CONFIG, $CC_DBC, $g_metadata_xml_to_db_mapping;
$columnsDisplayed = explode(",", $data["sColumns"]); global $CC_CONFIG, $g_metadata_xml_to_db_mapping;
if($data["sSearch"] !== "")
$searchTerms = explode(" ", $data["sSearch"]);
$plSelect = "SELECT "; $plSelect = "SELECT ";
$fileSelect = "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(*)"; $selectorCount = "SELECT COUNT(*)";
$selectorRows = "SELECT ". join("," , $columnsDisplayed); $selectorRows = "SELECT ". join("," , $columnsDisplayed);
$fromTable = " FROM ((".$plSelect."PL.id $sql = $selectorCount." FROM ".$fromTable;
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;
$totalRows = $CC_DBC->getOne($sql); $totalRows = $CC_DBC->getOne($sql);
// Where clause // Where clause
if(isset($data["optWhere"])) {
$where[] = join(" AND ", $data["optWhere"]);
}
if(isset($searchTerms)) { if(isset($searchTerms)) {
$searchCols = array(); $searchCols = array();
@ -1819,14 +1841,9 @@ class StoredFile {
$innerCond[] = "{$col}::text ILIKE '%{$term}%'"; $innerCond[] = "{$col}::text ILIKE '%{$term}%'";
} }
$outerCond[] = "(".join(" OR ", $innerCond).")";
$outerCond[] = join(" OR ", $innerCond);
} }
$where[] = "(".join(" AND ", $outerCond).")";
$where = join(" AND ", $outerCond);
$sql = $selectorCount." ".$fromTable." WHERE ".$where;
$totalDisplayRows = $CC_DBC->getOne($sql);
} }
// End Where clause // End Where clause
@ -1846,10 +1863,16 @@ class StoredFile {
$CC_DBC->setFetchMode(DB_FETCHMODE_ORDERED); $CC_DBC->setFetchMode(DB_FETCHMODE_ORDERED);
if(isset($where)) { 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 { 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); $results = $CC_DBC->getAll($sql);
@ -1863,7 +1886,7 @@ class StoredFile {
$totalDisplayRows = $totalRows; $totalDisplayRows = $totalRows;
} }
return array("iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results); return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results);

View file

@ -1,7 +1,18 @@
<div id="schedule_playlist_dialog"> <div id="schedule_playlist_dialog">
<div> <div>
<input id="schedule_playlist_search" type="text"></input> <table id="schedule_playlists" cellpadding="0" cellspacing="0" class="datatable">
<ul id="schedule_playlist_choice"></ul> <thead>
<tr>
<th>Id</th>
<th>Description</th>
<th>Title</th>
<th>Creator</th>
<th>Length</th>
<th>Editing</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div> </div>
<div> <div>
<div>Items In This Show:</div> <div>Items In This Show:</div>

View file

@ -11,14 +11,10 @@ function closeDialog(event, ui) {
function setScheduleDialogHtml(json) { function setScheduleDialogHtml(json) {
var dt;
$("#schedule_playlist_choice") dt = $('#schedule_playlists').dataTable();
.empty() dt.fnDraw();
.append(json.choice)
.find('li')
.draggable({
helper: 'clone'
});
$("#schedule_playlist_chosen") $("#schedule_playlist_chosen")
.empty() .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) { function makeScheduleDialog(dialog, json) {
dialog.find("#schedule_playlist_search").keyup(function(){ dialog.find("#schedule_playlist_search").keyup(function(){
@ -91,12 +107,34 @@ function makeScheduleDialog(dialog, json) {
}); });
}); });
dialog.find('#schedule_playlist_choice') dialog.find('#schedule_playlists').dataTable( {
.append(json.choice) "bProcessing": true,
.find('li') "bServerSide": true,
.draggable({ "sAjaxSource": "/Schedule/find-playlists/format/json",
helper: 'clone' "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") dialog.find("#schedule_playlist_chosen")
.append(json.chosen) .append(json.chosen)