everything moved to its new class, now just testing, context menu works.

This commit is contained in:
naomiaro 2011-02-05 19:10:34 -05:00
parent bfc1bccfdf
commit 51b6a79f6f
4 changed files with 90 additions and 138 deletions

View file

@ -171,17 +171,18 @@ class ScheduleController extends Zend_Controller_Action
public function makeContextMenuAction() public function makeContextMenuAction()
{ {
$id = $this->_getParam('id'); $id = $this->_getParam('id');
$start_timestamp = $this->_getParam('start');
$today_timestamp = date("Y-m-d H:i:s"); $today_timestamp = date("Y-m-d H:i:s");
$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);
$params = '/format/json/id/#id#/start/#start#/end/#end#'; $show = new ShowInstance($id);
if(strtotime($today_timestamp) < strtotime($start_timestamp)) { $params = '/format/json/id/#id#';
if($user->isHost($id)) { if(strtotime($today_timestamp) < strtotime($show->getShowStart())) {
if($user->isHost($show->getShowId())) {
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/delete-show'.$params, 'callback' => 'window["scheduleRefetchEvents"]'), $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/delete-show'.$params, 'callback' => 'window["scheduleRefetchEvents"]'),
'title' => 'Delete'); 'title' => 'Delete');
@ -203,9 +204,7 @@ class ScheduleController extends Zend_Controller_Action
public function scheduleShowAction() public function scheduleShowAction()
{ {
$start_timestamp = $this->sched_sess->showStart; $showInstanceId = $this->sched_sess->showInstanceId;
$end_timestamp = $this->sched_sess->showEnd;
$showId = $this->sched_sess->showId;
$search = $this->_getParam('search', null); $search = $this->_getParam('search', null);
$plId = $this->_getParam('plId'); $plId = $this->_getParam('plId');
@ -214,35 +213,33 @@ class ScheduleController extends Zend_Controller_Action
} }
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id, $userInfo->type);
$show = new ShowInstance($showInstanceId);
$user = new User($userInfo->id, $userInfo->type); if($user->isHost($show->getShowId())) {
$show = new Show($user, $showId); $show->scheduleShow(array($plId));
if($user->isHost($showId)) {
$show->scheduleShow($start_timestamp, array($plId));
} }
$this->view->showContent = $show->getShowContent($start_timestamp); $this->view->showContent = $show->getShowContent();
$this->view->timeFilled = $show->getTimeScheduled($start_timestamp, $end_timestamp); $this->view->timeFilled = $show->getTimeScheduled();
$this->view->percentFilled = Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp); $this->view->percentFilled = $show->getPercentScheduledInRange();
$this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
unset($this->view->showContent); unset($this->view->showContent);
} }
public function clearShowAction() public function clearShowAction()
{ {
$start = $this->_getParam('start'); $showInstanceId = $this->_getParam('id');
$showId = $this->_getParam('id');
$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);
if($user->isHost($showId)) { $show = new ShowInstance($showInstanceId);
$show = new Show($user, $showId); if($user->isHost($show->getShowId())) {
$show->clearShow($start);
$show->clearShow();
} }
} }
@ -253,14 +250,10 @@ class ScheduleController extends Zend_Controller_Action
public function findPlaylistsAction() public function findPlaylistsAction()
{ {
$show_id = $this->sched_sess->showId;
$start_timestamp = $this->sched_sess->showStart;
$end_timestamp = $this->sched_sess->showEnd;
$post = $this->getRequest()->getPost(); $post = $this->getRequest()->getPost();
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $show = new ShowInstance($this->sched_sess->showInstanceId);
$show = new Show(new User($userInfo->id, $userInfo->type), $show_id); $playlists = $show->searchPlaylistsForShow($post);
$playlists = $show->searchPlaylistsForShow($start_timestamp, $end_timestamp, $post);
//for datatables //for datatables
die(json_encode($playlists)); die(json_encode($playlists));
@ -268,31 +261,29 @@ class ScheduleController extends Zend_Controller_Action
public function removeGroupAction() public function removeGroupAction()
{ {
$showInstanceId = $this->sched_sess->showInstanceId;
$group_id = $this->_getParam('groupId'); $group_id = $this->_getParam('groupId');
$start_timestamp = $this->sched_sess->showStart;
$end_timestamp = $this->sched_sess->showEnd;
$show_id = $this->sched_sess->showId;
$search = $this->_getParam('search', null); $search = $this->_getParam('search', null);
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $show = new ShowInstance($showInstanceId);
$show = new Show(new User($userInfo->id, $userInfo->type), $show_id); $show->removeGroupFromShow($group_id);
$show->removeGroupFromShow($start_timestamp, $group_id);
$this->view->showContent = $show->getShowContent($start_timestamp); $this->view->showContent = $show->getShowContent();
$this->view->timeFilled = $show->getTimeScheduled($start_timestamp, $end_timestamp); $this->view->timeFilled = $show->getTimeScheduled();
$this->view->percentFilled = Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp); $this->view->percentFilled = $show->getPercentScheduledInRange();
$this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
unset($this->view->showContent); unset($this->view->showContent);
} }
public function scheduleShowDialogAction() public function scheduleShowDialogAction()
{ {
$showInstanceId = $this->_getParam('id');
$show = new ShowInstance($showInstanceId);
$start_timestamp = $this->_getParam('start'); $start_timestamp = $this->_getParam('start');
$end_timestamp = $this->_getParam('end'); $end_timestamp = $this->_getParam('end');
$showId = $this->_getParam('id');
$this->sched_sess->showId = $showId; $this->sched_sess->showId = $showId;
$this->sched_sess->showStart = $start_timestamp; $this->sched_sess->showStart = $start_timestamp;

View file

@ -281,14 +281,6 @@ class Schedule {
public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) { public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'";
$isNextDay = $CC_DBC->GetOne($sql);
if($isNextDay === 't') {
$sql = "SELECT date '{$e_datetime}' + interval '1 day'";
$e_datetime = $CC_DBC->GetOne($sql);
}
$sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]."
WHERE (starts >= '{$s_datetime}') WHERE (starts >= '{$s_datetime}')
AND (ends <= '{$e_datetime}')"; AND (ends <= '{$e_datetime}')";
@ -310,14 +302,6 @@ class Schedule {
public static function getTimeScheduledInRange($s_datetime, $e_datetime) { public static function getTimeScheduledInRange($s_datetime, $e_datetime) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'";
$isNextDay = $CC_DBC->GetOne($sql);
if($isNextDay === 't') {
$sql = "SELECT date '{$e_datetime}' + interval '1 day'";
$e_datetime = $CC_DBC->GetOne($sql);
}
$sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]."
WHERE (starts >= '{$s_datetime}') WHERE (starts >= '{$s_datetime}')
AND (ends <= '{$e_datetime}')"; AND (ends <= '{$e_datetime}')";

View file

@ -369,11 +369,24 @@ class ShowInstance {
$this->_instanceId = $instanceId; $this->_instanceId = $instanceId;
} }
public function getShowId() {
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
return $showInstance->getDbShowId();
}
public function getShowStart() {
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
return $showInstance->getDbStarts();
}
public function getShowEnd() {
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
return $showInstance->getDbEnds();
}
public function moveShow($deltaDay, $deltaMin){ public function moveShow($deltaDay, $deltaMin){
global $CC_DBC; global $CC_DBC;
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
$hours = $deltaMin/60; $hours = $deltaMin/60;
if($hours > 0) if($hours > 0)
$hours = floor($hours); $hours = floor($hours);
@ -382,8 +395,8 @@ class ShowInstance {
$mins = abs($deltaMin%60); $mins = abs($deltaMin%60);
$starts = $showInstance->getDbStarts(); $starts = $this->getShowStart();
$ends = $showInstance->getDbEnds(); $ends = $this->getShowEnd();
$sql = "SELECT timestamp '{$starts}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'"; $sql = "SELECT timestamp '{$starts}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'";
$new_starts = $CC_DBC->GetOne($sql); $new_starts = $CC_DBC->GetOne($sql);
@ -411,8 +424,6 @@ class ShowInstance {
public function resizeShow($deltaDay, $deltaMin){ public function resizeShow($deltaDay, $deltaMin){
global $CC_DBC; global $CC_DBC;
$showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
$hours = $deltaMin/60; $hours = $deltaMin/60;
if($hours > 0) if($hours > 0)
$hours = floor($hours); $hours = floor($hours);
@ -421,8 +432,8 @@ class ShowInstance {
$mins = abs($deltaMin%60); $mins = abs($deltaMin%60);
$starts = $showInstance->getDbStarts(); $starts = $this->getShowStart();
$ends = $showInstance->getDbEnds(); $ends = $this->getShowEnd();
$sql = "SELECT timestamp '{$ends}' + interval '{$hours}:{$mins}'"; $sql = "SELECT timestamp '{$ends}' + interval '{$hours}:{$mins}'";
$new_ends = $CC_DBC->GetOne($sql); $new_ends = $CC_DBC->GetOne($sql);
@ -442,12 +453,10 @@ class ShowInstance {
} }
private function getNextPos($instanceId) { private function getNextPos() {
global $CC_DBC; global $CC_DBC;
$timeinfo = explode(" ", $day); $sql = "SELECT MAX(position)+1 from cc_show_schedule WHERE instance_id = '{$this->_instanceId}'";
$sql = "SELECT MAX(position)+1 from cc_show_schedule WHERE instance_id = '{$instanceId}'";
$res = $CC_DBC->GetOne($sql); $res = $CC_DBC->GetOne($sql);
if(is_null($res)) if(is_null($res))
@ -456,73 +465,60 @@ class ShowInstance {
return $res; return $res;
} }
private function getLastGroupId($start_timestamp) { private function getLastGroupId() {
global $CC_DBC; global $CC_DBC;
$timeinfo = explode(" ", $start_timestamp); $sql = "SELECT MAX(group_id) from cc_show_schedule WHERE instance_id = '{$this->_instanceId}'";
$sql = "SELECT MAX(group_id) from cc_show_schedule WHERE show_id = '{$this->_showId}' AND show_day = '{$timeinfo[0]}'";
$res = $CC_DBC->GetOne($sql); $res = $CC_DBC->GetOne($sql);
return $res; return $res;
} }
public function addPlaylistToShow($start_timestamp, $plId) { public function addPlaylistToShow($plId) {
$sched = new ScheduleGroup(); $sched = new ScheduleGroup();
$lastGroupId = $this->getLastGroupId($start_timestamp); $lastGroupId = $this->getLastGroupId();
if(is_null($lastGroupId)) { if(is_null($lastGroupId)) {
$groupId = $sched->add($start_timestamp, null, $plId); $groupId = $sched->add($this->getShowStart(), null, $plId);
} }
else { else {
$groupId = $sched->addPlaylistAfter($lastGroupId, $plId); $groupId = $sched->addPlaylistAfter($lastGroupId, $plId);
} }
$instance = CcShowInstancesQuery::create()
->filterByDbStarts()
->findOne();
$instanceId = $instance->getDbId();
$pos = $this->getNextPos($day);
$groupsched = new CcShowSchedule(); $groupsched = new CcShowSchedule();
$groupsched->setDbInstanceId($instanceId); $groupsched->setDbInstanceId($this->_instanceId);
$groupsched->setDbGroupId($groupId); $groupsched->setDbGroupId($groupId);
$groupsched->setDbPosition($pos); $groupsched->setDbPosition($pos);
$groupsched->save(); $groupsched->save();
} }
public function scheduleShow($start_timestamp, $plIds) { public function scheduleShow($plIds) {
foreach($plIds as $plId) { foreach($plIds as $plId) {
$this->addPlaylistToShow($start_timestamp, $plId); $this->addPlaylistToShow($plId);
} }
} }
public function removeGroupFromShow($start_timestamp, $group_id){ public function removeGroupFromShow($group_id){
global $CC_DBC, $CC_CONFIG; global $CC_DBC;
$timeinfo = explode(" ", $start_timestamp);
$group = CcShowScheduleQuery::create() $group = CcShowScheduleQuery::create()
->filterByDbShowId($this->_showId) ->filterByDbInstanceId($this->_instanceId)
->filterByDbGroupId($group_id) ->filterByDbGroupId($group_id)
->filterByDbShowDay($timeinfo[0])
->findOne(); ->findOne();
$position = $group->getDbPosition(); $position = $group->getDbPosition();
$sql = "SELECT group_id FROM cc_show_schedule $sql = "SELECT group_id FROM cc_show_schedule
WHERE show_id = '{$this->_showId}' AND show_day = '{$timeinfo[0]}' WHERE instance_id = '{$this->_instanceId}' AND position > '{$position}'";
AND position > '{$position}'";
$followingGroups = $CC_DBC->GetAll($sql); $followingGroups = $CC_DBC->GetAll($sql);
$sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." WHERE group_id='{$group_id}'"; $sql = "SELECT SUM(clip_length) FROM cc_schedule WHERE group_id='{$group_id}'";
$group_length = $CC_DBC->GetOne($sql); $group_length = $CC_DBC->GetOne($sql);
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"]." WHERE group_id = '{$group_id}'"; $sql = "DELETE FROM cc_schedule WHERE group_id = '{$group_id}'";
$CC_DBC->query($sql); $CC_DBC->query($sql);
if(!is_null($followingGroups)) { if(!is_null($followingGroups)) {
@ -532,22 +528,19 @@ class ShowInstance {
} }
$sql_group_ids = join(" OR ", $sql_opt); $sql_group_ids = join(" OR ", $sql_opt);
$sql = "UPDATE ".$CC_CONFIG["scheduleTable"]." $sql = "UPDATE cc_schedule
SET starts = (starts - INTERVAL '{$group_length}'), ends = (ends - INTERVAL '{$group_length}') SET starts = (starts - INTERVAL '{$group_length}'), ends = (ends - INTERVAL '{$group_length}')
WHERE " . $sql_group_ids; WHERE " . $sql_group_ids;
$CC_DBC->query($sql); $CC_DBC->query($sql);
} }
$group->delete(); $group->delete();
} }
public function clearShow($day) { public function clearShow() {
$timeinfo = explode(" ", $day);
$groups = CcShowScheduleQuery::create() $groups = CcShowScheduleQuery::create()
->filterByDbShowId($this->_showId) ->filterByDbInstanceId($this->_instanceId)
->filterByDbShowDay($timeinfo[0])
->find(); ->find();
foreach($groups as $group) { foreach($groups as $group) {
@ -560,42 +553,49 @@ class ShowInstance {
} }
} }
public function getTimeScheduled($start_timestamp, $end_timestamp) { public function getTimeScheduled() {
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp); $time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp);
return $time; return $time;
} }
public function getTimeUnScheduled($start_timestamp, $end_timestamp) { public function getTimeUnScheduled() {
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$time = Schedule::getTimeUnScheduledInRange($start_timestamp, $end_timestamp); $time = Schedule::getTimeUnScheduledInRange($start_timestamp, $end_timestamp);
return $time; return $time;
} }
public function showHasContent($start_timestamp, $end_timestamp) { public function getPercentScheduledInRange(){
$con = Propel::getConnection(CcShowPeer::DATABASE_NAME); $start_timestamp = $this->getShowStart();
$sql = "SELECT TIMESTAMP '{$end_timestamp}' - TIMESTAMP '{$start_timestamp}'"; $end_timestamp = $this->getShowEnd();
$r = $con->query($sql);
$length = $r->fetchColumn(0);
return !Schedule::isScheduleEmptyInRange($start_timestamp, $length); Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp);
} }
public function getShowLength($start_timestamp, $end_timestamp){ public function getShowLength(){
global $CC_DBC; global $CC_DBC;
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$sql = "SELECT TIMESTAMP '{$end_timestamp}' - TIMESTAMP '{$start_timestamp}' "; $sql = "SELECT TIMESTAMP '{$end_timestamp}' - TIMESTAMP '{$start_timestamp}' ";
$length = $CC_DBC->GetOne($sql); $length = $CC_DBC->GetOne($sql);
return $length; return $length;
} }
public function searchPlaylistsForShow($start_timestamp, $end_timestamp, $datatables){ public function searchPlaylistsForShow($datatables){
$length = $this->getTimeUnScheduled($start_timestamp, $end_timestamp); $length = $this->getTimeUnScheduled();
return StoredFile::searchPlaylistsForSchedule($length, $datatables); return StoredFile::searchPlaylistsForSchedule($length, $datatables);
} }

View file

@ -91,34 +91,11 @@ function eventRender(event, element, view) {
function eventAfterRender( event, element, view ) { function eventAfterRender( event, element, view ) {
function getStartTS() {
var start = makeTimeStamp(event.start);
return start;
}
function getEndTS() {
var start = makeTimeStamp(event.end);
return start;
}
$(element) $(element)
.jjmenu("rightClick", .jjmenu("rightClick",
[{get:"/Schedule/make-context-menu/format/json/id/#id#/start/#start#/end/#end#"}], [{get:"/Schedule/make-context-menu/format/json/id/#id#"}],
{id: event.id, start: getStartTS, end: getEndTS, showId: event.showId}, {id: event.id},
{xposition: "mouse", yposition: "mouse"}); {xposition: "mouse", yposition: "mouse"});
/*
$(element).qtip({
content: {
text: event.description,
title: { text: 'Show Description' }
},
position: {
target: 'mouse',
adjust: { mouse: true }
}
});
*/
} }
function eventClick(event, jsEvent, view) { function eventClick(event, jsEvent, view) {