CC-3174 : showbuilder

modifying times to work with scheduling times.
This commit is contained in:
Naomi Aro 2012-02-07 17:29:52 +01:00
parent 251f3a3e5b
commit aa7afce245
6 changed files with 161 additions and 56 deletions

View file

@ -691,13 +691,15 @@ class Application_Model_Playlist {
} }
/** /**
- * Convert playlist time value to float seconds * This function is used for calculations! Don't modify for display purposes!
- * *
- * @param string $plt * Convert playlist time value to float seconds
- * playlist interval value (HH:mm:ss.dddddd) *
- * @return int * @param string $plt
- * seconds * playlist interval value (HH:mm:ss.dddddd)
- */ * @return int
* seconds
*/
public static function playlistTimeToSeconds($plt) public static function playlistTimeToSeconds($plt)
{ {
$arr = preg_split('/:/', $plt); $arr = preg_split('/:/', $plt);
@ -712,12 +714,14 @@ class Application_Model_Playlist {
/** /**
- * Convert float seconds value to playlist time format * This function is used for calculations! Don't modify for display purposes!
- * *
- * @param float $seconds * Convert float seconds value to playlist time format
- * @return string *
- * interval in playlist time format (HH:mm:ss.d) * @param float $seconds
- */ * @return string
* interval in playlist time format (HH:mm:ss.d)
*/
public static function secondsToPlaylistTime($p_seconds) public static function secondsToPlaylistTime($p_seconds)
{ {
$info = explode('.', $p_seconds); $info = explode('.', $p_seconds);

View file

@ -330,7 +330,7 @@ class Application_Model_Schedule {
ORDER BY si.starts, sched.starts;"; ORDER BY si.starts, sched.starts;";
Logging::log($sql); //Logging::log($sql);
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
return $rows; return $rows;

View file

@ -62,12 +62,31 @@ class Application_Model_Scheduler {
} }
/* /*
* @param DateTime startDT * @param DateTime startDT in UTC
* @param string duration * @param string duration
* in format H:i:s.u (could be more that 24 hours) * in format H:i:s.u (could be more that 24 hours)
*
* @return DateTime endDT in UTC
*/ */
private function findEndTime($startDT, $duration) { private function findEndTime($p_startDT, $p_duration) {
$startEpoch = $p_startDT->format("U.u");
$durationSeconds = Application_Model_Playlist::playlistTimeToSeconds($p_duration);
//add two float numbers to 6 subsecond precision
//DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number.
$endEpoch = bcadd($startEpoch , (string) $durationSeconds, 6);
Logging::log("end DateTime created {$p_startDT->format("Y-m-d H:i:s.u")}");
Logging::log("start epoch is {$startEpoch}");
Logging::log("duration in seconds is {$durationSeconds}");
Logging::log("end epoch is {$endEpoch}");
$dt = DateTime::createFromFormat("U.u", $endEpoch, new DateTimeZone("UTC"));
Logging::log("end DateTime created {$dt->format("Y-m-d H:i:s.u")}");
return $dt;
} }
/* /*
@ -130,9 +149,7 @@ class Application_Model_Scheduler {
Logging::log("adding file with id: ".$file["id"]); Logging::log("adding file with id: ".$file["id"]);
$durationDT = new DateTime("1970-01-01 {$file['cliplength']}", new DateTimeZone("UTC")); $endTimeDT = $this->findEndTime($nextStartDT, $file['cliplength']);
$endTimeEpoch = $nextStartDT->format("U") + $durationDT->format("U");
$endTimeDT = DateTime::createFromFormat("U", $endTimeEpoch, new DateTimeZone("UTC"));
//item existed previously and is being moved. //item existed previously and is being moved.
//need to keep same id for resources if we want REST. //need to keep same id for resources if we want REST.
@ -153,7 +170,7 @@ class Application_Model_Scheduler {
$sched->setDbCueOut($file['cueout']); $sched->setDbCueOut($file['cueout']);
$sched->setDbFadeIn($file['fadein']); $sched->setDbFadeIn($file['fadein']);
$sched->setDbFadeOut($file['fadeout']); $sched->setDbFadeOut($file['fadeout']);
$sched->setDbClipLength($durationDT->format("H:i:s.u")); $sched->setDbClipLength($file['cliplength']);
$sched->setDbInstanceId($instance); $sched->setDbInstanceId($instance);
$sched->save($this->con); $sched->save($this->con);
@ -167,9 +184,7 @@ class Application_Model_Scheduler {
Logging::log("adjusting iterm {$item->getDbId()}"); Logging::log("adjusting iterm {$item->getDbId()}");
$durationDT = new DateTime("1970-01-01 {$item->getDbClipLength()}", new DateTimeZone("UTC")); $endTimeDT = $this->findEndTime($nextStartDT, $item->getDbClipLength());
$endTimeEpoch = $nextStartDT->format("U") + $durationDT->format("U");
$endTimeDT = DateTime::createFromFormat("U", $endTimeEpoch, new DateTimeZone("UTC"));
$item->setDbStarts($nextStartDT); $item->setDbStarts($nextStartDT);
$item->setDbEnds($endTimeDT); $item->setDbEnds($endTimeDT);
@ -325,28 +340,13 @@ class Application_Model_Scheduler {
Logging::log("adjusting item #".$item->getDbId()); Logging::log("adjusting item #".$item->getDbId());
if (!$item->isDeleted()) { $itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength());
Logging::log("item #".$item->getDbId()." is not deleted");
$durationDT = new DateTime("1970-01-01 {$item->getDbClipLength()}", new DateTimeZone("UTC")); $item->setDbStarts($itemStartDT);
$startEpoch = $itemStartDT->format("U"); $item->setDbEnds($itemEndDT);
Logging::log("new start time"); $item->save($this->con);
Logging::log($itemStartDT->format("Y-m-d H:i:s"));
Logging::log("duration"); $itemStartDT = $itemEndDT;
Logging::log($durationDT->format("U"). "seconds");
$endEpoch = $itemStartDT->format("U") + $durationDT->format("U");
$itemEndDT = DateTime::createFromFormat("U", $endEpoch, new DateTimeZone("UTC"));
Logging::log("new end time");
Logging::log($itemEndDT->format("Y-m-d H:i:s"));
$item->setDbStarts($itemStartDT);
$item->setDbEnds($itemEndDT);
$item->save($this->con);
$itemStartDT = $itemEndDT;
}
} }
} }
} }

View file

@ -73,8 +73,6 @@ class Application_Model_ShowBuilder {
$showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC")); $showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
$showEndDT->setTimezone(new DateTimeZone($this->timezone)); $showEndDT->setTimezone(new DateTimeZone($this->timezone));
//$diff =
$row["header"] = true; $row["header"] = true;
$row["starts"] = $showStartDT->format("Y-m-d H:i"); $row["starts"] = $showStartDT->format("Y-m-d H:i");
$row["ends"] = $showEndDT->format("Y-m-d H:i"); $row["ends"] = $showEndDT->format("Y-m-d H:i");
@ -88,6 +86,10 @@ class Application_Model_ShowBuilder {
private function makeScheduledItemRow($p_item) { private function makeScheduledItemRow($p_item) {
$row = $this->defaultRowArray; $row = $this->defaultRowArray;
if ($this->user->canSchedule($item["show_id"]) == true) {
$row["checkbox"] = true;
}
if (isset($p_item["sched_starts"])) { if (isset($p_item["sched_starts"])) {
$schedStartDT = new DateTime($p_item["sched_starts"], new DateTimeZone("UTC")); $schedStartDT = new DateTime($p_item["sched_starts"], new DateTimeZone("UTC"));
@ -105,10 +107,6 @@ class Application_Model_ShowBuilder {
$row["title"] = $p_item["file_track_title"]; $row["title"] = $p_item["file_track_title"];
$row["creator"] = $p_item["file_artist_name"]; $row["creator"] = $p_item["file_artist_name"];
$row["album"] = $p_item["file_album_title"]; $row["album"] = $p_item["file_album_title"];
if ($this->user->canSchedule($item["show_id"]) === true) {
$row["checkbox"] = true;
}
} }
//show is empty //show is empty
else { else {

View file

@ -42,7 +42,7 @@ class Application_Model_User {
$type === UTYPE_PROGRAM_MANAGER || $type === UTYPE_PROGRAM_MANAGER ||
CcShowHostsQuery::create()->filterByDbShow($p_showId)->filterByDbHost($this->getId())->count() > 0 ) CcShowHostsQuery::create()->filterByDbShow($p_showId)->filterByDbHost($this->getId())->count() > 0 )
{ {
return true; return true;
} }
return false; return false;

View file

@ -31,7 +31,24 @@ class CcSchedule extends BaseCcSchedule {
*/ */
public function getDbStarts($format = 'Y-m-d H:i:s.u') public function getDbStarts($format = 'Y-m-d H:i:s.u')
{ {
return parent::getDbStarts($format); if ($this->starts === null) {
return null;
}
try {
$dt = new DateTime($this->starts, new DateTimeZone("UTC"));
} catch (Exception $x) {
throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->starts, true), $x);
}
if ($format === null) {
// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
return $dt;
} elseif (strpos($format, '%') !== false) {
return strftime($format, $dt->format('U'));
} else {
return $dt->format($format);
}
} }
/** /**
@ -45,7 +62,24 @@ class CcSchedule extends BaseCcSchedule {
*/ */
public function getDbEnds($format = 'Y-m-d H:i:s.u') public function getDbEnds($format = 'Y-m-d H:i:s.u')
{ {
return parent::getDbEnds($format); if ($this->ends === null) {
return null;
}
try {
$dt = new DateTime($this->ends, new DateTimeZone("UTC"));
} catch (Exception $x) {
throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->ends, true), $x);
}
if ($format === null) {
// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
return $dt;
} elseif (strpos($format, '%') !== false) {
return strftime($format, $dt->format('U'));
} else {
return $dt->format($format);
}
} }
/** /**
@ -143,7 +177,7 @@ class CcSchedule extends BaseCcSchedule {
} }
$this->fadeIout = $dt->format('H:i:s.u'); $this->fadeIout = $dt->format('H:i:s.u');
$this->modifiedColumns[] = CcPlaylistcontentsPeer::FADE_OUT; $this->modifiedColumns[] = CcSchedulePeer::FADE_OUT;
return $this; return $this;
} // setDbFadeout() } // setDbFadeout()
@ -170,7 +204,7 @@ class CcSchedule extends BaseCcSchedule {
} }
$this->cue_in = $dt->format('H:i:s.u'); $this->cue_in = $dt->format('H:i:s.u');
$this->modifiedColumns[] = CcPlaylistcontentsPeer::CUE_IN; $this->modifiedColumns[] = CcSchedulePeer::CUE_IN;
return $this; return $this;
} // setDbCuein() } // setDbCuein()
@ -197,7 +231,7 @@ class CcSchedule extends BaseCcSchedule {
} }
$this->cue_out = $dt->format('H:i:s.u'); $this->cue_out = $dt->format('H:i:s.u');
$this->modifiedColumns[] = CcPlaylistcontentsPeer::CUE_OUT; $this->modifiedColumns[] = CcSchedulePeer::CUE_OUT;
return $this; return $this;
} // setDbCueout() } // setDbCueout()
@ -226,9 +260,78 @@ class CcSchedule extends BaseCcSchedule {
} }
$this->clip_length = $dt->format('H:i:s.u'); $this->clip_length = $dt->format('H:i:s.u');
$this->modifiedColumns[] = CcPlaylistcontentsPeer::CLIP_LENGTH; $this->modifiedColumns[] = CcSchedulePeer::CLIP_LENGTH;
return $this; return $this;
} // setDbCliplength() } // setDbCliplength()
/**
* Sets the value of [starts] column to a normalized version of the date/time value specified.
*
* @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
* be treated as NULL for temporal objects.
* @return CcSchedule The current object (for fluent API support)
*/
public function setDbStarts($v)
{
if ($v instanceof DateTime) {
$dt = $v;
} else {
// some string/numeric value passed; we normalize that so that we can
// validate it.
try {
if (is_numeric($v)) { // if it's a unix timestamp
$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
// We have to explicitly specify and then change the time zone because of a
// DateTime bug: http://bugs.php.net/bug.php?id=43003
$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
} else {
$dt = new DateTime($v);
}
} catch (Exception $x) {
throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
}
}
$this->starts = ($dt ? $dt->format('Y-m-d H:i:s.u') : null);
$this->modifiedColumns[] = CcSchedulePeer::STARTS;
return $this;
} // setDbStarts()
/**
* Sets the value of [ends] column to a normalized version of the date/time value specified.
*
* @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
* be treated as NULL for temporal objects.
* @return CcSchedule The current object (for fluent API support)
*/
public function setDbEnds($v)
{
if ($v instanceof DateTime) {
$dt = $v;
} else {
// some string/numeric value passed; we normalize that so that we can
// validate it.
try {
if (is_numeric($v)) { // if it's a unix timestamp
$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
// We have to explicitly specify and then change the time zone because of a
// DateTime bug: http://bugs.php.net/bug.php?id=43003
$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
} else {
$dt = new DateTime($v);
}
} catch (Exception $x) {
throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
}
}
$this->ends = ($dt ? $dt->format('Y-m-d H:i:s.u') : null);
$this->modifiedColumns[] = CcSchedulePeer::ENDS;
return $this;
} // setDbEnds()
} // CcSchedule } // CcSchedule