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

View file

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

View file

@ -62,12 +62,31 @@ class Application_Model_Scheduler {
}
/*
* @param DateTime startDT
* @param DateTime startDT in UTC
* @param string duration
* 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"]);
$durationDT = new DateTime("1970-01-01 {$file['cliplength']}", new DateTimeZone("UTC"));
$endTimeEpoch = $nextStartDT->format("U") + $durationDT->format("U");
$endTimeDT = DateTime::createFromFormat("U", $endTimeEpoch, new DateTimeZone("UTC"));
$endTimeDT = $this->findEndTime($nextStartDT, $file['cliplength']);
//item existed previously and is being moved.
//need to keep same id for resources if we want REST.
@ -153,7 +170,7 @@ class Application_Model_Scheduler {
$sched->setDbCueOut($file['cueout']);
$sched->setDbFadeIn($file['fadein']);
$sched->setDbFadeOut($file['fadeout']);
$sched->setDbClipLength($durationDT->format("H:i:s.u"));
$sched->setDbClipLength($file['cliplength']);
$sched->setDbInstanceId($instance);
$sched->save($this->con);
@ -167,9 +184,7 @@ class Application_Model_Scheduler {
Logging::log("adjusting iterm {$item->getDbId()}");
$durationDT = new DateTime("1970-01-01 {$item->getDbClipLength()}", new DateTimeZone("UTC"));
$endTimeEpoch = $nextStartDT->format("U") + $durationDT->format("U");
$endTimeDT = DateTime::createFromFormat("U", $endTimeEpoch, new DateTimeZone("UTC"));
$endTimeDT = $this->findEndTime($nextStartDT, $item->getDbClipLength());
$item->setDbStarts($nextStartDT);
$item->setDbEnds($endTimeDT);
@ -325,21 +340,7 @@ class Application_Model_Scheduler {
Logging::log("adjusting item #".$item->getDbId());
if (!$item->isDeleted()) {
Logging::log("item #".$item->getDbId()." is not deleted");
$durationDT = new DateTime("1970-01-01 {$item->getDbClipLength()}", new DateTimeZone("UTC"));
$startEpoch = $itemStartDT->format("U");
Logging::log("new start time");
Logging::log($itemStartDT->format("Y-m-d H:i:s"));
Logging::log("duration");
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"));
$itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength());
$item->setDbStarts($itemStartDT);
$item->setDbEnds($itemEndDT);
@ -348,5 +349,4 @@ class Application_Model_Scheduler {
$itemStartDT = $itemEndDT;
}
}
}
}

View file

@ -73,8 +73,6 @@ class Application_Model_ShowBuilder {
$showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
$showEndDT->setTimezone(new DateTimeZone($this->timezone));
//$diff =
$row["header"] = true;
$row["starts"] = $showStartDT->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) {
$row = $this->defaultRowArray;
if ($this->user->canSchedule($item["show_id"]) == true) {
$row["checkbox"] = true;
}
if (isset($p_item["sched_starts"])) {
$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["creator"] = $p_item["file_artist_name"];
$row["album"] = $p_item["file_album_title"];
if ($this->user->canSchedule($item["show_id"]) === true) {
$row["checkbox"] = true;
}
}
//show is empty
else {

View file

@ -31,7 +31,24 @@ class CcSchedule extends BaseCcSchedule {
*/
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')
{
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->modifiedColumns[] = CcPlaylistcontentsPeer::FADE_OUT;
$this->modifiedColumns[] = CcSchedulePeer::FADE_OUT;
return $this;
} // setDbFadeout()
@ -170,7 +204,7 @@ class CcSchedule extends BaseCcSchedule {
}
$this->cue_in = $dt->format('H:i:s.u');
$this->modifiedColumns[] = CcPlaylistcontentsPeer::CUE_IN;
$this->modifiedColumns[] = CcSchedulePeer::CUE_IN;
return $this;
} // setDbCuein()
@ -197,7 +231,7 @@ class CcSchedule extends BaseCcSchedule {
}
$this->cue_out = $dt->format('H:i:s.u');
$this->modifiedColumns[] = CcPlaylistcontentsPeer::CUE_OUT;
$this->modifiedColumns[] = CcSchedulePeer::CUE_OUT;
return $this;
} // setDbCueout()
@ -226,9 +260,78 @@ class CcSchedule extends BaseCcSchedule {
}
$this->clip_length = $dt->format('H:i:s.u');
$this->modifiedColumns[] = CcPlaylistcontentsPeer::CLIP_LENGTH;
$this->modifiedColumns[] = CcSchedulePeer::CLIP_LENGTH;
return $this;
} // 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