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

View File

@ -281,14 +281,6 @@ class Schedule {
public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) {
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"]."
WHERE (starts >= '{$s_datetime}')
AND (ends <= '{$e_datetime}')";
@ -310,14 +302,6 @@ class Schedule {
public static function getTimeScheduledInRange($s_datetime, $e_datetime) {
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"]."
WHERE (starts >= '{$s_datetime}')
AND (ends <= '{$e_datetime}')";

View File

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

View File

@ -91,34 +91,11 @@ function eventRender(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)
.jjmenu("rightClick",
[{get:"/Schedule/make-context-menu/format/json/id/#id#/start/#start#/end/#end#"}],
{id: event.id, start: getStartTS, end: getEndTS, showId: event.showId},
[{get:"/Schedule/make-context-menu/format/json/id/#id#"}],
{id: event.id},
{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) {