diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index fac6aee00..b9f140e3e 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -295,24 +295,6 @@ class CcShow extends BaseCcShow { } return $instanceIds; } - - /* - * Returns all show instances ordered by 'starts' column in desc order. - */ - public function getInstanceIdsSortedByMostRecentStartTime() - { - $instances = CcShowInstancesQuery::create() - ->filterByCcShow($this) - ->filterByDbModifiedInstance(false) - ->orderByDbStarts(Criteria::DESC) - ->find(); - - $instanceIdsDescOrder = array(); - foreach ($instances as $instance) { - $instanceIdsDescOrder[] = $instance->getDbId(); - } - return $instanceIdsDescOrder; - } //what is this?? public function getOtherInstances($instanceId) diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 36d16356d..60509390a 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -153,46 +153,59 @@ class Application_Service_SchedulerService /** * * Gets a copy of the linked show's schedule from cc_schedule table - * The schedule is taken from the most recent show instance that existed - * before new show instances were created. + * + * If $instanceId is not null, we use that variable to grab the linked + * show's schedule from cc_schedule table. (This is likely to be the case + * if a user has edited a show and changed it from un-linked to linked, in + * which case we copy the show content from the show instance that was clicked + * on to edit the show in the calendar.) Otherwise the schedule is taken + * from the most recent show instance that existed before new show + * instances were created. (This is likely to be the case when a user edits a + * show and a new repeat show day is added (i.e. mondays), or moves forward in the + * calendar triggering show creation) * * @param integer $showId * @param array $instancsIdsToFill + * @param integer $instanceId */ - public static function getLinkedShowSchedule($showId, $instancsIdsToFill) + private static function getLinkedShowSchedule($showId, $instancsIdsToFill, $instanceId) { - $showsPopulatedUntil = Application_Model_Preference::GetShowsPopulatedUntil(); - - - $showInstanceWithMostRecentSchedule = CcShowInstancesQuery::create() - ->filterByDbShowId($showId) - ->filterByDbStarts($showsPopulatedUntil->format("Y-m-d H:i:s"), Criteria::LESS_THAN) - ->filterByDbId($instancsIdsToFill, Criteria::NOT_IN) - ->orderByDbStarts(Criteria::DESC) - ->limit(1) - ->findOne(); - $con = Propel::getConnection(); - $instanceId = $showInstanceWithMostRecentSchedule->getDbId(); + + if (is_null($instanceId)) { + $showsPopulatedUntil = Application_Model_Preference::GetShowsPopulatedUntil(); + + $showInstanceWithMostRecentSchedule = CcShowInstancesQuery::create() + ->filterByDbShowId($showId) + ->filterByDbStarts($showsPopulatedUntil->format("Y-m-d H:i:s"), Criteria::LESS_THAN) + ->filterByDbId($instancsIdsToFill, Criteria::NOT_IN) + ->orderByDbStarts(Criteria::DESC) + ->limit(1) + ->findOne(); + + $instanceId = $showInstanceWithMostRecentSchedule->getDbId(); + } + $linkedShowSchedule_sql = $con->prepare( "select * from cc_schedule where instance_id = :instance_id ". "order by starts"); $linkedShowSchedule_sql->bindParam(':instance_id', $instanceId); $linkedShowSchedule_sql->execute(); - + return $linkedShowSchedule_sql->fetchAll(); } /** * - * This function gets called after new linked show_instances are created. + * This function gets called after new linked show_instances are created, or after + * a show has been edited and went from being un-linked to linked. * It fills the new show instances' schedules. * * @param CcShow_type $ccShow * @param array $instanceIdsToFill ids of the new linked cc_show_instances that - * were created and now need their schedules filled + * need their schedules filled */ - public static function fillNewLinkedInstances($ccShow, $instanceIdsToFill) + public static function fillLinkedInstances($ccShow, $instanceIdsToFill, $instanceId=null) { //TODO can we remove the code until line 216 ?? @@ -230,7 +243,7 @@ class Application_Service_SchedulerService //Get the "template" schedule for the linked show (contents of the linked show) that will be //copied into to all the new show instances. - $linkedShowSchedule = self::getLinkedShowSchedule($ccShow->getDbId(), $instanceIdsToFill); + $linkedShowSchedule = self::getLinkedShowSchedule($ccShow->getDbId(), $instanceIdsToFill, $instanceId); //get time_filled so we can update cc_show_instances if (!empty($linkedShowSchedule)) { diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index be07a03fa..5a2f22e63 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -15,7 +15,6 @@ class Application_Service_ShowService private $isRebroadcast; private $repeatType; private $isUpdate; - /*private $linkedShowContent;*/ private $oldShowTimezone; private $localShowStartHour; private $localShowStartMin; @@ -199,6 +198,7 @@ class Application_Service_ShowService $daysAdded = array(); if ($this->isUpdate) { + if (!$this->ccShow->getCcShowDayss()->isEmpty()) { $this->storeOrigLocalShowInfo(); } @@ -371,7 +371,7 @@ class Application_Service_ShowService foreach ($ccShows as $ccShow) { if (($this->isUpdate || $fillInstances) && $ccShow->isLinked()) { - Application_Service_SchedulerService::fillNewLinkedInstances( + Application_Service_SchedulerService::fillLinkedInstances( $ccShow, $this->newInstanceIdsCreated[$ccShow->getDbId()]); } } @@ -1145,16 +1145,13 @@ SQL; if ($this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); $newInstance = false; - //$updateScheduleStatus = true; } else { $newInstance = true; $ccShowInstance = new CcShowInstances(); - //$updateScheduleStatus = false; } } else { $newInstance = true; $ccShowInstance = new CcShowInstances(); - //$updateScheduleStatus = false; } /* When editing the start/end time of a repeating show, we don't want to @@ -1247,11 +1244,9 @@ SQL; if ($this->isUpdate && $this->hasInstance($utcStartDateTime)) { $ccShowInstance = $this->getInstance($utcStartDateTime); $newInstance = false; - //$updateScheduleStatus = true; } else { $newInstance = true; $ccShowInstance = new CcShowInstances(); - //$updateScheduleStatus = false; } /* When editing the start/end time of a repeating show, we don't want to @@ -1520,10 +1515,14 @@ SQL; $ccShow->setDbLiveStreamUsingCustomAuth($showData['cb_custom_auth'] == 1); $ccShow->setDbLiveStreamUser($showData['custom_username']); $ccShow->setDbLiveStreamPass($showData['custom_password']); - - // Once a show is unlinked it cannot be linked again - if ($ccShow->getDbLinked() && !$showData["add_show_linked"]) { - $ccShow->setDbIsLinkable(false); + + //Here a user has edited a show and linked it. + //We need to grab the existing show instances ids and fill their content + //with the content from the show instance that was clicked on to edit the show. + //We do this because linked show instances need to have the same content in each. + if ($this->isUpdate && (!$ccShow->getDbLinked() && $showData["add_show_linked"])) { + $existingShowInstanceIds = $ccShow->getFutureInstanceIds(new Criteria()); + Application_Service_SchedulerService::fillLinkedInstances($ccShow, $existingShowInstanceIds, $showData["add_show_instance_id"]); } $ccShow->setDbLinked($showData["add_show_linked"]); diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index 6ec2996b3..307a5c2c6 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -273,9 +273,16 @@ function setAddShowEvents(form) { } return false; } - - if (!$(this).attr("checked") && $("#show-link-warning").length === 0) { - $(this).parent().after("