Deleted unused functions in Show.php

This commit is contained in:
denise 2013-05-13 09:55:17 -04:00
parent 741507fab1
commit 6b560eede1

View file

@ -326,73 +326,6 @@ SQL;
Application_Model_RabbitMq::PushSchedule();
}
/**
* This function is called when a repeating show is edited and the
* days that is repeats on have changed. More specifically, a day
* that the show originally repeated on has been "unchecked".
*
* Removes Show Instances that occur on days of the week specified
* by input array. For example, if array contains one value of "0",
* (0 = Sunday, 1=Monday) then all show instances that occur on
* Sunday are removed.
*
* @param array p_uncheckedDays
* An array specifying which days should be removed. (in the local timezone)
*/
public function removeUncheckedDaysInstances($p_uncheckedDays)
{
//need to convert local doftw to UTC doftw (change made for 2.0 since shows are stored in UTC)
$daysRemovedUTC = array();
$showDays = CcShowDaysQuery::create()
->filterByDbShowId($this->getId())
->find();
Logging::info("Unchecked days:");
foreach ($p_uncheckedDays as $day) {
Logging::info($day);
}
foreach ($showDays as $showDay) {
//Logging::info("Local show day is: {$showDay->getDbDay()}");
//Logging::info("First show day is: {$showDay->getDbFirstShow()}");
//Logging::info("Id show days is: {$showDay->getDbId()}");
if (in_array($showDay->getDbDay(), $p_uncheckedDays)) {
$showDay->reload();
//Logging::info("Local show day is: {$showDay->getDbDay()}");
//Logging::info("First show day is: {$showDay->getDbFirstShow()}");
//Logging::info("Id show days is: {$showDay->getDbId()}");
$startDay = new DateTime("{$showDay->getDbFirstShow()} {$showDay->getDbStartTime()}", new DateTimeZone($showDay->getDbTimezone()));
//Logging::info("Show start day: {$startDay->format('Y-m-d H:i:s')}");
$startDay->setTimezone(new DateTimeZone("UTC"));
//Logging::info("Show start day UTC: {$startDay->format('Y-m-d H:i:s')}");
$daysRemovedUTC[] = $startDay->format('w');
//Logging::info("UTC show day is: {$startDay->format('w')}");
}
}
$uncheckedDaysImploded = implode(",", $daysRemovedUTC);
$showId = $this->getId();
$esc_uncheckedDays = pg_escape_string($uncheckedDaysImploded);
$timestamp = gmdate("Y-m-d H:i:s");
$sql = <<<SQL
DELETE
FROM cc_show_instances
WHERE EXTRACT(DOW FROM starts) IN ($esc_uncheckedDays)
AND starts > :timestamp::TIMESTAMP
AND show_id = :showId
SQL;
Application_Common_Database::prepareAndExecute( $sql,
array(
":timestamp" => $timestamp,
":showId" => $showId,
), "execute");
}
/**
* Check whether the current show originated
* from a recording.
@ -604,92 +537,6 @@ SQL;
':timestamp' => gmdate("Y-m-d H:i:s")), 'execute');
}
/**
* Deletes all show instances of current show after a
* certain date. Note that although not enforced, $p_date
* should never be in the past, as we never want to allow
* deletion of shows that have already occured.
*
* @param string $p_date
* The date which to delete after, if null deletes from the current timestamp.
*/
public function removeAllInstancesFromDate($p_date=null)
{
$timestamp = gmdate("Y-m-d H:i:s");
if (is_null($p_date)) {
$date = new Application_Common_DateHelper;
$p_date = $date->getDate();
}
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances "
." WHERE date(starts) >= :date::date"
." AND starts > :timestamp::timestamp"
." AND show_id = :showId";
$map = array(":date"=>$p_date,
':timestamp'=>$timestamp,
':showId'=>$showId);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
}
/**
* Deletes all show instances of current show before a
* certain date.
*
* This function is used in the case where a repeating show is being
* edited and the start date of the first show has been changed more
* into the future. In this case, delete any show instances that
* exist before the new start date.
*
* @param string $p_date
* The date which to delete before
*/
public function removeAllInstancesBeforeDate($p_date)
{
$timestamp = gmdate("Y-m-d H:i:s");
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances "
." WHERE date(starts) < :date::date"
." AND starts > :timestamp::timestamp"
." AND show_id = :showId";
$map = array(":date"=>$p_date,
":timestamp"=>$timestamp,
":showId"=>$showId);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
}
public function getNextFutureRepeatShowTime()
{
$sql = <<<SQL
SELECT starts, ends FROM cc_show_instances
WHERE ends > now() at time zone 'UTC'
AND show_id = :showId
ORDER BY starts
LIMIT 1
SQL;
$result = Application_Common_Database::prepareAndExecute( $sql,
array( 'showId' => $this->getId() ), 'all' );
foreach ($result as $r) {
$show["starts"] = new DateTime($r["starts"], new DateTimeZone('UTC'));
$show["ends"] = new DateTime($r["ends"], new DateTimeZone('UTC'));
}
$currentUser = Application_Model_User::getCurrentUser();
$currentUserId = $currentUser->getId();
$userTimezone = Application_Model_Preference::GetUserTimezone($currentUserId);
$show["starts"]->setTimezone(new DateTimeZone($userTimezone));
$show["ends"]->setTimezone(new DateTimeZone($userTimezone));
return $show;
}
/**
* Get the start date of the current show in UTC timezone.
*
@ -1040,635 +887,6 @@ SQL;
}
public function deletePossiblyInvalidInstances($p_data, $p_endDate, $isRecorded, $repeatType)
{
if ($p_data['add_show_repeats'] != $this->isRepeating()) {
//repeat option was toggled
$this->deleteAllInstances();
}
if ($p_data['add_show_duration'] != $this->getDuration()) {
//duration has changed
$this->updateDurationTime($p_data);
}
if ($p_data['add_show_repeats']) {
if (($repeatType == 1 || $repeatType == 2) &&
$p_data['add_show_start_date'] != $this->getStartDate()){
//start date has changed when repeat type is bi-weekly or monthly.
//This screws up the repeating positions of show instances, so lets
//just delete them for now. (CC-2351)
$this->deleteAllInstances();
}
if ($repeatType != $this->getRepeatType()) {
//repeat type changed.
$this->deleteAllInstances();
} else {
//repeat type is the same, check if the days of the week are the same
$repeatingDaysChanged = false;
$showDaysArray = $this->getShowDays();
if (count($p_data['add_show_day_check']) == count($showDaysArray)) {
//same number of days checked, lets see if they are the same numbers
$intersect = array_intersect($p_data['add_show_day_check'], $showDaysArray);
if (count($intersect) != count($p_data['add_show_day_check'])) {
$repeatingDaysChanged = true;
}
} else {
$repeatingDaysChanged = true;
}
if ($repeatingDaysChanged) {
$daysRemoved = array_diff($showDaysArray, $p_data['add_show_day_check']);
if (count($daysRemoved) > 0) {
$this->removeUncheckedDaysInstances($daysRemoved);
}
}
if ($p_data['add_show_start_date'] != $this->getStartDate()
|| $p_data['add_show_start_time'] != $this->getStartTime()){
//start date/time has changed
$newDate = strtotime($p_data['add_show_start_date']);
$oldDate = strtotime($this->getStartDate());
if ($newDate > $oldDate) {
$this->removeAllInstancesBeforeDate($p_data['add_show_start_date']);
}
$this->updateStartDateTime($p_data, $p_endDate);
}
}
//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) == $p_data['add_show_no_end']) {
//show "Never Ends" option was toggled.
if ($p_data['add_show_no_end']) {
} else {
$this->removeAllInstancesFromDate($p_endDate);
}
}
if ($this->getRepeatingEndDate() != $p_data['add_show_end_date']) {
//end date was changed.
$newDate = strtotime($p_data['add_show_end_date']);
$oldDate = strtotime($this->getRepeatingEndDate());
if ($newDate < $oldDate) {
$this->removeAllInstancesFromDate($p_endDate);
}
}
}
}
/**
* Create a show.
*
* Note: end dates are non inclusive.
*
* @param array $data
* @return int
* Show ID
*/
public static function create($data)
{
/*$startDateTime = new DateTime($data['add_show_start_date']." ".$data['add_show_start_time']);*/
// these are not used
/*$utcStartDateTime = clone $startDateTime;
$utcStartDateTime->setTimezone(new DateTimeZone('UTC'));*/
/*if ($data['add_show_no_end']) {
$endDate = NULL;
} elseif ($data['add_show_repeats']) {
$endDateTime = new DateTime($data['add_show_end_date']);
//$endDateTime->setTimezone(new DateTimeZone('UTC'));
$endDateTime->add(new DateInterval("P1D"));
$endDate = $endDateTime->format("Y-m-d");
} else {
$endDateTime = new DateTime($data['add_show_start_date']);
//$endDateTime->setTimezone(new DateTimeZone('UTC'));
$endDateTime->add(new DateInterval("P1D"));
$endDate = $endDateTime->format("Y-m-d");
}*/
//What we are doing here is checking if the show repeats or if
//any repeating days have been checked. If not, then by default
//the "selected" DOW is the initial day.
//DOW in local time.
/*$startDow = date("w", $startDateTime->getTimestamp());
if (!$data['add_show_repeats']) {
$data['add_show_day_check'] = array($startDow);
} elseif ($data['add_show_repeats'] && $data['add_show_day_check'] == "") {
$data['add_show_day_check'] = array($startDow);
}*/
//find repeat type or set to a non repeating show.
/*$repeatType = ($data['add_show_repeats']) ? $data['add_show_repeat_type'] : -1;*/
/*if ($data['add_show_id'] == -1) {
$ccShow = new CcShow();
} else {
$ccShow = CcShowQuery::create()->findPK($data['add_show_id']);
}*/
/*$ccShow->setDbName($data['add_show_name']);
$ccShow->setDbDescription($data['add_show_description']);
$ccShow->setDbUrl($data['add_show_url']);
$ccShow->setDbGenre($data['add_show_genre']);
$ccShow->setDbColor($data['add_show_color']);
$ccShow->setDbBackgroundColor($data['add_show_background_color']);
$ccShow->setDbLiveStreamUsingAirtimeAuth($data['cb_airtime_auth'] == 1);
$ccShow->setDbLiveStreamUsingCustomAuth($data['cb_custom_auth'] == 1);
$ccShow->setDbLiveStreamUser($data['custom_username']);
$ccShow->setDbLiveStreamPass($data['custom_password']);
$ccShow->save();*/
/*$showId = $ccShow->getDbId();*/
/*$isRecorded = (isset($data['add_show_record']) && $data['add_show_record']) ? 1 : 0;*/
/*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) {
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) {
$showDay = new CcShowDays();
$showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($startDateTime->format("H:i:s"));
$showDay->setDbTimezone(date_default_timezone_get());
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbRepeatType($repeatType);
$showDay->setDbShowId($showId);
$showDay->setDbRecord($isRecorded);
$showDay->save();
} else {
foreach ($data['add_show_day_check'] as $day) {
$daysAdd=0;
$startDateTimeClone = clone $startDateTime;
if ($startDow !== $day) {
if ($startDow > $day)
$daysAdd = 6 - $startDow + 1 + $day;
else
$daysAdd = $day - $startDow;
$startDateTimeClone->add(new DateInterval("P".$daysAdd."D"));
}
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
$showDay = new CcShowDays();
$showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($startDateTimeClone->format("H:i"));
$showDay->setDbTimezone(date_default_timezone_get());
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbDay($day);
$showDay->setDbRepeatType($repeatType);
$showDay->setDbShowId($showId);
$showDay->setDbRecord($isRecorded);
$showDay->save();
}
}
}*/
//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']) {
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 */
/*if (($isRecorded && $data['add_show_rebroadcast']) && ($repeatType != -1)) {
for ($i=1; $i<=10; $i++) {
if ($data['add_show_rebroadcast_date_'.$i]) {
$showRebroad = new CcShowRebroadcast();
$showRebroad->setDbDayOffset($data['add_show_rebroadcast_date_'.$i]);
$showRebroad->setDbStartTime($data['add_show_rebroadcast_time_'.$i]);
$showRebroad->setDbShowId($showId);
$showRebroad->save();
}
}
} elseif ($isRecorded && $data['add_show_rebroadcast'] && ($repeatType == -1)) {
for ($i=1; $i<=10; $i++) {
if ($data['add_show_rebroadcast_date_absolute_'.$i]) {
//$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
//$sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' ";
$sql = <<<SQL
SELECT :rebroadcast::date - :start::date
SQL;
$offset_days =
Application_Common_Database::prepareAndExecute($sql,
array(
'rebroadcast' =>
$data["add_show_rebroadcast_date_absolute_$i"],
'start' =>
$data['add_show_start_date']), "column" );
//$r = $con->query($sql);
//$offset_days = $r->fetchColumn(0);
$showRebroad = new CcShowRebroadcast();
$showRebroad->setDbDayOffset($offset_days." days");
$showRebroad->setDbStartTime($data['add_show_rebroadcast_time_absolute_'.$i]);
$showRebroad->setDbShowId($showId);
$showRebroad->save();
}
}
}*/
//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) {
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) {
$showHost = new CcShowHosts();
$showHost->setDbShow($showId);
$showHost->setDbHost($host);
$showHost->save();
}
}*/
/*if ($data['add_show_id'] != -1) {
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
$con->beginTransaction();
//current timesamp in UTC.
$current_timestamp = gmdate("Y-m-d H:i:s");
try {
//update the status flag in cc_schedule.
$instances = CcShowInstancesQuery::create()
->filterByDbEnds($current_timestamp, Criteria::GREATER_THAN)
->filterByDbShowId($data['add_show_id'])
->find($con);
foreach ($instances as $instance) {
$instance->updateScheduleStatus($con);
}
$con->commit();
} catch (Exception $e) {
$con->rollback();
Logging::info("Couldn't update schedule status.");
Logging::info($e->getMessage());
}
}*/
/*Application_Model_Show::populateShowUntil($showId);
Application_Model_RabbitMq::PushSchedule();*/
/*return $showId;*/
}
/**
* Generate repeating show instances for a single show up to the given date.
* It will always try to use enddate from DB but if that's empty, it will use
* time now.
*
* @param int $p_showId
*/
/*public static function populateShowUntil($p_showId)
{
$con = Propel::getConnection();
$date = Application_Model_Preference::GetShowsPopulatedUntil();
if (is_null($date)) {
$p_populateUntilDateTime = new DateTime("now", new DateTimeZone('UTC'));
Application_Model_Preference::SetShowsPopulatedUntil($p_populateUntilDateTime);
} else {
$p_populateUntilDateTime = $date;
}
$stmt = $con->prepare("SELECT * FROM cc_show_days WHERE show_id = :show_id");
$stmt->bindParam(':show_id', $p_showId);
$stmt->execute();
$res = $stmt->fetchAll();
foreach ($res as $showDaysRow) {
Application_Model_Show::populateShow($showDaysRow, $p_populateUntilDateTime);
}
}*/
/**
* We are going to use cc_show_days as a template, to generate Show Instances. This function
* is basically a dispatcher that looks at the show template, and sends it to the correct function
* so that Show Instance generation can begin. After the all show instances have been created, pushes
* the schedule to Pypo.
*
* @param array $p_showRow
* A row from cc_show_days table
* @param DateTime $p_populateUntilDateTime
* DateTime object in UTC time.
*/
/*private static function populateShow($p_showDaysRow, $p_populateUntilDateTime)
{
// TODO : use constants instead of int values here? or maybe php will
// get enum types by the time somebody gets around to fix this. -- RG
if ($p_showDaysRow["repeat_type"] == -1) {
Application_Model_Show::populateNonRepeatingShow($p_showDaysRow, $p_populateUntilDateTime);
} elseif ($p_showDaysRow["repeat_type"] == 0) {
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P7D');
} elseif ($p_showDaysRow["repeat_type"] == 1) {
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P14D');
} elseif ($p_showDaysRow["repeat_type"] == 2) {
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P1M');
}
Application_Model_RabbitMq::PushSchedule();
}*/
/**
* Creates a single show instance. If the show is recorded, it may have multiple
* rebroadcast dates, and so this function will create those as well.
*
* @param array $p_showRow
* A row from cc_show_days table
* @param DateTime $p_populateUntilDateTime
* DateTime object in UTC time.
*/
private static function populateNonRepeatingShow($p_showRow, $p_populateUntilDateTime)
{
/*$show_id = $p_showRow["show_id"];
$first_show = $p_showRow["first_show"]; //non-UTC
$start_time = $p_showRow["start_time"]; //non-UTC
$duration = $p_showRow["duration"];
$record = $p_showRow["record"];
$timezone = $p_showRow["timezone"];
$start = $first_show." ".$start_time;
//start & end UTC DateTimes for the show.
list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start, $duration, $timezone);
if ($utcStartDateTime->getTimestamp() < $p_populateUntilDateTime->getTimestamp()) {
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");*/
/*$show = new Application_Model_Show($show_id);
if ($show->hasInstance()) {
$ccShowInstance = $show->getInstance();
$newInstance = false;
}*/ /*else {
$ccShowInstance = new CcShowInstances();
$newInstance = true;
}*/
/*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);*/
/*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()) {
//only do this for editing
$showInstance->deleteRebroadcasts();
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
}*/
/*}*/
}
/**
* Creates a 1 or more than 1 show instances (user has stated this show repeats). If the show
* is recorded, it may have multiple rebroadcast dates, and so this function will create
* those as well.
*
* @param array $p_showRow
* A row from cc_show_days table
* @param DateTime $p_populateUntilDateTime
* DateTime object in UTC time. "shows_populated_until" date YY-mm-dd in cc_pref
* @param string $p_interval
* Period of time between repeating shows (in php DateInterval notation 'P7D')
*/
private static function populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, $p_interval)
{
/*$show_id = $p_showDaysRow["show_id"];
$next_pop_date = $p_showDaysRow["next_pop_date"];
$first_show = $p_showDaysRow["first_show"]; //non-UTC
$last_show = $p_showDaysRow["last_show"]; //non-UTC
$start_time = $p_showDaysRow["start_time"]; //non-UTC
$duration = $p_showDaysRow["duration"];
$day = $p_showDaysRow["day"];
$record = $p_showDaysRow["record"];
$timezone = $p_showDaysRow["timezone"];
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
if (isset($next_pop_date)) {
$start = $next_pop_date." ".$start_time;
} else {
$start = $first_show." ".$start_time;
}
$utcStartDateTime = Application_Common_DateHelper::ConvertToUtcDateTime($start, $timezone);
//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";
$rebroadcasts = Application_Common_Database::prepareAndExecute( $sql,
array( ':show_id' => $show_id ), 'all');
$show = new Application_Model_Show($show_id);*/
/*while ($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp()
&& (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){*/
/*list($utcStartDateTime, $utcEndDateTime) = self::createUTCStartEndDateTime($start, $duration, $timezone);*/
//determine if we are adding a new show
//or editing a show
/* if ($show->hasInstanceOnDate($utcStartDateTime)) {
$ccShowInstance = $show->getInstanceOnDate($utcStartDateTime);
if ($ccShowInstance->getDbModifiedInstance()) {
//show instance on this date has been deleted.
list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone);
continue;
}
$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() > $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);*/
/* If we are updating a show then make sure that the scheduled content within
* the show is updated to the correct time. */
// don't we already do this in deletePossiblyInvalidInstances???
/*if (!$newInstance) {
$showInstance->correctScheduleStartTimes();
}*/
/*$showInstance->deleteRebroadcasts();
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone);*/
/*}*/
/*Application_Model_Show::setNextPop($start, $show_id, $day);*/
}
private static function advanceRepeatingDate($p_interval, $start, $timezone)
{
$startDt = new DateTime($start, new DateTimeZone($timezone));
if ($p_interval == 'P1M') {
/* When adding months, there is a problem if we are on January 31st and add one month with PHP.
* What ends up happening is that since February 31st doesn't exist, the date returned is
* March 3rd. For now let's ignore the day and assume we are always working with the
* first of each month, and use PHP to add 1 month to this (this will take care of rolling
* over the years 2011->2012, etc.). Then let's append the actual day, and use the php
* checkdate() function, to see if it is valid. If not, then we'll just skip this month. */
/* pass in only the year and month (not the day) */
$dt = new DateTime($startDt->format("Y-m"), new DateTimeZone($timezone));
/* Keep adding 1 month, until we find the next month that contains the day
* we are looking for (31st day for example) */
do {
$dt->add(new DateInterval($p_interval));
} while (!checkdate($dt->format("m"), $startDt->format("d"), $dt->format("Y")));
$dt->setDate($dt->format("Y"), $dt->format("m"), $startDt->format("d"));
} else {
$dt = new DateTime($start, new DateTimeZone($timezone));
$dt->add(new DateInterval($p_interval));
}
$start = $dt->format("Y-m-d H:i:s");
$dt->setTimezone(new DateTimeZone('UTC'));
$utcStartDateTime = $dt;
return array($start, $utcStartDateTime);
}
/*
* @param $p_start
* timestring format "Y-m-d H:i:s" (not UTC)
* @param $p_duration
* string time interval (h)h:(m)m(:ss)
* @param $p_timezone
* string "Europe/Prague"
* @param $p_offset
* array (days, hours, mins) used for rebroadcast shows.
*
* @return
* array of 2 DateTime objects, start/end time of the show in UTC.
*/
private static function createUTCStartEndDateTime($p_start, $p_duration, $p_timezone=null, $p_offset=null)
{
/*$timezone = $p_timezone ? $p_timezone : date_default_timezone_get();
$startDateTime = new DateTime($p_start, new DateTimeZone($timezone));
if (isset($p_offset)) {
$startDateTime->add(new DateInterval("P{$p_offset["days"]}DT{$p_offset["hours"]}H{$p_offset["mins"]}M"));
}
//convert time to UTC
$startDateTime->setTimezone(new DateTimeZone('UTC'));
$endDateTime = clone $startDateTime;
$duration = explode(":", $p_duration);
list($hours, $mins) = array_slice($duration, 0, 2);
$endDateTime->add(new DateInterval("PT{$hours}H{$mins}M"));
return array($startDateTime, $endDateTime);*/
}
/* Create rebroadcast instances for a created show marked for recording
*
* @param $p_rebroadcasts
* rows gotten from the db table cc_show_rebroadcasts, tells airtime when to schedule the rebroadcasts.
* @param $p_currentUtcTimestamp
* a timestring in format "Y-m-d H:i:s", current UTC time.
* @param $p_showId
* int of the show it belongs to (from cc_show)
* @param $p_showInstanceId
* the instance id of the created recorded show instance
* (from cc_show_instances), used to associate rebroadcasts to this show.
* @param $p_startTime
* a timestring in format "Y-m-d H:i:s" in the timezone, not UTC of the rebroadcasts' parent recorded show.
* @param $p_duration
* string time interval (h)h:(m)m:(ss) length of the show.
* @param $p_timezone
* string of user's timezone "Europe/Prague"
*
*/
private static function createRebroadcastInstances($p_rebroadcasts, $p_currentUtcTimestamp, $p_showId, $p_showInstanceId, $p_startTime, $p_duration, $p_timezone=null)
{
//Y-m-d
//use only the date part of the show start time stamp for the offsets to work properly.
/*$date = explode(" ", $p_startTime);
$start_date = $date[0];
foreach ($p_rebroadcasts as $rebroadcast) {
$days = explode(" ", $rebroadcast["day_offset"]);
$time = explode(":", $rebroadcast["start_time"]);
$offset = array("days"=>$days[0], "hours"=>$time[0], "mins"=>$time[1]);
list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start_date, $p_duration, $p_timezone, $offset);
if ($utcStartDateTime->format("Y-m-d H:i:s") > $p_currentUtcTimestamp) {
$newRebroadcastInstance = new CcShowInstances();
$newRebroadcastInstance->setDbShowId($p_showId);
$newRebroadcastInstance->setDbStarts($utcStartDateTime);
$newRebroadcastInstance->setDbEnds($utcEndDateTime);
$newRebroadcastInstance->setDbRecord(0);
$newRebroadcastInstance->setDbRebroadcast(1);
$newRebroadcastInstance->setDbOriginalShow($p_showInstanceId);
$newRebroadcastInstance->save();
}
}*/
}
/**
* Get all the show instances in the given time range (inclusive).
*
@ -1895,39 +1113,6 @@ SQL;
return $percent;
}
/* private static function &makeFullCalendarEvent(&$show, $options=array(), $startDateTime, $endDateTime, $startsEpoch, $endsEpoch)
{
$event = array();
$event["id"] = intval($show["instance_id"]);
$event["title"] = $show["name"];
$event["start"] = $startDateTime->format("Y-m-d H:i:s");
$event["startUnix"] = $startsEpoch;
$event["end"] = $endDateTime->format("Y-m-d H:i:s");
$event["endUnix"] = $endsEpoch;
$event["allDay"] = false;
$event["showId"] = intval($show["show_id"]);
$event["record"] = intval($show["record"]);
$event["rebroadcast"] = intval($show["rebroadcast"]);
$event["soundcloud_id"] = is_null($show["soundcloud_id"])
? -1 : $show["soundcloud_id"];
//event colouring
if ($show["color"] != "") {
$event["textColor"] = "#".$show["color"];
}
if ($show["background_color"] != "") {
$event["color"] = "#".$show["background_color"];
}
foreach ($options as $key => $value) {
$event[$key] = $value;
}
return $event;
}*/
/* Takes in a UTC DateTime object.
* Converts this to local time, since cc_show days
* requires local time. */