diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index adf84380e..a8b5b557c 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -784,7 +784,10 @@ class ScheduleController extends Zend_Controller_Action if ($success) { $scheduler = new Application_Model_Scheduler(); - $scheduler->removeGaps($data['add_show_instance_id']); + $showInstances = CcShowInstancesQuery::create()->filterByDbShowId($data['add_show_id'])->find(); + foreach ($showInstances as $si) { + $scheduler->removeGaps($si->getDbId()); + } $this->view->addNewShow = true; $this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); } else { diff --git a/airtime_mvc/application/forms/AddShowWhen.php b/airtime_mvc/application/forms/AddShowWhen.php index 86018ff1a..eb4e68a35 100644 --- a/airtime_mvc/application/forms/AddShowWhen.php +++ b/airtime_mvc/application/forms/AddShowWhen.php @@ -163,7 +163,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm } elseif (!$formData["add_show_no_end"]) { $popUntil = $formData["add_show_end_date"]." ".$formData["add_show_end_time"]; - $populateUntilDateTime = new DateTime($popUntil, new DateTimeZone('UTC')); + $populateUntilDateTime = new DateTime($popUntil); + $populateUntilDateTime->setTimezone(new DateTimeZone('UTC')); } //get repeat interval @@ -198,21 +199,33 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm $repeatShowStart->add(new DateInterval("P".$daysAdd."D")); $repeatShowEnd->add(new DateInterval("P".$daysAdd."D")); } + /* Here we are checking each repeating show by + * the show day. + * (i.e: every wednesday, then every thursday, etc.) + */ while ($repeatShowStart->getTimestamp() < $populateUntilDateTime->getTimestamp()) { - //need to get each repeating show's instance id - $qry = CcShowInstancesQuery::create() - ->filterByDbStarts($repeatShowStart->format('Y-m-d H:i:s')) - ->filterByDbEnds($repeatShowEnd->format('Y-m-d H:i:s')) - ->find(); - $count = $qry->count(); - if ($count > 1) { - $overlapping = true; - } elseif ($count == 1) { - $instanceId = $qry->getFirst()->getDbId(); - $overlapping = Application_Model_Schedule::checkOverlappingShows($repeatShowStart, $repeatShowEnd, $update, $instanceId); + if ($formData['add_show_id'] == -1) { + //this is a new show + $overlapping = Application_Model_Schedule::checkOverlappingShows( + $repeatShowStart, $repeatShowEnd); + + /* If the repeating show is rebroadcasted we need to check + * the rebroadcast dates relative to the repeating show + */ + if (!$overlapping && $formData['add_show_rebroadcast']) { + $overlapping = self::checkRebroadcastDates( + $repeatShowStart, $formData, $hours, $minutes); + } } else { - $overlapping = false; + $overlapping = Application_Model_Schedule::checkOverlappingShows( + $repeatShowStart, $repeatShowEnd, $update, null, $formData["add_show_id"]); + + if (!$overlapping && $formData['add_show_rebroadcast']) { + $overlapping = self::checkRebroadcastDates( + $repeatShowStart, $formData, $hours, $minutes, true); + } } + if ($overlapping) { $valid = false; $this->getElement('add_show_duration')->setErrors(array('Cannot schedule overlapping shows')); @@ -275,6 +288,39 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm return $valid; } + public function checkRebroadcastDates($repeatShowStart, $formData, $hours, $minutes, $showEdit=false) { + $overlapping = false; + for ($i = 1; $i <= 10; $i++) { + if (empty($formData["add_show_rebroadcast_date_".$i])) break; + $rebroadcastShowStart = clone $repeatShowStart; + /* formData is in local time so we need to set the + * show start back to local time + */ + $rebroadcastShowStart->setTimezone(new DateTimeZone( + Application_Model_Preference::GetTimezone())); + $rebroadcastWhenDays = explode(" ", $formData["add_show_rebroadcast_date_".$i]); + $rebroadcastWhenTime = explode(":", $formData["add_show_rebroadcast_time_".$i]); + $rebroadcastShowStart->add(new DateInterval("P".$rebroadcastWhenDays[0]."D")); + $rebroadcastShowStart->setTime($rebroadcastWhenTime[0], $rebroadcastWhenTime[1]); + $rebroadcastShowStart->setTimezone(new DateTimeZone('UTC')); + + $rebroadcastShowEnd = clone $rebroadcastShowStart; + $rebroadcastShowEnd->add(new DateInterval("PT".$hours."H".$minutes."M")); + + if ($showEdit) { + $overlapping = Application_Model_Schedule::checkOverlappingShows( + $rebroadcastShowStart, $rebroadcastShowEnd, true, null, $formData['add_show_id']); + } else { + $overlapping = Application_Model_Schedule::checkOverlappingShows( + $rebroadcastShowStart, $rebroadcastShowEnd); + } + + if ($overlapping) break; + } + + return $overlapping; + } + public function disable() { $elements = $this->getElements(); diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index eff64b2ec..1102efaff 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -1157,14 +1157,21 @@ SQL; } public static function checkOverlappingShows($show_start, $show_end, - $update=false, $instanceId=null) + $update=false, $instanceId=null, $showId=null) { $overlapping = false; + + $params = array( + ':show_end1' => $show_end->format('Y-m-d H:i:s'), + ':show_end2' => $show_end->format('Y-m-d H:i:s'), + ':show_end3' => $show_end->format('Y-m-d H:i:s') + ); + + /* If a show is being edited, exclude it from the query * In both cases (new and edit) we only grab shows that * are scheduled 2 days prior */ - //$se = $show_end->format('Y-m-d H:i:s'); if ($update) { $sql = <<= (date(:show_end3) - INTERVAL '2 days') AND modified_instance = FALSE +SQL; + if (is_null($showId)) { + $sql .= << $show_end->format('Y-m-d H:i:s'), - ':show_end2' => $show_end->format('Y-m-d H:i:s'), - ':show_end3' => $show_end->format('Y-m-d H:i:s'), - ':instanceId' => $instanceId - ), 'all'); + $params[':instanceId'] = $instanceId; + } else { + $sql .= << $show_end->format('Y-m-d H:i:s'), ':show_end3' => $show_end->format('Y-m-d H:i:s')), 'all'); } + foreach ($rows as $row) { $start = new DateTime($row["starts"], new DateTimeZone('UTC')); $end = new DateTime($row["ends"], new DateTimeZone('UTC')); diff --git a/airtime_mvc/application/views/scripts/form/showbuilder.phtml b/airtime_mvc/application/views/scripts/form/showbuilder.phtml index 877f28849..a0193b664 100644 --- a/airtime_mvc/application/views/scripts/form/showbuilder.phtml +++ b/airtime_mvc/application/views/scripts/form/showbuilder.phtml @@ -3,7 +3,7 @@ element->getElement('sb_date_end'); ?> element->getElement('sb_time_end'); ?> - + Find Shows
@@ -22,4 +22,4 @@
- \ No newline at end of file + diff --git a/airtime_mvc/application/views/scripts/showbuilder/index.phtml b/airtime_mvc/application/views/scripts/showbuilder/index.phtml index 3239b82f6..04851dfc4 100644 --- a/airtime_mvc/application/views/scripts/showbuilder/index.phtml +++ b/airtime_mvc/application/views/scripts/showbuilder/index.phtml @@ -11,8 +11,8 @@
disableLib && !$this->showLib):?> - - Schedule files + + Add / Remove Content sb_form; ?> diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 161d18d45..a832134c1 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -815,9 +815,10 @@ var AIRTIME = (function(AIRTIME) { //playlist screen if this is the currently edited playlist. if ((data.ftype === "playlist" || data.ftype === "block") && screen === "playlist") { callback = function() { - + aMedia = []; + aMedia.push({"id": data.id, "type": data.ftype}); if (confirm('Are you sure you want to delete the selected item?')) { - AIRTIME.playlist.fnDelete(data.id); + AIRTIME.library.fnDeleteItems(aMedia); } }; } diff --git a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js index 9f6047d9d..b640a2882 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js @@ -15,7 +15,7 @@ AIRTIME = (function(AIRTIME) { timeStartId = "#sb_time_start", dateEndId = "#sb_date_end", timeEndId = "#sb_time_end", - $toggleLib = $("Schedule files"), + $toggleLib = $("Add / Remove Content"), $libClose = $('', { "class": "close-round", "href": "#",