From dc0ea0a5327617b5c5dda25ca2bd4a3eba16368c Mon Sep 17 00:00:00 2001 From: Naomi Date: Mon, 7 Mar 2011 12:43:05 -0500 Subject: [PATCH] edits to show class to support resizing/dragging with overbooking. --- application/models/Schedule.php | 25 +----------- application/models/Shows.php | 38 ++++++------------- application/models/StoredFile.php | 5 ++- .../schedule/full-calendar-functions.js | 6 +++ public/js/airtime/schedule/schedule.js | 4 -- 5 files changed, 21 insertions(+), 57 deletions(-) diff --git a/application/models/Schedule.php b/application/models/Schedule.php index e8f20dc78..aa47c9ade 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -323,32 +323,9 @@ class Schedule { return $res; } - public static function getPercentScheduledInRange($s_datetime, $e_datetime) { - - $time = Schedule::getTimeScheduledInRange($s_datetime, $e_datetime); - - $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); - - $sql = "SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '{$s_datetime}')"; - $r = $con->query($sql); - $s_epoch = $r->fetchColumn(0); - - $sql = "SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '{$e_datetime}')"; - $r = $con->query($sql); - $e_epoch = $r->fetchColumn(0); - - $sql = "SELECT EXTRACT(EPOCH FROM INTERVAL '{$time}')"; - $r = $con->query($sql); - $i_epoch = $r->fetchColumn(0); - - $percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100); - - return $percent; - } - public static function GetPercentScheduled($instance_id, $s_datetime, $e_datetime){ $time = Schedule::GetTotalShowTime($instance_id); - + $s_epoch = strtotime($s_datetime); $e_epoch = strtotime($e_datetime); diff --git a/application/models/Shows.php b/application/models/Shows.php index 993c5e84f..8684fd597 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -435,7 +435,7 @@ class Show { $event[$key] = $value; } - $percent = Schedule::getPercentScheduledInRange($show["starts"], $show["ends"]); + $percent = Schedule::GetPercentScheduled($show["instance_id"], $show["starts"], $show["ends"]); $event["percent"] = $percent; return $event; @@ -491,10 +491,9 @@ class ShowInstance { global $CC_DBC; $sql = "UPDATE cc_schedule - SET starts = (starts + interval '{$deltaDay} days' + interval '{$deltaHours}:{$deltaMin}'), + SET starts = (starts + interval '{$deltaDay} days' + interval '{$deltaHours}:{$deltaMin}'), ends = (ends + interval '{$deltaDay} days' + interval '{$deltaHours}:{$deltaMin}') - WHERE (starts >= '{$this->getShowStart()}') - AND (ends <= '{$this->getShowEnd()}')"; + WHERE instance_id = '{$this->_instanceId}'"; $CC_DBC->query($sql); } @@ -560,17 +559,8 @@ class ShowInstance { return "Should not overlap shows"; } } - //have to check if any scheduled content still fits. - else{ - $scheduledTime = $this->getTimeScheduled(); - $sql = "SELECT (timestamp '{$new_ends}' - timestamp '{$starts}') >= interval '{$scheduledTime}'"; - $scheduledContentFits = $CC_DBC->GetOne($sql); - - if($scheduledContentFits != "t") { - return "Must remove some scheduled content."; - } - } - + //with overbooking no longer need to check already scheduled content still fits. + $this->setShowEnd($new_ends); } @@ -639,6 +629,7 @@ class ShowInstance { } public function getTimeScheduled() { + $instance_id = $this->getShowInstanceId(); $time = Schedule::GetTotalShowTime($instance_id); @@ -656,23 +647,16 @@ class ShowInstance { return $time; } - public function getPercentScheduledInRange(){ + public function getPercentScheduled() { $start_timestamp = $this->getShowStart(); $end_timestamp = $this->getShowEnd(); - - return Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp); - } - - public function getPercentScheduled(){ - $start_timestamp = $this->getShowStart(); - $end_timestamp = $this->getShowEnd(); $instance_id = $this->getShowInstanceId(); return Schedule::GetPercentScheduled($instance_id, $start_timestamp, $end_timestamp); } - public function getShowLength(){ + public function getShowLength() { global $CC_DBC; $start_timestamp = $this->getShowStart(); @@ -686,9 +670,9 @@ class ShowInstance { public function searchPlaylistsForShow($datatables){ - $length = $this->getTimeUnScheduled(); - - return StoredFile::searchPlaylistsForSchedule($length, $datatables); + //$length = $this->getTimeUnScheduled(); + //return StoredFile::searchPlaylistsForSchedule($length, $datatables); + return StoredFile::searchPlaylistsForSchedule($datatables); } public function getShowListContent() { diff --git a/application/models/StoredFile.php b/application/models/StoredFile.php index fc62e28dd..73a2bcf64 100644 --- a/application/models/StoredFile.php +++ b/application/models/StoredFile.php @@ -1558,10 +1558,11 @@ class StoredFile { } - public static function searchPlaylistsForSchedule($p_length, $datatables) { + public static function searchPlaylistsForSchedule($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"][] = "INTERVAL '{$p_length}' > INTERVAL '00:00:00'"; $datatables["optWhere"][] = "plt.length > INTERVAL '00:00:00'"; + return StoredFile::searchFiles($fromTable, $datatables); } diff --git a/public/js/airtime/schedule/full-calendar-functions.js b/public/js/airtime/schedule/full-calendar-functions.js index 8d542509d..87388f0fd 100644 --- a/public/js/airtime/schedule/full-calendar-functions.js +++ b/public/js/airtime/schedule/full-calendar-functions.js @@ -4,6 +4,10 @@ * */ +function scheduleRefetchEvents() { + $("#schedule_calendar").fullCalendar( 'refetchEvents' ); +} + function openAddShowForm() { if(($("#add-show-form").length == 1) && ($("#add-show-form").css('display')=='none')) { @@ -221,6 +225,8 @@ function eventResize( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, vie alert(json.error); revertFunc(); } + + scheduleRefetchEvents(); }); } diff --git a/public/js/airtime/schedule/schedule.js b/public/js/airtime/schedule/schedule.js index 5fb842593..48b256a10 100644 --- a/public/js/airtime/schedule/schedule.js +++ b/public/js/airtime/schedule/schedule.js @@ -204,10 +204,6 @@ function buildEditDialog(json){ } -function scheduleRefetchEvents() { - $("#schedule_calendar").fullCalendar( 'refetchEvents' ); -} - $(window).load(function() { var mainHeight = document.documentElement.clientHeight - 200 - 50;