Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
James 2011-08-18 13:54:17 -04:00
commit 38256de606
22 changed files with 199 additions and 184 deletions

View file

@ -2,11 +2,11 @@
class DateHelper
{
private $_timestamp;
private $_dateTime;
function __construct()
{
$this->_timestamp = date("U");
$this->_dateTime = date("U");
}
/**
@ -15,7 +15,19 @@ class DateHelper
*/
function getTimestamp()
{
return date("Y-m-d H:i:s", $this->_timestamp);
return date("Y-m-d H:i:s", $this->_dateTime);
}
/**
* Get time of object construction in the format
* YYYY-MM-DD HH:mm:ss
*/
function getUtcTimestamp()
{
$dateTime = new DateTime("@".$this->_dateTime);
$dateTime->setTimezone(new DateTimeZone("UTC"));
return $dateTime->format("Y-m-d H:i:s");
}
/**
@ -24,7 +36,7 @@ class DateHelper
*/
function getDate()
{
return date("Y-m-d", $this->_timestamp);
return date("Y-m-d", $this->_dateTime);
}
/**
@ -33,7 +45,7 @@ class DateHelper
*/
function getTime()
{
return date("H:i:s", $this->_timestamp);
return date("H:i:s", $this->_dateTime);
}
/**
@ -41,28 +53,30 @@ class DateHelper
*/
function setDate($dateString)
{
$this->_timestamp = strtotime($dateString);
$this->_dateTime = strtotime($dateString);
}
/**
*
* Enter description here ...
* Find the epoch timestamp difference from "now" to the beginning of today.
*/
function getNowDayStartDiff()
{
$dayStartTS = strtotime(date("Y-m-d", $this->_timestamp));
return $this->_timestamp - $dayStartTS;
$dayStartTs = ((int)($this->_dateTime/86400))*86400;
return $this->_dateTime - $dayStartTs;
}
/**
* Find the epoch timestamp difference from "now" to the end of today.
*/
function getNowDayEndDiff()
{
$dayEndTS = strtotime(date("Y-m-d", $this->_timestamp+(86400)));
return $dayEndTS - $this->_timestamp;
$dayEndTs = ((int)(($this->_dateTime+86400)/86400))*86400;
return $dayEndTs - $this->_dateTime;
}
function getEpochTime()
{
return $this->_timestamp;
return $this->_dateTime;
}
public static function TimeDiff($time1, $time2)
@ -100,31 +114,31 @@ class DateHelper
* format "hh:mm:ss". But when dealing with show times, we
* do not care about the seconds.
*
* @param int $p_timestamp
* @param int $p_dateTime
* The value which to format.
* @return int
* The timestamp with the new format "hh:mm", or
* the original input parameter, if it does not have
* the correct format.
*/
public static function removeSecondsFromTime($p_timestamp)
public static function removeSecondsFromTime($p_dateTime)
{
//Format is in hh:mm:ss. We want hh:mm
$timeExplode = explode(":", $p_timestamp);
$timeExplode = explode(":", $p_dateTime);
if (count($timeExplode) == 3)
return $timeExplode[0].":".$timeExplode[1];
else
return $p_timestamp;
return $p_dateTime;
}
public static function getDateFromTimestamp($p_timestamp){
$explode = explode(" ", $p_timestamp);
public static function getDateFromTimestamp($p_dateTime){
$explode = explode(" ", $p_dateTime);
return $explode[0];
}
public static function getTimeFromTimestamp($p_timestamp){
$explode = explode(" ", $p_timestamp);
public static function getTimeFromTimestamp($p_dateTime){
$explode = explode(" ", $p_dateTime);
return $explode[1];
}
@ -157,5 +171,19 @@ class DateHelper
return $totalSeconds;
}
public static function ConvertToLocalDateTime($p_dateString){
$dateTime = new DateTime($p_dateString, new DateTimeZone("UTC"));
$dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
return $dateTime;
}
public static function ConvertToLocalDateTimeString($p_dateString, $format="Y-m-d H:i:s"){
$dateTime = new DateTime($p_dateString, new DateTimeZone("UTC"));
$dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
return $dateTime->format($format);
}
}

View file

@ -3,21 +3,31 @@
class Application_Model_Nowplaying
{
public static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){
private static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){
return array("h", "", $p_showStart, $p_showEnd, $p_showName, "", "", "", "", "", "");
}
public static function CreateDatatableRows($p_dbRows){
private static function CreateDatatableRows($p_dbRows){
$dataTablesRows = array();
$date = new DateHelper;
$timeNow = $date->getTimestamp();
$epochNow = time();
foreach ($p_dbRows as $dbRow){
$showStartDateTime = DateHelper::ConvertToLocalDateTime($dbRow['show_starts']);
$showEndDateTime = DateHelper::ConvertToLocalDateTime($dbRow['show_ends']);
$itemStartDateTime = DateHelper::ConvertToLocalDateTime($dbRow['item_starts']);
$itemEndDateTime = DateHelper::ConvertToLocalDateTime($dbRow['item_ends']);
$showStarts = $showStartDateTime->format("Y-m-d H:i:s");
$showEnds = $showEndDateTime->format("Y-m-d H:i:s");
$itemStarts = $itemStartDateTime->format("Y-m-d H:i:s");
$itemEnds = $itemEndDateTime->format("Y-m-d H:i:s");
$status = ($dbRow['show_ends'] < $dbRow['item_ends']) ? "x" : "";
$type = "a";
$type .= ($dbRow['item_ends'] > $timeNow && $dbRow['item_starts'] <= $timeNow) ? "c" : "";
$type .= ($itemEndDateTime->getTimestamp() > $epochNow && $itemStartDateTime->getTimestamp() <= $epochNow) ? "c" : "";
// remove millisecond from the time format
$itemStart = explode('.', $dbRow['item_starts']);
@ -25,36 +35,36 @@ class Application_Model_Nowplaying
//format duration
$duration = explode('.', $dbRow['clip_length']);
$formated = Application_Model_Nowplaying::FormatDuration($duration[0]);
$dataTablesRows[] = array($type, $dbRow['show_starts'], $itemStart[0], $itemEnd[0],
$formated, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'],
$formatted = self::FormatDuration($duration[0]);
$dataTablesRows[] = array($type, $showStarts, $itemStarts, $itemEnds,
$formatted, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'],
$dbRow['playlist_name'], $dbRow['show_name'], $status);
}
return $dataTablesRows;
}
public static function CreateGapRow($p_gapTime){
private static function CreateGapRow($p_gapTime){
return array("g", "", "", "", $p_gapTime, "", "", "", "", "", "");
}
public static function CreateRecordingRow($p_showInstance){
private static function CreateRecordingRow($p_showInstance){
return array("r", "", "", "", $p_showInstance->getName(), "", "", "", "", "", "");
}
public static function GetDataGridData($viewType, $dateString){
if ($viewType == "now"){
$date = new DateHelper;
$timeNow = $date->getTimestamp();
$dateTime = new DateTime("now", new DateTimeZone("UTC"));
$timeNow = $dateTime->format("Y-m-d H:i:s");
$startCutoff = 60;
$endCutoff = 86400; //60*60*24 - seconds in a day
} else {
$date = new DateHelper;
$time = $date->getTime();
$date->setDate($dateString." ".$time);
$timeNow = $date->getTimestamp();
$timeNow = $date->getUtcTimestamp();
$startCutoff = $date->getNowDayStartDiff();
$endCutoff = $date->getNowDayEndDiff();
@ -71,21 +81,24 @@ class Application_Model_Nowplaying
$showId = $si->getShowId();
$show = new Show($showId);
$showStartDateTime = DateHelper::ConvertToLocalDateTime($si->getShowStart());
$showEndDateTime = DateHelper::ConvertToLocalDateTime($si->getShowEnd());
//append show header row
$data[] = Application_Model_Nowplaying::CreateHeaderRow($show->getName(), $si->getShowStart(), $si->getShowEnd());
$data[] = self::CreateHeaderRow($show->getName(), $showStartDateTime->format("Y-m-d H:i:s"), $showEndDateTime->format("Y-m-d H:i:s"));
$scheduledItems = $si->getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff);
$dataTablesRows = Application_Model_Nowplaying::CreateDatatableRows($scheduledItems);
$dataTablesRows = self::CreateDatatableRows($scheduledItems);
//append show audio item rows
$data = array_merge($data, $dataTablesRows);
//append show gap time row
$gapTime = Application_Model_Nowplaying::FormatDuration($si->getShowEndGapTime(), true);
$gapTime = self::FormatDuration($si->getShowEndGapTime(), true);
if ($si->isRecorded())
$data[] = Application_Model_Nowplaying::CreateRecordingRow($si);
$data[] = self::CreateRecordingRow($si);
else if ($gapTime > 0)
$data[] = Application_Model_Nowplaying::CreateGapRow($gapTime);
$data[] = self::CreateGapRow($gapTime);
}
return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data);
@ -102,7 +115,7 @@ class Application_Model_Nowplaying
* default $time format should be in format of 00:00:00
* if $inSecond = true, then $time should be in seconds
*/
public static function FormatDuration($time, $inSecond=false){
private static function FormatDuration($time, $inSecond=false){
if($inSecond == false){
$duration = explode(':', $time);
}else{

View file

@ -264,7 +264,6 @@ class Application_Model_Preference
Application_Model_Preference::SetValue("timezone", $timezone);
date_default_timezone_set($timezone);
$md = array("timezone" => $timezone);
RabbitMq::SendMessageToPypo("update_timezone", $md);
}
public static function GetTimezone(){

View file

@ -108,13 +108,12 @@ class RabbitMq
$EXCHANGE = 'airtime-show-recorder';
$channel->exchange_declare($EXCHANGE, 'direct', false, true);
$today_timestamp = date("Y-m-d H:i:s");
$now = new DateTime($today_timestamp);
$end_timestamp = $now->add(new DateInterval("PT2H"));
$end_timestamp = $end_timestamp->format("Y-m-d H:i:s");
$now = new DateTime("@".time());
$end_timestamp = new DateTime("@".time() + 3600*2);
$temp['event_type'] = $event_type;
if($event_type = "update_schedule"){
$temp['shows'] = Show::getShows($today_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=TRUE);
$temp['shows'] = Show::getShows($now->format("Y-m-d H:i:s"), $end_timestamp->format("Y-m-d H:i:s"), $excludeInstance=NULL, $onlyRecord=TRUE);
}
$data = json_encode($temp);
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));

View file

@ -364,12 +364,9 @@ class Schedule {
global $CC_CONFIG;
$date = new DateHelper;
$timeNow = $date->getTimestamp();
$timeNow = $date->getUtcTimestamp();
return array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"),
//"previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"),
//"current"=>Schedule::GetScheduledItemData($timeNow, 0),
//"next"=>Schedule::GetScheduledItemData($timeNow, 1, $next, "48 hours"),
"schedulerTime"=>$timeNow,
"previous"=>Application_Model_Dashboard::GetPreviousItem($timeNow),
"current"=>Application_Model_Dashboard::GetCurrentItem($timeNow),
"next"=>Application_Model_Dashboard::GetNextItem($timeNow),
@ -660,13 +657,13 @@ class Schedule {
global $CC_CONFIG, $CC_DBC;
if (is_null($p_fromDateTime)) {
$t1 = new DateTime();
$t1 = new DateTime("now", new DateTimeZone("UTC"));
$range_start = $t1->format("Y-m-d H:i:s");
} else {
$range_start = Schedule::PypoTimeToAirtimeTime($p_fromDateTime);
}
if (is_null($p_fromDateTime)) {
$t2 = new DateTime();
$t2 = new DateTime("now", new DateTimeZone("UTC"));
$t2->add(new DateInterval("PT24H"));
$range_end = $t2->format("Y-m-d H:i:s");
} else {
@ -740,7 +737,6 @@ class Schedule {
$result['stream_metadata'] = array();
$result['stream_metadata']['format'] = Application_Model_Preference::GetStreamLabelFormat();
$result['stream_metadata']['station_name'] = Application_Model_Preference::GetStationName();
$result['server_timezone'] = date('O');
return $result;
}

View file

@ -724,27 +724,26 @@ class Show {
*/
public static function create($data)
{
$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
$sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$data['add_show_start_date']} {$data['add_show_start_time']}')";
$r = $con->query($sql);
$startDow = $r->fetchColumn(0);
$utcStartDateTime = new DateTime($data['add_show_start_date']." ".$data['add_show_start_time']);
$utcStartDateTime->setTimezone(new DateTimeZone('UTC'));
if ($data['add_show_no_end']) {
$endDate = NULL;
$endDateTime = NULL;
}
else if ($data['add_show_repeats']) {
$sql = "SELECT date '{$data['add_show_end_date']}' + INTERVAL '1 day' ";
$r = $con->query($sql);
$endDate = $r->fetchColumn(0);
$endDateTime = new DateTime($data['add_show_end_date']);
$endDateTime->setTimezone(new DateTimeZone('UTC'));
$endDateTime->add(new DateInterval("P1D"));
}
else {
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '1 day' ";
$r = $con->query($sql);
$endDate = $r->fetchColumn(0);
$endDateTime = new DateTime($data['add_show_start_date']);
$endDateTime->setTimezone(new DateTimeZone('UTC'));
$endDateTime->add(new DateInterval("P1D"));
}
//only want the day of the week from the start date.
$startDow = date("w", $utcStartDateTime->getTimestamp());
if (!$data['add_show_repeats']) {
$data['add_show_day_check'] = array($startDow);
} else if ($data['add_show_repeats'] && $data['add_show_day_check'] == "") {
@ -768,12 +767,12 @@ class Show {
$ccShow->save();
$showId = $ccShow->getDbId();
$show = new Show($showId);
$isRecorded = ($data['add_show_record']) ? 1 : 0;
if ($data['add_show_id'] != -1){
$show->deletePossiblyInvalidInstances($data, $endDate, $isRecorded, $repeatType);
$show = new Show($showId);
$show->deletePossiblyInvalidInstances($data, $endDateTime->format("Y-m-d"), $isRecorded, $repeatType);
}
//check if we are adding or updating a show, and if updating
@ -785,37 +784,30 @@ class Show {
//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($data['add_show_start_date']);
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($data['add_show_start_time']);
$showDay->setDbFirstShow($utcStartDateTime->format("Y-m-d"));
$showDay->setDbLastShow($endDateTime->format("Y-m-d"));
$showDay->setDbStartTime($utcStartDateTime->format("H:i:s"));
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbRepeatType($repeatType);
$showDay->setDbShowId($showId);
$showDay->setDbRecord($isRecorded);
$showDay->save();
}
else {
} else {
foreach ($data['add_show_day_check'] as $day) {
if ($startDow !== $day){
if ($startDow > $day)
$daysAdd = 6 - $startDow + 1 + $day;
else
$daysAdd = $day - $startDow;
$sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '{$daysAdd} day' ";
$r = $con->query($sql);
$start = $r->fetchColumn(0);
}
else {
$start = $data['add_show_start_date'];
$utcStartDateTime->add("P".$daysAdd."d");
}
if (strtotime($start) <= strtotime($endDate) || is_null($endDate)) {
if (is_null($endDateTime) || strtotime($utcStartDateTime->format("Y-m-d")) <= $endDateTime->getTimestamp()) {
$showDay = new CcShowDays();
$showDay->setDbFirstShow($start);
$showDay->setDbLastShow($endDate);
$showDay->setDbStartTime($data['add_show_start_time']);
$showDay->setDbFirstShow($utcStartDateTime->format("Y-m-d"));
$showDay->setDbLastShow($endDateTime->format("Y-m-d"));
$showDay->setDbStartTime($utcStartDateTime->format("H:i:s"));
$showDay->setDbDuration($data['add_show_duration']);
$showDay->setDbDay($day);
$showDay->setDbRepeatType($repeatType);
@ -826,15 +818,11 @@ class Show {
}
}
$date = new DateHelper();
$currentTimestamp = $date->getTimestamp();
//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) && $data['add_show_rebroadcast']){
CcShowRebroadcastQuery::create()
->filterByDbShowId($data['add_show_id'])
//->filterByDbStartTime($currentTimestamp, Criteria::GREATER_EQUAL)
->delete();
}
//adding rows to cc_show_rebroadcast
@ -852,6 +840,7 @@ class Show {
else if ($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']}' ";
$r = $con->query($sql);
$offset_days = $r->fetchColumn(0);
@ -1236,11 +1225,17 @@ class Show {
if($show["rebroadcast"]) {
$event["disableResizing"] = true;
}
$startDateTime = new DateTime($show["starts"], new DateTimeZone("UTC"));
$startDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
$endDateTime = new DateTime($show["ends"], new DateTimeZone("UTC"));
$endDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
$event["id"] = $show["instance_id"];
$event["title"] = $show["name"];
$event["start"] = $show["starts"];
$event["end"] = $show["ends"];
$event["start"] = $startDateTime->format("Y-m-d H:i:s");
$event["end"] = $endDateTime->format("Y-m-d H:i:s");
$event["allDay"] = false;
$event["description"] = $show["description"];
$event["showId"] = $show["show_id"];