diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index bc56fd993..09a2495ca 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -5,7 +5,7 @@ class ScheduleController extends Zend_Controller_Action protected $sched_sess = null; - private $service_schedule; + private $service_calendar; public function init() { @@ -41,7 +41,7 @@ class ScheduleController extends Zend_Controller_Action $this->sched_sess = new Zend_Session_Namespace("schedule"); - $this->service_schedule = new Application_Service_ScheduleService(); + $this->service_calendar = new Application_Service_CalendarService(); } public function indexAction() @@ -798,12 +798,13 @@ class ScheduleController extends Zend_Controller_Action $forms = $this->createShowFormAction(); list($data, $validateStartDate, $validateStartTime, $originalShowStartDateTime) = - $this->service_schedule->preEditShowValidationCheck($data); + $this->service_calendar->preEditShowValidationCheck($data); - if ($this->service_schedule->validateShowForms($forms, $data, $validateStartDate, + if ($this->service_calendar->validateShowForms($forms, $data, $validateStartDate, $originalShowStartDateTime, true, $data["add_show_instance_id"])) { - $this->service_schedule->editShow($data); + //pass in true to indicate we are updating a show + $this->service_calendar->addUpdateShow($data, true); $scheduler = new Application_Model_Scheduler(); $showInstances = CcShowInstancesQuery::create()->filterByDbShowId($data['add_show_id'])->find(); @@ -848,8 +849,8 @@ class ScheduleController extends Zend_Controller_Action $this->view->addNewShow = true; - if ($this->service_schedule->validateShowForms($forms, $data)) { - $this->service_schedule->createShow($data); + if ($this->service_calendar->validateShowForms($forms, $data)) { + $this->service_calendar->addUpdateShow($data); $this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); //send new show forms to the user @@ -864,7 +865,7 @@ class ScheduleController extends Zend_Controller_Action public function createShowFormAction($populate=false) { - $forms = $this->service_schedule->createShowForms(); + $forms = $this->service_calendar->createShowForms(); // populate forms with default values if ($populate) { @@ -886,7 +887,7 @@ class ScheduleController extends Zend_Controller_Action public function populateNewShowFormsAction($forms) { - $this->service_schedule->populateNewShowForms( + $this->service_calendar->populateNewShowForms( $forms["what"], $forms["when"], $forms["repeats"]); } diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 17ee99bb2..8490f6295 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1169,17 +1169,17 @@ SQL; /*$isRecorded = (isset($data['add_show_record']) && $data['add_show_record']) ? 1 : 0;*/ - if ($data['add_show_id'] != -1) { + /*if ($data['add_show_id'] != -1) { $show = new Application_Model_Show($showId); //CC-4150 CULPRIT $show->deletePossiblyInvalidInstances($data, $endDate, $isRecorded, $repeatType); - } + }*/ //check if we are adding or updating a show, and if updating //erase all the show's show_days information first. - if ($data['add_show_id'] != -1) { + /*if ($data['add_show_id'] != -1) { CcShowDaysQuery::create()->filterByDbShowId($data['add_show_id'])->delete(); - } + }*/ //don't set day for monthly repeat type, it's invalid. /*if ($data['add_show_repeats'] && $data['add_show_repeat_type'] == 2) { @@ -1223,11 +1223,11 @@ SQL; //check if we are adding or updating a show, and if updating //erase all the show's future show_rebroadcast information first. - if (($data['add_show_id'] != -1) && isset($data['add_show_rebroadcast']) && $data['add_show_rebroadcast']) { + /*if (($data['add_show_id'] != -1) && isset($data['add_show_rebroadcast']) && $data['add_show_rebroadcast']) { CcShowRebroadcastQuery::create() ->filterByDbShowId($data['add_show_id']) ->delete(); - } + }*/ //adding rows to cc_show_rebroadcast /* TODO: Document magic constant 10 and define it properly somewhere --RG */ @@ -1272,9 +1272,9 @@ SQL; //check if we are adding or updating a show, and if updating //erase all the show's show_rebroadcast information first. - if ($data['add_show_id'] != -1) { + /*if ($data['add_show_id'] != -1) { CcShowHostsQuery::create()->filterByDbShow($data['add_show_id'])->delete(); - } + }*/ /*if (is_array($data['add_show_hosts'])) { //add selected hosts to cc_show_hosts table. foreach ($data['add_show_hosts'] as $host) { @@ -1285,7 +1285,7 @@ SQL; } }*/ - if ($data['add_show_id'] != -1) { + /*if ($data['add_show_id'] != -1) { $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); $con->beginTransaction(); @@ -1310,12 +1310,12 @@ SQL; Logging::info("Couldn't update schedule status."); Logging::info($e->getMessage()); } - } + }*/ /*Application_Model_Show::populateShowUntil($showId); Application_Model_RabbitMq::PushSchedule();*/ - return $showId; + /*return $showId;*/ } /** @@ -1399,39 +1399,39 @@ SQL; if ($utcStartDateTime->getTimestamp() < $p_populateUntilDateTime->getTimestamp()) { $currentUtcTimestamp = gmdate("Y-m-d H:i:s");*/ - $show = new Application_Model_Show($show_id); + /*$show = new Application_Model_Show($show_id); if ($show->hasInstance()) { $ccShowInstance = $show->getInstance(); $newInstance = false; - } /*else { + }*/ /*else { $ccShowInstance = new CcShowInstances(); $newInstance = true; }*/ - if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) { + /*if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) { $ccShowInstance->setDbShowId($show_id); $ccShowInstance->setDbStarts($utcStartDateTime); $ccShowInstance->setDbEnds($utcEndDateTime); $ccShowInstance->setDbRecord($record); $ccShowInstance->save(); - } + }*/ - $show_instance_id = $ccShowInstance->getDbId(); - $showInstance = new Application_Model_ShowInstance($show_instance_id); + /* $show_instance_id = $ccShowInstance->getDbId(); + $showInstance = new Application_Model_ShowInstance($show_instance_id);*/ - if (!$newInstance) { + /*if (!$newInstance) { $showInstance->correctScheduleStartTimes(); - } + }*/ /*$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id"; $rebroadcasts = Application_Common_Database::prepareAndExecute($sql, array( ':show_id' => $show_id ), 'all');*/ - if ($showInstance->isRecorded()) { + /*if ($showInstance->isRecorded()) { //only do this for editing $showInstance->deleteRebroadcasts(); self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone); - } + }*/ /*}*/ } @@ -1471,21 +1471,21 @@ SQL; //convert $last_show into a UTC DateTime object, or null if there is no last show. $utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;*/ - $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id"; + /*$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id"; $rebroadcasts = Application_Common_Database::prepareAndExecute( $sql, array( ':show_id' => $show_id ), 'all'); - $show = new Application_Model_Show($show_id); + $show = new Application_Model_Show($show_id);*/ - while ($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp() - && (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){ + /*while ($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp() + && (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){*/ - list($utcStartDateTime, $utcEndDateTime) = self::createUTCStartEndDateTime($start, $duration, $timezone); + /*list($utcStartDateTime, $utcEndDateTime) = self::createUTCStartEndDateTime($start, $duration, $timezone);*/ //determine if we are adding a new show //or editing a show - if ($show->hasInstanceOnDate($utcStartDateTime)) { + /* if ($show->hasInstanceOnDate($utcStartDateTime)) { $ccShowInstance = $show->getInstanceOnDate($utcStartDateTime); if ($ccShowInstance->getDbModifiedInstance()) { @@ -1498,12 +1498,12 @@ SQL; } else { $ccShowInstance = new CcShowInstances(); $newInstance = true; - } + }*/ /* When editing the start/end time of a repeating show, we don't want to * change shows that started in the past. So check the start time. */ - if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) { + /*if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) { $ccShowInstance->setDbShowId($show_id); $ccShowInstance->setDbStarts($utcStartDateTime); $ccShowInstance->setDbEnds($utcEndDateTime); @@ -1513,21 +1513,22 @@ SQL; $show_instance_id = $ccShowInstance->getDbId(); - $showInstance = new Application_Model_ShowInstance($show_instance_id); + $showInstance = new Application_Model_ShowInstance($show_instance_id);*/ /* If we are updating a show then make sure that the scheduled content within * the show is updated to the correct time. */ - if (!$newInstance) { + // don't we already do this in deletePossiblyInvalidInstances??? + /*if (!$newInstance) { $showInstance->correctScheduleStartTimes(); - } + }*/ - $showInstance->deleteRebroadcasts(); + /*$showInstance->deleteRebroadcasts(); self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone); - list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone); + list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone);*/ - } + /*}*/ - Application_Model_Show::setNextPop($start, $show_id, $day); + /*Application_Model_Show::setNextPop($start, $show_id, $day);*/ } private static function advanceRepeatingDate($p_interval, $start, $timezone) @@ -1581,7 +1582,7 @@ SQL; */ private static function createUTCStartEndDateTime($p_start, $p_duration, $p_timezone=null, $p_offset=null) { - $timezone = $p_timezone ? $p_timezone : date_default_timezone_get(); + /*$timezone = $p_timezone ? $p_timezone : date_default_timezone_get(); $startDateTime = new DateTime($p_start, new DateTimeZone($timezone)); if (isset($p_offset)) { @@ -1595,7 +1596,7 @@ SQL; list($hours, $mins) = array_slice($duration, 0, 2); $endDateTime->add(new DateInterval("PT{$hours}H{$mins}M")); - return array($startDateTime, $endDateTime); + return array($startDateTime, $endDateTime);*/ } /* Create rebroadcast instances for a created show marked for recording @@ -1621,7 +1622,7 @@ SQL; { //Y-m-d //use only the date part of the show start time stamp for the offsets to work properly. - $date = explode(" ", $p_startTime); + /*$date = explode(" ", $p_startTime); $start_date = $date[0]; foreach ($p_rebroadcasts as $rebroadcast) { @@ -1643,7 +1644,7 @@ SQL; $newRebroadcastInstance->setDbOriginalShow($p_showInstanceId); $newRebroadcastInstance->save(); } - } + }*/ } /** diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php new file mode 100644 index 000000000..a03fd734b --- /dev/null +++ b/airtime_mvc/application/services/CalendarService.php @@ -0,0 +1,271 @@ +service_show = new Application_Service_ShowService(); + $this->service_showInstances = new Application_Service_ShowInstanceService(); + $this->service_user = new Application_Service_UserService(); + } +/* + * Form stuff begins here + * Typically I would keep form creation and validation + * in the controller but since shows require 9 forms, + * the controller will become too fat. + * Maybe we should create a special form show service? + */ + /** + * + * @return array of schedule forms + */ + public function createShowForms() + { + $formWhat = new Application_Form_AddShowWhat(); + $formWho = new Application_Form_AddShowWho(); + $formWhen = new Application_Form_AddShowWhen(); + $formRepeats = new Application_Form_AddShowRepeats(); + $formStyle = new Application_Form_AddShowStyle(); + $formLive = new Application_Form_AddShowLiveStream(); + $formRecord = new Application_Form_AddShowRR(); + $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates(); + $formRebroadcast = new Application_Form_AddShowRebroadcastDates(); + + $formWhat->removeDecorator('DtDdWrapper'); + $formWho->removeDecorator('DtDdWrapper'); + $formWhen->removeDecorator('DtDdWrapper'); + $formRepeats->removeDecorator('DtDdWrapper'); + $formStyle->removeDecorator('DtDdWrapper'); + $formLive->removeDecorator('DtDdWrapper'); + $formRecord->removeDecorator('DtDdWrapper'); + $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper'); + $formRebroadcast->removeDecorator('DtDdWrapper'); + + $forms = array(); + $forms["what"] = $formWhat; + $forms["who"] = $formWho; + $forms["when"] = $formWhen; + $forms["repeats"] = $formRepeats; + $forms["style"] = $formStyle; + $forms["live"] = $formLive; + $forms["record"] = $formRecord; + $forms["abs_rebroadcast"] = $formAbsoluteRebroadcast; + $forms["rebroadcast"] = $formRebroadcast; + + return $forms; + } + + /** + * + * Popluates the what, when, and repeat forms + * with default values + */ + public function populateNewShowForms($formWhat, $formWhen, $formRepeats) + { + $formWhat->populate( + array('add_show_id' => '-1', + 'add_show_instance_id' => '-1')); + + $formWhen->populate( + array('add_show_start_date' => date("Y-m-d"), + 'add_show_start_time' => '00:00', + 'add_show_end_date_no_repeate' => date("Y-m-d"), + 'add_show_end_time' => '01:00', + 'add_show_duration' => '01h 00m')); + + $formRepeats->populate(array('add_show_end_date' => date("Y-m-d"))); + } + + public function populateForm($form, $values) + { + $form->populate($values); + } + + /** + * + * Validates show forms + * + * @return boolean + */ + public function validateShowForms($forms, $formData, $validateStartDate = true, + $originalStartDate=null, $editShow=false, $instanceId=null) + { + $what = $forms["what"]->isValid($formData); + $live = $forms["live"]->isValid($formData); + $record = $forms["record"]->isValid($formData); + $who = $forms["who"]->isValid($formData); + $style = $forms["style"]->isValid($formData); + $when = $forms["when"]->isWhenFormValid($formData, $validateStartDate, + $originalStartDate, $editShow, $instanceId); + + $repeats = true; + if ($formData["add_show_repeats"]) { + $repeats = $forms["repeats"]->isValid($formData); + + /* + * Make the absolute rebroadcast form valid since + * it does not get used if the show is repeating + */ + $forms["abs_rebroadcast"]->reset(); + $absRebroadcast = true; + + $rebroadcast = true; + if ($formData["add_show_rebroadcast"]) { + $formData["add_show_duration"] = $this->formatShowDuration( + $formData["add_show_duration"]); + $rebroadcast = $forms["rebroadcast"]->isValid($formData); + } + } else { + /* + * Make the rebroadcast form valid since it does + * not get used if the show is not repeating. + * Instead, we use the absolute rebroadcast form + */ + $forms["rebroadcast"]->reset(); + $rebroadcast = true; + + $absRebroadcast = true; + if ($formData["add_show_rebroadcast"]) { + $formData["add_show_duration"] = $this->formatShowDuration( + $formData["add_show_duration"]); + $absRebroadcast = $forms["abs_rebroadcast"]->isValid($formData); + } + } + + if ($what && $live && $record && $who && $style && $when && + $repeats && $absRebroadcast && $rebroadcast) { + return true; + } else { + return false; + } + } +/* + * Form stuff ends + */ + + public function formatShowDuration($duration) { + $hPos = strpos($duration, 'h'); + $mPos = strpos($duration, 'm'); + + $hValue = 0; + $mValue = 0; + + if ($hPos !== false) { + $hValue = trim(substr($duration, 0, $hPos)); + } + if ($mPos !== false) { + $hPos = $hPos === false ? 0 : $hPos+1; + $mValue = trim(substr($duration, $hPos, -1 )); + } + + return $hValue.":".$mValue; + } + + public function addUpdateShow($showData, $isUpdate=false) + { + //CcSubj object + $currentUser = $this->service_user->getCurrentUser(); + + $repeatType = ($showData['add_show_repeats']) ? $showData['add_show_repeat_type'] : -1; + $isRecorded = (isset($showData['add_show_record']) && $showData['add_show_record']) ? 1 : 0; + $isRebroadcast = (isset($showData['add_show_rebroadcast']) && $showData['add_show_rebroadcast']) ? 1 : 0; + + $showData["add_show_duration"] = $this->formatShowDuration( + $showData["add_show_duration"]); + + $con = Propel::getConnection(); + $con->beginTransaction(); + try { + if (!$currentUser->isAdminOrPM()) { + throw new Exception("Permission denied"); + } + //update ccShow + $ccShow = $this->service_show->setShow($showData, $isUpdate); + $showId = $ccShow->getDbId(); + + if ($isUpdate) { + $this->service_showInstances->deleteInvalidInstances($showData, $isRecorded, $repeatType); + $this->service_showInstances->updateScheduleStatus($showId); + $this->service_showInstances->deleteRebroadcastInstances($showId); + $this->service_showDays->deleteShowDays(); + $this->service_show->deleteShowHosts($showId); + if ($isRebroadcast) { + //delete entry in cc_show_rebroadcast + $this->service_show->deleteShowRebroadcasts($showId); + } + } + + //update ccShowDays + $this->service_showDays = new Application_Service_ShowDaysService($showId); + $this->service_showDays->setShowDays($showData, $repeatType, $isRecorded); + + //update ccShowRebroadcasts + $this->service_show->setShowRebroadcasts($showData, $showId, $repeatType, $isRecorded); + + //update ccShowHosts + $this->service_show->setShowHosts($showData, $showId); + + //create new ccShowInstances + $this->service_showInstances->delegateShowInstanceCreation($showId, $isRebroadcast, $isUpdate); + + $con->commit(); + Application_Model_RabbitMq::PushSchedule(); + } catch (Exception $e) { + $con->rollback(); + $isUpdate ? $action = "update" : $action = "creation"; + Logging::info("EXCEPTION: Show ".$action." failed."); + Logging::info($e->getMessage()); + } + } + + /** + * + * Before we send the form data in for validation, there + * are a few fields we may need to adjust first + * @param $formData + */ + public function preEditShowValidationCheck($formData) { + $validateStartDate = true; + $validateStartTime = true; + $this->service_showDays = new Application_Service_ShowDaysService( + $formData["add_show_id"]); + + //CcShowDays object of the show currently being edited + $currentShowDay = $this->service_showDays->getCurrentShowDay(); + + if (!array_key_exists('add_show_start_date', $formData)) { + //Changing the start date was disabled, since the + //array key does not exist. We need to repopulate this entry from the db. + //The start date will be returned in UTC time, so lets convert it to local time. + $dt = Application_Common_DateHelper::ConvertToLocalDateTime( + $this->service_showDays->getStartDateAndTime()); + $formData['add_show_start_date'] = $dt->format("Y-m-d"); + + if (!array_key_exists('add_show_start_time', $formData)) { + $formData['add_show_start_time'] = $dt->format("H:i"); + $validateStartTime = false; + } + $validateStartDate = false; + } + $formData['add_show_record'] = $currentShowDay->getDbRecord(); + + //if the show is repeating, set the start date to the next + //repeating instance in the future + if ($currentShowDay->isRepeating()) { + $nextFutureRepeatShow = $this->service_showInstances + ->getNextFutureRepeatShowTime($formData["add_show_id"]); + $originalShowStartDateTime = $nextFutureRepeatShow["starts"]; + } else { + $originalShowStartDateTime = Application_Common_DateHelper::ConvertToLocalDateTime( + $this->service_showDays->getStartDateAndTime()); + } + + return array($formData, $validateStartDate, $validateStartTime, $originalShowStartDateTime); + } + +} \ No newline at end of file diff --git a/airtime_mvc/application/services/ScheduleService.php b/airtime_mvc/application/services/ScheduleService.php index 72304cdb7..9ff581542 100644 --- a/airtime_mvc/application/services/ScheduleService.php +++ b/airtime_mvc/application/services/ScheduleService.php @@ -1,276 +1,26 @@ service_show = new Application_Service_ShowService(); - $this->service_showInstances = new Application_Service_ShowInstanceService(); - $this->service_user = new Application_Service_UserService(); - } -/* - * Form stuff begins here - * Typically I would keep form creation and validation - * in the controller but since shows require 9 forms, - * the controller will become too fat. - * Maybe we should create a special form show service? - */ /** * - * @return array of schedule forms + * Enter description here ... + * @param array $instanceIds */ - public function createShowForms() + public static function updateScheduleStartTime($instanceIds, $diff) { - $formWhat = new Application_Form_AddShowWhat(); - $formWho = new Application_Form_AddShowWho(); - $formWhen = new Application_Form_AddShowWhen(); - $formRepeats = new Application_Form_AddShowRepeats(); - $formStyle = new Application_Form_AddShowStyle(); - $formLive = new Application_Form_AddShowLiveStream(); - $formRecord = new Application_Form_AddShowRR(); - $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates(); - $formRebroadcast = new Application_Form_AddShowRebroadcastDates(); + if (count($instanceIds) > 0 && $diff != 0) { + $showIdList = implode(",", $instanceIds); + $sql = <<removeDecorator('DtDdWrapper'); - $formWho->removeDecorator('DtDdWrapper'); - $formWhen->removeDecorator('DtDdWrapper'); - $formRepeats->removeDecorator('DtDdWrapper'); - $formStyle->removeDecorator('DtDdWrapper'); - $formLive->removeDecorator('DtDdWrapper'); - $formRecord->removeDecorator('DtDdWrapper'); - $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper'); - $formRebroadcast->removeDecorator('DtDdWrapper'); - - $forms = array(); - $forms["what"] = $formWhat; - $forms["who"] = $formWho; - $forms["when"] = $formWhen; - $forms["repeats"] = $formRepeats; - $forms["style"] = $formStyle; - $forms["live"] = $formLive; - $forms["record"] = $formRecord; - $forms["abs_rebroadcast"] = $formAbsoluteRebroadcast; - $forms["rebroadcast"] = $formRebroadcast; - - return $forms; - } - - /** - * - * Popluates the what, when, and repeat forms - * with default values - */ - public function populateNewShowForms($formWhat, $formWhen, $formRepeats) - { - $formWhat->populate( - array('add_show_id' => '-1', - 'add_show_instance_id' => '-1')); - - $formWhen->populate( - array('add_show_start_date' => date("Y-m-d"), - 'add_show_start_time' => '00:00', - 'add_show_end_date_no_repeate' => date("Y-m-d"), - 'add_show_end_time' => '01:00', - 'add_show_duration' => '01h 00m')); - - $formRepeats->populate(array('add_show_end_date' => date("Y-m-d"))); - } - - public function populateForm($form, $values) - { - $form->populate($values); - } - - /** - * - * Validates show forms - * - * @return boolean - */ - public function validateShowForms($forms, $formData, $validateStartDate = true, - $originalStartDate=null, $editShow=false, $instanceId=null) - { - $what = $forms["what"]->isValid($formData); - $live = $forms["live"]->isValid($formData); - $record = $forms["record"]->isValid($formData); - $who = $forms["who"]->isValid($formData); - $style = $forms["style"]->isValid($formData); - $when = $forms["when"]->isWhenFormValid($formData, $validateStartDate, - $originalStartDate, $editShow, $instanceId); - - $repeats = true; - if ($formData["add_show_repeats"]) { - $repeats = $forms["repeats"]->isValid($formData); - - /* - * Make the absolute rebroadcast form valid since - * it does not get used if the show is repeating - */ - $forms["abs_rebroadcast"]->reset(); - $absRebroadcast = true; - - $rebroadcast = true; - if ($formData["add_show_rebroadcast"]) { - $formData["add_show_duration"] = $this->formatShowDuration( - $formData["add_show_duration"]); - $rebroadcast = $forms["rebroadcast"]->isValid($formData); - } - } else { - /* - * Make the rebroadcast form valid since it does - * not get used if the show is not repeating. - * Instead, we use the absolute rebroadcast form - */ - $forms["rebroadcast"]->reset(); - $rebroadcast = true; - - $absRebroadcast = true; - if ($formData["add_show_rebroadcast"]) { - $formData["add_show_duration"] = $this->formatShowDuration( - $formData["add_show_duration"]); - $absRebroadcast = $forms["abs_rebroadcast"]->isValid($formData); - } - } - - if ($what && $live && $record && $who && $style && $when && - $repeats && $absRebroadcast && $rebroadcast) { - return true; - } else { - return false; + Application_Common_Database::prepareAndExecute($sql, + array(':diff1' => $diff, ':diff2' => $diff, + ':showIds' => $showIdList), + 'execute'); } } -/* - * Form stuff ends - */ - - public function formatShowDuration($duration) { - $hPos = strpos($duration, 'h'); - $mPos = strpos($duration, 'm'); - - $hValue = 0; - $mValue = 0; - - if ($hPos !== false) { - $hValue = trim(substr($duration, 0, $hPos)); - } - if ($mPos !== false) { - $hPos = $hPos === false ? 0 : $hPos+1; - $mValue = trim(substr($duration, $hPos, -1 )); - } - - return $hValue.":".$mValue; - } - - /** - * - * Creates a new show, which entails creating entries in - * the following tables: - * cc_show - * cc_show_days - * cc_show_hosts - * cc_show_rebroadcast - * cc_show_instances - */ - public function createShow($showData) - { - //CcSubj object - $currentUser = $this->service_user->getCurrentUser(); - - $repeatType = ($showData['add_show_repeats']) ? $showData['add_show_repeat_type'] : -1; - $isRecorded = (isset($showData['add_show_record']) && $showData['add_show_record']) ? 1 : 0; - $isRebroadcast = (isset($showData['add_show_rebroadcast']) && $showData['add_show_rebroadcast']) ? 1 : 0; - - $showData["add_show_duration"] = $this->formatShowDuration( - $showData["add_show_duration"]); - - if ($currentUser->isAdminOrPM()) { - //create ccShow - $ccShow = $this->service_show->setShow($showData, true); - $showId = $ccShow->getDbId(); - - //create ccShowDays - $this->service_showDays = new Application_Service_ShowDaysService($showId); - $this->service_showDays->setShowDays( - $showData, $currentUser->getDbId(), $repeatType, $isRecorded); - - //create ccShowRebroadcasts - $this->service_show->setShowRebroadcasts($showData, $showId, $repeatType, $isRecorded); - - //create ccShowHosts - $this->service_show->setShowHosts($showData, $showId); - - //create ccShowInstances - $this->service_showInstances->delegateShowInstanceCreation($showId, $isRebroadcast); - } - } - - public function editShow($showData) - { - //CcSubj object - $currentUser = $this->service_user->getCurrentUser(); - - $repeatType = ($showData['add_show_repeats']) ? $showData['add_show_repeat_type'] : -1; - $isRecorded = (isset($showData['add_show_record']) && $showData['add_show_record']) ? 1 : 0; - $isRebroadcast = (isset($showData['add_show_rebroadcast']) && $showData['add_show_rebroadcast']) ? 1 : 0; - - $showData["add_show_duration"] = $this->formatShowDuration( - $showData["add_show_duration"]); - - if ($currentUser->isAdminOrPM()) { - $ccShow = $this->service_show->setShow($showData, false); - - $this->service_showInstances->updateShowInstances($showData, $isRecorded, $repeatType); - } - } - - /** - * - * Before we send the form data in for validation, there - * are a few fields we may need to adjust first - * @param $formData - */ - public function preEditShowValidationCheck($formData) { - $validateStartDate = true; - $validateStartTime = true; - $this->service_showDays = new Application_Service_ShowDaysService( - $formData["add_show_id"]); - - //CcShowDays object of the show currently being edited - $currentShowDay = $this->service_showDays->getCurrentShowDay(); - - if (!array_key_exists('add_show_start_date', $formData)) { - //Changing the start date was disabled, since the - //array key does not exist. We need to repopulate this entry from the db. - //The start date will be returned in UTC time, so lets convert it to local time. - $dt = Application_Common_DateHelper::ConvertToLocalDateTime( - $this->service_showDays->getStartDateAndTime()); - $formData['add_show_start_date'] = $dt->format("Y-m-d"); - - if (!array_key_exists('add_show_start_time', $formData)) { - $formData['add_show_start_time'] = $dt->format("H:i"); - $validateStartTime = false; - } - $validateStartDate = false; - } - $formData['add_show_record'] = $currentShowDay->getDbRecord(); - - //if the show is repeating, set the start date to the next - //repeating instance in the future - if ($currentShowDay->isRepeating()) { - $nextFutureRepeatShow = $this->service_showInstances - ->getNextFutureRepeatShowTime($formData["add_show_id"]); - $originalShowStartDateTime = $nextFutureRepeatShow["starts"]; - } else { - $originalShowStartDateTime = Application_Common_DateHelper::ConvertToLocalDateTime( - $this->service_showDays->getStartDateAndTime()); - } - - return array($formData, $validateStartDate, $validateStartTime, $originalShowStartDateTime); - } - } \ No newline at end of file diff --git a/airtime_mvc/application/services/ShowDaysService.php b/airtime_mvc/application/services/ShowDaysService.php index b22fd4292..07616b552 100644 --- a/airtime_mvc/application/services/ShowDaysService.php +++ b/airtime_mvc/application/services/ShowDaysService.php @@ -9,6 +9,17 @@ class Application_Service_ShowDaysService $this->showId = $id; } + /** + * + * Deletes all the cc_show_days entries for a specific show + * that is currently being edited. They will get recreated with + * the new show day specs + */ + public function deleteShowDays() + { + CcShowDaysQuery::create()->filterByDbShowId($this->showId)->delete(); + } + /** * * Determines what the show end date should be based on @@ -22,13 +33,11 @@ class Application_Service_ShowDaysService if ($showData['add_show_no_end']) { $endDate = NULL; } elseif ($showData['add_show_repeats']) { - $endDateTime = new DateTime($showData['add_show_end_date']); - $endDateTime->add(new DateInterval("P1D")); - $endDate = $endDateTime->format("Y-m-d"); + $endDate = new DateTime($showData['add_show_end_date']); + $endDate->add(new DateInterval("P1D")); } else { - $endDateTime = new DateTime($showData['add_show_start_date']); - $endDateTime->add(new DateInterval("P1D")); - $endDate = $endDateTime->format("Y-m-d"); + $endDate = new DateTime($showData['add_show_start_date']); + $endDate->add(new DateInterval("P1D")); } return $endDate; @@ -42,12 +51,18 @@ class Application_Service_ShowDaysService * @param $userId * @param $repeatType * @param $isRecorded + * @param $showDay ccShowDay object we are setting values on */ - public function setShowDays($showData, $userId, $repeatType, $isRecorded) + public function setShowDays($showData, $repeatType, $isRecorded) { $startDateTime = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time']); - $endDate = $this->calculateEndDate($showData); + $endDateTime = $this->calculateEndDate($showData); + if (!is_null($endDateTime)) { + $endDate = $endDateTime->format("Y-m-d"); + } else { + $endDate = $endDateTime; + } /* What we are doing here is checking if the show repeats or if * any repeating days have been checked. If not, then by default @@ -67,7 +82,7 @@ class Application_Service_ShowDaysService $showDay->setDbFirstShow($startDateTime->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTime->format("H:i:s")); - $showDay->setDbTimezone(Application_Model_Preference::GetUserTimezone($userId)); + $showDay->setDbTimezone(Application_Model_Preference::GetTimezone()); $showDay->setDbDuration($showData['add_show_duration']); $showDay->setDbRepeatType($repeatType); $showDay->setDbShowId($this->showId); @@ -90,7 +105,7 @@ class Application_Service_ShowDaysService $showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTimeClone->format("H:i")); - $showDay->setDbTimezone(Application_Model_Preference::GetUserTimezone($userId)); + $showDay->setDbTimezone(Application_Model_Preference::GetTimezone()); $showDay->setDbDuration($showData['add_show_duration']); $showDay->setDbDay($day); $showDay->setDbRepeatType($repeatType); @@ -110,10 +125,6 @@ class Application_Service_ShowDaysService */ public function getShowDays() { - /*$sql = "SELECT * FROM cc_show_days WHERE show_id = :show_id"; - - return Application_Common_Database::prepareAndExecute( - $sql, array(":show_id" => $this->showId), 'all');*/ return CcShowDaysQuery::create()->filterByDbShowId( $this->showId)->find(); } @@ -140,4 +151,31 @@ class Application_Service_ShowDaysService return CcShowDaysQuery::create()->filterByDbShowId($this->showId) ->findOne(); } + + public function getRepeatingEndDate() + { + $sql = << $this->showId ), 'column' ); + + return ($query !== false) ? $query : false; + } + + public function getNextStartDateTime($showDay) + { + $nextPopDate = $showDay->getDbNextPopDate(); + $startTime = $showDay->getDbStartTime(); + + if (isset($nextPopDate)) { + return $nextPopDate." ".$startTime; + } else { + return $showDay->getDbFirstShow()." ".$startTime; + } + } } \ No newline at end of file diff --git a/airtime_mvc/application/services/ShowInstanceService.php b/airtime_mvc/application/services/ShowInstanceService.php index ccd6f3c0b..b6701e705 100644 --- a/airtime_mvc/application/services/ShowInstanceService.php +++ b/airtime_mvc/application/services/ShowInstanceService.php @@ -22,7 +22,7 @@ class Application_Service_ShowInstanceService * Receives a cc_show id and determines whether to create a * single show instance or repeating show instances */ - public function delegateShowInstanceCreation($showId, $isRebroadcast) + public function delegateShowInstanceCreation($showId, $isRebroadcast, $isUpdate) { $populateUntil = $this->service_show->getPopulateShowUntilDateTIme(); @@ -32,10 +32,10 @@ class Application_Service_ShowInstanceService foreach ($showDays as $day) { switch ($day->getDbRepeatType()) { case NO_REPEAT: - $this->createNonRepeatingShowInstance($day, $populateUntil, $isRebroadcast); + $this->createNonRepeatingShowInstance($day, $populateUntil, $isRebroadcast, $isUpdate); break; case REPEAT_WEEKLY: - $this->createWeeklyRepeatingShowInstances($day, $populateUntil, "P7D", $isRebroadcast); + $this->createWeeklyRepeatingShowInstances($day, $populateUntil, "P7D", $isRebroadcast, $isUpdate); break; case REPEAT_BI_WEEKLY: $this->createWeeklyRepeatingShowInstances($day, $populateUntil, "P14D", $isRebroadcast); @@ -57,7 +57,7 @@ class Application_Service_ShowInstanceService * @param $showDay * @param $populateUntil */ - private function createNonRepeatingShowInstance($showDay, $populateUntil, $isRebroadcast) + private function createNonRepeatingShowInstance($showDay, $populateUntil, $isRebroadcast, $isUpdate) { $start = $showDay->getDbFirstShow()." ".$showDay->getDbStartTime(); @@ -66,6 +66,15 @@ class Application_Service_ShowInstanceService if ($utcStartDateTime->getTimestamp() < $populateUntil->getTimestamp()) { $ccShowInstance = new CcShowInstances(); + if ($isUpdate) { + $ccShowInstance = $this->getInstance($utcStartDateTime, $showDay->getDbShowId()); + //update schedule start times + //ccShowDays object of the show being edited + $currentShowDay = $this->service_showDays->getCurrentShowDay(); + $diff = $this->calculateShowStartDiff($utcStartDateTime, + $currentShowDay->getUTCStartDateAndTime()); + Application_Service_ScheduleService::updateScheduleStartTime(array($ccShowInstance->getDbId()), $diff); + } $ccShowInstance->setDbShowId($showDay->getDbShowId()); $ccShowInstance->setDbStarts($utcStartDateTime); $ccShowInstance->setDbEnds($utcEndDateTime); @@ -87,35 +96,26 @@ class Application_Service_ShowInstanceService * @param unknown_type $isRebroadcast */ private function createWeeklyRepeatingShowInstances($showDay, $populateUntil, - $repeatInterval, $isRebroadcast) + $repeatInterval, $isRebroadcast, $isUpdate) { $show_id = $showDay->getDbShowId(); - $next_pop_date = $showDay->getDbNextPopDate(); $first_show = $showDay->getDbFirstShow(); //non-UTC $last_show = $showDay->getDbLastShow(); //non-UTC - $start_time = $showDay->getDbStartTime(); //non-UTC $duration = $showDay->getDbDuration(); $day = $showDay->getDbDay(); $record = $showDay->getDbRecord(); $timezone = $showDay->getDbTimezone(); - $currentUtcTimestamp = gmdate("Y-m-d H:i:s"); + $start = $this->service_showDays->getNextStartDateTime($showDay); - if (isset($next_pop_date)) { - $start = $next_pop_date." ".$start_time; - } else { - $start = $first_show." ".$start_time; - } - - $period = $this->getDatePeriod($start, $timezone, $last_show, + $datePeriod = $this->getDatePeriod($start, $timezone, $last_show, $repeatInterval, $populateUntil); - $utcStartDateTime = Application_Common_DateHelper::ConvertToUtcDateTime($start, $timezone); $utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null; $utcEndDateTime = null; - foreach ($period as $date) { + foreach ($datePeriod as $date) { list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime( $date->format("Y-m-d H:i:s"), $duration, $timezone); /* @@ -127,14 +127,23 @@ class Application_Service_ShowInstanceService $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) ) { $ccShowInstance = new CcShowInstances(); - $ccShowInstance->setDbShowId($show_id); - $ccShowInstance->setDbStarts($utcStartDateTime); - $ccShowInstance->setDbEnds($utcEndDateTime); - $ccShowInstance->setDbRecord($record); - $ccShowInstance->save(); + if ($isUpdate) { + $ccShowInstance = $this->getInstance($utcStartDateTime, $show_id); + } + + /* When editing the start/end time of a repeating show, we don't want to + * change shows that started in the past. So check the start time. + */ + if (!$isUpdate || $ccShowInstance->getDbStarts() > gmdate("Y-m-d H:i:s")) { + $ccShowInstance->setDbShowId($show_id); + $ccShowInstance->setDbStarts($utcStartDateTime); + $ccShowInstance->setDbEnds($utcEndDateTime); + $ccShowInstance->setDbRecord($record); + $ccShowInstance->save(); + } if ($isRebroadcast) { - $this->createRebroadcastShowInstances($showDay, $date->format("Y-m-d"), $ccShowInstance->getDbId()); + $this->createRebroadcastInstances($showDay, $date->format("Y-m-d"), $ccShowInstance->getDbId()); } } } @@ -147,10 +156,10 @@ class Application_Service_ShowInstanceService * Enter description here ... * @param $showDay */ - private function createRebroadcastShowInstances($showDay, $showStartDate, $instanceId) + private function createRebroadcastInstances($showDay, $showStartDate, $instanceId) { $currentUtcTimestamp = gmdate("Y-m-d H:i:s"); - $showId = $showDay["show_id"]; + $showId = $showDay->getDbShowId(); $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id"; $rebroadcasts = Application_Common_Database::prepareAndExecute($sql, @@ -162,7 +171,7 @@ class Application_Service_ShowInstanceService $offset = array("days"=>$days[0], "hours"=>$time[0], "mins"=>$time[1]); list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime( - $showStartDate, $showDay["duration"], $showDay["timezone"], $offset); + $showStartDate, $showDay->getDbDuration(), $showDay->getDbTimezone(), $offset); if ($utcStartDateTime->format("Y-m-d H:i:s") > $currentUtcTimestamp) { $ccShowInstance = new CcShowInstances(); @@ -177,9 +186,30 @@ class Application_Service_ShowInstanceService } } - private function deleteRebroadcastShowInstances() + public function updateScheduleStatus($showId) { + $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); + $instances = CcShowInstancesQuery::create() + ->filterByDbEnds(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN) + ->filterByDbShowId($showId) + ->find(); + foreach ($instances as $instance) { + $instance->updateScheduleStatus($con); + } + } + + public function deleteRebroadcastInstances($showId) + { + $sql = << :timestamp::TIMESTAMP +AND show_id = :showId +AND rebroadcast = 1; +SQL; + Application_Common_Database::prepareAndExecute( $sql, array( + ':showId' => $showId, + ':timestamp' => gmdate("Y-m-d H:i:s")), 'execute'); } /** @@ -231,7 +261,80 @@ SQL; } /** - * This function is messy. But sometimes there is no easy way to do it. + * + * Returns all the show instances of the show currently + * being edited. + * @param $showId + */ + public function getCurrentInstances($showId) + { + return CcShowInstancesQuery::create() + ->filterByDbShowId($showId) + ->filterByDbModifiedInstance(false) + ->orderBy("starts"); + } + + /** + * + * Attempts to retrieve the cc_show_instance belonging to a cc_show + * that starts at $starts. We have to pass in the start + * time in case the show is repeating + * + * Returns the instance if one was found (one that is not a recording + * and modified instance is false (has not been deleted)) + */ + public function getInstance($starts, $showId) + { + $ccShowInstance = CcShowInstancesQuery::create() + ->filterByDbStarts($starts->format("Y-m-d H:i:s"), Criteria::EQUAL) + ->filterByDbShowId($showId, Criteria::EQUAL) + ->filterByDbModifiedInstance(false, Criteria::EQUAL) + ->filterByDbRebroadcast(0, Criteria::EQUAL) + ->limit(1) + ->find(); + + if ($ccShowInstance->isEmpty()) { + throw new Exception("Show instance not found"); + } + + return $ccShowInstance[0]; + } + + public function getAllFutureInstanceIds($showId) + { + $sql = << :timestamp::TIMESTAMP + AND modified_instance != TRUE +SQL; + $rows = Application_Common_Database::prepareAndExecute($sql, + array( ':showId' => $showId, + ':timestamp' => gmdate("Y-m-d H:i:s")), "all"); + + $ids = array(); + foreach ($ids as $id) { + $ids[] = $id['id']; + } + return $ids; + } + + /** + * + * Returns the difference in seconds between a show's new and + * old start time + * + * @param $newStartDateTime DateTime object + * @param $oldStartDateTime DateTime object + */ + public function calculateShowStartDiff($newStartDateTime, $oldStartDateTime) + { + return $newStartDateTime->getTimestamp() - $oldStartDateTime->getTimestamp(); + } + + /** + * TODO: This function is messy. Needs refactoring * * When editing a show we may need to perform some actions to reflect the new specs: * - Delete some show instances @@ -242,7 +345,7 @@ SQL; * @param $isRecorded value computed from the edit show form * @param $repeatType value computed from the edit show form */ - public function updateShowInstances($showData, $isRecorded, $repeatType) + public function deleteInvalidInstances($showData, $isRecorded, $repeatType) { $showId = $showData["add_show_id"]; @@ -250,7 +353,13 @@ SQL; //ccShowDays object of the show being edited $currentShowDay = $this->service_showDays->getCurrentShowDay(); - $endDate = $this->service_showDays->calculateEndDate($showData); + //new end date in users' local time + $endDateTime = $this->service_showDays->calculateEndDate($showData); + if (!is_null($endDateTime)) { + $endDate = $endDateTime->format("Y-m-d"); + } else { + $endDate = $endDateTime; + } //repeat option was toggled if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) { @@ -258,9 +367,9 @@ SQL; } //duration has changed - if ($showData['add_show_duration'] != $currentShowDay->getDbDuration()) { - $this->updateDuration($showData); - } + /*if ($showData['add_show_duration'] != $currentShowDay->getDbDuration()) { + $this->updateInstanceDuration($showData); + }*/ if ($showData['add_show_repeats']) { @@ -315,7 +424,7 @@ SQL; } if ($showData['add_show_start_date'] != $localShowStart->format("Y-m-d") - || $showData['add_show_start_time'] != $localShowStart->format("H:i:s")){ + || $showData['add_show_start_time'] != $localShowStart->format("H:i")) { //start date has been pushed forward so we need to delete //any instances of this show scheduled before the new start date @@ -323,70 +432,65 @@ SQL; $this->deleteInstancesBeforeDate($showData['add_show_start_date'], $showId); } - $this->updateStartDateAndTime($showData, $currentShowDay); + } } -/* - //Check if end date for the repeat option has changed. If so, need to take care - //of deleting possible invalid Show Instances. - if ((strlen($this->getRepeatingEndDate()) == 0) == $showData['add_show_no_end']) { - //show "Never Ends" option was toggled. - if ($showData['add_show_no_end']) { - } else { - $this->removeAllInstancesFromDate($p_endDate); - } - } - if ($this->getRepeatingEndDate() != $showData['add_show_end_date']) { - //end date was changed. - $newDate = strtotime($showData['add_show_end_date']); - $oldDate = strtotime($this->getRepeatingEndDate()); - if ($newDate < $oldDate) { - $this->removeAllInstancesFromDate($p_endDate); + $currentShowEndDate = $this->service_showDays->getRepeatingEndDate(); + //check if "no end" option has changed + if ($currentShowEndDate != $showData['add_show_no_end']) { + //show "No End" option was toggled + if (!$showData['add_show_no_end']) { + //"No End" option was unchecked so we need to delete the + //repeat instances that are scheduled after the new end date + $this->deleteInstancesFromDate($endDate, $showId); } - }*/ - } + } + + if ($currentShowEndDate != $showData['add_show_end_date']) { + //end date was changed + $newEndDate = strtotime($showData['add_show_end_date']); + $oldEndDate = strtotime($currentShowEndDate); + if ($newEndDate < $oldEndDate) { + //end date was pushed back so we have to delete any + //instances of this show scheduled after the new end date + $this->deleteInstancesFromDate($endDate, $showId); + } + } + }//if repeats + + /*$newStartDateTime = new DateTime($showData["add_show_start_date"]." ". + $showData["add_show_start_time"], + new DateTimeZone(Application_Model_Preference::GetTimezone())); + + $diff = $this->calculateShowStartDiff($newStartDateTime, + $currentShowDay->getLocalStartDateAndTime()); + + $this->updateInstanceStartEndTime($showId, $diff); + $instanceIds = $this->getAllFutureInstanceIds($showId); + Application_Service_ScheduleService::updateScheduleStartTime($instanceIds, $diff);*/ } /** * - * Updates the start date and time for cc_show_instances - * and entries in cc_schedule + * Updates the start and end time for cc_show_instances * * @param $showData edit show form data */ - public function updateStartDateAndTime($showData, $currentShowDay) + public function updateInstanceStartEndTime($showId, $diff) { - $date = new Application_Common_DateHelper(); - //current time in UTC - $timestamp = $date->getTimestamp(); - - $dtOld = $currentShowDay->getUTCStartDateAndTime(); - $dtNew = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time'], - new DateTimeZone(date_default_timezone_get())); - $diff = $dtOld->getTimestamp() - $dtNew->getTimestamp(); $sql = << :timestamp + AND starts > :timestamp::TIMESTAMP SQL; Application_Common_Database::prepareAndExecute($sql, array(':diff1' => $diff, ':diff2' => $diff, - ':showId' => $showData["add_show_id"], ':timestamp' => $timestamp), + ':showId' => $showId, ':timestamp' => gmdate("Y-m-d H:i:s")), 'execute'); - - /*$showInstanceIds = $this->getAllFutureInstanceIds(); - if (count($showInstanceIds) > 0 && $diff != 0) { - $showIdsImploded = implode(",", $showInstanceIds); - $sql = "UPDATE cc_schedule " - ."SET starts = starts + INTERVAL '$diff sec', " - ."ends = ends + INTERVAL '$diff sec' " - ."WHERE instance_id IN ($showIdsImploded)"; - $con->exec($sql); - }*/ } public function deleteAllRepeatInstances($currentShowDay, $showId) @@ -451,11 +555,9 @@ WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDays) AND show_id = :showId SQL; - Application_Common_Database::prepareAndExecute( $sql, - array( - ":timestamp" => gmdate("Y-m-d H:i:s"), - ":showId" => $showId, - ), "execute"); + Application_Common_Database::prepareAndExecute( $sql, array( + ":timestamp" => gmdate("Y-m-d H:i:s"), ":showId" => $showId), + "execute"); } public function deleteInstancesBeforeDate($newStartDate, $showId) @@ -473,21 +575,31 @@ SQL; ":showId" => $showId), "execute"); } - public function updateDuration($showData) + public function deleteInstancesFromDate($endDate, $showId) { - $date = new Application_Common_DateHelper; - $timestamp = $date->getUtcTimestamp(); + $sql = <<= :endDate::DATE + AND starts > :timestamp::TIMESTAMP + AND show_id = :showId +SQL; + Application_Common_Database::prepareAndExecute($sql, array( + ':endDate' => $endDate, ':timestamp' => gmdate("Y-m-d H:i:s"), + ':showId' => $showId), 'execute'); + } +/* public function updateInstanceDuration($showData) + { $sql = << :timestamp::TIMESTAMP SQL; - + Application_Common_Database::prepareAndExecute( $sql, array( ':add_show_duration' => $showData['add_show_duration'], ':show_id' => $showData['add_show_id'], - ':timestamp' => $timestamp), "execute"); - } + ':timestamp' => gmdate("Y-m-d H:i:s")), "execute"); + }*/ } \ No newline at end of file diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index e858809c8..7747a32af 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -10,9 +10,9 @@ class Application_Service_ShowService * @param $ccShow * @param $showData */ - public function setShow($showData, $isNewShow) + public function setShow($showData, $isUpdate) { - if ($isNewShow) { + if (!$isUpdate) { $ccShow = new CcShow(); } else { $ccShow = CcShowQuery::create()->findPk($showData["add_show_id"]); @@ -33,6 +33,17 @@ class Application_Service_ShowService return $ccShow; } + /** + * + * Deletes all the cc_show_rebroadcast entries for a specific show + * that is currently being edited. They will get recreated with + * the new show specs + */ + public function deleteShowRebroadcasts($showId) + { + CcShowRebroadcastQuery::create()->filterByDbShowId($showId)>delete(); + } + /** * * Sets the fields for a cc_show_rebroadcast table row @@ -70,6 +81,17 @@ class Application_Service_ShowService } } + /** + * + * Deletes all the cc_show_hosts entries for a specific show + * that is currently being edited. They will get recreated with + * the new show specs + */ + public function deleteShowHosts($showId) + { + CcShowHostsQuery::create()->filterByDbShow($showId)->delete(); + } + /** * * Sets the fields for a cc_show_hosts table row