diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index ed4140b46..9feca24ab 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -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); diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 71e1eb462..5bf7f91fd 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -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; diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index d6e21d13a..3309f0e2d 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -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,28 +340,13 @@ class Application_Model_Scheduler { Logging::log("adjusting item #".$item->getDbId()); - if (!$item->isDeleted()) { - Logging::log("item #".$item->getDbId()." is not deleted"); + $itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength()); - $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")); + $item->setDbStarts($itemStartDT); + $item->setDbEnds($itemEndDT); + $item->save($this->con); - 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")); - - $item->setDbStarts($itemStartDT); - $item->setDbEnds($itemEndDT); - $item->save($this->con); - - $itemStartDT = $itemEndDT; - } + $itemStartDT = $itemEndDT; } } } \ No newline at end of file diff --git a/airtime_mvc/application/models/ShowBuilder.php b/airtime_mvc/application/models/ShowBuilder.php index b7f462732..136ceea5c 100644 --- a/airtime_mvc/application/models/ShowBuilder.php +++ b/airtime_mvc/application/models/ShowBuilder.php @@ -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 { diff --git a/airtime_mvc/application/models/User.php b/airtime_mvc/application/models/User.php index aa79e71bf..3e94e61ae 100644 --- a/airtime_mvc/application/models/User.php +++ b/airtime_mvc/application/models/User.php @@ -42,7 +42,7 @@ class Application_Model_User { $type === UTYPE_PROGRAM_MANAGER || CcShowHostsQuery::create()->filterByDbShow($p_showId)->filterByDbHost($this->getId())->count() > 0 ) { - return true; + return true; } return false; diff --git a/airtime_mvc/application/models/airtime/CcSchedule.php b/airtime_mvc/application/models/airtime/CcSchedule.php index 1d4a8a674..67af99cff 100644 --- a/airtime_mvc/application/models/airtime/CcSchedule.php +++ b/airtime_mvc/application/models/airtime/CcSchedule.php @@ -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