private static function populateRepeatingShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $record, $end_timestamp, $interval) { global $CC_DBC; if (isset($next_pop_date)) { $next_date = $next_pop_date . " " . $start_time; } else { $next_date = $first_show . " " . $start_time; } $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}"; $rebroadcasts = $CC_DBC->GetAll($sql); $show = new Show($show_id); $date = new DateHelper(); $currentTimestamp = $date->getTimestamp(); while (strtotime($next_date) <= strtotime($end_timestamp) && (strtotime($last_show) > strtotime($next_date) || is_null($last_show))) { $start = $next_date; $sql = "SELECT timestamp '{$start}' + interval '{$duration}'"; $end = $CC_DBC->GetOne($sql); if ($show->hasInstanceOnDate($start)) { $ccShowInstance = $show->getInstanceOnDate($start); $newInstance = false; } 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() > $currentTimestamp) { $ccShowInstance->setDbShowId($show_id); $ccShowInstance->setDbStarts($start); $ccShowInstance->setDbEnds($end); $ccShowInstance->setDbRecord($record); $ccShowInstance->save(); } $show_instance_id = $ccShowInstance->getDbId(); $showInstance = new ShowInstance($show_instance_id); if (!$newInstance) { $showInstance->correctScheduleStartTimes(); } foreach ($rebroadcasts as $rebroadcast) { $timeinfo = explode(" ", $next_date); $sql = "SELECT timestamp '{$timeinfo[0]}' + interval '{$rebroadcast["day_offset"]}' + interval '{$rebroadcast["start_time"]}'"; $rebroadcast_start_time = $CC_DBC->GetOne($sql); $sql = "SELECT timestamp '{$rebroadcast_start_time}' + interval '{$duration}'"; $rebroadcast_end_time = $CC_DBC->GetOne($sql); if ($rebroadcast_start_time > $currentTimestamp) { $newRebroadcastInstance = new CcShowInstances(); $newRebroadcastInstance->setDbShowId($show_id); $newRebroadcastInstance->setDbStarts($rebroadcast_start_time); $newRebroadcastInstance->setDbEnds($rebroadcast_end_time); $newRebroadcastInstance->setDbRecord(0); $newRebroadcastInstance->setDbRebroadcast(1); $newRebroadcastInstance->setDbOriginalShow($show_instance_id); $newRebroadcastInstance->save(); } } $sql = "SELECT timestamp '{$start}' + interval '{$interval}'"; $next_date = $CC_DBC->GetOne($sql); } Show::setNextPop($next_date, $show_id, $day); RabbitMq::PushSchedule(); }